* C/C++ mode feature I badly want... (non-persistent indentation)
@ 2012-11-13 23:32 S Boucher
2012-11-14 11:18 ` Tom
0 siblings, 1 reply; 3+ messages in thread
From: S Boucher @ 2012-11-13 23:32 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
[-- Attachment #1: Type: text/plain, Size: 924 bytes --]
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$.
[-- Attachment #2: Type: text/html, Size: 1133 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: C/C++ mode feature I badly want... (non-persistent indentation)
2012-11-13 23:32 C/C++ mode feature I badly want... (non-persistent indentation) S Boucher
@ 2012-11-14 11:18 ` Tom
2012-11-14 11:50 ` Tassilo Horn
0 siblings, 1 reply; 3+ messages in thread
From: Tom @ 2012-11-14 11:18 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: C/C++ mode feature I badly want... (non-persistent indentation)
2012-11-14 11:18 ` Tom
@ 2012-11-14 11:50 ` Tassilo Horn
0 siblings, 0 replies; 3+ messages in thread
From: Tassilo Horn @ 2012-11-14 11:50 UTC (permalink / raw)
To: help-gnu-emacs
Tom <adatgyujto@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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-14 11:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-13 23:32 C/C++ mode feature I badly want... (non-persistent indentation) S Boucher
2012-11-14 11:18 ` Tom
2012-11-14 11:50 ` Tassilo Horn
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).