From: Robert Pluim Date: Mon, 3 Jun 2024 12:00:56 +0000 (+0200) Subject: Add common pairs to defcustom for electric-quote-chars X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2907126c74ef552c49031301e1327bc938e5f910;p=emacs.git Add common pairs to defcustom for electric-quote-chars * lisp/electric.el (electric--print-list-of-chars): New function to display chars as chars instead of integers in a custom widget. (electric-char-pair): New widget for displaying a pair of characters. (electric-quote-chars-pairs): New widget. Contains presets for common combinations of left/right quotation characters (electric-quote-chars): Update to use 'electric-quote-chars-pairs'. * etc/NEWS: Announce the change. (cherry picked from commit 62d6ba2ede95805ba309bdc538628eb49b331f03) --- diff --git a/etc/NEWS b/etc/NEWS index 8325b5ef2d6..a0a98d2b797 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -120,6 +120,12 @@ function to the advice to remove. ** Emacs now supports Unicode Standard version 15.1. +** New pre-defined values for 'electric-quote-chars'. +The available customization options for 'electric-quote-chars' have been +updated with common pairs of quotation characters, including "‘", "’", +"“", "”", "«", "»", "‹", "›", "‚", "„", "「", "」", "『", and "』". +The default is unchanged. + ** Network Security Manager +++ diff --git a/lisp/electric.el b/lisp/electric.el index fee0bf36d7f..d02bcb4735b 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -506,12 +506,64 @@ The variable `electric-layout-rules' says when and how to insert newlines." :version "25.1" :type 'boolean :safe 'booleanp :group 'electricity) +;; The default :value-create produces "list of numbers" when given "list +;; of characters", this prints them as characters. +(defun electric--print-list-of-chars (widget) + (let ((print-integers-as-characters t)) + (princ (widget-get widget :value) (current-buffer)))) + +;; This is just so we can make pairs print as characters. +(define-widget 'electric-char-pair 'const + "Electric quote character pair." + :group 'electricity + :format "%t: %v\n" + :inline t + :value-create #'electric--print-list-of-chars + :type '(list character character)) + +(define-widget 'electric-quote-chars-pairs 'lazy + "Choose pair of electric quote chars." + :group 'electricity + :type '(radio + (electric-char-pair :tag "Single" (?‘ ?’)) + (electric-char-pair :tag "Double" (?“ ?”)) + (electric-char-pair :tag "Guillemets" (?« ?»)) + (electric-char-pair :tag "Single guillemets" (?‹ ?›)) + (electric-char-pair :tag "Corners" (?「 ?」)) + (electric-char-pair :tag "Double corners" (?『 ?』)) + (electric-char-pair :tag "Low/high single left" (?‚ ?‘)) + (electric-char-pair :tag "Low/high double left" (?„ ?“)) + (electric-char-pair :tag "Low/high single right" (?‚ ?’)) + (electric-char-pair :tag "Low/high double right" (?„ ?”)) + (electric-char-pair :tag "Single inverted" (?’ ?‘)) + (electric-char-pair :tag "Right single only" (?’ ?’)) + (electric-char-pair :tag "Right double only" (?” ?”)) + (electric-char-pair :tag "Guillemets inverted" (?» ?«)) + (electric-char-pair :tag "Guillemets right only" (?» ?»)) + (electric-char-pair :tag "Single guillemets inverted" (?› ?‹)) + (electric-char-pair :tag "Mathematical double angle" (?⟪ ?⟫)) + (electric-char-pair :tag "Mathematical single angle" (?⟨ ?⟩)) + (electric-char-pair :tag "Double angle" (?《 ?》)) + (electric-char-pair :tag "Single angle" (?〈 ?〉)))) + (defcustom electric-quote-chars '(?‘ ?’ ?“ ?”) "Curved quote characters for `electric-quote-mode'. This list's members correspond to left single quote, right single -quote, left double quote, and right double quote, respectively." +quote, left double quote, and right double quote, respectively. + +Commonly used pairs are predefined, or you can define your own +completely custom style." :version "26.1" - :type '(list character character character character) + :type '(choice + (const :format "%t: %v\n" :tag "Default" + :value-create electric--print-list-of-chars + (?‘ ?’ ?“ ?”)) + (list :tag "Predefined pairs" + (electric-quote-chars-pairs :tag "Single quotes") + (electric-quote-chars-pairs :tag "Double quotes")) + (list :tag "Custom" + (character ?‘) (character ?’) + (character ?“) (character ?”))) :safe (lambda (x) (pcase x (`(,(pred characterp) ,(pred characterp)