tags:

views:

124

answers:

2

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> ")">)
                 nil
                 "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)
         nil
         "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?

+1  A: 

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)
scottfrazer
Spot on. The thing that was really tripping me up was the inability to include dash characters in the abbreviation. The problem with 'tempo-template-lambda was a cut/paste error that crept in while I was experimenting with this. Thanks much.
BD at Rivenhill
+1  A: 

An alternative to tempo is yasnippet, which I found to be easier to set up interesting expansions.

Trey Jackson
+1 for yasnippet -- works naturally with few surprises.
Ashutosh Mehra