conf-paredit.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;; My keybindings for paredit
  2. (require 'paredit)
  3. (require 'dash)
  4. (require 's)
  5. (defun paredit-wrap-round-from-behind ()
  6. (interactive)
  7. (forward-sexp -1)
  8. (paredit-wrap-round)
  9. (insert " ")
  10. (forward-char -1))
  11. (defun paredit-wrap-square-from-behind ()
  12. (interactive)
  13. (forward-sexp -1)
  14. (paredit-wrap-square))
  15. (defun paredit-wrap-curly-from-behind ()
  16. (interactive)
  17. (forward-sexp -1)
  18. (paredit-wrap-curly))
  19. (defun paredit-kill-region-or-backward-word ()
  20. (interactive)
  21. (if (region-active-p)
  22. (kill-region (region-beginning) (region-end))
  23. (paredit-backward-kill-word)))
  24. ;(add-hook 'clojure-mode-hook (lambda () (paredit-mode 1)))
  25. ;(add-hook 'cider-repl-mode-hook (lambda () (paredit-mode 1)))
  26. ;(add-hook 'emacs-lisp-mode-hook (lambda () (paredit-mode 1)))
  27. (autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
  28. (add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
  29. (add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
  30. (add-hook 'ielm-mode-hook #'enable-paredit-mode)
  31. (add-hook 'lisp-mode-hook #'enable-paredit-mode)
  32. (add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
  33. (add-hook 'scheme-mode-hook #'enable-paredit-mode)
  34. (define-key paredit-mode-map (kbd "M-(") 'paredit-wrap-round)
  35. (define-key paredit-mode-map (kbd "M-)") 'paredit-wrap-round-from-behind)
  36. (define-key paredit-mode-map (kbd "M-s-8") 'paredit-wrap-square)
  37. (define-key paredit-mode-map (kbd "M-s-9") 'paredit-wrap-square-from-behind)
  38. (define-key paredit-mode-map (kbd "M-s-(") 'paredit-wrap-curly)
  39. (define-key paredit-mode-map (kbd "M-s-)") 'paredit-wrap-curly-from-behind)
  40. (define-key paredit-mode-map (kbd "C-w") 'paredit-kill-region-or-backward-word)
  41. ;; Change nasty paredit keybindings
  42. (defvar my-nasty-paredit-keybindings-remappings
  43. '(("M-s" "s-s" paredit-splice-sexp)
  44. ("M-<up>" "M-s-<up>" paredit-splice-sexp-killing-backward)
  45. ("M-<down>" "M-s-<down>" paredit-splice-sexp-killing-forward)
  46. ("C-<right>" "M-s-<right>" paredit-forward-slurp-sexp)
  47. ("C-<left>" "C-s-<left>" paredit-forward-barf-sexp)
  48. ("C-M-<left>" "M-s-<left>" paredit-backward-slurp-sexp)
  49. ("C-M-<right>" "C-s-<right>" paredit-backward-barf-sexp)))
  50. (define-key paredit-mode-map (kbd "s-r") 'paredit-raise-sexp)
  51. (--each my-nasty-paredit-keybindings-remappings
  52. (let ((original (car it))
  53. (replacement (cadr it))
  54. (command (car (last it))))
  55. (define-key paredit-mode-map (read-kbd-macro original) nil)
  56. (define-key paredit-mode-map (read-kbd-macro replacement) command)))
  57. ;; don't hijack \ please
  58. (define-key paredit-mode-map (kbd "\\") nil)
  59. ;; Enable `paredit-mode' in the minibuffer, during `eval-expression'.
  60. (defun conditionally-enable-paredit-mode ()
  61. (if (eq this-command 'eval-expression)
  62. (paredit-mode 1)))
  63. (add-hook 'minibuffer-setup-hook 'conditionally-enable-paredit-mode)
  64. ;; making paredit work with delete-selection-mode
  65. (put 'paredit-forward-delete 'delete-selection 'supersede)
  66. (put 'paredit-backward-delete 'delete-selection 'supersede)
  67. (put 'paredit-newline 'delete-selection t)
  68. ;; functions in smartparens that do not have an equivalent in paredit - take a look at them
  69. (when nil
  70. '(sp-beginning-of-sexp
  71. sp-end-of-sexp
  72. sp-next-sexp
  73. sp-previous-sexp
  74. sp-kill-sexp
  75. sp-unwrap-sexp
  76. sp-backward-unwrap-sexp
  77. sp-select-next-thing-exchange
  78. sp-select-next-thing
  79. sp-forward-symbol
  80. sp-backward-symbol))
  81. (provide 'conf-paredit)