Move smartparens pair definition out of hooks

There are two reasons for doing this:
- It's inefficient, we don't have to define the pairs every time we
  enter the mode.
- It's extremely difficult to override the pair definition, even with
  `eval-after-load` and `add-hook`
This commit is contained in:
toctan 2014-06-25 11:01:12 +08:00
parent 2e8859b936
commit 07ff79872e
2 changed files with 23 additions and 19 deletions

View file

@ -113,6 +113,11 @@ This functions should be added to the hooks of major modes for programming."
;; ;;
;; (the final optional t sets the *append* argument) ;; (the final optional t sets the *append* argument)
;; smart curly braces
(sp-pair "{" nil :post-handlers
'(((lambda (&rest _ignored)
(prelude-smart-open-line-above)) "RET")))
(defun prelude-prog-mode-defaults () (defun prelude-prog-mode-defaults ()
"Default coding hook, useful with any programming language." "Default coding hook, useful with any programming language."
(when (and (executable-find ispell-program-name) (when (and (executable-find ispell-program-name)
@ -121,9 +126,6 @@ This functions should be added to the hooks of major modes for programming."
(when prelude-guru (when prelude-guru
(guru-mode +1)) (guru-mode +1))
(smartparens-mode +1) (smartparens-mode +1)
(sp-pair "{" nil :post-handlers
'(((lambda (&rest _ignored)
(prelude-smart-open-line-above)) "RET")))
(prelude-enable-whitespace) (prelude-enable-whitespace)
(prelude-local-comment-auto-fill) (prelude-local-comment-auto-fill)
(prelude-font-lock-comment-annotations)) (prelude-font-lock-comment-annotations))

View file

@ -34,6 +34,8 @@
(prelude-require-packages '(web-mode)) (prelude-require-packages '(web-mode))
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.blade\\.php\\'" . web-mode)) (add-to-list 'auto-mode-alist '("\\.blade\\.php\\'" . web-mode))
@ -44,14 +46,10 @@
(add-to-list 'auto-mode-alist (add-to-list 'auto-mode-alist
'("/\\(views\\|html\\|theme\\|templates\\)/.*\\.php\\'" . web-mode)) '("/\\(views\\|html\\|theme\\|templates\\)/.*\\.php\\'" . web-mode))
;; make web-mode play nice with smartparens
(setq web-mode-enable-auto-pairing nil)
(sp-with-modes '(web-mode)
(eval-after-load 'web-mode
'(progn
(defun prelude-web-mode-defaults ()
;; make web-mode play nice with smartparens
(setq web-mode-enable-auto-pairing nil)
(sp-with-modes '(web-mode)
(sp-local-pair "%" "%" (sp-local-pair "%" "%"
:unless '(sp-in-string-p) :unless '(sp-in-string-p)
:post-handlers '(((lambda (&rest _ignored) :post-handlers '(((lambda (&rest _ignored)
@ -63,7 +61,11 @@
(sp-local-pair "<%# " " %>" :insert "C-c #") (sp-local-pair "<%# " " %>" :insert "C-c #")
(sp-local-tag "%" "<% " " %>") (sp-local-tag "%" "<% " " %>")
(sp-local-tag "=" "<%= " " %>") (sp-local-tag "=" "<%= " " %>")
(sp-local-tag "#" "<%# " " %>"))) (sp-local-tag "#" "<%# " " %>"))
(eval-after-load 'web-mode
'(progn
(defun prelude-web-mode-defaults ())
(setq prelude-web-mode-hook 'prelude-web-mode-defaults) (setq prelude-web-mode-hook 'prelude-web-mode-defaults)
(add-hook 'web-mode-hook (lambda () (add-hook 'web-mode-hook (lambda ()