anzu.el is an Emacs port of anzu.vim.
anzu.el provides a minor mode which displays current match and total matches
information in the mode-line in various search modes.
This package has a new maintainer as of 2024, @LemonBreezes. If you have any questions or concerns, please feel free to open an issue on GitHub or to send me an email.
- Emacs 24 or higher
cl-lib0.5 or higher (you don't need to installcl-libif you use Emacs 24.3 or higher)
You can install anzu.el from MELPA with package.el
M-x package-install anzu
Enable global anzu mode:
(global-anzu-mode +1)Enable anzu minor mode:
(anzu-mode +1)Same as query-replace except displays anzu information in the
mode-line.
Same as query-replace-regexp except displays anzu information in the
mode-line.
You can replace key bindings for the standard definitions of
query-replace and query-replace-regexp with their anzu versions by
adding this snippet to your configuration:
(global-set-key [remap query-replace] 'anzu-query-replace)
(global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp)Works like anzu-query-replace except the from-string is the symbol
at the cursor.
Works like anzu-query-replace-at-cursor except the replacement is
constrained to the region specified by the variable
anzu-replace-at-cursor-thing. See the variable's description in
the customization section for additional details.
Be careful not to confuse this variable with the identically named function (see below).
Like anzu-query-replace-at-cursor-thing, but doesn't query for
confirmation before making the substitution.
Be careful not to confuse this function with the identically named
customization variable. See the discussion in the
anzu-query-replace-at-cursor-thing section.
The anzu version of isearch-query-replace.
The anzu version of isearch-query-replace-regexp.
Face of mode-line anzu information
Face of mode-line at no matching case
Face of from-string of replacement
Face of to-string of replacement
Function which constructs mode-line string. anzu.el puts its output to mode-line. It is called at searching, inputting replaced word, replacing. This must be non-nil.
The function takes 2 integer arguments, current position and total match number. You can get current-state from anzu--state('search, 'replace-query, replace).
(defun my/anzu-update-func (here total)
(when anzu--state
(let ((status (cl-case anzu--state
(search (format "<%d/%d>" here total))
(replace-query (format "(%d Replaces)" total))
(replace (format "<%d/%d>" here total)))))
(propertize status 'face 'anzu-mode-line))))
(custom-set-variables
'(anzu-mode-line-update-function #'my/anzu-update-func))Set nil if you want to display anzu information at any position in mode-line.
anzu.el cons search information head of mode-line as default.
For example, show search information tail of minor-mode-alist
(setq anzu-cons-mode-line-p nil)
(setcar (cdr (assq 'isearch-mode minor-mode-alist))
'(:eval (anzu--update-mode-line)))Mode name in mode-line. Default is Anzu.
Delay second of updating mode-line information when you input from-string
Commands which have regexp input. If the last command is a member of this list,
anzu.el treats input as regular expression.
The default value is '(isearch-forward-regexp isearch-backward-regexp).
Set to t if you use migemo.
Threshold of searched words. If there are searched word more than this value,
anzu.el stops to search and display total number like 1000+(as default).
If this value is nil, anzu.el counts all words.
Threshold of replacement overlay. If this value is nil,
Minimum input length to enable anzu. This parameter is useful for migemo users.
Searching 1 or 2 characters with migemo is too heavy if buffer is so large.
Please set 3 or higher if you frequently edit such file.
Deactivate region at anzu replace command if this value is non-nil. It is hard to see with anzu replace command when region is active.
Describes the type of thing used by the anzu-*-thing functions.
It can be set to any symbol that is a valid argument for the
thing-at-point function, including e.g. defun, word, and
page. See the documentation for thing-at-point for additional
information.
Separator of to string.
(require 'anzu)
(global-anzu-mode +1)
(set-face-attribute 'anzu-mode-line nil
:foreground "yellow" :weight 'bold)
(custom-set-variables
'(anzu-mode-lighter "")
'(anzu-deactivate-region t)
'(anzu-search-threshold 1000)
'(anzu-replace-threshold 50)
'(anzu-replace-to-string-separator " => "))
(define-key isearch-mode-map [remap isearch-query-replace] #'anzu-isearch-query-replace)
(define-key isearch-mode-map [remap isearch-query-replace-regexp] #'anzu-isearch-query-replace-regexp)