Emacs-Kotlin-Mode-Maintainers/kotlin-mode

forward-word and backward-word do not behave correctly with subword-mode

elizagamedev opened this issue · 1 comments

To reproduce, enable subword-mode.

With > representing the cursor position, pressing M-f repeatedly should result in the following behavior:

private const val >UPPER_SNAKE_CASE_IDENTIFIER = 30
private const val UPPER>_SNAKE_CASE_IDENTIFIER = 30
private const val UPPER_SNAKE>_CASE_IDENTIFIER = 30
private const val UPPER_SNAKE_CASE>_IDENTIFIER = 30
private const val UPPER_SNAKE_CASE_IDENTIFIER> = 30

Instead, the following behavior is observed:

private const val >UPPER_SNAKE_CASE_IDENTIFIER = 30
private const val UPPER_>SNAKE_CASE_IDENTIFIER = 30
private const val UPPER_SNAKE_CASE_IDENTIFIER> = 30

Similarly, when moving backwards with M-b:

private const val UPPER_SNAKE_CASE_IDENTIFIER> = 30
private const val UPPER_SNAKE_CASE_>IDENTIFIER = 30
private const val UPPER_SNAKE_>CASE_IDENTIFIER = 30
private const val UPPER_>SNAKE_CASE_IDENTIFIER = 30
private const val >UPPER_SNAKE_CASE_IDENTIFIER = 30

Instead, we get the following behavior:

private const val UPPER_SNAKE_CASE_IDENTIFIER> = 30
private const val UPPE>R_SNAKE_CASE_IDENTIFIER = 30
private const val >UPPER_SNAKE_CASE_IDENTIFIER = 30

Strangely, it ends up in between the E and the R.

taku0 commented

java-mode/swift-mode

Without subword-mode nor superword-mode:

>UPPER_SNAKE_CASE_IDENTIFIER
UPPER>_SNAKE_CASE_IDENTIFIER
UPPER_SNAKE>_CASE_IDENTIFIER

With subword-mode:

>UPPER_SNAKE_CASE_IDENTIFIER
UPPER>_SNAKE_CASE_IDENTIFIER
UPPER_SNAKE>_CASE_IDENTIFIER

With superword-mode:

>UPPER_SNAKE_CASE_IDENTIFIER
UPPER_SNAKE_CASE_IDENTIFIER>

kotlin-mode

Without subword-mode nor superword-mode:

>UPPER_SNAKE_CASE_IDENTIFIER
UPPER_SNAKE_CASE_IDENTIFIER>

With subword-mode:

>UPPER_SNAKE_CASE_IDENTIFIER
UPPER>_SNAKE_CASE_IDENTIFIER
UPPER_SNAKE_CASE_IDENTIFIER>

With superword-mode:

>UPPER_SNAKE_CASE_IDENTIFIER
UPPER_SNAKE_CASE_IDENTIFIER>

Cause

kotlin-mode processes _ as a part of a word:

    ;; `_' as being a valid part of a word
    (modify-syntax-entry ?_ "w" st)

java-mode/swift-mode processes _ as a part of a symbol:

    (modify-syntax-entry ?_ "_" table)