All Projects → minad → Consult

minad / Consult

Licence: gpl-3.0
consult.el - Consulting completing-read

Projects that are alternatives of or similar to Consult

Swiper
Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
Stars: ✭ 1,948 (+1173.2%)
Mutual labels:  emacs, completion
Icomplete Vertical
Global Emacs minor mode to display icomplete candidates vertically
Stars: ✭ 66 (-56.86%)
Mutual labels:  emacs, completion
Company Box
A company front-end with icons
Stars: ✭ 395 (+158.17%)
Mutual labels:  emacs, completion
Company Irony
company-mode completion back-end for irony-mode
Stars: ✭ 110 (-28.1%)
Mutual labels:  emacs, completion
Emacs Fish Completion
[MOVED TO GITLAB]
Stars: ✭ 53 (-65.36%)
Mutual labels:  emacs, completion
Auto Complete
Emacs auto-complete package
Stars: ✭ 1,622 (+960.13%)
Mutual labels:  emacs, completion
Dots
💾 — Dumb & Opinionated Configurations
Stars: ✭ 144 (-5.88%)
Mutual labels:  emacs
Mu4e Alert
Desktop notifications and modeline display for mu4e
Stars: ✭ 143 (-6.54%)
Mutual labels:  emacs
Monky
Magit for Hg
Stars: ✭ 142 (-7.19%)
Mutual labels:  emacs
Hledger Mode
An Emacs major mode for Hledger
Stars: ✭ 142 (-7.19%)
Mutual labels:  emacs
Discover.el
Discover more of emacs with context menus!
Stars: ✭ 153 (+0%)
Mutual labels:  emacs
Emacs4cl
A 40 line ~/.emacs to quickly set up vanilla Emacs for Common Lisp programming
Stars: ✭ 151 (-1.31%)
Mutual labels:  emacs
Emacs Bootstrap
Your on-the-fly Emacs development environment.
Stars: ✭ 147 (-3.92%)
Mutual labels:  emacs
Webmacs
webmacs - keyboard driven (emacs key bindings) browser, https://webmacs.readthedocs.io/en/latest/
Stars: ✭ 145 (-5.23%)
Mutual labels:  emacs
Writingwithemacs
Tips, Examples, and Resources for Writing with Emacs
Stars: ✭ 150 (-1.96%)
Mutual labels:  emacs
Lunarymacs
Moon-based Emacs configuration.
Stars: ✭ 151 (-1.31%)
Mutual labels:  emacs
Org Mode Workshop
Workshop for Org-mode with focus on todo-, project- and workflow-management
Stars: ✭ 141 (-7.84%)
Mutual labels:  emacs
Monroe
Clojure nREPL client for Emacs
Stars: ✭ 146 (-4.58%)
Mutual labels:  emacs
Doom Snippets
The Doom Emacs snippets library
Stars: ✭ 150 (-1.96%)
Mutual labels:  emacs
Spiral
Emacs Clojure IDE based on UNREPL
Stars: ✭ 146 (-4.58%)
Mutual labels:  emacs

#+title: consult.el - Consulting completing-read #+author: Daniel Mendler #+language: en #+export_file_name: consult.texi #+texinfo_dir_category: Emacs #+texinfo_dir_title: Consult: (consult). #+texinfo_dir_desc: Useful commands built on completing-read.

#+html: MELPA #+html: MELPA Stable

  • Introduction :properties: :description: Why Consult? 🔚 #+cindex: introduction

