unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Andrea Greselin <greselin.andrea@gmail.com>
To: 57057@debbugs.gnu.org
Subject: bug#57057: Prevent ‘electric-quote-mode’ from merging single quotes
Date: Mon, 8 Aug 2022 14:25:59 +0200	[thread overview]
Message-ID: <CAJ_oJbYZ1hCvMrEFiev3qUvbqC6iNbZ8=4FguJPjncWoKZuxTQ@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 532 bytes --]

Hello everyone,

I stumbled a couple of times across a behaviour by
‘electric-quote-mode’ where it replaces two consecutive single
electric quotes with a single double quote. To see what I mean open
‘emacs -Q’, enable ‘electric-quote-mode’ and ‘text-mode’, then hit `
or ' twice. I find it more annoying than helpful so I changed
‘electric-quote-post-self-insert-function’ to make it check an option
that can disable this behaviour. Do you think it can be included in
Emacs?

Best of wishes,
Andrea

[-- Attachment #1.2: Type: text/html, Size: 581 bytes --]

[-- Attachment #2: electric.patch --]
[-- Type: text/x-patch, Size: 1949 bytes --]

diff --git a/lisp/electric.el b/lisp/electric.el
index 042fc90..08ac447 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -534,6 +534,13 @@ closing double quote otherwise."
   :version "26.1"
   :type 'boolean :safe #'booleanp :group 'electricity)
 
+(defcustom electric-quote-replace-consecutive t
+  "Non-nil means to replace a pair of opening or closing single
+quotes with the corresponding double quote when the second quote
+of the pair is entered electrically (i.e. by typing ` or ')."
+  :version "29.1"
+  :type 'boolean :safe #'booleanp :group 'electricity)
+
 (defvar electric-quote-inhibit-functions ()
   "List of functions that should inhibit electric quoting.
 When the variable `electric-quote-mode' is non-nil, Emacs will
@@ -586,7 +593,8 @@ This requotes when a quoting key is typed."
                               (memq (char-syntax (char-before))
                                     '(?\s ?\())))
                         (setq backtick ?\')))
-               (cond ((search-backward (string q< backtick) (- (point) 2) t)
+               (cond ((and electric-quote-replace-consecutive
+                           (search-backward (string q< backtick) (- (point) 2) t))
                       (replace-match (string q<<))
                       (when (and electric-pair-mode
                                  (eq (cdr-safe
@@ -600,7 +608,8 @@ This requotes when a quoting key is typed."
                      ((search-backward "\"" (1- (point)) t)
                       (replace-match (string q<<))
                       (setq last-command-event q<<)))
-             (cond ((search-backward (string q> ?') (- (point) 2) t)
+             (cond ((and electric-quote-replace-consecutive
+                         (search-backward (string q> ?') (- (point) 2) t))
                     (replace-match (string q>>))
                     (setq last-command-event q>>))
                    ((search-backward "'" (1- (point)) t)

             reply	other threads:[~2022-08-08 12:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 12:25 Andrea Greselin [this message]
2022-08-09 18:43 ` bug#57057: Prevent ‘electric-quote-mode’ from merging single quotes Lars Ingebrigtsen
2022-08-09 21:43   ` Andrea Greselin

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='CAJ_oJbYZ1hCvMrEFiev3qUvbqC6iNbZ8=4FguJPjncWoKZuxTQ@mail.gmail.com' \
    --to=greselin.andrea@gmail.com \
    --cc=57057@debbugs.gnu.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).