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#18826: 24.3.94; c++-mode bad indentation after programmatic insert with locally changed syntax table Date: 25 Oct 2014 23:24:49 -0000 Organization: muc.de e.V. Message-ID: <20141025232449.90894.qmail@mail.muc.de> References: <86egtwgra0.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1414279527 20972 80.91.229.3 (25 Oct 2014 23:25:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 25 Oct 2014 23:25:27 +0000 (UTC) Cc: 18826@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 26 01:25:20 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 1XiAhz-0006x5-OK for geb-bug-gnu-emacs@m.gmane.org; Sun, 26 Oct 2014 01:25:19 +0200 Original-Received: from localhost ([::1]:54866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XiAhz-0008WF-A8 for geb-bug-gnu-emacs@m.gmane.org; Sat, 25 Oct 2014 19:25:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XiAhs-0008Rc-AD for bug-gnu-emacs@gnu.org; Sat, 25 Oct 2014 19:25:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XiAho-0004T1-06 for bug-gnu-emacs@gnu.org; Sat, 25 Oct 2014 19:25:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:43455) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XiAhi-0004Gr-Vy; Sat, 25 Oct 2014 19:25:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XiAhh-0005nC-Pb; Sat, 25 Oct 2014 19:25:02 -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: Sat, 25 Oct 2014 23:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18826 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 18826-submit@debbugs.gnu.org id=B18826.141427949522251 (code B ref 18826); Sat, 25 Oct 2014 23:25:01 +0000 Original-Received: (at 18826) by debbugs.gnu.org; 25 Oct 2014 23:24:55 +0000 Original-Received: from localhost ([127.0.0.1]:35553 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XiAha-0005mo-Ju for submit@debbugs.gnu.org; Sat, 25 Oct 2014 19:24:55 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:49608 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XiAhX-0005me-53 for 18826@debbugs.gnu.org; Sat, 25 Oct 2014 19:24:52 -0400 Original-Received: (qmail 90895 invoked by uid 3782); 25 Oct 2014 23:24:49 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug User-Agent: tin/2.2.0-20131224 ("Lochindaal") (UNIX) (FreeBSD/8.4-RELEASE (amd64)) 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:95086 Hello, Dmitry. In article you wrote: > On 10/26/2014 02:34 AM, Alan Mackenzie wrote: >> Why do you think it should be harmless? > Because the syntax table change is temporary and its effect should be > limited to my code? It's no so limited. The before-change-functions and after-change-functions hooks will be run with that syntax table active. This is not good. >> . The c-in-sws and c-is-sws indicate that the semicolon has been >> recognised and marked as syntactic whitespace. The second line thus gets >> parsed as "statement-cont", i.e. a continued statement, so it gets >> indented an extra level. > Yes, I see that. But how does this happen? Somewhere in a before- or after-change-functions, c-backward-sws is being called, to go backward over syntactic whitespace. Somehow it gets horribly confused, because the syntax table isn't correct. I don't think the exact details matter too much here. >> If you cripple C++ Mode by substituting a wrong syntax table, you >> shouldn't be too surprised when things go "wrong". This seems like one of >> these "well, don't do that, then" bugs. >> Question: why do you want to play around with the syntax table in this >> manner? What are you trying to achieve? > I'm using a different syntax table for sexp movement, where it's > necessary for both parens and angle brackets to have paren syntax class. > In the actual code I modify the text after it's inserted, and > `backward-sexp' is used two times to find necessary search bounds. OK. Can I suggest an alternative? In C++ (and Java) Modes, the template (generic) delimiters are marked with syntax-table text properties. Unfortunately, at the moment this is done as part of font-locking, so isn't done until you display. However, if you put "(sit-for 0)" into your code after inserting "< ... >", this will cause a redisplay, allowing subsequent code to use the text properties, and a backward-sexp will then work. In the medium future (several weeks away), I'm hoping to fix CC Mode so that the text properties are applied to < ... > on an after-change function rather than at redisplay. > https://github.com/company-mode/company-mode/blob/42012730da15ffaef7c61722475040babed15332/company-template.el#L155-L173 -- Alan Mackenzie (Nuremberg, Germany).