smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

A few questions about configuring smartparens package.

Open hongyi-zhao opened this issue 4 years ago • 4 comments

On Ubuntu 20.10, I use the latest git master version of Emacs and installed the lastest smartparens from melpa with the following settings in my ~/.emacs.d/init.el:

(use-package smartparens-config
  :ensure smartparens
  :config (progn (show-smartparens-global-mode t)))
(add-hook 'prog-mode-hook #'smartparens-strict-mode)
(setq sp-navigate-close-if-unbalanced t)

The above setting seems to be working smoothly. But I still can't understand a few questions as described below:

  1. Based on my tries, all the following forms are equivalent:
(add-hook 'prog-mode-hook 'turn-on-smartparens-strict-mode)
(add-hook 'prog-mode-hook 'smartparens-strict-mode)
(add-hook 'prog-mode-hook #'smartparens-strict-mode)

Why?

  1. As you can see, the above settings only activate the smartparens-strict-mode conditionally for prog-mode. If I want to always activate this mode in any case globally. What setting should I use?

  2. Are the following two instructions equivalent:

(require 'smartparens-config)

and

(use-package smartparens-config

Regards, HY

hongyi-zhao avatar Jan 16 '21 01:01 hongyi-zhao

  1. turn-on-smartparens-strict-mode starts the mode except in modes on the ignore list sp-ignore-modes-list or special buffers. This is described in the documentation.
  2. use smartparens-global-strict-mode which uses turn-on-smartparens-strict-mode to enable the mode in any new buffer.
  3. this is a question for use-package package: https://github.com/jwiegley/use-package, but in short no, it's not the same. use-package has a lot more features which are too much to describe here. Check their readme.

Fuco1 avatar Jan 17 '21 12:01 Fuco1

  1. use smartparens-global-strict-mode which uses turn-on-smartparens-strict-mode to enable the mode in any new buffer.

Do you mean something like this: :config (progn (smartparens-global-strict-mode t))?

hongyi-zhao avatar Jan 17 '21 14:01 hongyi-zhao

The global mode is generated by Emacs and this is the documentation:

(smartparens-global-strict-mode &optional ARG)

Toggle Smartparens-Strict mode in all buffers. With prefix ARG, enable Smartparens-Global-Strict mode if ARG is positive; otherwise, disable it. If called from Lisp, enable the mode if ARG is omitted or nil.

So drop the t argument.

Fuco1 avatar Aug 06 '21 20:08 Fuco1

So drop the t argument.

But based on my tries, the following usage in .emacs.d/init.el is still vaild:

(use-package smartparens
  :demand t
  :config
  (setq sp-navigate-close-if-unbalanced t)
  (progn
   (require 'smartparens-latex) 
   (smartparens-global-strict-mode t)
   (smartparens-mode +1)))

hongyi-zhao avatar Aug 07 '21 00:08 hongyi-zhao