mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
* Working on the issues regarding customization of yas/trigger-key and
yas/root-directory. Still not quite fixed.
This commit is contained in:
parent
b1c079f1e4
commit
371f68e860
99
yasnippet.el
99
yasnippet.el
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
;; Authors: pluskid <pluskid@gmail.com>, joaotavora <joaotavora@gmail.com>
|
;; Authors: pluskid <pluskid@gmail.com>, joaotavora <joaotavora@gmail.com>
|
||||||
;; Version: 0.6.1
|
;; Version: 0.6.1
|
||||||
;; Package-version: 0.6.1b
|
;; Package-version: 0.6.1c
|
||||||
;; X-URL: http://code.google.com/p/yasnippet/
|
;; X-URL: http://code.google.com/p/yasnippet/
|
||||||
;; Keywords: convenience, emulation
|
;; Keywords: convenience, emulation
|
||||||
;; URL: http://code.google.com/p/yasnippet/
|
;; URL: http://code.google.com/p/yasnippet/
|
||||||
@ -154,18 +154,21 @@
|
|||||||
(defcustom yas/root-directory nil
|
(defcustom yas/root-directory nil
|
||||||
"Root directory that stores the snippets for each major mode.
|
"Root directory that stores the snippets for each major mode.
|
||||||
|
|
||||||
Can also be a list of strings, for multiple root directories. If
|
If you set this from your .emacs, can also be a list of strings,
|
||||||
you make this a list, the first element is always the
|
for multiple root directories. If you make this a list, the first
|
||||||
user-created snippets directory. Other directories are used for
|
element is always the user-created snippets directory. Other
|
||||||
bulk reloading of all snippets using `yas/reload-all'"
|
directories are used for bulk reloading of all snippets using
|
||||||
|
`yas/reload-all'"
|
||||||
|
|
||||||
:type '(string)
|
:type 'string
|
||||||
:group 'yasnippet
|
:group 'yasnippet
|
||||||
:require 'yasnippet
|
:require 'yasnippet
|
||||||
:set #'(lambda (symbol roots)
|
:set #'(lambda (symbol new)
|
||||||
(set-default symbol roots)
|
(let ((old (symbol-value symbol)))
|
||||||
(if (fboundp 'yas/reload-all)
|
(set-default symbol new)
|
||||||
(yas/reload-all))))
|
(unless (or (not (fboundp 'yas/reload-all))
|
||||||
|
(equal old new))
|
||||||
|
(yas/reload-all)))))
|
||||||
|
|
||||||
(defcustom yas/prompt-functions '(yas/x-prompt
|
(defcustom yas/prompt-functions '(yas/x-prompt
|
||||||
yas/dropdown-prompt
|
yas/dropdown-prompt
|
||||||
@ -233,8 +236,13 @@ Naturally this is only valid when `yas/indent-line' is `auto'"
|
|||||||
Value is a string that is converted to the internal Emacs key
|
Value is a string that is converted to the internal Emacs key
|
||||||
representation using `read-kbd-macro'."
|
representation using `read-kbd-macro'."
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'yasnippet)
|
:group 'yasnippet
|
||||||
|
:set #'(lambda (symbol key)
|
||||||
|
(let ((old (symbol-value symbol)))
|
||||||
|
(set-default symbol key)
|
||||||
|
(if (fboundp 'yas/trigger-key-reload)
|
||||||
|
(yas/trigger-key-reload old)))))
|
||||||
|
|
||||||
(defcustom yas/next-field-key "TAB"
|
(defcustom yas/next-field-key "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.
|
||||||
|
|
||||||
@ -647,18 +655,27 @@ Here's an example:
|
|||||||
:help "Display some information about YASsnippet"]))
|
:help "Display some information about YASsnippet"]))
|
||||||
;; Now for the stuff that has direct keybindings
|
;; Now for the stuff that has direct keybindings
|
||||||
;;
|
;;
|
||||||
(when (and yas/trigger-key
|
(yas/trigger-key-reload)
|
||||||
(stringp yas/trigger-key))
|
|
||||||
(define-key yas/minor-mode-map (read-kbd-macro yas/trigger-key) 'yas/expand))
|
|
||||||
(define-key yas/minor-mode-map "\C-c&\C-s" 'yas/insert-snippet)
|
(define-key yas/minor-mode-map "\C-c&\C-s" 'yas/insert-snippet)
|
||||||
(define-key yas/minor-mode-map "\C-c&\C-n" 'yas/new-snippet)
|
(define-key yas/minor-mode-map "\C-c&\C-n" 'yas/new-snippet)
|
||||||
(define-key yas/minor-mode-map "\C-c&\C-v" 'yas/visit-snippet-file)
|
(define-key yas/minor-mode-map "\C-c&\C-v" 'yas/visit-snippet-file)
|
||||||
(define-key yas/minor-mode-map "\C-c&\C-f" 'yas/find-snippets))
|
(define-key yas/minor-mode-map "\C-c&\C-f" 'yas/find-snippets))
|
||||||
|
|
||||||
;;;### eval this on require!
|
|
||||||
(progn
|
|
||||||
(yas/init-minor-keymap))
|
|
||||||
|
|
||||||
|
(defun yas/trigger-key-reload (&optional unbind-key)
|
||||||
|
"Rebind `yas/expand' to the new value of `yas/trigger-key'.
|
||||||
|
|
||||||
|
With optional UNBIND-KEY, try to unbind that key from
|
||||||
|
`yas/minor-mode-map'."
|
||||||
|
(when (and unbind-key
|
||||||
|
(stringp unbind-key)
|
||||||
|
(not (string= unbind-key "")))
|
||||||
|
(define-key yas/minor-mode-map (read-kbd-macro unbind-key) nil))
|
||||||
|
(when (and yas/trigger-key
|
||||||
|
(stringp yas/trigger-key)
|
||||||
|
(not (string= yas/trigger-key "")))
|
||||||
|
(define-key yas/minor-mode-map (read-kbd-macro yas/trigger-key) 'yas/expand)))
|
||||||
|
|
||||||
(define-minor-mode yas/minor-mode
|
(define-minor-mode yas/minor-mode
|
||||||
"Toggle YASnippet mode.
|
"Toggle YASnippet mode.
|
||||||
|
|
||||||
@ -678,14 +695,18 @@ Key bindings:
|
|||||||
" yas"
|
" yas"
|
||||||
:group 'yasnippet
|
:group 'yasnippet
|
||||||
(when yas/minor-mode
|
(when yas/minor-mode
|
||||||
;; when turning on theminor mode, re-read the `yas/trigger-key'
|
;; when turning on the minor mode.
|
||||||
;; if a `yas/minor-mode-map' is already built. Else, call
|
;;
|
||||||
;; `yas/init-minor-keymap' to build it
|
;; re-read the `yas/trigger-key' if a `yas/minor-mode-map' is
|
||||||
(if (and (cdr yas/minor-mode-map)
|
;; already built. Else, call `yas/init-minor-keymap' to build it
|
||||||
yas/trigger-key
|
(unless (and (cdr yas/minor-mode-map)
|
||||||
(stringp yas/trigger-key))
|
(yas/trigger-key-reload))
|
||||||
(define-key yas/minor-mode-map (read-kbd-macro yas/trigger-key) 'yas/expand)
|
(yas/init-minor-keymap))
|
||||||
(yas/init-minor-keymap))))
|
;; load all snippets definitions unless we still don't have a
|
||||||
|
;; root-directory or some snippets have already been loaded.
|
||||||
|
(unless (or (null yas/root-directory)
|
||||||
|
(> (hash-table-count yas/snippet-tables) 0))
|
||||||
|
(yas/reload-all))))
|
||||||
|
|
||||||
(defvar yas/dont-activate nil
|
(defvar yas/dont-activate nil
|
||||||
"If non-nil don't let `yas/minor-mode-on' active yas for this buffer.
|
"If non-nil don't let `yas/minor-mode-on' active yas for this buffer.
|
||||||
@ -749,10 +770,6 @@ behaviour.")
|
|||||||
(list "Load this snippet" 'yas/load-snippet-buffer "\C-c\C-c")
|
(list "Load this snippet" 'yas/load-snippet-buffer "\C-c\C-c")
|
||||||
(list "Try out this snippet" 'yas/tryout-snippet "\C-c\C-t"))))))
|
(list "Try out this snippet" 'yas/tryout-snippet "\C-c\C-t"))))))
|
||||||
|
|
||||||
;;;### eval this on require!
|
|
||||||
(progn
|
|
||||||
(yas/init-major-keymap))
|
|
||||||
|
|
||||||
(define-derived-mode snippet-mode text-mode "Snippet"
|
(define-derived-mode snippet-mode text-mode "Snippet"
|
||||||
"A mode for editing yasnippets"
|
"A mode for editing yasnippets"
|
||||||
(set-syntax-table (standard-syntax-table))
|
(set-syntax-table (standard-syntax-table))
|
||||||
@ -1407,11 +1424,6 @@ content of the file is the template."
|
|||||||
|
|
||||||
(message "done.")))
|
(message "done.")))
|
||||||
|
|
||||||
;;;### eval this on require!
|
|
||||||
(progn
|
|
||||||
(when yas/root-directory
|
|
||||||
(yas/reload-all)))
|
|
||||||
|
|
||||||
(defun yas/quote-string (string)
|
(defun yas/quote-string (string)
|
||||||
"Escape and quote STRING.
|
"Escape and quote STRING.
|
||||||
foo\"bar\\! -> \"foo\\\"bar\\\\!\""
|
foo\"bar\\! -> \"foo\\\"bar\\\\!\""
|
||||||
@ -3408,6 +3420,23 @@ When multiple expressions are found, only the last one counts."
|
|||||||
;; When not in an undo, check if we must commit the snippet (use exited it).
|
;; When not in an undo, check if we must commit the snippet (use exited it).
|
||||||
(yas/check-commit-snippet))))
|
(yas/check-commit-snippet))))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Evaluated on load or require
|
||||||
|
;;
|
||||||
|
;; ;;;### eval this on require!
|
||||||
|
;; (progn
|
||||||
|
;; (yas/init-minor-keymap))
|
||||||
|
|
||||||
|
;; ;;;### eval this on require!
|
||||||
|
;; (progn
|
||||||
|
;; (yas/init-major-keymap))
|
||||||
|
|
||||||
|
;; ;;;### eval this on require!
|
||||||
|
;; (progn
|
||||||
|
;; (when yas/root-directory
|
||||||
|
;; (yas/reload-all)))
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Debug functions. Use (or change) at will whenever needed.
|
;; Debug functions. Use (or change) at will whenever needed.
|
||||||
;;
|
;;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user