Icicles - Ido and IswitchB

Previous: Icicles - S-RETIciclesIciclesIndexNext: Icicles - Completions Display

Ido and IswitchB

Libraries Ido and IswitchB are alternatives to Icicles that also enhance minibuffer completion in various ways. Their UIs are similar to each other – Ido essentially extends IswitchB’s buffer-name completion to file names as well. Neither completes other kinds of candidates. They work only for buffer names or file names, but you can advise the standard completion functions to get them to use Ido completion more generally.

The behavior of Ido and IswitchB is different from the default Icicles behavior. If you prefer their behavior for buffers then you can just use IswitchB and Icicles together. You cannot use Icicles and Ido together, however – they use the minibuffer in incompatible ways.

The default behavior of Icicles is different, but you can make Icicles behave more like Ido if you like. It would be a mistake to look for a complete reproduction of the Ido behavior in Icicles, however. If you want exactly the same behavior as Ido, then use Ido. ;-)

The Icicles UI is different by design. Some of this difference in approach has to do with the fact that Ido is specialized to buffer- and file-name completion. The generality of Icicles makes a different approach appropriate. Icicles has many additional features that are not available in other libraries, but its main advantage is its generality: you use the same user interface for input of any kind. (See KillingBuffers for an illustration of this generality, as well as some musings on special vs general solutions.) As you learn more about Icicles you may begin to appreciate its approach, even if you are a diehard Ido addict.

This section summarizes some differences between Icicles and Ido and tells you how you can get more Ido-like behavior in Icicles if that’s what you prefer. It does not cover Icicles features that have no counterpart in Ido or features that they have in common (except to emphasize some differences).

If you have the Ido habit but want to give Icicles a try, then this section is for you. I recommend, however, that you give the default Icicles behavior a good try before convincing yourself that you still prefer a more Ido-like approach.

See also the references at the section end for other sections that go into more detail about some of the things mentioned here.

1. Incremental completion

By default, Icicles does not turn on incremental completion until you have hit ‘TAB’ or ‘S-TAB’ to display the matching candidates. Ido turns it on immediately. You can get that behavior by setting option `icicle-show-Completions-initially-flag’ to ‘t’.

You can get an intermediate behavior in this regard by instead setting option `icicle-incremental-completion’ to a value that is neither ‘nil’ nor ‘t’. That makes Icicles show the matching candidates as soon as you start typing input, but not before that. See also Icicles - Icompletion and option `icicle-incremental-completion-delay’.

2. Non-expansion of minibuffer input

By default, Icicles expands your minibuffer input when you complete. This is like vanilla Emacs (for prefix completion), but it is unlike Ido, which only shows you the available candidates but does not change your input text. You can get this non-expansion behavior in Icicles by setting option `icicle-expand-input-to-common-match’ to 0. See Incremental Completion (Input Expansion) in the Minibuffer.

3. Matching

By default, Ido uses substring matching for completion. You can hit a key to switch to prefix matching, “flex” matching, or regexp matching. Icicles gives you these same matching possibilities, and more. (What Ido calls “flex matching” Icicles calls “scatter matching”.) The main difference here is that Icicles regexp support is general and complete. Regexp-matching in Ido does not work with Ido-style completion.

4. Current candidate, cycling, sorting

Both Ido and Icicles have a notion of “current candidate”. In Ido, completion candidates are presented in a predefined sort order, most recently used first. The current candidate is the first one. You cycle candidates by moving the first to last or the last to first.

In Icicles, you can switch among any number of sort orders at any time by hitting a key. (And you can easily define your own sort orders.) When you cycle candidates, the candidates stay in order. If the candidates are displayed in ‘*Completions*’ then the current one is highlighted there, in place. The highlight moves, not the candidate.

5. Input editing

In Ido, cycling does not replace your input by the current candidate. To edit the current candidate you hit a key to enter an edit mode (recursive minibuffer). In Icicles, cycling replaces your input in the minibuffer by the current candidate, so you can just edit it there normally. You can use ‘C-l’ to retrieve your original input.

6. Completions shown

In Ido, a limited number of matching completion candidates are shown in the minibuffer. You can hit a key to see all matches in a separate buffer.

