Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Abbrev expansion after certain symbols in Emacs

Is there a way to prevent automatic expansion of an abbreviation in the built-in abbrev-mode after certain symbols? E.g. I want my abbrev to expand after whitespace, newline, comma etc., but not after a dash or underscore.

I know I can hit C-q before typing the (say) underscore, but an automatic solution would be much nicer since this occurs for me very often.

There are some abbrev hooks in the manual, but since I am a total beginner with Elisp I don't see an obvious solution...

Thank you very much!

like image 666
user673592 Avatar asked Dec 14 '25 01:12

user673592


1 Answers

Make underscore be a word-constituent character for the current mode. From the Emacs manual, node Expanding Abbrevs:

[A]ny character that is not a word constituent expands an abbrev, and any word-constituent character can be part of an abbrev.

Use function modify-syntax-entry to modify the syntax class of _, to make it a word constituent:

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

This solution is useful only if it is not otherwise bothersome for _ to be a word-constituent character. Do you want _ to act as if it is a part of a word or not? That's the first question.

like image 184
Drew Avatar answered Dec 15 '25 21:12

Drew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!