emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unbalanced change hooks (part 2) [PATCH]


From: Alan Mackenzie
Subject: Re: Unbalanced change hooks (part 2) [PATCH]
Date: Mon, 8 Aug 2016 19:54:59 +0000
User-agent: Mutt/1.5.24 (2015-08-30)

Hello, Eli.

On Mon, Aug 08, 2016 at 10:04:45PM +0300, Eli Zaretskii wrote:
> > Date: Mon, 8 Aug 2016 18:42:23 +0000
> > Cc: address@hidden, address@hidden, address@hidden, address@hidden
> > From: Alan Mackenzie <address@hidden>

> > > So, if worse comes to worst, you could trigger such a complete scan
> > > after revert-buffer, e.g. in a specialized revert-buffer-function.

> > Why would that be bad?

> Not bad, just potentially expensive for large buffers.  But if that's
> "good enough", I don't really mind.

> However, the patch you show below doesn't implement this, does it?

No, but the following does.  It looks kind of simple, given the problems
we've been through.  Maybe this one is the solution:



diff -r 7a969360b796 cc-mode.el
--- a/cc-mode.el        Fri Aug 05 08:13:50 2016 +0000
+++ b/cc-mode.el        Mon Aug 08 19:46:40 2016 +0000
@@ -475,10 +475,13 @@
 (defvar c-just-done-before-change nil)
 (make-variable-buffer-local 'c-just-done-before-change)
 ;; This variable is set to t by `c-before-change' and to nil by
-;; `c-after-change'.  It is used to detect a spurious invocation of
-;; `before-change-functions' directly following on from a correct one.  This
-;; happens in some Emacsen, for example when `basic-save-buffer' does (insert
-;; ?\n) when `require-final-newline' is non-nil.
+;; `c-after-change'.  It is used for two purposes: (i) to detect a spurious
+;; invocation of `before-change-functions' directly following on from a
+;; correct one.  This happens in some Emacsen, for example when
+;; `basic-save-buffer' does (insert ?\n) when `require-final-newline' is
+;; non-nil; (ii) to detect when Emacs fails to invoke
+;; `before-change-functions'.  This can happend when reverting a buffer - see
+;; bug #24094.
 
 (defun c-basic-common-init (mode default-style)
   "Do the necessary initialization for the syntax handling routines
@@ -1220,6 +1223,18 @@
   ;; This calls the language variable c-before-font-lock-functions, if non nil.
   ;; This typically sets `syntax-table' properties.
 
+  ;; We can sometimes get two consecutive calls to `after-change-functions'
+  ;; without an intervening call to `before-change-functions' when reverting
+  ;; the buffer (see bug #24094).  Whatever the cause assume that the entire
+  ;; buffer has changed.
+  (when (not c-just-done-before-change)
+    (save-restriction
+      (widen)
+      (c-before-change (point-min) (point-max))
+      (setq beg (point-min)
+           end (point-max)
+           old-len (- end beg))))
+
   ;; (c-new-BEG c-new-END) will be the region to fontify.  It may become
   ;; larger than (beg end).
   (setq c-new-END (- (+ c-new-END (- end beg)) old-len))


-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]