This commit is contained in:
Daniel Ziltener 2023-11-20 01:59:52 +01:00
parent 718c3bff85
commit 7602078739
Signed by: zilti
GPG key ID: B38976E82C9DAE42

View file

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