diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-10-30 09:38:40 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-10-30 09:38:40 +0000 |
| commit | feff965ac611804be0a68b73d01e29aff5690997 (patch) | |
| tree | 51b04ba22519fc3638c27070fcf0283ef878f884 /src | |
| parent | cc01aab8b889b4cef9455e4f83b74e28f84f30a9 (diff) | |
Remove setg/setb/setw and use set <scope>
(with scope a prefix of global,buffer or window)
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 82 | ||||
| -rw-r--r-- | src/rc/asciidoc.kak | 2 | ||||
| -rw-r--r-- | src/rc/clang.kak | 4 | ||||
| -rw-r--r-- | src/rc/cpp.kak | 4 | ||||
| -rw-r--r-- | src/rc/diff.kak | 2 | ||||
| -rw-r--r-- | src/rc/git-tools.kak | 8 | ||||
| -rw-r--r-- | src/rc/git.kak | 4 | ||||
| -rw-r--r-- | src/rc/grep.kak | 2 | ||||
| -rw-r--r-- | src/rc/kakrc.kak | 6 | ||||
| -rw-r--r-- | src/rc/mail.kak | 2 | ||||
| -rw-r--r-- | src/rc/make.kak | 2 | ||||
| -rw-r--r-- | src/rc/man.kak | 4 | ||||
| -rw-r--r-- | src/rc/sh.kak | 4 |
13 files changed, 57 insertions, 69 deletions
diff --git a/src/commands.cc b/src/commands.cc index 4b015c16..ce973b22 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -460,47 +460,30 @@ void exec_commands_in_file(CommandParameters params, CommandManager::instance().execute(file_content, context); } -void set_global_option(CommandParameters params, Context& context) +static OptionManager& get_options(const String& scope, const Context& context) { - ParametersParser parser(params, { { "add", false } }, - ParametersParser::Flags::OptionsOnlyAtStart, - 2, 2); - - Option& opt = GlobalOptions::instance().get_local_option(parser[0]); - if (parser.has_option("add")) - opt.add_from_string(parser[1]); - else - opt.set_from_string(parser[1]); -} - -void set_buffer_option(CommandParameters params, Context& context) -{ - ParametersParser parser(params, { { "buffer", true}, { "add", false } }, - ParametersParser::Flags::OptionsOnlyAtStart, - 2, 2); - - OptionManager& options = parser.has_option("buffer") ? - BufferManager::instance().get_buffer(parser.option_value("buffer")).options() - : context.buffer().options(); - - Option& opt = options.get_local_option(parser[0]); - if (parser.has_option("add")) - opt.add_from_string(parser[1]); - else - opt.set_from_string(parser[1]); + if (prefix_match("global", scope)) + return GlobalOptions::instance(); + else if (prefix_match("buffer", scope)) + return context.buffer().options(); + else if (prefix_match("window", scope)) + return context.window().options(); + else if (prefix_match(scope, "buffer=")) + return BufferManager::instance().get_buffer(scope.substr(7_byte)).options(); + throw runtime_error("error: no such option container " + scope); } -void set_window_option(CommandParameters params, Context& context) +void set_option(CommandParameters params, Context& context) { ParametersParser parser(params, { { "add", false } }, ParametersParser::Flags::OptionsOnlyAtStart, - 2, 2); + 3, 3); - Option& opt = context.window().options().get_local_option(parser[0]); + Option& opt = get_options(parser[0], context).get_local_option(parser[1]); if (parser.has_option("add")) - opt.add_from_string(parser[1]); + opt.add_from_string(parser[2]); else - opt.set_from_string(parser[1]); + opt.set_from_string(parser[2]); } void declare_option(CommandParameters params, Context& context) @@ -873,21 +856,26 @@ void register_commands() cm.register_command("echo", echo_message); cm.register_command("debug", write_debug_message); - cm.register_commands({ "setg", "setglobal" }, set_global_option, - PerArgumentCommandCompleter({ - [](const Context& context, const String& prefix, ByteCount cursor_pos) - { return GlobalOptions::instance().complete_option_name(prefix, cursor_pos); } - })); - cm.register_commands({ "setb", "setbuffer" }, set_buffer_option, - PerArgumentCommandCompleter({ - [](const Context& context, const String& prefix, ByteCount cursor_pos) - { return context.buffer().options().complete_option_name(prefix, cursor_pos); } - })); - cm.register_commands({ "setw", "setwindow" }, set_window_option, - PerArgumentCommandCompleter({ - [](const Context& context, const String& prefix, ByteCount cursor_pos) - { return context.window().options().complete_option_name(prefix, cursor_pos); } - })); + cm.register_command("set", set_option, + [](const Context& context, CommandParameters params, size_t token_to_complete, ByteCount pos_in_token) + { + if (token_to_complete == 0) + { + CandidateList res; + for (auto scope : { "global", "buffer", "window" }) + { + if (params.size() == 0 or prefix_match(scope, params[0].substr(0_byte, pos_in_token))) + res.emplace_back(scope); + } + return res; + } + else if (token_to_complete == 1) + { + OptionManager& options = get_options(params[0], context); + return options.complete_option_name(params[1], pos_in_token); + } + return CandidateList{}; + } ); cm.register_commands({"ca", "colalias"}, define_color_alias); cm.register_commands({"nc", "nameclient"}, set_client_name); diff --git a/src/rc/asciidoc.kak b/src/rc/asciidoc.kak index 0d40780b..cfec02b1 100644 --- a/src/rc/asciidoc.kak +++ b/src/rc/asciidoc.kak @@ -1,4 +1,4 @@ -hook global BufCreate .*\.asciidoc %{ setb filetype asciidoc } +hook global BufCreate .*\.asciidoc %{ set buffer filetype asciidoc } hook global WinSetOption filetype=asciidoc %{ addhl group asciidoc-highlight diff --git a/src/rc/clang.kak b/src/rc/clang.kak index 5cb4647a..db9412dc 100644 --- a/src/rc/clang.kak +++ b/src/rc/clang.kak @@ -4,7 +4,7 @@ decl str clang_options def clang-complete %{ %sh{ filename=$(mktemp -d -t kak-clang.XXXXXXXX)/buffer.cpp - echo "setb clang_filename $filename" + echo "set buffer clang_filename $filename" echo "write $filename" } # end the previous %sh{} so that its output gets interpreted by kakoune @@ -23,7 +23,7 @@ def clang-complete %{ for cmp in ${output}; do completions="${completions}:${cmp}" done - echo "eval -client $kak_client %[ echo completed; setb completions '${completions}' ]" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} + echo "eval -client $kak_client %[ echo completed; set buffer completions '${completions}' ]" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} ) >& /dev/null < /dev/null & } } diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index d93a8888..18d4e96a 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -1,11 +1,11 @@ hook global BufCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) %{ - setb filetype cpp + set buffer filetype cpp } hook global BufOpen .* %{ %sh{ mimetype="$(file -b --mime-type ${kak_bufname})" if [[ "${mimetype}" == "text/x-c++" || "${mimetype}" == "text/x-c" ]]; then - echo setb filetype cpp; + echo set buffer filetype cpp; fi } } diff --git a/src/rc/diff.kak b/src/rc/diff.kak index fcd0e91f..b91b0f1e 100644 --- a/src/rc/diff.kak +++ b/src/rc/diff.kak @@ -1,5 +1,5 @@ hook global BufCreate .*\.(diff|patch) %{ - setb filetype diff + set buffer filetype diff } hook global WinSetOption filetype=diff %{ diff --git a/src/rc/git-tools.kak b/src/rc/git-tools.kak index c28c1070..61b5ebd0 100644 --- a/src/rc/git-tools.kak +++ b/src/rc/git-tools.kak @@ -27,7 +27,7 @@ def -shell-params git %{ %sh{ echo "edit! -scratch *git* exec |cat<space>${tmpfile}<ret>gk nop %sh{rm ${tmpfile}} - setb filetype '${filetype}'" + set buffer filetype '${filetype}'" [[ -n "$kak_opt_docsclient" ]] && echo "}" else @@ -40,7 +40,7 @@ def -shell-params git %{ %sh{ ( echo "eval -client '$kak_client' %{ try %{ addhl flag_lines magenta git_blame_flags } catch %{} - setb -buffer '$kak_bufname' git_blame_flags '' + set buffer=$kak_bufname git_blame_flags '' }" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} declare -A authors declare -A dates @@ -51,7 +51,7 @@ def -shell-params git %{ %sh{ for (( i=1; $i < $count; i++ )); do flag="$flag:$(($line+$i))|black|$text" done - echo "setb -add -buffer '$kak_bufname' git_blame_flags %{${flag}}" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} + echo "set buffer -add buffer=$kak_bufname git_blame_flags %{${flag}}" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} } git blame --incremental $kak_bufname | ( while read blame_line; do if [[ $blame_line =~ ([0-9a-f]{40}).([0-9]+).([0-9]+).([0-9]+) ]]; then @@ -84,7 +84,7 @@ def -shell-params git %{ %sh{ flags="$flags:$line|red|-" fi done - echo "setb git_diff_flags '$flags'" + echo "set buffer git_diff_flags '$flags'" } } diff --git a/src/rc/git.kak b/src/rc/git.kak index 678ffbb2..0444cdd7 100644 --- a/src/rc/git.kak +++ b/src/rc/git.kak @@ -1,5 +1,5 @@ hook global BufCreate .*COMMIT_EDITMSG %{ - setb filetype git-commit + set buffer filetype git-commit } hook global WinSetOption filetype=git-commit %{ @@ -13,7 +13,7 @@ hook global WinSetOption filetype=(?!git-commit).* %{ } hook global BufCreate .*git-rebase-todo %{ - setb filetype git-rebase + set buffer filetype git-rebase } hook global WinSetOption filetype=git-rebase %{ diff --git a/src/rc/grep.kak b/src/rc/grep.kak index 3ff91a0f..b98708b0 100644 --- a/src/rc/grep.kak +++ b/src/rc/grep.kak @@ -14,7 +14,7 @@ def -shell-params -file-completion \ [[ -n "$kak_opt_toolsclient" ]] && echo "eval -client '$kak_opt_toolsclient' %{" echo "edit! -fifo ${output} *grep* - setb filetype grep + set buffer filetype grep hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }" [[ -n "$kak_opt_toolsclient" ]] && echo "}" diff --git a/src/rc/kakrc.kak b/src/rc/kakrc.kak index 223ae638..2dfe050b 100644 --- a/src/rc/kakrc.kak +++ b/src/rc/kakrc.kak @@ -1,15 +1,15 @@ hook global BufCreate (.*/)?(kakrc|.*.kak) %{ - setb filetype kak + set buffer filetype kak } hook global WinSetOption filetype=kak %{ addhl group kak-highlight - addhl -group kak-highlight regex \<(hook|rmhooks|addhl|rmhl|addfilter|rmfilter|exec|eval|source|runtime|def|decl|echo|edit|set[gbw])\> 0:keyword + addhl -group kak-highlight regex \<(hook|rmhooks|addhl|rmhl|addfilter|rmfilter|exec|eval|source|runtime|def|decl|echo|edit|set)\> 0:keyword addhl -group kak-highlight regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> 0:value addhl -group kak-highlight regex (?<=\<hook)\h+((global|buffer|window)|(\S+))\h+(\S+)\h+(\H+) 2:attribute 3:error 4:identifier 5:string + addhl -group kak-highlight regex (?<=\<set)\h+((global|buffer|window)|(\S+))\h+(\S+)\h+(\H+) 2:attribute 3:error 4:identifier 5:value addhl -group kak-highlight regex (?<=\<regex)\h+(\S+) 1:string addhl -group kak-highlight regex (["'])(?:\\\1|.)*?\1 0:string - addhl -group kak-highlight regex (?<=\<set[gbw])\h+(\S+)\h+(\S+) 1:identifier 2:value addhl -group kak-highlight regex (^|\h)\#[^\n]*\n 0:comment } diff --git a/src/rc/mail.kak b/src/rc/mail.kak index d0603fec..abf5364a 100644 --- a/src/rc/mail.kak +++ b/src/rc/mail.kak @@ -1,7 +1,7 @@ hook global BufOpen .* %{ %sh{ mimetype="$(file -b --mime-type ${kak_bufname})" if [[ "${mimetype}" == "message/rfc822" ]]; then - echo setb filetype mail; + echo set buffer filetype mail; fi } } diff --git a/src/rc/make.kak b/src/rc/make.kak index 694f3415..6e77164a 100644 --- a/src/rc/make.kak +++ b/src/rc/make.kak @@ -9,7 +9,7 @@ def -shell-params make %{ %sh{ [[ -n "$kak_opt_toolsclient" ]] && echo "eval -client '$kak_opt_toolsclient' %{" echo "edit! -fifo ${output} *make* - setb filetype make + set buffer filetype make hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }" [[ -n "$kak_opt_toolsclient" ]] && echo "}" diff --git a/src/rc/man.kak b/src/rc/man.kak index 6d2c27a6..386f2df0 100644 --- a/src/rc/man.kak +++ b/src/rc/man.kak @@ -6,7 +6,7 @@ hook global WinSetOption filetype=man %{ addhl -group man-highlight regex ^\h+-+[-a-zA-Z_]+ 0:yellow addhl -group man-highlight regex [-a-zA-Z_.]+\(\d\) 0:green hook window -id man-hooks NormalKey <c-m> man - setb tabstop 8 + set buffer tabstop 8 } hook global WinSetOption filetype=(?!man).* %{ @@ -28,7 +28,7 @@ def -shell-params man %{ %sh{ echo "edit! -scratch '*man*' exec |cat<space>${tmpfile}<ret>gk nop %sh{rm ${tmpfile}} - setb filetype man" + set buffer filetype man" else echo "echo %{man '$@' failed: see *debug* buffer for details }" rm ${tmpfile} diff --git a/src/rc/sh.kak b/src/rc/sh.kak index fb338dbd..d558d0a9 100644 --- a/src/rc/sh.kak +++ b/src/rc/sh.kak @@ -1,11 +1,11 @@ hook global BufCreate .*\.(sh) %{ - setb filetype sh + set buffer filetype sh } hook global BufOpen .* %{ %sh{ mimetype="$(file -b --mime-type ${kak_bufname})" if [[ "${mimetype}" == "text/x-shellscript" ]]; then - echo setb filetype sh; + echo set buffer filetype sh; fi } } |
