From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#18749: 24.3.94; CC Mode 5.32.5 (C/l); cc-mode state cache failure leading to bad indentation Date: 17 Oct 2014 18:19:50 -0000 Message-ID: <20141017181950.4855.qmail@acm.muc.de> References: <87h9z367nq.fsf@maru2.md5i.com> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1413570394 568 80.91.229.3 (17 Oct 2014 18:26:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 Oct 2014 18:26:34 +0000 (UTC) Cc: 18749@debbugs.gnu.org To: Michael Welsh Duggan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Oct 17 20:26:26 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XfCEL-000150-4I for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 Oct 2014 20:26:25 +0200 Original-Received: from localhost ([::1]:34087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfCEK-0005sW-BT for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 Oct 2014 14:26:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfCEB-0005s8-9k for bug-gnu-emacs@gnu.org; Fri, 17 Oct 2014 14:26:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfCE5-0002uT-0l for bug-gnu-emacs@gnu.org; Fri, 17 Oct 2014 14:26:15 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfCDy-0002t1-67; Fri, 17 Oct 2014 14:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XfCDx-0007LI-Rd; Fri, 17 Oct 2014 14:26:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Fri, 17 Oct 2014 18:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18749 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 18749-submit@debbugs.gnu.org id=B18749.141357034228191 (code B ref 18749); Fri, 17 Oct 2014 18:26:01 +0000 Original-Received: (at 18749) by debbugs.gnu.org; 17 Oct 2014 18:25:42 +0000 Original-Received: from localhost ([127.0.0.1]:47650 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XfCDa-0007Ka-Nw for submit@debbugs.gnu.org; Fri, 17 Oct 2014 14:25:40 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:28473 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XfCDX-0007KQ-KI for 18749@debbugs.gnu.org; Fri, 17 Oct 2014 14:25:36 -0400 Original-Received: (qmail 78848 invoked by uid 3782); 17 Oct 2014 18:25:34 -0000 Original-Received: from acm.muc.de (pD951B34C.dip0.t-ipconnect.de [217.81.179.76]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 17 Oct 2014 20:25:33 +0200 Original-Received: (qmail 4856 invoked by uid 1000); 17 Oct 2014 18:19:50 -0000 In-Reply-To: <87h9z367nq.fsf@maru2.md5i.com> X-Newsgroups: gmane.emacs.bugs User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.8.13-gentoo (x86_64)) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:94688 Hello, Michael. It's been a fun day. ;-) In article <87h9z367nq.fsf@maru2.md5i.com> you wrote: > [-- text/plain, encoding 7bit, charset: US-ASCII, 6 lines --] > A consistent c-mode indentation error that causes bad indentation, much > cursing, and gnashing of teeth. This occurs in the latest emacs-24 > branch (and trunk). > From emacs -Q, using the attached file: > [-- text/plain, encoding 7bit, charset: US-ASCII, 2434 lines, name: rwuniqsetup.c.before.2 --] [ .... ] > [-- text/plain, encoding quoted-printable, charset: utf-8, 291 lines --] > M-x c-toggle-parse-state-debug > C-x C-f rwuniqsetup.c.before.2 > C-s ipaddr_rec_to_bin RET > C-v > At this point you should see the following in *Messages*: [ The following has been altered from the original to show the correct first inconsistency which occurred.] > Mark saved where search started > c-parse-state inconsistency at 46719: using cache: ((46217 . 46572) 45454 (43406 . 45002)), from scratch: (45454 (43406 . 45002)) > Old state: > (setq c-state-cache '((46217 . 46572) 45454 (43406 . 45002)) c-state-cache-good-pos 46747 c-state-nonlit-pos-cache '(76939 73939 70939 67939 64939 61939 58939 55939 52939 49939 46939 43114 39291 36291 33291 30291 27178 24178 21178 18178 15145 12046 9013 6002 3002) c-state-nonlit-pos-cache-limit 76939 c-state-semi-nonlit-pos-cache '(45291 42291 39291 36291 33291 30291 27094 24058 21058 18058 15058 12046 9013 6001 3001) c-state-semi-nonlit-pos-cache-limit 45291 c-state-brace-pair-desert '(1 . 45935) c-state-point-min 1 c-state-point-min-lit-type nil c-state-point-min-lit-start nil c-state-min-scan-pos 1 c-state-old-cpp-beg # c-state-old-cpp-end # c-parse-state-point 46793) > At this point, indentation is having problems. Try hitting TAB on line > 1371, for example. Or line 1374 for a complete failure to indent at > all. OK, for once c-parse-state seems to be blameless. What seems to be happening is that during the display fontification, operations are done at buffer offset 46793. This is the spot after the indentation on L1360. CC Mode puts a backwards search limit on many operations, and this is often implemented by temporarily narrowing the buffer (narrow-to-region (- (point) n) (point-max)), where n is sometimes 1000. 1000 bytes before 46793 is 45793. This spot is in the middle of the "##" operator on L1346. Thus the buffer is getting narrowed such that the first character, ostensibly at BOL (to the Emacs regexp matcher), is "#". A `c-beginning-of-macro' operation is thus spuriously finding point 45793, in the middle of this operator. This spot is then getting permanently marked as a beginning-of-CPP. (Technically, this is done with the 'category property, giving it a value 'c-cpp-delimiter.) When c-parse-state later tries to scan this part of the code, it trips up on this spurious beginning-of-CPP, terminating its scanning. If you look at the two inconsistent values for c-parse-state above, the "from scratch" value is actually the false one, where it fails to find the brace pair (46217 . 46572) which is after 45793. I think what I'm going to do is insert an extra check into c-beginning-of-macro, such that if there seems to be a match at (point-min) of a narrowed buffer (or possibly even on the top line of one), it will be widened and tested again. Look forward to a patch soon! > -- > Michael Welsh Duggan > (md5i@md5i.com) -- Alan Mackenzie (Nuremberg, Germany).