* yasnippet.el (yas--snippet-create): Remove CC-mode workaround for #953

This commit is contained in:
Stefan Monnier 2024-01-01 19:47:31 -05:00
parent 362e9b551d
commit bd2fdc8f7d

View File

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