Consult provides various handy commands based on the Emacs completion function [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Minibuffer-Completion.html][completing-read]], which allows to quickly select an item from a list of candidates with completion. Consult offers in particular a more advanced buffer switching command =consult-buffer= to switch to buffers and recently opened files. Various search commands are provided, like an asynchronous =consult-grep=, and =consult-line=, which resembles [[https://github.com/abo-abo/swiper#swiper][Swiper]] or [[https://github.com/emacsorphanage/helm-swoop][Helm-Swoop]]. Some of the offered commands are greatly enhanced versions of existing Emacs commands. For example the command =consult-imenu= presents a flat list of the Imenu with [[#live-previews][live preview]] and [[#narrowing-and-grouping][narrowing support]]. Please take a look at the [[#available-commands][full list of commands]].

All Consult commands are compatible with completion systems based on the standard Emacs =completing-read= API, notably the default completion system, [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Icomplete.html][Icomplete]], [[https://github.com/raxod502/selectrum][Selectrum]] and [[https://github.com/oantolin/embark/][Embark]], with which Consult works out of the box. If Icomplete is used, it is recommended to install [[https://github.com/oantolin/icomplete-vertical][Icomplete-vertical]] to enjoy the enhanced visuals. The completion system specifics in this package are kept to a minimum. The ability of the Consult commands to work well with arbitrary completion systems is one of main advantages of the package. Consult fits well into existing setups and it helps you to create a full completion environment out of small and independent components. Note that, if you use [[https://github.com/abo-abo/swiper#ivy][Ivy]] or [[https://github.com/emacs-helm/helm][Helm]], you probably don't need Consult, since both packages come with their own set of commands.

There are the [[https://github.com/minad/marginalia/][Marginalia]] and [[https://github.com/oantolin/embark/][Embark]] packages, which can be combined with Consult. Marginalia enriches the completion display with annotations, for example documentation strings or file information. The versatile Embark packages provides local actions, comparable to a context menu, which can be executed while selecting a candidate in the minibuffer or in other contexts. For example, when selecting from a list of files, it offers an action to delete the file. Additionally Embark can also be used as a completion system by itself through its live-updating completion buffer. The [[#embark-integration][Embark integration]] is described later in greater detail.

** Screenshots :noexport:

#+caption: consult-grep [[https://github.com/minad/consult/blob/main/images/consult-grep.gif?raw=true]] Fig. 1: Command =consult-git-grep=

#+caption: consult-imenu [[https://github.com/minad/consult/blob/main/images/consult-imenu.png?raw=true]] Fig. 2: Command =consult-imenu=

#+caption: consult-line [[https://github.com/minad/consult/blob/main/images/consult-line.png?raw=true]] Fig. 3: Command =consult-line=

  • Available commands :properties: :custom_id: available-commands :description: Navigation, search, editing commands and more 🔚 #+cindex: commands

Most provided commands follow the meaningful naming scheme =consult-=.

TIP: If you have [[https://github.com/minad/marginalia][Marginalia]] installed and heavy annotators enabled, type =M-x ^consult= to see all Consult commands with their abbreviated description. Alternatively, type =C-h a ^consult= to get an overview of all Consult variables and functions with their descriptions.

** Virtual Buffers :properties: :description: Buffers, bookmarks and recent files 🔚 #+cindex: virtual buffers

#+findex: consult-buffer #+findex: consult-buffer-other-window #+findex: consult-buffer-other-frame #+findex: consult-recent-file #+findex: consult-bookmark

  • =consult-buffer= (=-other-window=, =-other-frame=): Enhanced version of =switch-to-buffer= with support for virtual buffers. Supports live preview of buffers and narrowing to the virtual buffer types. You can type =f SPC= in order to narrow to recent files. Ephemeral buffers can be shown by pressing =SPC= - it works the same way as =switch-buffer=. Supported narrowing keys:
    • b Buffers
    • f Files
    • m Bookmarks
    • p Project (only available if =consult-project-root-function= is configured as shown in the [[#use-package-example][example configuration]]).
    • Arbitrary [[#multiple-sources][other sources]] can be configured via =consult-buffer-sources=. By default only buffers are preview in order to ensure that =consult-buffer= is fast, but it is possible to [[#multiple-sources][configure]] file and bookmark preview.
  • =consult-bookmark=: Select or create bookmark. You might use the powerful =consult-buffer= as an alternative, which can include a bookmark virtual buffer source. But note that =consult-bookmark= supports preview of bookmarks and narrowing.
  • =consult-recent-file=: Select from recent files with preview. You might prefer the powerful =consult-buffer= instead, which can include recent files as a virtual buffer source.

** Editing :properties: :description: Commands useful for editing 🔚 #+cindex: editing

#+findex: consult-yank #+findex: consult-kmacro

  • =consult-yank=, =consult-yank-pop=: Enhanced version of =yank= and =yank-pop= which allows selecting from the kill-ring. Live preview is supported when selecting from the kill-ring.
  • =consult-kmacro=: Select macro from the macro ring and execute it.

** Register :properties: :description: Searching through registers and fast access 🔚 #+cindex: register

#+findex: consult-register #+findex: consult-register-load #+findex: consult-register-store #+findex: consult-register-format #+findex: consult-register-window

  • =consult-register=: Select from list of registers. The command supports narrowing to register types and preview of marker positions. This command is useful to search the register contents. For quick access it is recommended to use =consult-register-load= or =consult-register-store= or the built-in Emacs register commands.
  • =consult-register-format=: Supplementary register formatting function which can be used as =register-preview-function= for an enhanced register formatting. See the [[#use-package-example][example configuration]].
  • =consult-register-window=: Supplementary function which can be used as replacement for =register-preview= for a better register window. See the [[#use-package-example][example configuration]].
  • =consult-register-load=: Utility command to quickly load a register. The command either jumps to the register value or inserts it.
  • =consult-register-store=: Improved UI to store registers depending on the current context with an action menu. With an active region, store/append/prepend the contents, optionally deleting the region when a prefix argument is given. With a numeric prefix argument, store/add the number. Otherwise store point, frameset, window or kmacro. Usage examples:
    • =M-' x=: If no region is active, store point in register =x=. If a region is active, store the region in register =x=.
    • =M-' M-w x=: Store window configuration in register =x=.
    • =C-u 100 M-' x=: Store number in register =x=.

** Navigation :properties: :description: Mark rings, outlines and imenu 🔚 #+cindex: navigation

#+findex: consult-goto-line #+findex: consult-mark #+findex: consult-global-mark #+findex: consult-outline #+findex: consult-imenu #+findex: consult-project-imenu

  • =consult-goto-line=: Jump to line number enhanced with live preview. This is a drop-in replacement for =goto-line=.
  • =consult-mark=: Jump to a marker in the =mark-ring=. Supports live preview and recursive editing.
  • =consult-global-mark=: Jump to a marker in the =global-mark-ring=. Supports live preview and recursive editing.
  • =consult-outline=: Jump to a heading of the outline. Supports live preview and recursive editing.
  • =consult-imenu=: Jump to imenu item in the current buffer. Supports live preview, recursive editing and narrowing.
  • =consult-project-imenu=: Jump to imenu item in project buffers, with the same major mode as the current buffer. Supports live preview, recursive editing and narrowing. This feature has been inspired by [[https://github.com/vspinu/imenu-anywhere][imenu-anywhere]].

** Search :properties: :description: Line search, grep and file search 🔚 #+cindex: search

#+findex: consult-line #+findex: consult-multi-occur #+findex: consult-keep-lines #+findex: consult-focus-lines #+findex: consult-isearch

  • =consult-line=: Enter search string and select from matching lines. Supports live preview and recursive editing. The symbol at point and the recent Isearch string are added to the "future history" and can be accessed by pressing =M-n=. When =consult-line= is bound to the =isearch-mode-map= and is invoked during a running Isearch, it will use the current Isearch string.
  • =consult-isearch=: During an Isearch session, this command picks a search string from history and continues the search with the newly selected string. Outside of Isearch, the command allows to pick a string from the history and starts a new Isearch. This command can be used as a drop-in replacement for =isearch-edit-string=.
  • =consult-multi-occur=: Replacement for =multi-occur= which uses =completing-read-multiple=.
  • =consult-keep-lines=: Replacement for =keep/flush-lines= which uses the current completion style for filtering the buffer. The function updates the buffer while typing. In particular, this function can be used to further narrow an exported Embark collect buffer with the same completion filtering as during =completing-read=. If the input begins with the negation operator, i.e., ! SPC, the filter matches the complement. If a region is active, the filtering is restricted to that region.
  • =consult-focus-lines=: Temporarily hide lines by filtering them using the current completion style. Call with =C-u= prefix argument in order to show the hidden lines again. If the input begins with the negation operator, i.e., ! SPC, the filter matches the complement. In contrast to =consult-keep-lines= this function does not edit the buffer. If a region is active, the focusing is restricted to that region.

** Grep and Find :properties: :description: Searching through the filesystem 🔚 #+cindex: grep #+cindex: find #+cindex: locate

#+findex: consult-grep #+findex: consult-ripgrep #+findex: consult-git-grep #+findex: consult-find #+findex: consult-locate

  • =consult-grep=, =consult-ripgrep=, =consult-git-grep=: Search for regular expression in files. Grep is invoked asynchronously, while you enter the search term. You are required to enter at least =consult-async-min-input= characters in order for the search to get started. The input string is split into two parts, if the first character is a punctuation character, like =#=. For example =#grep-regexp#filter-string=, is split at the second =#=. The string =grep-regexp= is passed to Grep, the =filter-string= is passed to the /fast/ Emacs filtering to further narrow down the list of matches. This is particularily useful if you are using an advanced completion style like orderless. =consult-grep= supports preview. If the =consult-project-root-function= is [[#use-package-example][configured]] and returns non-nil, =consult-grep= searches the current project directory. Otherwise the =default-directory= is searched. If =consult-grep= is invoked with prefix argument =C-u M-s g=, you can specify the directory manually.
  • =consult-find=, =consult-locate=: Find file by matching the path against a regexp. Like =consult-grep= either the project root or the current directory is used as root directory for the search. The input string is treated similarly to =consult-grep=, where the first part is passed to find, and the second part is used for Emacs filtering. Note that the standard =find= command uses wildcards in contrast to the popular =fd=, which uses regular expressions. In case you want to use =fd=, you can either change the =consult-find-command= configuration variable or define a small command as described in the [[https://github.com/minad/consult/wiki][Consult wiki]].

** Compilation errors :properties: :description: Jumping to compilation errors 🔚 #+cindex: compilation errors

#+findex: consult-compile-error #+findex: consult-flycheck #+findex: consult-flymake

  • =consult-compile-error=: Jump to a compilation error. Supports live preview narrowing and and recursive editing.
  • =consult-flycheck=: Jump to flycheck error. Supports live preview and recursive editing. The command supports narrowing. Press =e SPC=, =w SPC=, =i SPC= to only show errors, warnings and infos respectively. This command requires to install the additional =consult-flycheck.el= package since the main =consult.el= package only depends on Emacs core components.
  • =consult-flymake=: Jump to Flymake diagnostic, like =consult-flycheck=.

** Histories :properties: :description: Navigating histories 🔚 #+cindex: history

#+findex: consult-complex-command #+findex: consult-history

  • =consult-complex-command=: Select a command from the =command-history=. This command is a =completing-read= version of =repeat-complex-command= and can also be considered a replacement for the =command-history= command from chistory.el.
  • =consult-history=: Insert a string from the current buffer history. This command can be invoked from the minibuffer. In that case the history stored in the =minibuffer-history-variable= is used.

** Modes :properties: :description: Toggling minor modes and executing commands 🔚 #+cindex: minor mode #+cindex: major mode

#+findex: consult-minor-mode-menu #+findex: consult-mode-command

  • =consult-minor-mode-menu=: Enable/disable minor mode. Supports narrowing to on/off/local/global modes by pressing =i/o/l/g SPC= respectively.
  • =consult-mode-command=: Run a command from the currently active minor or major modes. Supports narrowing to local-minor/global-minor/major mode via the keys =l/g/m=.

** Miscellaneous :properties: :description: Various other useful commands 🔚

#+findex: consult-apropos #+findex: consult-file-externally #+findex: consult-completion-in-region #+findex: consult-theme #+findex: consult-man #+findex: consult-xref

  • =consult-apropos=: Replacement for =apropos= with completion.
  • =consult-man=: Find Unix man page, via Unix =apropos= or =man -k=. The selected man page is opened using the Emacs =man= command.
  • =consult-file-externally=: Select a file and open it externally, e.g. using =xdg-open= on Linux.
  • =consult-completion-in-region=: Function which can be used as =completion-in-region-function=. This way, the minibuffer completion UI will be used for =completion-at-point=. This function is particularily useful in combination with Icomplete-vertical, since Icomplete does not provide its own =completion-in-region-function=. In contrast, Selectrum already comes with its own function.
  • =consult-theme=: Select a theme and disable all currently enabled themes. Supports live preview of the theme while scrolling through the candidates.
  • =consult-xref=: Integration with xref. This function can be set as as =xref-show-xrefs-function= and =xref-show-definitions-function=.
  • Special features :properties: :description: Enhancements over built-in `completing-read' 🔚

Consult enhances =completing-read= with live previews of candidates, additional narrowing capabilities to candidate groups and asynchronously generated candidate lists. This functionality is provided by the internal =consult--read= function, which is used by most Consult commands. The =consult--read= function is a thin wrapper around =completing-read=. In order to support multiple candidate sources there exists the high-level function =consult--multi=. The architecture of Consult allows it to work with different completion systems in the backend, while still offering advanced features.

** Live previews :properties: :description: Preview the currently selected candidate :custom_id: live-previews 🔚 #+cindex: preview

Some Consult commands support live previews. For example when you scroll through the items of =consult-line=, the buffer will scroll to the corresponding position. It is possible to jump back and forth between the minibuffer and the buffer to perform recursive editing while the search is ongoing.

Previews are enabled by default but can be disabled via the =consult-preview-key= variable. Furthermore it is possible to specify keybindings which trigger the preview manually as shown in the [[#use-package-example][example configuration]]. The default setting of =consult-preview-key= is =any= which means that the preview will be triggered on any keypress when the selected candidate changes. Each command can be configured individually with its own =:preview-key=, such that preview can be manual for some commands, for some commands automatic and for some commands completely disabled.

** Narrowing and grouping :properties: :description: Restricting the completion to a candidate group :custom_id: narrowing-and-grouping 🔚 #+cindex: narrowing

Consult has special support for candidate groups which are separated by separator lines with titles if supported by the completion system. As of now, Selectrum and Icomplete-vertical provide support. This functionality is useful if the list of candidates consists of candidates of multiple types or candidates from [[#multiple-sources][multiple sources]], like the =consult-buffer= command, which shows both buffers and recently opened files. Note that the group titles can be disabled by setting the =:title= property of the corresponding command in the =consult-config= configuration alist to nil.

By entering a narrowing prefix or by pressing a narrowing key it is possible to restrict the completion candidates to a certain candidate group. When you use the =consult-buffer= command, you can enter the prefix =b SPC= and the list of candidates will be restricted to buffers only. If you press =DEL= afterwards, the full candidate list will be shown again. Furthermore a narrowing prefix key and a widening key can be configured which can be pressed to achieve the same effect, see the configuration variables =consult-narrow-key= and =consult-widen-key=.

If [[https://github.com/justbur/emacs-which-key][which-key]] is installed, the narrowing keys are shown in the which-key window after pressing the prefix key =consult-narrow-key=. Furthermore there is the =consult-narrow-help= command which can be bound to a key in the =consult-narrow-map= if this is desired, as shown in the [[#use-package-example][example configuration]].

** Asynchronous search :properties: :description: Filtering asynchronously generated candidate lists 🔚 #+cindex: asynchronous search

Consult has support for asynchronous generation of candidate lists. This feature is used for search commands like =consult-grep=, where the list of matches is generated dynamically while the user is typing a grep regular expression. The grep process is executed in the background. When modifying the grep regular expression, the background process is terminated and a new process is started with the modified regular expression.

The matches, which have been found, can then be narrowed using the installed Emacs completion-style. This can be powerful if you are using for example the =orderless= completion style.

This two-level filtering is possible by splitting the input string. Part of the input string is treated as input to grep and part of the input is used for filtering. The input string is split at a punctuation character, using a similar syntax as Perl regular expressions.

Examples:

  • =#defun=: Search for "defun" using grep.
  • =#defun#consult=: Search for "defun" using grep, filter with the word "consult".
  • =/defun/consult=: It is also possible to use other punctuation characters.
  • =#to#=: Force searching for "to" using grep, since the grep pattern must be longer than =consult-async-min-input= characters by default.
  • =#defun -- --invert-match#=: Pass argument =--invert-match= to grep.

For asynchronous processes like =find= and =grep=, the prompt has a small indicator showing the process status:

  • =:= the usual prompt colon, before input is provided.
  • =*= with warning face, the process is running.
  • =:= with success face, success, process exited with an error code of zero.
  • =!= with error face, failure, process exited with a nonzero error code.
  • =;= with error face, interrupted, for example if more input is provided.

There is an ephemeral error log buffer =_consult-async-log= (note the leading space), you can access the buffer using =consult-buffer= and =switch-to-buffer= by first pressing =SPC= and then selecting the buffer.

** Multiple sources :properties: :description: Combining candidates from different sources :custom_id: multiple-sources 🔚 #+cindex: multiple sources

Consult allows combining multiple synchronous candidate sources. This feature is used by the =consult-buffer= command to present buffer-like candidates in a single menu for quick access. By default =consult-buffer= includes buffers, bookmarks, recent files and project-specific buffers and files. It is possible to configure the list of sources via the =consult-buffer-sources= variable. Arbitrary custom sources can be defined.

As an example, the bookmark source is defined as follows:

#+begin_src emacs-lisp (defvar consult--source-bookmark `(:name "Bookmark" :narrow ?m :category bookmark :face consult-bookmark :history bookmark-history :items ,#'bookmark-all-names :action ,#'consult--bookmark-action)) #+end_src

Required source fields:

  • =:category= Completion category.
  • =:items= List of strings to select from or function returning list of strings.

Optional source fields:

  • =:name= Name of the source, used for narrowing, group titles and annotations.
  • =:narrow= Narrowing character or =(character . string)= pair.
  • =:enabled= Function which must return t if the source is enabled.
  • =:hidden= When t candidates of this source are hidden by default.
  • =:face= Face used for highlighting the candidates.
  • =:annotate= Annotation function called for each candidate, returns string.
  • =:history= Name of history variable to add selected candidate.
  • =:default= Must be t if the first item of the source is the default value.
  • =:action= Action function called with the selected candidate.
  • =:state= State constructor for the source, must return the state function.
  • Other source fields can be added specifically to the use case.

The =:state= and =:action= fields of the sources deserve a longer explanation. The =:action= function takes a single argument and is only called after selection with the selected candidate, if the selection has not been aborted. This functionality is provided for convenience and easy definition of sources. The =:state= field is more complicated and general. The =:state= function is a constructor function without arguments, which can perform some setup necessary for the preview. It must return a closure with two arguments: The first argument is the candidate string, the second argument is the restore flag. The state function is called during preview, if a preview key has been pressed, with the selected candidate or nil and the restore argument being nil. Furthermore the state function is always called after selection with the selected candidate or nil. The state function is called with nil for the candidate if for example the selection process has been aborted or if the original preview state should be restored during preview. The restore flag is t for the final call. The final call happens even if preview is disabled. For this reason you can also use the final call to the state function in a similar way as =:action=. You probably only want to specify both =:state= and =:action= if =:state= is purely responsible for preview and =:action= is then responsible for the real action after selection.

In order to avoid slowness, =consult-buffer= only preview buffers by default. Loading recent files, bookmarks or views can result in expensive operations. However it is possible to configure the bookmark and file sources to also perform preview.

#+begin_src emacs-lisp (nconc consult--source-bookmark (list :state #'consult--bookmark-preview)) (nconc consult--source-file (list :state #'consult--file-preview)) (nconc consult--source-project-file (list :state #'consult--file-preview)) #+end_src

Sources can be added directly to the =consult-buffer-source= list for convenience. For example views can be added to the list of virtual buffers from a library like https://github.com/minad/bookmark-view/.

#+begin_src emacs-lisp ;; Configure new bookmark-view source (add-to-list 'consult-buffer-sources (list :name "View" :narrow ?v :category 'bookmark :face 'font-lock-keyword-face :history 'bookmark-view-history :action #'consult--bookmark-jump :items #'bookmark-view-names) 'append)

;; Modify bookmark source, such that views are hidden (setq consult--source-bookmark (plist-put consult--source-bookmark :items (lambda () (bookmark-maybe-load-default-file) (mapcar #'car (seq-remove (lambda (x) (eq #'bookmark-view-handler (alist-get 'handler (cdr x)))) bookmark-alist))))) #+end_src

Other useful sources allow the creation of terminal and eshell buffers if they do not exist yet.

#+begin_src emacs-lisp (defun mode-buffer-exists-p (mode) (seq-some (lambda (buf) (provided-mode-derived-p (buffer-local-value 'major-mode buf) mode)) (buffer-list)))

(defvar eshell-source `(:category 'consult-new :face 'font-lock-constant-face :action ,(lambda (_) (eshell)) :items ,(lambda () (unless (mode-buffer-exists-p 'eshell-mode) '("eshell (new)")))))

(defvar term-source `(:category 'consult-new :face 'font-lock-constant-face :action ,(lambda (_) (ansi-term (or (getenv "SHELL") "/bin/sh"))) :items ,(lambda () (unless (mode-buffer-exists-p 'term-mode) '("ansi-term (new)")))))

(add-to-list 'consult-buffer-sources 'eshell-source 'append) (add-to-list 'consult-buffer-sources 'term-source 'append) #+end_src

For more details, see the documentation of =consult-buffer= and of the internal =consult--multi= API. The =consult--multi= function can be used to create new multi-source commands, but is part of the internal API as of now, since some details may still change.

** Embark integration :properties: :description: Actions, Grep/Occur-buffer export :custom_id: embark-integration 🔚 #+cindex: embark

NOTE: Install the =embark-consult= package from MELPA, which provides Consult-specific Embark actions and the Occur buffer export.

Embark is a versatile package which offers context dependent actions, comparable to a context menu. See the [[https://github.com/oantolin/embark][Embark manual]] for an extensive description of its capabilities.

Actions are commands which can operate on the currently selected candidate (or target in Embark terminology). When completing files, for example the =delete-file= command is offered. Embark also allows to to execute arbitrary commands on the currently selected candidate via =M-x=.

Furthermore Embark provides the =embark-collect-snapshot= command, which collects candidates and presents them in an Embark collect buffer, where further actions can be applied to them. A related feature is the =embark-export= command, which allows to export candidate lists to a buffer of a special type. For example in the case of file completion, a Dired buffer is opened.

In the context of Consult, particularily exciting is the possibility to export the matching lines from =consult-line=, =consult-outline=, =consult-mark= and =consult-global-mark=. The matching lines are exported to an Occur buffer where they can be edited via the =occur-edit-mode= (press key =e=). Similarily, Embark supports exporting the matches found by =consult-grep=, =consult-ripgrep= and =consult-git-grep= to a Grep buffer, where the matches across files can be edited, if the [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep]] package is installed.

  • Configuration :properties: :description: Example configuration and customization variables 🔚

Consult can be installed from [[https://melpa.org/][MELPA]] via the Emacs built-in package manager. Alternatively it can be directly installed from the development repository via other non-standard package managers.

Note that there are two packages as of now: =consult= and =consult-flycheck=. =consult-flycheck= is a separate package such that the core =consult= package only depends on Emacs core components. The =consult= package will work out of the box with the default completion, Icomplete and Selectrum.

There is the [[https://github.com/minad/consult/wiki][Consult wiki]], where additional configuration examples can be contributed.

IMPORTANT: It is strongly recommended that you enable [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html][lexical binding]] in your configuration. Consult uses a functional programming style, relying on lambdas and lexical closures. For this reason many Consult-related snippets require lexical binding.

** Use-package example :properties: :description: Configuration example based on use-package :custom_id: use-package-example 🔚 #+cindex: use-package

It is recommended to manage package configurations with the =use-package= macro. The Consult package only provides commands and does not add any keybindings or modes. Therefore the package is non-intrusive but requires a little setup effort. In order to use the Consult commands, it is advised to add keybindings for commands which are accessed often. Rarely used commands can be invoked via =M-x=. Feel free to only bind the commands you consider useful to your workflow.

NOTE: There is the [[https://github.com/minad/consult/wiki][Consult wiki]], where additional configuration examples can be contributed.

#+begin_src emacs-lisp ;; Example configuration for Consult (use-package consult ;; Replace bindings. Lazily loaded due by `use-package'. :bind (;; C-c bindings (mode-specific-map) ("C-c h" . consult-history) ("C-c m" . consult-mode-command) ("C-c b" . consult-bookmark) ("C-c k" . consult-kmacro) ;; C-x bindings (ctl-x-map) ("C-x M-:" . consult-complex-command) ;; orig. repeat-complet-command ("C-x b" . consult-buffer) ;; orig. switch-to-buffer ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame ;; Custom M-# bindings for fast register access ("M-#" . consult-register-load) ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated) ("C-M-#" . consult-register) ;; Other custom bindings ("M-y" . consult-yank-pop) ;; orig. yank-pop (" a" . consult-apropos) ;; orig. apropos-command ;; M-g bindings (goto-map) ("M-g e" . consult-compile-error) ("M-g g" . consult-goto-line) ;; orig. goto-line ("M-g M-g" . consult-goto-line) ;; orig. goto-line ("M-g o" . consult-outline) ("M-g m" . consult-mark) ("M-g k" . consult-global-mark) ("M-g i" . consult-imenu) ("M-g I" . consult-project-imenu) ;; M-s bindings (search-map) ("M-s f" . consult-find) ("M-s L" . consult-locate) ("M-s g" . consult-grep) ("M-s G" . consult-git-grep) ("M-s r" . consult-ripgrep) ("M-s l" . consult-line) ("M-s m" . consult-multi-occur) ("M-s k" . consult-keep-lines) ("M-s u" . consult-focus-lines) ;; Isearch integration ("M-s e" . consult-isearch) :map isearch-mode-map ("M-e" . consult-isearch) ;; orig. isearch-edit-string ("M-s e" . consult-isearch) ;; orig. isearch-edit-string ("M-s l" . consult-line)) ;; required by consult-line to detect isearch

;; The :init configuration is always executed (Not lazy) :init

;; Optionally configure the register formatting. This improves the register ;; preview for consult-register',consult-register-load', ;; `consult-register-store' and the Emacs built-ins. (setq register-preview-delay 0 register-preview-function #'consult-register-format)

;; Optionally tweak the register preview window. ;; This adds thin lines, sorting and hides the mode line of the window. (advice-add #'register-preview :override #'consult-register-window)

;; Use Consult to select xref locations with preview (setq xref-show-xrefs-function #'consult-xref xref-show-definitions-function #'consult-xref)

;; Configure other variables and modes in the :config section, ;; after lazily loading the package. :config

;; Optionally configure preview. Note that the preview-key can also be ;; configured on a per-command basis via `consult-config'. The default value ;; is 'any, such that any key triggers the preview. ;; (setq consult-preview-key 'any) ;; (setq consult-preview-key (kbd "M-p")) ;; (setq consult-preview-key (list (kbd "") (kbd "")))

;; Optionally configure the narrowing key. ;; Both < and C-+ work reasonably well. (setq consult-narrow-key "<") ;; (kbd "C-+")

;; Optionally make narrowing help available in the minibuffer. ;; Probably not needed if you are using which-key. ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)

;; Optionally configure a function which returns the project root directory. ;; There are multiple reasonable alternatives to chose from: ;; * projectile-project-root ;; * vc-root-dir ;; * project-roots ;; * locate-dominating-file (autoload 'projectile-project-root "projectile") (setq consult-project-root-function #'projectile-project-root) ;; (setq consult-project-root-function ;; (lambda () ;; (when-let (project (project-current)) ;; (car (project-roots project))))) ;; (setq consult-project-root-function #'vc-root-dir) ;; (setq consult-project-root-function ;; (lambda () (locate-dominating-file "." ".git"))) )

;; Optionally add the `consult-flycheck' command. (use-package consult-flycheck :bind (:map flycheck-command-map ("!" . consult-flycheck))) #+end_src

** Custom variables :properties: :description: Short description of all customization settings 🔚 #+cindex: customization

TIP: If you have [[https://github.com/minad/marginalia][Marginalia]] installed, type =M-x customize-variable RET ^consult= to see all Consult-specific customizable variables with their current values and abbreviated description. Alternatively, type =C-h a ^consult= to get an overview of all Consult variables and functions with their descriptions.

| Variable | Default | Description | |-------------------------------------+------------------+----------------------------------------------------------| | consult-after-jump-hook | '(recenter) | Functions to call after jumping to a location | | consult-async-default-split | "#" | Separator character used for splitting #async#filter | | consult-async-input-debounce | 0.25 | Input debounce for asynchronous commands | | consult-async-input-throttle | 0.5 | Input throttle for asynchronous commands | | consult-async-min-input | 3 | Minimum numbers of letters needed for async process | | consult-async-refresh-delay | 0.25 | Refresh delay for asynchronous commands | | consult-bookmark-narrow | ... | Narrowing configuration for =consult-bookmark= | | consult-buffer-filter | ... | Filter for =consult-buffer= | | consult-buffer-sources | ... | List of virtual buffer sources | | consult-completion-in-region-styles | nil | Completion styles used by =consult-completion-in-region= | | consult-config | nil | Invididual command option configuration | | consult-find-command | "find ..." | Command line arguments for find | | consult-fontify-max-size | 1048576 | Buffers larger than this limit are not fontified | | consult-fontify-preserve | t | Preserve fontification for line-based commands. | | consult-git-grep-command | '(...) | Command line arguments for git-grep | | consult-goto-line-numbers | t | Show line numbers for =consult-goto-line= | | consult-grep-max-colums | 250 | Maximal number of columns of the matching lines | | consult-grep-command | "grep ..." | Command line arguments for grep | | consult-imenu-config | ... | Mode-specific configuration for =consult-imenu= | | consult-line-numbers-widen | t | Show absolute line numbers when narrowing is active. | | consult-line-point-placement | 'match-beginning | Placement of the point used by =consult-line= | | consult-locate-command | "locate ..." | Command line arguments for locate | | consult-mode-command-filter | ... | Filter for =consult-mode-command= | | consult-mode-histories | ... | Mode-specific history variables | | consult-narrow-key | nil | Narrowing prefix key during completion | | consult-preview-key | 'any | Keys which triggers preview | | consult-preview-max-count | 10 | Maximum number of files to keep open during preview | | consult-preview-max-size | 10485760 | Files larger than this size are not previewed | | consult-preview-raw-size | 102400 | Files larger than this size are previewed in raw form | | consult-project-root-function | nil | Function which returns current project root | | consult-register-narrow | ... | Narrowing configuration for =consult-register= | | consult-ripgrep-command | "rg ..." | Command line arguments for ripgrep | | consult-themes | nil | List of themes to be presented for selection | | consult-widen-key | nil | Widening key during completion |

** Fine-tuning of individual commands :properties: :alt_title: Fine-tuning :description: Fine-grained configuration for special requirements 🔚

NOTE: Consult allows fine-grained customization of individual commands. This configuration feature is made available for experienced users with special requirements.

Commands allow flexible, individual customization by setting the =consult-config= list. You can override any option passed to the internal =consult--read= API. The [[https://github.com/minad/consult/wiki][Consult wiki]] already contains a few useful configuration examples. Note that since =consult--read= is part of the internal API, options could be removed, replaced or renamed in future versions of the package.

Useful options are:

  • =:prompt= set the prompt string
  • =:preview-key= set the preview key, default is =consult-preview-key=
  • =:initial= set the initial input
  • =:default= set the default value
  • =:history= set the history variable symbol
  • =:add-history= add items to the future history, for example symbol at point
  • =:sort= enable or disable sorting
  • =:title= set to nil in order to disable candidate grouping and titles.

#+begin_src emacs-lisp ;; Set preview for consult-buffer' to keyM-p' ;; and disable preview for consult-theme' completely. ;; Forconsult-line' specify multiple keybindings. ;; Note that you should bind and in the ;; minibuffer-local-completion-map' orselectrum-minibuffer-map' ;; to the commands which select the previous or next candidate. (setq consult-config `((consult-theme :preview-key nil) (consult-buffer :preview-key ,(kbd "M-p")) (consult-line :preview-key (list ,(kbd "") ,(kbd ""))))) #+end_src

Generally it is possible to modify commands for your individual needs by the following techniques:

  1. Create your own wrapper function which passes modified arguments to the Consult functions.
  2. Create your own buffer [[#multiple-sources][multi sources]] for =consult-buffer=.
  3. Modify =consult-config= in order to change the =consult--read= settings.
  4. Create advices to modify some internal behavior.
  5. Write or propose a patch.
  • Recommended packages :properties: :description: Related packages recommended for installation 🔚

It is recommended to install the following package combination:

  • consult: This package
  • consult-flycheck: Provides the consult-flycheck command
  • [[https://github.com/raxod502/selectrum][selectrum]] or [[https://github.com/oantolin/icomplete-vertical][icomplete-vertical]]: Vertical completion systems
  • [[https://github.com/minad/marginalia][marginalia]]: Annotations for the completion candidates
  • [[https://github.com/oantolin/embark][embark and embark-consult]]: Action commands, which can act on the completion candidates
  • [[https://github.com/oantolin/orderless][orderless]]: Completion style, Flexible candidate filtering
  • [[https://github.com/raxod502/prescient.el][prescient]]: Frecency-based candidate sorting, also offers filtering

There exist more packages related to Consult which provide wider integration with the Emacs ecosystem. You may want to install some of these packages too depending on your personal preferences.

  • [[https://github.com/justbur/emacs-which-key][which-key]]: Helpful mode showing keybindings, also shows the Consult narrowing keys
  • [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep]]: Editing of grep buffers, can be used together with =consult-grep= via Embark
  • [[https://github.com/minad/bookmark-view][bookmark-view]]: Store window configuration as bookmarks, integrates with =consult-buffer=
  • [[https://github.com/d12frosted/flyspell-correct][flyspell-correct]]: Apply spelling corrections by selecting via =completing-read=
  • [[https://codeberg.org/jao/consult-notmuch][consult-notmuch]]: Access the [[https://notmuchmail.org/][Notmuch]] email system using Consult.
  • [[https://codeberg.org/jao/consult-recoll][consult-recoll]]: Access the [[https://www.lesbonscomptes.com/recoll/][Recoll]] desktop full-text search using Consult.
  • [[https://codeberg.org/jao/espotify][consult-spotify]]: Access the Spotify API and control your local music player.

Note that all packages are independent and can potentially be exchanged with alternative components, since there exist no hard dependencies. Furthermore it is possible to get started with only default completion and Consult and add more components later to the mix, e.g., using Selectrum for enhanced minibuffer completion or Embark for actions.

The Selectrum repository provides a [[https://github.com/raxod502/selectrum/tree/master/test][set of scripts]] which allow testing multiple package combinations including various completion systems and Consult. After cloning the Selectrum repository, the scripts can be executed with =cd selectrum/test; ./run.sh <package-combo.el>=.

  • Bug reports :properties: :description: How to create reproducible bug reports 🔚

If you find a bug or suspect that there is a problem with Consult, please carry out the following steps:

  1. Check first that all the relevant packages are updated to the newest version. This includes Selectrum, Icomplete-vertical, Marginalia, Embark, Orderless and Prescient in case you are using any of those packages.
  2. Ensure that either =icomplete-mode= or =selectrum-mode= is enabled. Furthermore =ivy-mode= and =helm-mode= must be disabled.
  3. Ensure that the =completion-styles= variable is properly configured. Try to set =completion-styles= to a list including =substring= or =orderless=.
  4. Try to reproduce the issue by starting a barebone Emacs instance with =emacs -Q= on the command line. Execute the following minimal code snippets in the scratch buffer. This way we can exclude side effects due to configuration settings. If other packages are relevant to reproduce the issue, include them in the minimal configuration snippet.

#+begin_src emacs-lisp ;; Minimal setup using Selectrum (package-initialize) (require 'consult) (require 'selectrum) (selectrum-mode) (setq completion-styles '(substring)) #+end_src

#+begin_src emacs-lisp ;; Minimal setup using the default completion system (package-initialize) (require 'consult) (setq completion-styles '(substring)) #+end_src

Please provide the necessary important information with your bug report:

  • The minimal configuration snippet used to reproduce the issue.
  • The full stack trace in case the bug triggers an exception.
  • Your Emacs version, since bugs are often version-dependant.
  • Your operating system, since Emacs builds vary between Linux, Mac and Windows.
  • The package manager, e.g., straight.el or package.el, used to install the Emacs packages. This information is helpful to exclude update issues.
  • If you are using Evil or other special packages which change Emacs on a fundamental level. There have been Evil-related problems before, which are fixed now.

When evaluating Consult-related code snippets it is required to enable [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html][lexical binding]]. Consult uses a functional programming style, relying on lambdas and lexical closures.

  • Contributions :properties: :description: Feature requests and pull requests 🔚

Consult is intended to be a community effort, please participate in the discussions. Contributions are welcome. If you have a proposal, take a look first at the [[https://github.com/consult/issues][Consult issue tracker]] and the [[https://github.com/minad/consult/issues/6][Consult wishlist]]. For small configuration or command snippets you may want to share, there is the [[https://github.com/minad/consult/wiki][Consult wiki]].

  • Acknowledgements :properties: :description: Contributors and Sources of Inspiration 🔚

You probably guessed from the name that this package took inspiration from [[https://github.com/abo-abo/swiper#counsel][Counsel]] by Oleh Krehel. Some of the Consult commands originated in the [[https://github.com/raxod502/selectrum/wiki/Useful-Commands][Selectrum wiki]]. The commands have been rewritten and greatly enhanced in comparison to the wiki versions. In particular all Selectrum-specific code has been removed, such that the commands are compatible with the =completing-read= API.

Code contributions:

  • [[https://github.com/oantolin/][Omar Antolín Camarena]]
  • [[https://github.com/s-kostyaev/][Sergey Kostyaev]]
  • [[https://github.com/okamsn/][okamsn]]
  • [[https://github.com/clemera/][Clemens Radermacher]]
  • [[https://github.com/tomfitzhenry/][Tom Fitzhenry]]
  • [[https://github.com/jakanakaevangeli][jakanakaevangeli]]
  • [[https://github.com/inigoserna/][inigoserna]]
  • [[https://github.com/aspiers/][Adam Spiers]]
  • [[https://github.com/omar-polo][Omar Polo]]
  • [[https://github.com/astoff][Augusto Stoffel]]
  • [[https://codeberg.org/jao/][Jose A Ortega Ruiz]]

Advice and useful discussions:

  • [[https://github.com/clemera/][Clemens Radermacher]]
  • [[https://github.com/oantolin/][Omar Antolín Camarena]]
  • [[https://gitlab.com/protesilaos/][Protesilaos Stavrou]]
  • [[https://github.com/purcell/][Steve Purcell]]
  • [[https://github.com/alphapapa/][Adam Porter]]
  • [[https://github.com/manuel-uberti/][Manuel Uberti]]
  • [[https://github.com/tomfitzhenry/][Tom Fitzhenry]]
  • [[https://github.com/hmelman/][Howard Melman]]

#+html: <!--

  • Indices :properties: :description: Indices of concepts and functions 🔚

** Function index :properties: :description: List of all Consult commands :index: fn 🔚

** Concept index :properties: :description: List of all Consult-specific concepts :index: cp 🔚

#+html: -->

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].