I don't know the proper explaination for this so I could not find the answer. It might be already handled but I was not able to configure it correctly.

I have tried to integrate electric-pair and smart-quotes. It works pretty nice but in some cases it does not do the things as I want. Please see the table for an example.

  • Base column is the initial state.
  • inserted column is where I inserted the character
  • becamecolumn where the pair is intersed

  • Wanted behavior. 1st: do nothing or 2nd: I wrote added character in between ><

  • ==> If it is >"<NAME do "NAME"

  • ==> If it is NAME>"< do "NAME"

  • ==> If it is >(<"NAME" do ("NAME")

  • ==> If it is >[<NAME do [NAME]

enter image description here

My setup:

(electric-pair-mode 1)
(defun electric-pair ()
  "If at end of line, insert character pair without surrounding spaces.
    Otherwise, just insert the typed character."
  (if (eolp) (let (parens-require-spaces) (insert-pair)) (self-insert-command 1)))

; https://www.emacswiki.org/emacs/ElectricPair
(add-hook 'python-mode-hook
              (lambda ()
                (define-key python-mode-map "\"" 'electric-pair)
                (define-key python-mode-map "\'" 'electric-pair)
                (define-key python-mode-map "(" 'electric-pair)
                (define-key python-mode-map "[" 'electric-pair)
                (define-key python-mode-map "{" 'electric-pair)))

;(require 'smart-quotes)
(add-hook 'text-mode-hook 'turn-on-smart-quotes)

PS: I can try to explain more if the question is unclear

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.