aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2020-04-13 02:40:56 +0300
committerJuri Linkov2020-04-13 02:40:56 +0300
commit91e4acf7c736dfdb2673dc33c9303b5284e925df (patch)
treee72ce8d84512ee75701424fdac26560c94ee88f7 /lisp
parent68ffe4a3c9a001db528b057109d11de71471e4ff (diff)
downloademacs-91e4acf7c736dfdb2673dc33c9303b5284e925df.tar.gz
emacs-91e4acf7c736dfdb2673dc33c9303b5284e925df.zip
Fix hi-lock test and add new test for case-fold (bug#40337)
* lisp/hi-lock.el (hi-lock--regexps-at-point): Handle font-lock faces. (hi-lock-unface-buffer): Simplify default value handling. (hi-lock-set-pattern): Add either lighter or regexp to hi-lock-interactive-lighters. (hi-lock-set-pattern): Put overlay prop hi-lock-overlay-regexp to either lighter or regexp. * test/lisp/hi-lock-tests.el (hi-lock-bug26666): Use "b" instead of "a". (hi-lock-case-fold): New test.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/hi-lock.el37
1 files changed, 18 insertions, 19 deletions
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index d5e46651a50..1d8dc0624ba 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -564,13 +564,15 @@ in which case the highlighting will not update as you type."
564 (let ((regexp (get-char-property (point) 'hi-lock-overlay-regexp))) 564 (let ((regexp (get-char-property (point) 'hi-lock-overlay-regexp)))
565 (when regexp (push regexp regexps))) 565 (when regexp (push regexp regexps)))
566 ;; With font-locking on, check if the cursor is on a highlighted text. 566 ;; With font-locking on, check if the cursor is on a highlighted text.
567 (let ((face-after (get-text-property (point) 'face)) 567 (let* ((faces-after (get-text-property (point) 'face))
568 (face-before 568 (faces-before
569 (unless (bobp) (get-text-property (1- (point)) 'face))) 569 (unless (bobp) (get-text-property (1- (point)) 'face)))
570 (faces (mapcar #'hi-lock-keyword->face 570 (faces-after (if (consp faces-after) faces-after (list faces-after)))
571 hi-lock-interactive-patterns))) 571 (faces-before (if (consp faces-before) faces-before (list faces-before)))
572 (unless (memq face-before faces) (setq face-before nil)) 572 (faces (mapcar #'hi-lock-keyword->face
573 (unless (memq face-after faces) (setq face-after nil)) 573 hi-lock-interactive-patterns))
574 (face-after (seq-some (lambda (face) (car (memq face faces))) faces-after))
575 (face-before (seq-some (lambda (face) (car (memq face faces))) faces-before)))
574 (when (and face-before face-after (not (eq face-before face-after))) 576 (when (and face-before face-after (not (eq face-before face-after)))
575 (setq face-before nil)) 577 (setq face-before nil))
576 (when (or face-after face-before) 578 (when (or face-after face-before)
@@ -588,7 +590,8 @@ in which case the highlighting will not update as you type."
588 ;; highlighted text at point. Use this later in 590 ;; highlighted text at point. Use this later in
589 ;; during completing-read. 591 ;; during completing-read.
590 (dolist (hi-lock-pattern hi-lock-interactive-patterns) 592 (dolist (hi-lock-pattern hi-lock-interactive-patterns)
591 (let ((regexp (car hi-lock-pattern))) 593 (let ((regexp (or (car (rassq hi-lock-pattern hi-lock-interactive-lighters))
594 (car hi-lock-pattern))))
592 (if (string-match regexp hi-text) 595 (if (string-match regexp hi-text)
593 (push regexp regexps))))))) 596 (push regexp regexps)))))))
594 regexps)) 597 regexps))
@@ -642,15 +645,10 @@ then remove all hi-lock highlighting."
642 (user-error "No highlighting to remove")) 645 (user-error "No highlighting to remove"))
643 ;; Infer the regexp to un-highlight based on cursor position. 646 ;; Infer the regexp to un-highlight based on cursor position.
644 (let* ((defaults (or (hi-lock--regexps-at-point) 647 (let* ((defaults (or (hi-lock--regexps-at-point)
645 (mapcar #'car hi-lock-interactive-patterns)))) 648 (mapcar (lambda (pattern)
646 (setq defaults 649 (or (car (rassq pattern hi-lock-interactive-lighters))
647 (mapcar (lambda (default) 650 (car pattern)))
648 (or (car (rassq default 651 hi-lock-interactive-patterns))))
649 (mapcar (lambda (a)
650 (cons (car a) (cadr a)))
651 hi-lock-interactive-lighters)))
652 default))
653 defaults))
654 (list 652 (list
655 (completing-read (if (null defaults) 653 (completing-read (if (null defaults)
656 "Regexp to unhighlight: " 654 "Regexp to unhighlight: "
@@ -767,7 +765,8 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search."
767 (list subexp (list 'quote face) 'prepend))) 765 (list subexp (list 'quote face) 'prepend)))
768 (no-matches t)) 766 (no-matches t))
769 ;; Refuse to highlight a text that is already highlighted. 767 ;; Refuse to highlight a text that is already highlighted.
770 (if (assoc regexp hi-lock-interactive-patterns) 768 (if (or (assoc regexp hi-lock-interactive-patterns)
769 (assoc (or lighter regexp) hi-lock-interactive-lighters))
771 (add-to-list 'hi-lock--unused-faces (face-name face)) 770 (add-to-list 'hi-lock--unused-faces (face-name face))
772 (push pattern hi-lock-interactive-patterns) 771 (push pattern hi-lock-interactive-patterns)
773 (push (cons (or lighter regexp) pattern) hi-lock-interactive-lighters) 772 (push (cons (or lighter regexp) pattern) hi-lock-interactive-lighters)
@@ -792,7 +791,7 @@ SPACES-REGEXP is a regexp to substitute spaces in font-lock search."
792 (let ((overlay (make-overlay (match-beginning subexp) 791 (let ((overlay (make-overlay (match-beginning subexp)
793 (match-end subexp)))) 792 (match-end subexp))))
794 (overlay-put overlay 'hi-lock-overlay t) 793 (overlay-put overlay 'hi-lock-overlay t)
795 (overlay-put overlay 'hi-lock-overlay-regexp regexp) 794 (overlay-put overlay 'hi-lock-overlay-regexp (or lighter regexp))
796 (overlay-put overlay 'face face)) 795 (overlay-put overlay 'face face))
797 (goto-char (match-end 0))) 796 (goto-char (match-end 0)))
798 (when no-matches 797 (when no-matches