bugfix: fix #233

This commit is contained in:
Joao Tavora 2012-05-21 14:47:42 +01:00
parent 9fc2e20d91
commit 4f846f2c36

View File

@ -1018,7 +1018,6 @@ Has the following fields:
;; ;;
(remhash uuid (yas/table-uuidhash table)))))) (remhash uuid (yas/table-uuidhash table))))))
(defun yas/add-template (table template) (defun yas/add-template (table template)
"Store in TABLE the snippet template TEMPLATE. "Store in TABLE the snippet template TEMPLATE.
@ -1027,7 +1026,7 @@ keybinding)."
(let ((name (yas/template-name template)) (let ((name (yas/template-name template))
(key (yas/template-key template)) (key (yas/template-key template))
(keybinding (yas/template-keybinding template)) (keybinding (yas/template-keybinding template))
(menu-binding (car (yas/template-menu-binding-pair template)))) (menu-binding-pair (yas/snippet-menu-binding-pair-get-create template)))
(dolist (k (remove nil (list key keybinding))) (dolist (k (remove nil (list key keybinding)))
(puthash name (puthash name
template template
@ -1039,28 +1038,27 @@ keybinding)."
(when (vectorp k) (when (vectorp k)
(define-key (yas/table-direct-keymap table) k 'yas/expand-from-keymap))) (define-key (yas/table-direct-keymap table) k 'yas/expand-from-keymap)))
(when menu-binding ;; Update trigger & keybinding in the menu-binding pair
(setf (getf (cdr menu-binding) :keys) ;;
(or (and keybinding (key-description keybinding)) (setf (getf (cdr (car menu-binding-pair)) :keys)
(and key (concat key yas/trigger-symbol)))) (or (and keybinding (key-description keybinding))
(setcar (cdr menu-binding) (and key (concat key yas/trigger-symbol))))
name))
(puthash (yas/template-uuid template) template (yas/table-uuidhash table)))) (puthash (yas/template-uuid template) template (yas/table-uuidhash table))))
(defun yas/update-template (snippet-table template) (defun yas/update-template (table template)
"Add or update TEMPLATE in SNIPPET-TABLE. "Add or update TEMPLATE in TABLE.
Also takes care of adding and updaring to the associated menu." Also takes care of adding and updating to the associated menu."
;; Remove from table by uuid ;; Remove from table by uuid
;; ;;
(yas/remove-template-by-uuid snippet-table (yas/template-uuid template)) (yas/remove-template-by-uuid table (yas/template-uuid template))
;; Add to table again ;; Add to table again
;; ;;
(yas/add-template snippet-table template) (yas/add-template table template)
;; Take care of the menu ;; Take care of the menu
;; ;;
(let ((keymap (yas/menu-keymap-get-create snippet-table)) (let ((keymap (yas/menu-keymap-get-create table))
(group (yas/template-group template))) (group (yas/template-group template)))
(when (and yas/use-menu (when (and yas/use-menu
keymap keymap
@ -1680,34 +1678,49 @@ Below TOP-LEVEL-DIR each directory is a mode name."
Behaviour is affected by `yas/no-jit', which see." Behaviour is affected by `yas/no-jit', which see."
(interactive "p") (interactive "p")
(let ((errors)) (catch 'abort
;; Empty all snippet tables, parenting info and all menu tables (let ((errors)
;; (snippet-editing-buffers
(setq yas/tables (make-hash-table)) (remove-if-not #'(lambda (buffer)
(setq yas/parents (make-hash-table)) (with-current-buffer buffer yas/editing-template))
(setq yas/menu-table (make-hash-table)) (buffer-list))))
;; Warn if there are buffers visiting snippets, since reloading will break
;; any on-line editing of those buffers.
;;
(if snippet-editing-buffers
(if (y-or-n-p "Some buffers editing live snippets, close them and proceed with reload?")
(mapcar #'kill-buffer snippet-editing-buffers)
(yas/message 1 "Aborted reload...")
(throw 'abort nil)))
;; Cancel all pending 'yas/scheduled-jit-loads' ;; Empty all snippet tables, parenting info and all menu tables
;; ;;
(setq yas/scheduled-jit-loads (make-hash-table)) (setq yas/tables (make-hash-table))
(setq yas/parents (make-hash-table))
(setq yas/menu-table (make-hash-table))
;; Init the `yas/minor-mode-map', taking care not to break the ;; Cancel all pending 'yas/scheduled-jit-loads'
;; menu.... ;;
;; (setq yas/scheduled-jit-loads (make-hash-table))
(setf (cdr yas/minor-mode-map)
(cdr (yas/init-minor-keymap)))
;; Reload the directories listed in `yas/snippet-dirs' or prompt ;; Init the `yas/minor-mode-map', taking care not to break the
;; the user to select one. ;; menu....
;; ;;
(setq errors (yas/load-snippet-dirs no-jit)) (setf (cdr yas/minor-mode-map)
;; Reload the direct keybindings (cdr (yas/init-minor-keymap)))
;;
(yas/direct-keymaps-reload) ;; Reload the directories listed in `yas/snippet-dirs' or prompt
;; Reload the trigger-key (shoudn't be needed, but see issue #237) ;; the user to select one.
;; ;;
(yas/trigger-key-reload) (setq errors (yas/load-snippet-dirs no-jit))
(yas/message 3 "Reloaded everything...%s." (if errors " (some errors, check *Messages*)" "")))) ;; Reload the direct keybindings
;;
(yas/direct-keymaps-reload)
;; Reload the trigger-key (shoudn't be needed, but see issue #237)
;;
(yas/trigger-key-reload)
(yas/message 3 "Reloaded everything...%s." (if errors " (some errors, check *Messages*)" "")))))
(defun yas/load-pending-jits () (defun yas/load-pending-jits ()
(when yas/minor-mode (when yas/minor-mode