C++ – How to get emacs tempo mode working with abbrevs for C/C++


I've been experimenting with emacs tempo mode and it seems likely to save me lots of typing (always a good thing), but I haven't gotten it to work exactly the way I want it. On the wiki, there is an example for elisp similar to what I want to do which works as expected. Here is the complete .emacs that I tested it on:

(require 'tempo)
(setq tempo-interactive t)
(tempo-define-template "lambda"
                 '(> "(lambda (" p ")" n> r> ")">)
                 "Insert a template for an anonymous procedure")
(define-abbrev lisp-mode-abbrev-table "lambda" "" 'tempo-template-lambda)

This allows me to type "lambda" followed by a space and have it automatically insert

(lambda ( )

In my buffer with the point on the first closing parenthesis.

However, replacing the last two sexp's with the following code (stolen from Joachim Baumann via Sebastien Varrette and modified by me):

(tempo-define-template "c-include"
         '("#include <" r ".h>" > n)
         "Insert a #include <> statement")
(define-abbrev c-mode-abbrev-table "c-include" "" 'tempo-template-lambda)

Will not cause the template to be inserted after typing "c-include" followed by a space. This is on emacs 22.2.1 running under Ubuntu 9.04. Does anybody have any idea why this might be the case before I go digging deeper into the tempo code and/or (god forbid) the C-mode code?

Best Solution

The last argument to your define-abbrev should be 'tempo-template-c-include . Also, I'm not sure you can have a dash in there, i.e. it might have to be cinclude instead of c-include:

(define-abbrev c-mode-abbrev-table "cinclude" "" 'tempo-template-c-include)