| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.1 Ignoring some files Don't to complete on certain file names 6.2 Buffer completion An application of lightning completion 6.3 HTML mode completion Another example
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you are using this package to complete on file names, then you should
be aware of the lisp variable completion-ignored-extensions.
(Lightning completion on file names is based on a completion mode
already present in Emacs, and this variable comes from that mode.)
Here is its documentation: "Completion ignores filenames ending in any string in this list. This variable does not affect lists of possible completions, but does affect the commands that actually do completions."
Lightning completion mode uses a similar variable, called
lc-ignored-file-extensions, whose default value is equal to
completion-ignored-extensions.
I use LaTeX, and when I start with a file `bozo.tex', then
LaTeX produces a number of auxiliary files: `bozo.aux',
`bozo.dvi', `bozo.log', and possibly `bozo.bbl',
`bozo.blg', `bozo.toc', `bozo.lof', etc. When I am
editing such a file, I edit the file `bozo.tex' frequently, and I
almost never touch the others. So I make sure that
lc-ignored-file-extensions contains the strings ".toc"
".log" ".aux" ".lof" ".blg" ".bbl" ".dvi". The easiest way
to do this is to customize this variable.
In case you haven't been paying attention: suppose I have added ".aux" to
lc-ignored-file-extensions, and I want to find the file
`bozo.aux', with lightning completion enabled. One way to do this
is to type `bozo.aux' quickly enough that emacs is never idle for
half a second. Another option is to hit C-c right at the start,
to turn off lightning completion; then just type in `bozo.aux' at
one's leisure. Another way to do this is to use lightning completion to
get `bozo.tex' and ending completion there (if this is the only
file that starts `bozo' that doesn't end in an ignored extension,
completion will end automatically at this point; otherwise, hit
SPC). Then delete `tex' and type in `aux'. There are
other ways of doing this, no doubt, but I'll let you figure them out.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Buffer completion is an example of a use of lightning completion: it lets you complete on reasonably balanced substrings of a buffer. The main function is
(completing-insert-buffer-contents BUF) |
where BUF is interactively the current buffer or, with a prefix argument, a buffer specified by the user.
In other words, if I want to repeat something I said somewhere else in
this buffer, I call the function
completing-insert-buffer-contents. At that point, I enter
lightning completion mode on the contents of this buffer. If I want to
repeat something I said in a different buffer, I hit C-u and then
call completing-insert-buffer-contents. Emacs prompts me for a
buffer name, and then does lightning completion on the contents of that
other buffer. This is useful if you're too lazy to switch buffers, find
the material you want to copy, mark it, kill it, and yank it.
The `dabbrev' package (included as part of the standard GNU Emacs distribution) does some similar things, so you might want to look at that, too. I won't advocate the use of one package over the other--I think each has its uses.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is another example of how to use lightning completion: you can
automatically complete on HTML tags when in html mode. I have the
following lines in my `.emacs' file. The first line binds the <
key to the function html-lightning-tag (you could use a different
key, if you wanted, but since HTML tags all start with this character,
it seems to make sense). The next lines define this function--it does
lightning completion on HTML tags. And the remaining lines (starting
with `(defvar html-light-alist') define the list of HTML tags on
which to complete. A typical line is `("<h3></h3>" -5)'; the first
entry is the tag, and the second entry is the number of characters from
the end by which the point should be offset (i.e., Emacs inserts the
string `"<h3></h3>"' and then moves forward -5 characters). (This
whole business is intended to be used with the version of
html-mode that is contained in the file `sgml-mode.el', part
of (for example) the standard GNU Emacs distribution.
(define-key html-mode-map "<" 'html-lightning-tag)
(defun html-lightning-tag nil
"Lightning complete control sequence."
(interactive)
(insert "<")
(completing-insert html-light-alist nil 1 'point-adjust-hook
"html tags"))
(defvar html-light-alist
'(
("<a href=\"\"></a>" -6)
("<h1></h1>" -5)
("<h2></h2>" -5)
("<h3></h3>" -5)
("<h4></h4>" -5)
("<h-5></h-5>" -5)
("<h6></h6>" -5)
("<hr>
" 0)
("<!-- -->" -5)
("<img src=\"\" alt=\"\">" -9)
("<ol>
<li>
</ol>" -6)
("<ul>
<li>
</ul>" -6)
("<li> " 0)
("<dl>
<dt>
<dd>
</dl>" -12)
("<dt>
<dd> " -6)
("<p>
" 0)
("<table>
<tr>
<th> </th>
</tr>
</table>" -20)
("<th> </th>" -5)
("<tr>
<td> </td>
</tr>" -11)
("<td> </td>" -5)
("<html>
<head>
<title> </title>
</head>
<body lang=\"EN\">
</body>
</html>" -32)
("<address>John H. Palmieri, Department of Mathematics, University
of Washington, palmieri@math.washington.edu</address>
" 0)
("<address></address>
" -11)
("<cite></cite>" -7)
("<kbd></kbd>" -6)
("<dfn></dfn>" -6)
("<em></em>" -5)
("<samp></samp>" -7)
("<small></small>" -8)
("<strong></strong>" -9)
("<sub></sub>" -6)
("<sup></sup>" -6)
("<tt></tt>" -5)
("<var></var>" -6)
("<code></code>" -7)
("<blockquote>
</blockquote>
" -15)
("<math>
</math>
" -9)
("<pre>
</pre>
" -8)
("<br>
" 0))
"Alist of html tags for use with lightning completion")
|
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |