summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-11 22:59:03 -0500
committerpommicket <pommicket@gmail.com>2023-01-11 22:59:03 -0500
commit0c102146685ad0707ddb7e2f8ea1166782c1e76d (patch)
tree6576a100d629de66a117eb60b547f17e800969c4
parentb01c7b595cabce4704b6e5e6ead61bdebdedc923 (diff)
build-command setting + a bunch of config fixes
- now we only show the first config error - path matching is now ranked more highly than language matching - paths with forward slashes are now handled for Windows path-specific settings
-rw-r--r--build.c37
-rw-r--r--config.c17
-rw-r--r--ted.cfg6
-rw-r--r--ted.h3
4 files changed, 43 insertions, 20 deletions
diff --git a/build.c b/build.c
index dc15144..0311b09 100644
--- a/build.c
+++ b/build.c
@@ -86,26 +86,29 @@ void build_start_with_command(Ted *ted, const char *command) {
void build_start(Ted *ted) {
Settings *settings = ted_active_settings(ted);
- char *command = settings->build_default_command;
+ char *command = settings->build_command;
char *root = ted_get_root_dir(ted);
strbuf_cpy(ted->build_dir, root);
- change_directory(root);
- free(root);
-
-#if _WIN32
- if (fs_file_exists("make.bat")) {
- command = "make.bat";
- } else
-#endif
- if (fs_file_exists("Cargo.toml")) {
- command = "cargo build";
- } else if (fs_file_exists("Makefile")) {
- command = "make -j12";
- } else if (fs_file_exists("go.mod")) {
- command = "go build";
- }
+ if (*command == 0) {
+ command = settings->build_default_command;
+ change_directory(root);
- build_start_with_command(ted, command);
+ #if _WIN32
+ if (fs_file_exists("make.bat")) {
+ command = "make.bat";
+ } else
+ #endif
+ if (fs_file_exists("Cargo.toml")) {
+ command = "cargo build";
+ } else if (fs_file_exists("Makefile")) {
+ command = "make -j16";
+ } else if (fs_file_exists("go.mod")) {
+ command = "go build";
+ }
+ }
+ free(root);
+ if (*command)
+ build_start_with_command(ted, command);
}
static void build_go_to_error(Ted *ted) {
diff --git a/config.c b/config.c
index b8f0f17..390f1ac 100644
--- a/config.c
+++ b/config.c
@@ -117,6 +117,7 @@ static SettingFloat const settings_float[] = {
};
static SettingString const settings_string[] = {
{"build-default-command", settings_zero.build_default_command, sizeof settings_zero.build_default_command, true},
+ {"build-command", settings_zero.build_command, sizeof settings_zero.build_command, true},
{"bg-shader", settings_zero.bg_shader_text, sizeof settings_zero.bg_shader_text, true},
{"bg-texture", settings_zero.bg_shader_image, sizeof settings_zero.bg_shader_image, true},
{"root-identifiers", settings_zero.root_identifiers, sizeof settings_zero.root_identifiers, true},
@@ -159,6 +160,8 @@ typedef struct {
static void config_err(ConfigReader *cfg, PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
static void config_err(ConfigReader *cfg, const char *fmt, ...) {
+ if (cfg->error) return;
+ cfg->error = true;
char error[1024] = {0};
strbuf_printf(error, "%s:%u: ", cfg->filename, cfg->line_number);
va_list args;
@@ -177,9 +180,13 @@ static void context_copy(SettingsContext *dest, const SettingsContext *src) {
long context_score(const char *path, Language lang, const SettingsContext *context) {
long score = 0;
+ // currently contexts are ranked by:
+ // 1. path matching, the more specific the better
+ // 2. language
+
if (context->language) {
if (lang == context->language) {
- score += 10000;
+ score += 1;
} else {
// dont use this. it's language-specific and for the wrong language.
return INT_MIN;
@@ -188,7 +195,7 @@ long context_score(const char *path, Language lang, const SettingsContext *conte
if (context->path) {
if (path && str_has_path_prefix(path, context->path)) {
- score += (long)strlen(context->path);
+ score += 2 * (long)strlen(context->path);
} else {
// dont use this. it's path-specific and for the wrong path.
return INT_MIN;
@@ -335,6 +342,12 @@ static void parse_section_header(ConfigReader *cfg, char *line, ConfigPart *part
--path_len;
}
strn_cat(path, sizeof path, section, path_len);
+ #if _WIN32
+ // replace forward slashes with backslashes
+ for (char *p = path; *p; ++p)
+ if (*p == '/')
+ *p = '\\';
+ #endif
part->context.path = str_dup(path);
section = path_end + 2;
}
diff --git a/ted.cfg b/ted.cfg
index a2aef7a..df3e05b 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -26,7 +26,13 @@ line-numbers = on
auto-reload = on
# automatically reload config when saved
auto-reload-config = on
+# default build command to use if Cargo.toml/Makefile/etc. is not found
build-default-command = make
+# if this is non-empty, it will be used as the build command, even if Cargo.toml/Makefile/etc. exists.
+# very useful with path-specific settings, e.g. use
+# [/my/fav/project//core]
+# build-command = "supermake --treble-clef -rxvt"
+build-command = ""
# restore previously opened files when ted is launched?
restore-session = on
# show autocomplete menu when a trigger character (e.g. '.') is typed (LSP only)
diff --git a/ted.h b/ted.h
index f6e8ae4..76058af 100644
--- a/ted.h
+++ b/ted.h
@@ -147,7 +147,8 @@ typedef struct {
char root_identifiers[4096];
char lsp[512];
char lsp_configuration[4096];
- char build_default_command[256];
+ char build_command[1024];
+ char build_default_command[1024];
// [i] = comma-separated string of file extensions for language i, or NULL for none
char *language_extensions[LANG_COUNT];
KeyAction *key_actions; // dynamic array, sorted by KEY_COMBO(modifier, key)