[OS X Emacs] Abbrevs with '\' character don't work in Aquamacs 1.5

Ian Eure ian at digg.com
Fri Oct 10 17:55:48 EDT 2008

On Oct 8, 2008, at 2:29 PM, Adrian wrote:

> Hello,
> I'm trying to define some abbrevs for LaTeX commands.  However, if I  
> try to define any abbrevs beginning with a '\' character, the abbrev  
> is not completed when I type a space after the word.  I have  
> included several examples from my abbrevs file below:
> (define-abbrev-table 'text-mode-abbrev-table '(
>     ("teh"  "the "  nil 0)
>     ("\\c" "\\chapter{}" backward-char 0)
>     ("\\i" "\\item" nil 0)
>     ; abbreviations calling functions (which are defined in my- 
> latex.el)
>     ("\\ce" "" my-latex-center 0)
>   ))
> Of these examples, the first works fine in LaTeX mode.  However,  
> none of the others produce any results when I type a space after the  
> desired abbrev.  For example, "\c " will remain as "\c" and not  
> expand to "\chapter{}" as desired.  I have tried altering the syntax  
> of the abbrevs a bit.  If I remove one of the preceding slash  
> characters, so the abbrev definition looks like "\c" "\\chapter{}"  
> etc., the abbrev is inserted when I type "c " with no preceding  
> slash.  Also, if I try to define an abbrev using the command line  
> key sequence C-x a g, the resulting abbrev is still not functional.   
> For example, typing C-x a g after "\ref{}" and assigning the abbrev  
> "\foo", I see a new line in my list of abbrevs that looks just like  
> the ones above: ("\\foo" "\\ref{}" nil 0).  However, this abbrev,  
> like the ones I have defined for myself, also fails.  It seems that  
> Emacs doesn't know how to read its own syntax...?
So, I'm not 100% sure about my explanation, here, but the practical  
upshot is the same.

Abbrevs depend on the syntax of the character inserted. They only work  
on a sequence of word-syntax characters. Since a backslash is  
punctuation, it's not considered part of the abbreviation, and your  
abbrev isn't expanded.

E.g. If I type:

\c [SPC]

Abbrev will try to expand `c', not `\c'. This is not an Aquamacs bug,  
it's how Abbrev is implemented in GNU Emacs.

> I hope what I am trying to do is possible in Emacs, as it seems like  
> fairly basic functionality.  If not, is there a better way to handle  
> LaTeX completions in Emacs?
Define abbrevs which are sequences of word-syntax characters. e.g.  
`chap', `itm', `cen', etc.

You might also try using yasnippet. I don't know if it has the same  
limitation, but it might be a better fit for what you're doing, since  
it's much more flexible. For example, you can tell it where point  
should be within the text once it's expanded.

  - Ian

More information about the MacOSX-Emacs mailing list