aaron
aaron

Reputation: 1796

how can I get emacs to recognize single quotes as not being string begin/end tokens in font-lock mode

I've a preprocessor (xhp) that allows me to write unquoted text in php code e.g.:

<foo>
    my enemies' base
</foo>

might appear in a .php file, but as soon as emacs sees that single quote it sees the entire rest of the file as being in a string.

The simplest solution that I'd be happy with would be just assuming the string is one-line only.

Upvotes: 8

Views: 1338

Answers (1)

Stefan
Stefan

Reputation: 28571

I don't know what major-mode you're using, but in general the trick is to change the syntax of the ' character with something like (modify-syntax-entry ?\' "." <syntaxtable>). Of course, if the ' character can sometimes delimit strings and sometimes not, then it's more tricky and you'll need to come up with a font-lock-syntactic-keywords (or syntax-propertize-function) rule which can tell which is used at any given point.

E.g. assuming PHP never treats ' as a string delimiter, something like the following might solve your problem:

(add-hook 'php-mode-hook
          (lambda () (modify-syntax-table ?\' ".")))

Upvotes: 4

Related Questions