help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using indent program as filter to automatically view read-only C fil


From: Eli Zaretskii
Subject: Re: Using indent program as filter to automatically view read-only C files
Date: Fri, 03 Feb 2006 21:39:03 +0200

> From: juanleon1@gmail.com
> Date: 3 Feb 2006 03:46:40 -0800
> 
> 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.

Take a look at format.el, it has a machinery to filter a file through
a program when Emacs visits the file.  That machinery was invented for
a different purpose, but perhaps it is general enough to serve yours.

Btw, Emacs itself can reindent, so one easy way og doing what you want
is to copy the contents of the file into another buffer, set its major
mode to C, and then reindent there.  If the buffer has no file name,
you don't risk to overwrite the original files.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]