Commit 730ea8a4 authored by Juri Linkov's avatar Juri Linkov

Add isearch-lazy-hints

parent 44059ff7
......@@ -5,7 +5,7 @@
;; Author: Juri Linkov <>
;; Keywords: dotemacs, init
;; URL: <>
;; Version: 2018-12-30 for GNU Emacs 27.0.50 (x86_64-pc-linux-gnu)
;; Version: 2018-12-31 for GNU Emacs 27.0.50 (x86_64-pc-linux-gnu)
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
......@@ -1141,6 +1141,68 @@ Uses the value of the variable `search-whitespace-regexp'."
;; (re-search-backward (search-whitespace-regexp regexp) bound noerror count))
(setq search-default-mode #'char-fold-to-regexp)
;;;; isearch-lazy-hints
(defface isearch-lazy-hint
'((t :inherit lazy-highlight))
"Face for lazy highlighting of counter hints."
:group 'lazy-highlight
:group 'basic-faces)
(defvar isearch-lazy-hints-overlays nil)
(defun isearch-lazy-hints-cleanup ()
(while isearch-lazy-hints-overlays
(delete-overlay (pop isearch-lazy-hints-overlays))))
(defun isearch-lazy-hint (pos count)
(let* ((ov (make-overlay pos pos))
(hint (number-to-string count)))
(set-text-properties 0 (length hint)
'(face isearch-lazy-hint
display ((height 0.7) (raise 0.3)))
(overlay-put ov 'after-string hint)
(overlay-put ov 'priority 1000)
(overlay-put ov 'window (selected-window))
(push ov isearch-lazy-hints-overlays)))
(defun isearch-lazy-hints ()
(let* ((wgs (window-group-start))
(wge (window-group-end))
(seq-filter (lambda (ov) (and (>= (overlay-start ov) wgs)
(<= (overlay-end ov) wge)))
(seq-group-by (lambda (ov) (> (overlay-end ov) isearch-other-end))
(lambda (ov index)
(isearch-lazy-hint (if isearch-forward (overlay-end ov) (overlay-start ov))
(1+ index)))
;; Skip the current match
(seq-sort-by #'overlay-start (if isearch-forward #'< #'>)
(cdr (assq (if isearch-forward t nil)
(lambda (ov index)
(isearch-lazy-hint (if isearch-forward (overlay-start ov) (overlay-end ov))
(- (1+ index))))
(seq-sort-by #'overlay-start (if isearch-forward #'> #'<)
(cdr (assq (if isearch-forward nil t)
(add-hook 'isearch-mode-end-hook 'isearch-lazy-hints-cleanup)
;; TODO: add to the end of isearch-lazy-highlight-new-loop
(add-hook 'isearch-update-post-hook 'isearch-lazy-hints)
;; TODO: call isearch-lazy-hint from isearch-lazy-highlight-update?
(advice-add 'isearch-lazy-highlight-update :after 'isearch-lazy-hints)
;;;; isearch-decomposition
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment