summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Antolín Camarena <omar.antolin@gmail.com>2025-06-21 23:30:54 -0600
committerGitHub <noreply@github.com>2025-06-21 23:30:54 -0600
commit1f47c4ece2cfe715a1c6d254fb312fb65afd9ce3 (patch)
tree900398ef5ccfb241f965bd79ca5817401a4bbf22
parent2941f2ea36d61c1a84c3f79ebe47d604c9a92b5d (diff)
parent38829a3b6b0c4e4610c9b0dacb1b203a2898f5fe (diff)
Merge pull request #758 from minad/context-menu
Add embark-context-menu
-rw-r--r--CHANGELOG.org6
-rw-r--r--README.org4
-rw-r--r--embark.el41
-rw-r--r--embark.texi4
4 files changed, 55 insertions, 0 deletions
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 058be1c..dac0d45 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 d4026e0..cece0f3 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 61350d6..345f976 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 a07b49f..e970e77 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