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.)
'
having word syntax. It certainly changes the behavior of commands likeforward-word
andbackward-word
, however, which is reason enough not to make the change permanent.abbrev--check-chars
is the only function in theabbrev.el
library that contains syntax tables. Do you think it might be helpful to modify that one function to use your own custom syntax table? I could be wrong, but I don't think you would really be interested in changingself-insert-command
.abbrev
issue to motivate the problem. I'm more interested in modifying the syntax, which I need to do for a different function. (In other words: I'm not looking to hackabbrev-mode
.)