mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 05:03:04 +00:00
Avoid shadowing the tab
=> TAB remapping
* yasnippet.el (yas-keymap): Don't bind `tab`. (yas--read-keybinding): Prefer the more precise \` and \' regexps. (yas--parse-template): Use `pcase`.
This commit is contained in:
parent
d7a79d4a96
commit
25f5d8808a
57
yasnippet.el
57
yasnippet.el
@ -421,7 +421,12 @@ The condition will respect the value of `yas-keymap-disable-hook'."
|
|||||||
|
|
||||||
(defvar yas-keymap
|
(defvar yas-keymap
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(define-key map [(tab)] (yas-filtered-definition 'yas-next-field-or-maybe-expand))
|
;; Modes should always bind to TAB instead of `tab', so as not to override
|
||||||
|
;; bindings that should take higher precedence but which bind to `TAB`
|
||||||
|
;; instead (relying on `function-key-map` to remap `tab` to TAB).
|
||||||
|
;; If this causes problem because of another package that binds to `tab`,
|
||||||
|
;; complain to that other package!
|
||||||
|
;; (define-key map [tab] (yas-filtered-definition 'yas-next-field-or-maybe-expand))
|
||||||
(define-key map (kbd "TAB") (yas-filtered-definition 'yas-next-field-or-maybe-expand))
|
(define-key map (kbd "TAB") (yas-filtered-definition 'yas-next-field-or-maybe-expand))
|
||||||
(define-key map [(shift tab)] (yas-filtered-definition 'yas-prev-field))
|
(define-key map [(shift tab)] (yas-filtered-definition 'yas-prev-field))
|
||||||
(define-key map [backtab] (yas-filtered-definition 'yas-prev-field))
|
(define-key map [backtab] (yas-filtered-definition 'yas-prev-field))
|
||||||
@ -651,7 +656,7 @@ expanded.")
|
|||||||
;; instead (relying on `function-key-map` to remap `tab` to TAB).
|
;; instead (relying on `function-key-map` to remap `tab` to TAB).
|
||||||
;; If this causes problem because of another package that binds to `tab`,
|
;; If this causes problem because of another package that binds to `tab`,
|
||||||
;; complain to that other package!
|
;; complain to that other package!
|
||||||
;;(define-key map [(tab)] yas-maybe-expand)
|
;;(define-key map [tab] yas-maybe-expand)
|
||||||
(define-key map (kbd "TAB") yas-maybe-expand)
|
(define-key map (kbd "TAB") yas-maybe-expand)
|
||||||
(define-key map "\C-c&\C-s" #'yas-insert-snippet)
|
(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-n" #'yas-new-snippet)
|
||||||
@ -1510,7 +1515,7 @@ return an expression that when evaluated will issue an error."
|
|||||||
(when (and keybinding
|
(when (and keybinding
|
||||||
(not (string-match "keybinding" keybinding)))
|
(not (string-match "keybinding" keybinding)))
|
||||||
(condition-case err
|
(condition-case err
|
||||||
(let ((res (or (and (string-match "^\\[.*\\]$" keybinding)
|
(let ((res (or (and (string-match "\\`\\[.*\\]\\'" keybinding)
|
||||||
(read keybinding))
|
(read keybinding))
|
||||||
(read-kbd-macro keybinding 'need-vector))))
|
(read-kbd-macro keybinding 'need-vector))))
|
||||||
res)
|
res)
|
||||||
@ -1594,7 +1599,6 @@ Here's a list of currently recognized directives:
|
|||||||
(file-name-nondirectory file)))
|
(file-name-nondirectory file)))
|
||||||
(key nil)
|
(key nil)
|
||||||
template
|
template
|
||||||
bound
|
|
||||||
condition
|
condition
|
||||||
(group (and file
|
(group (and file
|
||||||
(yas--calculate-group file)))
|
(yas--calculate-group file)))
|
||||||
@ -1602,31 +1606,26 @@ Here's a list of currently recognized directives:
|
|||||||
binding
|
binding
|
||||||
uuid)
|
uuid)
|
||||||
(if (re-search-forward "^# --\\s-*\n" nil t)
|
(if (re-search-forward "^# --\\s-*\n" nil t)
|
||||||
(progn (setq template
|
(let ((bound (point)))
|
||||||
(buffer-substring-no-properties (point)
|
(setq template
|
||||||
(point-max)))
|
(buffer-substring-no-properties (point)
|
||||||
(setq bound (point))
|
(point-max)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (re-search-forward "^# *\\([^ ]+?\\) *: *\\(.*?\\)[[:space:]]*$" bound t)
|
(while (re-search-forward
|
||||||
(when (string= "uuid" (match-string-no-properties 1))
|
"^# *\\([^ ]+?\\) *: *\\(.*?\\)[[:space:]]*$" bound t)
|
||||||
(setq uuid (match-string-no-properties 2)))
|
(let ((val (match-string-no-properties 2)))
|
||||||
(when (string= "type" (match-string-no-properties 1))
|
(pcase (match-string-no-properties 1)
|
||||||
(setq type (if (string= "command" (match-string-no-properties 2))
|
("uuid" (setq uuid val))
|
||||||
'command
|
("type" (setq type (intern val)))
|
||||||
'snippet)))
|
("key" (setq key val))
|
||||||
(when (string= "key" (match-string-no-properties 1))
|
("name" (setq name val))
|
||||||
(setq key (match-string-no-properties 2)))
|
("condition" (setq condition (yas--read-lisp val)))
|
||||||
(when (string= "name" (match-string-no-properties 1))
|
("group" (setq group val))
|
||||||
(setq name (match-string-no-properties 2)))
|
("expand-env"
|
||||||
(when (string= "condition" (match-string-no-properties 1))
|
(setq expand-env (yas--read-lisp val 'nil-on-error)))
|
||||||
(setq condition (yas--read-lisp (match-string-no-properties 2))))
|
("binding" (setq binding val))
|
||||||
(when (string= "group" (match-string-no-properties 1))
|
("contributor" nil) ;Documented in `snippet-development.org'.
|
||||||
(setq group (match-string-no-properties 2)))
|
(dir (message "Ignoring unknown directive: %s" dir))))))
|
||||||
(when (string= "expand-env" (match-string-no-properties 1))
|
|
||||||
(setq expand-env (yas--read-lisp (match-string-no-properties 2)
|
|
||||||
'nil-on-error)))
|
|
||||||
(when (string= "binding" (match-string-no-properties 1))
|
|
||||||
(setq binding (match-string-no-properties 2)))))
|
|
||||||
(setq template
|
(setq template
|
||||||
(buffer-substring-no-properties (point-min) (point-max))))
|
(buffer-substring-no-properties (point-min) (point-max))))
|
||||||
(unless (or key binding)
|
(unless (or key binding)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user