branch: externals/embark commit 1f47c4ece2cfe715a1c6d254fb312fb65afd9ce3 Merge: 2941f2ea36 38829a3b6b Author: Omar Antolín Camarena <omar.anto...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #758 from minad/context-menu Add embark-context-menu --- CHANGELOG.org | 6 ++++++ README.org | 4 ++++ embark.el | 41 +++++++++++++++++++++++++++++++++++++++++ embark.texi | 4 ++++ 4 files changed, 55 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..345f976802 100644 --- a/embark.el +++ b/embark.el @@ -1139,6 +1139,47 @@ 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." + (if (and (minibufferp) (embark--targets)) + (define-key menu [embark-context-menu] + `( "Embark" . + ,(easy-menu-create-menu + "" + ;; PROBLEM: embark-dwim and embark-act in the minibuffer + ;; do not select the correct candidate + '(;;["DWIM" embark-dwim :keys "\\[embark-dwim]"] + ;;["Act" embark-act :keys "\\[embark-act]"] + ["Act All" embark-act :keys "\\[embark-act] A"] + ["Export" embark-export :keys "\\[embark-act] A"] + ["Snapshot" embark-collect :keys "\\[embark-act] S"])))) + (when-let ((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)) + :keys "\\[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)) + :keys "\\[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