diff --git a/emacs/init.el b/emacs/init.el index f55df49..228a0e3 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -22,6 +22,7 @@ ;; Description ;; ;;; Code: +(require 'cl-macs) ;;;; Early Variables (setq custom-file "~/.emacs.d/custom.el") @@ -54,12 +55,13 @@ (use-package el-patch) ;;;; Helper Functions -(defun conditional-keybind (filter-fn target-fn) +(cl-defun conditional-keybind (filter-fn target-fn + &optional (fail-fn #'self-insert-command)) (lambda (_prefix) (interactive "P") (if (funcall filter-fn) (call-interactively target-fn) - (call-interactively #'self-insert-command)))) + (call-interactively fail-fn)))) ;;;; Emacs (use-package emacs @@ -321,6 +323,12 @@ Point must be at the beginning of balanced expression (sexp)." (transpose-sexps 1) (forward-sexp -1)) +(defun looking-at-opening-paren () + (looking-at (rx (or "(" "{" "[")))) + +(defun being-past-closing-paren () + (thing-at-point-looking-at (rx (or ")" "}" "]")))) + ;;;;; Basic (use-package smartparens :hook @@ -331,18 +339,30 @@ Point must be at the beginning of balanced expression (sexp)." scheme-mode :config (evil-define-key 'insert smartparens-mode-map - (kbd "r") (conditional-keybind (lambda () (looking-at "(")) + (kbd "r") (conditional-keybind #'looking-at-opening-paren #'sp-raise-sexp) - (kbd "w") (conditional-keybind (lambda () (looking-at "(")) + (kbd "w") (conditional-keybind #'looking-at-opening-paren #'cc/move-sexp-backward) - (kbd "s") (conditional-keybind (lambda () (looking-at "(")) + (kbd "s") (conditional-keybind #'looking-at-opening-paren #'cc/move-sexp-forward) - (kbd "c") (conditional-keybind (lambda () (looking-at "(")) + (kbd "c") (conditional-keybind #'looking-at-opening-paren #'sp-clone-sexp) - (kbd ">") (conditional-keybind (lambda () (thing-at-point-looking-at ")")) - #'sp-forward-slurp-sexp) - (kbd "<") (conditional-keybind (lambda () (thing-at-point-looking-at ")")) - #'sp-backward-slurp-sexp))) + (kbd "DEL") (conditional-keybind #'being-past-closing-paren + #'sp-backward-delete-sexp + #'evil-delete-backward-char-and-join) + (kbd ">") (conditional-keybind #'being-past-closing-paren + (lambda (prefix) + (interactive "P") + (call-interactively #'backward-char) + (call-interactively #'sp-forward-slurp-sexp) + (call-interactively #'sp-forward-sexp) + (call-interactively #'forward-char))) + (kbd "<") (conditional-keybind #'being-past-closing-paren + (lambda (prefix) + (interactive "P") + (call-interactively #'backward-char) + (call-interactively #'sp-forward-barf-sexp) + (call-interactively #'forward-char))))) (use-package evil-cleverparens :after smartparens