all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Richard Riley <rileyrgdev@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: auto-indenting C++ files upon saving
Date: Fri, 19 Feb 2010 17:57:27 +0100	[thread overview]
Message-ID: <ogs257-mg8.ln1@news.eternal-september.org> (raw)
In-Reply-To: ue1vghp52p.fsf@sobolev.dsm.fordham.edu

Art Werschulz <agw@dsm.fordham.edu> writes:

> 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?

As a point of contention, I don't think you should do this when you
save. When you save you should be saving what you see. Students should
be indenting as they go.

Another reason is that people often save periodically anyway as they
edit - it would really annoy me if suddenly the program took it on
itself to re-indent the block I was working on.

As for putting it on auto-save this is even worse - it can auto-save
while you are typing and cause significant disruption.

>
> 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.

Is mark-whole-region a function?

>
> 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!

At the minimum if you want auto-save-hook (I dont think its a good idea)
you should save your point etc (save-excursion) before doing the rest.

regards,

r.





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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
     [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=ogs257-mg8.ln1@news.eternal-september.org \
    --to=rileyrgdev@gmail.com \
    --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.