From a63cf00b0508ac7e73984738a7faee51b70b5e06 Mon Sep 17 00:00:00 2001 From: Delapouite Date: Tue, 3 Oct 2017 23:00:08 +0200 Subject: [PATCH] Add debug mappings --- README.asciidoc | 4 ++-- doc/manpages/commands.asciidoc | 2 +- src/commands.cc | 44 ++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 8f01a692..268c14e6 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -685,7 +685,7 @@ Some commands take an exclamation mark (`!`), which can be used to force the execution of the command (i.e. to quit a modified buffer, the command `q!` has to be used). - * `cd []`: change the current directory to ``, or the home directory is unspecified + * `cd []`: change the current directory to ``, or the home directory if unspecified * `doc `: display documentation about a topic. The completion list displays the available topics. * `e[dit][!] [ []]`: open buffer on file, go to given @@ -1597,7 +1597,7 @@ Some helper commands can be used to define composite commands: * `reg `: set register to * `select .,.:...`: replace the current selections with the one described in the argument - * `debug {info,buffers,options,memory,shared-strings,profile-hash-maps,faces}`: + * `debug {info,buffers,options,memory,shared-strings,profile-hash-maps,faces,mappings}`: print some debug information in the `*debug*` buffer Note that these commands are available in interactive command mode, but are diff --git a/doc/manpages/commands.asciidoc b/doc/manpages/commands.asciidoc index 73aee9df..1140841f 100644 --- a/doc/manpages/commands.asciidoc +++ b/doc/manpages/commands.asciidoc @@ -221,7 +221,7 @@ commands: *select* .,.:...:: replace the current selections with the one described in the argument -*debug* {info,buffers,options,memory,shared-strings,profile-hash-maps,faces}:: +*debug* {info,buffers,options,memory,shared-strings,profile-hash-maps,faces,mappings}:: print some debug information in the *\*debug** buffer Note that those commands are also available in the interactive mode, but diff --git a/src/commands.cc b/src/commands.cc index e96f8deb..91a5269c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1111,6 +1111,19 @@ const CommandDesc echo_cmd = { } }; +KeymapMode parse_keymap_mode(const String& str) +{ + if (prefix_match("normal", str)) return KeymapMode::Normal; + if (prefix_match("insert", str)) return KeymapMode::Insert; + if (prefix_match("menu", str)) return KeymapMode::Menu; + if (prefix_match("prompt", str)) return KeymapMode::Prompt; + if (prefix_match("goto", str)) return KeymapMode::Goto; + if (prefix_match("view", str)) return KeymapMode::View; + if (prefix_match("user", str)) return KeymapMode::User; + if (prefix_match("object", str)) return KeymapMode::Object; + + throw runtime_error(format("unknown keymap mode '{}'", str)); +} const CommandDesc debug_cmd = { "debug", @@ -1124,7 +1137,7 @@ const CommandDesc debug_cmd = { [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) -> Completions { auto c = {"info", "buffers", "options", "memory", "shared-strings", - "profile-hash-maps", "faces"}; + "profile-hash-maps", "faces", "mappings"}; return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) }; }), [](const ParametersParser& parser, Context& context, const ShellContext&) @@ -1180,6 +1193,21 @@ const CommandDesc debug_cmd = { for (auto& face : FaceRegistry::instance().aliases()) write_to_debug_buffer(format(" * {}: {}", face.key, face.value.face)); } + else if (parser[0] == "mappings") + { + auto& keymaps = context.keymaps(); + auto modes = {"normal", "insert", "prompt", "menu", + "goto", "view", "user", "object"}; + write_to_debug_buffer("Mappings:"); + for (auto& mode : modes) + { + KeymapMode m = parse_keymap_mode(mode); + for (auto& key : keymaps.get_mapped_keys(m)) + write_to_debug_buffer(format(" * {} {}: {}", + mode, key_to_str(key), + keymaps.get_mapping(key, m).docstring)); + } + } else throw runtime_error(format("unknown debug command '{}'", parser[0])); } @@ -1394,20 +1422,6 @@ const CommandDesc declare_option_cmd = { } }; -KeymapMode parse_keymap_mode(const String& str) -{ - if (prefix_match("normal", str)) return KeymapMode::Normal; - if (prefix_match("insert", str)) return KeymapMode::Insert; - if (prefix_match("menu", str)) return KeymapMode::Menu; - if (prefix_match("prompt", str)) return KeymapMode::Prompt; - if (prefix_match("goto", str)) return KeymapMode::Goto; - if (prefix_match("view", str)) return KeymapMode::View; - if (prefix_match("user", str)) return KeymapMode::User; - if (prefix_match("object", str)) return KeymapMode::Object; - - throw runtime_error(format("unknown keymap mode '{}'", str)); -} - auto map_key_completer = [](const Context& context, CompletionFlags flags, CommandParameters params, size_t token_to_complete,