mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Closes #271: 2nd try, remove unescaping of backquote replacements
* Fixes previous fix (big blunder, expansion unusable) * Added more tests * Fixed previously broken tests.
This commit is contained in:
parent
12c21c6c62
commit
6aff6a0894
@ -153,7 +153,7 @@
|
||||
(yas-expand-snippet "Look ma! `(yas/selected-text)`")
|
||||
(should (string= (yas--buffer-contents) "Look ma! He\"\)\\o world!")))
|
||||
(yas-exit-all-snippets)
|
||||
(erase-buffer))))
|
||||
(erase-buffer)))
|
||||
|
||||
(ert-deftest be-careful-when-escaping-in-yas-selected-text-2 ()
|
||||
(with-temp-buffer
|
||||
@ -176,15 +176,33 @@
|
||||
(ert-deftest primary-field-transformation ()
|
||||
(with-temp-buffer
|
||||
(yas-minor-mode 1)
|
||||
;; The rules here is: to output a literal `"' you need to escape
|
||||
;; it with one backslash. You don't need to escape them in
|
||||
;; embedded elisp.
|
||||
(let ((snippet "${1:$$(upcase yas/text)}${1:$(concat \"bar\" yas/text)}"))
|
||||
(yas-expand-snippet snippet)
|
||||
(should (string= (yas--buffer-contents) "bar"))
|
||||
(ert-simulate-command `(yas-mock-insert "foo"))
|
||||
(should (string= (yas--buffer-contents) "FOObarFOO")))))
|
||||
|
||||
(ert-deftest example-for-issue-271 ()
|
||||
(with-temp-buffer
|
||||
(yas-minor-mode 1)
|
||||
(let ((yas-selected-text "aaa")
|
||||
(snippet "if ${1:condition}\n`yas/selected-text`\nelse\n$3\nend"))
|
||||
(yas-expand-snippet snippet)
|
||||
(yas-next-field)
|
||||
(ert-simulate-command `(yas-mock-insert "bbb"))
|
||||
(should (string= (yas--buffer-contents) "if condition\naaa\nelse\nbbb\nend")))))
|
||||
|
||||
(ert-deftest another-example-for-issue-271 ()
|
||||
(with-temp-buffer
|
||||
(yas-minor-mode 1)
|
||||
(let ((snippet "\\${${1:1}:`yas/selected-text`}"))
|
||||
(insert "aaabbbccc")
|
||||
(set-mark 4)
|
||||
(goto-char 7)
|
||||
(yas-expand-snippet snippet)
|
||||
(ert-simulate-command `(yas-mock-insert "bbb"))
|
||||
(should (string= (yas--buffer-contents) "if condition\naaa\nelse\nbbb\nend")))))
|
||||
|
||||
|
||||
;;; Misc tests
|
||||
;;;
|
||||
|
14
yasnippet.el
14
yasnippet.el
@ -3451,13 +3451,10 @@ considered when expanding the snippet."
|
||||
(run-hooks 'yas-before-expand-snippet-hook)
|
||||
|
||||
;;
|
||||
(let ((yas-selected-text (or yas-selected-text
|
||||
(let* ((yas-selected-text (or yas-selected-text
|
||||
(and (region-active-p)
|
||||
(buffer-substring-no-properties (region-beginning)
|
||||
(region-end)))))
|
||||
(to-delete (and start
|
||||
end
|
||||
(buffer-substring-no-properties start end)))
|
||||
(start (or start
|
||||
(and (region-active-p)
|
||||
(region-beginning))
|
||||
@ -3466,6 +3463,9 @@ considered when expanding the snippet."
|
||||
(and (region-active-p)
|
||||
(region-end))
|
||||
(point)))
|
||||
(to-delete (and start
|
||||
end
|
||||
(buffer-substring-no-properties start end)))
|
||||
snippet)
|
||||
(goto-char start)
|
||||
(setq yas--indent-original-column (current-column))
|
||||
@ -3762,9 +3762,9 @@ Meant to be called in a narrowed buffer, does various passes"
|
||||
;; Reset the yas--dollar-regions
|
||||
;;
|
||||
(setq yas--dollar-regions nil)
|
||||
;; protect escaped quote, backquotes and backslashes
|
||||
;; protect escaped characters
|
||||
;;
|
||||
(yas--protect-escapes nil `(?\\ ?` ?'))
|
||||
(yas--protect-escapes)
|
||||
;; replace all backquoted expressions
|
||||
;;
|
||||
(goto-char parse-start)
|
||||
@ -3927,7 +3927,7 @@ with their evaluated value into `yas--backquote-markers-and-strings'"
|
||||
(while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
|
||||
(let ((current-string (match-string 1)) transformed)
|
||||
(delete-region (match-beginning 0) (match-end 0))
|
||||
(setq transformed (yas--eval-lisp (yas--read-lisp (yas--restore-escapes current-string))))
|
||||
(setq transformed (yas--eval-lisp (yas--read-lisp current-string)))
|
||||
(goto-char (match-beginning 0))
|
||||
(when transformed
|
||||
(let ((marker (make-marker)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user