Closes #254: don't show a menu at all if yas-use-menu is nil.

This commit is contained in:
João Távora 2012-07-22 11:54:42 +01:00
parent 79d39c81a3
commit d4011a57d4

View File

@ -347,16 +347,18 @@ This affects `yas-insert-snippet', `yas-visit-snippet-file'"
When non-nil, submenus for each snippet table will be listed When non-nil, submenus for each snippet table will be listed
under the menu \"Yasnippet\". under the menu \"Yasnippet\".
- If set to `real-modes' only submenus whose name more or less
corresponds to a major mode are listed.
- If set to `abbreviate', only the current major-mode - If set to `abbreviate', only the current major-mode
menu and the modes set in `yas-extra-modes' are listed. menu and the modes set in `yas-extra-modes' are listed.
- If set to `full', every submenu is listed
- It set to nil, don't display a menu at all (this requires a
`yas-reload-all' call if the menu is already visible).
Any other non-nil value, every submenu is listed." Any other non-nil value, every submenu is listed."
:type '(choice (const :tag "Full" t) :type '(choice (const :tag "Full" full)
(const :tag "Real modes only" real-modes) (const :tag "Abbreviate" abbreviate)
(const :tag "Abbreviate" abbreviate)) (const :tag "No menu" nil))
:group 'yasnippet) :group 'yasnippet)
(defcustom yas-trigger-symbol " =>" (defcustom yas-trigger-symbol " =>"
@ -579,7 +581,8 @@ snippet itself contains a condition that returns the symbol
(defun yas--init-minor-keymap () (defun yas--init-minor-keymap ()
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(easy-menu-define yas--minor-mode-menu (when yas-use-menu
(easy-menu-define yas--minor-mode-menu
map map
"Menu used when `yas-minor-mode' is active." "Menu used when `yas-minor-mode' is active."
'("YASnippet" '("YASnippet"
@ -601,12 +604,9 @@ snippet itself contains a condition that returns the symbol
:help "Expand snippets from the menu" :help "Expand snippets from the menu"
:active t :style radio :selected (not yas-visit-from-menu)] :active t :style radio :selected (not yas-visit-from-menu)]
"----" "----"
["Show \"Real\" modes only" (setq yas-use-menu 'real-modes) ["Show all known modes" (setq yas-use-menu 'full)
:help "Show snippet submenus for modes that appear to be real major modes"
:active t :style radio :selected (eq yas-use-menu 'real-modes)]
["Show all modes" (setq yas-use-menu 't)
:help "Show one snippet submenu for each loaded table" :help "Show one snippet submenu for each loaded table"
:active t :style radio :selected (eq yas-use-menu 't)] :active t :style radio :selected (eq yas-use-menu 'full)]
["Abbreviate according to current mode" (setq yas-use-menu 'abbreviate) ["Abbreviate according to current mode" (setq yas-use-menu 'abbreviate)
:help "Show only snippet submenus for the current active modes" :help "Show only snippet submenus for the current active modes"
:active t :style radio :selected (eq yas-use-menu 'abbreviate)]) :active t :style radio :selected (eq yas-use-menu 'abbreviate)])
@ -685,7 +685,8 @@ snippet itself contains a condition that returns the symbol
["Reload everything" yas-reload-all ["Reload everything" yas-reload-all
:help "Cleanup stuff, reload snippets, rebuild menus"] :help "Cleanup stuff, reload snippets, rebuild menus"]
["About" yas-about ["About" yas-about
:help "Display some information about YASsnippet"])) :help "Display some information about YASsnippet"])))
;; Now for the stuff that has direct keybindings ;; Now for the stuff that has direct keybindings
;; ;;
(define-key map "\C-c&\C-s" 'yas-insert-snippet) (define-key map "\C-c&\C-s" 'yas-insert-snippet)
@ -1986,9 +1987,7 @@ static in the menu."
(mapcar #'(lambda (table) (mapcar #'(lambda (table)
(intern (yas--table-name table))) (intern (yas--table-name table)))
(yas--get-snippet-tables)))) (yas--get-snippet-tables))))
((eq yas-use-menu 'real-modes) ((eq yas-use-menu 'full)
(yas--real-mode? mode))
(t
t))) t)))
(defun yas--delete-from-keymap (keymap uuid) (defun yas--delete-from-keymap (keymap uuid)
@ -2033,21 +2032,24 @@ MENU is a list, its elements can be:
OMIT-ITEMS is a list of snippet uuid's that will always be OMIT-ITEMS is a list of snippet uuid's that will always be
ommited from MODE's menu, even if they're manually loaded. ommited from MODE's menu, even if they're manually loaded.
This function does nothing if `yas-use-menu' is nil.
" "
(let* ((table (yas--table-get-create mode)) (when yas-use-menu
(hash (yas--table-uuidhash table))) (let* ((table (yas--table-get-create mode))
(yas--define-menu-1 table (hash (yas--table-uuidhash table)))
(yas--menu-keymap-get-create table) (yas--define-menu-1 table
menu (yas--menu-keymap-get-create table)
hash) menu
(dolist (uuid omit-items) hash)
(let ((template (or (gethash uuid hash) (dolist (uuid omit-items)
(yas--populate-template (puthash uuid (let ((template (or (gethash uuid hash)
(yas--make-blank-template) (yas--populate-template (puthash uuid
hash) (yas--make-blank-template)
:table table hash)
:uuid uuid)))) :table table
(setf (yas--template-menu-binding-pair template) (cons nil :none)))))) :uuid uuid))))
(setf (yas--template-menu-binding-pair template) (cons nil :none)))))))
(defun yas--define-menu-1 (table keymap menu uuidhash &optional group-list) (defun yas--define-menu-1 (table keymap menu uuidhash &optional group-list)
(dolist (e (reverse menu)) (dolist (e (reverse menu))
@ -2075,12 +2077,12 @@ ommited from MODE's menu, even if they're manually loaded.
'(menu-item "----"))) '(menu-item "----")))
(t (t
(yas--message 3 "Don't know anything about menu entry %s" (first e)))))) (yas--message 3 "Don't know anything about menu entry %s" (first e))))))
(defun yas--define (mode key template &optional name condition group) (defun yas--define (mode key template &optional name condition group)
"Define a snippet. Expanding KEY into TEMPLATE. "Define a snippet. Expanding KEY into TEMPLATE.
NAME is a description to this template. Also update the menu if NAME is a description to this template. Also update the menu if
`yas-use-menu' is `t'. CONDITION is the condition attached to `yas-use-menu' is t. CONDITION is the condition attached to
this snippet. If you attach a condition to a snippet, then it this snippet. If you attach a condition to a snippet, then it
will only be expanded when the condition evaluated to non-nil." will only be expanded when the condition evaluated to non-nil."
(yas-define-snippets mode (yas-define-snippets mode