code icon indicating copy to clipboard operation
code copied to clipboard

Move strip trailing whitespace into main code; remove plugin

Open jeremypw opened this issue 4 years ago • 13 comments

Fixes #1098

A hopefully minor behavior change is that stripping (and saving) now occurs whenever the document loses focus as well as on manual saving.

Stripping does not occur on every autosave as it could interfere unacceptably with ongoing editing.

An issue raised by this is what to do about the already installed plugin - this PR overwrites it so that it does not appear in the Extensions dialog. Alternative solutions welcome.

I guess that once the app is supplied only as a Flatpak this will not be an issue and the plugin overwriting code can be removed.

jeremypw avatar Dec 08 '21 18:12 jeremypw

Bug found - converting to draft while fixing.

jeremypw avatar Dec 13 '21 16:12 jeremypw

Reduced scope of PR so that current behaviour (strip only on manual save or close) is unaffected. Stripping on autosave would be easy to add later if required.

jeremypw avatar Aug 11 '22 13:08 jeremypw

The problem with CI appears unrelated to this PR - it compiles OK locally.

jeremypw avatar Aug 11 '22 13:08 jeremypw

A possible refinement is to have the "strip trailing whiltespace" functionality independent of saving so that it occurs even if "autosave" is off.

jeremypw avatar Aug 20 '22 17:08 jeremypw

Hmmm how would that look separated from saving? Remove the trailing white space when a user starts a new line?

zeebok avatar Aug 21 '22 02:08 zeebok

No, I found it too intrusive for stripping to occur immediately after leaving a line. For example, I like to insert a blank line and the closing brace of an if () {} clause then go back and fill in the body of the clause - I do not want the indenting spaces to be removed at that point. The stripping would still occur when losing focus - e.g. switching to another document or a terminal even if the document is not autosaving. At the moment with master I have to consciously press <Ctrl>S on each document before running vala-lint.

jeremypw avatar Aug 21 '22 09:08 jeremypw

Gotcha. Do you think that might not do it often enough? If I write a quick fix, or just code for a short time, in a single doc and close Code it sounds like it wouldn't strip. Not a frequent scenario but one I can picture happening.

zeebok avatar Aug 22 '22 02:08 zeebok

I think #1188 might be relevant here - this could also ensure stripping occurs.

jeremypw avatar Aug 22 '22 07:08 jeremypw

Yeah that seems good. Personally the more places it checks and does the stripping without interfering the better so it ensures a consistent experience. Losing focus, on saves, etc are all good places to me.

zeebok avatar Aug 22 '22 16:08 zeebok

@zeebok Is it OK to merge this PR (which should behave pretty much the same as master, without regressions) and make changes to behaviour in future PRs?

jeremypw avatar Aug 22 '22 16:08 jeremypw

An issue raised by this is what to do about the already installed plugin - this PR overwrites it so that it does not appear in the Extensions dialog. Alternative solutions welcome.

I think this should be handled from the package side, for source installations, we should recommend doing an sudo ninja uninstall before a new ninja install, so that old plugins get removed.

For the deb package, aren't plugins installed in the same package? so when an update occurs, they all got removed and only the ones in the new build installed?

the flatpak package aren't affected by this.

Marukesu avatar Aug 31 '22 21:08 Marukesu

@Marukesu I didn't realise Code has an uninstall ninja target - not all projects (e.g. Files) have one. In that case, and in view of the fact that Flatpaks are unaffected I will remove the relevant code from this PR. I am uncertain whether just updating a deb will remove old plugins though.

jeremypw avatar Sep 01 '22 07:09 jeremypw

Yeah the Deb package will cleanup old installed files like plugins so this only affects source installs

danirabbit avatar Sep 01 '22 21:09 danirabbit