diff options
| author | Philipp Stephani | 2017-07-03 18:46:10 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-07-03 20:59:31 +0200 |
| commit | 4cd0db3d6e6e4d5bd49283483bdafbbfc0f583f1 (patch) | |
| tree | 4363283d8e790be49490ce2123f32db811e083f9 | |
| parent | 9ac7dccc51ee834b06cdabf6a5746eb375f984f0 (diff) | |
| download | emacs-4cd0db3d6e6e4d5bd49283483bdafbbfc0f583f1.tar.gz emacs-4cd0db3d6e6e4d5bd49283483bdafbbfc0f583f1.zip | |
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.
| -rw-r--r-- | etc/NEWS | 12 | ||||
| -rw-r--r-- | lisp/electric.el | 19 | ||||
| -rw-r--r-- | test/lisp/electric-tests.el | 16 |
3 files changed, 30 insertions, 17 deletions
| @@ -138,12 +138,12 @@ line, after a whitespace character, and after an opening parenthesis; | |||
| 138 | and it will replace the apostrophe by a closing quote character in all | 138 | and it will replace the apostrophe by a closing quote character in all |
| 139 | other cases. | 139 | other cases. |
| 140 | 140 | ||
| 141 | ** The new variable 'electric-quote-code-faces' controls when to | 141 | ** The new variable 'electric-quote-inhibit-functions' controls when |
| 142 | disable electric quoting in text modes. Major modes can add faces to | 142 | to disable electric quoting based on context. Major modes can add |
| 143 | this list; Emacs will temporarily disable 'electric-quote-mode' | 143 | functions to this list; Emacs will temporarily disable |
| 144 | whenever point is before a character having such a face. This is | 144 | 'electric-quote-mode' whenever any of the functions returns non-nil. |
| 145 | intended for major modes that derive from 'text-mode' but allow inline | 145 | This can be used by major modes that derive from 'text-mode' but allow |
| 146 | code segments, such as 'markdown-mode'. | 146 | inline 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. |
| 456 | When the variable `electric-quote-mode' is non-nil, Emacs will | ||
| 457 | call these functions in order after the user has typed an \\=` or | ||
| 458 | \\=' character. If one of them returns non-nil, electric quote | ||
| 459 | substitution is inhibited. The functions are called after the | ||
| 460 | \\=` or \\=' character has been inserted with point directly | ||
| 461 | after the inserted character. The functions in this hook should | ||
| 462 | not 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) |