Skip to content

Commit

Permalink
Merge pull request #26 from ffes/eol-on-save
Browse files Browse the repository at this point in the history
Convert EOL when saving the file
  • Loading branch information
ffes committed Feb 20, 2019
2 parents a36e9a2 + b599762 commit 080483a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ void onBeforeSave(HWND hWnd)

int trim_trailing_whitespace = NPPEC_BOOLVAL_UNSPECIFIED;
int insert_final_newline = NPPEC_BOOLVAL_UNSPECIFIED;
int end_of_line = 0;

int name_value_count = editorconfig_handle_get_name_value_count(eh);

for (int i = 0; i < name_value_count; ++i) {
const char* name;
const char* value;
Expand All @@ -307,6 +307,17 @@ void onBeforeSave(HWND hWnd)
}
continue;
}

// Need to convert the end of lines?
if (strcmp(name, "end_of_line") == 0) {
if (strcmp(value, "lf") == 0)
end_of_line = IDM_FORMAT_TOUNIX;
else if (strcmp(value, "crlf") == 0)
end_of_line = IDM_FORMAT_TODOS;
else if (strcmp(value, "cr") == 0)
end_of_line = IDM_FORMAT_TOMAC;
continue;
}
}

// Save the folding behavior and set it to 0 to keep folds from opening
Expand All @@ -325,6 +336,10 @@ void onBeforeSave(HWND hWnd)
insertFinalNewline(insert_final_newline == NPPEC_BOOLVAL_TRUE);
}

if (end_of_line != 0) {
SendMessage(hWnd, NPPM_MENUCOMMAND, 0, end_of_line);
}

// Restore the folding behavior
SendMessage(curScintilla, SCI_SETAUTOMATICFOLD, automatic_fold, 0);

Expand Down

0 comments on commit 080483a

Please sign in to comment.