Icicles - Dot, Dot, Dot

Previous: Icicles - Searching Named ContainersIciclesIciclesIndexNext: Icicles - More About Multi-Commands

Dot, Dot, Dot

This section is about dot, that is, `.’, and its role as a regexp special character in apropos completion.

Since the inception of regular-expression matching, `.’ has matched any character except a newline character (aka `^J’, aka ‘C-j’). Recent languages typically have an additional mode in which `.’ can match any character, including a newline. See, for example, [1] and this language comparison for regexp features: [2].

It is not unusual to manipulate multi-line completion candidates in Icicles, in which case it can be handy to let `.’ match any character, including a newline. For this and more general reasons, I long ago requested such a mode for Emacs, but there was little interest in implementing it. In Emacs, dot never matches a newline. Too bad.

The regexp `\(.\|[\n]\)’ is good enough, of course: it matches any character: any character any except newline, plus newline. But it is a bit unwieldly, especially when used within a larger regexp, and especially if used more than once in the same regexp. Interactively, you input the `\n’ using ‘C-j’, and it appears in the minibuffer as a newline character; that is, it creates another line of input.

For convenience in multi-line matching, I added a multi-line dot, or dot-matches-newline-too, hack to Icicles. This feature is turned off, by default. You can toggle it on/off, using command ‘icicle-toggle-dot’ (aka `icicle-toggle-.’), which is bound to `C-M-.’ in the minibuffer during completion.

When this is turned on, `.’ is highlighted in the minibuffer (using face ‘highlight’), and it matches newlines also. In fact, although it appears as just a highlighted dot, the ugly regexp `\(.\|[\n]\)’ (the value of constant ‘icicle-anychar-regexp’) is really used, under the covers. Icicles takes care of things so that you can edit normally (delete and transpose characters, etc.): A multi-line `.’ acts just like a normal, single character, even though it is really a string of ten characters.

If you prefer to see the full regexp, `\(.\|[\n]\)’, but highlighted, then set option `icicle-dot-show-regexp-flag’ to non-‘nil’. (In Emacs 20, the newline-matching dot is always shown as that full regexp.) And remember that you can use multi-command ‘icicle-toggle-option’ anytime (bound to ‘M-i M-i’ during completion) to toggle the option. If you prefer to turn on newline matching by default, then just customize option `icicle-dot-string’.

This match-anything dot is handy, but sometimes you might want to match anything except a newline, perhaps in the same input pattern where you also want to match any character (possibly a newline) at other positions. How can you get the plain dot behavior, when multi-line dot is turned on?

One way is just to use a regexp that matches anything except newline: `[^\n]’ (which you input using `[ ^ C-j ]’). Another way is to use a plain prefix argument: `C-u .’. (A numeric prefix argument N inserts N multi-line dots, each of which matches any single character.)

‘C-u’ flips the behavior of `.’ when you hit it: If by default `.’ enters a multi-line dot, then `C-u .’ enters a plain dot. If by default `.’ enters a plain dot, then `C-u .’ enters a multi-line dot. So ‘C-u’ also gives you a way to enter a one-off multi-line dot, if you prefer to generally have `.’ not match a newline. Either way, what you see in the minibuffer is the single character `.’, highlighted if it is a multi-line dot, unhighlighted if it is a plain dot.

Multi-line dots are converted to plain dots automatically when you use prefix completion. And if you then move back to apropos completion during the same completion operation, you get back any multi-line dots you had before, and any plain dots that you entered before remain plain.

So when is a multi-line dot useful? Whenever you want to match against multi-line candidates. Typical use cases include ‘icicle-search’ and the Icicles doc commands, ‘icicle-vardoc’, ‘icicle-fundoc’, and ‘icicle-doc’.

Note that the dot-matching behavior described here applies only to matching minibuffer input against completion candidates. It does not mean that whenever you type `.’ in the minibuffer it is interpreted specially. For example, when you input (using ‘RET’) a regexp as the context pattern for Icicles search, a `.’ has its usual meaning in Emacs regexps – it does not match newlines.

If you want a regexp that you input (using ‘RET’) to match any character including a newline, then you can use `C-u C-= icicle-anychar-regexp’ to insert the proper string explicitly. You can shorten this to just `C-=’ if you use command ‘icicle-save-string-to-variable’:

  M-x icicle-save-string-to-variable C-u C-= icicle-anychar-regexp

See Also:

Previous: Icicles - Searching Named ContainersIciclesIciclesIndexNext: Icicles - More About Multi-Commands

DrewsElispLibraries referenced here: Lisp:icicles.el

CategoryCommands CategoryCompletion CategoryRegexp CategoryDocumentation CategoryHelp CategoryProgrammerUtils CategoryCode