@@ -290,6 +290,67 @@ Looks up the state in meow-replace-state-name-list"
290
290
(regexp-quote selected))
291
291
selected))))
292
292
293
+ (defun meow--prompt-buffer-highlight (prompt beg end )
294
+ " PROMPT from the minibuffer while highlighting matches between BEG and END.
295
+
296
+ When `meow-visit-sanitize-completion' is non-nil, matches are
297
+ literal instead of regexps and only words and symbols are
298
+ matched.
299
+
300
+ Highlights are only visible in the selected window."
301
+ (let ((current-buffer (current-buffer ))
302
+ (selected-window (selected-window ))
303
+ (timer)
304
+ (overlays)
305
+ (prompter-minibuffer))
306
+ (cl-labels ((transform-text (txt &optional quote-regexp)
307
+ (cond (meow-visit-sanitize-completion
308
+ ; ; The below regexp was made using the below call to
309
+ ; ; `rx' , which has gained features since Emacs 26.3.
310
+ ; ;
311
+ ; ;(rx (or (seq symbol-start (literal txt) symbol-end))
312
+ ; ; (seq word-start (literal txt) word-end))
313
+ (let ((qtd (regexp-quote txt)))
314
+ (concat " \\ _<\\ (?:" qtd " \\ )\\ _>\\ |\\ <\\ (?:" qtd " \\ )\\ >" )))
315
+ (quote-regexp (regexp-quote txt))
316
+ (t txt)))
317
+ (delete-overlays ()
318
+ (mapc #'delete-overlay overlays)
319
+ (setq overlays nil ))
320
+ (highlight-matches ()
321
+ ; ; Before highlighting the minibuffer contents, we need to
322
+ ; ; check that we are still in the prompter's minibuffer, not
323
+ ; ; some other minibuffer.
324
+ (when (or (not enable-recursive-minibuffers)
325
+ (equal prompter-minibuffer (current-buffer )))
326
+ (delete-overlays)
327
+ (let ((regexp (transform-text (minibuffer-contents ))))
328
+ (unless (string-empty-p regexp)
329
+ (save-excursion
330
+ (with-current-buffer current-buffer
331
+ (goto-char beg)
332
+ (while (ignore-error invalid-regexp
333
+ ; ; If the user is still typing the regexp it
334
+ ; ; might not be valid. In that case, we
335
+ ; ; treat it as valid but not matching.
336
+ (re-search-forward regexp end t ))
337
+ (let ((ov (make-overlay (match-beginning 0 )
338
+ (match-end 0 ))))
339
+ (overlay-put ov 'face 'lazy-highlight )
340
+ ; ; Same priority as Isearch lazy-highlight.
341
+ (overlay-put ov 'priority 1000 )
342
+ (overlay-put ov 'window selected-window)
343
+ (push ov overlays)))))))))
344
+ (make-hl-timer ()
345
+ (run-with-idle-timer 0.01 'repeat #'highlight-matches )))
346
+ (unwind-protect
347
+ (minibuffer-with-setup-hook
348
+ (lambda () (setq timer (make-hl-timer)
349
+ prompter-minibuffer (current-buffer )))
350
+ (transform-text (read-from-minibuffer prompt) t ))
351
+ (cancel-timer timer)
352
+ (delete-overlays)))))
353
+
293
354
(defun meow--on-window-state-change (&rest _args )
294
355
" Update cursor style after switching window."
295
356
(meow--update-cursor)
0 commit comments