0

I’m trying to make a particular exclamation point behave like a word constituent (from the point of view of the syntax table), using the syntax-table text property, but I can’t get it to work.

In an empty buffer I write an exclamation mark and then evaluate the command (add-text-properties 1 2 '(syntax-table (2))). I think this is what I’m supposed to do. But describe-char on the exclamation mark shows

            character: ! (displayed as !) (codepoint 33, #o41, #x21)
[…]
               syntax: .    which means: punctuation
[…]
There are text properties here:
  syntax-table         (2)

Note that the text property has been applied, but it is still considered a punctuation character. What am I missing? Do I need to call a function to update it somehow? Other text properties (for instance display) are applied automatically.

  • You need to set parse-sexp-lookup-properties to a non-nil value. – Tobias Oct 20 '16 at 14:41
  • Thanks! But it’s a bit strange, it means that the syntax-table text property is useless otherwise? Why isn’t that on by default? – Guillaume Brunerie Oct 20 '16 at 14:44
  • "Why isn’t that on by default?" - performance? – npostavs Oct 20 '16 at 19:14
2

As mentioned by Tobias, you generally need

(set (make-local-variable 'parse-sexp-lookup-properties) t)

in order for those properties to have an effect. The reason for it is probably historical and linked to performance, and nobody bothered to try and change it since.

Notice that syntax-table text properties are usually set via syntax-propertize-function, in which case syntax-propertize will take it upon itself to set parse-sexp-lookup-properties for you, which is why you don't usually see major modes setting this var explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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