我正在寻找一种方法来复制我库中片段的YASnippet简易菜单栏条目(根据所使用的模式自动显示在菜单中),并将它们合并到我自己的自定义菜单中。 yas--minor-mode-menu
的条目不起作用。我正在寻找的代码基本上与常规的简单菜单栏自定义相同:
(easy-menu-define my-custom-menu LaTeX-mode-map "My own custom menu"
'("My Stuff"
["YASnippet" yas--minor-menu-mode t]
("Sub Menu"
["My subentry" my-obscure-function t])))
下面屏幕截图中的右键单击上下文菜单使用了几乎相同的东西:
(define-key map [mymenu] (cons "MyMenu" (make-sparse-keymap "hello world")))
(define-key map [mymenu 01] (cons "latexmk" 'run-latexmk))
(define-key map [mymenu 02] (cons "jump-to-pdf" 'TeX-view))
我不愿意放弃并简单地定义每个片段,然后为每个定义创建一个菜单项:
(defun bold ()
(interactive)
(yas--expand-or-visit-from-menu (quote latex-mode) "bold"))
screenshot1 http://www.lawlist.com/images/YASnippet.png screenshot2 http://www.lawlist.com/images/YASnippet2.png
答案 0 :(得分:3)
(defvar lawlist-context-menu-map
(let ((map (make-sparse-keymap "Context Menu")))
(define-key map [help-for-help] (cons "Help" 'help-for-help))
(define-key map [seperator-two] '(menu-item "--"))
(define-key map [my-menu] (cons "LAWLIST" (make-sparse-keymap "My Menu")))
(define-key map [my-menu 01] (cons "Next Line" 'next-line))
(define-key map [my-menu 02] (cons "Previous Line" 'previous-line))
(define-key map [seperator-one] '(menu-item "--"))
map) "Keymap for the LAWLIST context menu.")
(defun lawlist-popup-context-menu (event &optional prefix)
"Popup a context menu."
(interactive "@e \nP")
(define-key lawlist-context-menu-map [lawlist-major-mode-menu]
`(menu-item ,(symbol-name major-mode)
,(mouse-menu-major-mode-map) :visible t))
(define-key lawlist-context-menu-map (vector major-mode)
`(menu-item ,(concat "YAS " (symbol-name major-mode))
,(gethash major-mode yas--menu-table)
:visible (yas--show-menu-p ',major-mode)))
(popup-menu lawlist-context-menu-map event prefix))
(global-set-key [mouse-3] 'lawlist-popup-context-menu)