summaryrefslogtreecommitdiff
path: root/emacs/work_inits/22-lisp.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/work_inits/22-lisp.el')
-rw-r--r--emacs/work_inits/22-lisp.el104
1 files changed, 104 insertions, 0 deletions
diff --git a/emacs/work_inits/22-lisp.el b/emacs/work_inits/22-lisp.el
new file mode 100644
index 0000000..1a7e33d
--- /dev/null
+++ b/emacs/work_inits/22-lisp.el
@@ -0,0 +1,104 @@
+;; Time-stamp: <2022-06-03 09h28 CDT (radix)>
+
+;; ----------------------------------------------------------------------------
+;; Lisp helpers
+
+(defvar lh-pairs '(("(" . ")")
+ ("[" . "]")
+ ("{" . "}")
+ ("<" . ">")
+ ("\"" . "\"")))
+
+(defun lh-forward-delim ()
+ (interactive)
+ (save-match-data
+ (re-search-forward
+ (regexp-opt (mapcar #'cdr lh-pairs)))))
+
+(defun lh-backward-delim ()
+ (interactive)
+ (save-match-data
+ (re-search-backward
+ (regexp-opt (mapcar #'car lh-pairs)))))
+
+(defun lh-matching-delim ()
+ (interactive)
+ (cond
+ ((looking-at (regexp-opt (mapcar #'car lh-pairs)))
+ (forward-sexp))
+ ((looking-back (regexp-opt (mapcar #'cdr lh-pairs)) nil)
+ (backward-sexp))
+ (t (backward-up-list 1 t t))))
+
+(defun lh-slurp-forward ()
+ (interactive)
+ (corral-shift-forward ?\( ?\)))
+
+(defun lh-slurp-backward ()
+ (interactive)
+ (corral-shift-backward ?\( ?\)))
+
+(defun lh-open-parentheses-dwim (arg)
+ (interactive "P")
+ (if (or (= (line-beginning-position) (point))
+ (looking-at "\\Sw")) (insert-parentheses arg)
+ (backward-sexp)
+ (insert-parentheses 1)))
+
+(defun lh-end-of-defun (arg)
+ (interactive "P")
+ (end-of-defun arg)
+ (re-search-backward ")")
+ (forward-char))
+
+(defun lh-avy-open-paren ()
+ (interactive)
+ (avy-goto-char ?\( ))
+
+(defun lh-avy-close-paren ()
+ (interactive)
+ (avy-goto-char ?\) ))
+
+(use-package corral :ensure t)
+(defun make-lisp-bindings ()
+ (let ((map (eval (read (format "%s-map" major-mode)))))
+ (progn
+ (require 'corral)
+ (define-key map (kbd "M-e") 'forward-sexp)
+ (define-key map (kbd "M-a") 'backward-sexp)
+ (define-key map (kbd "M-,") 'lh-backward-delim)
+ (define-key map (kbd "M-.") 'lh-forward-delim)
+ (define-key map (kbd "M-/") 'lh-matching-delim)
+ (define-key map (kbd "C-c (") 'lh-avy-open-paren)
+ (define-key map (kbd "C-c )") 'lh-avy-close-paren)
+ (define-key map (kbd "(") 'lh-open-parentheses-dwim)
+ (define-key map (kbd "C-c r") 'raise-sexp)
+ (define-key map (kbd "C-k") 'kill-sexp)
+ (define-key map (kbd "M-(") 'corral-parentheses-forward)
+ (define-key map (kbd "M-)") 'corral-parentheses-backward)
+ (define-key map (kbd "M-{") 'corral-braces-forward)
+ (define-key map (kbd "M-}") 'corral-braces-backward)
+ (define-key map (kbd "M-[") 'corral-brackets-forward)
+ (define-key map (kbd "M-]") 'corral-brackets-backward)
+ (define-key map (kbd "C-)") 'lh-slurp-forward)
+ (define-key map (kbd "C-(") 'lh-slurp-backward)
+ (define-key map (kbd "M-p") 'beginning-of-defun)
+ (define-key map (kbd "M-n") 'lh-end-of-defun)
+ t)))
+
+;; ----------------------------------------------------------------------------
+;; Mode configurations
+
+;; (use-package rainbow-blocks :ensure t)
+
+(add-hook 'emacs-lisp-mode-hook
+ (lambda ()
+ (eldoc-mode)
+ (aggressive-indent-mode)
+ (make-lisp-bindings)))
+
+(use-package caps-lock-mode
+ :load-path "~/.emacs.d/scripts/")
+
+;; (use-package slime-company
+;; :ensure t :defer t)