Nameless icon indicating copy to clipboard operation
Nameless copied to clipboard

"Smart-fix" indentation?

Open alphapapa opened this issue 8 years ago • 8 comments

Hi Artur,

Thanks a lot for making Nameless, it makes working with packages so much nicer.

I haven't used it for very long, and I just realized today that it can affect indentation when I looked at a commit on GitHub instead of in Emacs.

Would it be possible to have the indentation swap between "affected" and "unaffected" in a save-hook? I guess it might cause a flicker in the buffer, but it seems like it shouldn't be too hard to 1) disable the mode, 2) save the file, 3) reenable the mode with indentation "affected."

That way the indentation would appear correct both inside Emacs with Nameless turned on, and outside Emacs in the plain file. :)

alphapapa avatar Mar 18 '17 01:03 alphapapa

I've just discovered nameless has an impact on indentation and I find that really weird. What if my colleague doesn't want nameless? I don't want indentation to change at each commit. Fortunately, the variable nameless-affect-indentation-and-filling is here to help.

DamienCassou avatar Apr 03 '17 20:04 DamienCassou

After having used nameless with nil for nameless-affect-indentation-and-filling for some time, I have to admit I don't really like it either: the indentation is really weird. I would like to see if @alphapapa suggestion would work in practice.

DamienCassou avatar May 10 '17 07:05 DamienCassou

After posting this I did some more testing/thinking, and I realized that the problem is adjusting the indentation without changing the buffer's modification status. But I see now that there are set-buffer-modified-p and restore-buffer-modified-p, so maybe this is possible after all.

...

It seems to work! Here's a branch: https://github.com/alphapapa/Nameless/tree/save-hooks

alphapapa avatar May 10 '17 17:05 alphapapa

Updated the branch again. Now reindents the buffer when toggling the mode, if the indentation option is enabled. Seems to work seamlessly (...), but wider testing is needed. :)

alphapapa avatar May 11 '17 22:05 alphapapa

I activated your branch in my configuration (plus set nameless-affect-indentation-and-filling back to outside-string) and will report if I see something weird. Thanks for your work.

DamienCassou avatar May 12 '17 08:05 DamienCassou

I noticed the code in your branch modifies not well-indented files. Also, it makes opening files slower. For example, open simple.el or simple.el.gz.

DamienCassou avatar May 12 '17 12:05 DamienCassou

In the *Messages* buffer, I can see:

uncompressing simple.el.gz...done
Indenting region...done
Indenting region...done
Indenting region...done
Indenting region...done

I understand the slow-down better if indentation happens 4 times :-).

DamienCassou avatar May 12 '17 12:05 DamienCassou

Hm, not sure why it would indent 4 times for opening the file once. But I consider this a proof-of-concept, so it surely needs some polishing. :)

Yeah, I set it to reindent the whole buffer if nameless is set to adjust indentation. I usually use aggressive-indent-mode anyway. I guess something more complicated could be done to reindent only parts of the buffer changed by nameless.

alphapapa avatar May 12 '17 20:05 alphapapa