Skip to content

charclass() sometimes returns 2 for punctuation #15965

@kennypete

Description

@kennypete

Steps to reproduce

  1. In a new buffer, source:
for c in range(32, 48, 8)
  echo nr2char(c) .. ' charclass=' .. nr2char(c)->charclass()
endfor

Echos (correctly):

  charclass=0
( charclass=1
0 charclass=2  
  1. In a help buffer, set ma to make it modifiable, then put the same for loop and source it:

Echos:

  charclass=0
( charclass=2
0 charclass=2  

Screenshots to illustrate:

image

Expected behaviour

charclass() should always return 1 for the left parenthesis (and any punctuation character):

builtin.txt help:

charclass({string})					charclass()
		Return the character class of the first character in {string}.
		The character class is one of:
			0	blank
			1	punctuation
			2	word character
			3	emoji
			other	specific Unicode class

The same thing happens for all punctuation characters, returning 2 instead of 1.

Version of Vim

9.1.90

Environment

Same result in Win11 gvim, Debian WSL Huge GTK3 GUI.

Also happens in Neovim 0.10.2, incidentally, just to see whether the same thing happens in it, and it does (not that I care particularly).

Logs and stack traces

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions