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.
This commit is contained in:
Noam Postavsky 2015-12-09 23:15:39 -05:00
parent eca2f995c1
commit ccc9adc3c4

View File

@ -346,11 +346,14 @@ Any other non-nil value, every submenu is listed."
:group 'yasnippet) :group 'yasnippet)
(defcustom yas-wrap-around-region nil (defcustom yas-wrap-around-region nil
"If non-nil, snippet expansion wraps around selected region. "What to insert for snippet's $0 field.
The wrapping occurs just before the snippet's exit marker. This If set to a character, insert contents of corresponding register.
can be overridden on a per-snippet basis." If non-nil insert region contents."
:type 'boolean :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) :group 'yasnippet)
(defcustom yas-good-grace t (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)))) (yas--make-exit (yas--make-marker (match-end 0))))
(save-excursion (save-excursion
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(when yas-wrap-around-region (when (eq yas-wrap-around-region 'cua)
(cond (yas-selected-text (setq yas-wrap-around-region ?0))
(insert yas-selected-text)) (cond ((and yas-wrap-around-region yas-selected-text)
((and (eq yas-wrap-around-region 'cua) (insert yas-selected-text))
cua-mode ((and (characterp yas-wrap-around-region)
(get-register ?0)) (get-register yas-wrap-around-region))
(insert (prog1 (get-register ?0) (insert (prog1 (get-register yas-wrap-around-region)
(set-register ?0 nil)))))) (set-register yas-wrap-around-region nil)))))
(push (cons (point) (yas--exit-marker (yas--snippet-exit snippet))) (push (cons (point) (yas--exit-marker (yas--snippet-exit snippet)))
yas--dollar-regions))) yas--dollar-regions)))
(t (t