mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Closes #271: 4th try, with backquote, need protection before collection
* Add one more test, probably will need even more.
This commit is contained in:
parent
197104b450
commit
c967f74847
@ -119,6 +119,12 @@
|
|||||||
(yas-expand-snippet "bla\\ble")
|
(yas-expand-snippet "bla\\ble")
|
||||||
(should (string= (yas--buffer-contents) "bla\\ble"))))
|
(should (string= (yas--buffer-contents) "bla\\ble"))))
|
||||||
|
|
||||||
|
(ert-deftest escape-backquotes ()
|
||||||
|
(with-temp-buffer
|
||||||
|
(yas-minor-mode 1)
|
||||||
|
(yas-expand-snippet "bla`(upcase \"foo\\`bar\")`ble")
|
||||||
|
(should (string= (yas--buffer-contents) "blaFOO`BARble"))))
|
||||||
|
|
||||||
(ert-deftest escape-some-elisp-with-strings ()
|
(ert-deftest escape-some-elisp-with-strings ()
|
||||||
"elisp with strings and unbalance parens inside it"
|
"elisp with strings and unbalance parens inside it"
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
@ -208,7 +214,9 @@
|
|||||||
(yas-minor-mode 1)
|
(yas-minor-mode 1)
|
||||||
;; the rule here is: To use regexps in embedded `(elisp)` expressions, write
|
;; the rule here is: To use regexps in embedded `(elisp)` expressions, write
|
||||||
;; it like you would normal elisp, i.e. no need to escape the backslashes.
|
;; it like you would normal elisp, i.e. no need to escape the backslashes.
|
||||||
(let ((snippet "`(if (string-match \"foo\\\\(ba+r\\\\)foo\" \"foobaaaaaaaaaarfoo\") \"ok\" \"fail\")`"))
|
(let ((snippet "`(if (string-match \"foo\\\\(ba+r\\\\)foo\" \"foobaaaaaaaaaarfoo\")
|
||||||
|
\"ok\"
|
||||||
|
\"fail\")`"))
|
||||||
(yas-expand-snippet snippet))
|
(yas-expand-snippet snippet))
|
||||||
(should (string= (yas--buffer-contents) "ok"))))
|
(should (string= (yas--buffer-contents) "ok"))))
|
||||||
|
|
||||||
@ -216,8 +224,10 @@
|
|||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(yas-minor-mode 1)
|
(yas-minor-mode 1)
|
||||||
;; the rule here is: To use regexps in embedded `(elisp)` expressions,
|
;; the rule here is: To use regexps in embedded `(elisp)` expressions,
|
||||||
;; escape backslashes once. i.e. to use \\( \\) constructs, write \\\\( \\\\).
|
;; escape backslashes once, i.e. to use \\( \\) constructs, write \\\\( \\\\).
|
||||||
(let ((snippet "$1${1:$(if (string-match \"foo\\\\\\\\(ba+r\\\\\\\\)baz\" yas/text) \"ok\" \"fail\")}"))
|
(let ((snippet "$1${1:$(if (string-match \"foo\\\\\\\\(ba+r\\\\\\\\)baz\" yas/text)
|
||||||
|
\"ok\"
|
||||||
|
\"fail\")}"))
|
||||||
(yas-expand-snippet snippet)
|
(yas-expand-snippet snippet)
|
||||||
(should (string= (yas--buffer-contents) "fail"))
|
(should (string= (yas--buffer-contents) "fail"))
|
||||||
(ert-simulate-command `(yas-mock-insert "foobaaar"))
|
(ert-simulate-command `(yas-mock-insert "foobaaar"))
|
||||||
|
@ -3762,6 +3762,9 @@ Meant to be called in a narrowed buffer, does various passes"
|
|||||||
;; Reset the yas--dollar-regions
|
;; Reset the yas--dollar-regions
|
||||||
;;
|
;;
|
||||||
(setq yas--dollar-regions nil)
|
(setq yas--dollar-regions nil)
|
||||||
|
;; protect just the backquotes
|
||||||
|
;;
|
||||||
|
(yas--protect-escapes nil '(?`))
|
||||||
;; replace all backquoted expressions
|
;; replace all backquoted expressions
|
||||||
;;
|
;;
|
||||||
(goto-char parse-start)
|
(goto-char parse-start)
|
||||||
@ -3927,7 +3930,7 @@ with their evaluated value into `yas--backquote-markers-and-strings'"
|
|||||||
(while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
|
(while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
|
||||||
(let ((current-string (match-string-no-properties 1)) transformed)
|
(let ((current-string (match-string-no-properties 1)) transformed)
|
||||||
(delete-region (match-beginning 0) (match-end 0))
|
(delete-region (match-beginning 0) (match-end 0))
|
||||||
(setq transformed (yas--eval-lisp (yas--read-lisp current-string)))
|
(setq transformed (yas--eval-lisp (yas--read-lisp (yas--restore-escapes current-string '(?`)))))
|
||||||
(goto-char (match-beginning 0))
|
(goto-char (match-beginning 0))
|
||||||
(when transformed
|
(when transformed
|
||||||
(let ((marker (make-marker)))
|
(let ((marker (make-marker)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user