mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Separate parsing from evaluation of backquote lisp
* yasnippet.el (yas--save-backquotes): Parse all backquoted lisp forms and only then evaluate them.
This commit is contained in:
parent
c7441486db
commit
e21420a497
34
yasnippet.el
34
yasnippet.el
@ -4017,20 +4017,34 @@ With optional string TEXT do it in string instead of the buffer."
|
|||||||
(defun yas--save-backquotes ()
|
(defun yas--save-backquotes ()
|
||||||
"Save all the \"`(lisp-expression)`\"-style expressions
|
"Save all the \"`(lisp-expression)`\"-style expressions
|
||||||
with their evaluated value into `yas--backquote-markers-and-strings'."
|
with their evaluated value into `yas--backquote-markers-and-strings'."
|
||||||
(while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
|
;; Gather `(lisp-expression)`s.
|
||||||
(let ((current-string (match-string-no-properties 1)) transformed)
|
(let ((end (point-max)))
|
||||||
(save-restriction (widen)
|
|
||||||
(delete-region (match-beginning 0) (match-end 0)))
|
|
||||||
(setq transformed (yas--eval-lisp (yas--read-lisp (yas--restore-escapes current-string '(?`)))))
|
|
||||||
(goto-char (match-beginning 0))
|
|
||||||
(when transformed
|
|
||||||
(let ((marker (make-marker)))
|
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen)
|
(widen)
|
||||||
|
(while (re-search-forward yas--backquote-lisp-expression-regexp end t)
|
||||||
|
(let ((expr (yas--read-lisp (yas--restore-escapes
|
||||||
|
(match-string-no-properties 1))))
|
||||||
|
(marker (make-marker)))
|
||||||
|
(delete-region (match-beginning 0) (match-end 0))
|
||||||
(insert "Y") ;; quite horrendous, I love it :)
|
(insert "Y") ;; quite horrendous, I love it :)
|
||||||
(set-marker marker (point))
|
(set-marker marker (point))
|
||||||
(insert "Y"))
|
(insert "Y")
|
||||||
(push (cons marker transformed) yas--backquote-markers-and-strings))))))
|
(push (cons marker expr) yas--backquote-markers-and-strings)))))
|
||||||
|
;; Evaluate them.
|
||||||
|
(dolist (m-e yas--backquote-markers-and-strings)
|
||||||
|
(let* ((marker (car m-e))
|
||||||
|
(expr (cdr m-e))
|
||||||
|
(result (save-excursion
|
||||||
|
(goto-char marker)
|
||||||
|
(yas--eval-lisp expr))))
|
||||||
|
(setcdr m-e result)
|
||||||
|
(unless result
|
||||||
|
(save-restriction (widen)
|
||||||
|
(delete-region (1- marker) (1+ marker)))
|
||||||
|
(set-marker marker nil))))
|
||||||
|
;; Drop the nil results.
|
||||||
|
(setq yas--backquote-markers-and-strings
|
||||||
|
(cl-delete-if-not #'cdr yas--backquote-markers-and-strings)))
|
||||||
|
|
||||||
(defun yas--restore-backquotes ()
|
(defun yas--restore-backquotes ()
|
||||||
"Replace markers in `yas--backquote-markers-and-strings' with their values."
|
"Replace markers in `yas--backquote-markers-and-strings' with their values."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user