[OS X Emacs] Abbrevs

M A markoilcan at gmail.com
Sat Feb 7 14:55:32 EST 2009


On Sat, Feb 7, 2009 at 12:38 AM, Jan Rosinski <jrosinsk at gmail.com> wrote:
> I was trying to define, unsuccessfully, abbrev of \frac{}{} to be triggered
> by \f
> with the cursor between the first braces at the end, in the local latex
> mode.
> I can do it with fr as a trigger but \f does not work.
> Eventually, I would like to have several such abbrevs for the math. Is it
> possible with
> the prefix \ ? If not, what is the best solution? Concrete examples are the
> best. Thanks.
>

In emacs abbrevs only work, I believe, on word characters, which rules
out using \ in
the key for the abbrev. I would recommend trying out yasnippet, which
is what I use
these day since it is both easy to define a "snippet" and to move the
point (cursor)
around. For instance, you would put the following text in a file in
your snippet directory
for latex mode,

#key:\f
#name: \frac{}{}
# --
\frac{$1}{$2}$0

(without a newline after $0), then after typing \f you press TAB it
expands into \frac{}{}
placing the cursor between the first two braces. Press TAB again and
the cursor moves
between the second pair of braces. Press TAB a third time and the
cursor is placed after
the last brace. There does appear to be a bug where \f does not expand
if the \ is the first
character on the line, but otherwise it works for me. You can find yasnippet at
http://code.google.com/p/yasnippet/

MarkA



More information about the MacOSX-Emacs mailing list