Preserve empty lines when cleaning files. #128

wants to merge 6 commits into

3 participants


This was originally submitted for this feature request but I figured a pull request was easier.

More details can be found at that ticket but basically to provides both a global and per-project setting to ignore empty lines when cleaning trailing spaces. This is because many people prefer their line breaks to be indented at the same level as the code around it.

So this is a rebased-onto-master version of the original patch, it adds GUI controls in both the global and per-project dialogs and defaults to current default behavior.

Geany member

Unfortunately this appears to have impacts on other uses of editor_strip_line_trailing_spaces() such as reflow lines.

Please re-factor so it only impacts the use when saving files.


Am I correct in assuming that I can't add an argument to that function?


Don't worry about that, it would be ugly anyway.

Geany member

Okay, I thought about it more and that seems like the best strategy.

Geany member

Just be sure that all callers semantics are preserved, except in the specific case you want to change. This may involve passing the option up further, but I haven't checked.


Okay, some of the uses I was a little unclear whether they should be affected by the preference.

  • For "clean on newline" I left it with the old behavior.
  • For the code refactoring functions I left it with the old style.
  • For "clean on save" both actually on save and when setting the preference I obey the "preserve empty" preference.

These made the most sense to me but could be changed.


Sorry to be a bother but what is preventing this from getting merged?

Geany member

Time, manpower and that it touches core C code :)

Will try to review and test soon.

@b4n b4n commented on an outdated diff Aug 15, 2013
@@ -1254,7 +1254,10 @@ static void on_new_line_added(GeanyEditor *editor)
if (editor_prefs.newline_strip)
{ /* strip the trailing spaces on the previous line */
- editor_strip_line_trailing_spaces(editor, line - 1);
Geany member
b4n added a line comment Aug 15, 2013

no blank line at start of blocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
kevincox added some commits Mar 16, 2013
@kevincox kevincox Added support for not cleaning empty lines.
See #3608223.

editor_strip_line_trailing_spaces() now skips empty lines if the
strip_preserve_empty pref is set.
@kevincox kevincox Added strip_preserve_empty pref.
See #3608223
 - Global setting option.
 - Per-project setting with global fallback.
 - UI element in global and project prefrences dialogs.
@kevincox kevincox Documented option to preserve empty lines. 52aec83
@kevincox kevincox Changed how empty lines are preserved.
Now they are only preserved with regards to the "clean on save" feature.
@kevincox kevincox Made reflow_lines use strip_preserve_empty pref. 3b002c2
@kevincox kevincox Removed blank line. 48a4cc1

Fixed that line and rebased on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment