This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Position of comment symbol, block-commenting - Kdevelop/Kate

Tags: None
(comma "," separated)
andrewmcleod
Registered Member
Posts
2
Karma
0
I am using Kdevelop, but the problem is the same in pure Kate. Editing a Python file, e.g.
Code: Select all
if something:
    # arbitrary comment
    if something_else:
        do something

and doing Ctrl-d used to produce:
Code: Select all
#if something:
#    # arbitrary comment
#    if something_else:
#        do something
(ignore the weird first line indent)
which is easy to read/remove the comment symbol/have nested comments. But now it seems to produce:
Code: Select all
#if something:
    ## arbitrary comment
    #if something_else:
        #do something

which is much less clear (at least to me). Is there a way to get back to the old behaviour? Thanks :)
cvk
Registered Member
Posts
2
Karma
0
I just stumbled on the same problem and wanted to know whether there is a solution. Using kate 16.08.3 (current debian stable).
ginette
Registered Member
Posts
40
Karma
0
Any solution yet? Thanks! Martin
alonsomm
Registered Member
Posts
1
Karma
0
Hello, I found how to change this behavior. The symbol and position of the comment are defined by syntax definition files used by KSyntaxHighlighting. You can see the syntax definition file for python under /data/syntax in the repository for KSyntaxHighlighting. The exact part of the file where the comment behavior is defined is at the end of the file in the <comment> element. For the python file, the element looks like this:

Code: Select all
<comment name="singleLine" start="#" position="afterwhitespace"/>


The string start defines the comment string used to comment python code, in this case it is "#" and the position part defines where the comment string should be put. For python by default the position is "afterwhitespace" which means that the comment is inserted after the white space. If you want the comments to appear at start of the line you can remove the position="afterwhitespace" part. You can then put the xml file in $HOME/.local/share/org.kde.syntax-highlighting/syntax/. Then kate should be able to insert comments at the start of the line instead of after the white space. Here is more information about where to put the xml file in other windows and macOS and more information about KSyntaxHighlighting.

I am not sure why the default comment behavior for python is done such that it results in a style warning by flake8 (Block comment should start with '# ' (E265)). I think it would be better if the position="afterwhitespace" is removed for the python syntax definition file or if start="#" is changed to start="# " so that comments add a space between # and the code.

I hope this is useful for others.
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
If you think this behaviour is desirable for everyone, consider submitting your change as a patch on invent.kde.org!


I'm working on the KDevelop IDE.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]