diff options
| author | Tino Calancha | 2017-04-27 12:01:19 +0900 |
|---|---|---|
| committer | Tino Calancha | 2017-04-27 12:01:19 +0900 |
| commit | 9af2ecc36d1d15bb63fb6b28a9b5baa6990f79b8 (patch) | |
| tree | 0ebd547d5aa6cc21b7afa6098e1565ecd834ec9f | |
| parent | 2058ed65fba79ecdbda6604683540bf9f9860bae (diff) | |
| download | emacs-9af2ecc36d1d15bb63fb6b28a9b5baa6990f79b8.tar.gz emacs-9af2ecc36d1d15bb63fb6b28a9b5baa6990f79b8.zip | |
Drop face from hi-lock--unused-faces only when used
* lisp/hi-lock.el (hi-lock-set-pattern): If REGEXP is already
highlighted, then push FACE into hi-lock--unused-faces (Bug#26666).
* test/lisp/hi-lock-tests.el (hi-lock-bug26666): Add test.
| -rw-r--r-- | lisp/hi-lock.el | 3 | ||||
| -rw-r--r-- | test/lisp/hi-lock-tests.el | 40 |
2 files changed, 42 insertions, 1 deletions
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index ebd18621ef9..5139e01fa84 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el | |||
| @@ -695,7 +695,8 @@ with completion and history." | |||
| 695 | (setq regexp (hi-lock--hashcons regexp)) | 695 | (setq regexp (hi-lock--hashcons regexp)) |
| 696 | (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend)))) | 696 | (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend)))) |
| 697 | ;; Refuse to highlight a text that is already highlighted. | 697 | ;; Refuse to highlight a text that is already highlighted. |
| 698 | (unless (assoc regexp hi-lock-interactive-patterns) | 698 | (if (assoc regexp hi-lock-interactive-patterns) |
| 699 | (add-to-list 'hi-lock--unused-faces (face-name face)) | ||
| 699 | (push pattern hi-lock-interactive-patterns) | 700 | (push pattern hi-lock-interactive-patterns) |
| 700 | (if (and font-lock-mode (font-lock-specified-p major-mode)) | 701 | (if (and font-lock-mode (font-lock-specified-p major-mode)) |
| 701 | (progn | 702 | (progn |
diff --git a/test/lisp/hi-lock-tests.el b/test/lisp/hi-lock-tests.el new file mode 100644 index 00000000000..2cb662cfaca --- /dev/null +++ b/test/lisp/hi-lock-tests.el | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | ;;; hi-lock-tests.el --- Tests for hi-lock.el -*- lexical-binding: t; -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Tino Calancha <tino.calancha@gmail.com> | ||
| 6 | ;; Keywords: | ||
| 7 | |||
| 8 | ;; This program is free software; you can redistribute it and/or modify | ||
| 9 | ;; it under the terms of the GNU General Public License as published by | ||
| 10 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 11 | ;; (at your option) any later version. | ||
| 12 | |||
| 13 | ;; This program is distributed in the hope that it will be useful, | ||
| 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | ;; GNU General Public License for more details. | ||
| 17 | |||
| 18 | ;; You should have received a copy of the GNU General Public License | ||
| 19 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | |||
| 21 | ;;; Code: | ||
| 22 | |||
| 23 | (require 'ert) | ||
| 24 | (require 'hi-lock) | ||
| 25 | |||
| 26 | (ert-deftest hi-lock-bug26666 () | ||
| 27 | "Test for http://debbugs.gnu.org/26666 ." | ||
| 28 | (let ((faces hi-lock-face-defaults)) | ||
| 29 | (with-temp-buffer | ||
| 30 | (insert "a A b B\n") | ||
| 31 | (cl-letf (((symbol-function 'completing-read) | ||
| 32 | (lambda (prompt coll x y z hist defaults) | ||
| 33 | (car defaults)))) | ||
| 34 | (dotimes (_ 2) | ||
| 35 | (let ((face (hi-lock-read-face-name))) | ||
| 36 | (hi-lock-set-pattern "a" face)))) | ||
| 37 | (should (equal hi-lock--unused-faces (cdr faces)))))) | ||
| 38 | |||
| 39 | (provide 'hi-lock-tests) | ||
| 40 | ;;; hi-lock-tests.el ends here | ||