Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1972 lines
72 KiB

5 years ago
  1. This is ivy.info, produced by makeinfo version 6.5 from ivy.texi.
  2. Ivy manual, version 0.13.0
  3. Ivy is an interactive interface for completion in Emacs. Emacs uses
  4. completion mechanism in a variety of contexts: code, menus, commands,
  5. variables, functions, etc. Completion entails listing, sorting,
  6. filtering, previewing, and applying actions on selected items. When
  7. active, ‘ivy-mode’ completes the selection process by narrowing
  8. available choices while previewing in the minibuffer. Selecting the
  9. final candidate is either through simple keyboard character inputs or
  10. through powerful regular expressions.
  11. Copyright (C) 2015-2019 Free Software Foundation, Inc.
  12. Permission is granted to copy, distribute and/or modify this
  13. document under the terms of the GNU Free Documentation License,
  14. Version 1.3 or any later version published by the Free Software
  15. Foundation; with no Invariant Sections, no Front-Cover Texts, and
  16. no Back-Cover Texts. A copy of the license is included in the
  17. section entitled "GNU Free Documentation License".
  18. INFO-DIR-SECTION Emacs
  19. START-INFO-DIR-ENTRY
  20. * Ivy: (ivy). Using Ivy for completion.
  21. END-INFO-DIR-ENTRY
  22. 
  23. File: ivy.info, Node: Top, Next: Introduction, Up: (dir)
  24. Ivy User Manual
  25. ***************
  26. * Menu:
  27. * Introduction::
  28. * Installation::
  29. * Getting started::
  30. * Key bindings::
  31. * Completion Styles::
  32. * Customization::
  33. * Commands::
  34. * API::
  35. * Variable Index::
  36. * Keystroke Index::
  37. — The Detailed Node Listing —
  38. Installation
  39. * Installing from Emacs Package Manager::
  40. * Installing from the Git repository::
  41. Getting started
  42. * Basic customization::
  43. Key bindings
  44. * Global key bindings::
  45. * Minibuffer key bindings::
  46. Minibuffer key bindings
  47. * Key bindings for navigation::
  48. * Key bindings for single selection, action, then exit minibuffer: Key bindings for single selection action then exit minibuffer.
  49. * Key bindings for multiple selections and actions, keep minibuffer open: Key bindings for multiple selections and actions keep minibuffer open.
  50. * Key bindings that alter the minibuffer input::
  51. * Other key bindings::
  52. * Hydra in the minibuffer::
  53. * Saving the current completion session to a buffer::
  54. Completion Styles
  55. * ivy--regex-plus::
  56. * ivy--regex-ignore-order::
  57. * ivy--regex-fuzzy::
  58. Customization
  59. * Faces::
  60. * Defcustoms::
  61. * Actions::
  62. * Packages::
  63. Actions
  64. * What are actions?::
  65. * How can different actions be called?::
  66. * How to modify the actions list?::
  67. * Example - add two actions to each command::
  68. * Example - define a new command with several actions::
  69. Example - add two actions to each command
  70. * How to undo adding the two actions::
  71. * How to add actions to a specific command::
  72. Example - define a new command with several actions
  73. * Test the above function with ivy-occur::
  74. Commands
  75. * File Name Completion::
  76. * Buffer Name Completion::
  77. * Counsel commands::
  78. File Name Completion
  79. * Using TRAMP::
  80. API
  81. * Required arguments for ivy-read::
  82. * Optional arguments for ivy-read::
  83. * Example - counsel-describe-function::
  84. * Example - counsel-locate::
  85. * Example - ivy-read-with-extra-properties::
  86. 
  87. File: ivy.info, Node: Introduction, Next: Installation, Prev: Top, Up: Top
  88. 1 Introduction
  89. **************
  90. Ivy is for quick and easy selection from a list. When Emacs prompts for
  91. a string from a list of several possible choices, Ivy springs into
  92. action to assist in narrowing and picking the right string from a vast
  93. number of choices.
  94. Ivy strives for minimalism, simplicity, customizability and
  95. discoverability.
  96. Minimalism
  97. ..........
  98. Uncluttered minibuffer is minimalism. Ivy shows the completion
  99. defaults, the number of matches, and 10 candidate matches below the
  100. input line. Customize ‘ivy-height’ to adjust the number of
  101. candidate matches displayed in the minibuffer.
  102. Simplicity
  103. ..........
  104. Simplicity is about Ivy’s behavior in the minibuffer. It is also
  105. about the code interface to extend Ivy’s functionality. The
  106. minibuffer area behaves as close to ‘fundamental-mode’ as possible.
  107. ‘SPC’ inserts a space, for example, instead of being bound to the
  108. more complex ‘minibuffer-complete-word’. Ivy’s code uses
  109. easy-to-examine global variables; avoids needless complications
  110. with branch-introducing custom macros.
  111. Customizability
  112. ...............
  113. Customizability is about being able to use different methods and
  114. interfaces of completion to tailor the selection process. For
  115. example, adding a custom display function that points to a selected
  116. candidate with ‘>’, instead of highlighting the selected candidate
  117. with the ‘ivy-current-match’ face (see
  118. ‘ivy-format-functions-alist’). Or take the customization of
  119. actions, say after the candidate function is selected. ‘RET’ uses
  120. ‘counsel-describe-function’ to describe the function, whereas ‘M-o
  121. d’ jumps to that function’s definition in the code. The ‘M-o’
  122. prefix can be uniformly used with characters like ‘d’ to group
  123. similar actions.
  124. Discoverability
  125. ...............
  126. Ivy displays easily discoverable commands through the hydra
  127. facility. ‘C-o’ in the minibuffer displays a hydra menu. It opens
  128. up within an expanded minibuffer area. Each menu item comes with
  129. short documentation strings and highlighted one-key completions.
  130. So discovering even seldom used keys is simply a matter of ‘C-o’ in
  131. the minibuffer while in the midst of the Ivy interaction. This
  132. discoverability minimizes exiting Ivy interface for documentation
  133. look-ups.
  134. 
  135. File: ivy.info, Node: Installation, Next: Getting started, Prev: Introduction, Up: Top
  136. 2 Installation
  137. **************
  138. Install Ivy automatically through Emacs’s package manager, or manually
  139. from Ivy’s development repository.
  140. Emacs 24.3 is the oldest version to run Ivy. Emacs 24.4 is the
  141. oldest version that runs Ivy with fancy faces display.
  142. * Menu:
  143. * Installing from Emacs Package Manager::
  144. * Installing from the Git repository::
  145. 
  146. File: ivy.info, Node: Installing from Emacs Package Manager, Next: Installing from the Git repository, Up: Installation
  147. 2.1 Installing from Emacs Package Manager
  148. =========================================
  149. ‘M-x’ ‘package-install’ ‘RET’ ‘counsel’ ‘RET’
  150. Ivy is installed as part of the ‘counsel’ package, which is available
  151. from two different package archives, GNU ELPA and MELPA. For the latest
  152. stable version, use the GNU ELPA archives. For current hourly builds,
  153. use the MELPA archives.
  154. Ivy is split into three packages: ‘ivy’, ‘swiper’ and ‘counsel’; by
  155. installing ‘counsel’, the other two are brought in as dependencies. If
  156. you are not interested in the extra functionality provided by ‘swiper’
  157. and ‘counsel’, you can install only ‘ivy’.
  158. See the code below for adding MELPA to the list of package archives:
  159. (require 'package)
  160. (add-to-list 'package-archives
  161. '("melpa" . "https://melpa.org/packages/"))
  162. After this do ‘M-x’ ‘package-refresh-contents’ ‘RET’, followed by
  163. ‘M-x’ ‘package-install’ ‘RET’ ‘counsel’ ‘RET’.
  164. For package manager details, see *note (emacs)Packages::.
  165. 
  166. File: ivy.info, Node: Installing from the Git repository, Prev: Installing from Emacs Package Manager, Up: Installation
  167. 2.2 Installing from the Git repository
  168. ======================================
  169. Why install from Git?
  170. .....................
  171. • No need to wait for MELPA’s hourly builds
  172. • Easy to revert to previous versions
  173. • Contribute to Ivy’s development; send patches; pull requests
  174. Configuration steps
  175. ...................
  176. First clone the Swiper repository with:
  177. cd ~/git && git clone https://github.com/abo-abo/swiper
  178. cd swiper && make compile
  179. Second, add these lines to the Emacs init file:
  180. (add-to-list 'load-path "~/git/swiper/")
  181. (require 'ivy)
  182. Then, update the code with:
  183. git pull
  184. make
  185. 
  186. File: ivy.info, Node: Getting started, Next: Key bindings, Prev: Installation, Up: Top
  187. 3 Getting started
  188. *****************
  189. First enable Ivy completion everywhere:
  190. (ivy-mode 1)
  191. Note: ‘ivy-mode’ can be toggled on and off with ‘M-x’ ‘ivy-mode’.
  192. * Menu:
  193. * Basic customization::
  194. 
  195. File: ivy.info, Node: Basic customization, Up: Getting started
  196. 3.1 Basic customization
  197. =======================
  198. Here are some basic settings particularly useful for new Ivy users:
  199. (setq ivy-use-virtual-buffers t)
  200. (setq ivy-count-format "(%d/%d) ")
  201. If you want, you can go without any customizations at all. The above
  202. settings are the most bang for the buck in terms of customization. So
  203. users that typically don’t like customize a lot are advised to look at
  204. these settings first.
  205. For more advanced customizations, refer to ‘M-x describe-variable’
  206. documentation.
  207. 
  208. File: ivy.info, Node: Key bindings, Next: Completion Styles, Prev: Getting started, Up: Top
  209. 4 Key bindings
  210. **************
  211. * Menu:
  212. * Global key bindings::
  213. * Minibuffer key bindings::
  214. 
  215. File: ivy.info, Node: Global key bindings, Next: Minibuffer key bindings, Up: Key bindings
  216. 4.1 Global key bindings
  217. =======================
  218. Here is a list of commands that are useful to be bound globally, along
  219. with some sample bindings:
  220. Ivy-based interface to standard commands
  221. ........................................
  222. (global-set-key (kbd "C-s") 'swiper-isearch)
  223. (global-set-key (kbd "M-x") 'counsel-M-x)
  224. (global-set-key (kbd "C-x C-f") 'counsel-find-file)
  225. (global-set-key (kbd "M-y") 'counsel-yank-pop)
  226. (global-set-key (kbd "<f1> f") 'counsel-describe-function)
  227. (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
  228. (global-set-key (kbd "<f1> l") 'counsel-find-library)
  229. (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
  230. (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
  231. (global-set-key (kbd "<f2> j") 'counsel-set-variable)
  232. (global-set-key (kbd "C-x b") 'ivy-switch-buffer)
  233. (global-set-key (kbd "C-c v") 'ivy-push-view)
  234. (global-set-key (kbd "C-c V") 'ivy-pop-view)
  235. Ivy-based interface to shell and system tools
  236. .............................................
  237. (global-set-key (kbd "C-c c") 'counsel-compile)
  238. (global-set-key (kbd "C-c g") 'counsel-git)
  239. (global-set-key (kbd "C-c j") 'counsel-git-grep)
  240. (global-set-key (kbd "C-c L") 'counsel-git-log)
  241. (global-set-key (kbd "C-c k") 'counsel-rg)
  242. (global-set-key (kbd "C-c m") 'counsel-linux-app)
  243. (global-set-key (kbd "C-c n") 'counsel-fzf)
  244. (global-set-key (kbd "C-x l") 'counsel-locate)
  245. (global-set-key (kbd "C-c J") 'counsel-file-jump)
  246. (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
  247. (global-set-key (kbd "C-c w") 'counsel-wmctrl)
  248. Ivy-resume and other commands
  249. .............................
  250. ‘ivy-resume’ resumes the last Ivy-based completion.
  251. (global-set-key (kbd "C-c C-r") 'ivy-resume)
  252. (global-set-key (kbd "C-c b") 'counsel-bookmark)
  253. (global-set-key (kbd "C-c d") 'counsel-descbinds)
  254. (global-set-key (kbd "C-c g") 'counsel-git)
  255. (global-set-key (kbd "C-c o") 'counsel-outline)
  256. (global-set-key (kbd "C-c t") 'counsel-load-theme)
  257. (global-set-key (kbd "C-c F") 'counsel-org-file)
  258. You can also enable ‘counsel-mode’ to make some global key binding
  259. remapping for you.
  260. 
  261. File: ivy.info, Node: Minibuffer key bindings, Prev: Global key bindings, Up: Key bindings
  262. 4.2 Minibuffer key bindings
  263. ===========================
  264. Ivy includes several minibuffer bindings, which are defined in the
  265. ‘ivy-minibuffer-map’ keymap variable. The most frequently used ones are
  266. described here.
  267. ‘swiper’ or ‘counsel-M-x’ add more key bindings through the ‘keymap’
  268. argument to ‘ivy-read’. These keys, also active in the minibuffer, are
  269. described under their respective commands.
  270. A key feature of ‘ivy-minibuffer-map’ is its full editing capability
  271. where the familiar ‘C-a’, ‘C-f’, ‘M-d’, ‘M-DEL’, ‘M-b’, ‘M-w’, ‘C-k’,
  272. ‘C-y’ key bindings work the same as in ‘fundamental-mode’.
  273. * Menu:
  274. * Key bindings for navigation::
  275. * Key bindings for single selection, action, then exit minibuffer: Key bindings for single selection action then exit minibuffer.
  276. * Key bindings for multiple selections and actions, keep minibuffer open: Key bindings for multiple selections and actions keep minibuffer open.
  277. * Key bindings that alter the minibuffer input::
  278. * Other key bindings::
  279. * Hydra in the minibuffer::
  280. * Saving the current completion session to a buffer::
  281. 
  282. File: ivy.info, Node: Key bindings for navigation, Next: Key bindings for single selection action then exit minibuffer, Up: Minibuffer key bindings
  283. 4.2.1 Key bindings for navigation
  284. ---------------------------------
  285. • ‘C-n’ (‘ivy-next-line’) selects the next candidate
  286. • ‘C-p’ (‘ivy-previous-line’) selects the previous candidate
  287. • ‘M-<’ (‘ivy-beginning-of-buffer’) selects the first candidate
  288. • ‘M->’ (‘ivy-end-of-buffer’) selects the last candidate
  289. • ‘C-v’ (‘ivy-scroll-up-command’) scrolls up by ‘ivy-height’ lines
  290. • ‘M-v’ (‘ivy-scroll-down-command’) scrolls down by ‘ivy-height’
  291. lines
  292. -- User Option: ivy-wrap
  293. Specifies the wrap-around behavior for ‘C-n’ and ‘C-p’. When
  294. ‘ivy-wrap’ is set to ‘t’, ‘ivy-next-line’ and ‘ivy-previous-line’
  295. will cycle past the last and the first candidates respectively.
  296. Wrap-around behavior is off by default.
  297. -- User Option: ivy-height
  298. Use this option to adjust the minibuffer height, which also affects
  299. scroll size when using ‘C-v’ and ‘M-v’ key bindings.
  300. ‘ivy-height’ is 10 lines by default.
  301. 
  302. File: ivy.info, Node: Key bindings for single selection action then exit minibuffer, Next: Key bindings for multiple selections and actions keep minibuffer open, Prev: Key bindings for navigation, Up: Minibuffer key bindings
  303. 4.2.2 Key bindings for single selection, action, then exit minibuffer
  304. ---------------------------------------------------------------------
  305. Ivy can offer several actions from which to choose which action to run.
  306. This "calling an action" operates on the selected candidate. For
  307. example, when viewing a list of files, one action could open it for
  308. editing, one to view it, another to invoke a special function, and so
  309. on. Custom actions can be added to this interface. The precise action
  310. to call on the selected candidate can be delayed until after the
  311. narrowing is completed. No need to exit the interface if unsure which
  312. action to run. This delayed flexibility and customization of actions
  313. extends usability of lists in Emacs.
  314. ‘C-m’ or ‘RET’ (‘ivy-done’)
  315. ...........................
  316. Calls the default action and then exits the minibuffer.
  317. ‘M-o’ (‘ivy-dispatching-done’)
  318. ..............................
  319. Presents valid actions from which to choose. When only one action
  320. is available, there is no difference between ‘M-o’ and ‘C-m’.
  321. ‘C-j’ (‘ivy-alt-done’)
  322. ......................
  323. When completing file names, selects the current directory candidate
  324. and starts a new completion session there. Otherwise, it is the
  325. same as ‘ivy-done’.
  326. ‘TAB’ (‘ivy-partial-or-done’)
  327. .............................
  328. Attempts partial completion, extending current input as much as
  329. possible. ‘TAB TAB’ is the same as ‘C-j’ (‘ivy-alt-done’).
  330. Example ERT test:
  331. (should
  332. (equal (ivy-with
  333. '(progn
  334. (ivy-read "Test: " '("can do" "can't, sorry" "other"))
  335. ivy-text)
  336. "c <tab>")
  337. "can"))
  338. ‘C-M-j’ (‘ivy-immediate-done’)
  339. ..............................
  340. Exits with _the current input_ instead of _the current candidate_
  341. (like other commands).
  342. This is useful e.g. when you call ‘find-file’ to create a new
  343. file, but the desired name matches an existing file. In that case,
  344. using ‘C-j’ would select that existing file, which isn’t what you
  345. want - use this command instead.
  346. ‘C-'’ (‘ivy-avy’)
  347. .................
  348. Uses avy to select one of the candidates on the current candidate
  349. page. This can often be faster than multiple ‘C-n’ or ‘C-p’
  350. keystrokes followed by ‘C-m’.
  351. 
  352. File: ivy.info, Node: Key bindings for multiple selections and actions keep minibuffer open, Next: Key bindings that alter the minibuffer input, Prev: Key bindings for single selection action then exit minibuffer, Up: Minibuffer key bindings
  353. 4.2.3 Key bindings for multiple selections and actions, keep minibuffer open
  354. ----------------------------------------------------------------------------
  355. For repeatedly applying multiple actions or acting on multiple
  356. candidates, Ivy does not close the minibuffer between commands. It
  357. keeps the minibuffer open for applying subsequent actions.
  358. Adding an extra meta key to the normal key chord invokes the special
  359. version of the regular commands that enables applying multiple actions.
  360. Note that these operations are supported only by completion sessions
  361. that use the ‘ivy-read’ API, rather than the built-in ‘completing-read’.
  362. ‘C-M-m’ (‘ivy-call’)
  363. ....................
  364. Is the non-exiting version of ‘C-m’ (‘ivy-done’).
  365. Instead of closing the minibuffer, ‘C-M-m’ allows selecting another
  366. candidate or another action. For example, ‘C-M-m’ on functions
  367. list invokes ‘describe-function’. When combined with ‘C-n’,
  368. function descriptions can be invoked quickly in succession.
  369. ‘C-M-o’ (‘ivy-dispatching-call’)
  370. ................................
  371. Is the non-exiting version of ‘M-o’ (‘ivy-dispatching-done’).
  372. For example, during the ‘counsel-rhythmbox’ completion, press
  373. ‘C-M-o e’ to en-queue the selected candidate, followed by ‘C-n C-m’
  374. to play the next candidate - the current action reverts to the
  375. default one after ‘C-M-o’.
  376. ‘C-M-n’ (‘ivy-next-line-and-call’)
  377. ..................................
  378. Combines ‘C-n’ and ‘C-M-m’. Moves to next line and applies an
  379. action.
  380. Comes in handy when opening multiple files from
  381. ‘counsel-find-file’, ‘counsel-git-grep’, ‘counsel-ag’,
  382. ‘counsel-rg’, or ‘counsel-locate’ lists. Just hold ‘C-M-n’ for
  383. rapid-fire default action on each successive element of the list.
  384. ‘C-M-p’ (‘ivy-previous-line-and-call’)
  385. ......................................
  386. Combines ‘C-p’ and ‘C-M-m’.
  387. Similar to the above except it moves through the list in the other
  388. direction.
  389. ‘ivy-resume’
  390. ............
  391. Recalls the state of the completion session just before its last
  392. exit.
  393. Useful after an accidental ‘C-m’ (‘ivy-done’). Use it with
  394. ‘universal-argument’ to resume any previous session.
  395. 
  396. File: ivy.info, Node: Key bindings that alter the minibuffer input, Next: Other key bindings, Prev: Key bindings for multiple selections and actions keep minibuffer open, Up: Minibuffer key bindings
  397. 4.2.4 Key bindings that alter the minibuffer input
  398. --------------------------------------------------
  399. ‘M-n’ (‘ivy-next-history-element’)
  400. ..................................
  401. Cycles forward through the Ivy command history.
  402. Ivy updates an internal history list after each action. When this
  403. history list is empty, ‘M-n’ inserts symbol (or URL) at point into
  404. the minibuffer.
  405. ‘M-p’ (‘ivy-previous-history-element’)
  406. ......................................
  407. Cycles forward through the Ivy command history.
  408. ‘M-i’ (‘ivy-insert-current’)
  409. ............................
  410. Inserts the current candidate into the minibuffer.
  411. Useful for copying and renaming files, for example: ‘M-i’ to insert
  412. the original file name string, edit it, and then ‘C-m’ to complete
  413. the renaming.
  414. ‘M-j’ (‘ivy-yank-word’)
  415. .......................
  416. Inserts the sub-word at point into the minibuffer.
  417. This is similar to ‘C-s C-w’ with ‘isearch’. Ivy reserves ‘C-w’
  418. for ‘kill-region’. See also ‘ivy-yank-symbol’ and ‘ivy-yank-char’.
  419. ‘S-SPC’ (‘ivy-restrict-to-matches’)
  420. ...................................
  421. Deletes the current input, and resets the candidates list to the
  422. currently restricted matches.
  423. This is how Ivy provides narrowing in successive tiers.
  424. ‘C-r’ (‘ivy-reverse-i-search’)
  425. ..............................
  426. Starts a recursive completion session through the command’s
  427. history.
  428. This works just like ‘C-r’ at the bash command prompt, where the
  429. completion candidates are the history items. Upon completion, the
  430. selected candidate string is inserted into the minibuffer.
  431. 
  432. File: ivy.info, Node: Other key bindings, Next: Hydra in the minibuffer, Prev: Key bindings that alter the minibuffer input, Up: Minibuffer key bindings
  433. 4.2.5 Other key bindings
  434. ------------------------
  435. ‘M-w’ (‘ivy-kill-ring-save’)
  436. ............................
  437. Copies selected candidates to the kill ring.
  438. Copies the region if the region is active.
  439. 
  440. File: ivy.info, Node: Hydra in the minibuffer, Next: Saving the current completion session to a buffer, Prev: Other key bindings, Up: Minibuffer key bindings
  441. 4.2.6 Hydra in the minibuffer
  442. -----------------------------
  443. ‘C-o’ (‘hydra-ivy/body’)
  444. ........................
  445. Invokes the hydra menu with short key bindings.
  446. When Hydra is active, minibuffer editing is disabled and menus
  447. display short aliases:
  448. Short Normal Command name
  449. ------------------------------------------------
  450. ‘o’ ‘C-g’ ‘keyboard-escape-quit’
  451. ‘j’ ‘C-n’ ‘ivy-next-line’
  452. ‘k’ ‘C-p’ ‘ivy-previous-line’
  453. ‘h’ ‘M-<’ ‘ivy-beginning-of-buffer’
  454. ‘l’ ‘M->’ ‘ivy-end-of-buffer’
  455. ‘d’ ‘C-m’ ‘ivy-done’
  456. ‘f’ ‘C-j’ ‘ivy-alt-done’
  457. ‘g’ ‘C-M-m’ ‘ivy-call’
  458. ‘u’ ‘C-c C-o’ ‘ivy-occur’
  459. Hydra reduces key strokes, for example: ‘C-n C-n C-n C-n’ is ‘C-o
  460. jjjj’ in Hydra.
  461. Hydra menu offers these additional bindings:
  462. ‘c’ (‘ivy-toggle-calling’)
  463. ..........................
  464. Toggle calling the action after each candidate change. It modifies
  465. ‘j’ to ‘jg’, ‘k’ to ‘kg’ etc.
  466. ‘m’ (‘ivy-rotate-preferred-builders’)
  467. .....................................
  468. Rotate the current regexp matcher.
  469. ‘>’ (‘ivy-minibuffer-grow’)
  470. ...........................
  471. Increase ‘ivy-height’ for the current minibuffer.
  472. ‘<’ (‘ivy-minibuffer-shrink’)
  473. .............................
  474. Decrease ‘ivy-height’ for the current minibuffer.
  475. ‘w’ (‘ivy-prev-action’)
  476. .......................
  477. Select the previous action.
  478. ‘s’ (‘ivy-next-action’)
  479. .......................
  480. Select the next action.
  481. ‘a’ (‘ivy-read-action’)
  482. .......................
  483. Use a menu to select an action.
  484. ‘C’ (‘ivy-toggle-case-fold’)
  485. ............................
  486. Toggle case folding (match both upper and lower case characters for
  487. lower case input).
  488. Hydra menu also offers bindings for marking multiple candidates:
  489. Key Command name
  490. --------------------------------
  491. ‘m’ ‘ivy-mark’
  492. ‘u’ ‘ivy-unmark’
  493. ‘DEL’ ‘ivy-unmark-backward’
  494. ‘t’ ‘ivy-toggle-marks’
  495. The action is called on each marked candidate one by one.
  496. 
  497. File: ivy.info, Node: Saving the current completion session to a buffer, Prev: Hydra in the minibuffer, Up: Minibuffer key bindings
  498. 4.2.7 Saving the current completion session to a buffer
  499. -------------------------------------------------------
  500. ‘C-c C-o’ (‘ivy-occur’)
  501. .......................
  502. Saves the current candidates to a new buffer and exits completion.
  503. The new buffer is read-only and has a few useful bindings defined.
  504. ‘RET’ or ‘f’ (‘ivy-occur-press’)
  505. ................................
  506. Call the current action on the selected candidate.
  507. ‘mouse-1’ (‘ivy-occur-click’)
  508. .............................
  509. Call the current action on the selected candidate.
  510. ‘j’ (‘next-line’)
  511. .................
  512. Move to next line.
  513. ‘k’ (‘previous-line’)
  514. .....................
  515. Move to previous line.
  516. ‘a’ (‘ivy-occur-read-action’)
  517. .............................
  518. Read an action and make it current for this buffer.
  519. ‘o’ (‘ivy-occur-dispatch’)
  520. ..........................
  521. Read an action and call it on the selected candidate.
  522. ‘q’ (‘quit-window’)
  523. ...................
  524. Bury the current buffer.
  525. Ivy has no limit on the number of active buffers like these.
  526. Ivy takes care of naming buffers uniquely by constructing descriptive
  527. names. For example: ‘*ivy-occur counsel-describe-variable "function$*’.
  528. 
  529. File: ivy.info, Node: Completion Styles, Next: Customization, Prev: Key bindings, Up: Top
  530. 5 Completion Styles
  531. *******************
  532. Ivy’s completion functions rely on a regex builder - a function that
  533. transforms a string input to a string regex. All current candidates
  534. simply have to match this regex. Each collection can be assigned its
  535. own regex builder by customizing ‘ivy-re-builders-alist’.
  536. The keys of this alist are collection names, and the values are one
  537. of the following:
  538. • ‘ivy--regex’
  539. • ‘ivy--regex-plus’
  540. • ‘ivy--regex-ignore-order’
  541. • ‘ivy--regex-fuzzy’
  542. • ‘regexp-quote’
  543. A catch-all key, ‘t’, applies to all collections that don’t have
  544. their own key.
  545. The default is:
  546. (setq ivy-re-builders-alist
  547. '((t . ivy--regex-plus)))
  548. This example shows a custom regex builder assigned to file name
  549. completion:
  550. (setq ivy-re-builders-alist
  551. '((read-file-name-internal . ivy--regex-fuzzy)
  552. (t . ivy--regex-plus)))
  553. Here, ‘read-file-name-internal’ is a function that is passed as the
  554. second argument to ‘completing-read’ for file name completion.
  555. The regex builder resolves as follows (in order of priority):
  556. 1. ‘re-builder’ argument passed to ‘ivy-read’.
  557. 2. ‘collection’ argument passed to ‘ivy-read’ is a function and has an
  558. entry on ‘ivy-re-builders-alist’.
  559. 3. ‘caller’ argument passed to ‘ivy-read’ has an entry on
  560. ‘ivy-re-builders-alist’.
  561. 4. ‘this-command’ has an entry on ‘ivy-re-builders-alist’.
  562. 5. ‘t’ has an entry on ‘ivy-re-builders-alist’.
  563. 6. ‘ivy--regex’.
  564. * Menu:
  565. * ivy--regex-plus::
  566. * ivy--regex-ignore-order::
  567. * ivy--regex-fuzzy::
  568. 
  569. File: ivy.info, Node: ivy--regex-plus, Next: ivy--regex-ignore-order, Up: Completion Styles
  570. 5.1 ivy–regex-plus
  571. ==================
  572. ‘ivy--regex-plus’ is Ivy’s default completion method.
  573. ‘ivy--regex-plus’ matches by splitting the input by spaces and
  574. rebuilding it into a regex.
  575. As the search string is typed in Ivy’s minibuffer, it is transformed
  576. into valid regex syntax. If the string is ‘"for example"’, it is
  577. transformed into
  578. "\\(for\\).*\\(example\\)"
  579. which in regex terminology matches ‘"for"’ followed by a wild card
  580. and then ‘"example"’. Note how Ivy uses the space character to build
  581. wild cards. To match a literal white space, use an extra space. So to
  582. match one space type two spaces, to match two spaces type three spaces,
  583. and so on.
  584. As Ivy transforms typed characters into regex strings, it provides an
  585. intuitive feedback through font highlights.
  586. Ivy supports regexp negation with ‘"!"’. For example, ‘"define key !
  587. ivy quit"’ first selects everything matching ‘"define.*key"’, then
  588. removes everything matching ‘"ivy"’, and finally removes everything
  589. matching ‘"quit"’. What remains is the final result set of the negation
  590. regexp.
  591. Since Ivy treats minibuffer input as a regexp, the standard regexp
  592. identifiers work: ‘"^"’, ‘"$"’, ‘"\b"’ or ‘"[a-z]"’. The exceptions are
  593. spaces, which translate to ‘".*"’, and ‘"!"’ that signal the beginning
  594. of a negation group.
  595. 
  596. File: ivy.info, Node: ivy--regex-ignore-order, Next: ivy--regex-fuzzy, Prev: ivy--regex-plus, Up: Completion Styles
  597. 5.2 ivy–regex-ignore-order
  598. ==========================
  599. ‘ivy--regex-ignore-order’ ignores the order of regexp tokens when
  600. searching for matching candidates. For instance, the input ‘"for
  601. example"’ will match ‘"example test for"’.
  602. 
  603. File: ivy.info, Node: ivy--regex-fuzzy, Prev: ivy--regex-ignore-order, Up: Completion Styles
  604. 5.3 ivy–regex-fuzzy
  605. ===================
  606. ‘ivy--regex-fuzzy’ splits each character with a wild card. Searching
  607. for ‘"for"’ returns all ‘"f.*o.*r"’ matches, resulting in a large number
  608. of hits. Yet some searches need these extra hits. Ivy sorts such large
  609. lists using ‘flx’ package’s scoring mechanism, if it’s installed.
  610. ‘C-o m’ toggles the current regexp builder.
  611. 
  612. File: ivy.info, Node: Customization, Next: Commands, Prev: Completion Styles, Up: Top
  613. 6 Customization
  614. ***************
  615. * Menu:
  616. * Faces::
  617. * Defcustoms::
  618. * Actions::
  619. * Packages::
  620. 
  621. File: ivy.info, Node: Faces, Next: Defcustoms, Up: Customization
  622. 6.1 Faces
  623. =========
  624. ‘ivy-current-match’
  625. ...................
  626. Highlights the currently selected candidate.
  627. ‘ivy-minibuffer-match-face-1’
  628. .............................
  629. Highlights the background of the match.
  630. ‘ivy-minibuffer-match-face-2’
  631. .............................
  632. Highlights the first (modulo 3) matched group.
  633. ‘ivy-minibuffer-match-face-3’
  634. .............................
  635. Highlights the second (modulo 3) matched group.
  636. ‘ivy-minibuffer-match-face-4’
  637. .............................
  638. Highlights the third (modulo 3) matched group.
  639. ‘ivy-confirm-face’
  640. ..................
  641. Highlights the "(confirm)" part of the prompt.
  642. When ‘confirm-nonexistent-file-or-buffer’ set to ‘t’, then
  643. confirming non-existent files in ‘ivy-mode’ requires an additional
  644. ‘RET’.
  645. The confirmation prompt will use this face.
  646. For example:
  647. (setq confirm-nonexistent-file-or-buffer t)
  648. Then call ‘find-file’, enter "eldorado" and press ‘RET’ - the
  649. prompt will be appended with "(confirm)". Press ‘RET’ once more to
  650. confirm, or any key to continue the completion.
  651. ‘ivy-match-required-face’
  652. .........................
  653. Highlights the "(match required)" part of the prompt.
  654. When completions have to match available candidates and cannot take
  655. random input, the "(match required)" prompt signals this
  656. constraint.
  657. For example, call ‘describe-variable’, enter "waldo" and press
  658. ‘RET’ - "(match required)" is prompted. Press any key for the
  659. prompt to disappear.
  660. ‘ivy-subdir’
  661. ............
  662. Highlights directories when completing file names.
  663. ‘ivy-remote’
  664. ............
  665. Highlights remote files when completing file names.
  666. ‘ivy-virtual’
  667. .............
  668. Highlights virtual buffers when completing buffer names.
  669. Virtual buffers correspond to bookmarks and recent files list,
  670. ‘recentf’.
  671. Enable virtual buffers with:
  672. (setq ivy-use-virtual-buffers t)
  673. ‘ivy-modified-buffer’
  674. .....................
  675. Highlights modified buffers when switching buffer.
  676. ‘ivy-modified-outside-buffer’
  677. .............................
  678. Highlights buffers modified outside Emacs when switching buffer.
  679. This takes precedence over ‘ivy-modified-buffer’.
  680. 
  681. File: ivy.info, Node: Defcustoms, Next: Actions, Prev: Faces, Up: Customization
  682. 6.2 Defcustoms
  683. ==============
  684. -- User Option: ivy-count-format
  685. A string that specifies display of number of candidates and current
  686. candidate, if one exists.
  687. The number of matching candidates by default is shown as a right-
  688. padded integer value.
  689. To disable showing the number of candidates:
  690. (setq ivy-count-format "")
  691. To also display the current candidate:
  692. (setq ivy-count-format "(%d/%d) ")
  693. The ‘format’-style switches this variable uses are described in the
  694. ‘format’ documentation.
  695. -- User Option: ivy-display-style
  696. Specifies highlighting candidates in the minibuffer.
  697. The default setting is ‘'fancy’ in Emacs versions 24.4 or newer.
  698. Set ‘ivy-display-style’ to ‘nil’ for a plain minibuffer.
  699. -- User Option: ivy-on-del-error-function
  700. Specifies what to do when ‘DEL’ (‘ivy-backward-delete-char’) fails.
  701. This is usually the case when there is no text left to delete,
  702. i.e., when ‘DEL’ is typed at the beginning of the minibuffer.
  703. The default behavior is to quit the completion after ‘DEL’ – a
  704. handy key to invoke after mistakenly triggering a completion.
  705. Another common option is ‘ignore’, which does nothing.
  706. 
  707. File: ivy.info, Node: Actions, Next: Packages, Prev: Defcustoms, Up: Customization
  708. 6.3 Actions
  709. ===========
  710. * Menu:
  711. * What are actions?::
  712. * How can different actions be called?::
  713. * How to modify the actions list?::
  714. * Example - add two actions to each command::
  715. * Example - define a new command with several actions::
  716. 
  717. File: ivy.info, Node: What are actions?, Next: How can different actions be called?, Up: Actions
  718. 6.3.1 What are actions?
  719. -----------------------
  720. An action is a function that is called after you select a candidate
  721. during completion. This function takes a single string argument, which
  722. is the selected candidate.
  723. Window context when calling an action
  724. .....................................
  725. Currently, the action is executed in the minibuffer window context.
  726. This means e.g. that if you call ‘insert’ the text will be
  727. inserted into the minibuffer.
  728. If you want to execute the action in the initial window from which
  729. the completion started, use the ‘with-ivy-window’ wrapper macro.
  730. (defun ivy-insert-action (x)
  731. (with-ivy-window
  732. (insert x)))
  733. 
  734. File: ivy.info, Node: How can different actions be called?, Next: How to modify the actions list?, Prev: What are actions?, Up: Actions
  735. 6.3.2 How can different actions be called?
  736. ------------------------------------------
  737. • ‘C-m’ (‘ivy-done’) calls the current action.
  738. • ‘M-o’ (‘ivy-dispatching-done’) presents available actions for
  739. selection, calls it after selection, and then exits.
  740. • ‘C-M-o’ (‘ivy-dispatching-call’) presents available actions for
  741. selection, calls it after selection, and then does not exit.
  742. 
  743. File: ivy.info, Node: How to modify the actions list?, Next: Example - add two actions to each command, Prev: How can different actions be called?, Up: Actions
  744. 6.3.3 How to modify the actions list?
  745. -------------------------------------
  746. Currently, you can append any amount of your own actions to the default
  747. list of actions. This can be done either for a specific command, or for
  748. all commands at once.
  749. Usually, the command has only one default action. The convention is
  750. to use single letters when selecting a command, and the letter ‘o’ is
  751. designated for the default command. This way, ‘M-o o’ should be always
  752. equivalent to ‘C-m’.
  753. 
  754. File: ivy.info, Node: Example - add two actions to each command, Next: Example - define a new command with several actions, Prev: How to modify the actions list?, Up: Actions
  755. 6.3.4 Example - add two actions to each command
  756. -----------------------------------------------
  757. The first action inserts the current candidate into the Ivy window - the
  758. window from which ‘ivy-read’ was called.
  759. The second action copies the current candidate to the kill ring.
  760. (defun ivy-yank-action (x)
  761. (kill-new x))
  762. (defun ivy-copy-to-buffer-action (x)
  763. (with-ivy-window
  764. (insert x)))
  765. (ivy-set-actions
  766. t
  767. '(("i" ivy-copy-to-buffer-action "insert")
  768. ("y" ivy-yank-action "yank")))
  769. Then in any completion session, ‘M-o y’ invokes ‘ivy-yank-action’,
  770. and ‘M-o i’ invokes ‘ivy-copy-to-buffer-action’.
  771. * Menu:
  772. * How to undo adding the two actions::
  773. * How to add actions to a specific command::
  774. 
  775. File: ivy.info, Node: How to undo adding the two actions, Next: How to add actions to a specific command, Up: Example - add two actions to each command
  776. 6.3.4.1 How to undo adding the two actions
  777. ..........................................
  778. Since ‘ivy-set-actions’ modifies the internal dictionary with new data,
  779. set the extra actions list to ‘nil’ by assigning ‘nil’ value to the ‘t’
  780. key as follows:
  781. (ivy-set-actions t nil)
  782. 
  783. File: ivy.info, Node: How to add actions to a specific command, Prev: How to undo adding the two actions, Up: Example - add two actions to each command
  784. 6.3.4.2 How to add actions to a specific command
  785. ................................................
  786. Use the command name as the key:
  787. (ivy-set-actions
  788. 'swiper
  789. '(("i" ivy-copy-to-buffer-action "insert")
  790. ("y" ivy-yank-action "yank")))
  791. 
  792. File: ivy.info, Node: Example - define a new command with several actions, Prev: Example - add two actions to each command, Up: Actions
  793. 6.3.5 Example - define a new command with several actions
  794. ---------------------------------------------------------
  795. (defun my-action-1 (x)
  796. (message "action-1: %s" x))
  797. (defun my-action-2 (x)
  798. (message "action-2: %s" x))
  799. (defun my-action-3 (x)
  800. (message "action-3: %s" x))
  801. (defun my-command-with-3-actions ()
  802. (interactive)
  803. (ivy-read "test: " '("foo" "bar" "baz")
  804. :action '(1
  805. ("o" my-action-1 "action 1")
  806. ("j" my-action-2 "action 2")
  807. ("k" my-action-3 "action 3"))))
  808. The number 1 above is the index of the default action. Each action
  809. has its own string description for easy selection.
  810. * Menu:
  811. * Test the above function with ivy-occur::
  812. 
  813. File: ivy.info, Node: Test the above function with ivy-occur, Up: Example - define a new command with several actions
  814. 6.3.5.1 Test the above function with ‘ivy-occur’
  815. ................................................
  816. To examine each action with each candidate in a key-efficient way, try:
  817. • Call ‘my-command-with-3-actions’
  818. • Press ‘C-c C-o’ to close the completion window and move to an
  819. ivy-occur buffer
  820. • Press ‘kkk’ to move to the first candidate, since the point is most
  821. likely at the end of the buffer
  822. • Press ‘oo’ to call the first action
  823. • Press ‘oj’ and ‘ok’ to call the second and the third actions
  824. • Press ‘j’ to move to the next candidate
  825. • Press ‘oo’, ‘oj’, ‘ok’
  826. • Press ‘j’ to move to the next candidate
  827. • and so on...
  828. 
  829. File: ivy.info, Node: Packages, Prev: Actions, Up: Customization
  830. 6.4 Packages
  831. ============
  832. ‘org-mode’
  833. ..........
  834. ‘org-mode’ versions 8.3.3 or later obey ‘completing-read-function’
  835. (which ‘ivy-mode’ sets). Try refiling headings with similar names
  836. to appreciate ‘ivy-mode’.
  837. ‘magit’
  838. .......
  839. Uses ivy by default if Ivy is installed.
  840. ‘find-file-in-project’
  841. ......................
  842. Uses ivy by default if Ivy is installed.
  843. ‘projectile’
  844. ............
  845. Projectile requires this setting for ivy completion:
  846. (setq projectile-completion-system 'ivy)
  847. ‘helm-make’
  848. ...........
  849. Helm-make requires this setting for ivy completion.
  850. (setq helm-make-completion-method 'ivy)
  851. automatically integrated packages
  852. .................................
  853. Ivy re-uses the following packages if they are installed: ‘avy’,
  854. ‘amx’ or ‘smex’, ‘flx’, and ‘wgrep’.
  855. 
  856. File: ivy.info, Node: Commands, Next: API, Prev: Customization, Up: Top
  857. 7 Commands
  858. **********
  859. * Menu:
  860. * File Name Completion::
  861. * Buffer Name Completion::
  862. * Counsel commands::
  863. 
  864. File: ivy.info, Node: File Name Completion, Next: Buffer Name Completion, Up: Commands
  865. 7.1 File Name Completion
  866. ========================
  867. Since file name completion is ubiquitous, Ivy provides extra bindings
  868. that work here:
  869. ‘C-j’ (‘ivy-alt-done’)
  870. ......................
  871. On a directory, restarts completion from that directory.
  872. On a file or ‘./’, exit completion with the selected candidate.
  873. ‘DEL’ (‘ivy-backward-delete-char’)
  874. ..................................
  875. Restart the completion in the parent directory if current input is
  876. empty.
  877. ‘//’ (‘self-insert-command’)
  878. ............................
  879. Switch to the root directory.
  880. ‘~’ (‘self-insert-command’)
  881. ...........................
  882. Switch to the home directory.
  883. ‘/’ (‘self-insert-command’)
  884. ...........................
  885. If the current input matches an existing directory name exactly,
  886. switch the completion to that directory.
  887. ‘C-M-y’ (‘ivy-insert-current-full’)
  888. ...................................
  889. Insert the current full path, in case you want to edit a part of
  890. it.
  891. ‘M-r’ (‘ivy-toggle-regexp-quote’)
  892. .................................
  893. Toggle between input as regexp or not.
  894. Switch to matching literally since file names include ‘.’, which is
  895. for matching any char in regexp mode.
  896. -- User Option: ivy-extra-directories
  897. Decide if you want to see ‘../’ and ‘./’ during file name
  898. completion.
  899. Reason to remove: ‘../’ is the same as ‘DEL’.
  900. Reason not to remove: navigate anywhere with only ‘C-n’, ‘C-p’ and
  901. ‘C-j’.
  902. Likewise, ‘./’ can be removed.
  903. History
  904. .......
  905. File history works the same with ‘M-p’, ‘M-n’, and ‘C-r’, but uses
  906. a custom code for file name completion that cycles through files
  907. previously opened. It also works with TRAMP files.
  908. * Menu:
  909. * Using TRAMP::
  910. 
  911. File: ivy.info, Node: Using TRAMP, Up: File Name Completion
  912. 7.1.1 Using TRAMP
  913. -----------------
  914. ‘~’ (tilde)
  915. ...........
  916. Move to the home directory. Either the local or the remote one,
  917. depending on the current directory. The boolean option
  918. ‘ivy-magic-tilde’ decides whether the binding to do this is ‘~’ or
  919. ‘~/’.
  920. ‘//’ (double slash)
  921. ...................
  922. Move to the root directory. Either the local or the remote one,
  923. depending on the current directory. Here, you can also select a
  924. TRAMP connection method, such as ‘ssh’ or ‘scpx’.
  925. ‘/ C-j’
  926. .......
  927. Move the the local root directory.
  928. ‘~~’
  929. ....
  930. Move to the local home directory.
  931. From any directory, with the empty input, inputting ‘/ssh:’ and
  932. pressing ‘C-j’ (or ‘RET’, which is the same thing) completes for host
  933. and user names.
  934. For ‘/ssh:user@’ input, completes the domain name.
  935. ‘C-i’ works in a similar way to the default completion.
  936. You can also get sudo access for the current directory by inputting
  937. ‘/sudo::’ ‘RET’. Using ‘/sudo:’ (i.e. single colon instead of double)
  938. will result in a completion session for the desired user.
  939. Multi-hopping is possible, although a bit complex.
  940. Example : connect to a remote host ‘cloud’ and open a file with ‘sudo’ there
  941. ............................................................................
  942. • ‘C-x C-f’ ‘/ssh:cloud|sudo:root:/’.
  943. 
  944. File: ivy.info, Node: Buffer Name Completion, Next: Counsel commands, Prev: File Name Completion, Up: Commands
  945. 7.2 Buffer Name Completion
  946. ==========================
  947. -- User Option: ivy-use-virtual-buffers
  948. When non-nil, add ‘recentf-mode’ and bookmarks to
  949. ‘ivy-switch-buffer’ completion candidates.
  950. Adding this to Emacs init file:
  951. (setq ivy-use-virtual-buffers t)
  952. will add additional virtual buffers to the buffers list for recent
  953. files. Selecting such virtual buffers, which are highlighted with
  954. ‘ivy-virtual’ face, will open the corresponding file.
  955. 
  956. File: ivy.info, Node: Counsel commands, Prev: Buffer Name Completion, Up: Commands
  957. 7.3 Counsel commands
  958. ====================
  959. The main advantages of ‘counsel-’ functions over their basic equivalents
  960. in ‘ivy-mode’ are:
  961. 1. Multi-actions and non-exiting actions work.
  962. 2. ‘ivy-resume’ can resume the last completion session.
  963. 3. Customize ‘ivy-set-actions’, ‘ivy-re-builders-alist’.
  964. 4. Customize individual keymaps, such as ‘counsel-describe-map’,
  965. ‘counsel-git-grep-map’, or ‘counsel-find-file-map’, instead of
  966. customizing ‘ivy-minibuffer-map’ that applies to all completion
  967. sessions.
  968. 
  969. File: ivy.info, Node: API, Next: Variable Index, Prev: Commands, Up: Top
  970. 8 API
  971. *****
  972. The main (and only) entry point is the ‘ivy-read’ function. It takes
  973. two required arguments and many optional arguments that can be passed by
  974. a key. The optional ‘:action’ argument is highly recommended for
  975. features such as multi-actions, non-exiting actions, ‘ivy-occur’ and
  976. ‘ivy-resume’.
  977. * Menu:
  978. * Required arguments for ivy-read::
  979. * Optional arguments for ivy-read::
  980. * Example - counsel-describe-function::
  981. * Example - counsel-locate::
  982. * Example - ivy-read-with-extra-properties::
  983. 
  984. File: ivy.info, Node: Required arguments for ivy-read, Next: Optional arguments for ivy-read, Up: API
  985. 8.1 Required arguments for ‘ivy-read’
  986. =====================================
  987. ‘prompt’
  988. ........
  989. A prompt string normally ending in a colon and a space.
  990. ‘ivy-count-format’ is prepended to it during completion.
  991. ‘collection’
  992. ............
  993. Either a list of strings, a function, an alist or a hash table.
  994. If a function, then it has to be compatible with ‘all-completions’.
  995. 
  996. File: ivy.info, Node: Optional arguments for ivy-read, Next: Example - counsel-describe-function, Prev: Required arguments for ivy-read, Up: API
  997. 8.2 Optional arguments for ‘ivy-read’
  998. =====================================
  999. ‘predicate’
  1000. ...........
  1001. Is a function to filter the initial collection. It has to be
  1002. compatible with ‘all-completions’. Tip: most of the time, it’s
  1003. simpler to just apply this filter to the ‘collection’ argument
  1004. itself, e.g. ‘(cl-remove-if-not predicate collection)’.
  1005. ‘require-match’
  1006. ...............
  1007. When set to a non-nil value, input must match one of the
  1008. candidates. Custom input is not accepted.
  1009. ‘initial-input’
  1010. ...............
  1011. This string argument is included for compatibility with
  1012. ‘completing-read’, which inserts it into the minibuffer.
  1013. It’s recommended to use the ‘preselect’ argument instead of this.
  1014. ‘history’
  1015. .........
  1016. Name of the symbol to store history. See ‘completing-read’.
  1017. ‘preselect’
  1018. ...........
  1019. Determines which one of the candidates to initially select.
  1020. When set to an integer value, select the candidate with that index
  1021. value.
  1022. When set to any other non-nil value, select the first candidate
  1023. matching this value. Comparison is first done with ‘equal’. If
  1024. this fails, and when applicable, match ‘preselect’ as a regular
  1025. expression.
  1026. Every time the input becomes empty, the item corresponding to
  1027. ‘preselect’ is selected.
  1028. ‘keymap’
  1029. ........
  1030. A keymap to be composed with ‘ivy-minibuffer-map’. This keymap has
  1031. priority over ‘ivy-minibuffer-map’ and can be modified at any later
  1032. stage.
  1033. ‘update-fn’
  1034. ...........
  1035. Is the function called each time the current candidate changes.
  1036. This function takes no arguments and is called in the minibuffer’s
  1037. ‘post-command-hook’. See ‘swiper’ for an example usage.
  1038. ‘sort’
  1039. ......
  1040. When non-nil, use ‘ivy-sort-functions-alist’ to sort the collection
  1041. as long as the collection is not larger than ‘ivy-sort-max-size’.
  1042. ‘action’
  1043. ........
  1044. Is the function to call after selection. It takes a string
  1045. argument.
  1046. ‘unwind’
  1047. ........
  1048. Is the function to call before exiting completion. It takes no
  1049. arguments. This function is called even if the completion is
  1050. interrupted with ‘C-g’. See ‘swiper’ for an example usage.
  1051. ‘re-builder’
  1052. ............
  1053. Is a function that takes a string and returns a valid regex. See
  1054. ‘Completion Styles’ for details.
  1055. ‘matcher’
  1056. .........
  1057. Is a function that takes a regex string and a list of strings and
  1058. returns a list of strings matching the regex. Any ordinary Emacs
  1059. matching function will suffice, yet finely tuned matching functions
  1060. can be used. See ‘counsel-find-file’ for an example usage.
  1061. ‘dynamic-collection’
  1062. ....................
  1063. When non-nil, ‘collection’ will be used to dynamically generate the
  1064. candidates each time the input changes, instead of being used once
  1065. statically with ‘all-completions’ to generate a list of strings.
  1066. See ‘counsel-locate’ for an example usage.
  1067. ‘caller’
  1068. ........
  1069. Is a symbol that uniquely identifies the function that called
  1070. ‘ivy-read’, which may be useful for further customizations.
  1071. 
  1072. File: ivy.info, Node: Example - counsel-describe-function, Next: Example - counsel-locate, Prev: Optional arguments for ivy-read, Up: API
  1073. 8.3 Example - ‘counsel-describe-function’
  1074. =========================================
  1075. This is a typical example of a function with a non-async collection,
  1076. which is a collection where all the strings in the collection are known
  1077. prior to any input from the user.
  1078. Only the first two arguments (along with ‘action’) are essential -
  1079. the rest of the arguments are for fine-tuning, and could be omitted.
  1080. The ‘action’ argument could also be omitted - but then ‘ivy-read’
  1081. would do nothing except returning the string result, which you could
  1082. later use yourself. However, it’s recommended that you use the ‘action’
  1083. argument.
  1084. (defun counsel-describe-function ()
  1085. "Forward to `describe-function'."
  1086. (interactive)
  1087. (ivy-read "Describe function: "
  1088. (let (cands)
  1089. (mapatoms
  1090. (lambda (x)
  1091. (when (fboundp x)
  1092. (push (symbol-name x) cands))))
  1093. cands)
  1094. :keymap counsel-describe-map
  1095. :preselect (ivy-thing-at-point)
  1096. :history 'counsel-describe-symbol-history
  1097. :require-match t
  1098. :action (lambda (x)
  1099. (describe-function
  1100. (intern x)))
  1101. :caller 'counsel-describe-function))
  1102. Here are the interesting features of the above function, in the order
  1103. that they appear:
  1104. • The ‘prompt’ argument is a simple string ending in ": ".
  1105. • The ‘collection’ argument evaluates to a (large) list of strings.
  1106. • The ‘keymap’ argument is for a custom keymap to supplement
  1107. ‘ivy-minibuffer-map’.
  1108. • The ‘preselect’ is provided by ‘ivy-thing-at-point’, which returns
  1109. a symbol near the point. Ivy then selects the first candidate from
  1110. the collection that matches this symbol. To select this
  1111. pre-selected candidate, a ‘RET’ will suffice. No further user
  1112. input is necessary.
  1113. • The ‘history’ argument is for keeping the history of this command
  1114. separate from the common history in ‘ivy-history’.
  1115. • The ‘require-match’ is set to ‘t’ since it doesn’t make sense to
  1116. call ‘describe-function’ on an un-interned symbol.
  1117. • The ‘action’ argument calls ‘describe-function’ on the interned
  1118. selected candidate.
  1119. • The ‘caller’ argument identifies this completion session. This is
  1120. important, since with the collection being a list of strings and
  1121. not a function name, the only other way for ‘ivy-read’ to identify
  1122. "who’s calling" and to apply the appropriate customizations is to
  1123. examine ‘this-command’. But ‘this-command’ would be modified if
  1124. another command called ‘counsel-describe-function’.
  1125. 
  1126. File: ivy.info, Node: Example - counsel-locate, Next: Example - ivy-read-with-extra-properties, Prev: Example - counsel-describe-function, Up: API
  1127. 8.4 Example - ‘counsel-locate’
  1128. ==============================
  1129. This is a typical example of a function with an async collection. Since
  1130. the collection function cannot pre-compute all the locatable files in
  1131. memory within reasonable limits (time or memory), it relies on user
  1132. input to filter the universe of possible candidates to a manageable size
  1133. while also continuing to search asynchronously for possible candidates.
  1134. Both the filtering and searching continues with each character change of
  1135. the input with rapid updates to the collection presented without idle
  1136. waiting times. This live update will continue as long as there are
  1137. likely candidates. Eventually updates to the minibuffer will stop after
  1138. user input, filtering, and searching have exhausted looking for possible
  1139. candidates.
  1140. Async collections suit long-running shell commands, such as ‘locate’.
  1141. With each new input, a new process starts while the old process is
  1142. killed. The collection is refreshed anew with each new process.
  1143. Meanwhile the user can provide more input characters (for further
  1144. narrowing) or select a candidate from the visible collection.
  1145. (defun counsel-locate-function (str)
  1146. (or
  1147. (ivy-more-chars)
  1148. (progn
  1149. (counsel--async-command
  1150. (format "locate %s '%s'"
  1151. (mapconcat #'identity counsel-locate-options " ")
  1152. (counsel--elisp-to-pcre
  1153. (ivy--regex str))))
  1154. '("" "working..."))))
  1155. ;;;###autoload
  1156. (defun counsel-locate (&optional initial-input)
  1157. "Call the \"locate\" shell command.
  1158. INITIAL-INPUT can be given as the initial minibuffer input."
  1159. (interactive)
  1160. (ivy-read "Locate: " #'counsel-locate-function
  1161. :initial-input initial-input
  1162. :dynamic-collection t
  1163. :history 'counsel-locate-history
  1164. :action (lambda (file)
  1165. (with-ivy-window
  1166. (when file
  1167. (find-file file))))
  1168. :unwind #'counsel-delete-process
  1169. :caller 'counsel-locate))
  1170. Here are the interesting features of the above functions, in the
  1171. order that they appear:
  1172. • ‘counsel-locate-function’ takes a string argument and returns a
  1173. list of strings. Note that it’s not compatible with
  1174. ‘all-completions’, but since we’re not using that here, might as
  1175. well use one argument instead of three.
  1176. • ‘ivy-more-chars’ is a simple function that returns e.g. ‘'("2
  1177. chars more")’ asking the user for more input.
  1178. • ‘counsel--async-command’ is a very easy API simplification that
  1179. takes a single string argument suitable for
  1180. ‘shell-command-to-string’. So you could prototype your function as
  1181. non-async using ‘shell-command-to-string’ and ‘split-string’ to
  1182. produce a collection, then decide that you want async and simply
  1183. swap in ‘counsel--async-command’.
  1184. • ‘counsel-locate’ is an interactive function with an optional
  1185. ‘initial-input’.
  1186. • ‘#'counsel-locate-function’ is passed as the ‘collection’ argument.
  1187. • ‘dynamic-collection’ is set to t, since this is an async
  1188. collection.
  1189. • ‘action’ argument uses ‘with-ivy-window’ wrapper, since we want to
  1190. open the selected file in the same window from which
  1191. ‘counsel-locate’ was called.
  1192. • ‘unwind’ argument is set to ‘#'counsel-delete-process’: when we
  1193. press ‘C-g’ we want to kill the running process created by
  1194. ‘counsel--async-command’.
  1195. • ‘caller’ argument identifies this command for easier customization.
  1196. 
  1197. File: ivy.info, Node: Example - ivy-read-with-extra-properties, Prev: Example - counsel-locate, Up: API
  1198. 8.5 Example - ‘ivy-read-with-extra-properties’
  1199. ==============================================
  1200. This is another example to show how to associate additional values to
  1201. each displayed strings.
  1202. (defun find-candidates-function (str pred _)
  1203. (let ((props '(1 2))
  1204. (strs '("foo" "foo2")))
  1205. (cl-mapcar (lambda (s p) (propertize s 'property p))
  1206. strs
  1207. props)))
  1208. (defun find-candidates ()
  1209. (interactive)
  1210. (ivy-read "Find symbols: "
  1211. #'find-candidates-function
  1212. :action (lambda (x)
  1213. (message "Value: %s" (get-text-property 0 'property x)
  1214. ))))
  1215. Here are the interesting features of the above function:
  1216. • ‘find-candidates-function’ builds up a list of strings and
  1217. associates "foo" with the value 1 and "foo2" with 2.
  1218. • ‘find-candidates’ is an interactive function.
  1219. • ‘#'find-candidates’ is passed as the ‘collection’ argument.
  1220. • ‘action’ gets passed the selected string with the associated value.
  1221. It then retrieves that value and displays it.
  1222. 
  1223. File: ivy.info, Node: Variable Index, Next: Keystroke Index, Prev: API, Up: Top
  1224. 9 Variable Index
  1225. ****************
  1226. [index]
  1227. * Menu:
  1228. * ivy-alt-done: Key bindings for single selection action then exit minibuffer.
  1229. (line 30)
  1230. * ivy-alt-done <1>: File Name Completion. (line 12)
  1231. * ivy-avy: Key bindings for single selection action then exit minibuffer.
  1232. (line 64)
  1233. * ivy-backward-delete-char: File Name Completion. (line 19)
  1234. * ivy-call: Key bindings for multiple selections and actions keep minibuffer open.
  1235. (line 19)
  1236. * ivy-confirm-face: Faces. (line 34)
  1237. * ivy-count-format: Defcustoms. (line 6)
  1238. * ivy-current-match: Faces. (line 9)
  1239. * ivy-dispatching-call: Key bindings for multiple selections and actions keep minibuffer open.
  1240. (line 29)
  1241. * ivy-dispatching-done: Key bindings for single selection action then exit minibuffer.
  1242. (line 24)
  1243. * ivy-display-style: Defcustoms. (line 24)
  1244. * ivy-done: Key bindings for single selection action then exit minibuffer.
  1245. (line 19)
  1246. * ivy-extra-directories: File Name Completion. (line 51)
  1247. * ivy-height: Key bindings for navigation.
  1248. (line 21)
  1249. * ivy-immediate-done: Key bindings for single selection action then exit minibuffer.
  1250. (line 53)
  1251. * ivy-insert-current: Key bindings that alter the minibuffer input.
  1252. (line 23)
  1253. * ivy-insert-current-full: File Name Completion. (line 41)
  1254. * ivy-kill-ring-save: Other key bindings. (line 9)
  1255. * ivy-match-required-face: Faces. (line 53)
  1256. * ivy-minibuffer-grow: Hydra in the minibuffer.
  1257. (line 45)
  1258. * ivy-minibuffer-map: Minibuffer key bindings.
  1259. (line 6)
  1260. * ivy-minibuffer-match-face-1: Faces. (line 14)
  1261. * ivy-minibuffer-match-face-2: Faces. (line 19)
  1262. * ivy-minibuffer-match-face-3: Faces. (line 24)
  1263. * ivy-minibuffer-match-face-4: Faces. (line 29)
  1264. * ivy-minibuffer-shrink: Hydra in the minibuffer.
  1265. (line 50)
  1266. * ivy-modified-buffer: Faces. (line 88)
  1267. * ivy-modified-outside-buffer: Faces. (line 93)
  1268. * ivy-next-action: Hydra in the minibuffer.
  1269. (line 60)
  1270. * ivy-next-history-element: Key bindings that alter the minibuffer input.
  1271. (line 9)
  1272. * ivy-next-line-and-call: Key bindings for multiple selections and actions keep minibuffer open.
  1273. (line 39)
  1274. * ivy-occur: Saving the current completion session to a buffer.
  1275. (line 9)
  1276. * ivy-occur-click: Saving the current completion session to a buffer.
  1277. (line 21)
  1278. * ivy-occur-dispatch: Saving the current completion session to a buffer.
  1279. (line 41)
  1280. * ivy-occur-press: Saving the current completion session to a buffer.
  1281. (line 16)
  1282. * ivy-occur-read-action: Saving the current completion session to a buffer.
  1283. (line 36)
  1284. * ivy-on-del-error-function: Defcustoms. (line 31)
  1285. * ivy-partial-or-done: Key bindings for single selection action then exit minibuffer.
  1286. (line 37)
  1287. * ivy-prev-action: Hydra in the minibuffer.
  1288. (line 55)
  1289. * ivy-previous-history-element: Key bindings that alter the minibuffer input.
  1290. (line 18)
  1291. * ivy-previous-line-and-call: Key bindings for multiple selections and actions keep minibuffer open.
  1292. (line 50)
  1293. * ivy-read-action: Hydra in the minibuffer.
  1294. (line 65)
  1295. * ivy-remote: Faces. (line 71)
  1296. * ivy-restrict-to-matches: Key bindings that alter the minibuffer input.
  1297. (line 40)
  1298. * ivy-resume: Key bindings for multiple selections and actions keep minibuffer open.
  1299. (line 58)
  1300. * ivy-reverse-i-search: Key bindings that alter the minibuffer input.
  1301. (line 48)
  1302. * ivy-rotate-preferred-builders: Hydra in the minibuffer.
  1303. (line 40)
  1304. * ivy-subdir: Faces. (line 66)
  1305. * ivy-toggle-calling: Hydra in the minibuffer.
  1306. (line 34)
  1307. * ivy-toggle-case-fold: Hydra in the minibuffer.
  1308. (line 70)
  1309. * ivy-toggle-regexp-quote: File Name Completion. (line 47)
  1310. * ivy-use-virtual-buffers: Buffer Name Completion.
  1311. (line 6)
  1312. * ivy-virtual: Faces. (line 76)
  1313. * ivy-wrap: Key bindings for navigation.
  1314. (line 14)
  1315. * ivy-yank-word: Key bindings that alter the minibuffer input.
  1316. (line 32)
  1317. 
  1318. File: ivy.info, Node: Keystroke Index, Prev: Variable Index, Up: Top
  1319. 10 Keystroke Index
  1320. ******************
  1321. [index]
  1322. * Menu:
  1323. * /: File Name Completion. (line 35)
  1324. * / C-j: Using TRAMP. (line 24)
  1325. * //: File Name Completion. (line 25)
  1326. * // <1>: Using TRAMP. (line 17)
  1327. * <: Hydra in the minibuffer.
  1328. (line 50)
  1329. * >: Hydra in the minibuffer.
  1330. (line 45)
  1331. * ~: File Name Completion. (line 30)
  1332. * ~ <1>: Using TRAMP. (line 9)
  1333. * ~~: Using TRAMP. (line 29)
  1334. * a: Hydra in the minibuffer.
  1335. (line 65)
  1336. * a <1>: Saving the current completion session to a buffer.
  1337. (line 36)
  1338. * c: Hydra in the minibuffer.
  1339. (line 34)
  1340. * C: Hydra in the minibuffer.
  1341. (line 70)
  1342. * C-': Key bindings for single selection action then exit minibuffer.
  1343. (line 64)
  1344. * C-c C-o: Saving the current completion session to a buffer.
  1345. (line 9)
  1346. * C-j: Key bindings for single selection action then exit minibuffer.
  1347. (line 30)
  1348. * C-j <1>: File Name Completion. (line 12)
  1349. * C-m: Key bindings for single selection action then exit minibuffer.
  1350. (line 19)
  1351. * C-M-j: Key bindings for single selection action then exit minibuffer.
  1352. (line 53)
  1353. * C-M-m: Key bindings for multiple selections and actions keep minibuffer open.
  1354. (line 19)
  1355. * C-M-n: Key bindings for multiple selections and actions keep minibuffer open.
  1356. (line 39)
  1357. * C-M-o: Key bindings for multiple selections and actions keep minibuffer open.
  1358. (line 29)
  1359. * C-M-p: Key bindings for multiple selections and actions keep minibuffer open.
  1360. (line 50)
  1361. * C-M-y: File Name Completion. (line 41)
  1362. * C-o: Hydra in the minibuffer.
  1363. (line 9)
  1364. * C-r: Key bindings that alter the minibuffer input.
  1365. (line 48)
  1366. * DEL: File Name Completion. (line 19)
  1367. * f: Saving the current completion session to a buffer.
  1368. (line 16)
  1369. * j: Saving the current completion session to a buffer.
  1370. (line 26)
  1371. * k: Saving the current completion session to a buffer.
  1372. (line 31)
  1373. * m: Hydra in the minibuffer.
  1374. (line 40)
  1375. * M-i: Key bindings that alter the minibuffer input.
  1376. (line 23)
  1377. * M-j: Key bindings that alter the minibuffer input.
  1378. (line 32)
  1379. * M-n: Key bindings that alter the minibuffer input.
  1380. (line 9)
  1381. * M-o: Key bindings for single selection action then exit minibuffer.
  1382. (line 24)
  1383. * M-p: Key bindings that alter the minibuffer input.
  1384. (line 18)
  1385. * M-r: File Name Completion. (line 47)
  1386. * M-w: Other key bindings. (line 9)
  1387. * mouse-1: Saving the current completion session to a buffer.
  1388. (line 21)
  1389. * o: Saving the current completion session to a buffer.
  1390. (line 41)
  1391. * q: Saving the current completion session to a buffer.
  1392. (line 46)
  1393. * RET: Key bindings for single selection action then exit minibuffer.
  1394. (line 19)
  1395. * RET <1>: Saving the current completion session to a buffer.
  1396. (line 16)
  1397. * s: Hydra in the minibuffer.
  1398. (line 60)
  1399. * S-SPC: Key bindings that alter the minibuffer input.
  1400. (line 40)
  1401. * TAB: Key bindings for single selection action then exit minibuffer.
  1402. (line 37)
  1403. * w: Hydra in the minibuffer.
  1404. (line 55)
  1405. 
  1406. Tag Table:
  1407. Node: Top1190
  1408. Node: Introduction3101
  1409. Node: Installation5624
  1410. Node: Installing from Emacs Package Manager6074
  1411. Node: Installing from the Git repository7284
  1412. Node: Getting started8104
  1413. Node: Basic customization8411
  1414. Node: Key bindings9006
  1415. Node: Global key bindings9198
  1416. Node: Minibuffer key bindings11672
  1417. Node: Key bindings for navigation12904
  1418. Node: Key bindings for single selection action then exit minibuffer14111
  1419. Node: Key bindings for multiple selections and actions keep minibuffer open16758
  1420. Node: Key bindings that alter the minibuffer input19379
  1421. Node: Other key bindings21324
  1422. Node: Hydra in the minibuffer21702
  1423. Node: Saving the current completion session to a buffer24120
  1424. Node: Completion Styles25532
  1425. Node: ivy--regex-plus27283
  1426. Node: ivy--regex-ignore-order28769
  1427. Node: ivy--regex-fuzzy29137
  1428. Node: Customization29634
  1429. Node: Faces29820
  1430. Node: Defcustoms32249
  1431. Node: Actions33608
  1432. Node: What are actions?33934
  1433. Node: How can different actions be called?34752
  1434. Node: How to modify the actions list?35323
  1435. Node: Example - add two actions to each command35983
  1436. Node: How to undo adding the two actions36942
  1437. Node: How to add actions to a specific command37394
  1438. Node: Example - define a new command with several actions37810
  1439. Node: Test the above function with ivy-occur38698
  1440. Node: Packages39540
  1441. Node: Commands40505
  1442. Node: File Name Completion40690
  1443. Node: Using TRAMP42647
  1444. Node: Buffer Name Completion44149
  1445. Node: Counsel commands44764
  1446. Node: API45411
  1447. Node: Required arguments for ivy-read46009
  1448. Node: Optional arguments for ivy-read46528
  1449. Node: Example - counsel-describe-function49954
  1450. Node: Example - counsel-locate52812
  1451. Node: Example - ivy-read-with-extra-properties56562
  1452. Node: Variable Index57770
  1453. Node: Keystroke Index64894
  1454. 
  1455. End Tag Table
  1456. 
  1457. Local Variables:
  1458. coding: utf-8
  1459. End: