aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2016-08-09 16:09:18 +0000
committerAlan Mackenzie2016-08-09 16:09:18 +0000
commit9cf9095838aefec9871b9922a95cb4c199696eb8 (patch)
treeb83d310159220803f6a66de2e4d7dce5796ed4e4
parent8b789c8cfeaee074f581e10009d781b52bf45c81 (diff)
downloademacs-9cf9095838aefec9871b9922a95cb4c199696eb8.tar.gz
emacs-9cf9095838aefec9871b9922a95cb4c199696eb8.zip
CC Mode: check for and fix missing call to before_change_functions.
Fixes bug #24094 and bug #24074. This can happen with `revert-buffer' or sometimes `find-file', when the file is already in a buffer, but the file has been changed outside of Emacs. * lisp/progmodes/cc-mode (c-after-change): When we detect a missing invocation of c-before-change-functions, we assume the changed region is the entire buffer, and call c-before-change explicitly before proceding.
-rw-r--r--lisp/progmodes/cc-mode.el25
1 files changed, 21 insertions, 4 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 8d75eea4da7..07476013354 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -492,10 +492,15 @@ preferably use the `c-mode-menu' language constant directly."
492(defvar c-just-done-before-change nil) 492(defvar c-just-done-before-change nil)
493(make-variable-buffer-local 'c-just-done-before-change) 493(make-variable-buffer-local 'c-just-done-before-change)
494;; This variable is set to t by `c-before-change' and to nil by 494;; This variable is set to t by `c-before-change' and to nil by
495;; `c-after-change'. It is used to detect a spurious invocation of 495;; `c-after-change'. It is used for two purposes: (i) to detect a spurious
496;; `before-change-functions' directly following on from a correct one. This 496;; invocation of `before-change-functions' directly following on from a
497;; happens in some Emacsen, for example when `basic-save-buffer' does (insert 497;; correct one. This happens in some Emacsen, for example when
498;; ?\n) when `require-final-newline' is non-nil. 498;; `basic-save-buffer' does (insert ?\n) when `require-final-newline' is
499;; non-nil; (ii) to detect when Emacs fails to invoke
500;; `before-change-functions'. This can happend when reverting a buffer - see
501;; bug #24094. It seems these failures happen only in GNU Emacs; XEmacs
502;; seems to maintain the strict alternation of calls to
503;; `before-change-functions' and `after-change-functions'.
499 504
500(defun c-basic-common-init (mode default-style) 505(defun c-basic-common-init (mode default-style)
501 "Do the necessary initialization for the syntax handling routines 506 "Do the necessary initialization for the syntax handling routines
@@ -1251,6 +1256,18 @@ Note that the style variables are always made local to the buffer."
1251 ;; This calls the language variable c-before-font-lock-functions, if non nil. 1256 ;; This calls the language variable c-before-font-lock-functions, if non nil.
1252 ;; This typically sets `syntax-table' properties. 1257 ;; This typically sets `syntax-table' properties.
1253 1258
1259 ;; We can sometimes get two consecutive calls to `after-change-functions'
1260 ;; without an intervening call to `before-change-functions' when reverting
1261 ;; the buffer (see bug #24094). Whatever the cause, assume that the entire
1262 ;; buffer has changed.
1263 (when (not c-just-done-before-change)
1264 (save-restriction
1265 (widen)
1266 (c-before-change (point-min) (point-max))
1267 (setq beg (point-min)
1268 end (point-max)
1269 old-len (- end beg))))
1270
1254 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become 1271 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become
1255 ;; larger than (beg end). 1272 ;; larger than (beg end).
1256 (setq c-new-END (- (+ c-new-END (- end beg)) old-len)) 1273 (setq c-new-END (- (+ c-new-END (- end beg)) old-len))