For writing texts on spectroscopy I would like to use abbrevs for common notations for spectral lines. However, the method outlined in the documentation for defining abbrevs with C-x a l
or C-x a g
fails on me. For example, I type Ly M-x insert-char greek small letter alpha
to get Lyα
now I hit C-x a l
and only α
is displayed in the minibuffer. Why? Is the only solution for me to manually edit the abbrev-table?
1 Answer
Curious. add-abbrev
scans backward by words using forward-word
to find out what abbrev to define. I'm not entirely sure why, but even though both "y" and "α" are defined as word characters in the syntax table (at least in the modes I tried it in, ymmv), it still considers there to be a word boundary between them. You can see this if you skip backwards and forwards by words with M-b
or M-f
. This is implemented in the scan_words
function in syntax.c
, which is sufficiently obscure that I can't tell exactly what the cause of this is; it might even be a feature.
Anyway, the help for add-global-abbrev
(and add-local-abbrev
) says this:
The prefix argument specifies the number of words before point that form the
expansion; or zero means the region is the expansion.
A negative argument means to undefine the specified abbrev.
This means that you can specify a prefix argument to tell it how many words to use; C-u 2 C-x a g
does the trick.
Edit:
I figured it out. scan_words
considers two word characters to have a word boundary between them if they are from different scripts. See word_boundary_p
in category.c, and the variable char-script-table
which maps characters to script names. I suppose that makes a reasonable rule to use.
I suppose you could advise add-abbrev
so that it uses forward-word-strictly
, which ignores the script and goes only by the syntax table. Or you could mess around with find-word-boundary-function-table
, but that seems like a lot of work.
-
2For this case you'd want to use
word-combining-categories
, eg(add-to-list 'word-combining-categories (cons ?l ?G))
to indicate that Latin letters followed by Greek letters don't form a word boundary– rpluimCommented Apr 3, 2020 at 9:16 -
Thanks for your answer @db48x , this helped. I am still confused, this is the second time I play with abbrev mode, and seems to be never doing what I like. Try entering
b M-x insert-char less-than or equivalent to
, which expands tob ≲
, nowC-x a l
wants to define an abbrev forb ≲
and not just≲
(I havent altered the word combining categories). So the edit to your answer seems not to be correct... Commented Apr 6, 2020 at 23:14 -
1Unicode classifies that as a symbol rather than as a word-constituent. If you use
backword-word
(M-b
), you'll see that it jumps over all punctuation to get to the start of the previous word. Sinceadd-abbrev
callsbackward-word
to find the start of the previous word, it does so as well.– db48xCommented Apr 7, 2020 at 2:14