Move context-menu selection items Defun/List/Symbol to prog-mode (bug#9054)

* 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.
This commit is contained in:
Juri Linkov 2021-10-03 20:35:49 +03:00
parent 0c341e6e84
commit 121a5abeae
3 changed files with 47 additions and 13 deletions

View 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"

View file

@ -68,6 +68,28 @@
`(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

View 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)
(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.