I use (show-paren-mode 1) to get help seeing where parentheses are. I have (setq show-paren-delay 2) to prevent intrusive highlighting when I don't need it. This is how it works now:

  1. Put cursor on a parenthesis. After 2 seconds, both parentheses highlight
  2. Use cursor keys. Highlighting stays on as long as I keep cursoring.
  3. Stop moving around. Highlighting eventually disappears, after 2 seconds.

It should work like this:

  1. Same as above.
  2. Use cursor keys. Highlighting disappears immediately!

The rationale is that I need highlighting as an aide to find the matching parenthesis, or to detect imbalance. Once I've established this, the highlighting is no longer useful and I want it gone.

  • Please provide a step-by-step recipe to describe what you're seeing and what you want to see instead.
    – Drew
    Apr 2, 2018 at 14:05
  • @Drew: See updated post.
    – forthrin
    Apr 2, 2018 at 14:55
  • 1
    Do you see that when you start Emacs using emacs -Q (no init file)? I don't. I don't see any such delay. If the cursor is moved away from a paren the highlighting ceases immediately, for me. If you don't see the problem without your init file, bisect the file to find the culprit.
    – Drew
    Apr 2, 2018 at 15:06
  • @Drew OP already put the settings needed to reproduce: (setq show-paren-delay 2) (show-paren-mode 1). The problem, as far as I can tell, is that show-paren-delay applies not only to the paren highlighting (which is what OP wants, I guess), but also to the unhighlighting.
    – npostavs
    Apr 2, 2018 at 15:49
  • @npostavs: Is there a bug or enhancement request here? (If so, OP should M-x report-emacs-bug.) If not, is it not OK for OP to just remove that delay customization?
    – Drew
    Apr 2, 2018 at 15:53

1 Answer 1


It should work like this: [...] Use cursor keys. Highlighting disappears immediately!

I want show-paren-delay only when navigating the code. If I actually type a new parenthesis, I want immediate highlighting.

You can make it work like that with the following code. show-paren-clear-highlight should be added to Emacs since it's accessing internal variables.

(defun show-paren-clear-highlight ()
  "Turn off any previous paren highlighting."
  (delete-overlay show-paren--overlay)
  (delete-overlay show-paren--overlay-1))

;; Instead of relying on `delsel', you could use
;; `before-change-functions' to detect insertions.  That might be more
;; reliable, but also more complicated.
(require 'delsel)
(defun my-show-paren-update-on-insert ()
  ;; A command with `delete-selection' property probably inserts text.
  (if (get this-command 'delete-selection)

(add-hook 'post-command-hook #'my-show-paren-update-on-insert)
  • I noticed something: I want show-paren-delay only when navigating the code. If I actually type a new parenthesis, I want immediate highlighting. How do I do this? (The reason I use show-paren-delay in the first place is to avoid this insane flickering of parenthesis when I cursor around in my code, but when I'm typing a parenthesis, I obviously want to see the matching parenthesis immediately to know my scoping is correct.)
    – forthrin
    Apr 4, 2018 at 9:39
  • @forthrin Updated. Not sure what you mean by "insane flickering" though. Maybe the double-buffering in Emacs 26 would help you more?
    – npostavs
    Apr 4, 2018 at 9:59
  • If you cursor down the first column of your .emacs, which usually has a lot of opening parenthesis, all the closing parentheses on the end of the line will blink quickly on and off as you pass them. This is not desirable. PS! I couldn't get your new snippet to work.
    – forthrin
    Apr 4, 2018 at 11:58
  • @forthin While I'm holding down C-n the parens don't get highlighted even with the default delay (0.125). If you are trying the new snippet in the same session as the old one, you need to (remove-hook 'post-command-hook #'show-paren-clear-highlight).
    – npostavs
    Apr 4, 2018 at 12:35
  • I noticed instant highlighting when typing happens for lisp-mode, but not for php-mode and c-mode. Can you check this?
    – forthrin
    Apr 6, 2018 at 9:17

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.