all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: "João Távora" <joaotavora@gmail.com>,
	"Lars Ingebrigtsen" <larsi@gnus.org>
Cc: Alan Mackenzie <acm@muc.de>,
	50538@debbugs.gnu.org, Dmitry Gutov <dgutov@yandex.ru>
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 10:29:47 -0700	[thread overview]
Message-ID: <16202af0-9d66-1996-8756-b3d0ff28ac9a@gmail.com> (raw)
In-Reply-To: <87fsu4h2oa.fsf@gmail.com>

On 9/16/2021 10:04 AM, João Távora wrote:
> 
> 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).

Hopefully the following summary will help. My patch is essentially an 
enhancement of the patch from bug#36474. In that bug, Alan Mackenzie 
describes the problem:

> Diagnosis: electric-pair--unbalanced-strings-p works after the (single)
> newly typed " has been stripped from the buffer.  It attempts to
> determine whether there are any open strings after the point of
> insertion.  It does this by using parse-partial-sexp, and checks (nth 3
> <result>) as evidence of an open string.
> 
> This does not work in CC Mode, since although there is an open string
> marker (with a string fence syntax-table property on it) this is
> "closed" (from parse-partial-sexp's point of view) by the string fence
> property on the newline at the end of the line.
> electric-pair--unbalanced-strings-p thus returns the wrong result.

The fix in that bug was to check if the just-inserted double-quote "is 
marked with a string fence syntax-table text property". That fixes the 
issue described in bug#36474, but it's not quite the right logic. CC 
Mode gives the *last* double-quote on a line the string fence property 
if a line has unbalanced quotes. Thus, the patch changes the behavior to 
check the last double-quote on the line, rather than the just-inserted 
double-quote.

The patch makes one other improvement as well: it doesn't check for the 
string fence property on a double-quote inside a comment. CC Mode 
doesn't apply string fence properties there, since it's not necessary. 
Therefore, inside a comment, `c-electric-pair-inhibit-predicate' just 
defers to the default value of `electric-pair-inhibit-predicate'.

As I mentioned earlier in the thread, this isn't quite perfect behavior, 
but it significantly improves the common case (`electric-pair-mode' with 
default or "default-like" settings). CC Mode's practice of closing 
strings at the end of a line - even without a closing quote - just 
doesn't play nicely with `electric-pair-mode', so barring some major 
changes to either CC Mode or `electric-pair-mode', I can't think of a 
way to improve this patch beyond where it's at now.





  parent reply	other threads:[~2021-09-16 17:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-12  3:58 bug#50538: [PATCH] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode Jim Porter
2021-09-12  6:26 ` Eli Zaretskii
2021-09-12 18:05   ` Jim Porter
2021-09-15 22:17     ` Jim Porter
2021-09-16  5:25       ` Eli Zaretskii
2021-09-16 12:40         ` Lars Ingebrigtsen
2021-09-16 12:59           ` Dmitry Gutov
2021-09-16 13:17             ` Lars Ingebrigtsen
2021-09-16 17:04               ` João Távora
2021-09-16 17:11                 ` Eli Zaretskii
2021-09-16 17:33                   ` João Távora
2021-09-16 17:29                 ` Jim Porter [this message]
2021-09-16 19:05                 ` Alan Mackenzie
2021-09-16 20:51                   ` João Távora
2021-09-17 18:12                     ` Alan Mackenzie
2021-09-16 18:26         ` Alan Mackenzie
2021-09-16 20:49     ` Alan Mackenzie
2021-09-16 21:36       ` Jim Porter
2021-09-17 17:08         ` Alan Mackenzie
2021-09-23  2:01           ` bug#50538: [PATCH v3] " Jim Porter
2021-09-26 20:58             ` Alan Mackenzie
2021-09-28  4:57               ` bug#50538: [PATCH v4] " Jim Porter
2021-10-03 17:58                 ` bug#50538: [PATCH v5] " Jim Porter
2021-11-06  0:22                   ` bug#50538: [PATCH] " Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16202af0-9d66-1996-8756-b3d0ff28ac9a@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=50538@debbugs.gnu.org \
    --cc=acm@muc.de \
    --cc=dgutov@yandex.ru \
    --cc=joaotavora@gmail.com \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.