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

1973 lines
72 KiB

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