Icicles - Completion in Other Buffers

iciclesimage
Previous: Icicles - Completion Methods and StylesIciclesIciclesIndexNext: Icicles - Customization and General Tips

Completion in Other Buffers

In addition to input completion, you can use Icicles to complete words and symbols in other buffers, besides the minibuffer. Icicles enhances this completion in these ways:

  1. Lisp symbol completion via ‘M-TAB’ (‘lisp-complete-symbol’). (This is also ‘ESC-TAB’ and ‘C-M-i’.)
  2. Word completion using the dynamic abbreviation of standard Emacs library dabbrev.el, via ‘C-M-/’.
  3. Word completion using the ‘dynamic-completion-mode’ of standard Emacs library completion.el, via ‘C-RET’ or ‘M-RET’.
  4. Word completion using the words and phrases in a thesaurus, via ‘C-c /’ (requires library synonyms.el – see Synonyms).
  5. Mailing-information completion for BBDB (Insidious Big Brother Database).
  6. ‘TAB’ completion of the following in ShellMode and ESS modes (and other, similar interpreters):
    1. Commands
    2. Previous inputs – commands plus their arguments
    3. File names
    4. Environment variables

Whenever multiple completion candidates are available, you can use Icicles completion, with all of its features: cycling of candidates (‘TAB’, ‘down’, or ‘next’), apropos (regexp) completion (‘S-TAB’), progressive completion (‘S-SPC’), help on individual candidates (‘C-M-RET’), and so on.

Dynamic Completion Using `dabbrev.el'

Library dabbrev.el lets you type a few characters in a buffer and then prefix-complete them (in the same buffer) to a full word or symbol name. The completion candidates come from words or symbol names in buffers that you are editing. Emacs calls this functionality “dynamic abbreviation”, though “dynamic completion” would be a better term for it (words are completed dynamically, not abbreviated).

Library dabbrev.el provides two ways to dynamically complete text:

If there are many candidate completions then cycling among them with ‘M-/’ can be tedious. You can use ‘M-C-/’ to complete to a common prefix, thus narrowing the set of candidates, but then you lose the ability to cycle among them.

If user option `icicle-top-level-key-bindings’ contains an entry for ‘dabbrev-completion’ then Icicles remaps keys normally bound to command ‘dabbrev-completion’ to command ‘icicle-dabbrev-completion’, which uses Icicles completion whenever there are multiple completion candidates. You can then use any Icicles features, such as apropos completion and candidate cycling. In addition, you can complete an empty prefix, starting from scratch with apropos completion.

Dynamic Completion Using `completion.el'

Standard Emacs library completion.el is quite old and little known nowadays. It is nevertheless very useful. In a way, it is like dabbrev.el on steroids. It is pretty smart, proposing first the completions that you have used most recently. You can use it anywhere, to complete all kinds of buffer text.

The command for completing the text before point is ‘complete’ (an unfortunately general name, as is the name of the library), which is bound globally to ‘C-RET’ and ‘M-RET’ when you are in ‘dynamic-completion-mode’.

Command ‘complete’ can act similar to the ‘dabbrev’ commands, in which case it is said to be using method ‘cdabbrev’ (but this name is not defined in any way programmatically; it is referred to informally).

But the ‘dabbrev’-like behavior of ‘complete’ is only a fallback, when its normal completion method comes up empty-handed. The normal method matches what you type against a persistent personal “database” of completions, which is constructed and updated automatically as you type. (It is saved only on demand or when you exit Emacs.)

To make good use of this library, you really should read the complete Commentary in the `completion.el’ source code (keeping in mind that in a few places it is not up to date). But the doc string of command ‘icicle-complete’ (which is the version of ‘complete’ used in Icicle mode) is a good place to start.

To make this kind of completion available, you must turn on ‘dynamic-completion-mode’.

Here is the beginning of the completion.el Commentary:

  This watches all the words that you type and remembers them.
  When typing a new word, pressing "complete" (meta-return)
  "completes" the word by inserting the most recently used word
  that begins with the same characters.  If you press meta-return
  repeatedly, it cycles through all the words it knows about.
  If you like the completion then just continue typing, it is as
  if you entered the text by hand.  If you want the inserted extra
  characters to go away, type control-w or delete.  More options
  are described below.
  The guesses are made in the order of the most recently "used".
  Typing in a word and then typing a separator character (such as
  a space) "uses" the word.  So does moving a cursor over the
  word.  If no words are found, it uses an extended version of the
  `dabbrev'-style completion.
  You automatically save the completions you use to a file between
  sessions.
  Completion enables programmers to enter longer, more descriptive
  variable names while typing fewer keystrokes than they normally
  would.

Just as for the ‘dabbrev’ commands, Icicles enhances this completion by letting you use Icicles minibuffer completion when there are multiple candidates. This happens only if one of these is true:

What about that fallback completion method, ‘cdabbrev’? Vanilla ‘complete’ uses it only if no matching completions are found in the database. (It is generally slower than database lookup.)

Icicles lets you choose whether to match only database completions or also terms found in your current Emacs windows (‘cdabbrev’), by customizing option `icicle-cmpl-include-cdabbrev-flag’.

