Skip to content
Completion in shell buffers using native mechanisms
Emacs Lisp
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
LICENSE
README.org
company-native-complete.el
native-complete.el

README.org

Native complete

This package interacts with a shell’s native completion functionality to provide the same completions in Emacs that you would get from the shell itself.

images/demo.gif

Currently this has been tested in

  • bash
  • csh
  • various CAD tool shells

Emacs setup

This package contains two completion functions; native-complete-at-point and company-native-complete. native-complete-at-point is a “completion at point function” (capf) and can be enabled by adding it to completion-at-point-functions in a shell buffer. company-native-complete is an asynchronous backend for the company completion framework. It is enabled by adding it to company-backends.

These functions look at the shell prompt or process name to determine which completion style to use. A completion style is the mechanism used to get the candidates from the native shell. Most shells support <tab> , but some shells won’t give you all the candidates consistently without using a different mechanism. There are currently the following completion styles:

bash
M-* and echo
zsh
C-D
tab
<tab>

Which completion mechanism to use is determined by the shell-file-name, which is the executable that is used to start your shell. If the mechanism can’t be determined from that, or if you use subshells that are a different type, you can use native-complete-style-regex-alist. This variable is a alist of (prompt-regex . mechanism) pairs. If the prompt of the current shell matches prompt-regex then the corresponding mechanism will be used. For example, if your prompt is of the form user> and your shell is bash, you could you the following setting to configure that.

(setq native-complete-style-regex-alist '(("[a-z]+> " . bash)))

To test what completion style your shell is using, evaluate M-: (native-complete-get-completion-style) when the point is at an empty prompt. The default completion mechanism is tab.

native-complete-exclude-regex is a regular expression that is used to match potential candidates that should not appear in the final completion list.

prompt components in completion list

if you encouter an issue where parts of your shell prompt are showing up as completion candidates you can add a function to comint-redirect-filter-functions to remove the prompt line from the process output. See the doc string of that variable for more details.

shell setup

bash

Run native-complete-setup-bash in Emacs before you load your first shell.

(with-eval-after-load 'shell
  (native-complete-setup-bash))

If the HISTCONTROL environment variable is not set to ignorespace or ignoreboth you will get a lot of garbage in your shell history.

export HISTCONTROL=ignoreboth

csh

Make sure editing is enabled.

set edit
You can’t perform that action at this time.