From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Using indent program as filter to automatically view read-only C files
Date: Fri, 03 Feb 2006 11:46:46 -0700 [thread overview]
Message-ID: <ds08eq$u32$1@sea.gmane.org> (raw)
In-Reply-To: <1138967200.247984.79880@f14g2000cwb.googlegroups.com>
juanleon1@gmail.com wrote:
> I have to work with C/C++ files with a very ugly and inconsistent
> indentation (many developers adding things with no style guide). This
> is very distracting, and since I cannot change them (to avoid conflicts
> when taking/carryng changes from/to other branches), I had think that
> for read-only files (those that I have not opened in the revision
> control system), it would be nice if emacs could run automagically the
> "indent" program so I can see the code "beatyfully" indented.
>
> I didn't find anything obvious on the net for that. I do not wanna
> modify files in disk, only to make emacs to put the indent output in
> the buffer without changing variables like `buffer-file-name' and so. I
> would like this to be done in a transparent way when opening a C/C++
> file (via find-file, find-tag or whatever).
>
> Before trying to code something like that myself (and most probably
> reinvent the wheel), I would like to know if anybody knows if this (or
> something similar enough I could reuse/modify) is already available.
>
> Any ideas welcome.
(add-hook 'find-file-hooks
(lambda ()
(when (and buffer-read-only
(memq major-mode '(c-mode c++-mode)))
(let ((buffer-modified-p (buffer-modified-p))
(inhibit-read-only t))
(shell-command-on-region (point-min) (point-max) "indent"
nil t nil)
(set-buffer-modified-p buffer-modified-p)
;; (set-visited-file-modtime)
))))
--
Kevin Rodgers
next prev parent reply other threads:[~2006-02-03 18:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-03 11:46 Using indent program as filter to automatically view read-only C files juanleon1
2006-02-03 18:46 ` Kevin Rodgers [this message]
2006-02-03 19:06 ` François Gannaz
2006-02-03 19:39 ` Eli Zaretskii
2006-02-03 23:10 ` Harry Putnam
[not found] ` <mailman.59.1138996411.2860.help-gnu-emacs@gnu.org>
2006-02-06 4:02 ` Paul Whitfield
[not found] ` <mailman.36.1138992933.2860.help-gnu-emacs@gnu.org>
2006-02-06 15:27 ` juanleon1
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='ds08eq$u32$1@sea.gmane.org' \
--to=ihs_4664@yahoo.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).