JavaScript/jsdoc Comment Blocks

Hey all!

I’m looking for something to make comment blocks in JacaScript (or other languages) easier. Specifically what I’m looking for is something that automatically adds * to the front of lines when I press <ret> inside a block starting with /*. This is pretty common formatting for multi line block comments. Is there anything built in or a plug-in for this?

If not, can anyone point me in the right direction for scripting this myself? Mainly, how would I determine that my cursor is currently inside a comment block? Would I need to do some manual parsing or is there something built in to help with that?

Thanks!

Whoa, I’m surprised this doesn’t already happen, since we already do // in JavaScript, bullets in markdown, and … we already handle /* like this in C.

Looks like the relevant part from C could be copied into the javascript’s javascript-insert-on-new-line.

Thanks Jason, will take a look at that. Always good to hear from you!

Hi joe, eraserhd comments

spot on, I recently did just this with c-family.kak#L140 for kotlin and java plugins and was: no mess, no fuss. A verbatim copy and paste was all I needed, also checkout the other indent and insert commands in the c-family.kak as you might like I did find that 99% copy and paste does a brilliant job for remaining tasks.

All the best, bye.

Thanks for the tips about copying the relevant bits from the c-family.kak script! This seems to work perfectly.

However, it makes me wonder what other nice features might already be implemented for one language but not for others. It also makes me consider whether there might be a clean way of extracting a layer of “primitive” commands to more easily share such features across the filetype scripts. Small differences between languages may make this impractical, but it could be worth some thought…

While all the critical information has been stated by the previous posters, I think it may also be worth explicitly stating how to accomplish this for one new to Kakoune:

  • Kakoune ships with extension scripts for filetype-specific functionality, which are by default installed to the /usr/local/share/kak/rc/filetype directory.
  • To get the functionality in question for JavaScript files, you can copy and paste some of the code from the c-family.kak script to the javascript.kak script verbatim.
    1. I realized I have an older version of the scripts which do not include an “insert-on-newline” command for JavaScript, so I did the following:
      a. Copy over the c-family-insert-on-newline command definition, as seen here.
      b. Copy the associated hook into the WinSetOption hook body, seen here.
    2. If you do have the “insert-on-newline” function in your JavaScript filetype file then you should be able to simply replace it’s body with the body of the c-family version and be good to go.

There may be some details in the c-family-insert-on-newline command that aren’t right for JavaScript, but it seems to be pretty spot-on in my initial testing.

Absolutely. This discussion was brought up a few times in GitHub issues. Here’s an example about mutualizing the trailing of whitespaces between rc files : https://github.com/mawww/kakoune/issues/2175