If the option value is non-‘nil’ then whenever Icicles completion is used the candidates include the completions found dynamically by searching your current windows. If it is ‘nil’ then only database completions are candidates. The dynamically found candidates are highlighted in buffer ‘*Completions*’ using face ‘icicle-special-candidate’, so you can easily distinguish them.

Thesaurus Lookup and Completion

Library synonyms.el provides various features for defining a thesaurus and looking up words and phrases in it. Icicles provides a multi-command version (alias ‘icicle-synonyms’) of the command ‘synonyms’, which shows all of the synonyms that match a regular expression (e.g. a word or phrase) and lets you navigate among hyperlinked thesaurus entries.

Command ‘icicle-complete-thesaurus-entry’ completes a word in a text buffer to any word or phrase in the thesaurus. With the default value of option `icicle-top-level-key-bindings’, this is bound to ‘C-c /’ in Icicle mode.

Tip:

You can use ‘icicle-complete-thesaurus-entry’ to quickly check the spelling of a word. If it is correctly spelled, then it appears as a complete completion (is highlighted as such in the minibuffer).

Another Icicles (multi-)command that uses the thesaurus is ‘icicle-insert-thesaurus-entry’. It lets you use Icicles completion, cycling, and so on to insert thesaurus words and phrases in any buffer. It does not complete the word at point. Within a single call to it, insert any number of thesaurus entries, in succession. If you wanted to, you could write an entire book using a single call to ‘icicle-insert-thesaurus-entry’!

All of these commands require that you load library synonyms.el.

See Synonyms for more information on the features of library synonyms.el.

BBDB Completion

Library bbdb.el is a rolodex-like database program for GNU Emacs – see BbdbMode. You can obtain a recent version, such as 3.1 or later, from one of these locations:

If user option `icicle-functions-to-redefine’ contains an entry for ‘bbdb-complete-mail’ (for BBDB version 3.0.2 or 3.1) or ‘bbdb-complete-name’ (for BBDB version 2.35), then Icicles redefines that command so that it uses Icicles completion when there are multiple completions.

You can use any Icicles features, such as apropos completion and candidate cycling. For this feature to take effect, you must load BBDB before you load Icicles. By default, option ‘icicle-functions-to-redefine’ includes an entry for ‘bbdb-complete-mail’ (not for ‘bbdb-complete-name’).

(If you have BBDB version 3.0.2 instead of version 3.1, then uncomment the version of ‘icicle-bbdb-complete-mail’ in `icicles-cmd1.el’ that supports BBDB version 3.0.2.)

Completion in Comint Modes

‘TAB’ in a shell or similar buffer provides Icicles completion for command names, file names, and environment variables that are known to the shell (or other interpreter). Starting with Emacs 23, Icicles completion is available also when you use `M-!’ (‘shell-command’) or `M-|’ (‘shell-command-on-region’).

In a shell or similar buffer you can also complete input using your previous inputs as the set of candidates. Just type something at the prompt, hit `C-c `’, and pick one or more previous inputs to execute again (this uses ‘icicle-search’, so it is a multi-command). You need not re-execute the exact same shell command; you can edit your previous input before hitting ‘RET’ to enter the command.

These features are available for ComintMode and several modes that inherit from it, including ShellMode, Shell Script mode (ShMode), various ESS modes (EmacsSpeaksStatistics), InferiorEmacsLispMode (IELM), GrandUnifiedDebugger (GUD) mode, TclMode, RloginMode, and NS Lookup mode.

See Also:


Previous: Icicles - Completion Methods and StylesIciclesIciclesIndexNext: Icicles - Customization and General Tips

DrewsElispLibraries referenced here: Lisp:icicles.el, Lisp:synonyms.el

CategoryCommands CategoryCompletion CategorySpelling CategoryModes CategoryProgrammerUtils CategoryCode CategoryBbdb CategoryESS