Skip to content

Commit 080483a

Browse files
authored
Merge pull request #26 from ffes/eol-on-save
Convert EOL when saving the file
2 parents a36e9a2 + b599762 commit 080483a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/PluginDefinition.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ void onBeforeSave(HWND hWnd)
281281

282282
int trim_trailing_whitespace = NPPEC_BOOLVAL_UNSPECIFIED;
283283
int insert_final_newline = NPPEC_BOOLVAL_UNSPECIFIED;
284+
int end_of_line = 0;
284285

285286
int name_value_count = editorconfig_handle_get_name_value_count(eh);
286-
287287
for (int i = 0; i < name_value_count; ++i) {
288288
const char* name;
289289
const char* value;
@@ -307,6 +307,17 @@ void onBeforeSave(HWND hWnd)
307307
}
308308
continue;
309309
}
310+
311+
// Need to convert the end of lines?
312+
if (strcmp(name, "end_of_line") == 0) {
313+
if (strcmp(value, "lf") == 0)
314+
end_of_line = IDM_FORMAT_TOUNIX;
315+
else if (strcmp(value, "crlf") == 0)
316+
end_of_line = IDM_FORMAT_TODOS;
317+
else if (strcmp(value, "cr") == 0)
318+
end_of_line = IDM_FORMAT_TOMAC;
319+
continue;
320+
}
310321
}
311322

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

339+
if (end_of_line != 0) {
340+
SendMessage(hWnd, NPPM_MENUCOMMAND, 0, end_of_line);
341+
}
342+
328343
// Restore the folding behavior
329344
SendMessage(curScintilla, SCI_SETAUTOMATICFOLD, automatic_fold, 0);
330345

0 commit comments

Comments
 (0)