branch: externals/embark commit 669e7f4e62084967a11ab4d9d9dec41f385a636c Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Add embark-context-menu (context-menu-mode 1) (add-hook 'context-menu-functions #'embark-context-menu 100) --- CHANGELOG.org | 6 ++++++ README.org | 4 ++++ embark.el | 28 ++++++++++++++++++++++++++++ embark.texi | 4 ++++ 4 files changed, 42 insertions(+) diff --git a/CHANGELOG.org b/CHANGELOG.org index 058be1ce20..dac0d45334 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -1,5 +1,11 @@ #+title: Embark changelog +* Development +- =embark-target-buffer-at-point=: New target finder for buffers at point in + Ibuffer or Buffer-menu. +- =embark-context-menu=: Bew function which can be added to + =context-menu-functions=. The mouse context menu is activated via + =context-menu-mode=. * Version 1.1 (2024-04-18) - The =embark-consult= package contains a new exporter for =consult-location= targets (produced by several =consult= commands such diff --git a/README.org b/README.org index d4026e0464..cece0f3c6c 100644 --- a/README.org +++ b/README.org @@ -375,6 +375,10 @@ starting configuration: ;; (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target) ;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly) + ;; Add Embark to the mouse context menu. Also enable `context-menu-mode'. + ;; (context-menu-mode 1) + ;; (add-hook 'context-menu-functions #'embark-context-menu 100) + :config ;; Hide the mode line of the Embark live/completions buffers diff --git a/embark.el b/embark.el index 61350d68cf..027f839b9c 100644 --- a/embark.el +++ b/embark.el @@ -1139,6 +1139,34 @@ added to `eldoc-documentation-functions'." targets ", "))))) +;;;###autoload +(defun embark-context-menu (menu event) + "Add Embark menu items to context MENU at the position of mouse EVENT." + (when-let (((not (minibufferp))) + (target (save-excursion + (mouse-set-point event) + (car (embark--targets))))) + (let* ((type (plist-get target :type)) + (target (embark--truncate-target (plist-get target :target))) + (action (embark--default-action type))) + (define-key menu [embark-act] + `( menu-item "Embark Act" + ,(lambda () + (interactive) + (mouse-set-point event) + (embark-act)) + :help ,(format "Act on %s ‘%s’" type target))) + (when (and action (symbolp action)) + (define-key menu [embark-dwim] + `( menu-item "Embark DWIM" + ,(lambda () + (interactive) + (mouse-set-point event) + (embark-dwim)) + :help ,(format "Run ‘%s’ on %s ‘%s’" + action type target)))))) + menu) + (defun embark--format-targets (target shadowed-targets rep) "Return a formatted string indicating the TARGET of an action. diff --git a/embark.texi b/embark.texi index a07b49f409..e970e77ee0 100644 --- a/embark.texi +++ b/embark.texi @@ -500,6 +500,10 @@ starting configuration: ;; (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target) ;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly) + ;; Add Embark to the mouse context menu. Also enable `context-menu-mode'. + ;; (context-menu 1) + ;; (add-hook 'context-menu-functions #'embark-context-menu 100) + :config ;; Hide the mode line of the Embark live/completions buffers