all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* auto-indenting C++ files upon saving
@ 2010-02-19 16:23 Art Werschulz
  2010-02-19 16:54 ` Eric James Michael Ritz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Art Werschulz @ 2010-02-19 16:23 UTC (permalink / raw)
  To: help-gnu-emacs

Hi.

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-\
i.e., 
  (mark-whole-buffer)
  (indent-region)
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
     (lambda 
     (mark-whole-region)
     (indent-region)))
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+ P++ e--- m* s n+ h f g+ w+ t+ r- 
Net: agw@dsm.fordham.edu http://www.dsm.fordham.edu/~agw
Phone:   Fordham U. (212) 636-6325, Columbia U. (646) 775-6035


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-02-22  6:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-19 16:23 auto-indenting C++ files upon saving Art Werschulz
2010-02-19 16:54 ` Eric James Michael Ritz
2010-02-19 18:11   ` Andreas Politz
2010-02-19 16:57 ` Richard Riley
     [not found] ` <mailman.1505.1266598832.14305.help-gnu-emacs@gnu.org>
2010-02-22  6:10   ` Torsten Mueller

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.