1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
# anzu.el
## Introduction
`anzu.el` is an Emacs port of [anzu.vim](https://github.com/osyo-manga/vim-anzu).
`anzu.el` provides a minor mode which displays *current match* and *total matches*
information in the mode-line in various search modes.
## New Maintainer
This package has a new maintainer as of March 2020, and based on the
valuable contribution of insights and fixes from the author, you
should see issues from years past are now getting resolved. You may
also see instability in the short term. Please bear with us!
## Requirements
- Emacs 24 or higher
- `cl-lib` 0.5 or higher (you don't need to install `cl-lib` if you use Emacs 24.3 or higher)
## Installation
You can install `anzu.el` from [MELPA](https://melpa.org/) with `package.el`
```
M-x package-install anzu
```
## Basic Usage
##### `global-anzu-mode`
Enable global anzu mode:
```lisp
(global-anzu-mode 1)
```
##### `anzu-mode`
Enable anzu minor mode:
```lisp
(anzu-mode 1)
```
##### `anzu-query-replace`
Same as `query-replace` except displays anzu information in the
mode-line.
##### `anzu-query-replace-regexp`
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:
```lisp
(global-set-key [remap query-replace] 'anzu-query-replace)
(global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp)
```
##### `anzu-query-replace-at-cursor`
Works like `anzu-query-replace` except the *from-string* is the symbol
at the cursor.
##### `anzu-query-replace-at-cursor-thing`
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).
##### `anzu-replace-at-cursor-thing`
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.
##### `anzu-isearch-query-replace`
The anzu version of `isearch-query-replace`.
##### `anzu-isearch-query-replace-regexp`
The anzu version of `isearch-query-replace-regexp`.
## Customization
##### `anzu-mode-line`
Face of mode-line anzu information
##### `anzu-mode-line-no-match`
Face of mode-line at no matching case
##### `anzu-replace-highlight`
Face of from-string of replacement
##### `anzu-replace-to`
Face of to-string of replacement
##### `anzu-mode-line-update-function`
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`).
```lisp
(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))
```
##### `anzu-cons-mode-line-p`(Default is `t`)
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`
```lisp
(setq anzu-cons-mode-line-p nil)
(setcar (cdr (assq 'isearch-mode minor-mode-alist))
'(:eval (anzu--update-mode-line)))
```
##### `anzu-mode-lighter`
Mode name in `mode-line`. Default is ` Anzu`.
##### `anzu-input-idle-delay`(Default is `0.05`)
Delay second of updating mode-line information when you input from-string
##### `anzu-regexp-search-commands`
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)`.
##### `anzu-use-migemo`(Default is `nil`)
Set to `t` if you use [migemo](https://github.com/emacs-jp/migemo).
##### `anzu-search-threshold`(Default is `nil`)
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.
##### `anzu-replace-threshold`(Default is `nil`)
Threshold of replacement overlay. If this value is `nil`,
##### `anzu-minimum-input-length`(Default is 1)
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.
##### `anzu-deactivate-region`(Default is `nil`)
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.
##### `anzu-replace-at-cursor-thing`(Default is 'defun)
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.
##### `anzu-replace-to-string-separator`(Default is "")
Separator of `to` string.
## Sample Configuration
```lisp
(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)
```
|