Make removing an unknown highlighter an error

Fail instead of silently doing nothing, this makes it easier to
toggle highlighters using a try/catch
This commit is contained in:
Maxime Coste 2024-04-11 12:13:11 +10:00
parent 7f556c1e87
commit b1c114bf6d
3 changed files with 10 additions and 4 deletions

View File

@ -183,7 +183,7 @@ define-command -params 1.. \
set-option buffer git_blame_flags $kak_timestamp set-option buffer git_blame_flags $kak_timestamp
set-option buffer git_blame_index $kak_timestamp set-option buffer git_blame_index $kak_timestamp
set-option buffer git_blame %{} set-option buffer git_blame %{}
remove-highlighter window/git-blame try %{ remove-highlighter window/git-blame }
unmap window normal <ret> %{:git blame-jump<ret>} unmap window normal <ret> %{:git blame-jump<ret>}
" "
} }
@ -217,7 +217,7 @@ define-command -params 1.. \
if [ -z "${kak_opt_git_blob}" ] && { if [ -z "${kak_opt_git_blob}" ] && {
[ "${kak_opt_filetype}" = git-diff ] || [ "${kak_opt_filetype}" = git-log ] [ "${kak_opt_filetype}" = git-diff ] || [ "${kak_opt_filetype}" = git-log ]
} then { } then {
echo 'remove-highlighter window/git-blame' echo 'try %{ remove-highlighter window/git-blame }'
printf >${kak_command_fifo} %s ' printf >${kak_command_fifo} %s '
evaluate-commands -client '${kak_client}' -draft %{ evaluate-commands -client '${kak_client}' -draft %{
try %{ try %{

View File

@ -43,7 +43,10 @@ void HighlighterGroup::add_child(String name, std::unique_ptr<Highlighter>&& hl,
void HighlighterGroup::remove_child(StringView id) void HighlighterGroup::remove_child(StringView id)
{ {
m_highlighters.remove(id); auto it = m_highlighters.find(id);
if (it == m_highlighters.end())
throw child_not_found(format("no such id: '{}'", id));
m_highlighters.remove(it);
} }
Highlighter& HighlighterGroup::get_child(StringView path) Highlighter& HighlighterGroup::get_child(StringView path)

View File

@ -2039,7 +2039,10 @@ public:
if (id == m_default_region) if (id == m_default_region)
m_default_region = String{}; m_default_region = String{};
m_regions.remove(id); auto it = m_regions.find(id);
if (it == m_regions.end())
throw child_not_found(format("no such id: {}", id));
m_regions.remove(it);
++m_regions_timestamp; ++m_regions_timestamp;
} }