all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Art Werschulz <agw@dsm.fordham.edu>
To: help-gnu-emacs@gnu.org
Subject: auto-indenting C++ files upon saving
Date: Fri, 19 Feb 2010 11:23:42 -0500	[thread overview]
Message-ID: <ue1vghp52p.fsf@sobolev.dsm.fordham.edu> (raw)

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


             reply	other threads:[~2010-02-19 16:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-19 16:23 Art Werschulz [this message]
2010-02-19 16:54 ` auto-indenting C++ files upon saving 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ue1vghp52p.fsf@sobolev.dsm.fordham.edu \
    --to=agw@dsm.fordham.edu \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.