From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Welsh Duggan Newsgroups: gmane.emacs.bugs Subject: bug#11749: Acknowledgement (24.1; C-mode indentation gives wrong-type-argument error.) Date: Fri, 01 Feb 2013 17:18:44 -0500 Message-ID: References: <20121028113610.GA3339@acm.acm> <20121104203912.GA3274@acm.acm> <20121121213340.GB4025@acm.acm> <87sj7elgtt.fsf@maru.md5i.com> <20130107120951.GB3384@acm.acm> <20130123141644.GB3411@acm.acm> <20130129113737.GA4544@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1359757355 31353 80.91.229.3 (1 Feb 2013 22:22:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Feb 2013 22:22:35 +0000 (UTC) Cc: "11749@debbugs.gnu.org" <11749@debbugs.gnu.org>, Kim Storm To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 01 23:22:54 2013 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 1U1P0X-0005sc-65 for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Feb 2013 23:22:53 +0100 Original-Received: from localhost ([::1]:56054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1P0E-00029y-Uw for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Feb 2013 17:22:34 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1Oz8-00020W-B2 for bug-gnu-emacs@gnu.org; Fri, 01 Feb 2013 17:22:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1Oy4-0006zl-7x for bug-gnu-emacs@gnu.org; Fri, 01 Feb 2013 17:21:26 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54509) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1Owy-0006Er-8V; Fri, 01 Feb 2013 17:19:12 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1U1Oxm-0006fT-1j; Fri, 01 Feb 2013 17:20:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Welsh Duggan Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Fri, 01 Feb 2013 22:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11749 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 11749-submit@debbugs.gnu.org id=B11749.135975718625593 (code B ref 11749); Fri, 01 Feb 2013 22:20:01 +0000 Original-Received: (at 11749) by debbugs.gnu.org; 1 Feb 2013 22:19:46 +0000 Original-Received: from localhost ([127.0.0.1]:59973 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U1OxU-0006eg-SX for submit@debbugs.gnu.org; Fri, 01 Feb 2013 17:19:46 -0500 Original-Received: from euclid.red.cert.org ([192.88.209.48]:58371) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1U1OxP-0006eS-Rm for 11749@debbugs.gnu.org; Fri, 01 Feb 2013 17:19:43 -0500 Original-Received: from bucknell.indigo.cert.org (bucknell.indigo.cert.org [10.60.10.121]) by euclid.red.cert.org (8.14.4/8.14.4) with ESMTP id r11MBrdO020429; Fri, 1 Feb 2013 17:11:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cert.org; s=jthatj15xw2j; t=1359756713; bh=N4PtBMr1ePawGqwDoJVrdj+FrAdDynW4RA/BCvsRURs=; h=From:To:Cc:Subject:References:Date:In-Reply-To:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding:Sender: Reply-To; b=mb4+IVx155TVIJdcjLDt/DX745RCDrQBd2BqWYQGLxpyEac8ItBGlOfcRVHR1A8iw PwCYXKsJQzDw2lYURBQiSo4maQjhqozfHM25YSvZz/j9EoXV/qpIOkUgYG/qHXPrYD KuMiZXAyTs3tsxzsIRfJI0k4+elxUKPGYzKTK0hk= Original-Received: from waterbuck.yellow.cert.org (waterbuck.yellow.cert.org [10.20.128.84]) by bucknell.indigo.cert.org (8.14.4/8.14.4/2.81) with ESMTP id r11MIkob012133; Fri, 1 Feb 2013 17:18:46 -0500 Original-Received: (from mwd@localhost) by waterbuck.yellow.cert.org (8.14.4/8.14.4/Submit/1.6) id r11MIiRb001534; Fri, 1 Feb 2013 17:18:44 -0500 X-Authentication-Warning: waterbuck.yellow.cert.org: mwd set sender to mwd@cert.org using -f In-Reply-To: <20130129113737.GA4544@acm.acm> (Alan Mackenzie's message of "Tue, 29 Jan 2013 11:37:37 +0000") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3.50 (gnu/linux) X-Spam-Score: -2.2 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-Spam-Score: -2.2 (--) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.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:70580 Archived-At: Alan Mackenzie writes: > Hi, Michael. I've been running with this for a few days, and have yet to run into a problem. I'll let you know when/if I do in the future. > On Wed, Jan 23, 2013 at 10:39:34AM -0500, Michael Welsh Duggan wrote: >> Alan Mackenzie writes: > >> > However, this isn't the end of the story -=20 > >> > (i) Start your test case in rwtransfer.c, and M-v until the top of the >> > file. (This shouldn't display any inconsistency messages) >> > (ii) M-x goto-char 20001 . This should go to EOL 671, just >> > after a "}". >> > (iii) Type }. (Two characters) >> > (iv) C-v, possibly twice. > >> > This displays a message something like: >> > c-parse-state inconsistency at 21070: using cache: ((20458 . 20935= )), >> > from scratch: ((20838 . 20877)) >> > , together with a state dump. > >> > This bug isn't a new one, but I've just come across it. I'll be worki= ng >> > on it in the meantime. > >> Oh, good. I haven't reported any "type stuff" errors I have been >> getting because they are harder to reproduce. (Unless it is triggered >> the first time you've typed in the buffer, it's hard to replicate the >> exact scenario.) I usually wait until you've fixed the last thing I >> sent in before attempting to report another, just in case the thing you >> are fixing is related. > > OK, I think I've fixed that above bug. I've also done a moderate amount > of refactoring to simplify things for the next bug, if any. > > I've removed the scanning strategy "start at the 2nd previous column-0 > beginning-of-defun", because it was returning false results, even in C > Mode. I'd already disabled it for C++ Mode (because hackers frequently > put things inside namespaces at column 0). One consequence is that > running with `c-toggle-parse-state-debug' is somewhat slower. Sorry for > that. > > Could you try this new version, please. The patch is based on the > emacs-24 branch of the savannah bzr repository. This should be identical > to the trunk. > > > > =3D=3D=3D modified file 'lisp/progmodes/cc-engine.el' > *** lisp/progmodes/cc-engine.el 2013-01-23 18:58:11 +0000 > --- lisp/progmodes/cc-engine.el 2013-01-29 11:03:35 +0000 > *************** > *** 2477,2496 **** >=20=20=20 > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;; > ;; Defuns which analyze the buffer, yet don't change `c-state-cache'. > - (defun c-get-fallback-scan-pos (here) > - ;; Return a start position for building `c-state-cache' from > - ;; scratch. This will be at the top level, 2 defuns back. > - (save-excursion > - ;; Go back 2 bods, but ignore any bogus positions returned by > - ;; beginning-of-defun (i.e. open paren in column zero). > - (goto-char here) > - (let ((cnt 2)) > - (while (not (or (bobp) (zerop cnt))) > - (c-beginning-of-defun-1) ; Pure elisp BOD. > - (if (eq (char-after) ?\{) > - (setq cnt (1- cnt))))) > - (point))) > -=20 > (defun c-state-balance-parens-backwards (here- here+ top) > ;; Return the position of the opening paren/brace/bracket before HERE= - which > ;; matches the outermost close p/b/b between HERE+ and TOP. Except w= hen > --- 2477,2482 ---- > *************** > *** 2548,2594 **** > ;; o - ('forward START-POINT) - scan forward from START-POINT, > ;; which is not less than the highest position in `c-state-cache' be= low here. > ;; o - ('backward nil) - scan backwards (from HERE). > - ;; o - ('BOD START-POINT) - scan forwards from START-POINT, which is = at the > - ;; top level. > ;; o - ('IN-LIT nil) - point is inside the literal containing point-m= in. > (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position belo= w HERE in cache (or 1) > ! BOD-pos ; position of 2nd BOD before HERE. > ! strategy ; 'forward, 'backward, 'BOD, or 'IN-LIT. > ! start-point > ! how-far) ; putative scanning distance. > (setq good-pos (or good-pos (c-state-get-min-scan-pos))) > (cond > ((< here (c-state-get-min-scan-pos)) > ! (setq strategy 'IN-LIT > ! start-point nil > ! cache-pos nil > ! how-far 0)) > ((<=3D good-pos here) > (setq strategy 'forward > ! start-point (max good-pos cache-pos) > ! how-far (- here start-point))) > ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some = sort of weighting. > ! (setq strategy 'backward > ! how-far (- good-pos here))) > (t > (setq strategy 'forward > ! how-far (- here cache-pos) > ! start-point cache-pos))) > !=20 > ! ;; Might we be better off starting from the top level, two defuns b= ack, > ! ;; instead? This heuristic no longer works well in C++, where > ! ;; declarations inside namespace brace blocks are frequently placed= at > ! ;; column zero. > ! (when (and (not (c-major-mode-is 'c++-mode)) > ! (> how-far c-state-cache-too-far)) > ! (setq BOD-pos (c-get-fallback-scan-pos here)) ; somewhat EXPENSIV= E!!! > ! (if (< (- here BOD-pos) how-far) > ! (setq strategy 'BOD > ! start-point BOD-pos))) > !=20 > ! (list > ! strategy > ! (and (memq strategy '(forward BOD)) start-point)))) >=20=20=20 >=20=20=20 > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;; > --- 2534,2556 ---- > ;; o - ('forward START-POINT) - scan forward from START-POINT, > ;; which is not less than the highest position in `c-state-cache' be= low here. > ;; o - ('backward nil) - scan backwards (from HERE). > ;; o - ('IN-LIT nil) - point is inside the literal containing point-m= in. > (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position belo= w HERE in cache (or 1) > ! strategy ; 'forward, 'backward, or 'IN-LIT. > ! start-point) > (setq good-pos (or good-pos (c-state-get-min-scan-pos))) > (cond > ((< here (c-state-get-min-scan-pos)) > ! (setq strategy 'IN-LIT)) > ((<=3D good-pos here) > (setq strategy 'forward > ! start-point (max good-pos cache-pos))) > ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some = sort of weighting. > ! (setq strategy 'backward)) > (t > (setq strategy 'forward > ! start-point cache-pos))) > ! (list strategy (and (eq strategy 'forward) start-point)))) >=20=20=20 >=20=20=20 > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;= ;; > *************** > *** 2630,2636 **** >=20=20=20 > (setq c-state-point-min (point-min))) >=20=20=20 > ! (defun c-append-lower-brace-pair-to-state-cache (from &optional upper-l= im) > ;; If there is a brace pair preceding FROM in the buffer, at the same= level > ;; of nesting (not necessarily immediately preceding), push a cons on= to > ;; `c-state-cache' to represent it. FROM must not be inside a litera= l. If > --- 2592,2598 ---- >=20=20=20 > (setq c-state-point-min (point-min))) >=20=20=20 > ! (defun c-append-lower-brace-pair-to-state-cache (from here &optional up= per-lim) > ;; If there is a brace pair preceding FROM in the buffer, at the same= level > ;; of nesting (not necessarily immediately preceding), push a cons on= to > ;; `c-state-cache' to represent it. FROM must not be inside a litera= l. If > *************** > *** 2654,2661 **** > ;; reduce the time wasted in repeated fruitless searches in brace des= erts. > (save-excursion > (save-restriction > ! (let* ((here (point-max)) > ! new-cons > (cache-pos (c-state-cache-top-lparen)) ; might be nil. > (macro-start-or-from > (progn (goto-char from) > --- 2616,2622 ---- > ;; reduce the time wasted in repeated fruitless searches in brace des= erts. > (save-excursion > (save-restriction > ! (let* (new-cons > (cache-pos (c-state-cache-top-lparen)) ; might be nil. > (macro-start-or-from > (progn (goto-char from) > *************** > *** 2690,2696 **** > ;; search bound, even though the algorithm below would skip > ;; over the new paren pair. > (cache-lim (and cache-pos (< cache-pos from) cache-pos))) > - (widen) > (narrow-to-region > (cond > ((and desert-lim cache-lim) > --- 2651,2656 ---- > *************** > *** 2698,2704 **** > (desert-lim) > (cache-lim) > ((point-min))) > ! (point-max))) >=20=20=20 > ;; In the next pair of nested loops, the inner one moves back past a > ;; pair of (mis-)matching parens or brackets; the outer one moves > --- 2658,2666 ---- > (desert-lim) > (cache-lim) > ((point-min))) > ! ;; The top limit is EOB to ensure that `bra' is inside the > ! ;; accessible part of the buffer at the next scan operation. > ! (1+ (buffer-size)))) >=20=20=20 > ;; In the next pair of nested loops, the inner one moves back past a > ;; pair of (mis-)matching parens or brackets; the outer one moves > *************** > *** 2765,2789 **** > (if (consp (car c-state-cache)) > (cdr c-state-cache) > c-state-cache))) > ! ;; N.B. This defsubst codes one method for the simple, normal case, > ;; and a more sophisticated, slower way for the general case. Don't > ;; eliminate this defsubst - it's a speed optimization. > ! (c-append-lower-brace-pair-to-state-cache (1- bra+1))))) >=20=20=20 > ! (defun c-append-to-state-cache (from) > ! ;; Scan the buffer from FROM to (point-max), adding elements into > ! ;; `c-state-cache' for braces etc. Return a candidate for > ! ;; `c-state-cache-good-pos'. > ;; > ;; FROM must be after the latest brace/paren/bracket in `c-state-cach= e', if > ;; any. Typically, it is immediately after it. It must not be insid= e a > ;; literal. > ! (let ((here-bol (c-point 'bol (point-max))) > (macro-start-or-here > ! (save-excursion (goto-char (point-max)) > (if (c-beginning-of-macro) > (point) > ! (point-max)))) > pa+1 ; pos just after an opening PAren (or brace). > (ren+1 from) ; usually a pos just after an closing paREN etc. > ; Is actually the pos. to scan for a (/{/[ from, > --- 2727,2750 ---- > (if (consp (car c-state-cache)) > (cdr c-state-cache) > c-state-cache))) > ! ;; N.B. This defsubst codes one method for the simple, normal case, > ;; and a more sophisticated, slower way for the general case. Don't > ;; eliminate this defsubst - it's a speed optimization. > ! (c-append-lower-brace-pair-to-state-cache (1- bra+1) (point-max))))) >=20=20=20 > ! (defun c-append-to-state-cache (from here) > ! ;; Scan the buffer from FROM to HERE, adding elements into `c-state-c= ache' > ! ;; for braces etc. Return a candidate for `c-state-cache-good-pos'. > ;; > ;; FROM must be after the latest brace/paren/bracket in `c-state-cach= e', if > ;; any. Typically, it is immediately after it. It must not be insid= e a > ;; literal. > ! (let ((here-bol (c-point 'bol here)) > (macro-start-or-here > ! (save-excursion (goto-char here) > (if (c-beginning-of-macro) > (point) > ! here))) > pa+1 ; pos just after an opening PAren (or brace). > (ren+1 from) ; usually a pos just after an closing paREN etc. > ; Is actually the pos. to scan for a (/{/[ from, > *************** > *** 2796,2870 **** > mstart) ; start of a macro. >=20=20=20 > (save-excursion > ! ;; Each time round the following loop, we enter a successively de= eper > ! ;; level of brace/paren nesting. (Except sometimes we "continue = at > ! ;; the existing level".) `pa+1' is a pos inside an opening > ! ;; brace/paren/bracket, usually just after it. > ! (while > ! (progn > ! ;; Each time round the next loop moves forward over an opening then > ! ;; a closing brace/bracket/paren. This loop is white hot, so it > ! ;; plays ugly tricks to go fast. DON'T PUT ANYTHING INTO THIS > ! ;; LOOP WHICH ISN'T ABSOLUTELY NECESSARY!!! It terminates when a > ! ;; call of `scan-lists' signals an error, which happens when there > ! ;; are no more b/b/p's to scan. > ! (c-safe > ! (while t > ! (setq pa+1 (scan-lists ren+1 1 -1) ; Into (/{/[; might signal > ! paren+1s (cons pa+1 paren+1s)) > ! (setq ren+1 (scan-lists pa+1 1 1)) ; Out of )/}/]; might signal > ! (if (and (eq (char-before pa+1) ?{)) ; Check for a macro later. > ! (setq bra+1 pa+1)) > ! (setcar paren+1s ren+1))) >=20=20=20 > ! (if (and pa+1 (> pa+1 ren+1)) > ! ;; We've just entered a deeper nesting level. > ! (progn > ! ;; Insert the brace pair (if present) and the single open > ! ;; paren/brace/bracket into `c-state-cache' It cannot be > ! ;; inside a macro, except one around point, because of what > ! ;; `c-neutralize-syntax-in-CPP' has done. > ! (c-state-push-any-brace-pair bra+1 macro-start-or-here) > ! ;; Insert the opening brace/bracket/paren position. > ! (setq c-state-cache (cons (1- pa+1) c-state-cache)) > ! ;; Clear admin stuff for the next more nested part of the scan. > ! (setq ren+1 pa+1 pa+1 nil bra+1 nil bra+1s nil) > ! t) ; Carry on the loop > !=20 > ! ;; All open p/b/b's at this nesting level, if any, have probably > ! ;; been closed by matching/mismatching ones. We're probably > ! ;; finished - we just need to check for having found an > ! ;; unmatched )/}/], which we ignore. Such a )/}/] can't be in a > ! ;; macro, due the action of `c-neutralize-syntax-in-CPP'. > ! (c-safe (setq ren+1 (scan-lists ren+1 1 1)))))) ; acts as loop c= ontrol. > !=20 > ! ;; Record the final, innermost, brace-pair if there is one. > ! (c-state-push-any-brace-pair bra+1 macro-start-or-here) > !=20 > ! ;; Determine a good pos > ! (while (and (setq paren+1 (car paren+1s)) > ! (> (if (> paren+1 macro-start-or-here) > ! paren+1 > ! (goto-char paren+1) > ! (setq mstart (and (c-beginning-of-macro) > ! (point))) > ! (or mstart paren+1)) > ! here-bol)) > ! (setq paren+1s (cdr paren+1s))) > ! (cond > ! ((and paren+1 mstart) > ! (min paren+1 mstart)) > ! (paren+1) > ! (t from))))) >=20=20=20 > ! (defun c-remove-stale-state-cache (start-point pps-point) > ;; Remove stale entries from the `c-cache-state', i.e. those which wi= ll > ! ;; not be in it when it is amended for position (point-max). > ! ;; Additionally, the "outermost" open-brace entry before (point-max) > ! ;; will be converted to a cons if the matching close-brace is scanned. > ;; > ;; START-POINT is a "maximal" "safe position" - there must be no open > ! ;; parens/braces/brackets between START-POINT and (point-max). > ;; > ;; As a second thing, calculate the result of parse-partial-sexp at > ;; PPS-POINT, w.r.t. START-POINT. The motivation here is that > --- 2757,2833 ---- > mstart) ; start of a macro. >=20=20=20 > (save-excursion > ! (save-restriction > ! (narrow-to-region (point-min) here) > ! ;; Each time round the following loop, we enter a successively deeper > ! ;; level of brace/paren nesting. (Except sometimes we "continue at > ! ;; the existing level".) `pa+1' is a pos inside an opening > ! ;; brace/paren/bracket, usually just after it. > ! (while > ! (progn > ! ;; Each time round the next loop moves forward over an opening t= hen > ! ;; a closing brace/bracket/paren. This loop is white hot, so it > ! ;; plays ugly tricks to go fast. DON'T PUT ANYTHING INTO THIS > ! ;; LOOP WHICH ISN'T ABSOLUTELY NECESSARY!!! It terminates when a > ! ;; call of `scan-lists' signals an error, which happens when the= re > ! ;; are no more b/b/p's to scan. > ! (c-safe > ! (while t > ! (setq pa+1 (scan-lists ren+1 1 -1) ; Into (/{/[; might signal > ! paren+1s (cons pa+1 paren+1s)) > ! (setq ren+1 (scan-lists pa+1 1 1)) ; Out of )/}/]; might signal > ! (if (and (eq (char-before pa+1) ?{)) ; Check for a macro later. > ! (setq bra+1 pa+1)) > ! (setcar paren+1s ren+1))) >=20=20=20 > ! (if (and pa+1 (> pa+1 ren+1)) > ! ;; We've just entered a deeper nesting level. > ! (progn > ! ;; Insert the brace pair (if present) and the single open > ! ;; paren/brace/bracket into `c-state-cache' It cannot be > ! ;; inside a macro, except one around point, because of what > ! ;; `c-neutralize-syntax-in-CPP' has done. > ! (c-state-push-any-brace-pair bra+1 macro-start-or-here) > ! ;; Insert the opening brace/bracket/paren position. > ! (setq c-state-cache (cons (1- pa+1) c-state-cache)) > ! ;; Clear admin stuff for the next more nested part of the scan. > ! (setq ren+1 pa+1 pa+1 nil bra+1 nil bra+1s nil) > ! t) ; Carry on the loop > !=20 > ! ;; All open p/b/b's at this nesting level, if any, have probably > ! ;; been closed by matching/mismatching ones. We're probably > ! ;; finished - we just need to check for having found an > ! ;; unmatched )/}/], which we ignore. Such a )/}/] can't be in a > ! ;; macro, due the action of `c-neutralize-syntax-in-CPP'. > ! (c-safe (setq ren+1 (scan-lists ren+1 1 1)))))) ; acts as loop contro= l. > !=20 > ! ;; Record the final, innermost, brace-pair if there is one. > ! (c-state-push-any-brace-pair bra+1 macro-start-or-here) > !=20 > ! ;; Determine a good pos > ! (while (and (setq paren+1 (car paren+1s)) > ! (> (if (> paren+1 macro-start-or-here) > ! paren+1 > ! (goto-char paren+1) > ! (setq mstart (and (c-beginning-of-macro) > ! (point))) > ! (or mstart paren+1)) > ! here-bol)) > ! (setq paren+1s (cdr paren+1s))) > ! (cond > ! ((and paren+1 mstart) > ! (min paren+1 mstart)) > ! (paren+1) > ! (t from)))))) >=20=20=20 > ! (defun c-remove-stale-state-cache (start-point here pps-point) > ;; Remove stale entries from the `c-cache-state', i.e. those which wi= ll > ! ;; not be in it when it is amended for position HERE. Additionally, = the > ! ;; "outermost" open-brace entry before HERE will be converted to a co= ns if > ! ;; the matching close-brace is scanned. > ;; > ;; START-POINT is a "maximal" "safe position" - there must be no open > ! ;; parens/braces/brackets between START-POINT and HERE. > ;; > ;; As a second thing, calculate the result of parse-partial-sexp at > ;; PPS-POINT, w.r.t. START-POINT. The motivation here is that > *************** > *** 2881,2903 **** > ;; last element to be removed from `c-state-cache', when that elt i= s a > ;; cons, otherwise nil. > ;; o - PPS-STATE is the parse-partial-sexp state at PPS-POINT. > ! (save-restriction > ! (narrow-to-region 1 (point-max)) > ! (save-excursion > ! (let* ((in-macro-start ; start of macro containing (point-max) = or nil. > (save-excursion > ! (goto-char (point-max)) > (and (c-beginning-of-macro) > (point)))) > (start-point-actual-macro-start ; Start of macro containing > ; start-point or nil > ! (and (< start-point (point-max)) > (save-excursion > (goto-char start-point) > (and (c-beginning-of-macro) > (point))))) > (start-point-actual-macro-end ; End of this macro, (maybe > ! ; (point-max)), or nil. > (and start-point-actual-macro-start > (save-excursion > (goto-char start-point-actual-macro-start) > --- 2844,2866 ---- > ;; last element to be removed from `c-state-cache', when that elt i= s a > ;; cons, otherwise nil. > ;; o - PPS-STATE is the parse-partial-sexp state at PPS-POINT. > ! (save-excursion > ! (save-restriction > ! (narrow-to-region 1 (point-max)) > ! (let* ((in-macro-start ; start of macro containing HERE or nil. > (save-excursion > ! (goto-char here) > (and (c-beginning-of-macro) > (point)))) > (start-point-actual-macro-start ; Start of macro containing > ; start-point or nil > ! (and (< start-point here) > (save-excursion > (goto-char start-point) > (and (c-beginning-of-macro) > (point))))) > (start-point-actual-macro-end ; End of this macro, (maybe > ! ; HERE), or nil. > (and start-point-actual-macro-start > (save-excursion > (goto-char start-point-actual-macro-start) > *************** > *** 2909,2922 **** > scan-back-pos > pair-beg pps-point-state target-depth) >=20=20=20 > ! ;; Remove entries beyond (point-max). Also remove any entries inside > ! ;; a macro, unless (point-max) is in the same macro. > (setq upper-lim > (if (or (null c-state-old-cpp-beg) > ! (and (> (point-max) c-state-old-cpp-beg) > ! (< (point-max) c-state-old-cpp-end))) > ! (point-max) > ! (min (point-max) c-state-old-cpp-beg))) > (while (and c-state-cache (>=3D (c-state-cache-top-lparen) upper-lim)) > (setq scan-back-pos (car-safe (car c-state-cache))) > (setq c-state-cache (cdr c-state-cache))) > --- 2872,2885 ---- > scan-back-pos > pair-beg pps-point-state target-depth) >=20=20=20 > ! ;; Remove entries beyond HERE. Also remove any entries inside > ! ;; a macro, unless HERE is in the same macro. > (setq upper-lim > (if (or (null c-state-old-cpp-beg) > ! (and (> here c-state-old-cpp-beg) > ! (< here c-state-old-cpp-end))) > ! here > ! (min here c-state-old-cpp-beg))) > (while (and c-state-cache (>=3D (c-state-cache-top-lparen) upper-lim)) > (setq scan-back-pos (car-safe (car c-state-cache))) > (setq c-state-cache (cdr c-state-cache))) > *************** > *** 2934,2940 **** > ;; time round; the corresponding elements in `c-state-cache' are > ;; removed. `pos' is just after the brace-pair or the open paren at > ;; (car c-state-cache). There can be no open parens/braces/brackets > ! ;; between `start-point'/`start-point-actual-macro-start' and (point-m= ax), > ;; due to the interface spec to this function. > (setq pos (if (and start-point-actual-macro-end > (not (eq start-point-actual-macro-start > --- 2897,2903 ---- > ;; time round; the corresponding elements in `c-state-cache' are > ;; removed. `pos' is just after the brace-pair or the open paren at > ;; (car c-state-cache). There can be no open parens/braces/brackets > ! ;; between `start-point'/`start-point-actual-macro-start' and HERE, > ;; due to the interface spec to this function. > (setq pos (if (and start-point-actual-macro-end > (not (eq start-point-actual-macro-start > *************** > *** 2944,2950 **** > start-point)) > (goto-char pos) > (while (and c-state-cache > ! (< (point) (point-max))) > (cond > ((null pps-state) ; first time through > (setq target-depth -1)) > --- 2907,2915 ---- > start-point)) > (goto-char pos) > (while (and c-state-cache > ! (or (numberp (car c-state-cache)) ; Have we a { at all?=20 > ! (cdr c-state-cache)) > ! (< (point) here)) > (cond > ((null pps-state) ; first time through > (setq target-depth -1)) > *************** > *** 2956,2962 **** > ;; Scan! > (setq pps-state > (parse-partial-sexp > ! (point) (if (< (point) pps-point) pps-point (point-max)) > target-depth > nil pps-state)) >=20=20=20 > --- 2921,2927 ---- > ;; Scan! > (setq pps-state > (parse-partial-sexp > ! (point) (if (< (point) pps-point) pps-point here) > target-depth > nil pps-state)) >=20=20=20 > *************** > *** 3209,3215 **** > ;; Do we need to add in an earlier brace pair, having lopped one = off? > (if (and dropped-cons > (< too-high-pa (+ here c-state-cache-too-far))) > ! (c-append-lower-brace-pair-to-state-cache too-high-pa here-bol)) > (setq c-state-cache-good-pos (or (c-state-cache-after-top-paren) > (c-state-get-min-scan-pos))))) >=20=20=20 > --- 3174,3180 ---- > ;; Do we need to add in an earlier brace pair, having lopped one = off? > (if (and dropped-cons > (< too-high-pa (+ here c-state-cache-too-far))) > ! (c-append-lower-brace-pair-to-state-cache too-high-pa here here-bol)) > (setq c-state-cache-good-pos (or (c-state-cache-after-top-paren) > (c-state-get-min-scan-pos))))) >=20=20=20 > *************** > *** 3285,3331 **** > strategy (car res) > start-point (cadr res)) >=20=20=20 > - (when (eq strategy 'BOD) > - (setq c-state-cache nil > - c-state-cache-good-pos start-point)) > -=20 > ;; SCAN! > ! (save-restriction > ! (cond > ! ((memq strategy '(forward BOD)) > ! (narrow-to-region (point-min) here) > ! (setq res (c-remove-stale-state-cache start-point here-bopl)) > ! (setq cache-pos (car res) > ! scan-backward-pos (cadr res) > ! bopl-state (car (cddr res))) ; will be nil if (< here-bopl > ; start-point) > ! (if scan-backward-pos > ! (c-append-lower-brace-pair-to-state-cache scan-backward-pos)) > ! (setq good-pos > ! (c-append-to-state-cache cache-pos)) > ! (setq c-state-cache-good-pos > ! (if (and bopl-state > ! (< good-pos (- here c-state-cache-too-far))) > ! (c-state-cache-non-literal-place here-bopl bopl-state) > ! good-pos))) > !=20 > ! ((eq strategy 'backward) > ! (setq res (c-remove-stale-state-cache-backwards here) > ! good-pos (car res) > ! scan-backward-pos (cadr res) > ! scan-forward-p (car (cddr res))) > ! (if scan-backward-pos > ! (c-append-lower-brace-pair-to-state-cache > ! scan-backward-pos)) > ! (setq c-state-cache-good-pos > ! (if scan-forward-p > ! (progn (narrow-to-region (point-min) here) > ! (c-append-to-state-cache good-pos)) > ! good-pos))) >=20=20=20 > ! (t ; (eq strategy 'IN-LIT) > ! (setq c-state-cache nil > ! c-state-cache-good-pos nil))))) >=20=20=20 > c-state-cache) >=20=20=20 > --- 3250,3288 ---- > strategy (car res) > start-point (cadr res)) >=20=20=20 > ;; SCAN! > ! (cond > ! ((eq strategy 'forward) > ! (setq res (c-remove-stale-state-cache start-point here here-bopl)) > ! (setq cache-pos (car res) > ! scan-backward-pos (cadr res) > ! bopl-state (car (cddr res))) ; will be nil if (< here-bopl > ; start-point) > ! (if scan-backward-pos > ! (c-append-lower-brace-pair-to-state-cache scan-backward-pos here)) > ! (setq good-pos > ! (c-append-to-state-cache cache-pos here)) > ! (setq c-state-cache-good-pos > ! (if (and bopl-state > ! (< good-pos (- here c-state-cache-too-far))) > ! (c-state-cache-non-literal-place here-bopl bopl-state) > ! good-pos))) > !=20 > ! ((eq strategy 'backward) > ! (setq res (c-remove-stale-state-cache-backwards here) > ! good-pos (car res) > ! scan-backward-pos (cadr res) > ! scan-forward-p (car (cddr res))) > ! (if scan-backward-pos > ! (c-append-lower-brace-pair-to-state-cache scan-backward-pos here)) > ! (setq c-state-cache-good-pos > ! (if scan-forward-p > ! (c-append-to-state-cache good-pos here) > ! good-pos))) >=20=20=20 > ! (t ; (eq strategy 'IN-LIT) > ! (setq c-state-cache nil > ! c-state-cache-good-pos nil)))) >=20=20=20 > c-state-cache) >=20=20=20 > *************** > *** 8559,8566 **** > )) >=20=20=20 > (defun c-looking-at-special-brace-list (&optional lim) > ! ;; If we're looking at the start of a pike-style list, ie `({=C2=A0})= ', > ! ;; `([=C2=A0])', `(<=C2=A0>)' etc, a cons of a cons of its starting a= nd ending > ;; positions and its entry in c-special-brace-lists is returned, nil > ;; otherwise. The ending position is nil if the list is still open. > ;; LIM is the limit for forward search. The point may either be at > --- 8516,8523 ---- > )) >=20=20=20 > (defun c-looking-at-special-brace-list (&optional lim) > ! ;; If we're looking at the start of a pike-style list, ie `({=C3=82= =C2=A0})', > ! ;; `([=C3=82=C2=A0])', `(<=C3=82=C2=A0>)' etc, a cons of a cons of it= s starting and ending > ;; positions and its entry in c-special-brace-lists is returned, nil > ;; otherwise. The ending position is nil if the list is still open. > ;; LIM is the limit for forward search. The point may either be at > > >> --=20 >> Michael Welsh Duggan >> (mwd@cert.org) --=20 Michael Welsh Duggan (mwd@cert.org)