#StackBounty: #electric-pair-mode smart-quotes how to close it on the end of the variable if there is one

Bounty: 50

I don’t know the proper explaination for this so I could not find the answer.

I have tried to integrate electric-pair and smart-quotes. It works pretty nice but in some cases it does not do the things I want.

Note: When you expand the browser to full size following table is readable.

I_____base______ inserted_______became_____wanted-behavior (2nd one preferred)

  • f(name) => f("name) ==> f(""name) ==> f("name) or f("name")
  • f(name) => f(name") ==> f(name"") ==> f(name") or
  • "name_" => f("name_" => f()"name_" => f("name_" or f("name_")
  • 1000000 => [1000000 => []1000000 => [1000000 or [1000000]

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)

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.