mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 13:33:04 +00:00
add: clear unmodified fields when inserting text at the beginning
This commit is contained in:
parent
54e93b60e9
commit
0daac695e2
15
snippet.el
15
snippet.el
@ -348,7 +348,8 @@ can be:
|
|||||||
(:include snippet--object)
|
(:include snippet--object)
|
||||||
(:print-function snippet--describe-field))
|
(:print-function snippet--describe-field))
|
||||||
name
|
name
|
||||||
(mirrors '()))
|
(mirrors '())
|
||||||
|
(modified-p nil))
|
||||||
|
|
||||||
(defun snippet--describe-field (field)
|
(defun snippet--describe-field (field)
|
||||||
(with-current-buffer (snippet--object-buffer field)
|
(with-current-buffer (snippet--object-buffer field)
|
||||||
@ -507,8 +508,8 @@ can be:
|
|||||||
(snippet--object-end field))
|
(snippet--object-end field))
|
||||||
(overlay-put snippet--field-overlay 'snippet--field field))
|
(overlay-put snippet--field-overlay 'snippet--field field))
|
||||||
|
|
||||||
(defun snippet--field-overlay-changed (overlay after? _beg _end
|
(defun snippet--field-overlay-changed (overlay after? beg end
|
||||||
&optional _length)
|
&optional pre-change-len)
|
||||||
;; there's a slight (apparently innocuous) bug here: if the overlay has
|
;; there's a slight (apparently innocuous) bug here: if the overlay has
|
||||||
;; zero-length, both `insert-in-front' and `insert-behind' modification hooks
|
;; zero-length, both `insert-in-front' and `insert-behind' modification hooks
|
||||||
;; are called
|
;; are called
|
||||||
@ -516,6 +517,14 @@ can be:
|
|||||||
(let* ((field (overlay-get overlay 'snippet--field))
|
(let* ((field (overlay-get overlay 'snippet--field))
|
||||||
(inhibit-modification-hooks t))
|
(inhibit-modification-hooks t))
|
||||||
(cond (after?
|
(cond (after?
|
||||||
|
(when (and (not (snippet--field-modified-p field))
|
||||||
|
(= beg (snippet--field-start field))
|
||||||
|
(zerop pre-change-len))
|
||||||
|
(delete-region end
|
||||||
|
(snippet--object-end field)))
|
||||||
|
|
||||||
|
(setf (snippet--field-modified-p field) t)
|
||||||
|
|
||||||
(mapc #'snippet--update-mirror (snippet--field-mirrors field))
|
(mapc #'snippet--update-mirror (snippet--field-mirrors field))
|
||||||
(move-overlay overlay
|
(move-overlay overlay
|
||||||
(snippet--object-start field)
|
(snippet--object-start field)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user