aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS12
-rw-r--r--lisp/electric.el19
-rw-r--r--test/lisp/electric-tests.el16
3 files changed, 30 insertions, 17 deletions
diff --git a/etc/NEWS b/etc/NEWS
index a766642ef22..83cb73f4a98 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -138,12 +138,12 @@ line, after a whitespace character, and after an opening parenthesis;
138and it will replace the apostrophe by a closing quote character in all 138and it will replace the apostrophe by a closing quote character in all
139other cases. 139other cases.
140 140
141** The new variable 'electric-quote-code-faces' controls when to 141** The new variable 'electric-quote-inhibit-functions' controls when
142disable electric quoting in text modes. Major modes can add faces to 142to disable electric quoting based on context. Major modes can add
143this list; Emacs will temporarily disable 'electric-quote-mode' 143functions to this list; Emacs will temporarily disable
144whenever point is before a character having such a face. This is 144'electric-quote-mode' whenever any of the functions returns non-nil.
145intended for major modes that derive from 'text-mode' but allow inline 145This can be used by major modes that derive from 'text-mode' but allow
146code segments, such as 'markdown-mode'. 146inline code segments, such as 'markdown-mode'.
147 147
148+++ 148+++
149** The new user variable 'dired-omit-case-fold' allows the user to 149** The new user variable 'dired-omit-case-fold' allows the user to
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."
451 :version "26.1" 451 :version "26.1"
452 :type 'boolean :safe #'booleanp :group 'electricity) 452 :type 'boolean :safe #'booleanp :group 'electricity)
453 453
454(defvar electric-quote-code-faces () 454(defvar electric-quote-inhibit-functions ()
455 "List of faces to treat as inline code in `text-mode'.") 455 "List of functions that should inhibit electric quoting.
456When the variable `electric-quote-mode' is non-nil, Emacs will
457call these functions in order after the user has typed an \\=` or
458\\=' character. If one of them returns non-nil, electric quote
459substitution is inhibited. The functions are called after the
460\\=` or \\=' character has been inserted with point directly
461after the inserted character. The functions in this hook should
462not move point or change the current buffer.")
456 463
457(defun electric-quote-post-self-insert-function () 464(defun electric-quote-post-self-insert-function ()
458 "Function that `electric-quote-mode' adds to `post-self-insert-hook'. 465 "Function that `electric-quote-mode' adds to `post-self-insert-hook'.
@@ -460,7 +467,9 @@ This requotes when a quoting key is typed."
460 (when (and electric-quote-mode 467 (when (and electric-quote-mode
461 (or (eq last-command-event ?\') 468 (or (eq last-command-event ?\')
462 (and (not electric-quote-context-sensitive) 469 (and (not electric-quote-context-sensitive)
463 (eq last-command-event ?\`)))) 470 (eq last-command-event ?\`)))
471 (not (run-hook-with-args-until-success
472 'electric-quote-inhibit-functions)))
464 (let ((start 473 (let ((start
465 (if (and comment-start comment-use-syntax) 474 (if (and comment-start comment-use-syntax)
466 (when (or electric-quote-comment electric-quote-string) 475 (when (or electric-quote-comment electric-quote-string)
@@ -475,10 +484,6 @@ This requotes when a quoting key is typed."
475 (syntax-ppss (1- (point))))))))) 484 (syntax-ppss (1- (point)))))))))
476 (and electric-quote-paragraph 485 (and electric-quote-paragraph
477 (derived-mode-p 'text-mode) 486 (derived-mode-p 'text-mode)
478 ;; FIXME: There should be a ‘cl-disjoint’ function.
479 (null (cl-intersection (face-at-point nil 'multiple)
480 electric-quote-code-faces
481 :test #'eq))
482 ;; FIXME: Why is the next form there? It’s never 487 ;; FIXME: Why is the next form there? It’s never
483 ;; nil. 488 ;; nil.
484 (or (eq last-command-event ?\`) 489 (or (eq last-command-event ?\`)
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index 6f63d30e755..9dd27661d46 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -697,16 +697,24 @@ baz\"\""
697(define-electric-pair-test electric-quote-markdown-in-text 697(define-electric-pair-test electric-quote-markdown-in-text
698 "" "'" :expected-string "’" :expected-point 2 698 "" "'" :expected-string "’" :expected-point 2
699 :modes '(text-mode) 699 :modes '(text-mode)
700 :fixture-fn #'electric-quote-local-mode 700 :fixture-fn (lambda ()
701 :bindings '((electric-quote-code-faces font-lock-constant-face)) 701 (electric-quote-local-mode)
702 (add-hook 'electric-quote-inhibit-functions
703 (lambda ()
704 (save-excursion (search-backward "`" nil t)))
705 nil :local))
702 :test-in-comments nil :test-in-strings nil) 706 :test-in-comments nil :test-in-strings nil)
703 707
704(define-electric-pair-test electric-quote-markdown-in-code 708(define-electric-pair-test electric-quote-markdown-in-code
705 #("`a`" 1 2 (face font-lock-constant-face)) "-'" 709 #("`a`" 1 2 (face font-lock-constant-face)) "-'"
706 :expected-string "`'a`" :expected-point 3 710 :expected-string "`'a`" :expected-point 3
707 :modes '(text-mode) 711 :modes '(text-mode)
708 :fixture-fn #'electric-quote-local-mode 712 :fixture-fn (lambda ()
709 :bindings '((electric-quote-code-faces font-lock-constant-face)) 713 (electric-quote-local-mode)
714 (add-hook 'electric-quote-inhibit-functions
715 (lambda ()
716 (save-excursion (search-backward "`" nil t)))
717 nil :local))
710 :test-in-comments nil :test-in-strings nil) 718 :test-in-comments nil :test-in-strings nil)
711 719
712(provide 'electric-tests) 720(provide 'electric-tests)