mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Previous approach breaks the mode menu, need another `yas/trigger-key-overriding\' var
This commit is contained in:
parent
50bcb8f2d8
commit
429db5c65c
64
yasnippet.el
64
yasnippet.el
@ -244,6 +244,7 @@ Naturally this is only valid when `yas/indent-line' is `auto'"
|
||||
:type 'boolean
|
||||
:group 'yasnippet)
|
||||
|
||||
(defvar yas/trigger-key-overriding nil)
|
||||
(defvar yas/trigger-key-map (make-sparse-keymap)
|
||||
"Keymap used only for adding the trigger key to `minor-mode-overriding-map-alist'")
|
||||
|
||||
@ -592,10 +593,20 @@ snippet itself contains a condition that returns the symbol
|
||||
(defvar yas/minor-mode-menu nil
|
||||
"Holds the YASnippet menu")
|
||||
|
||||
(defun yas/init-minor-keymap ()
|
||||
(defvar yas/minor-mode nil)
|
||||
|
||||
(defvar yas/minor-mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(easy-menu-define yas/minor-mode-menu
|
||||
map
|
||||
;; Now for the stuff that has direct keybindings
|
||||
;;
|
||||
(define-key map "\C-c&\C-s" 'yas/insert-snippet)
|
||||
(define-key map "\C-c&\C-n" 'yas/new-snippet)
|
||||
(define-key map "\C-c&\C-v" 'yas/visit-snippet-file)
|
||||
(define-key map "\C-c&\C-f" 'yas/find-snippets)
|
||||
map)
|
||||
"The keymap used when `yas/minor-mode' is active.")
|
||||
|
||||
(easy-menu-define yas/minor-mode-menu yas/minor-mode-map
|
||||
"Menu used when YAS/minor-mode is active."
|
||||
'("YASnippet"
|
||||
"----"
|
||||
@ -703,27 +714,12 @@ snippet itself contains a condition that returns the symbol
|
||||
:help "Cleanup stuff, reload snippets, rebuild menus"]
|
||||
["About" yas/about
|
||||
:help "Display some information about YASsnippet"]))
|
||||
;; Now for the stuff that has direct keybindings
|
||||
;;
|
||||
(define-key map "\C-c&\C-s" 'yas/insert-snippet)
|
||||
(define-key map "\C-c&\C-n" 'yas/new-snippet)
|
||||
(define-key map "\C-c&\C-v" 'yas/visit-snippet-file)
|
||||
(define-key map "\C-c&\C-f" 'yas/find-snippets)
|
||||
map))
|
||||
|
||||
(defvar yas/minor-mode-map (yas/init-minor-keymap)
|
||||
"The keymap used when `yas/minor-mode' is active.")
|
||||
|
||||
(defvar yas/trigger-key-active nil)
|
||||
(defun yas/trigger-key-reload (&optional override)
|
||||
"Rebind `yas/expand' to the new value of `yas/trigger-key'."
|
||||
(let ((override (yas/read-kbd-macro override)))
|
||||
(aput 'minor-mode-overriding-map-alist
|
||||
'yas/minor-mode
|
||||
(if override
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(define-key map override 'yas/expand)
|
||||
map)
|
||||
yas/trigger-key-map))))
|
||||
))
|
||||
|
||||
(defvar yas/tables (make-hash-table)
|
||||
"A hash table of MAJOR-MODE symbols to `yas/table' objects.")
|
||||
@ -770,7 +766,7 @@ all defined direct keybindings to the command
|
||||
(define-minor-mode yas/minor-mode
|
||||
"Toggle YASnippet mode.
|
||||
|
||||
When YASnippet mode is enabled, the `tas/trigger-key' key expands
|
||||
When YASnippet mode is enabled, the `yas/trigger-key' key expands
|
||||
snippets of code depending on the mode.
|
||||
|
||||
With no argument, this command toggles the mode.
|
||||
@ -781,29 +777,33 @@ You can customize the key through `yas/trigger-key'.
|
||||
|
||||
Key bindings:
|
||||
\\{yas/minor-mode-map}"
|
||||
nil
|
||||
;; The indicator for the mode line.
|
||||
" yas"
|
||||
:group 'yasnippet
|
||||
:lighter " yas"
|
||||
:keymap yas/minor-mode-map
|
||||
(cond (yas/minor-mode
|
||||
;; Reload the trigger key
|
||||
;; Install the trigger key binding
|
||||
;;
|
||||
(yas/trigger-key-reload)
|
||||
(setq yas/trigger-key-overriding t)
|
||||
(aput 'minor-mode-overriding-map-alist 'yas/trigger-key-overriding yas/trigger-key-map)
|
||||
;; Install the direct keymaps in `emulation-mode-map-alists'
|
||||
;; (we use `add-hook' even though it's not technically a hook,
|
||||
;; but it works). Then define variables named after modes to
|
||||
;; index `yas/direct-keymaps'.
|
||||
;;
|
||||
;; Also install the post-command-hook.
|
||||
;;
|
||||
(add-hook 'emulation-mode-map-alists 'yas/direct-keymaps)
|
||||
;; Also install the post-command-hook and a run-once call to
|
||||
;; `yas/direct-keymaps-set-vars'.
|
||||
;;
|
||||
(add-hook 'post-command-hook 'yas/post-command-handler nil t)
|
||||
(add-hook 'yas/minor-mode-hook 'yas/direct-keymaps-set-vars-runonce 'append))
|
||||
(t
|
||||
;; Uninstall the direct keymaps and the post-command hook
|
||||
;;
|
||||
(remove-hook 'post-command-hook 'yas/post-command-handler t)
|
||||
(remove-hook 'emulation-mode-map-alists 'yas/direct-keymaps))))
|
||||
(remove-hook 'emulation-mode-map-alists 'yas/direct-keymaps)
|
||||
;; Uninstall the trigger key binding
|
||||
;;
|
||||
(setq yas/trigger-key-overriding nil))))
|
||||
|
||||
(defun yas/direct-keymaps-set-vars-runonce ()
|
||||
(yas/direct-keymaps-set-vars)
|
||||
@ -1673,12 +1673,6 @@ Below TOP-LEVEL-DIR., each directory is a mode name."
|
||||
(setq yas/tables (make-hash-table))
|
||||
(setq yas/menu-table (make-hash-table))
|
||||
|
||||
;; Init the `yas/minor-mode-map', taking care not to break the
|
||||
;; menu....
|
||||
;;
|
||||
(setf (cdr yas/minor-mode-map)
|
||||
(cdr (yas/init-minor-keymap)))
|
||||
|
||||
;; Reload the directories listed in `yas/snippet-dirs' or prompt
|
||||
;; the user to select one.
|
||||
;;
|
||||
|
Loading…
x
Reference in New Issue
Block a user