Johnny [Life & Code]

Semper Exploro!

Tempo mode in Emacs

leave a comment »

When debugging or learning code i use a lot of printf statements to understand the execution path and things like that. I know there are better ways to learn the code …. But I like these printfs… So in emacs this is how i do it using the tempo mode. koool

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

;;; C-Mode Templates
(require 'tempo)
;;; (setq tempo-interactive t)

(add-hook 'c-mode-hook
'(lambda ()
(local-set-key [f11] 'tempo-complete-tag)
(tempo-use-tag-list 'c-tempo-tags)
;;; Templates appended to c-tempo-tags

(tempo-define-template "c-debug-pf"
'("printf(\"%s(%d):%s:" r "\\n\", __FILE__, __LINE__, __PRETTY_FUNCTION__);">)
"Insert a printf statement with info on location"

Add this line (i'm sure there ia better way to add this .. but for now ….)
(global-set-key "\C-x\C-q" 'tempo-template-c-debug-pf)

So from now on inside any buffer if you press C-x C-q… it'll insert the line

printf("%s(%d):%s:\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
You can add any number of templates


__FILE__ , __LINE__ and __PRETTY_FUNCTION__ are GCC magic identifiers🙂

Written by Johnny

May 25, 2006 at 4:09 am

Posted in Emacs, Tech

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: