summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-11-02 19:58:20 -0400
committerpommicket <pommicket@gmail.com>2022-11-02 19:58:20 -0400
commit9d0433ba028792f5a468507dba28d406b9f758e7 (patch)
treef83f5db4b4d6e54ef70c252f624b108d40978ac6
parentb070e5ce01c829bd101b1e0eda49f1e25d9d125c (diff)
fixed path-specific settings bugs. stuff seems to be working now
-rw-r--r--buffer.c10
-rw-r--r--config.c14
-rw-r--r--ted.cfg10
-rw-r--r--ted.h2
-rw-r--r--ui.c4
-rw-r--r--util.c2
6 files changed, 26 insertions, 16 deletions
diff --git a/buffer.c b/buffer.c
index d7e3062..036398b 100644
--- a/buffer.c
+++ b/buffer.c
@@ -277,13 +277,15 @@ static long context_score(const char *path, Language lang, const SettingsContext
long score = 0;
if (lang == context->language) {
- score += 100000;
+ score += 10000;
}
if (context->path) {
- int i;
- for (i = 0; i < TED_PATH_MAX && path[i] == context->path[i]; ++i);
- score += i;
+ if (path && str_has_prefix(path, context->path)) {
+ score += (long)strlen(context->path);
+ } else {
+ score -= 100000;
+ }
}
return score;
diff --git a/config.c b/config.c
index bf17f54..ed77810 100644
--- a/config.c
+++ b/config.c
@@ -35,7 +35,7 @@ static bool context_is_parent(const SettingsContext *parent, const SettingsConte
if (parent->path) {
if (!child->path)
return false;
- if (!str_is_prefix(parent->path, child->path))
+ if (!str_has_prefix(child->path, parent->path))
return false;
}
return true;
@@ -74,21 +74,21 @@ static u32 config_parse_key_combo(ConfigReader *cfg, char const *str) {
u32 modifier = 0;
// read modifier
while (true) {
- if (str_is_prefix(str, "Ctrl+")) {
+ if (str_has_prefix(str, "Ctrl+")) {
if (modifier & KEY_MODIFIER_CTRL) {
config_err(cfg, "Ctrl+ written twice");
return 0;
}
modifier |= KEY_MODIFIER_CTRL;
str += strlen("Ctrl+");
- } else if (str_is_prefix(str, "Shift+")) {
+ } else if (str_has_prefix(str, "Shift+")) {
if (modifier & KEY_MODIFIER_SHIFT) {
config_err(cfg, "Shift+ written twice");
return 0;
}
modifier |= KEY_MODIFIER_SHIFT;
str += strlen("Shift+");
- } else if (str_is_prefix(str, "Alt+")) {
+ } else if (str_has_prefix(str, "Alt+")) {
if (modifier & KEY_MODIFIER_ALT) {
config_err(cfg, "Alt+ written twice");
return 0;
@@ -548,7 +548,7 @@ static void config_parse_line(ConfigReader *cfg, Settings *settings, const Confi
// lines like Ctrl+Down = 10 :down
u32 key_combo = config_parse_key_combo(cfg, key);
KeyAction *action = &settings->key_actions[key_combo];
- llong argument = 1;
+ llong argument = 1; // default argument = 1
if (isdigit(*value)) {
// read the argument
char *endp;
@@ -733,7 +733,7 @@ void config_parse(Ted *ted, ConfigPart **pparts) {
--parent;
if (context_is_parent(&parent->context, &part->context)) {
// copy parent's settings
- settings_copy(settings, parent->settings);
+ settings_copy(settings, &ted->all_settings[parent->settings]);
break;
}
}
@@ -741,7 +741,7 @@ void config_parse(Ted *ted, ConfigPart **pparts) {
context_free(&settings->context);
context_copy(&settings->context, &part->context);
}
- part->settings = settings;
+ part->settings = arr_len(ted->all_settings) - 1;
arr_add(part->text, '\0'); // null termination
diff --git a/ted.cfg b/ted.cfg
index 388d644..eef8098 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -234,7 +234,7 @@ Python = .py
Tex = .tex
Markdown = .md
HTML = .html, .php, .xml, .xhtml, .iml
-Config = .cfg
+Config = .cfg, .toml
Javascript = .js
Java = .java
Go = .go
@@ -242,3 +242,11 @@ Go = .go
# You can add language-specific settings like this:
# [HTML.core]
# tab-width = 2
+
+# Or path-specific settings like this:
+# [/path/to/special/project//colors]
+# keyword = #f0f
+
+# Or both!
+# [/path/to/special/project//Javascript.keyboard]
+# Ctrl+J = "function() {" :insert-text
diff --git a/ted.h b/ted.h
index c014103..9f49fdd 100644
--- a/ted.h
+++ b/ted.h
@@ -196,7 +196,7 @@ typedef struct {
char *file;
u32 line;
char *text;
- Settings *settings; // only used in config_parse
+ u32 settings; // index into ted->all_settings. only used in config_parse
} ConfigPart;
// this refers to replacing prev_len characters (found in prev_text) at pos with new_len characters
diff --git a/ui.c b/ui.c
index 72c5ca2..583962e 100644
--- a/ui.c
+++ b/ui.c
@@ -197,8 +197,8 @@ static int qsort_file_entry_cmp(void *search_termv, void const *av, void const *
return +1;
}
if (search_term) {
- bool a_prefix = str_is_prefix(a->name, search_term);
- bool b_prefix = str_is_prefix(b->name, search_term);
+ bool a_prefix = str_has_prefix(a->name, search_term);
+ bool b_prefix = str_has_prefix(b->name, search_term);
if (a_prefix && !b_prefix) {
return -1;
}
diff --git a/util.c b/util.c
index b36bcd4..57b54da 100644
--- a/util.c
+++ b/util.c
@@ -61,7 +61,7 @@ static char32_t const *util_mem32chr_const(char32_t const *s, char32_t c, size_t
return NULL;
}
-static bool str_is_prefix(char const *str, char const *prefix) {
+static bool str_has_prefix(char const *str, char const *prefix) {
return strncmp(str, prefix, strlen(prefix)) == 0;
}