[OS X Emacs] auto-indenting C++ files upon saving

Art Werschulz agw at comcast.net
Fri Feb 12 11:25:57 EST 2010


I am trying to teach my students that they should auto-indent their C++ files before saving, by issuing the commands
   C-x h M-C-\
However, they haven't trained their "muscle memory" to do this, i.e., to automatically type the sequence 
   C-x M-C-\ C-x C-s
How can this be automated, so that a file gets auto-indented whenever it's saved?

I thinking of something along the lines of
(setq auto-save-hook
but this didn't seem to work.

Actually, I'd only want this to work in some situations, e.g., a file whose name matches a certain pattern.  Said pattern would be stored in some variable.

My emacs-lisp is very weak.  Suggestions?  Thanks!

Art Werschulz (8-{)}   "Metaphors be with you."  -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y?
Internet: agw STRUDEL comcast.net

More information about the MacOSX-Emacs mailing list