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.

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