Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C/C++ mode feature I badly want... (non-persistent indentation)

13 views
Skip to first unread message

S Boucher

unread,
Nov 13, 2012, 6:32:32 PM11/13/12
to help-gn...@gnu.org
I seem to often run into code with what I call random indentation.

Because it is in source control, it's a can of worm to re-indent everything and submit the code properly formatted (just makes it harder to look at history afterward, and it doesn't help when people mess the formatting again after...)

(let ((non-persistent-formatting t))
   (indent-region (point-min) (point-max)))

Would indent the lines, but instead of actually changing the buffer, it would put a display property over the leading white spaces, where the text in the property corresponds to the correct indentation.

The rest of the time, (when non-persistent-formatting is nil), then it removes the display property on the leading white spaces, and modifies the line the normal way.

In this way, I can actually understand the file without causing chaos in the source repository.

I think that would be a killer feature.  That's my .02$.

Tom

unread,
Nov 14, 2012, 6:18:18 AM11/14/12
to help-gn...@gnu.org
S Boucher <stbya <at> yahoo.com> writes:

>
> instead of actually changing the buffer, it would put a display property
> over the leading white spaces, where the text in the property corresponds
> to the correct indentation.

If you know some elisp then it's not hard to create a simple solution for
this. The elisp would reindent the whole buffer for each new file it
encounters, but it would not save it, just check where the whitespace
at the beginning of lines differs from the original file and then revert
the reindentation and add the display properties as necessary.

It should cache this whitespace info for each file, so if the same file
is encountered then its indentation could be fixed quickly using the
cached information. Cache validity could be tested by comparing cache
date to the file modification and if the file changes then its cache
info would be updated.

It does not seem too dificult and I imagine lots of people woould find
it useful. It really does seem like a useful idea.


Tassilo Horn

unread,
Nov 14, 2012, 6:50:48 AM11/14/12
to help-gn...@gnu.org
Tom <adatg...@gmail.com> writes:

> It does not seem too dificult and I imagine lots of people woould find
> it useful. It really does seem like a useful idea.

It would only be useful if all developers in the project used emacs with
non-persistent indentation. Else, the people not using it would still
need to reindent the code to make any rhyme of it.

And then, of course the repository browsers (ViewCVS/SVN, Github, etc)
or more correctly, their source-to-html transformations, should also
display this synthetic indentation... IMHO, that sounds like a can of
worms. And of course, it wouldn't work for languages where whitespace
has semantics like python and haskell.

FWIW, org-mode does have some feature like that. You might want to have
a look.

,----[ C-h f org-indent-mode RET ]
| org-indent-mode is an interactive autoloaded Lisp function in `org-indent.el'.
|
| (org-indent-mode &optional ARG)
|
| When active, indent text according to outline structure.
|
| Internally this works by adding `line-prefix' and `wrap-prefix'
| properties, after each buffer modification, on the modified zone.
|
| The process is synchronous. Though, initial indentation of
| buffer, which can take a few seconds on large buffers, is done
| during idle time.
`----

Bye,
Tassilo


0 new messages