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)`")
|
(yas-expand-snippet "Look ma! `(yas/selected-text)`")
|
||||||
(should (string= (yas--buffer-contents) "Look ma! He\"\)\\o world!")))
|
(should (string= (yas--buffer-contents) "Look ma! He\"\)\\o world!")))
|
||||||
(yas-exit-all-snippets)
|
(yas-exit-all-snippets)
|
||||||
(erase-buffer))))
|
(erase-buffer)))
|
||||||
|
|
||||||
(ert-deftest be-careful-when-escaping-in-yas-selected-text-2 ()
|
(ert-deftest be-careful-when-escaping-in-yas-selected-text-2 ()
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
@ -176,15 +176,33 @@
|
|||||||
(ert-deftest primary-field-transformation ()
|
(ert-deftest primary-field-transformation ()
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(yas-minor-mode 1)
|
(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)}"))
|
(let ((snippet "${1:$$(upcase yas/text)}${1:$(concat \"bar\" yas/text)}"))
|
||||||
(yas-expand-snippet snippet)
|
(yas-expand-snippet snippet)
|
||||||
(should (string= (yas--buffer-contents) "bar"))
|
(should (string= (yas--buffer-contents) "bar"))
|
||||||
(ert-simulate-command `(yas-mock-insert "foo"))
|
(ert-simulate-command `(yas-mock-insert "foo"))
|
||||||
(should (string= (yas--buffer-contents) "FOObarFOO")))))
|
(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
|
;;; Misc tests
|
||||||
;;;
|
;;;
|
||||||
|
38
yasnippet.el
38
yasnippet.el
@ -3451,22 +3451,22 @@ considered when expanding the snippet."
|
|||||||
(run-hooks 'yas-before-expand-snippet-hook)
|
(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)
|
(and (region-active-p)
|
||||||
(buffer-substring-no-properties (region-beginning)
|
(buffer-substring-no-properties (region-beginning)
|
||||||
(region-end)))))
|
(region-end)))))
|
||||||
(to-delete (and start
|
(start (or start
|
||||||
end
|
(and (region-active-p)
|
||||||
(buffer-substring-no-properties start end)))
|
(region-beginning))
|
||||||
(start (or start
|
(point)))
|
||||||
(and (region-active-p)
|
(end (or end
|
||||||
(region-beginning))
|
(and (region-active-p)
|
||||||
(point)))
|
(region-end))
|
||||||
(end (or end
|
(point)))
|
||||||
(and (region-active-p)
|
(to-delete (and start
|
||||||
(region-end))
|
end
|
||||||
(point)))
|
(buffer-substring-no-properties start end)))
|
||||||
snippet)
|
snippet)
|
||||||
(goto-char start)
|
(goto-char start)
|
||||||
(setq yas--indent-original-column (current-column))
|
(setq yas--indent-original-column (current-column))
|
||||||
;; Delete the region to delete, this *does* get undo-recorded.
|
;; Delete the region to delete, this *does* get undo-recorded.
|
||||||
@ -3762,9 +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 escaped quote, backquotes and backslashes
|
;; protect escaped characters
|
||||||
;;
|
;;
|
||||||
(yas--protect-escapes nil `(?\\ ?` ?'))
|
(yas--protect-escapes)
|
||||||
;; replace all backquoted expressions
|
;; replace all backquoted expressions
|
||||||
;;
|
;;
|
||||||
(goto-char parse-start)
|
(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)
|
(while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
|
||||||
(let ((current-string (match-string 1)) transformed)
|
(let ((current-string (match-string 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 (yas--restore-escapes current-string))))
|
(setq transformed (yas--eval-lisp (yas--read-lisp 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