feat: Progress towards comfortable Lisp editing

This commit is contained in:
Madeleine Sydney
2025-02-02 14:51:04 -07:00
parent a345b5a72d
commit fc14c41edd
11 changed files with 623 additions and 39 deletions

View File

@@ -1,5 +1,9 @@
;;; syd-evil.el -*- lexical-binding: t; -*-
;; More sensible undo functionality. Emacs' default is very weird, not
;; maintaining a proper history.
(use-package undo-fu)
;; Vim emulation.
(use-package evil
:preface
@@ -60,18 +64,24 @@ Otherwise, nil."
nil)))
(add-hook 'syd-escape-hook #'syd-evil-nohl-h)
(general-def
:states 'motion
"/" #'evil-ex-search-forward
"?" #'evil-ex-search-backward
"n" #'evil-ex-search-next
"N" #'evil-ex-search-previous
"*" #'evil-ex-search-word-forward)
(evil-mode 1))
(defvar evil-collection-key-blacklist)
;; A large, community-sourced collection of preconfigured Evil-mode
;; integrations.
(use-package evil-collection
:after evil
:defer t
;; :after evil
;; :defer t
:custom (evil-collection-setup-minibuffer t)
:config
:preface
(defvar evil-collection-key-blacklist)
(unless noninteractive
(defvar syd-evil-collection-disabled-list
'(anaconda-mode buff-menu calc comint company custom eldoc elisp-mode ert
@@ -314,4 +324,29 @@ modules."
:bind (:map evil-visual-state-map
("*" . evil-visualstar/begin-search-forward)))
(defvar syd-evil-last-eval-expression-register ?e
"An Evil-mode register in which the last expression evaluated with an
interactive call to `eval-expression' is stored.")
(with-eval-after-load 'evil
(defun syd-set-eval-expression-register-a (expr &rest _)
"If called interactively, set the register
`syd-evil-last-eval-expression-register' to a printed form of EXPR."
(when (called-interactively-p 'interactive)
(->> (pp-to-string expr)
(string-remove-suffix "\n")
(evil-set-register syd-evil-last-eval-expression-register))))
(advice-add #'eval-expression
:after #'syd-set-eval-expression-register-a))
;; HACK: '=' unpredictably moves the cursor when it really doesn't need to.
(defun syd-evil-dont-move-point-a (fn &rest args)
"Used as :around advice on Evil operators to avoid moving the point."
;; We don't use `save-excursion', as we /only/ want to restore the point.
(save-excursion (apply fn args)))
(with-eval-after-load 'evil
(advice-add #'evil-indent
:around #'syd-evil-dont-move-point-a))
(provide 'syd-evil)