on master help sign in
Add option for automatic insertion of closing-parens/brackets/etc (#779)
a958d34lurpahi
book/src/configuration.md+1
@@ -18,6 +18,7 @@ To override global configuration parameters, create a `config.toml` file located
18| `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
18| `shell` | Shell to use when running external commands. | Unix: `["sh", "-c"]`<br/>Windows: `["cmd", "/C"]` |
19| `line-number` | Line number display (`absolute`, `relative`) | `absolute` |
19| `line-number` | Line number display (`absolute`, `relative`) | `absolute` |
20| `smart-case` | Enable smart case regex searching (case insensitive unless pattern contains upper case characters) | `true` |
20| `smart-case` | Enable smart case regex searching (case insensitive unless pattern contains upper case characters) | `true` |
21+| `auto-pairs` | Enable automatic insertion of pairs to parenthese, brackets, etc. | `true` |
21
22
22## LSP
23## LSP
23
24
helix-term/src/commands.rs+7−4
@@ -3371,17 +3371,20 @@ pub mod insert {
3371 }
3371 }
3372
3372
3373 use helix_core::auto_pairs;
3373 use helix_core::auto_pairs;
3374− const HOOKS: &[Hook] = &[auto_pairs::hook, insert];
3375− const POST_HOOKS: &[PostHook] = &[completion, signature_help];
3376
3374
3377 pub fn insert_char(cx: &mut Context, c: char) {
3375 pub fn insert_char(cx: &mut Context, c: char) {
3378 let (view, doc) = current!(cx.editor);
3376 let (view, doc) = current!(cx.editor);
3379
3377
3378+ let hooks: &[Hook] = match cx.editor.config.auto_pairs {
3379+ true => &[auto_pairs::hook, insert],
3380+ false => &[insert],
3381+ };
3382+
3380 let text = doc.text();
3383 let text = doc.text();
3381 let selection = doc.selection(view.id).clone().cursors(text.slice(..));
3384 let selection = doc.selection(view.id).clone().cursors(text.slice(..));
3382
3385
3383 // run through insert hooks, stopping on the first one that returns Some(t)
3386 // run through insert hooks, stopping on the first one that returns Some(t)
3384− for hook in HOOKS {
3387+ for hook in hooks {
3385 if let Some(transaction) = hook(text, &selection, c) {
3388 if let Some(transaction) = hook(text, &selection, c) {
3386 doc.apply(&transaction, view.id);
3389 doc.apply(&transaction, view.id);
3387 break;
3390 break;
@@ -3391,7 +3394,7 @@ pub mod insert {
3391 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
3394 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
3392 // this could also generically look at Transaction, but it's a bit annoying to look at
3395 // this could also generically look at Transaction, but it's a bit annoying to look at
3393 // Operation instead of Change.
3396 // Operation instead of Change.
3394− for hook in POST_HOOKS {
3397+ for hook in &[completion, signature_help] {
3395 hook(cx, c);
3398 hook(cx, c);
3396 }
3399 }
3397 }
3400 }
helix-view/src/editor.rs+3
@@ -41,6 +41,8 @@ pub struct Config {
41 pub middle_click_paste: bool,
41 pub middle_click_paste: bool,
42 /// Smart case: Case insensitive searching unless pattern contains upper case characters. Defaults to true.
42 /// Smart case: Case insensitive searching unless pattern contains upper case characters. Defaults to true.
43 pub smart_case: bool,
43 pub smart_case: bool,
44+ /// Automatic insertion of pairs to parentheses, brackets, etc. Defaults to true.
45+ pub auto_pairs: bool,
44}
46}
45
47
46#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
48#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
@@ -67,6 +69,7 @@ impl Default for Config {
67 line_number: LineNumber::Absolute,
69 line_number: LineNumber::Absolute,
68 middle_click_paste: true,
70 middle_click_paste: true,
69 smart_case: true,
71 smart_case: true,
72+ auto_pairs: true,
70 }
73 }
71 }
74 }
72}
75}