help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to control pairing of quotes in text-mode with electric-pair-mode?


From: Andrea Greselin
Subject: How to control pairing of quotes in text-mode with electric-pair-mode?
Date: Fri, 5 Jul 2019 11:40:49 +0200

Hello,

I'd like 'electric-pair-mode' not to pair quotes at the end of words or
following punctuation characters, as in "…end of quote" or "… end of quote."

I've written this function for 'electric-pair-inhibit-predicate', based on
'electric-pair-conservative-inhibit':

    (defun my-electric-pair-inhibit (char)
      (or
       ;; Do not pair when the same char is next.
       (eq char (char-after))
       ;; Do not pair right before a word.
       (eq (char-syntax (following-char)) ?w)
       ;; After a word or a punctuation character, pair parentheses but do
not pair quotes.
       (when (and (> (point) 2) (char-equal char ?\"))
         (or (eq (char-syntax (char-before (1- (point)))) ?w)
             (eq (char-syntax (char-before (1- (point)))) ?.)))))

It works fine in 'emacs-lisp-mode' but it doesn't in 'text-mode': quotes
are still paired around words. I've noticed that it's the same with
'electric-pair-inhibit-predicate' set to
'electric-pair-conservative-inhibit', which should suppress pairing at the
beginning of words: in 'emacs-lisp-mode' both parentheses and quotes are
not paired at the beginning of words, but in 'text-mode' only parentheses
pairing is suppressed.

All the best,
Andrea


reply via email to

[Prev in Thread] Current Thread [Next in Thread]