aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.c19
-rw-r--r--config.h1
-rw-r--r--doc/foot.ini.5.scd4
-rw-r--r--foot.ini1
-rw-r--r--misc.c17
-rw-r--r--misc.h2
-rw-r--r--search.c3
-rw-r--r--selection.c9
8 files changed, 36 insertions, 20 deletions
diff --git a/config.c b/config.c
index 3ebb0cae..c25c001a 100644
--- a/config.c
+++ b/config.c
@@ -570,6 +570,21 @@ parse_section_main(const char *key, const char *value, struct config *conf,
conf->render_worker_count = count;
}
+ else if (strcmp(key, "word-delimiters") == 0) {
+ size_t chars = mbstowcs(NULL, value, 0);
+ if (chars == (size_t)-1) {
+ LOG_AND_NOTIFY_ERR(
+ "%s:%d: [default]: word-delimiters: invalid string: %s",
+ path, lineno, value);
+ return false;
+ }
+
+ free(conf->word_delimiters);
+
+ conf->word_delimiters = xmalloc((chars + 1) * sizeof(wchar_t));
+ mbstowcs(conf->word_delimiters, value, chars + 1);
+ }
+
else if (strcmp(key, "scrollback") == 0) {
LOG_WARN("deprecated: %s:%d: [default]: scrollback: use 'scrollback.lines' instead'", path, lineno);
@@ -648,7 +663,7 @@ parse_section_scrollback(const char *key, const char *value, struct config *conf
}
conf->scrollback.indicator.text = xcalloc(len + 1, sizeof(wchar_t));
- mbstowcs(conf->scrollback.indicator.text, value, len);
+ mbstowcs(conf->scrollback.indicator.text, value, len + 1);
}
}
@@ -1872,6 +1887,7 @@ config_load(struct config *conf, const char *conf_path,
.shell = get_shell(),
.title = xstrdup("foot"),
.app_id = xstrdup("foot"),
+ .word_delimiters = xwcsdup(L",│`|:\"'()[]{}<>"),
.size = {
.type = CONF_SIZE_PX,
.px = {
@@ -2024,6 +2040,7 @@ config_free(struct config conf)
free(conf.shell);
free(conf.title);
free(conf.app_id);
+ free(conf.word_delimiters);
free(conf.scrollback.indicator.text);
tll_foreach(conf.fonts, it)
config_font_destroy(&it->item);
diff --git a/config.h b/config.h
index 58b6f8a7..8e129329 100644
--- a/config.h
+++ b/config.h
@@ -53,6 +53,7 @@ struct config {
char *shell;
char *title;
char *app_id;
+ wchar_t *word_delimiters;
bool login_shell;
struct {
diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd
index 496162e8..4b10d6d2 100644
--- a/doc/foot.ini.5.scd
+++ b/doc/foot.ini.5.scd
@@ -110,6 +110,10 @@ in this order:
Default: _none_.
+*word-delimiters*
+ String of characters that act as word delimiters when selecting
+ text. Default: _,│`|:"'()[]{}<>_
+
# SECTION: scrollback
diff --git a/foot.ini b/foot.ini
index fea2f2b8..a291f867 100644
--- a/foot.ini
+++ b/foot.ini
@@ -10,6 +10,7 @@
# login-shell=no
# workers=<number of logical CPUs>
# bell=none
+# word-delimiters=,│`|:"'()[]{}<>
[scrollback]
# lines=1000
diff --git a/misc.c b/misc.c
index b8eb3296..feb5e73b 100644
--- a/misc.c
+++ b/misc.c
@@ -3,22 +3,13 @@
#include <wctype.h>
bool
-isword(wchar_t wc, bool spaces_only)
+isword(wchar_t wc, bool spaces_only, const wchar_t *delimiters)
{
if (spaces_only)
return iswgraph(wc);
- switch (wc) {
- default: return iswgraph(wc);
-
- case L'(': case L')':
- case L'[': case L']':
- case L'{': case L'}':
- case L'<': case L'>':
- case L'│': case L'|':
- case L',':
- case L'`': case L'"': case L'\'':
- case L':':
+ if (wcschr(delimiters, wc) != NULL)
return false;
- }
+
+ return iswgraph(wc);
}
diff --git a/misc.h b/misc.h
index 06dd3303..3c897336 100644
--- a/misc.h
+++ b/misc.h
@@ -3,4 +3,4 @@
#include <stdbool.h>
#include <wchar.h>
-bool isword(wchar_t wc, bool spaces_only);
+bool isword(wchar_t wc, bool spaces_only, const wchar_t *delimiters);
diff --git a/search.c b/search.c
index 551d21ba..0f1b4610 100644
--- a/search.c
+++ b/search.c
@@ -10,6 +10,7 @@
#define LOG_MODULE "search"
#define LOG_ENABLE_DBG 0
#include "log.h"
+#include "config.h"
#include "grid.h"
#include "input.h"
#include "misc.h"
@@ -368,7 +369,7 @@ search_match_to_end_of_word(struct terminal *term, bool spaces_only)
bool done = false;
for (; end_col < term->cols; end_col++) {
wchar_t wc = row->cells[end_col].wc;
- if (wc == 0 || (!first && !isword(wc, spaces_only))) {
+ if (wc == 0 || (!first && !isword(wc, spaces_only, term->conf->word_delimiters))) {
done = true;
break;
}
diff --git a/selection.c b/selection.c
index 6cfacc02..2a2e8034 100644
--- a/selection.c
+++ b/selection.c
@@ -15,6 +15,7 @@
#include "log.h"
#include "async.h"
+#include "config.h"
#include "extract.h"
#include "grid.h"
#include "misc.h"
@@ -725,7 +726,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
const struct row *r = grid_row_in_view(term->grid, start.row);
wchar_t c = r->cells[start.col].wc;
- if (!(c == 0 || !isword(c, spaces_only))) {
+ if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) {
while (true) {
int next_col = start.col - 1;
int next_row = start.row;
@@ -740,7 +741,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
const struct row *row = grid_row_in_view(term->grid, next_row);
c = row->cells[next_col].wc;
- if (c == 0 || !isword(c, spaces_only))
+ if (c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))
break;
start.col = next_col;
@@ -751,7 +752,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
r = grid_row_in_view(term->grid, end.row);
c = r->cells[end.col].wc;
- if (!(c == 0 || !isword(c, spaces_only))) {
+ if (!(c == 0 || !isword(c, spaces_only, term->conf->word_delimiters))) {
while (true) {
int next_col = end.col + 1;
int next_row = end.row;
@@ -766,7 +767,7 @@ selection_mark_word(struct seat *seat, struct terminal *term, int col, int row,
const struct row *row = grid_row_in_view(term->grid, next_row);
c = row->cells[next_col].wc;
- if (c == '\0' || !isword(c, spaces_only))
+ if (c == '\0' || !isword(c, spaces_only, term->conf->word_delimiters))
break;
end.col = next_col;