From c967f748478b4cf03055a9ca58b68d58851fd952 Mon Sep 17 00:00:00 2001 From: Joao Tavora Date: Fri, 3 Aug 2012 18:36:29 +0100 Subject: [PATCH] Closes #271: 4th try, with backquote, need protection before collection * Add one more test, probably will need even more. --- yasnippet-tests.el | 16 +++++++++++++--- yasnippet.el | 5 ++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index 2870afb38..98b2ddc1d 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -119,6 +119,12 @@ (yas-expand-snippet "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 () "elisp with strings and unbalance parens inside it" (with-temp-buffer @@ -208,7 +214,9 @@ (yas-minor-mode 1) ;; 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. - (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)) (should (string= (yas--buffer-contents) "ok")))) @@ -216,8 +224,10 @@ (with-temp-buffer (yas-minor-mode 1) ;; the rule here is: To use regexps in embedded `(elisp)` expressions, - ;; escape backslashes once. i.e. to use \\( \\) constructs, write \\\\( \\\\). - (let ((snippet "$1${1:$(if (string-match \"foo\\\\\\\\(ba+r\\\\\\\\)baz\" yas/text) \"ok\" \"fail\")}")) + ;; escape backslashes once, i.e. to use \\( \\) constructs, write \\\\( \\\\). + (let ((snippet "$1${1:$(if (string-match \"foo\\\\\\\\(ba+r\\\\\\\\)baz\" yas/text) + \"ok\" + \"fail\")}")) (yas-expand-snippet snippet) (should (string= (yas--buffer-contents) "fail")) (ert-simulate-command `(yas-mock-insert "foobaaar")) diff --git a/yasnippet.el b/yasnippet.el index 605b61a6d..6f99ce56e 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3762,6 +3762,9 @@ Meant to be called in a narrowed buffer, does various passes" ;; Reset the yas--dollar-regions ;; (setq yas--dollar-regions nil) + ;; protect just the backquotes + ;; + (yas--protect-escapes nil '(?`)) ;; replace all backquoted expressions ;; (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) (let ((current-string (match-string-no-properties 1)) transformed) (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)) (when transformed (let ((marker (make-marker))) -- 2.39.2