Commit 4cd0db3d authored by Philipp Stephani's avatar Philipp Stephani
Browse files

Use hook instead of face list to inhibit electric quoting

This is more flexible and doesn't couple electric quoting to font
locking.
Give that 'electric-quote-code-faces' was just introduced, remove it
without formal deprecation.

* lisp/electric.el (electric-quote-inhibit-functions): New abnormal
hook variable.
(electric-quote-post-self-insert-function): Run the hook.  Remove
use of old 'electric-quote-code-faces' variable.

* test/lisp/electric-tests.el (electric-quote-markdown-in-text)
(electric-quote-markdown-in-code): Adapt unit tests.
parent 9ac7dccc
......@@ -138,12 +138,12 @@ line, after a whitespace character, and after an opening parenthesis;
and it will replace the apostrophe by a closing quote character in all
other cases.
** The new variable 'electric-quote-code-faces' controls when to
disable electric quoting in text modes. Major modes can add faces to
this list; Emacs will temporarily disable 'electric-quote-mode'
whenever point is before a character having such a face. This is
intended for major modes that derive from 'text-mode' but allow inline
code segments, such as 'markdown-mode'.
** The new variable 'electric-quote-inhibit-functions' controls when
to disable electric quoting based on context. Major modes can add
functions to this list; Emacs will temporarily disable
'electric-quote-mode' whenever any of the functions returns non-nil.
This can be used by major modes that derive from 'text-mode' but allow
inline code segments, such as 'markdown-mode'.
+++
** The new user variable 'dired-omit-case-fold' allows the user to
......
......@@ -451,8 +451,15 @@ whitespace, opening parenthesis, or quote and leaves \\=` alone."
:version "26.1"
:type 'boolean :safe #'booleanp :group 'electricity)
(defvar electric-quote-code-faces ()
"List of faces to treat as inline code in `text-mode'.")
(defvar electric-quote-inhibit-functions ()
"List of functions that should inhibit electric quoting.
When the variable `electric-quote-mode' is non-nil, Emacs will
call these functions in order after the user has typed an \\=` or
\\=' character. If one of them returns non-nil, electric quote
substitution is inhibited. The functions are called after the
\\=` or \\=' character has been inserted with point directly
after the inserted character. The functions in this hook should
not move point or change the current buffer.")
(defun electric-quote-post-self-insert-function ()
"Function that `electric-quote-mode' adds to `post-self-insert-hook'.
......@@ -460,7 +467,9 @@ This requotes when a quoting key is typed."
(when (and electric-quote-mode
(or (eq last-command-event ?\')
(and (not electric-quote-context-sensitive)
(eq last-command-event ?\`))))
(eq last-command-event ?\`)))
(not (run-hook-with-args-until-success
'electric-quote-inhibit-functions)))
(let ((start
(if (and comment-start comment-use-syntax)
(when (or electric-quote-comment electric-quote-string)
......@@ -475,10 +484,6 @@ This requotes when a quoting key is typed."
(syntax-ppss (1- (point)))))))))
(and electric-quote-paragraph
(derived-mode-p 'text-mode)
;; FIXME: There should be a ‘cl-disjoint’ function.
(null (cl-intersection (face-at-point nil 'multiple)
electric-quote-code-faces
:test #'eq))
;; FIXME: Why is the next form there? It’s never
;; nil.
(or (eq last-command-event ?\`)
......
......@@ -697,16 +697,24 @@ baz\"\""
(define-electric-pair-test electric-quote-markdown-in-text
"" "'" :expected-string "’" :expected-point 2
:modes '(text-mode)
:fixture-fn #'electric-quote-local-mode
:bindings '((electric-quote-code-faces font-lock-constant-face))
:fixture-fn (lambda ()
(electric-quote-local-mode)
(add-hook 'electric-quote-inhibit-functions
(lambda ()
(save-excursion (search-backward "`" nil t)))
nil :local))
:test-in-comments nil :test-in-strings nil)
(define-electric-pair-test electric-quote-markdown-in-code
#("`a`" 1 2 (face font-lock-constant-face)) "-'"
:expected-string "`'a`" :expected-point 3
:modes '(text-mode)
:fixture-fn #'electric-quote-local-mode
:bindings '((electric-quote-code-faces font-lock-constant-face))
:fixture-fn (lambda ()
(electric-quote-local-mode)
(add-hook 'electric-quote-inhibit-functions
(lambda ()
(save-excursion (search-backward "`" nil t)))
nil :local))
:test-in-comments nil :test-in-strings nil)
(provide 'electric-tests)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment