forked from magnars/.emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-paredit.el
84 lines (69 loc) · 2.75 KB
/
setup-paredit.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;; My keybindings for paredit
(require 'paredit)
(require 'dash)
(require 's)
(defun paredit-wrap-round-from-behind ()
(interactive)
(forward-sexp -1)
(paredit-wrap-round)
(insert " ")
(forward-char -1))
(defun paredit-wrap-square-from-behind ()
(interactive)
(forward-sexp -1)
(paredit-wrap-square))
(defun paredit-wrap-curly-from-behind ()
(interactive)
(forward-sexp -1)
(paredit-wrap-curly))
(defun paredit-kill-region-or-backward-word ()
(interactive)
(if (region-active-p)
(kill-region (region-beginning) (region-end))
(paredit-backward-kill-word)))
(add-hook 'clojure-mode-hook (lambda () (paredit-mode 1)))
(add-hook 'nrepl-mode-hook (lambda () (paredit-mode 1)))
(add-hook 'emacs-lisp-mode-hook (lambda () (paredit-mode 1)))
(define-key paredit-mode-map (kbd "M-(") 'paredit-wrap-round)
(define-key paredit-mode-map (kbd "M-)") 'paredit-wrap-round-from-behind)
(define-key paredit-mode-map (kbd "M-s-8") 'paredit-wrap-square)
(define-key paredit-mode-map (kbd "M-s-9") 'paredit-wrap-square-from-behind)
(define-key paredit-mode-map (kbd "M-s-(") 'paredit-wrap-curly)
(define-key paredit-mode-map (kbd "M-s-)") 'paredit-wrap-curly-from-behind)
(define-key paredit-mode-map (kbd "C-w") 'paredit-kill-region-or-backward-word)
;; Change nasty paredit keybindings
(defvar my-nasty-paredit-keybindings-remappings
'(("M-s" "s-s" paredit-splice-sexp)
("M-<up>" "s-<up>" paredit-splice-sexp-killing-backward)
("M-<down>" "s-<down>" paredit-splice-sexp-killing-forward)
("C-<right>" "s-<right>" paredit-forward-slurp-sexp)
("C-<left>" "s-<left>" paredit-forward-barf-sexp)
("C-M-<left>" "s-S-<left>" paredit-backward-slurp-sexp)
("C-M-<right>" "s-S-<right>" paredit-backward-barf-sexp)))
(define-key paredit-mode-map (kbd "s-r") 'paredit-raise-sexp)
(--each my-nasty-paredit-keybindings-remappings
(let ((original (car it))
(replacement (cadr it))
(command (car (last it))))
(define-key paredit-mode-map (read-kbd-macro original) nil)
(define-key paredit-mode-map (read-kbd-macro replacement) command)))
;; don't hijack \ please
(define-key paredit-mode-map (kbd "\\") nil)
;; making paredit work with delete-selection-mode
(put 'paredit-forward-delete 'delete-selection 'supersede)
(put 'paredit-backward-delete 'delete-selection 'supersede)
(put 'paredit-newline 'delete-selection t)
;; functions in smartparens that do not have an equivalent in paredit - take a look at them
(when nil
'(sp-beginning-of-sexp
sp-end-of-sexp
sp-next-sexp
sp-previous-sexp
sp-kill-sexp
sp-unwrap-sexp
sp-backward-unwrap-sexp
sp-select-next-thing-exchange
sp-select-next-thing
sp-forward-symbol
sp-backward-symbol))
(provide 'setup-paredit)