4

I'm trying to get better at using Emacs regular expressions. Reading the documentation I see:

‘\cC’
matches any character that belongs to the category C. For example, ‘\cc’ matches Chinese characters, ‘\cg’ matches Greek characters, etc. For the description of the known categories, type ‘M-x describe-categories <RET>’.

If I run describe-categories I see:

Legend of category mnemonics (longer descriptions at the bottom)
 :space for indent  9:semivowel lower   R:Right-to-left ... k:Katakana
.:Base              <:Not at eol        Y:2-byte Cyrillic   l:Latin
0:consonant         >:Not at bol        ^:Combining     o:Lao
1:base vowel        A:2-byte alnum      a:ASCII         q:Tibetan
2:upper diacritic   C:2-byte han        b:Arabic        r:Roman
3:lower diacritic   G:2-byte Greek      c:Chinese       t:Thai
4:combining tone    H:2-byte Hiragana   e:Ethiopic      v:Viet
5:symbol            I:Indian Glyphs     g:Greek         w:Hebrew
6:digit             K:2-byte Katakana   h:Korean        y:Cyrillic
...

Isn't that first item the space character? But if run isearch-forward-regexp and try \c , it finds nothing, even in a buffer with lots of whitespace. Trying \c6 to find digits also doesn't work.

Are these bugs or am I using it wrong?

I'm using GNU Emacs 27.2 on macOS.

0

1 Answer 1

4

It's not in the space category for regexp search because it's not in the space category, full stop. It's not in the space category because the space category is actually not used. I don't know why the space category is not used.

A space is the mnemonic for the category “space for indent”. But the space character does not have the category “space for indent”. Check the character listing in the output of describe-categories:

character(s)    category mnemonics
------------    ------------------
C-@ .. C-_      
SPC             .al
! .. @          .alr
A .. Z          .Lalr
[               .alr
\               .al
] .. `          .alr
a .. z          .Lalr
{ .. }          .alr
~               .al
DEL             al
\200 .. \237    l
                .bjl

ASCII space (U+0020) only has the categories “Base”, “ASCII” and “Latin”. Unbreakable space (U+00A0) has the categories “Base”, “Arabic”, “Japanese” and “Latin”. Looking at the source code, no character has the category “space for indentation”.

Looking at the history, the space category was added in Emacs 20.3 with the intent of being used for indentation, and it was set for non-breakable space (but not for ASCII space). It was removed from all characters in Emacs 23.1, although the category definition wasn't removed. I don't know why this was done.

Likewise, ASCII digits only have the categories “Base”, “ASCII” and “Latin”. Only some non-ASCII digits do have the category “Digit” (Lao, Thai and Tibetan — not all non-Latin decimal digits). A comment states that the intent of having a digit category is as part of “phonetic classification”. Maybe separating digits from other non-letters is actually not useful for that purpose?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.