0

How to enable commenting of .asy files in Kate?

In the Kate editor, for some types of files, one can comment and uncomment lines by pressing Ctrl+D and Ctrl+Shift+D. But, in Kate's default configuration, this is not possible for .asy files (associated with Asymptote). Nothing happens if Ctrl+D is pressed (and also nothing happens if Ctrl+/ is pressed, and the 'Toggle comment' is grayed out in Tools).

The appropriate commenting symbol for .asy files is //.

I thought the solution could be if Kate had the proper highlighting .xml file for .asy files. I found the instructions for generating that file here. The relevant directory (the one containing the script asy-kate.sh) was a bit different for me (/usr/share/asymptote/ rather than /usr/local/share/asymptote). Also, the script asy-kate.sh needed the file asy-keywords.el, and was complaining that it was missing. I found that file elsewhere in my system (in /usr/share/emacs/site-lisp/) and I copied it to /usr/share/asymptote/. Now asy-kate.sh ran without problems, and produced a reasonable-looking asymptote.xml file.

The next question was where to put it. After some googling, two candidate directories turned up: ~/.kde/share/apps/katepart/syntax/ and ~/.local/share/katepart5/syntax/. I created them and placed asymptote.xml in both. I restarted Kate, but unfortunately the new .xml files seemed to have no effect: for one, nothing was highlighted in my .asy files, and, more important for my purposes, the Ctrl+D still wasn't working and 'Toggle comment' was still grayed out.

How can I configure kate so that Ctrl+D and Ctrl+Shift+D work properly with .asy files?

Here is my system:

Operating System: Kubuntu 20.04
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8
Kernel Version: 5.4.0-70-generic
OS Type: 64-bit

The Kate version is 19.12.3.

fra-san
  • 9,931
  • 2
  • 21
  • 42

1 Answers1

1

Using Kate 20.12.3 from KDE Plasma Desktop 5.21.3.

Inspired by this answer, I created a custom theme (in Kate, Settings → Configure Kate → Open/Save → Modes & Filetypes) to let the user-specific directory for themes appear. It happens to be

~/.local/share/org.kde.syntax-highlighting

By analogy, since on my system the KDE's syntax highlighting files are located in

/usr/share/org.kde.syntax-highlighting/syntax/

I created the syntax directory in ~/.local/share/org.kde.syntax-highlighting/.

The actual path may be different on your version of KDE/Kate, but you should be able to apply this procedure to find out what it is. You may also use something like strace -e openat kate 2>&1 | grep syntax-highlighting to list the files Kate actually opens (and, later, check whether your changes have the desired effect).

Then I used the /usr/share/texmf-dist/asymptote/asy-kate.sh script provided by Tex Live to generate the asymptote.xml syntax-highlighting description file and placed it in

~/.local/share/org.kde.syntax-highlighting/syntax/

That file already includes

<general>
        <comments>
                <comment name="singleLine" start="//" />
                <comment name="multiLine" start="/*" end="*/" region="Comment"/>
        </comments>
        <keywords casesensitive="1" />
</general>

that sets the string used by Kate to create comments when the Ctrl+D key combination is pressed.

Now, if I open Kate, open a file and select "asymptote" in Tools → Mode → Sources or in Tools → Highlighting → Sources, the key combination to comment lines works as you are expecting.

fra-san
  • 9,931
  • 2
  • 21
  • 42