diff options
Diffstat (limited to 'doc/en/weechat_user.en.adoc')
-rw-r--r-- | doc/en/weechat_user.en.adoc | 131 |
1 files changed, 98 insertions, 33 deletions
diff --git a/doc/en/weechat_user.en.adoc b/doc/en/weechat_user.en.adoc index 10f23bc78..afe02e2fe 100644 --- a/doc/en/weechat_user.en.adoc +++ b/doc/en/weechat_user.en.adoc @@ -4660,8 +4660,8 @@ A trigger has the following options (names are <<command_weechat_eval,/eval>>). | regex | string -| One or more POSIX extended regular expressions, to change data received in the - hook callback (and some stuff added by trigger plugin), see +| One or more regex "commands" (similar to the `sed` command) to change data + received in the hook callback (and some stuff added by trigger plugin), see <<trigger_regex,regular expression>>. | command | string @@ -4834,42 +4834,47 @@ ${tg_displayed} && (${tg_highlight} || ${tg_msg_pv}) The regular expression is used to change variables in callback hashtable. -The format is: "/regex/replace" or "/regex/replace/var" (where _var_ is a -variable of the hashtable). +Format is one of the following: -If _var_ does not exist in the hashtable, it is created automatically with an -empty value. This allows to create custom temporary variables. +---- +/string1/string2 +s/string1/string2 +s/string1/string2/var +y/string1/string2 +y/string1/string2/var +---- -If _var_ is not specified, the default variable is used, it depends on hook -type: +Fields: -[width="100%",cols="2,3,7",options="header"] -|=== -| Hook | Default variable | Update allowed ^(1)^ -| signal | tg_signal_data | -| hsignal | | -| modifier | tg_string | tg_string -| line | message | buffer, buffer_name, y, date, date_printed, str_time, tags, notify_level, highlight, prefix, message -| print | tg_message | -| command | tg_argv_eol1 | -| command_run | tg_command | -| timer | tg_remaining_calls | -| config | tg_value | -| focus | | -| info | tg_info | tg_info -| info_hashtable | | all variables received in hashtable -|=== - -[NOTE] -^(1)^ All variables can be updated in the trigger, but only these variables -have an effect on the value returned by the trigger and used by WeeChat. +* `s` or `y`: a letter with the command; if missing, default command is `s` + and the first char is then used as the delimiter: +** `s`: regex replacement: first string is a regular expression, second string + is the replacement for every matching string +** `y`: chars translation: first string is a set of characters that are replaced + by the characters in the second string; once evaluated, each string must have + exactly the same number of UTF-8 chars +* `/`: the regex delimiter; the char "/" can be replaced by any char + (one or more identical chars) +* `string1`: the first string (use depends on the command) +* `string2`: the second string (use depends on the command) +* `var`: the hashtable variable to update Many regular expressions can be separated by a space, for example: -"/regex1/replace1/var1 /regex2/replace2/var2". -The char "/" can be replaced by any char (one or more identical chars). +---- +s/regex1/replace1/var1 y/abcdef/ABDDEF/var2 +---- + +[[trigger_regex_replace]] +==== Regex replace + +For the command `s`, the format is: `s/regex/replace` or `s/regex/replace/var` +(where _var_ is a variable of the hashtable). -Matching groups can be used in "replace": +As `s` is the default command, it can be omitted, so `/regex/replace` is also +valid (but the first char, which is the delimiter, must not be a letter). + +Matching groups can be used in _replace_: * `+${re:0}+` to `+${re:99}+`: `+${re:0}+` is the whole match, `+${re:1}+` to `+${re:99}+` are groups captured @@ -4881,7 +4886,7 @@ Matching groups can be used in "replace": Example: use bold for words between `+*+`: ---- -/\*([^ ]+)\*/*${color:bold}${re:1}${color:-bold}*/ +s/\*([^ ]+)\*/*${color:bold}${re:1}${color:-bold}*/ ---- Example: default trigger _server_pass_ uses this regular expression to hide @@ -4889,13 +4894,73 @@ password in commands `/server` and `/connect` (chars in passwords are replaced by `+*+`): ---- -==^(/(server|connect) .*-(sasl_)?password=)([^ ]+)(.*)==${re:1}${hide:*,${re:4}}${re:5} +s==^(/(server|connect) .*-(sasl_)?password=)([^ ]+)(.*)==${re:1}${hide:*,${re:4}}${re:5} ---- [NOTE] In this example, the delimiter used is "==" because there is a "/" in the regular expression. +[[trigger_regex_translate_chars]] +==== Translate chars + +For the command `y`, the format is: `y/chars1/chars2` or `y/chars1/chars2/var` +(where _var_ is a variable of the hashtable). + +Example: replace "a", "b" and "c" by upper case letter: + +---- +y/abc/ABC/ +---- + +Example: rotate arrows clockwise: + +---- +y/←↑→↓/↑→↓←/ +---- + +Example: convert all letters to lower case: + +---- +y/${chars:upper}/${chars:lower}/ +---- + +Example: shift each letter by one position, preserving case: a→b, b→c … y→z, z→a: + +---- +y/${chars:a-z}${chars:A-Z}/${chars:b-z}a${chars:B-Z}A/ +---- + +[[trigger_regex_variable]] +==== Variable + +If _var_ does not exist in the hashtable, it is created automatically with an +empty value. This allows to create custom temporary variables. + +If _var_ is not specified, the default variable is used, it depends on hook +type: + +[width="100%",cols="2,3,7",options="header"] +|=== +| Hook | Default variable | Update allowed ^(1)^ +| signal | tg_signal_data | +| hsignal | | +| modifier | tg_string | tg_string +| line | message | buffer, buffer_name, y, date, date_printed, str_time, tags, notify_level, highlight, prefix, message +| print | tg_message | +| command | tg_argv_eol1 | +| command_run | tg_command | +| timer | tg_remaining_calls | +| config | tg_value | +| focus | | +| info | tg_info | tg_info +| info_hashtable | | all variables received in hashtable +|=== + +[NOTE] +^(1)^ All variables can be updated in the trigger, but only these variables +have an effect on the value returned by the trigger and used by WeeChat. + [[trigger_command]] === Command |