Escape yas-selected-text for new snippet.

* yasnippet.el (yas-escape-text): New function.
(yas-new-snippet-default): Call it on yas-selected-text.

Close #709.
This commit is contained in:
rubikitch 2016-06-14 07:18:02 +09:00 committed by Noam Postavsky
parent 8ca8c7de4f
commit 8907fd1d42

View File

@ -207,7 +207,7 @@ created with `yas-new-snippet'. "
# name: $1 # name: $1
# key: ${2:${1:$(yas--key-from-desc yas-text)}} # key: ${2:${1:$(yas--key-from-desc yas-text)}}
# -- # --
$0`yas-selected-text`" $0`(yas-escape-text yas-selected-text)`"
"Default snippet to use when creating a new snippet. "Default snippet to use when creating a new snippet.
If nil, don't use any snippet." If nil, don't use any snippet."
:type 'string :type 'string
@ -1926,6 +1926,11 @@ foo\"bar\\! -> \"foo\\\"bar\\\\!\""
string string
t) t)
"\"")) "\""))
(defun yas-escape-text (text)
"Escape TEXT for snippet."
(replace-regexp-in-string "[\\$]" "\\\\\\&" text))
;;; Snippet compilation function ;;; Snippet compilation function