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__);">)
"include"
"Insert a printf statement with info on location"
'c-tempo-tags)
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
BTW,
__FILE__ , __LINE__ and __PRETTY_FUNCTION__ are GCC magic identifiers