From 41169b55340878120fdf695eb4ac1fcb2679e7b8 Mon Sep 17 00:00:00 2001 From: Andrea Greselin Date: Tue, 9 Aug 2022 20:43:08 +0200 Subject: [PATCH] Add new user option electric-quote-replace-consecutive * lisp/electric.el (electric-quote-replace-consecutive): New user option (bug#57057). (electric-quote-post-self-insert-function): Use it. --- etc/NEWS | 3 +++ lisp/electric.el | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 9e509bc56e6..78f60d64cd0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -375,6 +375,9 @@ option) and can be set to nil to disable Just-in-time Lock mode. * Changes in Emacs 29.1 +--- +** New user option 'electric-quote-replace-consecutive'. + --- ** Emacs is now capable of editing files with very long lines. The display of long lines has been optimized, and Emacs should no diff --git a/lisp/electric.el b/lisp/electric.el index 0cf3a299cfa..f2ff837333f 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -540,6 +540,16 @@ 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 single quotes with a double quote. +Two single quotes are replaced by the corresponding double quote +when the second quote of the pair is entered (i.e. by typing ` or +') by default. If nil, the single quotes are not altered." + :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 @@ -592,7 +602,9 @@ 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 @@ -606,7 +618,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) @@ -627,7 +640,7 @@ and text paragraphs, and these are selectively controlled with `electric-quote-paragraph'. Customize `electric-quote-chars' to use characters other than the -ones listed here. +ones listed here. Also see `electric-quote-replace-consecutive'. This is a global minor mode. To toggle the mode in a single buffer, use `electric-quote-local-mode'."