aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2021-07-28 19:40:23 +0300
committerJuri Linkov2021-07-28 19:40:23 +0300
commitee1887bf54e7091a382ad24691ce0f482c61d7ea (patch)
tree72a391ca9736e72d291f6b967b27d18091b05a47
parent2c2baa9d1231ad9e642e3a80fb1c641fdde71b33 (diff)
downloademacs-ee1887bf54e7091a382ad24691ce0f482c61d7ea.tar.gz
emacs-ee1887bf54e7091a382ad24691ce0f482c61d7ea.zip
Improve :type of defcustom 'context-menu-functions' and add documentation.
* doc/emacs/frames.texi (Menu Mouse Clicks): Describe context-menu-mode and context-menu-functions instead of suggesting global-set-key. (Menu Bars): Mention context-menu-mode and context-menu-functions. * etc/NEWS: Add context-menu-mode and context-menu-functions. * lisp/mouse.el (context-menu-functions): Use :type with repeat/function-item. (context-menu-minor, context-menu-undo, context-menu-region) (context-menu-ffap): Improve docstrings displayed for function-item in defcustom of context-menu-functions.
-rw-r--r--doc/emacs/frames.texi25
-rw-r--r--etc/NEWS11
-rw-r--r--lisp/mouse.el22
3 files changed, 34 insertions, 24 deletions
diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi
index 70615f68ed8..e03fb95755b 100644
--- a/doc/emacs/frames.texi
+++ b/doc/emacs/frames.texi
@@ -366,20 +366,15 @@ This menu is for changing the default face within the window's buffer.
366@xref{Text Scale}. 366@xref{Text Scale}.
367@end table 367@end table
368 368
369@cindex context menu
370@findex context-menu-mode
371@vindex context-menu-functions
372@kindex Down-mouse-3
369 Some graphical applications use @kbd{mouse-3} for a mode-specific 373 Some graphical applications use @kbd{mouse-3} for a mode-specific
370menu. If you prefer @kbd{mouse-3} in Emacs to bring up such a menu 374menu. If you prefer @kbd{mouse-3} in Emacs to bring up such a context
371instead of running the @code{mouse-save-then-kill} command, rebind 375menu instead of running the @code{mouse-save-then-kill} command,
372@kbd{mouse-3} by adding the following line to your init file 376enable @code{context-menu-mode} and customize the variable
373(@pxref{Init Rebinding}): 377@code{context-menu-functions}.
374
375@smallexample
376(global-set-key [mouse-3]
377 '(menu-item "Menu Bar" ignore
378 :filter (lambda (_)
379 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
380 (mouse-menu-bar-map)
381 (mouse-menu-major-mode-map)))))
382@end smallexample
383 378
384@node Mode Line Mouse 379@node Mode Line Mouse
385@section Mode Line Mouse Commands 380@section Mode Line Mouse Commands
@@ -1217,7 +1212,9 @@ the use of menu bars at startup, customize the variable
1217terminals, where this makes one additional line available for text. 1212terminals, where this makes one additional line available for text.
1218If the menu bar is off, you can still pop up a menu of its contents 1213If the menu bar is off, you can still pop up a menu of its contents
1219with @kbd{C-mouse-3} on a display which supports pop-up menus. 1214with @kbd{C-mouse-3} on a display which supports pop-up menus.
1220@xref{Menu Mouse Clicks}. 1215Or you can enable @code{context-menu-mode} and customize the variable
1216@code{context-menu-functions} to pop up a context menu with
1217@kbd{mouse-3}. @xref{Menu Mouse Clicks}.
1221 1218
1222 @xref{Menu Bar}, for information on how to invoke commands with the 1219 @xref{Menu Bar}, for information on how to invoke commands with the
1223menu bar. @xref{X Resources}, for how to customize the menu bar 1220menu bar. @xref{X Resources}, for how to customize the menu bar
diff --git a/etc/NEWS b/etc/NEWS
index 49396c321dc..4ca2623e9a1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -346,8 +346,17 @@ onto 'file-name-history'.
346+++ 346+++
347** A prefix arg now causes 'delete-other-frames' to only iconify frames. 347** A prefix arg now causes 'delete-other-frames' to only iconify frames.
348 348
349** Menus
350
351+++
352*** New mode 'context-menu-mode' for a context menu bound to 'mouse-3'.
353When this mode is enabled, clicking 'down-mouse-3' anywhere in the buffer
354pops up a context menu whose contents depends on surrounding context
355near the mouse click. You can customize the order of the default submenus
356in the context menu by customizing the user option 'context-menu-functions'.
357
349+++ 358+++
350** The "Edit => Clear" menu item now obeys a rectangular region. 359*** The "Edit => Clear" menu item now obeys a rectangular region.
351 360
352+++ 361+++
353** New command 'execute-extended-command-for-buffer'. 362** New command 'execute-extended-command-for-buffer'.
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 60c4f4b85c5..49191e32ea4 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -286,14 +286,15 @@ not it is actually displayed."
286 "List of functions that produce the contents of the context menu. 286 "List of functions that produce the contents of the context menu.
287Each function receives the menu as its argument and should return 287Each function receives the menu as its argument and should return
288the same menu with changes such as added new menu items." 288the same menu with changes such as added new menu items."
289 :type 'hook 289 :type '(repeat
290 :options '(context-menu-undo 290 (choice (function-item context-menu-undo)
291 context-menu-region 291 (function-item context-menu-region)
292 context-menu-global 292 (function-item context-menu-global)
293 context-menu-local 293 (function-item context-menu-local)
294 context-menu-minor 294 (function-item context-menu-minor)
295 context-menu-vc 295 (function-item context-menu-vc)
296 context-menu-ffap) 296 (function-item context-menu-ffap)
297 (function :tag "Custom function")))
297 :version "28.1") 298 :version "28.1")
298 299
299(defcustom context-menu-filter-function nil 300(defcustom context-menu-filter-function nil
@@ -337,7 +338,7 @@ the same menu with changes such as added new menu items."
337 menu) 338 menu)
338 339
339(defun context-menu-minor (menu) 340(defun context-menu-minor (menu)
340 "Minor mode submenus." 341 "Minor modes submenus."
341 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) 342 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
342 (define-key-after menu [separator-minor] menu-bar-separator) 343 (define-key-after menu [separator-minor] menu-bar-separator)
343 (dolist (mode (minor-mode-key-binding [menu-bar])) 344 (dolist (mode (minor-mode-key-binding [menu-bar]))
@@ -357,6 +358,7 @@ the same menu with changes such as added new menu items."
357 menu) 358 menu)
358 359
359(defun context-menu-undo (menu) 360(defun context-menu-undo (menu)
361 "Undo menu."
360 (when (cddr menu) 362 (when (cddr menu)
361 (define-key-after menu [separator-undo] menu-bar-separator)) 363 (define-key-after menu [separator-undo] menu-bar-separator))
362 (define-key-after menu [undo] 364 (define-key-after menu [undo]
@@ -375,6 +377,7 @@ the same menu with changes such as added new menu items."
375 menu) 377 menu)
376 378
377(defun context-menu-region (menu) 379(defun context-menu-region (menu)
380 "Region commands menu."
378 (when (cddr menu) 381 (when (cddr menu)
379 (define-key-after menu [separator-region] menu-bar-separator)) 382 (define-key-after menu [separator-region] menu-bar-separator))
380 (define-key-after menu [cut] 383 (define-key-after menu [cut]
@@ -424,6 +427,7 @@ the same menu with changes such as added new menu items."
424 menu) 427 menu)
425 428
426(defun context-menu-ffap (menu) 429(defun context-menu-ffap (menu)
430 "File at point menu."
427 (save-excursion 431 (save-excursion
428 (mouse-set-point last-input-event) 432 (mouse-set-point last-input-event)
429 (when (ffap-guess-file-name-at-point) 433 (when (ffap-guess-file-name-at-point)