emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 2a1d5eb8f6 4/6: Add code to integrate menu with


From: ELPA Syncer
Subject: [elpa] externals/denote 2a1d5eb8f6 4/6: Add code to integrate menu with context-menu-mode
Date: Fri, 31 Mar 2023 12:57:39 -0400 (EDT)

branch: externals/denote
commit 2a1d5eb8f668724e5b37e085e64ff00d44f3eb1a
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Add code to integrate menu with context-menu-mode
    
    Enable it with:
    
            (add-hook 'context-menu-functions #'denote-context-menu)
    
    Read what I published about the menu:
    <https://protesilaos.com/codelog/2023-03-31-emacs-denote-menu/>.
---
 denote.el | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/denote.el b/denote.el
index 530b9178f4..c0954419c5 100644
--- a/denote.el
+++ b/denote.el
@@ -3224,8 +3224,7 @@ This command is meant to be used from a Dired buffer."
 
 ;;;;; Define menu
 
-(easy-menu-define denote-global-menu global-map
-  "Menu with all Denote commands, each available in the right context."
+(defvar denote--menu-contents
   '("Denote"
     ["Create a note" denote
      :help "Create a new note in the `denote-directory'"]
@@ -3268,7 +3267,23 @@ This command is meant to be used from a Dired buffer."
         :help "Apply colors to Denote file name components in Dired"
         :enable (derived-mode-p 'dired-mode)
         :style toggle
-     :selected (bound-and-true-p denote-dired-mode)]))
+     :selected (bound-and-true-p denote-dired-mode)])
+  "Contents of the Denote menu.")
+
+(easy-menu-define denote-global-menu global-map
+  "Menu with all Denote commands, each available in the right context."
+  denote--menu-contents)
+
+(defun denote-context-menu (menu _click)
+  "Populate MENU with Denote commands at CLICK."
+  (define-key menu [denote-separator] menu-bar-separator)
+  (let ((easy-menu (make-sparse-keymap "Denote")))
+    (easy-menu-define nil easy-menu nil
+      denote--menu-contents)
+    (dolist (item (reverse (lookup-key easy-menu [menu-bar])))
+      (when (consp item)
+        (define-key menu (vector (car item)) (cdr item)))))
+  menu)
 
 ;;;;; Register `denote:' custom Org hyperlink
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]