Don't clobber match data in modification hooks

Since modification hooks run just after any function that changes buffer
contents, it's important to save the match data, or else the code doing
the modification can become really confused.  See also Emacs bugs #23917
and #23869.

* yasnippet.el (yas--on-field-overlay-modification): Wrap main body in
`save-match-data'.
This commit is contained in:
Noam Postavsky 2016-07-12 19:59:43 -04:00
parent 7661dc161d
commit 0db65ee0bb

View File

@ -3416,14 +3416,15 @@ field start. This hook does nothing if an undo is in progress."
(let* ((inhibit-modification-hooks t) (let* ((inhibit-modification-hooks t)
(field (overlay-get overlay 'yas--field)) (field (overlay-get overlay 'yas--field))
(snippet (overlay-get yas--active-field-overlay 'yas--snippet))) (snippet (overlay-get yas--active-field-overlay 'yas--snippet)))
(when (yas--skip-and-clear-field-p field beg end length) (save-match-data
;; We delete text starting from the END of insertion. (when (yas--skip-and-clear-field-p field beg end length)
(yas--skip-and-clear field end)) ;; We delete text starting from the END of insertion.
(setf (yas--field-modified-p field) t) (yas--skip-and-clear field end))
(yas--advance-end-maybe field (overlay-end overlay)) (setf (yas--field-modified-p field) t)
(save-excursion (yas--advance-end-maybe field (overlay-end overlay))
(yas--field-update-display field)) (save-excursion
(yas--update-mirrors snippet)))) (yas--field-update-display field))
(yas--update-mirrors snippet)))))
;;; Apropos protection overlays: ;;; Apropos protection overlays:
;; ;;