From bc1a9ab08614e8c2bc2ae7e20909abba1497a17e Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Thu, 18 Sep 2014 22:07:58 +0100 Subject: Emacs: Use smartparens to replace 4 other modes Paredit, autopair, cedit and smart-forward. Should work nicely in HTML modes, too! --- tag-emacs/emacs.d/init.el | 92 ++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 69 deletions(-) (limited to 'tag-emacs/emacs.d/init.el') diff --git a/tag-emacs/emacs.d/init.el b/tag-emacs/emacs.d/init.el index 10bdea9..d5b693d 100644 --- a/tag-emacs/emacs.d/init.el +++ b/tag-emacs/emacs.d/init.el @@ -997,8 +997,6 @@ mouse-1: Display Line and Column Mode Menu")))))) ;; replace highlighted text rather than just inserting at point (delete-selection-mode t) -(show-paren-mode t) - (bind-key "S-SPC" #'set-mark-command) (req-package subword @@ -1029,21 +1027,6 @@ mouse-1: Display Line and Column Mode Menu")))))) (setq ace-jump-word-mode-use-query-char nil ace-jump-mode-scope 'window))) -(req-package autopair - :commands (autopair-mode - autopair-on) - :init (progn - (add-hook 'prog-mode-hook #'autopair-on) - (add-hook 'text-mode-hook #'autopair-on) - (add-hook 'yaml-mode-hook #'autopair-on) - (defun autopair-off () - (autopair-mode -1)) - (add-hook 'web-mode-hook #'autopair-off) - (add-hook 'lisp-mode-common-hook #'autopair-off) - (add-hook 'c-mode-common-hook #'autopair-off) - (setq autopair-blink nil - autopair-skip-whitespace nil))) - (req-package expand-region :bind ("C-M-SPC" . er/expand-region)) @@ -1069,61 +1052,34 @@ mouse-1: Display Line and Column Mode Menu")))))) :commands (eldoc-mode) :diminish eldoc-mode :config (progn - (eldoc-add-command 'paredit-backward-delete 'paredit-close-round 'autopair-insert-opening) (setq eldoc-idle-delay 0.1))) -(req-package cedit - :diminish "{}" - :require paredit - :init (progn - (defvar cedit-mode-map (make-sparse-keymap) - "Keymap for the cedit minor mode.") - (define-minor-mode cedit-mode - "Minor mode for paredit-style editing in c-style modes." - :lighter " Cedit") - (defun turn-on-cedit-mode () - (enable-paredit-mode) - (cedit-mode 1)) - (add-hook #'c-mode-common-hook #'turn-on-cedit-mode)) - :config (progn - (bind-key "M-a" #'cedit-beginning-of-statement cedit-mode-map) - (bind-key "M-e" #'cedit-end-of-statement cedit-mode-map) - (bind-key "C-M-d" #'cedit-down-block cedit-mode-map) - (bind-key "C-M-u" #'cedit-up-block-backward cedit-mode-map) - (bind-key "C-M-n" #'cedit-up-block-forward cedit-mode-map) - (bind-key "M-{" #'cedit-wrap-brace cedit-mode-map) - (bind-key "C-)" #'cedit-or-paredit-slurp cedit-mode-map) - (bind-key "C-}" #'cedit-or-paredit-barf cedit-mode-map) - (bind-key "M-" #'cedit-or-paredit-splice-killing-backward cedit-mode-map) - (bind-key "M-r" #'cedit-or-paredit-raise cedit-mode-map))) - -(req-package paredit - :diminish "()" - :commands (paredit-mode) +(req-package smartparens + :defer t :config (progn - (defun ap/cedit-space-delimiter-p (endp delimiter) - "Don't insert a space before delimiters in c-style modes" - (not cedit-mode)) - (add-to-list 'paredit-space-for-delimiter-predicates #'ap/cedit-space-delimiter-p)) - :init (progn - (add-hook 'lisp-mode-common-hook #'enable-paredit-mode) - (put #'paredit-forward-delete 'delete-selection 'supersede) - (put #'paredit-backward-delete 'delete-selection 'supersede) - (add-hook 'minibuffer-setup-hook #'conditionally-enable-paredit-mode) - (defun conditionally-enable-paredit-mode () - "enable paredit-mode during eval-expression" - (if (eq this-command 'eval-expression) - (paredit-mode 1))))) + (sp-use-smartparens-bindings) + (fset 'wrap-with-paren "\C-](") ;; `sp-select-next-thing-exchange' + (bind-key "C-(" #'wrap-with-paren sp-keymap) + (bind-key "C-)" #'sp-forward-slurp-sexp sp-keymap) + (bind-key "M-" #'backwarp-kill-word sp-keymap) + (bind-key "M-?" #'sp-convolute-sexp sp-keymap sp-keymap) + (bind-key "M-t" #'sp-transpose-sexp sp-keymap sp-keymap) + (bind-key "M-r" #'sp-raise-sexp sp-keymap) + (bind-key "M-s" #'sp-splice-sexp sp-keymap) + (bind-key "M-S" #'sp-split-sexp sp-keymap) + (bind-key "M-J" #'sp-join-sexp sp-keymap) + (bind-key "M-" #'sp-splice-sexp-killing-backward sp-keymap) + (bind-key "M-" #'sp-splice-sexp-killing-forward sp-keymap) + (show-smartparens-global-mode t) + (smartparens-global-strict-mode t))) + +(req-package smartparens-config + :require smartparens + :defer t) (req-package move-text :config (move-text-default-bindings)) -(req-package smart-forward - :bind (("C-M-u" . smart-up) - ("C-M-d" . smart-down) - ("C-M-p" . smart-backward) - ("C-M-n" . smart-forward))) - (req-package undo-tree :config (progn (global-undo-tree-mode) @@ -1149,8 +1105,7 @@ mouse-1: Display Line and Column Mode Menu")))))) (defun ap/lisp-setup () (run-hooks 'lisp-mode-common-hook) - (setq indent-tabs-mode nil) - (local-set-key (kbd "RET") #'paredit-newline)) + (setq indent-tabs-mode nil)) (defun set-common-lisp-indentation () (set (make-local-variable 'lisp-indent-function) @@ -1197,8 +1152,7 @@ mouse-1: Display Line and Column Mode Menu")))))) :config (progn (setq nrepl-hide-special-buffers t) (unbind-key "C-c C-f" cider-mode-map) - (add-hook 'cider-mode-hook #'cider-turn-on-eldoc-mode) - (add-hook 'cider-repl-mode-hook #'paredit-mode))) + (add-hook 'cider-mode-hook #'cider-turn-on-eldoc-mode))) (req-package redshank :diminish " Λ" -- cgit 1.4.1