mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
* Added `yas/get-template-by-uid'
This commit is contained in:
parent
f55c2dfc46
commit
3c90c1b279
25
yasnippet.el
25
yasnippet.el
@ -944,6 +944,12 @@ Has the following fields:
|
|||||||
(parents nil)
|
(parents nil)
|
||||||
(direct-keymap (make-sparse-keymap)))
|
(direct-keymap (make-sparse-keymap)))
|
||||||
|
|
||||||
|
(defun yas/get-template-by-uid (mode uid)
|
||||||
|
"Find the snippet template in MODE by its UID."
|
||||||
|
(let* ((table (gethash mode yas/tables mode)))
|
||||||
|
(when table
|
||||||
|
(gethash uid (yas/table-uidhash table)))))
|
||||||
|
|
||||||
;; Apropos storing/updating, this works with two steps:
|
;; Apropos storing/updating, this works with two steps:
|
||||||
;;
|
;;
|
||||||
;; 1. `yas/remove-template-by-uid' to remove any existing mappings by
|
;; 1. `yas/remove-template-by-uid' to remove any existing mappings by
|
||||||
@ -3262,9 +3268,12 @@ The error should be ignored in `debug-ignored-errors'"
|
|||||||
;; they should account for all situations...
|
;; they should account for all situations...
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defun yas/expand-snippet (template &optional start end expand-env)
|
(defun yas/expand-snippet (content &optional start end expand-env)
|
||||||
"Expand snippet at current point. Text between START and END
|
"Expand snippet CONTENT at current point.
|
||||||
will be deleted before inserting template."
|
|
||||||
|
Text between START and END will be deleted before inserting
|
||||||
|
template. EXPAND-ENV is are let-style variable to value bindings
|
||||||
|
considered when expanding the snippet."
|
||||||
(run-hooks 'yas/before-expand-snippet-hook)
|
(run-hooks 'yas/before-expand-snippet-hook)
|
||||||
|
|
||||||
;; If a region is active, set `yas/selected-text'
|
;; If a region is active, set `yas/selected-text'
|
||||||
@ -3291,14 +3300,14 @@ will be deleted before inserting template."
|
|||||||
(delete-region start end)
|
(delete-region start end)
|
||||||
(setq yas/deleted-text to-delete))
|
(setq yas/deleted-text to-delete))
|
||||||
|
|
||||||
(cond ((listp template)
|
(cond ((listp content)
|
||||||
;; x) This is a snippet-command
|
;; x) This is a snippet-command
|
||||||
;;
|
;;
|
||||||
(yas/eval-lisp-no-saves template))
|
(yas/eval-lisp-no-saves content))
|
||||||
(t
|
(t
|
||||||
;; x) This is a snippet-snippet :-)
|
;; x) This is a snippet-snippet :-)
|
||||||
;;
|
;;
|
||||||
;; Narrow the region down to the template, shoosh the
|
;; Narrow the region down to the content, shoosh the
|
||||||
;; `buffer-undo-list', and create the snippet, the new
|
;; `buffer-undo-list', and create the snippet, the new
|
||||||
;; snippet updates its mirrors once, so we are left with
|
;; snippet updates its mirrors once, so we are left with
|
||||||
;; some plain text. The undo action for deleting this
|
;; some plain text. The undo action for deleting this
|
||||||
@ -3318,9 +3327,9 @@ will be deleted before inserting template."
|
|||||||
(setq snippet
|
(setq snippet
|
||||||
(if expand-env
|
(if expand-env
|
||||||
(eval `(let ,expand-env
|
(eval `(let ,expand-env
|
||||||
(insert template)
|
(insert content)
|
||||||
(yas/snippet-create (point-min) (point-max))))
|
(yas/snippet-create (point-min) (point-max))))
|
||||||
(insert template)
|
(insert content)
|
||||||
(yas/snippet-create (point-min) (point-max))))))
|
(yas/snippet-create (point-min) (point-max))))))
|
||||||
|
|
||||||
;; stacked-expansion: This checks for stacked expansion, save the
|
;; stacked-expansion: This checks for stacked expansion, save the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user