Let snippet insertion trigger active field clearing.

* yasnippet.el (yas-expand-snippet): Since the actual insertion must
happen with modification hooks inhibited, we can't rely on that
mechanism to clear the field.  Call yas--skip-and-clear-field-p on the
active field.
This commit is contained in:
Noam Postavsky 2017-09-23 18:34:38 -04:00
parent ece7935d7a
commit e200a3b9b1

View File

@ -3760,30 +3760,36 @@ considered when expanding the snippet."
"[yas] `yas-expand-snippet' needs properly setup `yas-minor-mode'") "[yas] `yas-expand-snippet' needs properly setup `yas-minor-mode'")
(run-hooks 'yas-before-expand-snippet-hook) (run-hooks 'yas-before-expand-snippet-hook)
;; (let* ((clear-field
(let* ((yas-selected-text (or yas-selected-text (let ((field (and yas--active-field-overlay
(and (region-active-p) (overlay-buffer yas--active-field-overlay)
(buffer-substring-no-properties (region-beginning) (overlay-get yas--active-field-overlay 'yas--field))))
(region-end))))) (and field (yas--skip-and-clear-field-p
(start (or start field (point) (point) 0)
(and (region-active-p) field)))
(region-beginning)) (start (cond (start)
(point))) ((region-active-p)
(end (or end (region-beginning))
(and (region-active-p) (clear-field
(region-end)) (yas--field-start clear-field))
(point))) (t (point))))
(to-delete (and start (end (cond (end)
end ((region-active-p)
(region-end))
(clear-field
(yas--field-end clear-field))
(t (point))))
(to-delete (and (> end start)
(buffer-substring-no-properties start end))) (buffer-substring-no-properties start end)))
(yas-selected-text
(or yas-selected-text
(if (not clear-field) to-delete)))
(yas--first-indent-undo nil) (yas--first-indent-undo nil)
snippet) snippet)
(goto-char start) (goto-char start)
(setq yas--indent-original-column (current-column)) (setq yas--indent-original-column (current-column))
;; Delete the region to delete, this *does* get undo-recorded. ;; Delete the region to delete, this *does* get undo-recorded.
;; (when to-delete
(when (and to-delete
(> end start))
(delete-region start end)) (delete-region start end))
(cond ((listp content) (cond ((listp content)