Only kill snippets for text length change

of protection overlay.  Changes that keep the same length of text are
probably harmless (e.g. just change of text properties).  It's possible
that some harmful changes don't change text length, but the protection
overlays are already unable to catch all important changes since they
only cover 1 character each at the edges.

cc-mode modifies text properties in the buffer to cache parsing results,
therefore it's important that yasnippet not kill yasnippets when parsing
is triggered by a function that only wants to parse the
buffer (e.g. which-function-mode).

* yasnippet.el (yas--on-protection-overlay-modification): Check length
of text change to decide if change is harmful.  Fix docstring.
This commit is contained in:
Noam Postavsky 2016-04-16 11:31:44 -04:00
parent bd30a30d88
commit 4f2aa1526a

View File

@ -3467,12 +3467,11 @@ Move the overlays, or create them if they do not exit."
;; (overlay-put ov 'evaporate t)
(overlay-put ov 'modification-hooks '(yas--on-protection-overlay-modification)))))))
(defun yas--on-protection-overlay-modification (_overlay after? _beg _end &optional _length)
"Signals a snippet violation, then issues error.
The error should be ignored in `debug-ignored-errors'"
(defun yas--on-protection-overlay-modification (_overlay after? beg end &optional length)
"Commit the snippet if the protection overlay is being killed."
(unless (or yas--inhibit-overlay-hooks
after?
(not after?)
(= length (- end beg)) ; deletion or insertion
(yas--undo-in-progress))
(let ((snippets (yas--snippets-at-point)))
(yas--message 3 "Comitting snippets. Action would destroy a protection overlay.")