Closes #403: more uniform behaviour for `yas-use-menu'

Suggested by Noam Postavsky, this uses the :visible arg to
`easy-menu-define' to hide the whole "YASnippet" menu according to the
run-time value of `yas-use-menu'. Previously, only the load-time value
was considered and some functions we're noops when `yas-use-menu' was
nil.

The per-mode snippet submenus are now always updated even if
`yas-use-menu' is nil, although they won't be shown until it becomes
non-nil.

* yasnippet.el (yas--minor-mode-menu): Use :visible arg and eval `yas-use-menu'
(yas--update-template): Always update the menu.
(yas--show-menu-p): Always return t if `yas-use-menu' is non-nil and not `abbreviate'
(yas-define-menu): Always define a menu.
(yas-use-menu): Update docstring.
This commit is contained in:
Joao Tavora 2014-03-14 09:55:22 +00:00
parent b36a4f7449
commit 8e7295b934

View File

@ -313,6 +313,8 @@ menu and the modes set in `yas--extra-modes' are listed.
- If set to `full', every submenu is listed - If set to `full', every submenu is listed
- If set to `nil', hide the menu.
Any other non-nil value, every submenu is listed." Any other non-nil value, every submenu is listed."
:type '(choice (const :tag "Full" full) :type '(choice (const :tag "Full" full)
(const :tag "Abbreviate" abbreviate) (const :tag "Abbreviate" abbreviate)
@ -546,7 +548,7 @@ snippet itself contains a condition that returns the symbol
(easy-menu-define yas--minor-mode-menu (easy-menu-define yas--minor-mode-menu
yas-minor-mode-map yas-minor-mode-map
"Menu used when `yas-minor-mode' is active." "Menu used when `yas-minor-mode' is active."
'("YASnippet" '("YASnippet" :visible yas-use-menu
"----" "----"
["Expand trigger" yas-expand ["Expand trigger" yas-expand
:help "Possibly expand tab trigger before point"] :help "Possibly expand tab trigger before point"]
@ -1063,8 +1065,7 @@ Also takes care of adding and updating to the associated menu."
(yas--add-template table template) (yas--add-template table template)
;; Take care of the menu ;; Take care of the menu
;; ;;
(when yas-use-menu (yas--update-template-menu table template))
(yas--update-template-menu table template)))
(defun yas--update-template-menu (table template) (defun yas--update-template-menu (table template)
"Update every menu-related for TEMPLATE." "Update every menu-related for TEMPLATE."
@ -1976,10 +1977,7 @@ static in the menu."
(mapcar #'(lambda (table) (mapcar #'(lambda (table)
(yas--table-mode table)) (yas--table-mode table))
(yas--get-snippet-tables)))) (yas--get-snippet-tables))))
((eq yas-use-menu 'full) (yas-use-menu t)))
t)
((eq yas-use-menu t)
t)))
(defun yas--delete-from-keymap (keymap uuid) (defun yas--delete-from-keymap (keymap uuid)
"Recursively delete items with UUID from KEYMAP and its submenus." "Recursively delete items with UUID from KEYMAP and its submenus."
@ -2022,24 +2020,21 @@ MENU is a list, its elements can be:
list of groups of the snippets defined thereafter. list of groups of the snippets defined thereafter.
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
omitted from MODE's menu, even if they're manually loaded. omitted from MODE's menu, even if they're manually loaded."
(let* ((table (yas--table-get-create mode))
This function does nothing if `yas-use-menu' is nil." (hash (yas--table-uuidhash table)))
(when yas-use-menu (yas--define-menu-1 table
(let* ((table (yas--table-get-create mode)) (yas--menu-keymap-get-create mode)
(hash (yas--table-uuidhash table))) menu
(yas--define-menu-1 table hash)
(yas--menu-keymap-get-create mode) (dolist (uuid omit-items)
menu (let ((template (or (gethash uuid hash)
hash) (yas--populate-template (puthash uuid
(dolist (uuid omit-items) (yas--make-blank-template)
(let ((template (or (gethash uuid hash) hash)
(yas--populate-template (puthash uuid :table table
(yas--make-blank-template) :uuid uuid))))
hash) (setf (yas--template-menu-binding-pair template) (cons nil :none))))))
:table table
:uuid uuid))))
(setf (yas--template-menu-binding-pair template) (cons nil :none)))))))
(defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list) (defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list)
"Helper for `yas-define-menu'." "Helper for `yas-define-menu'."