From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Unbalanced change hooks (part 2) [PATCH] Date: Mon, 8 Aug 2016 19:54:59 +0000 Message-ID: <20160808195459.GD7208@acm.fritz.box> References: <83r3a7md69.fsf@gnu.org> <20160802165545.GD2328@acm.fritz.box> <83fuqnm6og.fsf@gnu.org> <83eg67m3aq.fsf@gnu.org> <20160808143614.GA7208@acm.fritz.box> <83mvkni7xf.fsf@gnu.org> <20160808165449.GB7208@acm.fritz.box> <83d1lji3ih.fsf@gnu.org> <20160808184223.GC7208@acm.fritz.box> <838tw7hyk2.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1470686186 20958 195.159.176.226 (8 Aug 2016 19:56:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 8 Aug 2016 19:56:26 +0000 (UTC) User-Agent: Mutt/1.5.24 (2015-08-30) Cc: ofv@wanadoo.es, rcopley@gmail.com, rms@gnu.org, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 08 21:56:22 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bWqer-0005Jb-9E for ged-emacs-devel@m.gmane.org; Mon, 08 Aug 2016 21:56:21 +0200 Original-Received: from localhost ([::1]:59469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWqeo-000232-3P for ged-emacs-devel@m.gmane.org; Mon, 08 Aug 2016 15:56:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWqeB-00022x-4y for emacs-devel@gnu.org; Mon, 08 Aug 2016 15:55:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWqe7-0007Bv-19 for emacs-devel@gnu.org; Mon, 08 Aug 2016 15:55:38 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:59545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWqe6-0007BY-My for emacs-devel@gnu.org; Mon, 08 Aug 2016 15:55:34 -0400 Original-Received: (qmail 47636 invoked by uid 3782); 8 Aug 2016 19:55:33 -0000 Original-Received: from acm.muc.de (p4FC46EDC.dip0.t-ipconnect.de [79.196.110.220]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 08 Aug 2016 21:55:31 +0200 Original-Received: (qmail 10373 invoked by uid 1000); 8 Aug 2016 19:54:59 -0000 Content-Disposition: inline In-Reply-To: <838tw7hyk2.fsf@gnu.org> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 193.149.48.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206495 Archived-At: 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: ofv@wanadoo.es, rcopley@gmail.com, rms@gnu.org, emacs-devel@gnu.org > > From: Alan Mackenzie > > > 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).