Electric-pair-mode always tries to insert a closing delimiter after the opening one if nothing is selected. However, if you're placing delimiters around an existing something that you don't want to select for some reason, this adds another keystroke instead of saving you one.

What's a good way to tell electric-pair-mode to check if the point is adjacent to a non-empty string first, and not bother adding a closing delimiter if so?

(For instance, this is the behavior of RStudio's electric pairs.)

2 Answers 2


Change the way pair insertion is inhibited:

(setq-default electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit)

You can also probably

(setq-default electric-pair-inhibit-predicate
              (lambda (c)
                (if (looking-at "[ \n\t]")
                    (electric-pair-default-inhibit c)

Seems a bit more correct in light of the actual question asked.

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.