from some@programming.dev to programming@programming.dev on 03 Jul 22:37
https://programming.dev/post/33310905
I noticed that the developer of kitty
terminal uses this style of comments I have rarely if ever seen elsewhere:
outside #: section {{{ inside #: }}}
Kate text editor recognize sections for purposes of highlighting, folding etc. It’s really nice for me because I sometimes I have a difficult time navigating large text files. And it lets you nest them.
- what is this called?
- are there other ways to do it?
- is it standard among text editors? I believe Kovid the dev for
kitty
is avim
guy so presumably there is support there also. - why don’t more people use it? are there problems?
Screenshot that shows the code folding.
- Cursor is at the end of line 7 so the whole section line 7-22 is highlighted
- lines 12-16 are folded in a 3rd level comment
- I also included tab indents just to make it easier to see what’s going on (Kate treats it the same way regardless of indents)
- Highlighting/Mode > Scripts > Bash
I also like his style of distinguishing between narrative comments (starting with #:
) and commented-out code (starting with #
). Although in my example, Kate doesn’t treat them differently. Is there a term for this? Any conventions, support etc?
plain text used for screenshot
bash #: Comment level 1 {{{ #: Comment level 2 {{{ #: configure something key value #: }}} #: Another Comment level 2 {{{ #: Comment level 3 {{{ #: Helpful explanatory comment file location #: }}} #: Comment level 3 with hidden text {{{ you_cant see_this hidden_emoji “👁️” hidden_emoji2 " 👁️" hidden_emoji3 " 👁️" #: }}} #: let’s set some things up # setting yes # other_setting no different_setting maybe #: }}} # regular comment #: }}} # regular comment outside anything
___
For a real world example, see sample kitty.conf
file provided on project website.
threaded - newest
Marker-based folding
Thanks! Searching for this led me to this extremely charming website where in addition to robust folding, the author argues in favor of proportional width fonts and tabstops (not spaces) in coding. Unconventional. It’s nice to know someone who processes text in a similar way to me can be a successful programmer. Even if they had to write their own tools. tibleiz.net/code-browser/elastic-tabstops.html
BTW, my personal note about the tabstops for indentation is, I wish everyone would use it over spaces. Because it would make it much easier to display the file differently without changing it. Also parsing it would make it easier too probably. But since spaces are the standard, I exclusively use space for indentation.
I actually think the argument for mixing tabs and spaces makes a lot of sense. Use tabs for indentation, coupled with spaces for alignment (e.g. of function arguments). It eliminates the downsides of using tabs resp. spaces exclusively. But since nobody uses it, I never have either. Following the style of the project at hand is the way.
You mean alignment of arguments or multiline strings in example? If they are not on their own line, then it does not matter to me. If they start on their own line, then mixing spaces and tabs isn’t a good idea to me. In example for function calls with a bit more complex calls and multiple arguments, I put them in their own line each. They are indented and therefore indentation level plays. If they are on the same line, I never align them and if I would, it would be spaces. In general:
^(update: just added a new link)^
The way you describe and show it, is called foldmethod “marker”. The advantage of markers are, that they are built into the file. The disadvantage is, its built into the file. I rather like having the source independent from folding markers. The good news is, you can change the foldingmethod in Neovim and ignore the marker comments and instead use your own method.
A simple one is just “manual”, where you set what is foldable and not. There are some automatic ones, like based on indentation and such. I was never a folding guy anyway, so don’t really know all the differences when to use and how they differ. Neovim has following foldmethod: manual, indent, expr, syntax, diff, marker. The “expr” method even allows you a custom code and logic.
It makes sense it’s a Vim thing since it’s used in kitty config. When I search for marker based folding as someone else said it’s called above, almost everything I get is for Vim. It’s always confused me why gui-based text editors seem to not have a lot of visually-based features like this compared to terminal-based editors. I guess it’s harder to create a system for user customization in a GUI application.
At least Kate has some support. Now that I know what it’s called I will look into what else is available there.
It’s often better to split code in smaller functions tho, and give these good names.
I am probably a bit over the top with this tbh. I put everything in functions, even single-use activities like declaring initial variables at the beginning. I just do it to enable the code folding. Even though everything I do is small time and I’m sure it’s not excessively burdensome on the system, it seems wasteful to me to have the computer hold a the function in memory when it’s never going to get used again. So I was thinking this might be more efficient in such cases.