]> git.eshelyaron.com Git - emacs.git/commitdiff
Move context-menu selection items Defun/List/Symbol to prog-mode (bug#9054)
authorJuri Linkov <juri@linkov.net>
Sun, 3 Oct 2021 17:35:49 +0000 (20:35 +0300)
committerJuri Linkov <juri@linkov.net>
Sun, 3 Oct 2021 17:35:49 +0000 (20:35 +0300)
* lisp/mouse.el (context-menu-functions):
Add context-menu-middle-separator to choices.
(context-menu-region): Move Defun/List/Symbol selection items
to prog-context-menu.

* lisp/progmodes/prog-mode.el (prog-context-menu):
Move Defun/List/Symbol selection items from context-menu-region.
Include text-mode select menu only in strings and comments.

* lisp/textmodes/text-mode.el (text-mode-menu): New function.
(text-mode): Add text-mode-menu to context-menu-functions.

lisp/mouse.el
lisp/progmodes/prog-mode.el
lisp/textmodes/text-mode.el

index 5d4e05fa25e328e2146f73de53e47db799bdddc6..bb47d04a3a862b2ff1af5928310dd5bd090ec372 100644 (file)
@@ -290,6 +290,7 @@ and should return the same menu with changes such as added new menu items."
   :type '(repeat
           (choice (function-item context-menu-undo)
                   (function-item context-menu-region)
+                  (function-item context-menu-middle-separator)
                   (function-item context-menu-toolbar)
                   (function-item context-menu-global)
                   (function-item context-menu-local)
@@ -478,14 +479,6 @@ Some context functions add menu items below the separator."
       `(menu-item "All"
                   ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'buffer))
                   :help "Mark the whole buffer for a subsequent cut/copy"))
-    (define-key-after submenu [mark-defun]
-      `(menu-item "Defun"
-                  ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'defun))
-                  :help "Mark the defun at click for a subsequent cut/copy"))
-    (define-key-after submenu [mark-list]
-      `(menu-item "List"
-                  ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'list))
-                  :help "Mark the list at click for a subsequent cut/copy"))
     (when (let* ((pos (posn-point (event-end click)))
                  (char (when pos (char-after pos))))
             (or (and char (eq (char-syntax char) ?\"))
@@ -498,10 +491,6 @@ Some context functions add menu items below the separator."
       `(menu-item "Line"
                   ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'line))
                   :help "Mark the line at click for a subsequent cut/copy"))
-    (define-key-after submenu [mark-symbol]
-      `(menu-item "Symbol"
-                  ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'symbol))
-                  :help "Mark the symbol at click for a subsequent cut/copy"))
     (when (region-active-p)
       (define-key-after submenu [mark-none]
         `(menu-item "None"
index 6c09dcf881da1ae4d5b8bcc00acccacd8b16ef4b..4f15686dc87ad0e90ef837bc1a552af98a7a0ecd 100644 (file)
         `(menu-item "Find Definition" xref-find-definitions-at-mouse
                     :help ,(format "Find definition of `%s'" identifier))
         'prog-separator)))
+
+  (when (thing-at-mouse click 'symbol)
+    (define-key-after menu [select-region mark-symbol]
+      `(menu-item "Symbol"
+                  ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'symbol))
+                  :help "Mark the symbol at click for a subsequent cut/copy")
+      'mark-whole-buffer))
+  (define-key-after menu [select-region mark-list]
+    `(menu-item "List"
+                ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'list))
+                :help "Mark the list at click for a subsequent cut/copy")
+    'mark-whole-buffer)
+  (define-key-after menu [select-region mark-defun]
+    `(menu-item "Defun"
+                ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'defun))
+                :help "Mark the defun at click for a subsequent cut/copy")
+    'mark-whole-buffer)
+
+  ;; Include text-mode select menu only in strings and comments.
+  (when (nth 8 (save-excursion (syntax-ppss (posn-point (event-end click)))))
+    (text-mode-menu menu click))
+
   menu)
 
 (defvar prog-mode-map
index 74c6d412a651283f73b5b57649b3e864c72fa324..3243bd31c4c0694ee0181bed76ec32aa1ec6e1ec 100644 (file)
@@ -95,6 +95,28 @@ inherit all the commands defined in this map.")
      :style toggle
      :selected (memq 'turn-on-auto-fill text-mode-hook)]))
 
+(defun text-mode-menu (menu click)
+  "Populate MENU with text selection commands at CLICK."
+
+  (when (thing-at-mouse click 'word)
+    (define-key-after menu [select-region mark-word]
+      `(menu-item "Word"
+                  ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'word))
+                  :help "Mark the word at click for a subsequent cut/copy")
+      'mark-whole-buffer))
+  (define-key-after menu [select-region mark-sentence]
+    `(menu-item "Sentence"
+                ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'sentence))
+                :help "Mark the sentence at click for a subsequent cut/copy")
+    'mark-whole-buffer)
+  (define-key-after menu [select-region mark-paragraph]
+    `(menu-item "Paragraph"
+                ,(lambda (e) (interactive "e") (mark-thing-at-mouse e 'paragraph))
+                :help "Mark the paragraph at click for a subsequent cut/copy")
+    'mark-whole-buffer)
+
+  menu)
+
 \f
 (define-derived-mode text-mode nil "Text"
   "Major mode for editing text written for humans to read.
@@ -104,7 +126,8 @@ You can thus get the full benefit of adaptive filling
 \\{text-mode-map}
 Turning on Text mode runs the normal hook `text-mode-hook'."
   (setq-local text-mode-variant t)
-  (setq-local require-final-newline mode-require-final-newline))
+  (setq-local require-final-newline mode-require-final-newline)
+  (add-hook 'context-menu-functions 'text-mode-menu 10 t))
 
 (define-derived-mode paragraph-indent-text-mode text-mode "Parindent"
   "Major mode for editing text, with leading spaces starting a paragraph.