2013-05-09 84 views
2

我正在尋找一種方法來複制YASnippet簡單的菜單欄條目爲我的庫中的片段(自動出現在菜單中無論使用何種模式),並將它們合併到我自己的自定義菜單中。 yas--minor-mode-menu的輸入不起作用。我正在尋找的代碼將基本上是相同的一個與普通簡單的菜單欄的定製作品:YASnippet - 如何創建一個右鍵單擊上下文菜單 - 彈出式菜單

(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

回答

2
(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) 

Example http://www.lawlist.com/images/context-menu.png

相關問題