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#11749: Acknowledgement (24.1; C-mode indentation gives wrong-type-argument error.) Date: Sun, 4 Nov 2012 20:39:12 +0000 Message-ID: <20121104203912.GA3274@acm.acm> References: <20120908211451.GA22477@acm.acm> <20121007105951.GA3194@acm.acm> <20121010200025.GA3449@acm.acm> <20121014170650.GA3766@acm.acm> <20121028113610.GA3339@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1352061967 17920 80.91.229.3 (4 Nov 2012 20:46:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 4 Nov 2012 20:46:07 +0000 (UTC) Cc: "11749@debbugs.gnu.org" <11749@debbugs.gnu.org> To: Kim Storm , Michael Welsh Duggan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 04 21:46:16 2012 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 1TV75D-00030N-P9 for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 Nov 2012 21:46:15 +0100 Original-Received: from localhost ([::1]:37011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV755-0000jJ-2T for geb-bug-gnu-emacs@m.gmane.org; Sun, 04 Nov 2012 15:46:07 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:44636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV752-0000ho-5y for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 15:46:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TV750-0002VD-M2 for bug-gnu-emacs@gnu.org; Sun, 04 Nov 2012 15:46:04 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:39086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TV74y-0002UV-KA; Sun, 04 Nov 2012 15:46:00 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TV77t-0007ym-PT; Sun, 04 Nov 2012 15:49:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Sun, 04 Nov 2012 20:49: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.135206209330614 (code B ref 11749); Sun, 04 Nov 2012 20:49:01 +0000 Original-Received: (at 11749) by debbugs.gnu.org; 4 Nov 2012 20:48:13 +0000 Original-Received: from localhost ([127.0.0.1]:49337 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TV776-0007xi-Ap for submit@debbugs.gnu.org; Sun, 04 Nov 2012 15:48:12 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:32037 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TV772-0007xY-4h for 11749@debbugs.gnu.org; Sun, 04 Nov 2012 15:48:11 -0500 Original-Received: (qmail 79192 invoked by uid 3782); 4 Nov 2012 20:45:03 -0000 Original-Received: from acm.muc.de (pD951B21F.dip.t-dialin.net [217.81.178.31]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 04 Nov 2012 21:45:01 +0100 Original-Received: (qmail 3298 invoked by uid 1000); 4 Nov 2012 20:39:12 -0000 Content-Disposition: inline In-Reply-To: <20121028113610.GA3339@acm.acm> User-Agent: Mutt/1.5.21 (2010-09-15) 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.13 Precedence: list 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:66447 Archived-At: Kim, could you please try out this patch on your C++ files, and let me know if the main problem has been resolved. Michael, there was a rather crass bug in last week's patch. Sorry. It's fixed now, below. M-x c-toggle-parse-state-debug has been enhanced to display messages when the state-cache is intrinsically invalid. It also now gives a message when you {en,dis}able it. Would you try out this patch now, please. Thanks to you both! On Sun, Oct 28, 2012 at 11:36:10AM +0000, Alan Mackenzie wrote: > On Thu, Oct 25, 2012 at 09:41:11AM -0400, Michael Welsh Duggan wrote: > > A new recipe. This is a strange one. I hope it works for you as well. > > emacs -Q > > M-x tool-bar-mode > > resize the frame to be height 56 (according to the window manager) > > Load the included file > > M-x c-toggle-parse-state-debug > > C-s FIXME C-s > > Move cursor to the "o" on the next line (1175). > > Type: > > PyTYPE( > > C-f > > ) > > I get errors at the first open paren, and the close paren. Resizing the > > fame is important! I think it's due to caching that happens during font > > locking. > Thanks for this one. > The cause was the cache invalidation function being called from > after-change-functions. The newly inserted parens were fouling up the > invalidation algorithm. :-( The solution is to call that function from > before-change-functions instead. diff -r ac6584d14c06 cc-engine.el --- a/cc-engine.el Sun Sep 09 11:15:13 2012 +0000 +++ b/cc-engine.el Sun Nov 04 20:24:06 2012 +0000 @@ -2560,8 +2560,11 @@ start-point cache-pos))) ;; Might we be better off starting from the top level, two defuns back, - ;; instead? - (when (> how-far c-state-cache-too-far) + ;; 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 EXPENSIVE!!! (if (< (- here BOD-pos) how-far) (setq strategy 'BOD @@ -2648,17 +2651,20 @@ ;; If we're essentially repeating a fruitless search, just give up. (unless (and c-state-brace-pair-desert (eq cache-pos (car c-state-brace-pair-desert)) + (or (null (car c-state-brace-pair-desert)) + (> from (car c-state-brace-pair-desert))) (<= from (cdr c-state-brace-pair-desert))) - ;; DESERT-LIM. Only search what we absolutely need to, + ;; DESERT-LIM. Avoid repeated searching through the cached desert. (let ((desert-lim (and c-state-brace-pair-desert (eq cache-pos (car c-state-brace-pair-desert)) + (>= from (cdr c-state-brace-pair-desert)) (cdr c-state-brace-pair-desert))) ;; CACHE-LIM. This limit will be necessary when an opening ;; paren at `cache-pos' has just had its matching close paren - ;; inserted. `cache-pos' continues to be a search bound, even - ;; though the algorithm below would skip over the new paren - ;; pair. + ;; inserted into the buffer. `cache-pos' continues to be a + ;; search bound, even though the algorithm below would skip + ;; over the new paren pair. (cache-lim (and cache-pos (< cache-pos from) cache-pos))) (narrow-to-region (cond @@ -3354,13 +3360,19 @@ (fset 'c-real-parse-state (symbol-function 'c-parse-state))) (cc-bytecomp-defun c-real-parse-state) +(defvar c-parse-state-point nil) (defvar c-parse-state-state nil) (make-variable-buffer-local 'c-parse-state-state) (defun c-record-parse-state-state () + (setq c-parse-state-point (point)) (setq c-parse-state-state (mapcar (lambda (arg) - (cons arg (symbol-value arg))) + (let ((val (symbol-value arg))) + (cons arg + (if (consp val) + (copy-tree val) + val)))) '(c-state-cache c-state-cache-good-pos c-state-nonlit-pos-cache @@ -3373,7 +3385,8 @@ c-state-point-min-lit-start c-state-min-scan-pos c-state-old-cpp-beg - c-state-old-cpp-end)))) + c-state-old-cpp-end + c-parse-state-point)))) (defun c-replay-parse-state-state () (message (concat "(setq " @@ -3383,6 +3396,16 @@ c-parse-state-state " ") ")"))) +(defun c-debug-parse-state-double-cons (state) + (let (state-car conses-not-ok) + (while state + (setq state-car (car state) + state (cdr state)) + (if (and (consp state-car) + (consp (car state))) + (setq conses-not-ok t))) + conses-not-ok)) + (defun c-debug-parse-state () (let ((here (point)) (res1 (c-real-parse-state)) res2) (let ((c-state-cache nil) @@ -3415,8 +3438,16 @@ here res1 res2) (message "Old state:") (c-replay-parse-state-state)) + + (when (c-debug-parse-state-double-cons res1) + (message "c-parse-state INVALIDITY at %s: %s" + here res1) + (message "Old state:") + (c-replay-parse-state-state)) + (c-record-parse-state-state) - res1)) + res2 ; res1 correct a cascading series of errors ASAP + )) (defun c-toggle-parse-state-debug (&optional arg) (interactive "P") @@ -3424,7 +3455,9 @@ (fset 'c-parse-state (symbol-function (if c-debug-parse-state 'c-debug-parse-state 'c-real-parse-state))) - (c-keep-region-active)) + (c-keep-region-active) + (message "c-debug-parse-state %sabled" + (if c-debug-parse-state "en" "dis"))) (when c-debug-parse-state (c-toggle-parse-state-debug 1)) diff -r ac6584d14c06 cc-mode.el --- a/cc-mode.el Sun Sep 09 11:15:13 2012 +0000 +++ b/cc-mode.el Sun Nov 04 20:24:06 2012 +0000 @@ -1058,7 +1058,10 @@ (mapc (lambda (fn) (funcall fn beg end)) c-get-state-before-change-functions)) - ))))) + ))) + ;; The following must be done here rather than in `c-after-change' because + ;; newly inserted parens would foul up the invalidation algorithm. + (c-invalidate-state-cache beg))) (defvar c-in-after-change-fontification nil) (make-variable-buffer-local 'c-in-after-change-fontification) @@ -1108,7 +1111,7 @@ (c-trim-found-types beg end old-len) ; maybe we don't need all of these. (c-invalidate-sws-region-after beg end) - (c-invalidate-state-cache beg) + ;; (c-invalidate-state-cache beg) ; moved to `c-before-change'. (c-invalidate-find-decl-cache beg) (when c-recognize-<>-arglists > > -- > > Michael Welsh Duggan > > (mwd@cert.org) -- Alan Mackenzie (Nuremberg, Germany).