Your one-stop-cake-shop for everything Freshly Baked has to offer
11
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add helix config

We've been using helix editor since the start but up until now it has
only been in configuration.nix rather than getting config through
home-manager. The config I've added here is a compilation of a couple of
pieces of work...

- My currently-set options
- Some past config I had for some nice keybindings

Additionally, the keybinding piece also needs a long-awaited helix PR -
we can just go ahead and patch that in

---

I've kept helix in configuration.nix too as I want to make sure that we
still have a nice editor for, say, editing files as root/etc. Probably
it should go in some file in "common" instead but that can be a followup

authored by a.starrysky.fyi and committed by

Skyler Grey 9bec9ede db788829

+1142
+144
packetmix/LICENSES/MPL-2.0.txt
··· 1 + Mozilla Public License Version 2.0 2 + 3 + 1. Definitions 4 + 5 + 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. 6 + 7 + 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. 8 + 9 + 1.3. "Contribution" means Covered Software of a particular Contributor. 10 + 11 + 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. 12 + 13 + 1.5. "Incompatible With Secondary Licenses" means 14 + 15 + (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or 16 + 17 + (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. 18 + 19 + 1.6. "Executable Form" means any form of the work other than Source Code Form. 20 + 21 + 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 22 + 23 + 1.8. "License" means this document. 24 + 25 + 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. 26 + 27 + 1.10. "Modifications" means any of the following: 28 + 29 + (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or 30 + 31 + (b) any new file in Source Code Form that contains any Covered Software. 32 + 33 + 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. 34 + 35 + 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. 36 + 37 + 1.13. "Source Code Form" means the form of the work preferred for making modifications. 38 + 39 + 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 40 + 41 + 2. License Grants and Conditions 42 + 43 + 2.1. Grants 44 + Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: 45 + 46 + (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and 47 + 48 + (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. 49 + 50 + 2.2. Effective Date 51 + The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. 52 + 53 + 2.3. Limitations on Grant Scope 54 + The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: 55 + 56 + (a) for any code that a Contributor has removed from Covered Software; or 57 + 58 + (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or 59 + 60 + (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. 61 + 62 + This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). 63 + 64 + 2.4. Subsequent Licenses 65 + No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). 66 + 67 + 2.5. Representation 68 + Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. 69 + 70 + 2.6. Fair Use 71 + This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. 72 + 73 + 2.7. Conditions 74 + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. 75 + 76 + 3. Responsibilities 77 + 78 + 3.1. Distribution of Source Form 79 + All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. 80 + 81 + 3.2. Distribution of Executable Form 82 + If You distribute Covered Software in Executable Form then: 83 + 84 + (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and 85 + 86 + (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. 87 + 88 + 3.3. Distribution of a Larger Work 89 + You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). 90 + 91 + 3.4. Notices 92 + You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. 93 + 94 + 3.5. Application of Additional Terms 95 + You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. 96 + 97 + 4. Inability to Comply Due to Statute or Regulation 98 + If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 99 + 100 + 5. Termination 101 + 102 + 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. 103 + 104 + 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. 105 + 106 + 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. 107 + 108 + 6. Disclaimer of Warranty 109 + Covered Software is provided under this License on an "as is" basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer. 110 + 111 + 7. Limitation of Liability 112 + Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You. 113 + 114 + 8. Litigation 115 + Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. 116 + 117 + 9. Miscellaneous 118 + This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. 119 + 120 + 10. Versions of the License 121 + 122 + 10.1. New Versions 123 + Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. 124 + 125 + 10.2. Effect of New Versions 126 + You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. 127 + 128 + 10.3. Modified Versions 129 + If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). 130 + 131 + 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses 132 + If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. 133 + 134 + Exhibit A - Source Code Form License Notice 135 + 136 + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 137 + 138 + If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. 139 + 140 + You may add additional accurate notices of copyright ownership. 141 + 142 + Exhibit B - "Incompatible With Secondary Licenses" Notice 143 + 144 + This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
+1
packetmix/homes/default.nix
··· 13 13 } 14 14 ./minion/direnv.nix 15 15 ./minion/ghostty.nix 16 + ./minion/helix.nix 16 17 (import ./minion/niri.nix { inherit (config.inputs) niri walker; }) 17 18 ./minion/ripgrep.nix 18 19 ./minion/sd.nix
+56
packetmix/homes/minion/helix.nix
··· 1 + # SPDX-FileCopyrightText: 2025 FreshlyBakedCake 2 + # 3 + # SPDX-License-Identifier: MIT 4 + 5 + { 6 + pkgs, 7 + project, 8 + system, 9 + ... 10 + }: 11 + { 12 + programs.helix = { 13 + enable = true; 14 + 15 + package = project.packages.helix.result.${system}; 16 + 17 + settings = { 18 + theme = "catppuccin_latte"; 19 + 20 + editor = { 21 + bufferline = "multiple"; 22 + 23 + line-number = "relative"; 24 + lsp.display-inlay-hints = true; 25 + 26 + end-of-line-diagnostics = "hint"; 27 + inline-diagnostics = { 28 + cursor-line = "warning"; 29 + other-lines = "error"; 30 + }; 31 + }; 32 + 33 + keys.normal = { 34 + space.E = { 35 + command = "@mip<space>e"; 36 + label = "Hard-wrap (rEflow) current paragraph"; 37 + }; 38 + space.e = { 39 + command = ":reflow"; 40 + label = "Hard-wrap (rEflow) selected text"; 41 + }; 42 + }; 43 + }; 44 + 45 + languages = { 46 + language = [ 47 + { 48 + name = "nix"; 49 + formatter = { 50 + command = "${pkgs.nixfmt-rfc-style}/bin/nixfmt"; 51 + }; 52 + } 53 + ]; 54 + }; 55 + }; 56 + }
+8
packetmix/nilla.nix
··· 63 63 }; 64 64 }; 65 65 66 + packages.helix = { 67 + systems = [ "x86_64-linux" ]; 68 + 69 + package = { helix }: helix.overrideAttrs ({ patches ? [], ... }: { 70 + patches = patches ++ [ ./patches/helix/3958-labels-for-config-menus.patch ]; 71 + }); 72 + }; 73 + 66 74 # With a package set defined, we can create a shell. 67 75 shells.default = { 68 76 # Declare what systems the shell can be used on.
+928
packetmix/patches/helix/3958-labels-for-config-menus.patch
··· 1 + From c92e341ee42b33c4c6dcb4e8287a12c03434c164 Mon Sep 17 00:00:00 2001 2 + From: Matthew Cheely <matt_cheely@fastmail.com> 3 + Date: Fri, 23 Sep 2022 21:37:23 -0400 4 + Subject: [PATCH 01/15] Add support for labels in custom menu keymaps 5 + 6 + --- 7 + helix-term/src/config.rs | 33 +++++++++++++++++++++++++++++++++ 8 + helix-term/src/keymap.rs | 17 +++++++++++++---- 9 + 2 files changed, 46 insertions(+), 4 deletions(-) 10 + 11 + diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs 12 + index bcba8d8e1d45..91738f3ef562 100644 13 + --- a/helix-term/src/config.rs 14 + +++ b/helix-term/src/config.rs 15 + @@ -174,6 +174,39 @@ mod tests { 16 + ); 17 + } 18 + 19 + + #[test] 20 + + fn parsing_menus() { 21 + + use crate::keymap; 22 + + use crate::keymap::Keymap; 23 + + use helix_core::hashmap; 24 + + use helix_view::document::Mode; 25 + + 26 + + let sample_keymaps = r#" 27 + + [keys.normal] 28 + + f = { f = "file_picker", c = "wclose" } 29 + + b = { label = "buffer", b = "buffer_picker", n = "goto_next_buffer" } 30 + + "#; 31 + + 32 + + assert_eq!( 33 + + toml::from_str::<Config>(sample_keymaps).unwrap(), 34 + + Config { 35 + + keys: hashmap! { 36 + + Mode::Normal => Keymap::new(keymap!({ "Normal mode" 37 + + "f" => { "" 38 + + "f" => file_picker, 39 + + "c" => wclose, 40 + + }, 41 + + "b" => { "buffer" 42 + + "b" => buffer_picker, 43 + + "n" => goto_next_buffer, 44 + + }, 45 + + })), 46 + + }, 47 + + ..Default::default() 48 + + } 49 + + ); 50 + + } 51 + + 52 + #[test] 53 + fn keys_resolve_to_correct_defaults() { 54 + // From serde default 55 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 56 + index 020ecaf40f0f..01abd708604e 100644 57 + --- a/helix-term/src/keymap.rs 58 + +++ b/helix-term/src/keymap.rs 59 + @@ -197,13 +197,22 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 60 + where 61 + M: serde::de::MapAccess<'de>, 62 + { 63 + + let mut name = ""; 64 + let mut mapping = HashMap::new(); 65 + let mut order = Vec::new(); 66 + - while let Some((key, value)) = map.next_entry::<KeyEvent, KeyTrie>()? { 67 + - mapping.insert(key, value); 68 + - order.push(key); 69 + + 70 + + while let Some(key) = map.next_key::<&str>()? { 71 + + match key { 72 + + "label" => name = map.next_value::<&str>()?, 73 + + _ => { 74 + + let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?; 75 + + let key_trie = map.next_value::<KeyTrie>()?; 76 + + mapping.insert(key_event, key_trie); 77 + + order.push(key_event); 78 + + } 79 + + } 80 + } 81 + - Ok(KeyTrie::Node(KeyTrieNode::new("", mapping, order))) 82 + + Ok(KeyTrie::Node(KeyTrieNode::new(name, mapping, order))) 83 + } 84 + } 85 + 86 + 87 + From be13c26c803ce887fec065ecf817306e89022f1e Mon Sep 17 00:00:00 2001 88 + From: Matthew Cheely <matt_cheely@fastmail.com> 89 + Date: Fri, 23 Sep 2022 23:03:56 -0400 90 + Subject: [PATCH 02/15] Add support for labels on typable commands 91 + 92 + --- 93 + helix-term/src/config.rs | 38 ++++++++++++++++++++++++++++++++++++++ 94 + helix-term/src/keymap.rs | 28 +++++++++++++++++++++++++--- 95 + 2 files changed, 63 insertions(+), 3 deletions(-) 96 + 97 + diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs 98 + index 91738f3ef562..92b4fb8565ce 100644 99 + --- a/helix-term/src/config.rs 100 + +++ b/helix-term/src/config.rs 101 + @@ -207,6 +207,44 @@ mod tests { 102 + ); 103 + } 104 + 105 + + #[test] 106 + + fn parsing_typable_commands() { 107 + + use crate::keymap; 108 + + use crate::keymap::MappableCommand; 109 + + use helix_view::document::Mode; 110 + + use helix_view::input::KeyEvent; 111 + + use std::str::FromStr; 112 + + 113 + + let sample_keymaps = r#" 114 + + [keys.normal] 115 + + o = { label = "Edit Config", command = ":open ~/.config" } 116 + + c = ":buffer-close" 117 + + "#; 118 + + 119 + + let config = toml::from_str::<Config>(sample_keymaps).unwrap(); 120 + + 121 + + let tree = config.keys.get(&Mode::Normal).unwrap().root(); 122 + + 123 + + if let keymap::KeyTrie::Node(node) = tree { 124 + + let open_node = node.get(&KeyEvent::from_str("o").unwrap()).unwrap(); 125 + + 126 + + if let keymap::KeyTrie::Leaf(MappableCommand::Typable { doc, .. }) = open_node { 127 + + assert_eq!(doc, "Edit Config"); 128 + + } else { 129 + + panic!("Edit Config did not parse to typable command"); 130 + + } 131 + + 132 + + let close_node = node.get(&KeyEvent::from_str("c").unwrap()).unwrap(); 133 + + if let keymap::KeyTrie::Leaf(MappableCommand::Typable { doc, .. }) = close_node { 134 + + assert_eq!(doc, ":buffer-close []"); 135 + + } else { 136 + + panic!(":buffer-close command did not parse to typable command"); 137 + + } 138 + + } else { 139 + + panic!("Config did not parse to trie"); 140 + + } 141 + + } 142 + + 143 + #[test] 144 + fn keys_resolve_to_correct_defaults() { 145 + // From serde default 146 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 147 + index 01abd708604e..f157e2fee0dc 100644 148 + --- a/helix-term/src/keymap.rs 149 + +++ b/helix-term/src/keymap.rs 150 + @@ -197,13 +197,15 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 151 + where 152 + M: serde::de::MapAccess<'de>, 153 + { 154 + - let mut name = ""; 155 + + let mut label = ""; 156 + + let mut command = None; 157 + let mut mapping = HashMap::new(); 158 + let mut order = Vec::new(); 159 + 160 + while let Some(key) = map.next_key::<&str>()? { 161 + match key { 162 + - "label" => name = map.next_value::<&str>()?, 163 + + "label" => label = map.next_value::<&str>()?, 164 + + "command" => command = Some(map.next_value::<MappableCommand>()?), 165 + _ => { 166 + let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?; 167 + let key_trie = map.next_value::<KeyTrie>()?; 168 + @@ -212,7 +214,27 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 169 + } 170 + } 171 + } 172 + - Ok(KeyTrie::Node(KeyTrieNode::new(name, mapping, order))) 173 + + 174 + + match command { 175 + + None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), 176 + + Some(cmd) => { 177 + + if label.is_empty() { 178 + + Ok(KeyTrie::Leaf(cmd)) 179 + + } else { 180 + + match cmd { 181 + + MappableCommand::Typable { name, args, .. } => { 182 + + Ok(MappableCommand::Typable { 183 + + name, 184 + + args, 185 + + doc: label.to_string(), 186 + + }) 187 + + .map(KeyTrie::Leaf) 188 + + } 189 + + MappableCommand::Static { .. } => Ok(KeyTrie::Leaf(cmd)), 190 + + } 191 + + } 192 + + } 193 + + } 194 + } 195 + } 196 + 197 + 198 + From 73d8700f601fd0e8bedd19daf1bb094e1e5c0d0b Mon Sep 17 00:00:00 2001 199 + From: Matthew Cheely <matt_cheely@fastmail.com> 200 + Date: Sat, 24 Sep 2022 21:31:15 -0400 201 + Subject: [PATCH 03/15] refactor keymap map visitor to reduce # of cases 202 + 203 + --- 204 + helix-term/src/keymap.rs | 22 +++++++++------------- 205 + 1 file changed, 9 insertions(+), 13 deletions(-) 206 + 207 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 208 + index f157e2fee0dc..98521eb3de08 100644 209 + --- a/helix-term/src/keymap.rs 210 + +++ b/helix-term/src/keymap.rs 211 + @@ -218,20 +218,16 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 212 + match command { 213 + None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), 214 + Some(cmd) => { 215 + - if label.is_empty() { 216 + - Ok(KeyTrie::Leaf(cmd)) 217 + + let status = (cmd, label.is_empty()); 218 + + if let (MappableCommand::Typable { name, args, .. }, false) = status { 219 + + Ok(MappableCommand::Typable { 220 + + name, 221 + + args, 222 + + doc: label.to_string(), 223 + + }) 224 + + .map(KeyTrie::Leaf) 225 + } else { 226 + - match cmd { 227 + - MappableCommand::Typable { name, args, .. } => { 228 + - Ok(MappableCommand::Typable { 229 + - name, 230 + - args, 231 + - doc: label.to_string(), 232 + - }) 233 + - .map(KeyTrie::Leaf) 234 + - } 235 + - MappableCommand::Static { .. } => Ok(KeyTrie::Leaf(cmd)), 236 + - } 237 + + Ok(KeyTrie::Leaf(status.0)) 238 + } 239 + } 240 + } 241 + 242 + From a1c746cdb98a3d492bd81c2d80def81d45463091 Mon Sep 17 00:00:00 2001 243 + From: Matthew Cheely <matt_cheely@fastmail.com> 244 + Date: Tue, 4 Oct 2022 19:18:22 -0400 245 + Subject: [PATCH 04/15] Simplify labelled command pattern match 246 + 247 + Co-authored-by: Michael Davis <mcarsondavis@gmail.com> 248 + --- 249 + helix-term/src/keymap.rs | 19 +++++++------------ 250 + 1 file changed, 7 insertions(+), 12 deletions(-) 251 + 252 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 253 + index 98521eb3de08..cdad51a32567 100644 254 + --- a/helix-term/src/keymap.rs 255 + +++ b/helix-term/src/keymap.rs 256 + @@ -217,19 +217,14 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 257 + 258 + match command { 259 + None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), 260 + - Some(cmd) => { 261 + - let status = (cmd, label.is_empty()); 262 + - if let (MappableCommand::Typable { name, args, .. }, false) = status { 263 + - Ok(MappableCommand::Typable { 264 + - name, 265 + - args, 266 + - doc: label.to_string(), 267 + - }) 268 + - .map(KeyTrie::Leaf) 269 + - } else { 270 + - Ok(KeyTrie::Leaf(status.0)) 271 + - } 272 + + Some(MappableCommand::Typable { name, args, .. }) if !label.is_empty() => { 273 + + Ok(KeyTrie::Leaf(MappableCommand::Typable { 274 + + name, 275 + + args, 276 + + doc: label.to_string(), 277 + + })) 278 + } 279 + + Some(command) => Ok(KeyTrie::Leaf(command)), 280 + } 281 + } 282 + } 283 + 284 + From 789af1ec9fb522a4f3ef70f19f001729a6a0dd25 Mon Sep 17 00:00:00 2001 285 + From: Matthew Cheely <matt_cheely@fastmail.com> 286 + Date: Mon, 17 Oct 2022 20:15:27 -0400 287 + Subject: [PATCH 05/15] Add some basic docs 288 + 289 + --- 290 + book/src/remapping.md | 7 +++++++ 291 + 1 file changed, 7 insertions(+) 292 + 293 + diff --git a/book/src/remapping.md b/book/src/remapping.md 294 + index e3efdf16f851..a0c8acada596 100644 295 + --- a/book/src/remapping.md 296 + +++ b/book/src/remapping.md 297 + @@ -19,6 +19,13 @@ w = "move_line_up" # Maps the 'w' key move_line_up 298 + g = { a = "code_action" } # Maps `ga` to show possible code actions 299 + "ret" = ["open_below", "normal_mode"] # Maps the enter key to open_below then re-enter normal mode 300 + 301 + +# You can create labeled sub-menus and provide friendly labels for typeable commands 302 + +[keys.normal.space.f] # Registering multiple mappings under a single entry creates a sub-menu (accesed by 'space', 'f' in this case) 303 + +label = "File" # The menu is called file and within it: 304 + +f = "file_picker" # 'f' opens the file picker 305 + +s = { label = "Save", command = ":write" } # 's' saves the current file 306 + +c = { label = "Edit Config", command = ":open ~/.config/helix/config.toml" } # 'c' opens the helix config file 307 + + 308 + [keys.insert] 309 + "A-x" = "normal_mode" # Maps Alt-X to enter normal mode 310 + j = { k = "normal_mode" } # Maps `jk` to exit insert mode 311 + 312 + From c1b77b541803a41a2aa0a96a000993eb68b03ef7 Mon Sep 17 00:00:00 2001 313 + From: Matthew Cheely <matt_cheely@fastmail.com> 314 + Date: Tue, 15 Nov 2022 18:42:36 -0500 315 + Subject: [PATCH 06/15] fix typos in menu label docs 316 + 317 + --- 318 + book/src/remapping.md | 4 ++-- 319 + 1 file changed, 2 insertions(+), 2 deletions(-) 320 + 321 + diff --git a/book/src/remapping.md b/book/src/remapping.md 322 + index a0c8acada596..4fb92109e448 100644 323 + --- a/book/src/remapping.md 324 + +++ b/book/src/remapping.md 325 + @@ -20,8 +20,8 @@ g = { a = "code_action" } # Maps `ga` to show possible code actions 326 + "ret" = ["open_below", "normal_mode"] # Maps the enter key to open_below then re-enter normal mode 327 + 328 + # You can create labeled sub-menus and provide friendly labels for typeable commands 329 + -[keys.normal.space.f] # Registering multiple mappings under a single entry creates a sub-menu (accesed by 'space', 'f' in this case) 330 + -label = "File" # The menu is called file and within it: 331 + +[keys.normal.space.f] # Registering multiple mappings under a single entry creates a sub-menu (accessed by 'space', 'f' in this case) 332 + +label = "File" # The menu is called file and within it: 333 + f = "file_picker" # 'f' opens the file picker 334 + s = { label = "Save", command = ":write" } # 's' saves the current file 335 + c = { label = "Edit Config", command = ":open ~/.config/helix/config.toml" } # 'c' opens the helix config file 336 + 337 + From fa8c2372b359674dc1874561351701b95b1b8d02 Mon Sep 17 00:00:00 2001 338 + From: Matthew Cheely <matt_cheely@fastmail.com> 339 + Date: Tue, 15 Nov 2022 21:20:39 -0500 340 + Subject: [PATCH 07/15] return errors for ambiguous and unsupported labels in 341 + menus 342 + 343 + --- 344 + helix-term/src/keymap.rs | 6 ++++++ 345 + 1 file changed, 6 insertions(+) 346 + 347 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 348 + index cdad51a32567..d4eb41176de6 100644 349 + --- a/helix-term/src/keymap.rs 350 + +++ b/helix-term/src/keymap.rs 351 + @@ -217,6 +217,12 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 352 + 353 + match command { 354 + None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), 355 + + Some(_command) if !order.is_empty() => { 356 + + Err(serde::de::Error::custom("ambiguous mapping: 'command' is only valid with 'label', but I found other keys")) 357 + + } 358 + + Some(MappableCommand::Static { .. }) if !label.is_empty() => { 359 + + Err(serde::de::Error::custom("custom labels are only available for typable commands (the ones starting with ':')")) 360 + + } 361 + Some(MappableCommand::Typable { name, args, .. }) if !label.is_empty() => { 362 + Ok(KeyTrie::Leaf(MappableCommand::Typable { 363 + name, 364 + 365 + From fb649610ebd6097789a64a5013d2cb1ef6f04de6 Mon Sep 17 00:00:00 2001 366 + From: Matthew Cheely <matt_cheely@fastmail.com> 367 + Date: Sat, 10 Jun 2023 19:31:36 -0400 368 + Subject: [PATCH 08/15] Fix runtime config parse issues after rebase on latest 369 + master 370 + 371 + --- 372 + helix-term/src/config.rs | 34 ++++++++++++++++++++-------------- 373 + helix-term/src/keymap.rs | 10 +++++----- 374 + 2 files changed, 25 insertions(+), 19 deletions(-) 375 + 376 + diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs 377 + index 92b4fb8565ce..0363311c4d5a 100644 378 + --- a/helix-term/src/config.rs 379 + +++ b/helix-term/src/config.rs 380 + @@ -187,21 +187,27 @@ mod tests { 381 + b = { label = "buffer", b = "buffer_picker", n = "goto_next_buffer" } 382 + "#; 383 + 384 + + let mut keys = keymap::default(); 385 + + merge_keys( 386 + + &mut keys, 387 + + hashmap! { 388 + + Mode::Normal => Keymap::new(keymap!({ "Normal mode" 389 + + "f" => { "" 390 + + "f" => file_picker, 391 + + "c" => wclose, 392 + + }, 393 + + "b" => { "buffer" 394 + + "b" => buffer_picker, 395 + + "n" => goto_next_buffer, 396 + + }, 397 + + })), 398 + + }, 399 + + ); 400 + + 401 + assert_eq!( 402 + - toml::from_str::<Config>(sample_keymaps).unwrap(), 403 + + Config::load_test(sample_keymaps), 404 + Config { 405 + - keys: hashmap! { 406 + - Mode::Normal => Keymap::new(keymap!({ "Normal mode" 407 + - "f" => { "" 408 + - "f" => file_picker, 409 + - "c" => wclose, 410 + - }, 411 + - "b" => { "buffer" 412 + - "b" => buffer_picker, 413 + - "n" => goto_next_buffer, 414 + - }, 415 + - })), 416 + - }, 417 + + keys, 418 + ..Default::default() 419 + } 420 + ); 421 + @@ -221,7 +227,7 @@ mod tests { 422 + c = ":buffer-close" 423 + "#; 424 + 425 + - let config = toml::from_str::<Config>(sample_keymaps).unwrap(); 426 + + let config = Config::load_test(sample_keymaps); 427 + 428 + let tree = config.keys.get(&Mode::Normal).unwrap().root(); 429 + 430 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 431 + index d4eb41176de6..8b4247f03211 100644 432 + --- a/helix-term/src/keymap.rs 433 + +++ b/helix-term/src/keymap.rs 434 + @@ -197,14 +197,14 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 435 + where 436 + M: serde::de::MapAccess<'de>, 437 + { 438 + - let mut label = ""; 439 + + let mut label = String::from(""); 440 + let mut command = None; 441 + let mut mapping = HashMap::new(); 442 + let mut order = Vec::new(); 443 + 444 + - while let Some(key) = map.next_key::<&str>()? { 445 + - match key { 446 + - "label" => label = map.next_value::<&str>()?, 447 + + while let Some(key) = map.next_key::<String>()? { 448 + + match &key as &str { 449 + + "label" => label = map.next_value::<String>()?, 450 + "command" => command = Some(map.next_value::<MappableCommand>()?), 451 + _ => { 452 + let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?; 453 + @@ -216,7 +216,7 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 454 + } 455 + 456 + match command { 457 + - None => Ok(KeyTrie::Node(KeyTrieNode::new(label, mapping, order))), 458 + + None => Ok(KeyTrie::Node(KeyTrieNode::new(label.as_str(), mapping, order))), 459 + Some(_command) if !order.is_empty() => { 460 + Err(serde::de::Error::custom("ambiguous mapping: 'command' is only valid with 'label', but I found other keys")) 461 + } 462 + 463 + From e652d01e0c4b5d1a0f2d784711d2631a914994cb Mon Sep 17 00:00:00 2001 464 + From: Matthew Cheely <matt_cheely@fastmail.com> 465 + Date: Sun, 22 Oct 2023 13:16:40 +1300 466 + Subject: [PATCH 09/15] Fix build after latest rebase 467 + 468 + --- 469 + helix-term/src/keymap.rs | 4 ++-- 470 + 1 file changed, 2 insertions(+), 2 deletions(-) 471 + 472 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 473 + index 8b4247f03211..f4c1b9e7e8dd 100644 474 + --- a/helix-term/src/keymap.rs 475 + +++ b/helix-term/src/keymap.rs 476 + @@ -224,13 +224,13 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 477 + Err(serde::de::Error::custom("custom labels are only available for typable commands (the ones starting with ':')")) 478 + } 479 + Some(MappableCommand::Typable { name, args, .. }) if !label.is_empty() => { 480 + - Ok(KeyTrie::Leaf(MappableCommand::Typable { 481 + + Ok(KeyTrie::MappableCommand(MappableCommand::Typable { 482 + name, 483 + args, 484 + doc: label.to_string(), 485 + })) 486 + } 487 + - Some(command) => Ok(KeyTrie::Leaf(command)), 488 + + Some(command) => Ok(KeyTrie::MappableCommand(command)), 489 + } 490 + } 491 + } 492 + 493 + From 029f7b441464aa3335c48a53d90ca73aee20e458 Mon Sep 17 00:00:00 2001 494 + From: Vulpesx <potaytochipgamer@gmail.com> 495 + Date: Thu, 6 Jun 2024 11:58:19 +1000 496 + Subject: [PATCH 10/15] fix: tests after merging master 497 + 498 + --- 499 + helix-term/src/config.rs | 15 +++++++++------ 500 + 1 file changed, 9 insertions(+), 6 deletions(-) 501 + 502 + diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs 503 + index 0363311c4d5a..1cec5c139741 100644 504 + --- a/helix-term/src/config.rs 505 + +++ b/helix-term/src/config.rs 506 + @@ -177,7 +177,6 @@ mod tests { 507 + #[test] 508 + fn parsing_menus() { 509 + use crate::keymap; 510 + - use crate::keymap::Keymap; 511 + use helix_core::hashmap; 512 + use helix_view::document::Mode; 513 + 514 + @@ -191,7 +190,7 @@ mod tests { 515 + merge_keys( 516 + &mut keys, 517 + hashmap! { 518 + - Mode::Normal => Keymap::new(keymap!({ "Normal mode" 519 + + Mode::Normal => keymap!({ "Normal mode" 520 + "f" => { "" 521 + "f" => file_picker, 522 + "c" => wclose, 523 + @@ -200,7 +199,7 @@ mod tests { 524 + "b" => buffer_picker, 525 + "n" => goto_next_buffer, 526 + }, 527 + - })), 528 + + }), 529 + }, 530 + ); 531 + 532 + @@ -229,19 +228,23 @@ mod tests { 533 + 534 + let config = Config::load_test(sample_keymaps); 535 + 536 + - let tree = config.keys.get(&Mode::Normal).unwrap().root(); 537 + + let tree = config.keys.get(&Mode::Normal).unwrap(); 538 + 539 + if let keymap::KeyTrie::Node(node) = tree { 540 + let open_node = node.get(&KeyEvent::from_str("o").unwrap()).unwrap(); 541 + 542 + - if let keymap::KeyTrie::Leaf(MappableCommand::Typable { doc, .. }) = open_node { 543 + + if let keymap::KeyTrie::MappableCommand(MappableCommand::Typable { doc, .. }) = 544 + + open_node 545 + + { 546 + assert_eq!(doc, "Edit Config"); 547 + } else { 548 + panic!("Edit Config did not parse to typable command"); 549 + } 550 + 551 + let close_node = node.get(&KeyEvent::from_str("c").unwrap()).unwrap(); 552 + - if let keymap::KeyTrie::Leaf(MappableCommand::Typable { doc, .. }) = close_node { 553 + + if let keymap::KeyTrie::MappableCommand(MappableCommand::Typable { doc, .. }) = 554 + + close_node 555 + + { 556 + assert_eq!(doc, ":buffer-close []"); 557 + } else { 558 + panic!(":buffer-close command did not parse to typable command"); 559 + 560 + From 6764c3374c5716a8952b8759317dfb9403f2edf9 Mon Sep 17 00:00:00 2001 561 + From: Vulpesx <potaytochipgamer@gmail.com> 562 + Date: Thu, 6 Jun 2024 15:17:35 +1000 563 + Subject: [PATCH 11/15] feat: labels for sequences 564 + 565 + --- 566 + helix-term/src/config.rs | 28 ++++++++++++ 567 + helix-term/src/keymap.rs | 93 +++++++++++++++++++++++++++++++--------- 568 + 2 files changed, 100 insertions(+), 21 deletions(-) 569 + 570 + diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs 571 + index 1cec5c139741..f9d6966d6ef9 100644 572 + --- a/helix-term/src/config.rs 573 + +++ b/helix-term/src/config.rs 574 + @@ -224,6 +224,8 @@ mod tests { 575 + [keys.normal] 576 + o = { label = "Edit Config", command = ":open ~/.config" } 577 + c = ":buffer-close" 578 + + h = ["vsplit", "normal_mode", "swap_view_left"] 579 + + j = {command = ["hsplit", "normal_mode", {}], label = "split down"} 580 + "#; 581 + 582 + let config = Config::load_test(sample_keymaps); 583 + @@ -249,6 +251,32 @@ mod tests { 584 + } else { 585 + panic!(":buffer-close command did not parse to typable command"); 586 + } 587 + + 588 + + let split_left = node.get(&KeyEvent::from_str("h").unwrap()).unwrap(); 589 + + if let keymap::KeyTrie::Sequence(label, cmds) = split_left { 590 + + assert_eq!(label, KeyTrie::DEFAULT_SEQUENCE_LABEL); 591 + + assert_eq!( 592 + + *cmds, 593 + + vec![ 594 + + MappableCommand::vsplit, 595 + + MappableCommand::normal_mode, 596 + + MappableCommand::swap_view_left 597 + + ] 598 + + ); 599 + + } 600 + + 601 + + let split_down = node.get(&KeyEvent::from_str("j").unwrap()).unwrap(); 602 + + if let keymap::KeyTrie::Sequence(label, cmds) = split_down { 603 + + assert_eq!(label, "split down"); 604 + + assert_eq!( 605 + + *cmds, 606 + + vec![ 607 + + MappableCommand::hsplit, 608 + + MappableCommand::normal_mode, 609 + + MappableCommand::swap_view_down 610 + + ] 611 + + ); 612 + + } 613 + } else { 614 + panic!("Config did not parse to trie"); 615 + } 616 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 617 + index f4c1b9e7e8dd..77a8bc58695b 100644 618 + --- a/helix-term/src/keymap.rs 619 + +++ b/helix-term/src/keymap.rs 620 + @@ -12,6 +12,7 @@ use std::{ 621 + borrow::Cow, 622 + collections::{BTreeSet, HashMap}, 623 + ops::{Deref, DerefMut}, 624 + + str::FromStr, 625 + sync::Arc, 626 + }; 627 + 628 + @@ -83,7 +84,7 @@ impl KeyTrieNode { 629 + cmd.doc() 630 + } 631 + KeyTrie::Node(n) => &n.name, 632 + - KeyTrie::Sequence(_) => "[Multiple commands]", 633 + + KeyTrie::Sequence(..) => KeyTrie::DEFAULT_SEQUENCE_LABEL, 634 + }; 635 + match body.iter().position(|(_, d)| d == &desc) { 636 + Some(pos) => { 637 + @@ -133,10 +134,18 @@ impl DerefMut for KeyTrieNode { 638 + #[derive(Debug, Clone, PartialEq)] 639 + pub enum KeyTrie { 640 + MappableCommand(MappableCommand), 641 + - Sequence(Vec<MappableCommand>), 642 + + Sequence(String, Vec<MappableCommand>), 643 + Node(KeyTrieNode), 644 + } 645 + 646 + +impl KeyTrie { 647 + + pub const DEFAULT_SEQUENCE_LABEL: &'static str = "[Multiple commands]"; 648 + + 649 + + pub fn sequence(commands: Vec<MappableCommand>) -> Self { 650 + + Self::Sequence(Self::DEFAULT_SEQUENCE_LABEL.to_string(), commands) 651 + + } 652 + +} 653 + + 654 + impl<'de> Deserialize<'de> for KeyTrie { 655 + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> 656 + where 657 + @@ -190,7 +199,10 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 658 + )); 659 + } 660 + 661 + - Ok(KeyTrie::Sequence(commands)) 662 + + Ok(KeyTrie::Sequence( 663 + + KeyTrie::DEFAULT_SEQUENCE_LABEL.to_string(), 664 + + commands, 665 + + )) 666 + } 667 + 668 + fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> 669 + @@ -205,7 +217,35 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 670 + while let Some(key) = map.next_key::<String>()? { 671 + match &key as &str { 672 + "label" => label = map.next_value::<String>()?, 673 + - "command" => command = Some(map.next_value::<MappableCommand>()?), 674 + + "command" => { 675 + + command = Some(match map.next_value::<toml::Value>()? { 676 + + toml::Value::String(s) => { 677 + + vec![MappableCommand::from_str(&s).map_err(serde::de::Error::custom)?] 678 + + } 679 + + toml::Value::Array(arr) => { 680 + + let mut vec = Vec::with_capacity(arr.len()); 681 + + for value in arr { 682 + + let toml::Value::String(s) = value else { 683 + + return Err(serde::de::Error::invalid_type( 684 + + serde::de::Unexpected::Other(value.type_str()), 685 + + &"string", 686 + + )); 687 + + }; 688 + + vec.push( 689 + + MappableCommand::from_str(&s) 690 + + .map_err(serde::de::Error::custom)?, 691 + + ); 692 + + } 693 + + vec 694 + + } 695 + + value => { 696 + + return Err(serde::de::Error::invalid_type( 697 + + serde::de::Unexpected::Other(value.type_str()), 698 + + &"string or array", 699 + + )) 700 + + } 701 + + }); 702 + + } 703 + _ => { 704 + let key_event = key.parse::<KeyEvent>().map_err(serde::de::Error::custom)?; 705 + let key_trie = map.next_value::<KeyTrie>()?; 706 + @@ -220,17 +260,28 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 707 + Some(_command) if !order.is_empty() => { 708 + Err(serde::de::Error::custom("ambiguous mapping: 'command' is only valid with 'label', but I found other keys")) 709 + } 710 + - Some(MappableCommand::Static { .. }) if !label.is_empty() => { 711 + - Err(serde::de::Error::custom("custom labels are only available for typable commands (the ones starting with ':')")) 712 + - } 713 + - Some(MappableCommand::Typable { name, args, .. }) if !label.is_empty() => { 714 + - Ok(KeyTrie::MappableCommand(MappableCommand::Typable { 715 + - name, 716 + - args, 717 + - doc: label.to_string(), 718 + - })) 719 + + Some(mut commands) if commands.len() == 1 => match commands.pop() { 720 + + None => Err(serde::de::Error::custom("UNREACHABLE!, vec is empty after checking len == 1")), 721 + + Some(MappableCommand::Static { .. }) if !label.is_empty() => { 722 + + Err(serde::de::Error::custom("custom labels are only available for typable commands (the ones starting with ':')")) 723 + + } 724 + + Some(MappableCommand::Typable { name, args, .. }) if !label.is_empty() => { 725 + + Ok(KeyTrie::MappableCommand(MappableCommand::Typable { 726 + + name, 727 + + args, 728 + + doc: label, 729 + + })) 730 + + } 731 + + Some(command) => Ok(KeyTrie::MappableCommand(command)), 732 + } 733 + - Some(command) => Ok(KeyTrie::MappableCommand(command)), 734 + + Some(commands) => { 735 + + let label = if label.is_empty() { 736 + + KeyTrie::DEFAULT_SEQUENCE_LABEL.to_string() 737 + + } else { 738 + + label 739 + + }; 740 + + Ok(KeyTrie::Sequence(label, commands)) 741 + + }, 742 + } 743 + } 744 + } 745 + @@ -254,7 +305,7 @@ impl KeyTrie { 746 + keys.pop(); 747 + } 748 + } 749 + - KeyTrie::Sequence(_) => {} 750 + + KeyTrie::Sequence(..) => {} 751 + }; 752 + } 753 + 754 + @@ -266,14 +317,14 @@ impl KeyTrie { 755 + pub fn node(&self) -> Option<&KeyTrieNode> { 756 + match *self { 757 + KeyTrie::Node(ref node) => Some(node), 758 + - KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None, 759 + + KeyTrie::MappableCommand(_) | KeyTrie::Sequence(..) => None, 760 + } 761 + } 762 + 763 + pub fn node_mut(&mut self) -> Option<&mut KeyTrieNode> { 764 + match *self { 765 + KeyTrie::Node(ref mut node) => Some(node), 766 + - KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None, 767 + + KeyTrie::MappableCommand(_) | KeyTrie::Sequence(..) => None, 768 + } 769 + } 770 + 771 + @@ -290,7 +341,7 @@ impl KeyTrie { 772 + trie = match trie { 773 + KeyTrie::Node(map) => map.get(key), 774 + // leaf encountered while keys left to process 775 + - KeyTrie::MappableCommand(_) | KeyTrie::Sequence(_) => None, 776 + + KeyTrie::MappableCommand(_) | KeyTrie::Sequence(..) => None, 777 + }? 778 + } 779 + Some(trie) 780 + @@ -380,7 +431,7 @@ impl Keymaps { 781 + Some(KeyTrie::MappableCommand(ref cmd)) => { 782 + return KeymapResult::Matched(cmd.clone()); 783 + } 784 + - Some(KeyTrie::Sequence(ref cmds)) => { 785 + + Some(KeyTrie::Sequence(_, ref cmds)) => { 786 + return KeymapResult::MatchedSequence(cmds.clone()); 787 + } 788 + None => return KeymapResult::NotFound, 789 + @@ -400,7 +451,7 @@ impl Keymaps { 790 + self.state.clear(); 791 + KeymapResult::Matched(cmd.clone()) 792 + } 793 + - Some(KeyTrie::Sequence(cmds)) => { 794 + + Some(KeyTrie::Sequence(_, cmds)) => { 795 + self.state.clear(); 796 + KeymapResult::MatchedSequence(cmds.clone()) 797 + } 798 + @@ -625,7 +676,7 @@ mod tests { 799 + let expectation = KeyTrie::Node(KeyTrieNode::new( 800 + "", 801 + hashmap! { 802 + - key => KeyTrie::Sequence(vec!{ 803 + + key => KeyTrie::sequence(vec!{ 804 + MappableCommand::select_all, 805 + MappableCommand::Typable { 806 + name: "pipe".to_string(), 807 + 808 + From bb8a44cec0cfcff0cd4eba3b3c4157b65bddcc86 Mon Sep 17 00:00:00 2001 809 + From: Vulpesx <potaytochipgamer@gmail.com> 810 + Date: Thu, 6 Jun 2024 15:48:56 +1000 811 + Subject: [PATCH 12/15] fix: forgor to tell helix to display sequence labels 812 + 813 + --- 814 + helix-term/src/keymap.rs | 2 +- 815 + 1 file changed, 1 insertion(+), 1 deletion(-) 816 + 817 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 818 + index 77a8bc58695b..f47160e73b2f 100644 819 + --- a/helix-term/src/keymap.rs 820 + +++ b/helix-term/src/keymap.rs 821 + @@ -84,7 +84,7 @@ impl KeyTrieNode { 822 + cmd.doc() 823 + } 824 + KeyTrie::Node(n) => &n.name, 825 + - KeyTrie::Sequence(..) => KeyTrie::DEFAULT_SEQUENCE_LABEL, 826 + + KeyTrie::Sequence(l, ..) => l, 827 + }; 828 + match body.iter().position(|(_, d)| d == &desc) { 829 + Some(pos) => { 830 + 831 + From e625945398dbbae475f13a2375a0a6b427a4ff16 Mon Sep 17 00:00:00 2001 832 + From: Nylme <nylme@protonmail.com> 833 + Date: Tue, 19 Nov 2024 08:09:21 +1100 834 + Subject: [PATCH 13/15] Fixed deserializing macro labels/names from .toml 835 + keymap 836 + 837 + --- 838 + helix-term/src/keymap.rs | 9 +++++++++ 839 + 1 file changed, 9 insertions(+) 840 + 841 + diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs 842 + index f47160e73b2f..a01a05f866bb 100644 843 + --- a/helix-term/src/keymap.rs 844 + +++ b/helix-term/src/keymap.rs 845 + @@ -272,6 +272,15 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor { 846 + doc: label, 847 + })) 848 + } 849 + + 850 + + // To label/name macro commands from config 851 + + Some(MappableCommand::Macro { keys, .. }) if !label.is_empty() => { 852 + + Ok(KeyTrie::MappableCommand(MappableCommand::Macro { 853 + + keys, 854 + + name: label 855 + + })) 856 + + } 857 + + 858 + Some(command) => Ok(KeyTrie::MappableCommand(command)), 859 + } 860 + Some(commands) => { 861 + 862 + From af83072ebf66a04f8033cbbfcb7ca0a454c8c6f2 Mon Sep 17 00:00:00 2001 863 + From: Nylme <nylme@protonmail.com> 864 + Date: Tue, 19 Nov 2024 22:29:26 +1100 865 + Subject: [PATCH 14/15] parsing_typeable_commands: fixed test 866 + 867 + --- 868 + helix-term/src/config.rs | 2 +- 869 + 1 file changed, 1 insertion(+), 1 deletion(-) 870 + 871 + diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs 872 + index f9d6966d6ef9..abc6784486cb 100644 873 + --- a/helix-term/src/config.rs 874 + +++ b/helix-term/src/config.rs 875 + @@ -225,7 +225,7 @@ mod tests { 876 + o = { label = "Edit Config", command = ":open ~/.config" } 877 + c = ":buffer-close" 878 + h = ["vsplit", "normal_mode", "swap_view_left"] 879 + - j = {command = ["hsplit", "normal_mode", {}], label = "split down"} 880 + + j = {command = ["hsplit", "normal_mode", "swap_view_down"], label = "split down"} 881 + "#; 882 + 883 + let config = Config::load_test(sample_keymaps); 884 + 885 + From 8e7e1283a572379bef40e5b8deb3ecef4e7962ac Mon Sep 17 00:00:00 2001 886 + From: Nylme <nylme@protonmail.com> 887 + Date: Tue, 19 Nov 2024 22:32:20 +1100 888 + Subject: [PATCH 15/15] parsing_typeable_commands: added test for macro command 889 + labels 890 + 891 + --- 892 + helix-term/src/config.rs | 15 +++++++++++++++ 893 + 1 file changed, 15 insertions(+) 894 + 895 + diff --git a/helix-term/src/config.rs b/helix-term/src/config.rs 896 + index abc6784486cb..4c2340e91226 100644 897 + --- a/helix-term/src/config.rs 898 + +++ b/helix-term/src/config.rs 899 + @@ -226,6 +226,7 @@ mod tests { 900 + c = ":buffer-close" 901 + h = ["vsplit", "normal_mode", "swap_view_left"] 902 + j = {command = ["hsplit", "normal_mode", "swap_view_down"], label = "split down"} 903 + + n = { label = "Delete word", command = "@wd" } 904 + "#; 905 + 906 + let config = Config::load_test(sample_keymaps); 907 + @@ -277,6 +278,20 @@ mod tests { 908 + ] 909 + ); 910 + } 911 + + 912 + + let macro_keys = node.get(&KeyEvent::from_str("n").unwrap()).unwrap(); 913 + + if let keymap::KeyTrie::MappableCommand(MappableCommand::Macro { name, keys }) = 914 + + macro_keys 915 + + { 916 + + assert_eq!(name, "Delete word"); 917 + + assert_eq!( 918 + + keys, 919 + + &vec![ 920 + + KeyEvent::from_str("w").unwrap(), 921 + + KeyEvent::from_str("d").unwrap() 922 + + ] 923 + + ); 924 + + } 925 + } else { 926 + panic!("Config did not parse to trie"); 927 + } 928 +
+5
packetmix/patches/helix/3958-labels-for-config-menus.patch.license
··· 1 + SPDX-FileCopyrightText: 2025 Matthew Cheely <matt_cheely@fastmail.com> 2 + SPDX-FileCopyrightText: 2025 Nylme <nylme@protonmail.com> 3 + SPDX-FileCopyrightText: 2025 Vulpesx <potaytochipgamer@gmail.com> 4 + 5 + SPDX-License-Identifier: MPL-2.0