mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
much better `yas/trigger-key' still needs some cleanup...
This commit is contained in:
parent
1cc002ee32
commit
f80e7f4612
56
yasnippet.el
56
yasnippet.el
@ -244,6 +244,16 @@ Naturally this is only valid when `yas/indent-line' is `auto'"
|
|||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'yasnippet)
|
:group 'yasnippet)
|
||||||
|
|
||||||
|
(defvar yas/trigger-key-map (make-sparse-keymap)
|
||||||
|
"Keymap used only for adding the trigger key to `minor-mode-overriding-map-alist'")
|
||||||
|
|
||||||
|
(defun yas/read-kbd-macro (key)
|
||||||
|
(and key
|
||||||
|
(not (string= key ""))
|
||||||
|
(if (string= key "TAB")
|
||||||
|
[tab]
|
||||||
|
(read-kbd-macro key))))
|
||||||
|
|
||||||
(defcustom yas/trigger-key "TAB"
|
(defcustom yas/trigger-key "TAB"
|
||||||
"The key bound to `yas/expand' when function `yas/minor-mode' is active.
|
"The key bound to `yas/expand' when function `yas/minor-mode' is active.
|
||||||
|
|
||||||
@ -252,13 +262,11 @@ representation using `read-kbd-macro'."
|
|||||||
:type 'string
|
:type 'string
|
||||||
:group 'yasnippet
|
:group 'yasnippet
|
||||||
:set #'(lambda (symbol key)
|
:set #'(lambda (symbol key)
|
||||||
(let ((old (and (boundp symbol)
|
(set-default symbol key)
|
||||||
(symbol-value symbol))))
|
(setcdr yas/trigger-key-map nil)
|
||||||
(set-default symbol key)
|
(let ((kbd (yas/read-kbd-macro key)))
|
||||||
;; On very first loading of this defcustom,
|
(when kbd
|
||||||
;; `yas/trigger-key' is *not* loaded.
|
(define-key yas/trigger-key-map kbd 'yas/expand)))))
|
||||||
(if (fboundp 'yas/trigger-key-reload)
|
|
||||||
(yas/trigger-key-reload old)))))
|
|
||||||
|
|
||||||
(defcustom yas/next-field-key '("TAB" "<tab>")
|
(defcustom yas/next-field-key '("TAB" "<tab>")
|
||||||
"The key to navigate to next field when a snippet is active.
|
"The key to navigate to next field when a snippet is active.
|
||||||
@ -706,24 +714,16 @@ snippet itself contains a condition that returns the symbol
|
|||||||
(defvar yas/minor-mode-map (yas/init-minor-keymap)
|
(defvar yas/minor-mode-map (yas/init-minor-keymap)
|
||||||
"The keymap used when `yas/minor-mode' is active.")
|
"The keymap used when `yas/minor-mode' is active.")
|
||||||
|
|
||||||
(defvar yas/trigger-key-map (make-sparse-keymap)
|
(defun yas/trigger-key-reload (&optional override)
|
||||||
"Keymap used only for adding the trigger key to `minor-mode-overriding-map-alist'")
|
"Rebind `yas/expand' to the new value of `yas/trigger-key'."
|
||||||
|
(let ((override (yas/read-kbd-macro override)))
|
||||||
(defun yas/trigger-key-reload (&optional unbind-key)
|
(aput 'minor-mode-overriding-map-alist
|
||||||
"Rebind `yas/expand' to the new value of `yas/trigger-key'.
|
'yas/minor-mode
|
||||||
|
(if override
|
||||||
With optional UNBIND-KEY, try to unbind that key from
|
(let ((map (make-sparse-keymap)))
|
||||||
`yas/minor-mode-map'."
|
(define-key map override 'yas/expand)
|
||||||
(pushnew (cons 'yas/minor-mode yas/trigger-key-map)
|
map)
|
||||||
minor-mode-overriding-map-alist)
|
yas/trigger-key-map))))
|
||||||
(when (and unbind-key
|
|
||||||
(stringp unbind-key)
|
|
||||||
(not (string= unbind-key "")))
|
|
||||||
(define-key yas/trigger-key-map (read-kbd-macro unbind-key) nil))
|
|
||||||
(when (and yas/trigger-key
|
|
||||||
(stringp yas/trigger-key)
|
|
||||||
(not (string= yas/trigger-key "")))
|
|
||||||
(define-key yas/trigger-key-map (read-kbd-macro yas/trigger-key) 'yas/expand)))
|
|
||||||
|
|
||||||
(defvar yas/tables (make-hash-table)
|
(defvar yas/tables (make-hash-table)
|
||||||
"A hash table of MAJOR-MODE symbols to `yas/table' objects.")
|
"A hash table of MAJOR-MODE symbols to `yas/table' objects.")
|
||||||
@ -2102,10 +2102,8 @@ Common gateway for `yas/expand-from-trigger-key' and
|
|||||||
(let* ((yas/minor-mode nil)
|
(let* ((yas/minor-mode nil)
|
||||||
(yas/direct-keymaps nil)
|
(yas/direct-keymaps nil)
|
||||||
(keys-1 (this-command-keys-vector))
|
(keys-1 (this-command-keys-vector))
|
||||||
(keys-2 (and yas/trigger-key
|
(keys-2 (and from-trigger-key-p
|
||||||
from-trigger-key-p
|
(yas/read-kbd-macro yas/trigger-key)))
|
||||||
(stringp yas/trigger-key)
|
|
||||||
(read-kbd-macro yas/trigger-key)))
|
|
||||||
(command-1 (and keys-1 (key-binding keys-1)))
|
(command-1 (and keys-1 (key-binding keys-1)))
|
||||||
(command-2 (and keys-2 (key-binding keys-2)))
|
(command-2 (and keys-2 (key-binding keys-2)))
|
||||||
;; An (ugly) safety: prevents infinite recursion of
|
;; An (ugly) safety: prevents infinite recursion of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user