From 8a4f15b01c0951b8d3efe54848843346ba241aae Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 25 Jun 2018 15:54:38 +0200 Subject: [PATCH] Refactor smartparens default rules Move them to config/default, but move single-lang-specific ones to their respective modules. --- core/core-editor.el | 18 ++++-------------- modules/config/default/config.el | 16 ++++++++++++---- modules/lang/elixir/config.el | 3 +++ modules/lang/latex/config.el | 3 +++ modules/lang/lua/config.el | 3 +++ 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/core/core-editor.el b/core/core-editor.el index 9b0ea39ff..abd3a6e81 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -157,10 +157,7 @@ fundamental-mode) for performance sake." sp-navigate-consider-sgml-tags nil)) (add-hook 'after-change-major-mode-hook #'doom|disable-smartparens-navigate-skip-match) - ;; smartparenss conflicts with evil-mode's replace state - (add-hook 'evil-replace-state-entry-hook #'turn-off-smartparens-mode) - (add-hook 'evil-replace-state-exit-hook #'turn-on-smartparens-mode) - + ;; autopairing in `eval-expression' and `evil-ex' (defun doom|init-smartparens-in-eval-expression () "Enable `smartparens-mode' in the minibuffer, during `eval-expression' or `evil-ex'." @@ -169,16 +166,9 @@ fundamental-mode) for performance sake." (add-hook 'minibuffer-setup-hook #'doom|init-smartparens-in-eval-expression) (sp-local-pair 'minibuffer-inactive-mode "'" nil :actions nil) - (sp-local-pair sp--html-modes "" - :actions '(insert) :post-handlers '(("| " "SPC"))) - - (sp-local-pair - '(js2-mode typescript-mode rjsx-mode rust-mode - c-mode c++-mode objc-mode java-mode php-mode - css-mode scss-mode less-css-mode stylus-mode) - "/*" "*/" - :actions '(insert) - :post-handlers '(("| " "SPC") ("|\n*/[i][d-2]" "RET") ("\n* ||\n*/[i][d-2]" "*"))) + ;; smartparenss conflicts with evil-mode's replace state + (add-hook 'evil-replace-state-entry-hook #'turn-off-smartparens-mode) + (add-hook 'evil-replace-state-exit-hook #'turn-on-smartparens-mode) (smartparens-global-mode +1)) diff --git a/modules/config/default/config.el b/modules/config/default/config.el index 272ad49d7..d6822a1fc 100644 --- a/modules/config/default/config.el +++ b/modules/config/default/config.el @@ -44,10 +44,6 @@ (sp-local-pair 'ruby-mode "{" "}" :pre-handlers '(:rem sp-ruby-prehandler) :post-handlers '(:rem sp-ruby-posthandler)) - ;; sp's default rules for these modes are obnoxious, so disable them - (provide 'smartparens-elixir) - (provide 'smartparens-latex) - (provide 'smartparens-lua) ;; Expand {|} => { | } ;; Expand {|} => { @@ -63,6 +59,18 @@ (sp-local-pair '(emacs-lisp-mode org-mode markdown-mode gfm-mode) "[" nil :post-handlers '(:rem ("| " "SPC"))) + ;; Reasonable default pairs for comments + (sp-local-pair (append sp--html-modes '(markdown-mode gfm-mode)) + "" :actions '(insert) :post-handlers '(("| " "SPC"))) + + (sp-local-pair + '(js2-mode typescript-mode rjsx-mode rust-mode + c-mode c++-mode objc-mode java-mode php-mode + css-mode scss-mode less-css-mode stylus-mode) + "/*" "*/" + :actions '(insert) + :post-handlers '(("| " "SPC") ("|\n*/[i][d-2]" "RET") ("\n* ||\n*/[i][d-2]" "*"))) + ;; Highjacks backspace to: ;; a) balance spaces inside brackets/parentheses ( | ) -> (|) ;; b) delete space-indented `tab-width' steps at a time diff --git a/modules/lang/elixir/config.el b/modules/lang/elixir/config.el index eb0f7e857..f367ddf29 100644 --- a/modules/lang/elixir/config.el +++ b/modules/lang/elixir/config.el @@ -2,6 +2,9 @@ (def-package! elixir-mode :defer t + :init + ;; disable default smartparens config + (provide 'smartparens-elixir) :config ;; ...and only complete the basics (after! smartparens diff --git a/modules/lang/latex/config.el b/modules/lang/latex/config.el index 6030884dc..9dd2e534d 100644 --- a/modules/lang/latex/config.el +++ b/modules/lang/latex/config.el @@ -14,6 +14,9 @@ ;; Plugins ;; +;; sp's default rules are obnoxious, so disable them +(provide 'smartparens-latex) + (after! tex ;; Set some varibles to fontify common LaTeX commands. (load! "+fontification") diff --git a/modules/lang/lua/config.el b/modules/lang/lua/config.el index db48750f7..9774638b2 100644 --- a/modules/lang/lua/config.el +++ b/modules/lang/lua/config.el @@ -1,5 +1,8 @@ ;;; lang/lua/config.el -*- lexical-binding: t; -*- +;; sp's default rules are obnoxious, so disable them +(provide 'smartparens-lua) + (after! lua-mode (set-lookup-handlers! 'lua-mode :documentation 'lua-search-documentation) (set-electric! 'lua-mode :words '("else" "end"))