summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2025-06-03 02:56:40 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2025-06-03 03:03:38 +0200
commit669e7f4e62084967a11ab4d9d9dec41f385a636c (patch)
tree6a7e8d4e5e87d415ba6822a69ac7c4f118cdeb72
parent2941f2ea36d61c1a84c3f79ebe47d604c9a92b5d (diff)
Add embark-context-menu
(context-menu-mode 1) (add-hook 'context-menu-functions #'embark-context-menu 100)
-rw-r--r--CHANGELOG.org6
-rw-r--r--README.org4
-rw-r--r--embark.el28
-rw-r--r--embark.texi4
4 files changed, 42 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..027f839 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 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