branch: master commit ccc9adc3c41097dc848911141d76a6bc5bd1a7fc Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
Add register option for yas-wrap-around-region Replace `cua' setting with more general behaviour that can use any given register. A `cua' setting is converted to ?0 for backwards compatibility. * yasnippet.el (yas--simple-mirror-parse-create): Use contents of any register depending on `yas-wrap-around-region' value. (yas-wrap-around-region): Update docstring. --- yasnippet.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/yasnippet.el b/yasnippet.el index 366c616..47618f9 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -346,11 +346,14 @@ Any other non-nil value, every submenu is listed." :group 'yasnippet) (defcustom yas-wrap-around-region nil - "If non-nil, snippet expansion wraps around selected region. - -The wrapping occurs just before the snippet's exit marker. This -can be overridden on a per-snippet basis." - :type 'boolean + "What to insert for snippet's $0 field. + +If set to a character, insert contents of corresponding register. +If non-nil insert region contents." + :type '(choice (character :tag "Insert from register") + (const t :tag "Insert region contents") + (const nil :tag "Don't insert anything") + (const cua)) ; backwards compat :group 'yasnippet) (defcustom yas-good-grace t @@ -4127,14 +4130,14 @@ When multiple expressions are found, only the last one counts." (yas--make-exit (yas--make-marker (match-end 0)))) (save-excursion (goto-char (match-beginning 0)) - (when yas-wrap-around-region - (cond (yas-selected-text - (insert yas-selected-text)) - ((and (eq yas-wrap-around-region 'cua) - cua-mode - (get-register ?0)) - (insert (prog1 (get-register ?0) - (set-register ?0 nil)))))) + (when (eq yas-wrap-around-region 'cua) + (setq yas-wrap-around-region ?0)) + (cond ((and yas-wrap-around-region yas-selected-text) + (insert yas-selected-text)) + ((and (characterp yas-wrap-around-region) + (get-register yas-wrap-around-region)) + (insert (prog1 (get-register yas-wrap-around-region) + (set-register yas-wrap-around-region nil))))) (push (cons (point) (yas--exit-marker (yas--snippet-exit snippet))) yas--dollar-regions))) (t