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

bright-star
  • 839
  • 9
  • 17

2 Answers2

3

Change the way pair insertion is inhibited:

(setq-default electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit)
scottfrazer
  • 314
  • 1
  • 2
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.

joao
  • 245
  • 1
  • 8