Skip to content

Commit 74fbe3d

Browse files
committed
hotfix meow--highlight-regexp-in-buffer bug
caching mechanism is broken in many ways if the buffer changes but the regexp stays the same. * pos moves but the idx of the regexp stays the same * number of hits changes, cnt is not recomputed this commit always regenerates idx and cnt, removing the caching. temporarily fixes #270.
1 parent 70c27de commit 74fbe3d

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

meow-visual.el

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -96,52 +96,28 @@ Value is a list of (last-regexp last-pos idx cnt).")
9696
(push ov meow--match-overlays)))))
9797

9898
(defun meow--highlight-regexp-in-buffer (regexp)
99-
"Highlight all regexp in this buffer.
100-
101-
There is a cache mechanism, if the REGEXP is not changed,
102-
we simply inc/dec idx and redraw the overlays. Only count for the first time."
99+
"Highlight all regexp in this buffer."
103100
(when (and (meow-normal-mode-p)
104101
(region-active-p))
105102
(meow--remove-expand-highlights)
106103
(let* ((cnt 0)
107104
(idx 0)
108105
(pos (region-end))
109-
(last-regexp (car meow--search-indicator-state))
110-
(last-pos (cadr meow--search-indicator-state))
111-
(last-idx (caddr meow--search-indicator-state))
112-
(last-cnt (cadddr meow--search-indicator-state))
113106
(hl-start (max (point-min) (- (point) 3000)))
114107
(hl-end (min (point-max) (+ (point) 3000))))
115108
(setq meow--expand-nav-function nil)
116109
(setq meow--visual-command this-command)
117-
(cond
118-
((equal last-regexp regexp)
119-
(setq cnt last-cnt
120-
idx (cond ((> pos last-pos) (1+ last-idx))
121-
((< pos last-pos) (1- last-idx))
122-
(t last-idx)))
110+
(save-mark-and-excursion
123111
(meow--remove-search-indicator)
124-
(save-mark-and-excursion
125-
(goto-char hl-start)
126-
(while (re-search-forward regexp hl-end t)
127-
(meow--highlight-match))
128-
(meow--show-indicator pos idx cnt)
129-
(setq meow--search-indicator-state (list regexp pos idx cnt))))
130-
131-
;; For initializing search highlight, we need to count
132-
(t
133-
(save-mark-and-excursion
134-
(meow--remove-search-indicator)
135-
(let ((case-fold-search nil))
136-
(goto-char (point-min))
137-
(while (re-search-forward regexp (point-max) t)
138-
(cl-incf cnt)
139-
(when (<= (match-beginning 0) pos (match-end 0))
140-
(setq idx cnt))
141-
(when (<= hl-start (point) hl-end)
142-
(meow--highlight-match)))
143-
(meow--show-indicator pos idx cnt)
144-
(setq meow--search-indicator-state (list regexp pos idx cnt)))))))))
112+
(let ((case-fold-search nil))
113+
(goto-char (point-min))
114+
(while (re-search-forward regexp (point-max) t)
115+
(cl-incf cnt)
116+
(when (<= (match-beginning 0) pos (match-end 0))
117+
(setq idx cnt))
118+
(when (<= hl-start (point) hl-end)
119+
(meow--highlight-match)))
120+
(meow--show-indicator pos idx cnt))))))
145121

146122
(defun meow--format-full-width-number (n)
147123
(alist-get n meow-full-width-number-position-chars))

0 commit comments

Comments
 (0)