summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-04-11 12:13:11 +1000
committerMaxime Coste <mawww@kakoune.org>2024-04-12 15:28:40 +1000
commitb1c114bf6d950684df0524e450782a151e6a0323 (patch)
tree9033f055147a92292e9593bdea3965541f34e288
parent7f556c1e871dbe9c43dd8350cb6419104dbc1d8d (diff)
Make removing an unknown highlighter an error
Fail instead of silently doing nothing, this makes it easier to toggle highlighters using a try/catch
-rw-r--r--rc/tools/git.kak4
-rw-r--r--src/highlighter_group.cc5
-rw-r--r--src/highlighters.cc5
3 files changed, 10 insertions, 4 deletions
diff --git a/rc/tools/git.kak b/rc/tools/git.kak
index be1d7e70..ac349a97 100644
--- a/rc/tools/git.kak
+++ b/rc/tools/git.kak
@@ -183,7 +183,7 @@ define-command -params 1.. \
set-option buffer git_blame_flags $kak_timestamp
set-option buffer git_blame_index $kak_timestamp
set-option buffer git_blame %{}
- remove-highlighter window/git-blame
+ try %{ remove-highlighter window/git-blame }
unmap window normal <ret> %{:git blame-jump<ret>}
"
}
@@ -217,7 +217,7 @@ define-command -params 1.. \
if [ -z "${kak_opt_git_blob}" ] && {
[ "${kak_opt_filetype}" = git-diff ] || [ "${kak_opt_filetype}" = git-log ]
} then {
- echo 'remove-highlighter window/git-blame'
+ echo 'try %{ remove-highlighter window/git-blame }'
printf >${kak_command_fifo} %s '
evaluate-commands -client '${kak_client}' -draft %{
try %{
diff --git a/src/highlighter_group.cc b/src/highlighter_group.cc
index e23b5979..813262c0 100644
--- a/src/highlighter_group.cc
+++ b/src/highlighter_group.cc
@@ -43,7 +43,10 @@ void HighlighterGroup::add_child(String name, std::unique_ptr<Highlighter>&& hl,
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)
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 2123e596..1ab6466d 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -2039,7 +2039,10 @@ public:
if (id == m_default_region)
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;
}