Merge pull request #1149 from pestctrl/quit-undo-tree

Push modifications to buffer-undo-list, even if unwinding
This commit is contained in:
monnier 2024-10-13 11:57:55 -04:00 committed by GitHub
commit fe1f4e0e96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4128,39 +4128,40 @@ Returns the newly created snippet."
(yas--letenv expand-env (yas--letenv expand-env
;; Put a single undo action for the expanded snippet's ;; Put a single undo action for the expanded snippet's
;; content. ;; content.
(let ((buffer-undo-list t)) (unwind-protect
(goto-char begin) (let ((buffer-undo-list t))
(if (> emacs-major-version 29) (goto-char begin)
;; Don't use the workaround for CC-mode's cache, (if (> emacs-major-version 29)
;; since it was presumably a bug in CC-mode, so either ;; Don't use the workaround for CC-mode's cache,
;; it's fixed already, or it should get fixed. ;; since it was presumably a bug in CC-mode, so either
(progn ;; it's fixed already, or it should get fixed.
(insert content) (progn
(narrow-to-region begin (point)) (insert content)
(goto-char (point-min)) (narrow-to-region begin (point))
(yas--snippet-parse-create snippet)) (goto-char (point-min))
;; Call before and after change functions manually, (yas--snippet-parse-create snippet))
;; otherwise cc-mode's cache can get messed up. Don't use ;; Call before and after change functions manually,
;; `inhibit-modification-hooks' for that, that blocks ;; otherwise cc-mode's cache can get messed up. Don't use
;; overlay and text property hooks as well! FIXME: Maybe ;; `inhibit-modification-hooks' for that, that blocks
;; use `combine-change-calls'? (Requires Emacs 27+ though.) ;; overlay and text property hooks as well! FIXME: Maybe
(run-hook-with-args 'before-change-functions begin end) ;; use `combine-change-calls'? (Requires Emacs 27+ though.)
(let ((before-change-functions nil) (run-hook-with-args 'before-change-functions begin end)
(after-change-functions nil)) (let ((before-change-functions nil)
;; Some versions of cc-mode (might be the one with Emacs (after-change-functions nil))
;; 24.3 only) fail when inserting snippet content in a ;; Some versions of cc-mode (might be the one with Emacs
;; narrowed buffer, so make sure to insert before ;; 24.3 only) fail when inserting snippet content in a
;; narrowing. ;; narrowed buffer, so make sure to insert before
(insert content) ;; narrowing.
(narrow-to-region begin (point)) (insert content)
(goto-char (point-min)) (narrow-to-region begin (point))
(yas--snippet-parse-create snippet)) (goto-char (point-min))
(run-hook-with-args 'after-change-functions (yas--snippet-parse-create snippet))
(point-min) (point-max) (run-hook-with-args 'after-change-functions
(- end begin)))) (point-min) (point-max)
(when (listp buffer-undo-list) (- end begin))))
(push (cons (point-min) (point-max)) (when (listp buffer-undo-list)
buffer-undo-list)) (push (cons (point-min) (point-max))
buffer-undo-list)))
;; Indent, collecting undo information normally. ;; Indent, collecting undo information normally.
(yas--indent snippet) (yas--indent snippet)