From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= 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 18:04:53 +0100 Message-ID: <87fsu4h2oa.fsf@gmail.com> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23482"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Jim Porter , Dmitry Gutov , 50538@debbugs.gnu.org, Alan Mackenzie To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 16 19:06:14 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 1mQupy-0005rD-7X for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 Sep 2021 19:06:14 +0200 Original-Received: from localhost ([::1]:58266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQupw-0001Jr-AN for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 Sep 2021 13:06:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQupm-0001JP-Qp for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 13:06:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQupm-0007EG-HI for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 13:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mQupm-0000A0-2e for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 13:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Sep 2021 17:06: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.1631811905532 (code B ref 50538); Thu, 16 Sep 2021 17:06:02 +0000 Original-Received: (at 50538) by debbugs.gnu.org; 16 Sep 2021 17:05:05 +0000 Original-Received: from localhost ([127.0.0.1]:56442 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQuor-00008W-Bj for submit@debbugs.gnu.org; Thu, 16 Sep 2021 13:05:05 -0400 Original-Received: from mail-wr1-f51.google.com ([209.85.221.51]:33384) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQuon-00007s-2r for 50538@debbugs.gnu.org; Thu, 16 Sep 2021 13:05:04 -0400 Original-Received: by mail-wr1-f51.google.com with SMTP id t18so10683562wrb.0 for <50538@debbugs.gnu.org>; Thu, 16 Sep 2021 10:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=gFletwjxuVROGSbGzV6dxZu7RNhAemLD/sBAnVs9FGs=; b=H5rQbLGbSo+NAv24OoNTVI29VAA8DAJR5CvL156RpsI4yVFVaehRs/MTV7HOlCZ4Gb 9cMU458uHUfzOFwOggjto6Jpnw9zzWRE7qoGeyko0W62DsZ51KpFFl4baU5ExgVwlSA1 UHCdsElZr8qS/W8htyW7Ez3yDBjnvGLEzB21Vtg7dtVsY8qBepZpQ7hIcIQLlDuvyrOB HYDYlJMzPMh5V5mTgscU3j7/lVCA2Xm669/fADTXmA4geCqAdHKNkqLfsFLmmXR+2xbQ KFJ5hi2o8LaGcwrr6GzQgAgPjsmvAb6CXN0ecBZPmweogmoavlgo3pUsSu7JBmVwn9FV +N7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=gFletwjxuVROGSbGzV6dxZu7RNhAemLD/sBAnVs9FGs=; b=XtHWaGn+RTxKZoTggoyd9j9R0mZ7WJ3MKlSPYJ+eeWwwTuqzOShTY2BLrXyxSDag7U xO6kN9AwSM705DfTxhbIpT/8SVFQmx6mJxL1UjqMozsIBn3nVPHt+sapRPe7PJfNsp9d GRV1UyWuDCB7jtZopKyfCeQ95+Lc9yEJeY6lC/0Px2/ylRACXJ+9yoA5V1AtWhq8eI9x 9OE3uzKIPEdjYTMCYVsvJtVTpIRMN/ZmCKI72DeyrJ3u1xyMlrFHwdyUHDIm4ibixYw3 bUCoB+2cXnSNqJ+qPAfOeL3whWDtBFeJRwJwIutw0E6V1GHDnt/h19wBqbj8QXjOlLxL pEYw== X-Gm-Message-State: AOAM530l1VQzx/nWHrI/OodzLPVwco32Jafhft6Kif0duDGm6vNF/KX9 qVi9Be7z3aLvLab710Qyoxo= X-Google-Smtp-Source: ABdhPJwhbXZeMhqMTTU6vWYSy0ClYTGTTfxDW8wx/ipqdRnAIn78H703orz/bJhA+qE3Sp0cE866yw== X-Received: by 2002:a05:6000:181:: with SMTP id p1mr7473117wrx.247.1631811895203; Thu, 16 Sep 2021 10:04:55 -0700 (PDT) Original-Received: from krug ([62.48.174.238]) by smtp.gmail.com with ESMTPSA id q19sm8193343wmq.29.2021.09.16.10.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 10:04:54 -0700 (PDT) In-Reply-To: <871r5o3biv.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 16 Sep 2021 15:17:28 +0200") 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:214486 Archived-At: 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=C3=A3o, 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 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.=20=20 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,=20 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-s= ome-cc-things))) (add-hook 'c-mode-common-hook (lambda () (kill-local-variable 'electric-pair-inhibit-predicate)))= )) 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. 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. Hope this helps. I'm sorry I can't offer any better solutions. Jo=C3=A3o