summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-06-19 22:59:42 +1000
committerMaxime Coste <mawww@kakoune.org>2019-06-23 12:04:21 +1000
commit4b7b5d077ced7efd4f67cc619b9f2ddaa731b8d5 (patch)
tree16cc36c7e879c24e2856282117657412a846b404
parent8b2906a14d3395a6619c7e40d3206b75eef11b25 (diff)
Make quoting opt-in by using $kak_quoted_...
-rw-r--r--rc/filetype/c-family.kak2
-rw-r--r--rc/filetype/crystal.kak8
-rw-r--r--rc/tools/clang.kak4
-rw-r--r--rc/tools/ctags.kak6
-rw-r--r--rc/tools/doc.kak6
-rw-r--r--rc/tools/lint.kak6
-rw-r--r--src/shell_manager.cc10
7 files changed, 22 insertions, 20 deletions
diff --git a/rc/filetype/c-family.kak b/rc/filetype/c-family.kak
index e4217a0b..9a6d79e3 100644
--- a/rc/filetype/c-family.kak
+++ b/rc/filetype/c-family.kak
@@ -399,7 +399,7 @@ define-command -hidden c-family-alternative-file %{
dir=$(dirname "${kak_buffile}")
# Set $@ to alt_dirs
- eval "set -- ${kak_opt_alt_dirs}"
+ eval "set -- ${kak_quoted_opt_alt_dirs}"
case ${file} in
*.c|*.cc|*.cpp|*.cxx|*.C|*.inl|*.m)
diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak
index d5717c76..ed7a235a 100644
--- a/rc/filetype/crystal.kak
+++ b/rc/filetype/crystal.kak
@@ -92,7 +92,7 @@ provide-module crystal %🐈
evaluate-commands %sh[
# Keywords
- eval "set -- $kak_opt_crystal_keywords"
+ eval "set -- $kak_quoted_opt_crystal_keywords"
regex="\\b(?:\\Q$1\\E"
shift
for keyword do
@@ -102,7 +102,7 @@ provide-module crystal %🐈
printf 'add-highlighter shared/crystal/code/keywords regex %s 0:keyword\n' "$regex"
# Attributes
- eval "set -- $kak_opt_crystal_attributes"
+ eval "set -- $kak_quoted_opt_crystal_attributes"
regex="\\b(?:\\Q$1\\E"
shift
for attribute do
@@ -112,7 +112,7 @@ provide-module crystal %🐈
printf 'add-highlighter shared/crystal/code/attributes regex %s 0:attribute\n' "$regex"
# Symbols
- eval "set -- $kak_opt_crystal_operators"
+ eval "set -- $kak_quoted_opt_crystal_operators"
# Avoid to match modules
regex="(?<!:):(?:\\w+[?!]?"
for operator do
@@ -122,7 +122,7 @@ provide-module crystal %🐈
printf 'add-highlighter shared/crystal/code/symbols regex %%(%s) 0:value\n' "$regex"
# Objects
- eval "set -- $kak_opt_crystal_objects"
+ eval "set -- $kak_quoted_opt_crystal_objects"
regex="\\b(?:\\Q$1\\E"
shift
for object do
diff --git a/rc/tools/clang.kak b/rc/tools/clang.kak
index 678181bf..0958c75c 100644
--- a/rc/tools/clang.kak
+++ b/rc/tools/clang.kak
@@ -139,7 +139,7 @@ define-command clang-disable-autocomplete -docstring "Disable automatic clang co
define-command -hidden clang-show-error-info %{
update-option buffer clang_errors # Ensure we are up to date with buffer changes
evaluate-commands %sh{
- eval "set -- ${kak_opt_clang_errors}"
+ eval "set -- ${kak_quoted_opt_clang_errors}"
shift # skip timestamp
desc=$(for error in "$@"; do
if [ "${error%%|*}" = "$kak_cursor_line" ]; then
@@ -168,7 +168,7 @@ define-command clang-disable-diagnostics -docstring "Disable automatic error rep
define-command clang-diagnostics-next -docstring "Jump to the next line that contains an error" %{
update-option buffer clang_errors # Ensure we are up to date with buffer changes
evaluate-commands %sh{
- eval "set -- ${kak_opt_clang_errors}"
+ eval "set -- ${kak_quoted_opt_clang_errors}"
shift # skip timestamp
for error in "$@"; do
candidate=${error%%|*}
diff --git a/rc/tools/ctags.kak b/rc/tools/ctags.kak
index a14203cf..eaf92740 100644
--- a/rc/tools/ctags.kak
+++ b/rc/tools/ctags.kak
@@ -15,7 +15,7 @@ declare-option -docstring "shell command to run" str readtagscmd "readtags"
define-command -params ..1 \
-shell-script-candidates %{
realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) }
- eval "set -- $kak_opt_ctagsfiles"
+ eval "set -- $kak_quoted_opt_ctagsfiles"
for candidate in "$@"; do
[ -f "$candidate" ] && realpath "$candidate"
done | awk '!x[$0]++' | # remove duplicates
@@ -32,7 +32,7 @@ If no symbol is passed then the current selection is used as symbol name} \
%[ evaluate-commands %sh[
realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) }
export tagname="${1:-${kak_selection}}"
- eval "set -- $kak_opt_ctagsfiles"
+ eval "set -- $kak_quoted_opt_ctagsfiles"
for candidate in "$@"; do
[ -f "$candidate" ] && realpath "$candidate"
done | awk '!x[$0]++' | # remove duplicates
@@ -68,7 +68,7 @@ define-command ctags-complete -docstring "Complete the current selection" %{
(
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
compl=$(
- eval "set -- $kak_opt_ctagsfiles"
+ eval "set -- $kak_quoted_opt_ctagsfiles"
for ctagsfile in "$@"; do
${kak_opt_readtagscmd} -p -t "$ctagsfile" ${kak_selection}
done | awk '{ uniq[$1]++ } END { for (elem in uniq) printf " %1$s||%1$s", elem }'
diff --git a/rc/tools/doc.kak b/rc/tools/doc.kak
index f1dbc850..0476c406 100644
--- a/rc/tools/doc.kak
+++ b/rc/tools/doc.kak
@@ -13,7 +13,7 @@ define-command -hidden -params 4 doc-render-regex %{
execute-keys "%arg{3}"
evaluate-commands %sh{
face="$4"
- eval "set -- $kak_selections_desc"
+ eval "set -- $kak_quoted_selections_desc"
for desc in "$@"; do ranges="$ranges '$desc|$face'"; done
echo "update-option buffer doc_render_ranges"
echo "set-option -add buffer doc_render_ranges $ranges"
@@ -58,7 +58,7 @@ define-command doc-jump-to-anchor -params 1 %{
update-option buffer doc_anchors
evaluate-commands %sh{
anchor="$1"
- eval "set -- $kak_opt_doc_anchors"
+ eval "set -- $kak_quoted_opt_doc_anchors"
shift
for range in "$@"; do
@@ -74,7 +74,7 @@ define-command doc-jump-to-anchor -params 1 %{
define-command doc-follow-link %{
update-option buffer doc_links
evaluate-commands %sh{
- eval "set -- $kak_opt_doc_links"
+ eval "set -- $kak_quoted_opt_doc_links"
for link in "$@"; do
printf '%s\n' "$link"
done | awk -v FS='[.,|#]' '
diff --git a/rc/tools/lint.kak b/rc/tools/lint.kak
index de120df2..e719960d 100644
--- a/rc/tools/lint.kak
+++ b/rc/tools/lint.kak
@@ -85,7 +85,7 @@ define-command lint -docstring 'Parse the current buffer with a linter' %{
define-command -hidden lint-show %{
update-option buffer lint_errors
evaluate-commands %sh{
- eval "set -- ${kak_opt_lint_errors}"
+ eval "set -- ${kak_quoted_opt_lint_errors}"
shift
s=""
@@ -124,7 +124,7 @@ define-command lint-next-error -docstring "Jump to the next line that contains a
update-option buffer lint_errors
evaluate-commands %sh{
- eval "set -- ${kak_opt_lint_errors}"
+ eval "set -- ${kak_quoted_opt_lint_errors}"
shift
for i in "$@"; do
@@ -148,7 +148,7 @@ define-command lint-previous-error -docstring "Jump to the previous line that co
update-option buffer lint_errors
evaluate-commands %sh{
- eval "set -- ${kak_opt_lint_errors}"
+ eval "set -- ${kak_quoted_opt_lint_errors}"
shift
for i in "$@"; do
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 5abad543..9c0604dd 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -134,12 +134,13 @@ pid_t spawn_shell(const char* shell, StringView cmdline,
Vector<String> generate_env(StringView cmdline, const Context& context, const ShellContext& shell_context)
{
- static const Regex re(R"(\bkak_(\w+)\b)");
+ static const Regex re(R"(\bkak_(quoted_)?(\w+)\b)");
Vector<String> kak_env;
for (auto&& match : RegexIterator{cmdline.begin(), cmdline.end(), re})
{
- StringView name{match[1].first, match[1].second};
+ StringView name{match[2].first, match[2].second};
+ Quoting quoting = match[1].matched ? Quoting::Shell : Quoting::Raw;
auto match_name = [&](const String& s) {
return s.substr(0_byte, name.length()) == name and
@@ -152,9 +153,10 @@ Vector<String> generate_env(StringView cmdline, const Context& context, const Sh
try
{
const String& value = var_it != shell_context.env_vars.end() ?
- var_it->value : ShellManager::instance().get_val(name, context, Quoting::Shell);
+ var_it->value : ShellManager::instance().get_val(name, context, quoting);
- kak_env.push_back(format("kak_{}={}", name, value));
+ StringView quoted{match[1].first, match[1].second};
+ kak_env.push_back(format("kak_{}{}={}", quoted, name, value));
} catch (runtime_error&) {}
}