Is it possible to highlight matching quotes as show-paren-mode does with parentheses? The characters I'm looking to highlight are "dumb" quotes, both single (Unicode: apostrophe, U+0027) and double (Unicode: quotation mark, U+0022).

Sometimes I get lost in Fortran format specifiers, like '("strg1", i2, "strg2", i11)'. Highlighting matching quotes there would help me tell apart the pieces of the specifier.

I'd prefer not to use smartparens. If your solution uses it please provide a set-up that just highlights matching quotes without otherwise altering the pairing or highlighting of matching delimiters.

  • Please specify what you mean by matching quotes. Which characters?
    – Drew
    Commented Jul 18, 2018 at 19:34
  • @Drew Both ' and ". Commented Jul 18, 2018 at 21:14
  • Put that info in the question, please. So no "curly" quotes - just double-quote (you might mention a programming "string") and apostrophe chars. Giving their Unicode names or code points would be clearest.
    – Drew
    Commented Jul 18, 2018 at 23:03

1 Answer 1


Of course it is.

(defun show-paren--match-quotes ()
  (let ((ppss (syntax-ppss)))
    ;; In order to distinguish which quote is opening and which is starting,
    ;; check that that point is not within a string (or comment, for that
    ;; matter).  Also ignore escaped quotes.
    (unless (or (nth 8 ppss) (nth 5 ppss))
       (and (not (bobp))
            (eq 7 (car-safe (syntax-after (1- (point)))))
              (let ((end (point))
                    (ppss (syntax-ppss (1- (point)))))
                (when (nth 3 ppss)
                  (let ((beg (nth 8 ppss)))
                    (list beg
                          (1+ beg)
                          (1- end)
       (and (not (eobp))
            (eq 7 (car-safe (syntax-after (point))))
              (let ((beg (point)))
                (condition-case nil
                      (forward-sexp 1)
                      (list beg
                            (1+ beg)
                            (1- (point))

(advice-add 'show-paren--default :after-until #'show-paren--match-quotes)
  • Very nice! But I wanted this because I was getting lost on a Fortran format specifier sort of like '("blahblah", i2, "blah", i11)'. In it, show-paren--match-quotes only highlights the outer single quotes. Commented Jul 18, 2018 at 21:26
  • Shouldn't the advice-add rather be add-function on show-paren-data-function?
    – npostavs
    Commented Jul 19, 2018 at 9:34
  • @npostavs: Indeed.
    – Stefan
    Commented Jul 19, 2018 at 12:39
  • @ArchStanton: sorry, I missed that part of your question. I'm not sufficiently familiar with Fortran to know offhand how to fix that. What major mode do you use? f90-mode?
    – Stefan
    Commented Jul 20, 2018 at 12:01
  • @Stefan Yes. Btw don't worry, that was an edit that I added later. Commented Jul 20, 2018 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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