Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.82k stars 195 forks source link

sp-local-pair :actions nil does not seem to work the first time the minibuffer is used #1009

Closed Emiluren closed 4 years ago

Emiluren commented 4 years ago

Expected behavior

I have a turn-on-smartparens-strict-mode in my eval-expression-minibuffer-setup-hook and (sp-local-pair 'minibuffer-inactive-mode "'" nil :actions nil) to prevent ' from creating a pair when I use eval-expression M-:.

Actual behavior

If I press M-: immediately after starting Emacs I get two quotes ''. Any other time it actually works which makes me think that something does not run in the order I expect.

Steps to reproduce the problem

This is the configuration I have for smartparens

(use-package smartparens
  :straight t
  :demand t
  :delight
  :hook (eval-expression-minibuffer-setup . turn-on-smartparens-strict-mode)
  :config
  (require 'smartparens-config)
  ;; Prevent single quote ' from pairing in minibuffer eval
  ;; For some reason, this does not work the first time the minibuffer is used
  (sp-local-pair 'minibuffer-inactive-mode "'" nil
                 :actions nil)
  (smartparens-global-mode 1)
  (smartparens-global-strict-mode 1)
  :custom
  (sp-override-key-bindings '(("M-<backspace>" . nil)))
  (sp-ignore-modes-list ())
  (sp-base-key-bindings 'paredit))

I use straight.el and use-package. https://github.com/Emiluren/.emacs.d/blob/0a492767f6e6e9e9953de2db6d10d19e89fc09ba/init.el#L570

Environment & version information

Emiluren commented 4 years ago

Ok, I managed to fix my own problem by changing my :init/:hook to this:

  :init
  (defun conditionally-enable-smartparens ()
    "enable paredit-mode during eval-expression"
    (if (eq this-command 'eval-expression)
        ;; Prevent single quote ' from pairing in minibuffer eval
        (sp-local-pair 'minibuffer-inactive-mode "'" nil
                       :actions nil)
        (smartparens-strict-mode 1)
      (smartparens-strict-mode 0)))
  :hook (minibuffer-setup . conditionally-enable-smartparens)
Fuco1 commented 4 years ago

Interestingly things have stopped working for me in minibuffer so I'll probably borrow some of your config. Thanks! :)