In Icicles, completion candidates are always shown in buffer ‘*Completions*’, not in the minibuffer. You can limit the number of matches shown by customizing option `icicle-max-candidates’. Only the first ‘icicle-max-candidates’ (in the current sort order) are shown.

You can also increment and decrement this truncation value on the fly during completion, by hitting `C-x #’ and then using the vertical arrow keys or the mouse wheel. (For that feature you also need library doremi.el.)

7. Auto-choice of sole candidate

In Ido, if there is only one match for your input then ‘TAB’, which normally completes, also chooses that candidate – you do not need to hit ‘RET’. By default, Icicles always requires you to explicitly choose, with ‘RET’ (or `C-RET’). If you set option `icicle-top-level-when-sole-completion-flag’ to non-‘nil’, then Icicles provides similar behavior to Ido. See also option `icicle-top-level-when-sole-completion-delay’.

Ido-Like Behavior Everywhere: `icicle-ido-like-mode'

If you want Icicles to be Ido-like in general, then turn on global minor mode ‘icicle-ido-like-mode’ (not available in Emacs 20). Doing that sets options `icicle-show-Completions-initially-flag’ and `icicle-top-level-when-sole-completion-flag’ to ‘t’. Turning the mode off sets them to ‘nil’.

You can simultaneously set option `icicle-max-candidates’ when you turn on ‘icicle-ido-like-mode’, by using a positive prefix argument. If you want the option to keep that value when you turn the mode off, then use a zero or negative prefix argument. Otherwise, it is reset to ‘nil’ (no limit on the number of candidates displayed).

When you use this mode, you might also want to use ‘nil’ or ‘t’ as the value of option `icicle-default-value’, in order to not insert the default value in the minibuffer. If you want to change that option dynamically for the mode, use ‘icicle-ido-like-mode-hook’. E.g.:

  (add-hook 'icicle-ido-like-mode-hook
            (lambda () (setq icicle-default-value
                        (if icicle-ido-like-mode t 'insert-end))))

Ido-Like Behavior for Buffers and Files

If you want Ido-like behavior in Icicles for buffers or files, but not in general, then customize either or both options `icicle-buffers-ido-like-flag’ and `icicle-files-ido-like-flag’ to non-‘nil’.

IswitchB-Like Behavior for `icicle-buffer'

As mentioned, you can use IswitchB with Icicles. GnuEmacs deprecated IswitchB starting with Emacs 24.4, but it is still available.

If you want to get IswitchB-like behavior with Icicles without using IswitchB then you can advise ‘icicle-buffer’.

There are at least two ways to do this, depending on what behavior you want. Let’s assume that in any case (a) you want incremental completion from the outset (no need to hit ‘TAB’ or ‘S-TAB’, and (b) you want to Emacs to accept as your choice the sole candidate as soon as you narrow matching to a single candidate. For (a), you bind `icicle-incremental-completion’ to ‘always’. For (b), you bind `icicle-top-level-when-sole-completion-flag’ to ‘t’.

1. In the first case, prefix completion is the default (as usual), but ‘icicle-buffer’ uses vanilla Emacs completion as the Icicles ‘TAB’ completion method. This reflects IswitchB’s substring matching. To do this, bind `icicle-current-TAB-method’ to ‘vanilla’.

2. In the second case, ‘icicle-buffer’ starts out with apropos completion, not prefix completion. This too reflects IswitchB’s substring matching, but it extends it to regexp completion. To do this, you bind `icicle-default-cycling-mode’ to ‘apropos’.

    ;; 1. Use vanilla Emacs matching for prefix completion by default.
    (defadvice icicle-buffer (around iswitchb-like-1 activate)
      (let* ((icicle-current-TAB-method                   'vanilla)
             (icicle-incremental-completion               'always)
             (icicle-top-level-when-sole-completion-flag  't))
    (ad-activate 'icicle-buffer)
    ;; 2. Start with apropos completion by default.
    (defadvice icicle-buffer (around iswitchb-like-2 activate)
      (let* ((icicle-default-cycling-mode  'apropos)
                (icicle-incremental-completion  'always)
                (icicle-top-level-when-sole-completion-flag 't))
    (ad-activate 'icicle-buffer)

See Also:

Previous: Icicles - S-RETIciclesIciclesIndexNext: Icicles - Completions Display

DrewsElispLibraries referenced here: Lisp:icicles.el

CategoryCommands CategoryBufferSwitching CategoryCompletion CategoryDocumentation CategoryHelp CategoryDirectories CategoryFiles CategoryProgrammerUtils CategoryCode