From 5005c14e99ff5037ed29a8c0a9119a564943c768 Mon Sep 17 00:00:00 2001 From: TornaxO7 Date: Tue, 10 Dec 2024 00:31:41 +0100 Subject: [PATCH] Add config option for continue commenting (#12213) Co-authored-by: Michael Davis --- book/src/editor.md | 1 + helix-term/src/commands.rs | 22 ++++++++++++++-------- helix-view/src/editor.rs | 4 ++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/book/src/editor.md b/book/src/editor.md index 241d5056346a..64800625e889 100644 --- a/book/src/editor.md +++ b/book/src/editor.md @@ -31,6 +31,7 @@ | `line-number` | Line number display: `absolute` simply shows each line's number, while `relative` shows the distance from the current line. When unfocused or in insert mode, `relative` will still show absolute line numbers | `absolute` | | `cursorline` | Highlight all lines with a cursor | `false` | | `cursorcolumn` | Highlight all columns with a cursor | `false` | +| `continue-comments` | if helix should automatically add a line comment token if you create a new line inside a comment. | `false` | | `gutters` | Gutters to display: Available are `diagnostics` and `diff` and `line-numbers` and `spacer`, note that `diagnostics` also includes other features like breakpoints, 1-width padding will be inserted if gutters is non-empty | `["diagnostics", "spacer", "line-numbers", "spacer", "diff"]` | | `auto-completion` | Enable automatic pop up of auto-completion | `true` | | `path-completion` | Enable filepath completion. Show files and directories if an existing path at the cursor was recognized, either absolute or relative to the current opened document or current working directory (if the buffer is not yet saved). Defaults to true. | `true` | diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index d08148362e25..27c852a7b2e2 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3486,10 +3486,13 @@ fn open(cx: &mut Context, open: Open) { ) }; - let continue_comment_token = doc - .language_config() - .and_then(|config| config.comment_tokens.as_ref()) - .and_then(|tokens| comment::get_comment_token(text, tokens, cursor_line)); + let continue_comment_token = if doc.config.load().continue_comments { + doc.language_config() + .and_then(|config| config.comment_tokens.as_ref()) + .and_then(|tokens| comment::get_comment_token(text, tokens, cursor_line)) + } else { + None + }; let line = text.line(cursor_line); let indent = match line.first_non_whitespace_char() { @@ -3965,10 +3968,13 @@ pub mod insert { let mut new_text = String::new(); - let continue_comment_token = doc - .language_config() - .and_then(|config| config.comment_tokens.as_ref()) - .and_then(|tokens| comment::get_comment_token(text, tokens, current_line)); + let continue_comment_token = if doc.config.load().continue_comments { + doc.language_config() + .and_then(|config| config.comment_tokens.as_ref()) + .and_then(|tokens| comment::get_comment_token(text, tokens, current_line)) + } else { + None + }; let (from, to, local_offs) = if let Some(idx) = text.slice(line_start..pos).last_non_whitespace_char() diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 4fc3f4700a1e..3b4e4a5c7b51 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -304,6 +304,9 @@ pub struct Config { /// Whether to instruct the LSP to replace the entire word when applying a completion /// or to only insert new text pub completion_replace: bool, + /// `true` if helix should automatically add a line comment token if you're currently in a comment + /// and press `enter`. + pub continue_comments: bool, /// Whether to display infoboxes. Defaults to true. pub auto_info: bool, pub file_picker: FilePickerConfig, @@ -985,6 +988,7 @@ impl Default for Config { }, text_width: 80, completion_replace: false, + continue_comments: true, workspace_lsp_roots: Vec::new(), default_line_ending: LineEndingConfig::default(), insert_final_newline: true,