Q: how can I change the syntax of a character for a single function?
In text-mode
and its derivatives, the '
character has word syntax rather than, say punctuation or string quote syntax. That's a problem when using abbrev-mode
, as I would like the '
character to fire the abbrev
when I'm using a possessive.
For example, if the abbrev
"pres" expands to "president" and I want to write the "president's cat", I'd expect to be able to type p r e s ' s, where "pres" expands automatically to "president" when I hit '.
Now: I don't want to change the syntax for '
globally or permanently, because I don't want to interfere with any other functions that depend on '
having word syntax. I tried the following:
(defadvice self-insert-command (around testing activate)
(with-syntax-table (copy-syntax-table (syntax-table))
(modify-syntax-entry ?' "\"")
ad-do-it))
Two problems.
First: although it does fire the abbrev
as expected, smartparens-mode
complains every second time the abbrev
fires (really: it's every second time). That's a tangent on the main point, however.
Second, and more importantly: this advice seems awfully costly for a function that gets invoked on every insertion command. It calls up the syntax table, copies it, modifies it, uses it, and then restores the original syntax table. That seems awfully silly when I really only care about one character, which leads me to suspect I'm going about this wrong.
Is there a smarter way to do this? (Note that I'm most interested in temporarily changing the syntax of a character and am using the abbrev
example to motivate it.)