diff options
| author | Juri Linkov | 2021-01-19 20:12:47 +0200 |
|---|---|---|
| committer | Juri Linkov | 2021-01-19 20:13:48 +0200 |
| commit | e718d3a84920f545b6a3540a3ba9c2ccd7eefdf7 (patch) | |
| tree | 64db641db63630f7a9528d14e6127da3531e9a4e | |
| parent | 1248c67484d599b36e094f0e641c82482fd269ce (diff) | |
| download | emacs-e718d3a84920f545b6a3540a3ba9c2ccd7eefdf7.tar.gz emacs-e718d3a84920f545b6a3540a3ba9c2ccd7eefdf7.zip | |
Better check for nil in search-/query-replace-highlight-submatches (bug#45973)
* lisp/isearch.el (isearch-highlight):
* lisp/replace.el (replace-highlight):
Use integer-or-marker-p to check matches.
| -rw-r--r-- | lisp/isearch.el | 30 | ||||
| -rw-r--r-- | lisp/replace.el | 30 |
2 files changed, 34 insertions, 26 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el index c6f7fe7bd4a..a86678572c4 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -3757,23 +3757,27 @@ since they have special meaning in a regexp." | |||
| 3757 | (overlay-put isearch-overlay 'priority 1001) | 3757 | (overlay-put isearch-overlay 'priority 1001) |
| 3758 | (overlay-put isearch-overlay 'face isearch-face))) | 3758 | (overlay-put isearch-overlay 'face isearch-face))) |
| 3759 | 3759 | ||
| 3760 | (when (and search-highlight-submatches | 3760 | (when (and search-highlight-submatches isearch-regexp) |
| 3761 | isearch-regexp) | ||
| 3762 | (mapc 'delete-overlay isearch-submatches-overlays) | 3761 | (mapc 'delete-overlay isearch-submatches-overlays) |
| 3763 | (setq isearch-submatches-overlays nil) | 3762 | (setq isearch-submatches-overlays nil) |
| 3764 | (let ((submatch-data (cddr (butlast match-data))) | 3763 | ;; 'cddr' removes whole expression match from match-data |
| 3764 | (let ((submatch-data (cddr match-data)) | ||
| 3765 | (group 0) | 3765 | (group 0) |
| 3766 | ov face) | 3766 | b e ov face) |
| 3767 | (while submatch-data | 3767 | (while submatch-data |
| 3768 | (setq group (1+ group)) | 3768 | (setq b (pop submatch-data) |
| 3769 | (setq ov (make-overlay (pop submatch-data) (pop submatch-data)) | 3769 | e (pop submatch-data)) |
| 3770 | face (intern-soft (format "isearch-group-%d" group))) | 3770 | (when (and (integer-or-marker-p b) |
| 3771 | ;; Recycle faces from beginning. | 3771 | (integer-or-marker-p e)) |
| 3772 | (unless (facep face) | 3772 | (setq ov (make-overlay b e) |
| 3773 | (setq group 1 face 'isearch-group-1)) | 3773 | group (1+ group) |
| 3774 | (overlay-put ov 'face face) | 3774 | face (intern-soft (format "isearch-group-%d" group))) |
| 3775 | (overlay-put ov 'priority 1002) | 3775 | ;; Recycle faces from beginning |
| 3776 | (push ov isearch-submatches-overlays))))) | 3776 | (unless (facep face) |
| 3777 | (setq group 1 face 'isearch-group-1)) | ||
| 3778 | (overlay-put ov 'face face) | ||
| 3779 | (overlay-put ov 'priority 1002) | ||
| 3780 | (push ov isearch-submatches-overlays)))))) | ||
| 3777 | 3781 | ||
| 3778 | (defun isearch-dehighlight () | 3782 | (defun isearch-dehighlight () |
| 3779 | (when isearch-overlay | 3783 | (when isearch-overlay |
diff --git a/lisp/replace.el b/lisp/replace.el index 8f8cbfac542..db5b340631a 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -2425,23 +2425,27 @@ It is called with three arguments, as if it were | |||
| 2425 | (overlay-put replace-overlay 'priority 1001) ;higher than lazy overlays | 2425 | (overlay-put replace-overlay 'priority 1001) ;higher than lazy overlays |
| 2426 | (overlay-put replace-overlay 'face 'query-replace))) | 2426 | (overlay-put replace-overlay 'face 'query-replace))) |
| 2427 | 2427 | ||
| 2428 | (when (and query-replace-highlight-submatches | 2428 | (when (and query-replace-highlight-submatches regexp-flag) |
| 2429 | regexp-flag) | ||
| 2430 | (mapc 'delete-overlay replace-submatches-overlays) | 2429 | (mapc 'delete-overlay replace-submatches-overlays) |
| 2431 | (setq replace-submatches-overlays nil) | 2430 | (setq replace-submatches-overlays nil) |
| 2432 | (let ((submatch-data (cddr (butlast (match-data t)))) | 2431 | ;; 'cddr' removes whole expression match from match-data |
| 2432 | (let ((submatch-data (cddr (match-data t))) | ||
| 2433 | (group 0) | 2433 | (group 0) |
| 2434 | ov face) | 2434 | b e ov face) |
| 2435 | (while submatch-data | 2435 | (while submatch-data |
| 2436 | (setq group (1+ group)) | 2436 | (setq b (pop submatch-data) |
| 2437 | (setq ov (make-overlay (pop submatch-data) (pop submatch-data)) | 2437 | e (pop submatch-data)) |
| 2438 | face (intern-soft (format "isearch-group-%d" group))) | 2438 | (when (and (integer-or-marker-p b) |
| 2439 | ;; Recycle faces from beginning. | 2439 | (integer-or-marker-p e)) |
| 2440 | (unless (facep face) | 2440 | (setq ov (make-overlay b e) |
| 2441 | (setq group 1 face 'isearch-group-1)) | 2441 | group (1+ group) |
| 2442 | (overlay-put ov 'face face) | 2442 | face (intern-soft (format "isearch-group-%d" group))) |
| 2443 | (overlay-put ov 'priority 1002) | 2443 | ;; Recycle faces from beginning |
| 2444 | (push ov replace-submatches-overlays)))) | 2444 | (unless (facep face) |
| 2445 | (setq group 1 face 'isearch-group-1)) | ||
| 2446 | (overlay-put ov 'face face) | ||
| 2447 | (overlay-put ov 'priority 1002) | ||
| 2448 | (push ov replace-submatches-overlays))))) | ||
| 2445 | 2449 | ||
| 2446 | (if query-replace-lazy-highlight | 2450 | (if query-replace-lazy-highlight |
| 2447 | (let ((isearch-string search-string) | 2451 | (let ((isearch-string search-string) |