Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto comment continuation also happens with shebangs #12423

Open
schrottkatze opened this issue Jan 6, 2025 · 8 comments · May be fixed by #12663
Open

Auto comment continuation also happens with shebangs #12423

schrottkatze opened this issue Jan 6, 2025 · 8 comments · May be fixed by #12663
Labels
C-enhancement Category: Improvements

Comments

@schrottkatze
Copy link

When writing stuff like a shell script, you usually write a shebang at the start.

The shebang, however, looks like a comment in many shell languages because they use # as comment syntax.

Also, maybe adding a way to not extend the comment (idk... shift-enter?) would be cool :)

Thanks!

@schrottkatze schrottkatze added the C-enhancement Category: Improvements label Jan 6, 2025
@sibouras
Copy link

sibouras commented Jan 6, 2025

you can ]<space> to add newline below, or go down a line and O

or if u want a mapping ["add_newline_below", "move_visual_line_down", "insert_mode"]

@nik-rev
Copy link
Contributor

nik-rev commented Jan 7, 2025

Really like your idea to have a keymap for adding newline without continuing the comment. See linked PR above ^^

@uncenter
Copy link
Contributor

uncenter commented Jan 7, 2025

I feel like even some sort of naive detection would work, something like: if the comment character is "#", the first character following the start character is a "!", and the cursor is on the first line of the file - don't continue the "comment".

@TornaxO7
Copy link
Contributor

TornaxO7 commented Jan 7, 2025

You can also just press <C-w> to remove a word in front of your cursor (it's also a keybinding in the terminal and pretty useful in my opinion).

@TornaxO7
Copy link
Contributor

I feel like even some sort of naive detection would work, something like: if the comment character is "#", the first character following the start character is a "!", and the cursor is on the first line of the file - don't continue the "comment".

Hm... I don't really see it as a trivial problem which can be fixed unless we apply this check only to bash.
Rust for example uses ! after // to mark it as a module documentation.

@nik-rev
Copy link
Contributor

nik-rev commented Jan 16, 2025

I feel like even some sort of naive detection would work, something like: if the comment character is "#", the first character following the start character is a "!", and the cursor is on the first line of the file - don't continue the "comment".

Hm... I don't really see it as a trivial problem which can be fixed unless we apply this check only to bash.
Rust for example uses ! after // to mark it as a module documentation.

I remember seeing somewhere in the codebase a SHEBANG_REGEX (probs different name) const str which is a regex. That could probably be re-used for this

@nik-rev
Copy link
Contributor

nik-rev commented Jan 24, 2025

Ah, I found it, helix-core/src/syntax.rs:

const SHEBANG: &str = r"#!\s*(?:\S*[/\\](?:env\s+(?:\-\S+\s+)*)?)?([^\s\.\d]+)";

When we continue line comments, perhaps we could

  1. check if the current line index is 0, so we are on a (possibly) shebang line
  2. check the regex against the line

@TornaxO7
Copy link
Contributor

Let me try to create a PR for this then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants