Some examples of tempo.el use


html-helper-mode

Available from http://www.santafe.edu/~nelson/tools/


C and C++

These were written by Joachim Baumann <joachim.baumann@informatik.uni-stuttgart.de>.

;; This is a way to hook tempo into cc-mode

(defvar c-tempo-tags nil
  "Tempo tags for C mode")

(defvar c++-tempo-tags nil
  "Tempo tags for C++ mode")

;;; C-Mode Templates and C++-Mode Templates (uses C-Mode Templates also)
(require 'tempo)
(add-hook 'c-mode-hook '(lambda ()
			  (tempo-use-tag-list 'c-tempo-tags)
			  ))

(add-hook 'c++-mode-hook '(lambda ()
			    (tempo-use-tag-list 'c-tempo-tags)
			    (tempo-use-tag-list 'c++-tempo-tags)
			    ))


;;; Preprocessor Templates (appended to c-tempo-tags)

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

(tempo-define-template "c-ifdef"
		       '("#ifdef " (p "ifdef-clause: " clause) > n> p n
			 "#else /* !(" (s clause) ") */" n> p n
			 "#endif /* " (s clause)" */" n>
			 )
		       "#ifdef"
		       "Insert a #ifdef #else #endif statement"
		       'c-tempo-tags)

(tempo-define-template "c-ifndef"
		       '("#ifndef " (p "ifndef-clause: " clause) > n 
			 "#define " (s clause) n> p n
			 "#endif /* " (s clause)" */" n>
			 )
		       "#ifndef"
		       "Insert a #ifndef #define #endif statement"
		       'c-tempo-tags)

;;; C-Mode Templates

(tempo-define-template "c-if"
		       '(> "if(" (p "if-clause: " clause) ")"  n> 
			 "{" > n> r n 
			 "} /* end of if(" (s clause) ") */" > n> 
			 )
		       "if"
		       "Insert a C if statement"
		       'c-tempo-tags)

(tempo-define-template "c-else"
		       '(> "else" n> 
			 "{" > n> r n 
			 "} /* end of else */" > n>
			 )
		       "else"
		       "Insert a C else statement"
		       'c-tempo-tags)

(tempo-define-template "c-if-else"
		       '(> "if(" (p "if-clause: " clause) ")"  n> 
			 "{" > n> r n 
			 "} /* end of if(" (s clause) ") */" > n>
			 > "else" n> 
			 "{" > n> r n 
			 "} /* end of if(" (s clause) ")else */" > n> 
			 )
		       "ifelse"
		       "Insert a C if else statement"
		       'c-tempo-tags)

(tempo-define-template "c-while"
		       '(> "while(" (p "while-clause: " clause) ")" >  n> 
			 "{" > n> r n 
			 "} /* end of while(" (s clause) ") */" > n>
			 )
		       "while"
		       "Insert a C while statement"
		       'c-tempo-tags)

(tempo-define-template "c-for"
		       '(> "for(" (p "for-clause: " clause) ")" >  n> 
			 "{" > n> r n 
			 "} /* end of for(" (s clause) ") */" > n>
			 )
		       "for"
		       "Insert a C for statement"
		       'c-tempo-tags)

(tempo-define-template "c-for-i"
		       '(> "for(" (p "variable: " var) " = 0; " (s var)
			 " < "(p "upper bound: " ub)"; " (s var) "++)" >  n> 
			 "{" > n> r n 
			 "} /* end of for(" (s var) " = 0; "
			 (s var) " < " (s ub) "; " (s var) "++) */" > n>
			 )
		       "fori"
		       "Insert a C for loop: for(x = 0; x < ..; x++)"
		       'c-tempo-tags)

(tempo-define-template "c-for"
		       '(> "for(" (p "for-clause: " clause) ")" >  n> 
			 "{" > n> r n 
			 "} /* end of for(" (s clause) ") */" > n>
			 )
		       "for"
		       "Insert a C for statement"
		       'c-tempo-tags)

(tempo-define-template "c-main"
		       '(> "main(int argc, char *argv[])" >  n> 
			 "{" > n> r n 
			 "} /* end of main() */" > n>
			 )
		       "main"
		       "Insert a C main statement"
		       'c-tempo-tags)

(tempo-define-template "c-if-malloc"
		       '(> "if((" (p "variable: " var) " = ("
			 (p "type: " type) " *) malloc(sizeof(" (s type) 
			 "))) == (" (s type) " *) NULL)" n> 
			 "{" > n> r n 
			 "} /* end of if((" (s var) " = (" (s type) 
			 " *) malloc...) == NULL) */" > n>
			 )
		       "ifmalloc"
		       "Insert a C if(malloc...) statement"
		       'c-tempo-tags)

(tempo-define-template "c-switch"
		       '(> "switch(" (p "switch-condition: " clause) ")" >  n> 
			 "{" > n 
			 "case " (p "first value: ") ":" > n> p n
			 "break;" > n> p n
			 "default:" > n> p n
			 "break;" > n
			 "} /* end of switch(" (s clause) ") */" > n>
			 )
		       "switch"
		       "Insert a C switch statement"
		       'c-tempo-tags)

(tempo-define-template "c-case"
		       '(n "case " (p "value: ") ":" > n> p n
			   "break;" > n> p
			   )
		       "case"
		       "Insert a C case statement"
		       'c-tempo-tags)


;;;C++-Mode Templates


(tempo-define-template "c++-class"
		       '("class " (p "classname: " class) p n "{" n "public:" n>

			 (s class) "();" 
			 (indent-for-comment) "the default constructor" n>

			 (s class) 
			 "(const " (s class) "&rhs);"
			 (indent-for-comment) "the copy constructor" n>

			 (s class)
			 "& operator=(const " (s class) "&rhs);"
			 (indent-for-comment) "the assignment operator" n>

			 n> "// the default address-of operators" n>
			 "// "(s class)
			 "* operator&()             { return this; };" n>
			 "// const "(s class)
			 "* operator&() const { return this; };" n


			 n > "~" (s class) "();"
			 (indent-for-comment) "the destructor" n n>
			 p n
			 "protected:" n> p n
			 "private:" n> p n
			 "};\t// end of class " (s class) n>
			 )
		       "class"
		       "Insert a class skeleton"
		       'c++-tempo-tags)

Emacs lisp

These are my own templates. It includes a rebinding of the space bar, which is rather experimental. That requires tempo.el version 1.2.1, at least.

(require 'tempo)

(defvar elisp-tempo-tags nil)

(tempo-define-template "defun"
		       '("defun " p " (" p ")" n> "\"" p "\"" n> r ")")
		       "defun"
		       "Insert a defun expression"
		       'elisp-tempo-tags)

(tempo-define-template "defvar"
		       '("defvar " p  n> "\"" p "\")")
		       "defvar"
		       "Insert a defvar expression"
		       'elisp-tempo-tags)

(tempo-define-template "if"
		       '("if " p n> r ")")
		       "if"
		       "Insert an if expression"
		       'elisp-tempo-tags)

(tempo-define-template "cond"
		       '("cond ((" p ") " r "))")
		       "cond"
		       "Insert a cond expression"
		       'elisp-tempo-tags)

(defun elisp-tempo ()
   "Set up emacs-lisp mode to use tempo.el"
   (local-set-key [M-S-tab] 'tempo-complete-tag)
   (local-set-key "\C-c\C-f" 'tempo-forward-mark)
   (local-set-key "\C-c\C-b" 'tempo-backward-mark)
   (local-set-key " " 'elisp-space)
   (setq tempo-match-finder "(\\([^\\b]+\\)\\=")
   (tempo-use-tag-list 'elisp-tempo-tags))

(defun elisp-space ()
  ""
  (interactive)
  (if (tempo-expand-if-complete)
      nil
    (insert " ")))
(define-key emacs-lisp-mode-map " " 'elisp-space)

David K├ągedal <davidk@lysator.liu.se>