jmacdonald / amp

A complete text editor for your terminal.
https://amp.rs
Other
3.68k stars 105 forks source link

Add command to comment out a selection of text #204

Closed christoph-heiss closed 3 years ago

christoph-heiss commented 3 years ago

[Closes #100]

Hi!

This implements the buffer::toggle_line_comment for normal and select_line mode. It either:

I'm really used to that functionality to quickly comment in/out something, so I though I'd implement this. This works only for languages which have single-line comments. We could extend that to block comments, but I don't think that is much of a priority (at least for me).

I made a small gif on how this functionality looks.

~~How a comment starts is defined in a Hashmap, based on the syntax scope of the buffer. I already added quite a few languages, I tried to pick the most likely-to-be-used. We can extend that list easily in the future as needed. Question: Should there be a way for users to define their own entries in their preferences file? Could be useful I guess. 😅~~

Also, for now I assigned the command to [. I can of course happily change that if you want.

cpfiffer commented 3 years ago

I like it!

christoph-heiss commented 3 years ago

Just pushed a new spin of this PR, addressing all your suggestions.

This PR got definitely bigger than I expected! Anyway, to properly support having the line comment prefix in the preferences, overridable by the user, I had to first move all our defaults from constant to a external yaml file. I've done that similiar to how src/input/key_map/ does it, I hope that is fine.

But I also like this solution way more than having a hashmap in-code.