diff --git a/README.asciidoc b/README.asciidoc index a028f2bb..a6c4caf2 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -654,7 +654,7 @@ Some helper commands can be used to define composite commands: specify where the info box should be anchored relative to the main selection. * +try catch +: prevent an error in from aborting the whole commands execution, execute - instead. + instead. If nothing is to be done on error, the catch part can be ommitted. * +reg +: set register to Note that these commands are available in interactive command mode, but are diff --git a/src/commands.cc b/src/commands.cc index eb560b4f..a331c94f 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -657,10 +657,12 @@ void info(CommandParameters params, Context& context) void try_catch(CommandParameters params, Context& context) { - if (params.size() != 3) + if (params.size() != 1 and params.size() != 3) throw wrong_argument_count(); - if (params[1] != "catch") - throw runtime_error("try needs a catch"); + + const bool do_catch = params.size() == 3; + if (do_catch and params[1] != "catch") + throw runtime_error("usage: try [catch ]"); CommandManager& command_manager = CommandManager::instance(); try @@ -669,7 +671,8 @@ void try_catch(CommandParameters params, Context& context) } catch (Kakoune::runtime_error& e) { - command_manager.execute(params[2], context); + if (do_catch) + command_manager.execute(params[2], context); } } diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index 8bcc987a..1db0ca5a 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -18,11 +18,11 @@ hook global WinSetOption filetype=cpp %~ addhl -group cpp-highlight regex "^\h*?#.*?(?s\h+$d } catch %{} } - hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft ks^\h+yjP } catch %{} ] # preserve previous line indent - hook window InsertKey \n -id cpp-hooks %[ try %[ exec -draft k[{(]\h*$j ] catch %{} ] # indent after lines ending with { or ( - hook window InsertKey \} -id cpp-hooks %[ try %[ exec -draft ^\h+\}$< ] catch %{} ] # deindent on insert } alone on a line - hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft ks\h+$d } catch %{} ] # cleanup trailing white space son previous line + hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft s\h+$d } } + hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft ks^\h+yjP } ] # preserve previous line indent + hook window InsertKey \n -id cpp-hooks %[ try %[ exec -draft k[{(]\h*$j ] ] # indent after lines ending with { or ( + hook window InsertKey \} -id cpp-hooks %[ try %[ exec -draft ^\h+\}$< ] ] # deindent on insert } alone on a line + hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft ks\h+$d } ] # cleanup trailing white space son previous line ~ hook global WinSetOption filetype=(?!cpp).* %{ diff --git a/src/rc/git-tools.kak b/src/rc/git-tools.kak index 61b5ebd0..3cc005a4 100644 --- a/src/rc/git-tools.kak +++ b/src/rc/git-tools.kak @@ -39,7 +39,7 @@ def -shell-params git %{ %sh{ run_git_blame() { ( echo "eval -client '$kak_client' %{ - try %{ addhl flag_lines magenta git_blame_flags } catch %{} + try %{ addhl flag_lines magenta git_blame_flags } set buffer=$kak_bufname git_blame_flags '' }" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} declare -A authors @@ -92,7 +92,7 @@ def -shell-params git %{ %sh{ show|log|diff) show_git_cmd_output "$@" ;; blame) run_git_blame ;; show-diff) - echo "try %{ addhl flag_lines black git_diff_flags } catch %{}" + echo "try %{ addhl flag_lines black git_diff_flags }" update_diff ;; update-diff) update_diff ;;