mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
use a hook to ensure yas/minor-mode's keybinding always takes priority.
This commit is contained in:
parent
b9ad7f282a
commit
aedf0e230b
22
yasnippet.el
22
yasnippet.el
@ -210,7 +210,11 @@ Here's an example:
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(defvar yas/minor-mode-map (make-sparse-keymap)
|
(defvar yas/minor-mode-map (make-sparse-keymap)
|
||||||
"The keymap of yas/minor-mode")
|
"The keymap of yas/minor-mode")
|
||||||
|
(defvar yas/minor-mode-on-hook nil
|
||||||
|
"Hook to call when yas/minor-mode is on.")
|
||||||
|
(defvar yas/minor-mode-off-hook nil
|
||||||
|
"Hook to call when yas/minor-mode is off.")
|
||||||
|
(define-key yas/minor-mode-map yas/trigger-key 'yas/expand)
|
||||||
(define-minor-mode yas/minor-mode
|
(define-minor-mode yas/minor-mode
|
||||||
"Toggle YASnippet mode.
|
"Toggle YASnippet mode.
|
||||||
With no argument, this command toggles the mode.
|
With no argument, this command toggles the mode.
|
||||||
@ -225,8 +229,8 @@ You can customize the key through `yas/trigger-key'."
|
|||||||
nil
|
nil
|
||||||
;; The indicator for the mode line.
|
;; The indicator for the mode line.
|
||||||
" yas"
|
" yas"
|
||||||
:group 'editing
|
:group 'editing)
|
||||||
(define-key yas/minor-mode-map yas/trigger-key 'yas/expand))
|
|
||||||
(defun yas/minor-mode-on ()
|
(defun yas/minor-mode-on ()
|
||||||
"Turn on YASnippet minor mode."
|
"Turn on YASnippet minor mode."
|
||||||
(interactive)
|
(interactive)
|
||||||
@ -372,6 +376,16 @@ fetch from parent if any."
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Internal functions
|
;; Internal functions
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
(defun yas/ensure-minor-mode-priority ()
|
||||||
|
"Ensure that the key binding of yas/minor-mode takes priority."
|
||||||
|
(unless (eq 'yas/minor-mode
|
||||||
|
(caar minor-mode-map-alist))
|
||||||
|
(setq minor-mode-map-alist
|
||||||
|
(cons
|
||||||
|
(cons 'yas/minor-mode yas/minor-mode-map)
|
||||||
|
(assq-delete-all 'yas/minor-mode
|
||||||
|
minor-mode-map-alist)))))
|
||||||
|
|
||||||
(defun yas/real-mode? (mode)
|
(defun yas/real-mode? (mode)
|
||||||
"Try to find out if MODE is a real mode. The MODE bound to
|
"Try to find out if MODE is a real mode. The MODE bound to
|
||||||
a function (like `c-mode') is considered real mode. Other well
|
a function (like `c-mode') is considered real mode. Other well
|
||||||
@ -1000,6 +1014,8 @@ content of the file is the template."
|
|||||||
(dolist (hook yas/extra-mode-hooks)
|
(dolist (hook yas/extra-mode-hooks)
|
||||||
(add-hook hook
|
(add-hook hook
|
||||||
'yas/minor-mode-on))
|
'yas/minor-mode-on))
|
||||||
|
(add-hook 'yas/minor-mode-on-hook
|
||||||
|
'yas/ensure-minor-mode-priority)
|
||||||
(when yas/use-menu
|
(when yas/use-menu
|
||||||
(define-key-after
|
(define-key-after
|
||||||
(lookup-key global-map [menu-bar])
|
(lookup-key global-map [menu-bar])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user