Add some elisp editing stuff

This commit is contained in:
Alexander Rosenberg 2024-09-13 01:20:27 -07:00
parent 35797a591d
commit a3791c4048
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

95
init.el
View File

@ -46,8 +46,8 @@
;; basic stuff
(use-package emacs
:hook (;(emacs-lisp-mode . my/-emacs-lisp-mode-setup-evil-lookup)
(prog-mode . electric-pair-local-mode)
:hook (;;(emacs-lisp-mode . my/-emacs-lisp-mode-setup-evil-lookup)
;;(prog-mode . electric-pair-local-mode)
((text-mode message-mode tex-mode) . flyspell-mode)
((text-mode message-mode tex-mode prog-mode) . auto-fill-mode)
(prog-mode . flyspell-prog-mode))
@ -137,7 +137,8 @@
(setq-default indent-tabs-mode nil
tab-width 4
fill-column 80
comment-multi-line t)
comment-multi-line t
comment-empty-lines 'eol)
;; Tree sitter download locations
(setq treesit-language-source-alist
@ -300,8 +301,13 @@ Interactively, force the recompile if called with a prefix."
("C-c C-+" . evil-numbers/inc-at-pt-incremental)
("C-c C--" . evil-numbers/dec-at-pt-incremental)))
(use-package evil-cleverparens
:hook ((lisp-mode emacs-lisp-mode) . evil-cleverparens-mode)
:hook (((lisp-mode emacs-lisp-mode) . evil-cleverparens-mode)
(evil-cleverparens-mode . paredit-mode))
:bind (:map paredit-mode-map
("C-<return>" . paredit-RET)
("C-RET" . paredit-RET))
:custom
(eldoc-add-command 'paredit-RET)
(evil-cleverparens-use-s-and-S nil))
;; make lisp editing nicer
@ -414,7 +420,7 @@ visual states."
(command
(styles my/orderless-with-initialism basic)))))
; marginalia
;; marginalia
(use-package marginalia
:bind (:map minibuffer-local-map
("M-a" . marginalia-cycle))
@ -455,6 +461,9 @@ visual states."
("M-g i" . consult-imenu)
("M-g I" . consult-imenu-multi)
("M-g r" . consult-imenu-multi)
;; these are so that you can still newline even if a completion popup is open
("C-RET" . newline)
("C-<return>" . newline)
:map help-map
("TAB". consult-info)
("C-m" . consult-man))
@ -637,7 +646,6 @@ to `posframe-show' if the display is graphical."
"--clang-tidy" "--completion-style=detailed"
"--header-insertion=never" "--pch-storage=memory"
"--function-arg-placeholders"))))
;"--malloc-trim" "--function-arg-placeholders"))))
;; gud
(use-package gud
@ -973,11 +981,80 @@ COMMAND and COMINT are like `compile'."
;; yuck (config language for eww)
(use-package yuck-mode)
;; Some Elisp indentation stuff
;; Source: https://github.com/magit/emacsql
;; emacsql.el line 394
(defun my/lisp-inside-plist-p ()
"Return t if point is inside a plist."
(save-excursion
(let ((start (point)))
(beginning-of-defun)
(when-let ((sexp (nth 1 (parse-partial-sexp (point) start))))
(goto-char sexp)
(looking-at (rx "(" (* (syntax whitespace)) ":"))))))
(defun my/-calculate-indent-fix-plists (oldfun &rest args)
"This function is meant to advise `calculate-lisp-indent'.
It calls OLDFUN with ARGS in such an environment as to prevent the default
indentation of plists."
(if (save-excursion
(beginning-of-line)
(my/lisp-inside-plist-p))
(let ((lisp-indent-offset 1))
(apply oldfun args))
(apply oldfun args)))
(advice-add 'calculate-lisp-indent :around
'my/-calculate-indent-fix-plists)
(defvar my/max-lisp-noindent-comment-search-lines 10
"Max lines to search for the noindent comment.")
(defun my/-calculate-lisp-indent-noindent-comment (oldfun &rest args)
"This function is meant to advise `calculate-lisp-indent'.
It calls OLDFUN with ARGS, unless the line ends with the comment
; noindent [LINES]
In this case, it just returns the current amount of indentation. LINES is the
number of lines that this comment affects. This is limited by
`my/max-lisp-noindent-comment-search-lines'.
This only works if its on the first or second form in a block. I think this is
because the indentation code only checks those and then assumes the same
indentation for every following line in the same block. This is probably OK as
I can't imagine too many instances where you need to randomly change the indent
midway through a block, and in those cases you can just stick this on the first
line in the block and manually deal with indentation."
(if (and (save-excursion
(end-of-line)
(re-search-backward
(rx (+ ";") (syntax whitespace) "noindent"
(? (syntax whitespace) (group (+ num)))
line-end)
(pos-bol (- my/max-lisp-noindent-comment-search-lines))
t))
(save-excursion
;; if we are on a blank line, move forward a line
(when (zerop (length (buffer-substring-no-properties
(pos-bol) (pos-eol))))
(beginning-of-line 2))
(<= (count-lines (match-beginning 0) (pos-eol))
(if-let ((match (match-string 1)))
(string-to-number match)
1))))
(save-excursion
(beginning-of-line)
(looking-at (rx (* blank)))
(length (match-string 0)))
(apply oldfun args)))
(advice-add 'calculate-lisp-indent :around
'my/-calculate-lisp-indent-noindent-comment)
;; sly
(use-package sly
:hook (lisp-mode . my/-lisp-mode-autoconnect-sly)
:bind (:map sly-mode-map
("C-c e" . my/sly-show-notes-at-point))
("C-c e" . my/sly-show-notes-at-point)) ; noindent
:autoload sly-connected-p
:init
(defun my/-lisp-mode-autoconnect-sly ()
@ -1634,10 +1711,12 @@ one of the normal rainbow-delimiters-depth-N-face faces."
;; page break lines
(use-package page-break-lines
:hook (helpful-mode . page-break-lines-mode)
:config
(global-page-break-lines-mode 1)
(add-to-list 'page-break-lines-modes 'prog-mode)
(add-to-list 'page-break-lines-modes 'text-mode))
(add-to-list 'page-break-lines-modes 'text-mode)
(add-to-list 'page-break-lines-modes 'helpful-mode))
;; fun!
(use-package mines)