From e76d8dd7af0cd7b6b2e1b5ed9c395bd75f503e61 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 30 Jan 2025 11:58:52 +0100 Subject: config: remove url.{uri-characters,protocols} --- doc/foot.ini.5.scd | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 903d3375..813348c9 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -782,19 +782,6 @@ xdgtoken=95ebdfe56e4f47ddb5bba9d7dc3a2c35 Default: _sadfjklewcmpgh_. -*protocols* - Comma separated list of protocols (schemes) that should be - recognized in URL mode. Note that only auto-detected URLs are - affected by this option. OSC-8 URLs are always enabled, regardless - of protocol. Default: _http, https, ftp, ftps, file, gemini, - gopher, irc, ircs_. - -*uri-characters* - Set of characters allowed in auto-detected URLs. Any character not - included in this set constitutes a URL delimiter. - - Default: - _abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-\_.,~:;/?#@!$&%\*+="'()[]_ # SECTION: cursor -- cgit v1.3 From d41b28bd027affe67bfd8032a2041241df8be823 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 30 Jan 2025 12:26:23 +0100 Subject: url-mode+config: wip: add url.regex option --- config.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ config.h | 6 +++++- doc/foot.ini.5.scd | 5 +++++ foot.ini | 2 ++ url-mode.c | 57 ++++----------------------------------------------- 5 files changed, 76 insertions(+), 54 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index c96e7168..dd4300e3 100644 --- a/config.c +++ b/config.c @@ -1234,6 +1234,26 @@ parse_section_url(struct context *ctx) (int *)&conf->url.osc8_underline); } + else if (streq(key, "regex")) { + const char *regex = ctx->value; + regex_t preg; + + int r = regcomp(&preg, regex, REG_EXTENDED); + if (r != 0) { + char err_buf[128]; + regerror(r, &preg, err_buf, sizeof(err_buf)); + LOG_CONTEXTUAL_ERR("invalid regex: %s", err_buf); + return false; + } + + regfree(&conf->url.preg); + free(conf->url.regex); + + conf->url.regex = xstrdup(regex); + conf->url.preg = preg; + return true; + } + else { LOG_CONTEXTUAL_ERR("not a valid option: %s", key); return false; @@ -3241,6 +3261,42 @@ config_load(struct config *conf, const char *conf_path, tokenize_cmdline("--action ${action-name}=${action-label}", &conf->desktop_notifications.command_action_arg.argv.args); tokenize_cmdline("xdg-open ${url}", &conf->url.launch.argv.args); + { + /* + * Based on https://gist.github.com/gruber/249502, but modified: + * - Do not allow {} at all + * - Do allow matched [] + */ + const char *url_regex_string = + "(" + "[a-z][[:alnum:]-]+:" // protocol + "(" + "/{1,3}|[a-z0-9%]" // slashes (what's the OR part for?) + ")" + "|" + "www[:digit:]{0,3}[.]" + //"|" + //"[a-z0-9.\\-]+[.][a-z]{2,4}/" /* "looks like domain name followed by a slash" - remove? */ + ")" + "(" + "[^[:space:](){}<>]+" + "|" + "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" + "|" + "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" + ")+" + "(" + "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" + "|" + "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" + "|" + "[^]\\[[:space:]`!(){};:'\".,<>?«»“”‘’]" + ")" + ; + int r = regcomp(&conf->url.preg, url_regex_string, REG_EXTENDED); + xassert(r == 0); + conf->url.regex = xstrdup(url_regex_string); + } tll_foreach(*initial_user_notifications, it) { tll_push_back(conf->notifications, it->item); @@ -3476,6 +3532,8 @@ config_clone(const struct config *old) conf->url.label_letters = xc32dup(old->url.label_letters); spawn_template_clone(&conf->url.launch, &old->url.launch); + conf->url.regex = xstrdup(old->url.regex); + regcomp(&conf->url.preg, conf->url.regex, REG_EXTENDED); key_binding_list_clone(&conf->bindings.key, &old->bindings.key); key_binding_list_clone(&conf->bindings.search, &old->bindings.search); @@ -3556,6 +3614,8 @@ config_free(struct config *conf) free(conf->url.label_letters); spawn_template_free(&conf->url.launch); + regfree(&conf->url.preg); + free(conf->url.regex); free_key_binding_list(&conf->bindings.key); free_key_binding_list(&conf->bindings.search); diff --git a/config.h b/config.h index a7947d9d..ea0bd942 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,8 @@ #pragma once -#include +#include #include +#include #include #include @@ -219,6 +220,9 @@ struct config { OSC8_UNDERLINE_URL_MODE, OSC8_UNDERLINE_ALWAYS, } osc8_underline; + + char *regex; + regex_t preg; } url; struct { diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 813348c9..ddf5ce84 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -782,6 +782,11 @@ xdgtoken=95ebdfe56e4f47ddb5bba9d7dc3a2c35 Default: _sadfjklewcmpgh_. +*regex* + URL regex to use when auto-detecting URLs. The format is + "POSIX-Extended Regular Expressions". + + Default: _TODO_ # SECTION: cursor diff --git a/foot.ini b/foot.ini index 864c990c..ae0002d4 100644 --- a/foot.ini +++ b/foot.ini @@ -69,6 +69,8 @@ # launch=xdg-open ${url} # label-letters=sadfjklewcmpgh # osc8-underline=url-mode +# regex=TODO + [cursor] # style=block diff --git a/url-mode.c b/url-mode.c index 36dc0250..9ba07d14 100644 --- a/url-mode.c +++ b/url-mode.c @@ -380,54 +380,7 @@ regex_detected(const struct terminal *term, enum url_action action, url_list_t * } } - /* - * Based on https://gist.github.com/gruber/249502, but modified: - * - Do not allow {} at all - * - Do allow matched [] - */ - regex_t preg; - const char *regex_string = - "(" - "[a-z][[:alnum:]-]+:" // protocol - "(" - "/{1,3}|[a-z0-9%]" // slashes (what's the OR part for?) - ")" - "|" - "www[:digit:]{0,3}[.]" - "|" - "[a-z0-9.\\-]+[.][a-z]{2,4}/" - ")" - "(" - "[^[:space:](){}<>]+" - "|" - "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" - "|" - "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" - ")+" - "(" - "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" - "|" - "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" - "|" - "[^]\\[[:space:]`!(){};:'\".,<>?«»“”‘’]" - ")" - ; - - int r = regcomp(&preg, regex_string, REG_EXTENDED); - - if (r != 0) { - char err_buf[1024]; - regerror(r, &preg, err_buf, sizeof(err_buf)); - LOG_ERR("failed to compile regular expression: %s", err_buf); - - for (size_t i = 0; i < ALEN(vlines); i++) { - const struct vline *v = &vlines[i]; - free(v->utf8); - free(v->map); - } - - return; - } + const regex_t *preg = &term->conf->url.preg; for (size_t i = 0; i < ALEN(vlines); i++) { const struct vline *v = &vlines[i]; @@ -436,9 +389,8 @@ regex_detected(const struct terminal *term, enum url_action action, url_list_t * const char *search_string = v->utf8; while (true) { - - regmatch_t matches[preg.re_nsub + 1]; - r = regexec(&preg, search_string, preg.re_nsub + 1, matches, 0); + regmatch_t matches[preg->re_nsub + 1]; + int r = regexec(preg, search_string, preg->re_nsub + 1, matches, 0); if (r == REG_NOMATCH) break; @@ -470,9 +422,8 @@ regex_detected(const struct terminal *term, enum url_action action, url_list_t * free(v->utf8); free(v->map); } - - regfree(&preg); } + static void osc8_uris(const struct terminal *term, enum url_action action, url_list_t *urls) { -- cgit v1.3 From 130b05f02baaebe533bb00cc2824ffb9902f11d3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 30 Jan 2025 12:33:58 +0100 Subject: foot.ini+doc: add default value of url.regex --- config.c | 1 + doc/foot.ini.5.scd | 2 +- foot.ini | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index dd4300e3..1f779724 100644 --- a/config.c +++ b/config.c @@ -1239,6 +1239,7 @@ parse_section_url(struct context *ctx) regex_t preg; int r = regcomp(&preg, regex, REG_EXTENDED); + if (r != 0) { char err_buf[128]; regerror(r, &preg, err_buf, sizeof(err_buf)); diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index ddf5ce84..a23e3977 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -786,7 +786,7 @@ xdgtoken=95ebdfe56e4f47ddb5bba9d7dc3a2c35 URL regex to use when auto-detecting URLs. The format is "POSIX-Extended Regular Expressions". - Default: _TODO_ + Default: _([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’])_ # SECTION: cursor diff --git a/foot.ini b/foot.ini index ae0002d4..85f3c861 100644 --- a/foot.ini +++ b/foot.ini @@ -69,7 +69,8 @@ # launch=xdg-open ${url} # label-letters=sadfjklewcmpgh # osc8-underline=url-mode -# regex=TODO +# regex=([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’]) + [cursor] -- cgit v1.3 From 2f902c1f5b5cd3a0bcbc985865a533de58a2a655 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 3 Feb 2025 09:15:33 +0100 Subject: doc: foot.ini: document custom regular expressions --- doc/foot.ini.5.scd | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index a23e3977..af355d68 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -755,6 +755,9 @@ xdgtoken=95ebdfe56e4f47ddb5bba9d7dc3a2c35 # SECTION: url +Note that you can also add custom regular expressions, see the 'regex' +section. + *launch* Command to execute when opening URLs. _${url}_ will be replaced with the actual URL. Default: _xdg-open ${url}_. @@ -783,11 +786,40 @@ xdgtoken=95ebdfe56e4f47ddb5bba9d7dc3a2c35 Default: _sadfjklewcmpgh_. *regex* - URL regex to use when auto-detecting URLs. The format is + + Regular expression to use when auto-detecting URLs. The format is "POSIX-Extended Regular Expressions". Default: _([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’])_ +# SECTION: regex + +Similar to the 'url' mode, but with custom defined regular expressions +(and launchers). + +To use a custom defined regular expression, you also need to add a key +binding for it. This is done in the *key-binding* section, see below +for details. In short, you need to: + +``` +[regex:foo] +regex=foo(bar)? +launch=path-to-script-or-application {match} + +[key-bindings] +regex-launch=[foo] Control+Shift+q +regex-copy=[foo] Control+Mod1+Shift+q +``` + +*launch* + Command to execute when "launching" a regex match. _${match}_ will + be replaced with the actual URL. Default: _not set_. + +*regex* + Regular expression to use when matching text. The format is + "POSIX-Extended Regular Expressions". Default: _not set_. + + # SECTION: cursor This section controls the cursor style and color. Note that @@ -1230,6 +1262,30 @@ e.g. *search-start=none*. jump label with a key sequence that will place the URL in the clipboard. Default: _none_. +*regex-launch* + Enter regex mode. This works exactly the same as URL mode; all + regex matches are tagged with a jump label with a key sequence + that will "launch" to match (and exit regex mode). + + The name of the regex section must be specified in the key + binding: + + ``` + [regex:foo] + regex=foo(bar)? + launch=path-to-script-or-application {match} + + [key-bindings] + regex-launch=[foo] Control+Shift+q + regex-copy=[foo] Control+Mod1+Shift+q + ``` + + Default: _none_. + +*regex-copy* + Same as *regex-copy*, but the match is placed in the clipboard, + instead of "launched", upon activation. Default: _none_. + *prompt-prev* Jump to the previous, currently not visible, prompt (requires shell integration, see *foot*(1)). Default: _Control+Shift+z_. -- cgit v1.3 From a984531ce57f30bc9ec7f664e7c2e8c77b3f439e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 3 Feb 2025 13:56:57 +0100 Subject: url-mode: use the first *sub* expression as URL When auto-matching URLs (or custom regular expressions), use the first *subexpression* as URL, rather than the while regex match. This allows us to write custom regular expressions with prefix/suffix strings that should not be included in the presented match. --- config.c | 56 +++++++++++++++++++++++++++++++++++------------------- doc/foot.ini.5.scd | 15 +++++++++++---- foot.ini | 2 +- url-mode.c | 6 +++--- 4 files changed, 51 insertions(+), 28 deletions(-) (limited to 'doc') diff --git a/config.c b/config.c index 82a4811f..604c0a76 100644 --- a/config.c +++ b/config.c @@ -1256,6 +1256,12 @@ parse_section_url(struct context *ctx) return false; } + if (preg.re_nsub == 0) { + LOG_CONTEXTUAL_ERR("invalid regex: no marked subexpression(s)"); + regfree(&preg); + return false; + } + regfree(&conf->url.preg); free(conf->url.regex); @@ -1300,6 +1306,12 @@ parse_section_regex(struct context *ctx) return false; } + if (preg.re_nsub == 0) { + LOG_CONTEXTUAL_ERR("invalid regex: no marked subexpression(s)"); + regfree(&preg); + return false; + } + if (regex == NULL) { tll_push_back(conf->custom_regexes, ((struct custom_regex){.name = xstrdup(regex_name)})); @@ -3426,33 +3438,37 @@ config_load(struct config *conf, const char *conf_path, */ const char *url_regex_string = "(" - "[a-z][[:alnum:]-]+:" // protocol "(" - "/{1,3}|[a-z0-9%]" // slashes (what's the OR part for?) + "[a-z][[:alnum:]-]+:" // protocol + "(" + "/{1,3}|[a-z0-9%]" // slashes (what's the OR part for?) + ")" + "|" + "www[:digit:]{0,3}[.]" + //"|" + //"[a-z0-9.\\-]+[.][a-z]{2,4}/" /* "looks like domain name followed by a slash" - remove? */ + ")" + "(" + "[^[:space:](){}<>]+" + "|" + "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" + "|" + "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" + ")+" + "(" + "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" + "|" + "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" + "|" + "[^]\\[[:space:]`!(){};:'\".,<>?«»“”‘’]" ")" - "|" - "www[:digit:]{0,3}[.]" - //"|" - //"[a-z0-9.\\-]+[.][a-z]{2,4}/" /* "looks like domain name followed by a slash" - remove? */ - ")" - "(" - "[^[:space:](){}<>]+" - "|" - "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" - "|" - "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" - ")+" - "(" - "\\(([^[:space:](){}<>]+|(\\([^[:space:](){}<>]+\\)))*\\)" - "|" - "\\[([^]\\[[:space:](){}<>]+|(\\[[^]\\[[:space:](){}<>]+\\]))*\\]" - "|" - "[^]\\[[:space:]`!(){};:'\".,<>?«»“”‘’]" ")" ; + int r = regcomp(&conf->url.preg, url_regex_string, REG_EXTENDED); xassert(r == 0); conf->url.regex = xstrdup(url_regex_string); + xassert(conf->url.preg.re_nsub >= 1); } tll_foreach(*initial_user_notifications, it) { diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index af355d68..742281d4 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -786,11 +786,13 @@ section. Default: _sadfjklewcmpgh_. *regex* - Regular expression to use when auto-detecting URLs. The format is - "POSIX-Extended Regular Expressions". + "POSIX-Extended Regular Expressions". Note that the first marked + subexpression is used a the URL. In other words, if you want the + whole regex matćh to be used as an URL, surround all of it with + parenthesis: *(regex-pattern)*. - Default: _([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’])_ + Default: _(([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’]))_ # SECTION: regex @@ -817,7 +819,12 @@ regex-copy=[foo] Control+Mod1+Shift+q *regex* Regular expression to use when matching text. The format is - "POSIX-Extended Regular Expressions". Default: _not set_. + "POSIX-Extended Regular Expressions". Note that the first marked + subexpression is used a the URL. In other words, if you want the + whole regex matćh to be used as an URL, surround all of it with + parenthesis: *(regex-pattern)*. + + Default: _not set_. # SECTION: cursor diff --git a/foot.ini b/foot.ini index 7514c02b..a9a790ac 100644 --- a/foot.ini +++ b/foot.ini @@ -69,7 +69,7 @@ # launch=xdg-open ${url} # label-letters=sadfjklewcmpgh # osc8-underline=url-mode -# regex=([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’]) +# regex=(([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’])) # You can define your own regex's, by adding a section called # 'regex:' with a 'regex' and 'launch' key. These can then be tied diff --git a/url-mode.c b/url-mode.c index 3108ec12..0101de19 100644 --- a/url-mode.c +++ b/url-mode.c @@ -400,13 +400,13 @@ regex_detected(const struct terminal *term, enum url_action action, if (r == REG_NOMATCH) break; - const size_t mlen = matches[0].rm_eo - matches[0].rm_so; - const size_t start = &search_string[matches[0].rm_so] - v->utf8; + const size_t mlen = matches[1].rm_eo - matches[1].rm_so; + const size_t start = &search_string[matches[1].rm_so] - v->utf8; const size_t end = start + mlen; LOG_DBG( "regex match at row %d: %.*srow/col = %dx%d", - matches[0].rm_so, (int)mlen, &search_string[matches[0].rm_so], + matches[1].rm_so, (int)mlen, &search_string[matches[1].rm_so], v->map[start].row, v->map[start].col); tll_push_back( -- cgit v1.3 From 0a32dc3820af009aedbb58cfb5817b9462dbb010 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 3 Feb 2025 14:08:23 +0100 Subject: spawn template variables are on the form ${}, not {} --- doc/foot.ini.5.scd | 4 ++-- foot.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 742281d4..89984ef5 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -806,7 +806,7 @@ for details. In short, you need to: ``` [regex:foo] regex=foo(bar)? -launch=path-to-script-or-application {match} +launch=path-to-script-or-application ${match} [key-bindings] regex-launch=[foo] Control+Shift+q @@ -1280,7 +1280,7 @@ e.g. *search-start=none*. ``` [regex:foo] regex=foo(bar)? - launch=path-to-script-or-application {match} + launch=path-to-script-or-application ${match} [key-bindings] regex-launch=[foo] Control+Shift+q diff --git a/foot.ini b/foot.ini index a9a790ac..2489887f 100644 --- a/foot.ini +++ b/foot.ini @@ -77,7 +77,7 @@ # [regex:your-fancy-name] # regex= -# launch= {match} +# launch= ${match} # # [key-bindings] # regex-launch=[your-fancy-name] Control+Shift+q -- cgit v1.3 From b1f16c84e0be8d3074139f0be56e0852acceaef3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 4 Feb 2025 10:10:10 +0100 Subject: doc: improve regex example --- doc/foot.ini.5.scd | 19 ++++++++++--------- foot.ini | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 89984ef5..68216fcd 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -801,16 +801,17 @@ Similar to the 'url' mode, but with custom defined regular expressions To use a custom defined regular expression, you also need to add a key binding for it. This is done in the *key-binding* section, see below -for details. In short, you need to: +for details. For example, a regex to detect hash digests (e.g. git +commit hashes) could look like: ``` -[regex:foo] -regex=foo(bar)? +[regex:hashes] +regex=([a-fA-f0-9]{7,128}) launch=path-to-script-or-application ${match} [key-bindings] -regex-launch=[foo] Control+Shift+q -regex-copy=[foo] Control+Mod1+Shift+q +regex-launch=[hashes] Control+Shift+q +regex-copy=[hashes] Control+Mod1+Shift+q ``` *launch* @@ -1278,13 +1279,13 @@ e.g. *search-start=none*. binding: ``` - [regex:foo] - regex=foo(bar)? + [regex:hashes] + regex=([a-fA-f0-9]{7,128}) launch=path-to-script-or-application ${match} [key-bindings] - regex-launch=[foo] Control+Shift+q - regex-copy=[foo] Control+Mod1+Shift+q + regex-launch=[hashes] Control+Shift+q + regex-copy=[hashes] Control+Mod1+Shift+q ``` Default: _none_. diff --git a/foot.ini b/foot.ini index 2489887f..a1aa118c 100644 --- a/foot.ini +++ b/foot.ini @@ -73,7 +73,7 @@ # You can define your own regex's, by adding a section called # 'regex:' with a 'regex' and 'launch' key. These can then be tied -# to a key-binding: +# to a key-binding. See foot.ini(5) for details # [regex:your-fancy-name] # regex= -- cgit v1.3 From 9e12f791c5df3ac25574894d41d606967d618888 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 Feb 2025 13:43:11 +0100 Subject: doc: regex: custom regex's aren't URLs --- doc/foot.ini.5.scd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'doc') diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd index 68216fcd..61216c75 100644 --- a/doc/foot.ini.5.scd +++ b/doc/foot.ini.5.scd @@ -788,8 +788,8 @@ section. *regex* Regular expression to use when auto-detecting URLs. The format is "POSIX-Extended Regular Expressions". Note that the first marked - subexpression is used a the URL. In other words, if you want the - whole regex matćh to be used as an URL, surround all of it with + subexpression is used as the URL. In other words, if you want the + whole regex match to be used as an URL, surround all of it with parenthesis: *(regex-pattern)*. Default: _(([a-z][[:alnum:]-]+:(/{1,3}|[a-z0-9%])|www[:digit:]{0,3}[.])([^[:space:](){}<>]+|\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\])+(\(([^[:space:](){}<>]+|(\([^[:space:](){}<>]+\)))\*\)|\[([^]\[[:space:](){}<>]+|(\[[^]\[[:space:](){}<>]+\]))\*\]|[^]\[[:space:]`!(){};:'".,<>?«»“”‘’]))_ @@ -821,8 +821,8 @@ regex-copy=[hashes] Control+Mod1+Shift+q *regex* Regular expression to use when matching text. The format is "POSIX-Extended Regular Expressions". Note that the first marked - subexpression is used a the URL. In other words, if you want the - whole regex matćh to be used as an URL, surround all of it with + subexpression is used as the match. In other words, if you want + the whole regex match to be used, surround all of it with parenthesis: *(regex-pattern)*. Default: _not set_. -- cgit v1.3