5

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.)

| improve this question | | | | |
3

Change the way pair insertion is inhibited:

(setq-default electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit)
| improve this answer | | | | |
3

You can also probably

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

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

| improve this answer | | | | |

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.