Bug 360456 - Pointer assignment after closed C comment incorrectly triggers autostar
Summary: Pointer assignment after closed C comment incorrectly triggers autostar
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: indentation (show other bugs)
Version: unspecified
Platform: Debian stable Linux
: NOR minor
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-13 06:58 UTC by Louis Wust
Modified: 2017-07-24 15:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Louis Wust 2016-03-13 06:58:21 UTC
The logic which provides automatic indentation for C code being edited in both Kate and KWrite features the capability to "autostar" (automatically start new lines with an asterisk and appropriate whitespace) when it detects that the region being edited is within a comment. For example, given the following C code:

/* This is a comment
 * This is where the cursor is/was positioned ->

then, after pressing the Return/Enter key on the keyboard, the indenter automatically adds an asterisk to the next line:

/* This is a comment
 * This is where the cursor is/was positioned ->
 *

This is a very useful feature. However, it can become confused when a closed C-style comment is followed by a pointer assignment. See the steps to reproduce, actual results, and expected results for an example.

Reproducible: Always

Steps to Reproduce:
1. Open a new document in Kate (although this also happens in KWrite)
2. Save the document as "test.c" to indicate that this is a C source file
3. Within the document, type the following syntactically-valid C code:

    int *test;
    /* Here, we assign a value to the pointee object */
    *test = 42;

4. Position the cursor immediately after the semicolon which terminates the final line (the assignment).
5. Press the Enter/Return key.

Actual Results:  
The new line is automatically indented, as expected, but an asterisk is added as though we are currently in a C comment, which is incorrect:

    int *test;
    /* Here, we assign a value to the pointee object */
    *test = 42;
    *

Expected Results:  
The new line should have automatically been indented, but no asterisk should have been added because the comment was already closed:

    int *test;
    /* Here, we assign a value to the pointee object */
    *test = 42;
    {note that this line is blank, but see the indentation to the left}

I assume that this is not a wishlist item, because it is technically incorrect behavior. However, there is most certainly an easy workaround (i.e., delete the asterisk). Honestly, this "bug" doesn't "bug" me and I expect very few people will ever even run into it -- I'm just trying to do my part as an open source citizen by reporting the unexpected behavior. I would be happy to provide more information if required.
Comment 1 Buovjaga 2016-07-02 10:49:13 UTC
Repro.
Had to really save it as .c, the behavior did not start with defining the highlighting from the menu.

Arch Linux 64-bit
Kate 16.04.2
KDE Frameworks 5.23.0
Qt 5.7
xcb wm
Comment 2 Christoph Cullmann 2017-07-24 15:34:44 UTC
Git commit 58baf7c318d4641a243ea18f04ef15ee017509e3 by Christoph Cullmann.
Committed on 24/07/2017 at 15:32.
Pushed by cullmann into branch 'master'.

fix problem with * adding for lines outside of comments

A  +4    -0    autotests/input/indent/cstyle/360456/expected
A  +3    -0    autotests/input/indent/cstyle/360456/input.js
A  +3    -0    autotests/input/indent/cstyle/360456/origin
M  +6    -1    src/script/data/indentation/cstyle.js

https://commits.kde.org/ktexteditor/58baf7c318d4641a243ea18f04ef15ee017509e3