diff options
| author | Juri Linkov | 2020-04-12 02:45:02 +0300 |
|---|---|---|
| committer | Juri Linkov | 2020-04-12 02:45:02 +0300 |
| commit | 86b820752349de572bfbb306cc0d8f7cea41d0a7 (patch) | |
| tree | 31fd8df7c51e4ec37fba45a3273f7da78b666e49 | |
| parent | e7b4233d9bccf4f65c008682eef4f88d0f003d6d (diff) | |
| download | emacs-86b820752349de572bfbb306cc0d8f7cea41d0a7.tar.gz emacs-86b820752349de572bfbb306cc0d8f7cea41d0a7.zip | |
Implement case-insensitivity in hi-lock (bug#40337)
* lisp/hi-lock.el (hi-lock-interactive-lighters): New buffer-local variable.
(hi-lock-mode): Set hi-lock-interactive-lighters to nil.
(hi-lock-line-face-buffer): Use case-fold-search and search-upper-case.
(hi-lock-face-buffer): Add new arg LIGHTER. Use case-fold-search,
search-upper-case and search-spaces-regexp.
(hi-lock-face-phrase-buffer): Don't call hi-lock-process-phrase.
Use case-fold-search, search-upper-case and search-whitespace-regexp.
(hi-lock-face-symbol-at-point): Use case-fold-search and search-upper-case.
(hi-lock-unface-buffer): Use hi-lock-interactive-lighters to get
a human-readable string for completion and x-popup-menu.
(hi-lock-process-phrase): Remove function.
(hi-lock-set-pattern): Add new args LIGHTER, CASE-FOLD, SPACES-REGEXP.
Set font-lock pattern to a search function. Add mapping from
lighter or regexp to pattern to hi-lock-interactive-lighters.
Let-bind case-fold-search and search-spaces-regexp in search functions.
* lisp/isearch.el (isearch--highlight-regexp-or-lines): Replace ugly code
with let-binding of case-fold-search, search-upper-case, search-spaces-regexp.
(isearch-highlight-regexp, isearch-highlight-lines-matching-regexp):
Use lambda.
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/hi-lock.el | 139 | ||||
| -rw-r--r-- | lisp/isearch.el | 33 |
3 files changed, 117 insertions, 62 deletions
| @@ -257,6 +257,13 @@ case-insensitive matching of messages when the old behaviour is | |||
| 257 | required, but the recommended solution is to use a correctly matching | 257 | required, but the recommended solution is to use a correctly matching |
| 258 | regexp instead. | 258 | regexp instead. |
| 259 | 259 | ||
| 260 | ** Hi-Lock | ||
| 261 | |||
| 262 | *** Matching in 'hi-lock-mode' is case-sensitive when regexp contains | ||
| 263 | upper case characters and `search-upper-case' is non-nil. | ||
| 264 | 'highlight-phrase' also uses 'search-whitespace-regexp' | ||
| 265 | to substitute spaces in regexp search. | ||
| 266 | |||
| 260 | ** Texinfo | 267 | ** Texinfo |
| 261 | 268 | ||
| 262 | --- | 269 | --- |
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index de258935e18..41d1094f237 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el | |||
| @@ -233,6 +233,10 @@ Instead, each hi-lock command will cycle through the faces in | |||
| 233 | "Patterns provided to hi-lock by user. Should not be changed.") | 233 | "Patterns provided to hi-lock by user. Should not be changed.") |
| 234 | (put 'hi-lock-interactive-patterns 'permanent-local t) | 234 | (put 'hi-lock-interactive-patterns 'permanent-local t) |
| 235 | 235 | ||
| 236 | (defvar-local hi-lock-interactive-lighters nil | ||
| 237 | "Human-readable lighters for `hi-lock-interactive-patterns'.") | ||
| 238 | (put 'hi-lock-interactive-lighters 'permanent-local t) | ||
| 239 | |||
| 236 | (define-obsolete-variable-alias 'hi-lock-face-history | 240 | (define-obsolete-variable-alias 'hi-lock-face-history |
| 237 | 'hi-lock-face-defaults "23.1") | 241 | 'hi-lock-face-defaults "23.1") |
| 238 | (defvar hi-lock-face-defaults | 242 | (defvar hi-lock-face-defaults |
| @@ -403,7 +407,8 @@ versions before 22 use the following in your init file: | |||
| 403 | hi-lock-file-patterns) | 407 | hi-lock-file-patterns) |
| 404 | (when hi-lock-interactive-patterns | 408 | (when hi-lock-interactive-patterns |
| 405 | (font-lock-remove-keywords nil hi-lock-interactive-patterns) | 409 | (font-lock-remove-keywords nil hi-lock-interactive-patterns) |
| 406 | (setq hi-lock-interactive-patterns nil)) | 410 | (setq hi-lock-interactive-patterns nil |
| 411 | hi-lock-interactive-lighters nil)) | ||
| 407 | (when hi-lock-file-patterns | 412 | (when hi-lock-file-patterns |
| 408 | (font-lock-remove-keywords nil hi-lock-file-patterns) | 413 | (font-lock-remove-keywords nil hi-lock-file-patterns) |
| 409 | (setq hi-lock-file-patterns nil)) | 414 | (setq hi-lock-file-patterns nil)) |
| @@ -434,6 +439,9 @@ of text in those lines. | |||
| 434 | Interactively, prompt for REGEXP using `read-regexp', then FACE. | 439 | Interactively, prompt for REGEXP using `read-regexp', then FACE. |
| 435 | Use the global history list for FACE. | 440 | Use the global history list for FACE. |
| 436 | 441 | ||
| 442 | If REGEXP contains upper case characters (excluding those preceded by `\\') | ||
| 443 | and `search-upper-case' is non-nil, the matching is case-sensitive. | ||
| 444 | |||
| 437 | Use Font lock mode, if enabled, to highlight REGEXP. Otherwise, | 445 | Use Font lock mode, if enabled, to highlight REGEXP. Otherwise, |
| 438 | use overlays for highlighting. If overlays are used, the | 446 | use overlays for highlighting. If overlays are used, the |
| 439 | highlighting will not update as you type." | 447 | highlighting will not update as you type." |
| @@ -447,19 +455,29 @@ highlighting will not update as you type." | |||
| 447 | (hi-lock-set-pattern | 455 | (hi-lock-set-pattern |
| 448 | ;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ? | 456 | ;; The \\(?:...\\) grouping construct ensures that a leading ^, +, * or ? |
| 449 | ;; or a trailing $ in REGEXP will be interpreted correctly. | 457 | ;; or a trailing $ in REGEXP will be interpreted correctly. |
| 450 | (concat "^.*\\(?:" regexp "\\).*\\(?:$\\)\n?") face)) | 458 | (concat "^.*\\(?:" regexp "\\).*\\(?:$\\)\n?") face nil nil |
| 459 | (if (and case-fold-search search-upper-case) | ||
| 460 | (isearch-no-upper-case-p regexp t) | ||
| 461 | case-fold-search))) | ||
| 451 | 462 | ||
| 452 | 463 | ||
| 453 | ;;;###autoload | 464 | ;;;###autoload |
| 454 | (defalias 'highlight-regexp 'hi-lock-face-buffer) | 465 | (defalias 'highlight-regexp 'hi-lock-face-buffer) |
| 455 | ;;;###autoload | 466 | ;;;###autoload |
| 456 | (defun hi-lock-face-buffer (regexp &optional face subexp) | 467 | (defun hi-lock-face-buffer (regexp &optional face subexp lighter) |
| 457 | "Set face of each match of REGEXP to FACE. | 468 | "Set face of each match of REGEXP to FACE. |
| 458 | Interactively, prompt for REGEXP using `read-regexp', then FACE. | 469 | Interactively, prompt for REGEXP using `read-regexp', then FACE. |
| 459 | Use the global history list for FACE. Limit face setting to the | 470 | Use the global history list for FACE. Limit face setting to the |
| 460 | corresponding SUBEXP (interactively, the prefix argument) of REGEXP. | 471 | corresponding SUBEXP (interactively, the prefix argument) of REGEXP. |
| 461 | If SUBEXP is omitted or nil, the entire REGEXP is highlighted. | 472 | If SUBEXP is omitted or nil, the entire REGEXP is highlighted. |
| 462 | 473 | ||
| 474 | LIGHTER is a human-readable string that can be used to select | ||
| 475 | a regexp to unhighlight by its name instead of selecting a possibly | ||
| 476 | complex regexp or closure. | ||
| 477 | |||
| 478 | If REGEXP contains upper case characters (excluding those preceded by `\\') | ||
| 479 | and `search-upper-case' is non-nil, the matching is case-sensitive. | ||
| 480 | |||
| 463 | Use Font lock mode, if enabled, to highlight REGEXP. Otherwise, | 481 | Use Font lock mode, if enabled, to highlight REGEXP. Otherwise, |
| 464 | use overlays for highlighting. If overlays are used, the | 482 | use overlays for highlighting. If overlays are used, the |
| 465 | highlighting will not update as you type." | 483 | highlighting will not update as you type." |
| @@ -471,7 +489,12 @@ highlighting will not update as you type." | |||
| 471 | current-prefix-arg)) | 489 | current-prefix-arg)) |
| 472 | (or (facep face) (setq face 'hi-yellow)) | 490 | (or (facep face) (setq face 'hi-yellow)) |
| 473 | (unless hi-lock-mode (hi-lock-mode 1)) | 491 | (unless hi-lock-mode (hi-lock-mode 1)) |
| 474 | (hi-lock-set-pattern regexp face subexp)) | 492 | (hi-lock-set-pattern |
| 493 | regexp face subexp lighter | ||
| 494 | (if (and case-fold-search search-upper-case) | ||
| 495 | (isearch-no-upper-case-p regexp t) | ||
| 496 | case-fold-search) | ||
| 497 | search-spaces-regexp)) | ||
| 475 | 498 | ||
| 476 | ;;;###autoload | 499 | ;;;###autoload |
| 477 | (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) | 500 | (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) |
| @@ -481,9 +504,9 @@ highlighting will not update as you type." | |||
| 481 | Interactively, prompt for REGEXP using `read-regexp', then FACE. | 504 | Interactively, prompt for REGEXP using `read-regexp', then FACE. |
| 482 | Use the global history list for FACE. | 505 | Use the global history list for FACE. |
| 483 | 506 | ||
| 484 | When called interactively, replace whitespace in user-provided | 507 | If REGEXP contains upper case characters (excluding those preceded by `\\') |
| 485 | regexp with arbitrary whitespace, and make initial lower-case | 508 | and `search-upper-case' is non-nil, the matching is case-sensitive. |
| 486 | letters case-insensitive, before highlighting with `hi-lock-set-pattern'. | 509 | Also set `search-spaces-regexp' to the value of `search-whitespace-regexp'. |
| 487 | 510 | ||
| 488 | Use Font lock mode, if enabled, to highlight REGEXP. Otherwise, | 511 | Use Font lock mode, if enabled, to highlight REGEXP. Otherwise, |
| 489 | use overlays for highlighting. If overlays are used, the | 512 | use overlays for highlighting. If overlays are used, the |
| @@ -491,12 +514,16 @@ highlighting will not update as you type." | |||
| 491 | (interactive | 514 | (interactive |
| 492 | (list | 515 | (list |
| 493 | (hi-lock-regexp-okay | 516 | (hi-lock-regexp-okay |
| 494 | (hi-lock-process-phrase | 517 | (read-regexp "Phrase to highlight" 'regexp-history-last)) |
| 495 | (read-regexp "Phrase to highlight" 'regexp-history-last))) | ||
| 496 | (hi-lock-read-face-name))) | 518 | (hi-lock-read-face-name))) |
| 497 | (or (facep face) (setq face 'hi-yellow)) | 519 | (or (facep face) (setq face 'hi-yellow)) |
| 498 | (unless hi-lock-mode (hi-lock-mode 1)) | 520 | (unless hi-lock-mode (hi-lock-mode 1)) |
| 499 | (hi-lock-set-pattern regexp face)) | 521 | (hi-lock-set-pattern |
| 522 | regexp face nil nil | ||
| 523 | (if (and case-fold-search search-upper-case) | ||
| 524 | (isearch-no-upper-case-p regexp t) | ||
| 525 | case-fold-search) | ||
| 526 | search-whitespace-regexp)) | ||
| 500 | 527 | ||
| 501 | ;;;###autoload | 528 | ;;;###autoload |
| 502 | (defalias 'highlight-symbol-at-point 'hi-lock-face-symbol-at-point) | 529 | (defalias 'highlight-symbol-at-point 'hi-lock-face-symbol-at-point) |
| @@ -507,6 +534,9 @@ Uses the next face from `hi-lock-face-defaults' without prompting, | |||
| 507 | unless you use a prefix argument. | 534 | unless you use a prefix argument. |
| 508 | Uses `find-tag-default-as-symbol-regexp' to retrieve the symbol at point. | 535 | Uses `find-tag-default-as-symbol-regexp' to retrieve the symbol at point. |
| 509 | 536 | ||
| 537 | If REGEXP contains upper case characters (excluding those preceded by `\\') | ||
| 538 | and `search-upper-case' is non-nil, the matching is case-sensitive. | ||
| 539 | |||
| 510 | This uses Font lock mode if it is enabled; otherwise it uses overlays, | 540 | This uses Font lock mode if it is enabled; otherwise it uses overlays, |
| 511 | in which case the highlighting will not update as you type." | 541 | in which case the highlighting will not update as you type." |
| 512 | (interactive) | 542 | (interactive) |
| @@ -516,7 +546,11 @@ in which case the highlighting will not update as you type." | |||
| 516 | (face (hi-lock-read-face-name))) | 546 | (face (hi-lock-read-face-name))) |
| 517 | (or (facep face) (setq face 'hi-yellow)) | 547 | (or (facep face) (setq face 'hi-yellow)) |
| 518 | (unless hi-lock-mode (hi-lock-mode 1)) | 548 | (unless hi-lock-mode (hi-lock-mode 1)) |
| 519 | (hi-lock-set-pattern regexp face))) | 549 | (hi-lock-set-pattern |
| 550 | regexp face nil nil | ||
| 551 | (if (and case-fold-search search-upper-case) | ||
| 552 | (isearch-no-upper-case-p regexp t) | ||
| 553 | case-fold-search)))) | ||
| 520 | 554 | ||
| 521 | (defun hi-lock-keyword->face (keyword) | 555 | (defun hi-lock-keyword->face (keyword) |
| 522 | (cadr (cadr (cadr keyword)))) ; Keyword looks like (REGEXP (0 'FACE) ...). | 556 | (cadr (cadr (cadr keyword)))) ; Keyword looks like (REGEXP (0 'FACE) ...). |
| @@ -586,12 +620,15 @@ then remove all hi-lock highlighting." | |||
| 586 | 'keymap | 620 | 'keymap |
| 587 | (cons "Select Pattern to Unhighlight" | 621 | (cons "Select Pattern to Unhighlight" |
| 588 | (mapcar (lambda (pattern) | 622 | (mapcar (lambda (pattern) |
| 589 | (list (car pattern) | 623 | (let ((lighter |
| 590 | (format | 624 | (or (car (rassq pattern hi-lock-interactive-lighters)) |
| 591 | "%s (%s)" (car pattern) | 625 | (car pattern)))) |
| 592 | (hi-lock-keyword->face pattern)) | 626 | (list lighter |
| 593 | (cons nil nil) | 627 | (format |
| 594 | (car pattern))) | 628 | "%s (%s)" lighter |
| 629 | (hi-lock-keyword->face pattern)) | ||
| 630 | (cons nil nil) | ||
| 631 | lighter))) | ||
| 595 | hi-lock-interactive-patterns)))) | 632 | hi-lock-interactive-patterns)))) |
| 596 | ;; If the user clicks outside the menu, meaning that they | 633 | ;; If the user clicks outside the menu, meaning that they |
| 597 | ;; change their mind, x-popup-menu returns nil, and | 634 | ;; change their mind, x-popup-menu returns nil, and |
| @@ -602,17 +639,33 @@ then remove all hi-lock highlighting." | |||
| 602 | (t | 639 | (t |
| 603 | ;; Un-highlighting triggered via keyboard action. | 640 | ;; Un-highlighting triggered via keyboard action. |
| 604 | (unless hi-lock-interactive-patterns | 641 | (unless hi-lock-interactive-patterns |
| 605 | (error "No highlighting to remove")) | 642 | (user-error "No highlighting to remove")) |
| 606 | ;; Infer the regexp to un-highlight based on cursor position. | 643 | ;; Infer the regexp to un-highlight based on cursor position. |
| 607 | (let* ((defaults (or (hi-lock--regexps-at-point) | 644 | (let* ((defaults (or (hi-lock--regexps-at-point) |
| 608 | (mapcar #'car hi-lock-interactive-patterns)))) | 645 | (mapcar #'car hi-lock-interactive-patterns)))) |
| 646 | (setq defaults | ||
| 647 | (mapcar (lambda (default) | ||
| 648 | (or (car (rassq default | ||
| 649 | (mapcar (lambda (a) | ||
| 650 | (cons (car a) (cadr a))) | ||
| 651 | hi-lock-interactive-lighters))) | ||
| 652 | default)) | ||
| 653 | defaults)) | ||
| 609 | (list | 654 | (list |
| 610 | (completing-read (if (null defaults) | 655 | (completing-read (if (null defaults) |
| 611 | "Regexp to unhighlight: " | 656 | "Regexp to unhighlight: " |
| 612 | (format "Regexp to unhighlight (default %s): " | 657 | (format "Regexp to unhighlight (default %s): " |
| 613 | (car defaults))) | 658 | (car defaults))) |
| 614 | hi-lock-interactive-patterns | 659 | (mapcar (lambda (pattern) |
| 660 | (cons (or (car (rassq pattern hi-lock-interactive-lighters)) | ||
| 661 | (car pattern)) | ||
| 662 | (cdr pattern))) | ||
| 663 | hi-lock-interactive-patterns) | ||
| 615 | nil t nil nil defaults)))))) | 664 | nil t nil nil defaults)))))) |
| 665 | |||
| 666 | (when (assoc regexp hi-lock-interactive-lighters) | ||
| 667 | (setq regexp (cadr (assoc regexp hi-lock-interactive-lighters)))) | ||
| 668 | |||
| 616 | (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns | 669 | (dolist (keyword (if (eq regexp t) hi-lock-interactive-patterns |
| 617 | (list (assoc regexp hi-lock-interactive-patterns)))) | 670 | (list (assoc regexp hi-lock-interactive-patterns)))) |
| 618 | (when keyword | 671 | (when keyword |
| @@ -629,7 +682,11 @@ then remove all hi-lock highlighting." | |||
| 629 | (setq hi-lock-interactive-patterns | 682 | (setq hi-lock-interactive-patterns |
| 630 | (delq keyword hi-lock-interactive-patterns)) | 683 | (delq keyword hi-lock-interactive-patterns)) |
| 631 | (remove-overlays | 684 | (remove-overlays |
| 632 | nil nil 'hi-lock-overlay-regexp (hi-lock--hashcons (car keyword))) | 685 | nil nil 'hi-lock-overlay-regexp |
| 686 | (hi-lock--hashcons (or (car (rassq keyword hi-lock-interactive-lighters)) | ||
| 687 | (car keyword)))) | ||
| 688 | (setq hi-lock-interactive-lighters | ||
| 689 | (rassq-delete-all keyword hi-lock-interactive-lighters)) | ||
| 633 | (font-lock-flush)))) | 690 | (font-lock-flush)))) |
| 634 | 691 | ||
| 635 | ;;;###autoload | 692 | ;;;###autoload |
| @@ -641,7 +698,7 @@ Interactively added patterns are those normally specified using | |||
| 641 | be found in variable `hi-lock-interactive-patterns'." | 698 | be found in variable `hi-lock-interactive-patterns'." |
| 642 | (interactive) | 699 | (interactive) |
| 643 | (if (null hi-lock-interactive-patterns) | 700 | (if (null hi-lock-interactive-patterns) |
| 644 | (error "There are no interactive patterns")) | 701 | (user-error "There are no interactive patterns")) |
| 645 | (let ((beg (point))) | 702 | (let ((beg (point))) |
| 646 | (mapc | 703 | (mapc |
| 647 | (lambda (pattern) | 704 | (lambda (pattern) |
| @@ -655,25 +712,6 @@ be found in variable `hi-lock-interactive-patterns'." | |||
| 655 | 712 | ||
| 656 | ;; Implementation Functions | 713 | ;; Implementation Functions |
| 657 | 714 | ||
| 658 | (defun hi-lock-process-phrase (phrase) | ||
| 659 | "Convert regexp PHRASE to a regexp that matches phrases. | ||
| 660 | |||
| 661 | Blanks in PHRASE replaced by regexp that matches arbitrary whitespace | ||
| 662 | and initial lower-case letters made case insensitive." | ||
| 663 | (let ((mod-phrase nil)) | ||
| 664 | ;; FIXME fragile; better to just bind case-fold-search? (Bug#7161) | ||
| 665 | (setq mod-phrase | ||
| 666 | (replace-regexp-in-string | ||
| 667 | "\\(^\\|\\s-\\)\\([a-z]\\)" | ||
| 668 | (lambda (m) (format "%s[%s%s]" | ||
| 669 | (match-string 1 m) | ||
| 670 | (upcase (match-string 2 m)) | ||
| 671 | (match-string 2 m))) phrase)) | ||
| 672 | ;; FIXME fragile; better to use search-spaces-regexp? | ||
| 673 | (setq mod-phrase | ||
| 674 | (replace-regexp-in-string | ||
| 675 | "\\s-+" "[ \t\n]+" mod-phrase nil t)))) | ||
| 676 | |||
| 677 | (defun hi-lock-regexp-okay (regexp) | 715 | (defun hi-lock-regexp-okay (regexp) |
| 678 | "Return REGEXP if it appears suitable for a font-lock pattern. | 716 | "Return REGEXP if it appears suitable for a font-lock pattern. |
| 679 | 717 | ||
| @@ -713,19 +751,26 @@ with completion and history." | |||
| 713 | (add-to-list 'hi-lock-face-defaults face t)) | 751 | (add-to-list 'hi-lock-face-defaults face t)) |
| 714 | (intern face))) | 752 | (intern face))) |
| 715 | 753 | ||
| 716 | (defun hi-lock-set-pattern (regexp face &optional subexp) | 754 | (defun hi-lock-set-pattern (regexp face &optional subexp lighter case-fold spaces-regexp) |
| 717 | "Highlight SUBEXP of REGEXP with face FACE. | 755 | "Highlight SUBEXP of REGEXP with face FACE. |
| 718 | If omitted or nil, SUBEXP defaults to zero, i.e. the entire | 756 | If omitted or nil, SUBEXP defaults to zero, i.e. the entire |
| 719 | REGEXP is highlighted." | 757 | REGEXP is highlighted. LIGHTER is a human-readable string to |
| 758 | display instead of a regexp. Non-nil CASE-FOLD ignores case. | ||
| 759 | SPACES-REGEXP is a regexp to substitute spaces in font-lock search." | ||
| 720 | ;; Hashcons the regexp, so it can be passed to remove-overlays later. | 760 | ;; Hashcons the regexp, so it can be passed to remove-overlays later. |
| 721 | (setq regexp (hi-lock--hashcons regexp)) | 761 | (setq regexp (hi-lock--hashcons regexp)) |
| 722 | (setq subexp (or subexp 0)) | 762 | (setq subexp (or subexp 0)) |
| 723 | (let ((pattern (list regexp (list subexp (list 'quote face) 'prepend))) | 763 | (let ((pattern (list (lambda (limit) |
| 764 | (let ((case-fold-search case-fold) | ||
| 765 | (search-spaces-regexp spaces-regexp)) | ||
| 766 | (re-search-forward regexp limit t))) | ||
| 767 | (list subexp (list 'quote face) 'prepend))) | ||
| 724 | (no-matches t)) | 768 | (no-matches t)) |
| 725 | ;; Refuse to highlight a text that is already highlighted. | 769 | ;; Refuse to highlight a text that is already highlighted. |
| 726 | (if (assoc regexp hi-lock-interactive-patterns) | 770 | (if (assoc regexp hi-lock-interactive-patterns) |
| 727 | (add-to-list 'hi-lock--unused-faces (face-name face)) | 771 | (add-to-list 'hi-lock--unused-faces (face-name face)) |
| 728 | (push pattern hi-lock-interactive-patterns) | 772 | (push pattern hi-lock-interactive-patterns) |
| 773 | (push (cons (or lighter regexp) pattern) hi-lock-interactive-lighters) | ||
| 729 | (if (and font-lock-mode (font-lock-specified-p major-mode)) | 774 | (if (and font-lock-mode (font-lock-specified-p major-mode)) |
| 730 | (progn | 775 | (progn |
| 731 | (font-lock-add-keywords nil (list pattern) t) | 776 | (font-lock-add-keywords nil (list pattern) t) |
| @@ -737,7 +782,9 @@ REGEXP is highlighted." | |||
| 737 | (- range-min (max 0 (- range-max (point-max)))))) | 782 | (- range-min (max 0 (- range-max (point-max)))))) |
| 738 | (search-end | 783 | (search-end |
| 739 | (min (point-max) | 784 | (min (point-max) |
| 740 | (+ range-max (max 0 (- (point-min) range-min)))))) | 785 | (+ range-max (max 0 (- (point-min) range-min))))) |
| 786 | (case-fold-search case-fold) | ||
| 787 | (search-spaces-regexp spaces-regexp)) | ||
| 741 | (save-excursion | 788 | (save-excursion |
| 742 | (goto-char search-start) | 789 | (goto-char search-start) |
| 743 | (while (re-search-forward regexp search-end t) | 790 | (while (re-search-forward regexp search-end t) |
| @@ -751,7 +798,9 @@ REGEXP is highlighted." | |||
| 751 | (when no-matches | 798 | (when no-matches |
| 752 | (add-to-list 'hi-lock--unused-faces (face-name face)) | 799 | (add-to-list 'hi-lock--unused-faces (face-name face)) |
| 753 | (setq hi-lock-interactive-patterns | 800 | (setq hi-lock-interactive-patterns |
| 754 | (cdr hi-lock-interactive-patterns))))))))) | 801 | (cdr hi-lock-interactive-patterns) |
| 802 | hi-lock-interactive-lighters | ||
| 803 | (cdr hi-lock-interactive-lighters))))))))) | ||
| 755 | 804 | ||
| 756 | (defun hi-lock-set-file-patterns (patterns) | 805 | (defun hi-lock-set-file-patterns (patterns) |
| 757 | "Replace file patterns list with PATTERNS and refontify." | 806 | "Replace file patterns list with PATTERNS and refontify." |
diff --git a/lisp/isearch.el b/lisp/isearch.el index 7625ec12b58..e13a4dda83f 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -2382,22 +2382,17 @@ respectively)." | |||
| 2382 | (funcall isearch-regexp-function isearch-string)) | 2382 | (funcall isearch-regexp-function isearch-string)) |
| 2383 | (isearch-regexp-function (word-search-regexp isearch-string)) | 2383 | (isearch-regexp-function (word-search-regexp isearch-string)) |
| 2384 | (isearch-regexp isearch-string) | 2384 | (isearch-regexp isearch-string) |
| 2385 | ((if (and (eq isearch-case-fold-search t) | ||
| 2386 | search-upper-case) | ||
| 2387 | (isearch-no-upper-case-p | ||
| 2388 | isearch-string isearch-regexp) | ||
| 2389 | isearch-case-fold-search) | ||
| 2390 | ;; Turn isearch-string into a case-insensitive | ||
| 2391 | ;; regexp. | ||
| 2392 | (mapconcat | ||
| 2393 | (lambda (c) | ||
| 2394 | (let ((s (string c))) | ||
| 2395 | (if (string-match "[[:alpha:]]" s) | ||
| 2396 | (format "[%s%s]" (upcase s) (downcase s)) | ||
| 2397 | (regexp-quote s)))) | ||
| 2398 | isearch-string "")) | ||
| 2399 | (t (regexp-quote isearch-string))))) | 2385 | (t (regexp-quote isearch-string))))) |
| 2400 | (funcall hi-lock-func regexp (hi-lock-read-face-name))) | 2386 | (let ((case-fold-search isearch-case-fold-search) |
| 2387 | ;; Set `search-upper-case' to nil to not call | ||
| 2388 | ;; `isearch-no-upper-case-p' in `hi-lock'. | ||
| 2389 | (search-upper-case nil) | ||
| 2390 | (search-spaces-regexp | ||
| 2391 | (if (if isearch-regexp | ||
| 2392 | isearch-regexp-lax-whitespace | ||
| 2393 | isearch-lax-whitespace) | ||
| 2394 | search-whitespace-regexp))) | ||
| 2395 | (funcall hi-lock-func regexp (hi-lock-read-face-name) isearch-string))) | ||
| 2401 | (and isearch-recursive-edit (exit-recursive-edit))) | 2396 | (and isearch-recursive-edit (exit-recursive-edit))) |
| 2402 | 2397 | ||
| 2403 | (defun isearch-highlight-regexp () | 2398 | (defun isearch-highlight-regexp () |
| @@ -2405,14 +2400,18 @@ respectively)." | |||
| 2405 | The arguments passed to `highlight-regexp' are the regexp from | 2400 | The arguments passed to `highlight-regexp' are the regexp from |
| 2406 | the last search and the face from `hi-lock-read-face-name'." | 2401 | the last search and the face from `hi-lock-read-face-name'." |
| 2407 | (interactive) | 2402 | (interactive) |
| 2408 | (isearch--highlight-regexp-or-lines 'highlight-regexp)) | 2403 | (isearch--highlight-regexp-or-lines |
| 2404 | #'(lambda (regexp face lighter) | ||
| 2405 | (highlight-regexp regexp face nil lighter)))) | ||
| 2409 | 2406 | ||
| 2410 | (defun isearch-highlight-lines-matching-regexp () | 2407 | (defun isearch-highlight-lines-matching-regexp () |
| 2411 | "Exit Isearch mode and call `highlight-lines-matching-regexp'. | 2408 | "Exit Isearch mode and call `highlight-lines-matching-regexp'. |
| 2412 | The arguments passed to `highlight-lines-matching-regexp' are the | 2409 | The arguments passed to `highlight-lines-matching-regexp' are the |
| 2413 | regexp from the last search and the face from `hi-lock-read-face-name'." | 2410 | regexp from the last search and the face from `hi-lock-read-face-name'." |
| 2414 | (interactive) | 2411 | (interactive) |
| 2415 | (isearch--highlight-regexp-or-lines 'highlight-lines-matching-regexp)) | 2412 | (isearch--highlight-regexp-or-lines |
| 2413 | #'(lambda (regexp face _lighter) | ||
| 2414 | (highlight-lines-matching-regexp regexp face)))) | ||
| 2416 | 2415 | ||
| 2417 | 2416 | ||
| 2418 | (defun isearch-delete-char () | 2417 | (defun isearch-delete-char () |