[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 85f39ce 06/40: Warn about backquote exprs modifying the bu
From: |
Noam Postavsky |
Subject: |
[elpa] master 85f39ce 06/40: Warn about backquote exprs modifying the buffer |
Date: |
Wed, 26 Oct 2016 23:06:32 +0000 (UTC) |
branch: master
commit 85f39cec2b0e34f60266057f5ef2f45193d75339
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Warn about backquote exprs modifying the buffer
* yasnippet.el (yas--save-backquotes): Show a warning if evaluating the
backquote expression modifies the buffer.
---
yasnippet.el | 41 +++++++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/yasnippet.el b/yasnippet.el
index 8a6258c..406b514 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -4017,20 +4017,33 @@ With optional string TEXT do it in string instead of
the buffer."
(defun yas--save-backquotes ()
"Save all the \"`(lisp-expression)`\"-style expressions
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)
- (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
- (widen)
- (insert "Y") ;; quite horrendous, I love it :)
- (set-marker marker (point))
- (insert "Y"))
- (push (cons marker transformed)
yas--backquote-markers-and-strings))))))
+ (let* ((yas--change-detected nil)
+ (detect-change (lambda (_beg _end) (setq yas--change-detected t))))
+ (while (re-search-forward yas--backquote-lisp-expression-regexp nil t)
+ (let ((current-string (match-string-no-properties 1)) transformed)
+ (save-restriction (widen)
+ (delete-region (match-beginning 0) (match-end 0)))
+ (let ((before-change-functions
+ (cons detect-change before-change-functions)))
+ (setq transformed (yas--eval-lisp (yas--read-lisp
+ (yas--restore-escapes
+ current-string '(?`))))))
+ (goto-char (match-beginning 0))
+ (when transformed
+ (let ((marker (make-marker))
+ (before-change-functions (cdr before-change-functions)))
+ (save-restriction
+ (widen)
+ (insert "Y") ;; quite horrendous, I love it :)
+ (set-marker marker (point))
+ (insert "Y"))
+ (push (cons marker transformed)
yas--backquote-markers-and-strings)))))
+ (when yas--change-detected
+ (lwarn '(yasnippet backquote-change) :warning
+ "`%s' modified buffer in a backquote expression."
+ (if yas--current-template
+ (yas--template-name yas--current-template)
+ "Snippet")))))
(defun yas--restore-backquotes ()
"Replace markers in `yas--backquote-markers-and-strings' with their values."
- [elpa] master updated (f06d730 -> 299efcb), Noam Postavsky, 2016/10/26
- [elpa] master bc80f67 01/40: .travis.yml: Don't notify on success, Noam Postavsky, 2016/10/26
- [elpa] master 6b785e1 08/40: Say how to hide the backquote side-effect warning, Noam Postavsky, 2016/10/26
- [elpa] master 1735a28 02/40: Add region contents to new snippet, Noam Postavsky, 2016/10/26
- [elpa] master ee4efdb 05/40: Revert "Separate parsing from evaluation of backquote lisp", Noam Postavsky, 2016/10/26
- [elpa] master 85f39ce 06/40: Warn about backquote exprs modifying the buffer,
Noam Postavsky <=
- [elpa] master e21420a 04/40: Separate parsing from evaluation of backquote lisp, Noam Postavsky, 2016/10/26
- [elpa] master c744148 03/40: Make yas-describe-tables easier to use from lisp, Noam Postavsky, 2016/10/26
- [elpa] master d218ed8 11/40: Do indent the first line of mirrors, but in correct order, Noam Postavsky, 2016/10/26
- [elpa] master 0db65ee 20/40: Don't clobber match data in modification hooks, Noam Postavsky, 2016/10/26
- [elpa] master dc098cf 25/40: Fix yas--message verbosity levels, Noam Postavsky, 2016/10/26
- [elpa] master 5af9276 27/40: Support yas/ symbols in yas-define-menu, Noam Postavsky, 2016/10/26
- [elpa] master ea9581f 22/40: Fix some quoting problems in doc strings, Noam Postavsky, 2016/10/26
- [elpa] master ee6e7a9 09/40: Fix some compilation warnings, Noam Postavsky, 2016/10/26
- [elpa] master 7661dc1 19/40: yasnippet.el (yas-escape-text): No error on nil text, Noam Postavsky, 2016/10/26
- [elpa] master 351c1e3 10/40: Don't indent first line of mirrors, Noam Postavsky, 2016/10/26