I have my own font locking that highlights quotes in comments eg.

/* Some comment 'this is quoted'
 * more 'text in an escaped \` quote'.
 * Plurals such as Moe's or Joe's should work too. */
  • Assuming the quotes don't need to span multiple lines.
  • And quotes can be escaped.

Currently I'm using

(concat "'" ".*?" "[^\\]" "'")

However it doesn't check spaces around the quotes.

Is there a convention to matching quotation?

  • FYI "\'" is the same as "'".
    – npostavs
    Aug 10 '19 at 2:58
  • thx, updated Q.
    – ideasman42
    Aug 10 '19 at 3:31

There's no convention, AFAIK.

But define "matching quotation". That could mean several different things. The devil is in the definition/specification.

Typically you want to match a quote char, followed by zero or more chars that are each either (1) a non-quote char or (2) an escaped quote char, followed by an unescaped quote char. If start and close quote chars are different (e.g. curly quotes) then that too needs to be added to the spec.

In some cases it's easier not to try to do everything with a single regexp (and in some cases it's not even possible to do everything with a single regexp). Emacs Lisp lets you use a combination of regexps and arbitrary functions, and that's often the best approach. That's even possible for font-locking.

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.