Allow to ommit the catch part in the try command

This commit is contained in:
Maxime Coste 2013-10-31 19:22:00 +00:00
parent 5e54705e26
commit 02312fe5ff
4 changed files with 15 additions and 12 deletions

View File

@ -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. specify where the info box should be anchored relative to the main selection.
* +try <commands> catch <on_error_commands>+: prevent an error in <commands> * +try <commands> catch <on_error_commands>+: prevent an error in <commands>
from aborting the whole commands execution, execute <on_error_commands> from aborting the whole commands execution, execute <on_error_commands>
instead. instead. If nothing is to be done on error, the catch part can be ommitted.
* +reg <name> <content>+: set register <name> to <content> * +reg <name> <content>+: set register <name> to <content>
Note that these commands are available in interactive command mode, but are Note that these commands are available in interactive command mode, but are

View File

@ -657,10 +657,12 @@ void info(CommandParameters params, Context& context)
void try_catch(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(); 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 <commands> [catch <on error commands>]");
CommandManager& command_manager = CommandManager::instance(); CommandManager& command_manager = CommandManager::instance();
try try
@ -669,7 +671,8 @@ void try_catch(CommandParameters params, Context& context)
} }
catch (Kakoune::runtime_error& e) catch (Kakoune::runtime_error& e)
{ {
command_manager.execute(params[2], context); if (do_catch)
command_manager.execute(params[2], context);
} }
} }

View File

@ -18,11 +18,11 @@ hook global WinSetOption filetype=cpp %~
addhl -group cpp-highlight regex "^\h*?#.*?(?<!\\)$" 0:macro addhl -group cpp-highlight regex "^\h*?#.*?(?<!\\)$" 0:macro
addhl -group cpp-highlight regex "(?<!')\".*?(?<!\\)(\\\\)*\"" 0:string addhl -group cpp-highlight regex "(?<!')\".*?(?<!\\)(\\\\)*\"" 0:string
addhl -group cpp-highlight regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" 0:comment addhl -group cpp-highlight regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" 0:comment
hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } catch %{} } hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } }
hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s^\h+<ret>yj<a-h>P } catch %{} ] # preserve previous line indent hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s^\h+<ret>yj<a-h>P } ] # preserve previous line indent
hook window InsertKey \n -id cpp-hooks %[ try %[ exec -draft k<a-x><a-k>[{(]\h*$<ret>j<a-gt> ] catch %{} ] # indent after lines ending with { or ( hook window InsertKey \n -id cpp-hooks %[ try %[ exec -draft k<a-x><a-k>[{(]\h*$<ret>j<a-gt> ] ] # indent after lines ending with { or (
hook window InsertKey \} -id cpp-hooks %[ try %[ exec -draft <a-h><a-k>^\h+\}$<ret>< ] catch %{} ] # deindent on insert } alone on a line hook window InsertKey \} -id cpp-hooks %[ try %[ exec -draft <a-h><a-k>^\h+\}$<ret>< ] ] # deindent on insert } alone on a line
hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s\h+$<ret>d } catch %{} ] # cleanup trailing white space son previous line hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s\h+$<ret>d } ] # cleanup trailing white space son previous line
~ ~
hook global WinSetOption filetype=(?!cpp).* %{ hook global WinSetOption filetype=(?!cpp).* %{

View File

@ -39,7 +39,7 @@ def -shell-params git %{ %sh{
run_git_blame() { run_git_blame() {
( (
echo "eval -client '$kak_client' %{ 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 '' set buffer=$kak_bufname git_blame_flags ''
}" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} }" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session}
declare -A authors declare -A authors
@ -92,7 +92,7 @@ def -shell-params git %{ %sh{
show|log|diff) show_git_cmd_output "$@" ;; show|log|diff) show_git_cmd_output "$@" ;;
blame) run_git_blame ;; blame) run_git_blame ;;
show-diff) 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) update_diff ;; update-diff) update_diff ;;