My attempt to optimize my emacs load time <1 second
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.

1966 lines
72 KiB

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