2

我正在寻找一种方法来复制库中片段的 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"))

截图1
(来源:lawlist.com

截图2

4

1 回答 1

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)

例子
(来源:lawlist.com

于 2013-10-06T17:46:21.750 回答