Tempo mode in Emacs

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 🙂

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s