Emacs hacks for bootcamp
Home : Emacs tips :
rgr-hacks
This is a subset of my personal collection of hacks and tweaks; by
default, not all of it is enabled.
Table of Contents
- Emacs hacks for bootcamp
- Table of Contents
- Installation
- Using rgr-abbrev-completion to save typing
- Mouse commands
- Useful commands in
html-helper-mode
- Additional rgr-html-hacks commands
- More
html-helper-mode
documentation
Installation
These installation instructions are for setting up your bootcamp machine
with the extra emacs stuff documented below.
- Download the file rgr-hacks-1.3.tar.gz
into your home directory. (Clicking on the link should be
sufficient to accomplish this.)
- Untar this into your ~/emacs directory. In a shell, do
the following:
cd
gunzip < rgr-hacks-1.3.tar.gz | tar xf -
This creates an ~/emacs directory, if one does not
already exist.
- Install the sample
.emacs
file in your home
directory.
mv emacs/dot-emacs.el .emacs
(Don't forget the dot in ".emacs"!)
-- Or --
If you already have a .emacs
file, you may prefer to
append the new stuff:
cat emacs/dot-emacs.el >> .emacs
- Start a new emacs, and you should have it. Find a
.html file using C-x C-f to test it (an
empty file is fine); the mode line (in inverse video near the
bottom) should say
--:** foo.html (HTML helper Fill)--L3--All--------
or something similar.
Enjoy, and let me know if you encounter any bugs.
Using rgr-abbrev-completion to save typing
emacs has an "abbrev" concept whereby you can save typing by using
abbreviations, which emacs will automatically expand as they are typed.
This has the disadvantage that the abbreviations must predefined, and
furthermore they must be unique. There is also a notion of definition
name completion (e.g. M-TAB in the minibuffer when M-.
prompts you for a tag name) that uses the same style of completion as
for file names, but this is limited to names of definitions found in tags tables, and runs into the problem
that definitions usually have common prefixes.
In the mean time, I got used to a package on the Symbolics Lisp
Machine that had the best features of both, plus some extras. When I
stopped being able to use Lisp Machines, I hacked a version (from
memory) for emacs that I called rgr-abbrev-completion. It currently has
the following features:
- Names are learned automatically whenever you read in a file in a
syntax that rgr-abbrev-completion knows about.
Currently supported language modes are emacs-lisp-mode,
lisp-mode, makefile-mode, and c-mode.
(tcl-mode is also supported if you use
rgr-tcl-mode-hook.)
- Names available for completion are also learned as you type, so
they are not limited to definition names.
- Names can be completed normally (by specifying prefixes), or by
specifying abbreviations (e.g. "rtmh" or "rtm"
for "rgr-tcl-mode-hook".) The abbreviations are
constructed automatically from initial letters as names are
learned.
- In order to avoid confusion, completion is invoked explicitly; I
bind it to f4 because this is easy to type.
- Abbreviations need not be unique. The first f4 inserts
the most used abbreviation, and subsequent f4
invocations cycle through the other possibilities in order from
most to least used.
- Completion names and their usage frequencies can also be saved to
disk and restored on restart, so that useful names are not
immediately forgotten.
Commands:
- f4 (rgr-insert-symbol-abbreviation) --
attempt to complete the name before point. Must have at least
three characters. Repeated invocations will attempt to complete
more of the name (for traditional completion) or cycle through
the possibilities from most to least used (for abbreviations).
- M-x rgr-install-abbrev-completion --
- M-x rgr-install-weekly-completion-cycle --
[finish. -- rgr, 7-Oct-99.]
Mouse commands
Because I have been seriously and permanently handicapped by using the
powerful Lisp Machine user interface, I was driven to recreate some of
its mouse commands within emacs after being forced back into the Unix
world. There is a Symbolics-like cut-and-paste interface, but the real
win is a mouse interface to M-.. (Though you may have to
disable your window manager's interception of the "meta" modifier on the
mouse buttons in order to get it to work.)
These are not enabled by default, since they override standard emacs
mouse command bindings.
- M-mouse-1 (rgr-mouse-edit-thing) --
finds the source files for the thing under the mouse.
- If it looks like a pathname (i.e. starts with '.', '/', or
'~', or has a host: prefix followed by one of these three
characters), then do C-x C-f on it.
(Relative pathnames are interpreted relative to the
filename of the buffer in which you clicked.)
- If it looks like a Common Lisp or emacs Lisp symbol, then
do M-.
(find-tag) on it.
- If it looks like a file URL (i.e. starts with
"ftp:" or "file:"), then it converts the
URL to an
ange-ftp file name and uses
C-x C-f on it.
- If it looks like a World Wide Web URL (i.e. starts with
"http:", etc.), then it brings up the page in
Netscape. (Although it is possible to teach it to bring
up a page in other browsers, I have not written the code
to do so.)
Whatever it is (unless it gets viewed in Netscape), it is found
in the current window, regardless of where you click.
- C-down-mouse-1
(rgr-mouse-mark-text-down) -- sets the mark or copies
text to kill ring. If clicked in a single spot, sets the mark
there. If clicked in one spot and dragged to and released at
another, copies the intervening text to the kill ring. The click
and release points may be in either order, and need not even be
in the same window, as long as they are in the same buffer (which
need not be the same as the current buffer).
- C-mouse-2 (rgr-mouse-insert-thing) --
Insert the thing under the mouse at point. Sets the mark to the
beginning of the insertion, and leaves point at the end. If
clicked after the end of a line, inserts the whole line, else
inserts the word or expression clicked on. This works between
windows/buffers, including the minibuffer, and does not change
the current buffer.
Setting up:
[finish. -- rgr, 8-Nov-99.]
Useful commands in html-helper-mode
HTML helper mode is a mode for editing HTML documents which I prefer to
the default HTML mode distributed with emacs. For more documentation
and the newest version, see
http://www.santafe.edu/~nelson/tools/.
The main function html-helper-mode provides is a menu and keybindings
for the HTML tags one inserts when writing HTML documents. Selecting
the menu item or typing the key sequence for a command inserts the
corresponding tag and places point in the right place. If a prefix
argument is supplied, the tags is instead wrapped around the region.
Alternately, one can type in part of the tag and complete it with
M-TAB. (Personally, I don't use either, much; I type it all
the hard way because I find going back and forth to fill in the template
to be annoying.)
There is also code for indentation, timestamps, skeletons for new
documents, and lots of other neat features.
Commands:
- M-RET (tempo-template-html-paragraph)
inserts a <p> tag.
- M-TAB (tempo-complete-tag) completes the
tag name before point.
- M-C-b (tempo-forward-mark) goes to the
previous template mark in an inserted HTML template. (But I don't
use HTML templates, so I restore the default binding of
M-C-b to backward-sexp).
- M-C-f (tempo-backward-mark) goes to the
next template mark in an inserted HTML template. (But I don't
use HTML templates, so I restore the default binding of
M-C-f to forward-sexp).
Inserting entities:
These are those &foo; things;
see ASCII - ISO
8859-1 Table with HTML Entity Names for a description and
list of names and encodings.
- C-c <
(tempo-template-html-less-than) inserts the entity for
"<".
- C-c >
(tempo-template-html-greater-than) inserts the entity for
">".
- C-c &
(tempo-template-html-ampersand) inserts the entity for
"&".
- C-c SPC
(tempo-template-html-nonbreaking-space) inserts the entity for
" " (a hard space).
- C-c -
(tempo-template-html-soft-hyphen) inserts the entity for
"" (normally not displayed, but may be turned into a hyphen
by line wrapping).
- C-c @
(tempo-template-html-copyright) inserts the entity for
"©" (the copyright symbol).
- C-c $
(tempo-template-html-registered) inserts the entity for
"®" (the registered trademark symbol).
- C-c "
(tempo-template-html-quotation-mark) inserts the entity for
'"' (a quotation mark).
- C-c #
(tempo-template-html-ascii-code) inserts "&#;", with
the cursor positioned before the ";", which specifies an entity
by its decimal internal encoding.
Text markup (physical presentation):
Typing these inserts matching start/end tags with the cursor
positioned between them; with a numeric argument, tags are put
around the region.
- C-c C-p f
(tempo-template-html-fixed)
- C-c C-p b
(tempo-template-html-bold)
- C-c C-p i
(tempo-template-html-italic)
- C-c C-p u
(tempo-template-html-underline)
- C-c C-p s
(tempo-template-html-strikethru
Text markup (logical presentation):
- C-c C-s p
(tempo-template-html-preformatted)
- C-c C-s s
(tempo-template-html-strong)
- C-c C-s e
(tempo-template-html-emphasized)
- C-c C-s a
(tempo-template-html-address)
- C-c C-s d
(tempo-template-html-definition)
- C-c C-s v
(tempo-template-html-variable)
- C-c C-s k
(tempo-template-html-keyboard-input)
- C-c C-s r
(tempo-template-html-citation)
- C-c C-s x
(tempo-template-html-sample)
- C-c C-s c
(tempo-template-html-code)
- C-c C-s b
(tempo-template-html-blockquote)
Headings:
Typing these inserts matching start/end tags with the cursor
positioned between them.
- C-c C-t 1
(tempo-template-html-header-1)
- C-c C-t 2
(tempo-template-html-header-2)
- C-c C-t 3
(tempo-template-html-header-3)
- C-c C-t 4
(tempo-template-html-header-4)
- C-c C-t 5
(tempo-template-html-header-5)
- C-c C-t 6
(tempo-template-html-header-6)
Links ("anchors"):
- C-c C-a l
(tempo-template-html-hyperlink)
- C-c C-a n
(tempo-template-html-link-target)
Miscellaneous tags:
- C-c RET
(tempo-template-html-line-break) inserts a
<br> tag.
- C-c =
(tempo-template-horizontal-rule) inserts an
<hr> tag.
- C-c C-z v (browse-url-of-file)
- C-c C-z t
(html-helper-insert-timestamp-delimiter-at-point)
Images:
- C-c TAB t
(tempo-template-html-image-with-alternate-text)
- C-c TAB e
(tempo-template-html-aligned-image-with-alt.-text)
- C-c TAB i
(tempo-template-html-image)
- C-c TAB a
(tempo-template-html-aligned-image)
Additional rgr-html-hacks commands
These are installed by the rgr-html-define-commands hook
function; the rgr-hacks sample
.emacs file does the following to install
html-helper-mode and rgr-html-hacks:
;; Install html-helper-mode.
(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))
;; Add my HTML code hacks: check tag nesting (C-c n), make table of contents
;; (C-c t), check href's (C-c h c), paragraph motion, markup motion (C-c C-f,
;; C-c C-b, C-c C-k), and much more. (Only need to do this once, so these are
;; on html-helper-load-hook.)
(add-hook 'html-helper-load-hook 'rgr-html-define-commands)
(add-hook 'html-helper-load-hook 'rgr-html-fix-regexps)
;; This has some per-buffer stuff (and is therefore on html-helper-mode-hook).
;; -- rgr, 19-Mar-96.
(add-hook 'html-helper-mode-hook 'rgr-html-helper-mode-hook)
If you are using emacs at BMERC,
then these are all pre-installed (at no extra charge).
Markup commands: These operate on nested
<foo>..</foo>
constructs.
- C-c C-f (rgr-html-forward-markup)
-- move forward past markup (M-C-f equivalent for HTML).
- C-c C-b (rgr-html-backward-markup)
-- move backward past markup (M-C-b equivalent for
HTML).
- C-c C-u
(rgr-html-backward-up-markup) -- move backward out of
the current markup (M-C-u equivalent for HTML).
- C-c C-l (rgr-html-forward-li) --
moves forward to the next <li> tag of the current
list (i.e. ignoring any <li> items within nested
lists). If there aren't any, this just leaves you after the last
list close tag. This needs a special command because people
almost never use </li> tags.
- C-c / (rgr-html-close-markup) --
insert a close tag for the last open tag; a numeric argument
closes the last N tags.
- C-c C-k (rgr-html-kill-markup) --
kill markup (M-C-k equivalent for HTML).
- C-c n (rgr-html-check-tag-nesting)
-- check HTML tags for nesting errors. If any are found, they are
put in a buffer which is viewed in the other window, and you can
use
C-x ` to step through them, as for the M-x grep command.
- TAB (html-helper-indent-command) -- indent the
current line prettily. (html-helper-mode implements
this, but rgr-html-hacks fixes some bugs.)
- M-C-q (rgr-html-indent-markup) -- indent
all markup lines.
Anchor checking commands:
- c-c h c
(rgr-html-check-buffer-hrefs) -- check for href's to
undefined pages/tags. if any are found, they are put in a buffer
which is viewed in the other window, as with c-c n,
and you can use
c-x ` to step through them.
- c-c h f
(rgr-html-fix-buffer-hrefs) -- like
c-c h c, but offers to replace an undefined
reference to one in another file, if it knows of any of the same
name (see C-c a u and
C-c a f). Can't handle offsite references.
- C-c h d
(rgr-html-check-directory-hrefs) -- checks references to
undefined anchors in the current buffer, like
C-c h c, but also checks everything in the
same directory that is reachable from the current buffer, and
lists all files in that directory that are not reachable from the
current buffer.
- C-c a u
(rgr-html-update-buffer-anchors) -- learns the anchor
names (the "foo" in "<a name=foo>")
of the current buffer, for possible use by
C-c h f.
- C-c a f
(rgr-html-flush-file-anchors) -- forgets the current
buffer's anchor names.
Heading commands:
- M-x rgr-html-add-heading-anchors RET -- add
anchors to all headings that do not already have them.
- M-x rgr-html-increment-buffer-heading-nesting RET
-- increment or decrement the nesting level of headings in the
buffer, e.g. changing <h1> to <h2>,
<h2> to <h3>, etc. By default, the
depth is increased by one, but this can be changed with a prefix
argument, which can be negative to decrease the nesting depth.
- M-x rgr-html-increment-region-heading-nesting RET
-- increment or decrement the nesting level of headings in the
buffer, as by
M-x rgr-html-increment-region-heading-nesting.
Miscellaneous commands:
- M-} (rgr-html-forward-paragraph) --
moves forward to the end of the HTML paragraph. With arg N, do
it N times; a negative arg -N means move backward N paragraphs.
See the online documentation (using C-h f) for
details of how an "HTML paragraph" is defined.
- M-{ (rgr-html-backward-paragraph) --
moves backward to the start of the HTML paragraph. With arg N,
do it N times; a negative arg -N means move forward N paragraphs.
- M-q (rgr-html-fill-paragraph) -- fills
text in the paragraph defined by doing M-{ and
M-} from point.
- C-c t (rgr-html-make-toc) --
inserts a nested table of contents generated from
<h#></h#> lines. If this is the first
invocation in this buffer, this command inserts at point, and you
will be asked to confirm this. Otherwise, the previous TOC is
replaced with a new one. If an anchor definition
(i.e. "<a name=foo>") appears on the previous
line, it will be used to hyperlink the section names. (The TOC
at the top of this document is an example.) If given a numeric
argument, the items are generated within nested
<ul> forms; otherwise, they are within
<ol> forms.
More html-helper-mode
documentation
See the html-helper-mode
documentation at
http://host16.bootcamp.arsdigita.com/html-helper-mode/ (dead
link).
If you don't mind shelling out the money (or already have a copy),
the O'Reilly emacs offerings describe
html-helper-mode
, albeit briefly.
Bob Rogers
<rogers@darwin.bu.edu>
Last modified: Fri Apr 30 22:41:16 EDT 2004