From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#50538: [PATCH] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode Date: Thu, 16 Sep 2021 19:05:56 +0000 Message-ID: References: <021853bf-0169-c158-ab3d-296b6c144e08@gmail.com> <83r1dufgxu.fsf@gnu.org> <94c7b4ec-813b-515f-d947-116c294dd74b@gmail.com> <716194ea-817f-eaad-f9ce-7d600ad359b1@gmail.com> <83k0jh9jn6.fsf@gnu.org> <87o88s3d87.fsf@gnus.org> <871r5o3biv.fsf@gnus.org> <87fsu4h2oa.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15985"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jim Porter , Lars Ingebrigtsen , 50538@debbugs.gnu.org, Dmitry Gutov To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 16 21:07:13 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mQwj3-0003vj-3l for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 Sep 2021 21:07:13 +0200 Original-Received: from localhost ([::1]:36124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQwj2-0001fd-2c for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 Sep 2021 15:07:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQwis-0001e9-SZ for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 15:07:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45033) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQwis-0000iw-Ka for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 15:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mQwis-0003n6-Ba for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 15:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Sep 2021 19:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50538 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50538-submit@debbugs.gnu.org id=B50538.163181916814482 (code B ref 50538); Thu, 16 Sep 2021 19:07:02 +0000 Original-Received: (at 50538) by debbugs.gnu.org; 16 Sep 2021 19:06:08 +0000 Original-Received: from localhost ([127.0.0.1]:56579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQwhz-0003lV-9S for submit@debbugs.gnu.org; Thu, 16 Sep 2021 15:06:08 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:21250 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1mQwhu-0003ku-Kb for 50538@debbugs.gnu.org; Thu, 16 Sep 2021 15:06:06 -0400 Original-Received: (qmail 41644 invoked by uid 3782); 16 Sep 2021 19:05:56 -0000 Original-Received: from acm.muc.de (p4fe15a47.dip0.t-ipconnect.de [79.225.90.71]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 16 Sep 2021 21:05:56 +0200 Original-Received: (qmail 9504 invoked by uid 1000); 16 Sep 2021 19:05:56 -0000 Content-Disposition: inline In-Reply-To: <87fsu4h2oa.fsf@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:214502 Archived-At: Hello, Joćo. On Thu, Sep 16, 2021 at 18:04:53 +0100, Joćo Tįvora wrote: > Lars Ingebrigtsen writes: > > Dmitry Gutov writes: > >>>> I don't use this minor mode, so I don't think my opinion on this > >>>> matters much. I will defer to Lars and Alan here. > >>> I seldom use electric-pair-mode, and since this touches cc-mode, I'll > >>> defer to Alan.:-) > >>> Alan? > >> At risk of reigniting an old disagreement, perhaps we should ask Joao? > > Sure; added to the CCs. Joćo, do you have an opinion here? > I couldn't understand the initial issue fully, but I can only confirm > that the relationship between cc-mode and electric-pair-mode has been > rocky. I think the situation is similar with electric-layout-mode and > with electric-indent-mode, to a certain degree (though I am not sure for > this last one). I think it is up to both of us to make this relationship less rocky. > I don't think there are any easy technical solutions for it. I certainly > cannot invest the effort in any of them right now. > It wasn't like this from the beginning: when I first created > electric-pair-mode it worked mostly if not fully fine with cc-mode, like > one expects e-p-m to work in other modes (ruby, python, js, elisp, rust, > perl, even non-programming modes). > At times, compatibility deteriorated as cc-mode added mechanisms for > solving electricity problems or related problems in an idiosyncratic > way. Sometimes these changes broke e-p-m's tests and the solution was > -- incorrectly in my view --to disable the tests "temporarily". I see > that for one of them at least, the test has been re-instated. A good > sign, maybe. > Regardless of history and current state of affairs, my personal solution > to C in Emacs is to use a hand-rolled mode, a so-called plainer-cc-mode. > The goal is to make it behave like most other modes w.r.t > electric-pair-mode and keep the basic c syntax and indentation. I've > used it reasonably successfully with C and C++. Here it is in its > entirety. I think I use something similar for c++-mode. > (define-derived-mode plainer-c-mode c-mode "pC" > "A plainer C-mode with no internal electric machinery." > (c-toggle-electric-state -1) > (setq-local electric-indent-local-mode-hook nil) > (setq-local electric-indent-mode-hook nil) > (electric-indent-local-mode 1) > (dolist (key '(?\" ?\' ?\{ ?\} ?\( ?\) ?\[ ?\])) > (local-set-key (vector key) 'self-insert-command))) > Among other simpler things, this makes the major mode not bind special > keys to special commands. They are all bound to `self-insert-command` > like most major modes. This simplifies electric-pair-mode, as far as I > remember. > The above is a hack, but not very dirty one. The one below much more so. > It's a brute-force hack for solving electricity problems. It simply > disables some cc internal functions. May be out of date by now, YMMV, > warranty void, etc, as they say. > (defun joaot/disable-some-cc-things () > (interactive) > (dolist (name '(c-restore-string-fences > c-remove-string-fences > c-before-change-check-unbalanced-strings > c-after-change-mark-abnormal-strings > c-after-change-escape-NL-in-string)) > (advice-add name :override #'ignore '((name . joaot/remove-disable-some-cc-things))) > (add-hook 'c-mode-common-hook > (lambda () > (kill-local-variable 'electric-pair-inhibit-predicate))))) Needless to say, my point of view with respect to the above is somewhat different. Succinctly put, the minor modes electric-.... are MINOR modes, and are quite new. They were implemented in a way which interfered with major modes, and I can't see there was any need for this. In particular, they interfered with CC Mode features which had existed for 20 years at the time. > On the C++/C editing-front, I am eagerly waiting for Treesitter to > arrive so that is it becomes possible to write a new major mode for c++ > and c from scratch. I am also looking forward to Treesitter, though I think starting a new C++ Mode from scratch would not be a good use of time, and would be needlessly disruptive for current CC Mode users. > Reusing solid and efficient parsing logic based on language grammars. > Another more closely available option, is to simply use LSP for > indentation and fontification. Though that is almost certainly slower > and less confortable/portable/etc... Anyway, whatever the solution, > I'm quite confident that such a mode won't have these characteristics > that cc-mode has when used with `electric-pair-mode`. > If you're writing C, and not C++, my also try Stefan Monnier's aptly > named sm-c-mode, installable via M-x package-install RET sm-c-mode. > Works fine with electric-pair-mode, but seems to indent very oddly for > some reason. I would rather suggest using straight C Mode, which works and works well. If there are incompatibilities between CC Mode and electric-pair-mode, and it seems there are, let's get these fixed. > Hope this helps. I'm sorry I can't offer any better solutions. Could you please express your expert view? In Jim's opening post he implies that: (i) electric-pair-mode should be active inside comments. (ii) In some circumstances at least, typing a " immediately in front of another " causes two "s to be inserted. Are these circumstances spelt out anywhere? (iii) Typing a " inside a string causes two "s to be inserted, leaving point between the two new adjacent strings formed. This feature is not intended to work in C++ raw strings, or other similar multi-line strings in other CC Mode modes. Are these three features all intended in electric-pair-mode? Thanks! > Joćo -- Alan Mackenzie (Nuremberg, Germany).