Klimi's new dotfiles with stow.
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.

1936 line
70 KiB

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