Skip to content

Commit

Permalink
Better fix for previous commit. Also refactor avoiding some indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jackburton79 committed Dec 11, 2024
1 parent 64b89ba commit f5881d8
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions src/ui/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,60 +840,63 @@ Editor::LoadEditorConfig()
fEditorConfig.TrimTrailingWhitespace = (bool)gCFG["trim_trailing_whitespace"];
fHasEditorConfig = false;

if (!(bool)gCFG["ignore_editorconfig"]) {
// start parsing
// Ignore full path error, whose error code is EDITORCONFIG_PARSE_NOT_FULL_PATH
editorconfig_handle handle = editorconfig_handle_init();
int errNum;
if ((errNum = editorconfig_parse(FilePath().String(), handle)) != 0 &&
errNum != EDITORCONFIG_PARSE_NOT_FULL_PATH) {
editorconfig_handle_destroy(handle);
LogError("Can't load .editorconfig with error %d", editorconfig_get_error_msg(errNum));
} else {
int32 nameValueCount = editorconfig_handle_get_name_value_count(handle);
if (nameValueCount != 0)
fHasEditorConfig = true;

/* get settings */
// Defaults. TODO: This avoids the compiler error
// but maybe the code should be refactored
int32 tabWidth = 4;
for (int32 i = 0; i < nameValueCount; ++i) {
const char* name;
const char* value;
editorconfig_handle_get_name_value(handle, i, &name, &value);

if (!strcmp(name, "indent_style")) {
fEditorConfig.IndentStyle = !strcmp(value, "space") ? IndentStyle::Space : IndentStyle::Tab;
} else if (!strcmp(name, "tab_width")) {
if (strcmp(value, "undefine"))
tabWidth = atoi(value);
} else if (!strcmp(name, "indent_size")) {
if (strcmp(value, "undefine")) {
int valueInt = atoi(value);
if (!strcmp(value, "tab"))
fEditorConfig.IndentSize = tabWidth;
else if (valueInt > 0)
fEditorConfig.IndentSize = valueInt;
}
} else if (!strcmp(name, "end_of_line")) {
if (strcmp(value, "undefine")) {
if (!strcmp(value, "lf"))
fEditorConfig.EndOfLine = SC_EOL_LF;
else if (!strcmp(value, "cr"))
fEditorConfig.EndOfLine = SC_EOL_CR;
else if (!strcmp(value, "crlf"))
fEditorConfig.EndOfLine = SC_EOL_CRLF;
}
} else if (!strcmp(name, "trim_trailing_whitespace")) {
if (strcmp(value, "undefine"))
fEditorConfig.TrimTrailingWhitespace = !strcmp(value, "true") ? true : false;
} else if (!strcmp(name, "insert_final_newline"))
fEditorConfig.InsertFinalNewline = !strcmp(value, "true") ? true : false;
}
if ((bool)gCFG["ignore_editorconfig"])
return;

// start parsing
// Ignore full path error, whose error code is EDITORCONFIG_PARSE_NOT_FULL_PATH
editorconfig_handle handle = editorconfig_handle_init();
if (handle == nullptr)
return;

int errNum;
if ((errNum = editorconfig_parse(FilePath().String(), handle)) != 0 &&
errNum != EDITORCONFIG_PARSE_NOT_FULL_PATH) {
LogError("Can't load .editorconfig with error %d", editorconfig_get_error_msg(errNum));
} else {
int32 nameValueCount = editorconfig_handle_get_name_value_count(handle);
if (nameValueCount != 0)
fHasEditorConfig = true;

/* get settings */
// Defaults. TODO: This avoids the compiler error
// but maybe the code should be refactored
int32 tabWidth = 4;
for (int32 i = 0; i < nameValueCount; ++i) {
const char* name;
const char* value;
editorconfig_handle_get_name_value(handle, i, &name, &value);

if (!strcmp(name, "indent_style")) {
fEditorConfig.IndentStyle = !strcmp(value, "space") ? IndentStyle::Space : IndentStyle::Tab;
} else if (!strcmp(name, "tab_width")) {
if (strcmp(value, "undefine"))
tabWidth = atoi(value);
} else if (!strcmp(name, "indent_size")) {
if (strcmp(value, "undefine")) {
int valueInt = atoi(value);
if (!strcmp(value, "tab"))
fEditorConfig.IndentSize = tabWidth;
else if (valueInt > 0)
fEditorConfig.IndentSize = valueInt;
}
} else if (!strcmp(name, "end_of_line")) {
if (strcmp(value, "undefine")) {
if (!strcmp(value, "lf"))
fEditorConfig.EndOfLine = SC_EOL_LF;
else if (!strcmp(value, "cr"))
fEditorConfig.EndOfLine = SC_EOL_CR;
else if (!strcmp(value, "crlf"))
fEditorConfig.EndOfLine = SC_EOL_CRLF;
}
} else if (!strcmp(name, "trim_trailing_whitespace")) {
if (strcmp(value, "undefine"))
fEditorConfig.TrimTrailingWhitespace = !strcmp(value, "true") ? true : false;
} else if (!strcmp(name, "insert_final_newline"))
fEditorConfig.InsertFinalNewline = !strcmp(value, "true") ? true : false;
}
editorconfig_handle_destroy(handle);
}
editorconfig_handle_destroy(handle);
}


Expand Down

0 comments on commit f5881d8

Please sign in to comment.