From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rolf Ade Newsgroups: gmane.emacs.bugs Subject: bug#23565: 24.5; tcl-end-of-defun and tcl-eval-defun doesn't work reliable Date: Sat, 28 Sep 2019 02:20:54 +0200 Message-ID: <874l0xmftl.fsf@pointsman.de> References: <87mvnoe3pi.fsf@linux-qg7d.fritz.box> <871scw3x6g.fsf@tromey.com> <87zhz99742.fsf@pointsman.de> <87woua8xf5.fsf@pointsman.de> <87muv5n841.fsf@tromey.com> <87d0hruonx.fsf@pointsman.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="66664"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: 23565@debbugs.gnu.org To: Tom Tromey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Sep 28 02:22:15 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iE0V3-000H8V-MJ for geb-bug-gnu-emacs@m.gmane.org; Sat, 28 Sep 2019 02:22:13 +0200 Original-Received: from localhost ([::1]:58540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iE0V2-0003rY-2A for geb-bug-gnu-emacs@m.gmane.org; Fri, 27 Sep 2019 20:22:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54486) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iE0Ut-0003rM-Vg for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2019 20:22:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iE0Us-0001fP-LA for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2019 20:22:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40028) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iE0Us-0001fF-GJ for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2019 20:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iE0Us-0001eC-9E for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2019 20:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Rolf Ade Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Sep 2019 00:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23565 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 23565-submit@debbugs.gnu.org id=B23565.15696300696238 (code B ref 23565); Sat, 28 Sep 2019 00:22:02 +0000 Original-Received: (at 23565) by debbugs.gnu.org; 28 Sep 2019 00:21:09 +0000 Original-Received: from localhost ([127.0.0.1]:48848 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iE0U1-0001cX-5A for submit@debbugs.gnu.org; Fri, 27 Sep 2019 20:21:09 -0400 Original-Received: from mxout5.interscholz.de ([85.236.196.72]:51893) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iE0Ty-0001bY-46 for 23565@debbugs.gnu.org; Fri, 27 Sep 2019 20:21:07 -0400 Original-Received: from localhost (mxout5 [127.0.0.1]) by mxout5.interscholz.de (Postfix) with ESMTP id CD59225D3A; Sat, 28 Sep 2019 02:20:44 +0200 (CEST) X-Virus-Scanned: interscholz amavisd-new at mxout5.interscholz.de Original-Received: from server.web01.interscholz.net (server.web01.interscholz.net [85.236.196.138]) by mxout5.interscholz.de (Postfix) with ESMTP id 26B5F20C11; Sat, 28 Sep 2019 02:20:42 +0200 (CEST) Original-Received: from pointsman2 (p5B317A9C.dip0.t-ipconnect.de [91.49.122.156]) by server.web01.interscholz.net (Postfix) with ESMTPSA id 4433B340099; Sat, 28 Sep 2019 02:20:54 +0200 (CEST) In-Reply-To: <87d0hruonx.fsf@pointsman.de> (Rolf Ade's message of "Wed, 31 Jul 2019 00:45:54 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:167448 Archived-At: Rolf Ade writes: > Tom Tromey writes: >>>>>>> "Rolf" == Rolf Ade writes: >> >> Rolf> Indent the second line ("foo") with and you get >> Rolf> do { >> Rolf> foo >> >> Thanks for trying this. >> I suppose instead of the fix for the "namespace" thing, tcl-mode should >> maybe just looking at brace depth for indentation. I will take a deeper >> look. > > Despite #32035 this is still open with master of today (but not with > 26.2). Completely legal and commen code at the beginning befor the first > word out of tcl-proc-list are not indented as expected. Examples: > > do { > something > } > > if {$argc != 0} { > puts stderr "usage: $argv0" > } > > set options { > -foo "default" > -bar "bardefault" > } > > > Expected indentation would be of course something like: > > do { > something > } > > if {$argc != 0} { > puts stderr "usage: $argv0" > } > > set options { > -foo "default" > -bar "bardefault" > } > > > After the first word out of tcl-proc-list in the buffer all that > examples above will be indented as expected, no misbehaviour any more. > > I happily confirm again, that master hasn't the original problem of this > bug report. And I'd really love to see that fixed, after it has plagued > me for 20 years. > > But I'm afraid that the cure (current behavior of master) is worse than > the problem (26.2). (I'm getting nervous - emacs-dev already talks about cutting an emacs-27 branch ... I'd really love to see this long standing bug to be fixed. Let me recapitulate.) The original bug of this report was fixed by commit cd5bb4bf3dbad8941d25823f398b595b8f0edbb9 Author: Tom Tromey Date: Sun Jun 24 11:18:19 2018 -0600 This fix introduced a new unwanted indentation behaviour. Any code at the beginning of a buffer in tcl-mode before the first word that match an element out of tcl-proc-list (or so it looks like, I haven't really understand all details but I've provided some examples earlier in the thread) will not be indented as typically expected. I'm afraid the behaviour of current master is more worse than it was before of cd5bb4bf3dbad8941d25823f398b595b8f0edbb9. E.g. work with a notable fraction of the tcl files included in the tcl core distribution (https://core.tcl-lang.org/tcl/download) would suffer from this. So before release of emacs 27 this commit should be reverted. Or, much better, because the commit fixes the original problem (which I really love to see fixed), it should be improved. I came up with the following. The simple idea is to keep the new behaviour where it shines and fall back to the old way otherwise. Commit message: Fix tcl-mode indentation after fix of bug#23565 * lisp/progmodes/tcl.el (tcl-calculate-indent) Fall back to old indentation method for tcl code at the start of the buffer before the first word matching an element out of tcl-proc-list. Copyright-paperwork-exempt: yes diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el index 0fd3d6d1bf..db97230480 100644 --- a/lisp/progmodes/tcl.el +++ b/lisp/progmodes/tcl.el @@ -817,7 +817,9 @@ tcl-calculate-indent found-next-line) (if parse-start (goto-char parse-start) - (beginning-of-defun)) + (if (not (beginning-of-defun)) + (let ((beginning-of-defun-function nil)) + (beginning-of-defun)))) (while (< (point) indent-point) (setq parse-start (point)) (setq state (parse-partial-sexp (point) indent-point 0))