8

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.

  • I can't figure out where 'font-lock-syntactic-keywords' is getting set in (c-mode), but it has a syntax table associated with it that seems to cause this
  • (c-in-literal) returns 'string as well, so maybe I need to solve this deeper in the code than at the font-lock level, if anyone has any tips on this it would be appreciated

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

1 Answer 1

4

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 ?\' "."))) 
Sign up to request clarification or add additional context in comments.

1 Comment

it's in php-mode, which is derived from c-mode. My guess is that it is using the local syntax somehow to match strings but the c-mode setup function is so convoluted that I've had trouble debugging through it to figure out where things are getting set

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.