summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank LENORMAND <lenormf@gmail.com>2015-12-03 08:52:57 +0300
committerFrank LENORMAND <lenormf@gmail.com>2015-12-03 08:52:57 +0300
commit74112ef23cc6fb74cddc115d45f0048af49752d3 (patch)
treee2533b60b2810d4c77830afc4e3891b0c1c1ad34
parentc40dba8a208ccf68ac4e7cb43654b069966117ae (diff)
Simplify/remove the escaping routines
-rw-r--r--rc/commenting.kak14
1 files changed, 4 insertions, 10 deletions
diff --git a/rc/commenting.kak b/rc/commenting.kak
index 076e4027..f11e5634 100644
--- a/rc/commenting.kak
+++ b/rc/commenting.kak
@@ -6,19 +6,13 @@ decl str comment_line_chars "//"
def comment-selection -docstring "Comment/uncomment the current selection" %{
%sh{
- function escape_regex_chars {
- ## Escape characters that can be interpreted as modifiers/repetitors by the regex engine
- sed -r 's,(\*|\+|\[|\]|\{\}|\||\(|\)|\?|\^|\$),\\\1,g' <<< "$@"
- }
function exec_proof {
- ## Replace some special characters that are interpreted differently in `exec`
- sed -r -e 's,<,<lt,g' -e 's,>,gt>,g' -e 's,<lt\b,<lt>,g' -e 's,\bgt>,<gt>,g' <<< "$@"
+ ## Replace the '<' sign that is interpreted differently in `exec`
+ sed -r 's,<,<lt>,g' <<< "$@"
}
readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%%:*}")
readonly closing=$(exec_proof "${kak_opt_comment_selection_chars##*:}")
- readonly opening_escaped=$(escape_regex_chars "${opening}")
- readonly closing_escaped=$(escape_regex_chars "${closing}")
if [ -z "${opening}" -o -z "${closing}" ]; then
echo "The \`comment_selection_chars\` variable is empty, couldn't comment the selection" >&2
@@ -31,13 +25,13 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{
try %{
## The selection has already been commented
- exec -draft %{<a-K>\A${opening_escaped}.*${closing_escaped}\z<ret>}
+ exec -draft %{<a-K>\A\Q${opening}\E.*\Q${closing}\E\z<ret>}
## Comment the selection
exec %{a${closing}<esc>i${opening}<esc>${#opening}H}
} catch %{
## Uncomment the commented selection
- exec -draft %{s(\A${opening_escaped})|(${closing_escaped}\z)<ret>d}
+ exec -draft %{s(\A\Q${opening}\E)|(\Q${closing}\E\z)<ret>d}
}
}"
}