summaryrefslogtreecommitdiff
path: root/lisp/electric.el
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2017-07-03 18:46:10 +0200
committerPhilipp Stephani <phst@google.com>2017-07-03 20:59:31 +0200
commit4cd0db3d6e6e4d5bd49283483bdafbbfc0f583f1 (patch)
tree4363283d8e790be49490ce2123f32db811e083f9 /lisp/electric.el
parent9ac7dccc51ee834b06cdabf6a5746eb375f984f0 (diff)
downloademacs-4cd0db3d6e6e4d5bd49283483bdafbbfc0f583f1.tar.gz
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.
Diffstat (limited to 'lisp/electric.el')
-rw-r--r--lisp/electric.el19
1 files changed, 12 insertions, 7 deletions
diff --git a/lisp/electric.el b/lisp/electric.el
index 1564df5949c..4c1d9039d9a 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -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 ?\`)