Fix adjust-parens indent stuff

This commit is contained in:
Alexander Rosenberg 2024-10-16 23:10:20 -07:00
parent 68aa9afd18
commit 34e599de92
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

59
init.el
View File

@ -493,19 +493,56 @@ With NO-EDGE, return nil if beg or end fall on the edge of the range."
(use-package adjust-parens (use-package adjust-parens
:hook (prog-mode . adjust-parens-mode) :hook (prog-mode . adjust-parens-mode)
:config :config
(defun my/normal-state-lisp-indent-adjust-parens () (defun my/lisp-indent-adjust-parens ()
"Like `lisp-indent-adjust-parens', but got to first char on line first." "Like `lisp-indent-adjust-parens', but got to first char on line first.
Also, this works even if the region is active (it indents every line in the
region)."
(interactive) (interactive)
(back-to-indentation) (save-mark-and-excursion
(lisp-indent-adjust-parens)) (let ((end (mark t))
(defun my/normal-state-lisp-dedent-adjust-parens () (line-count 1)
"Like `lisp-dedent-adjust-parens', but got to first char on line first." (indent-cols))
(when (and (region-active-p) end)
(setq mark-active nil
line-count (count-lines (point) end))
(when (> (point) end)
(let ((start (point)))
(goto-char end)
(setq end start))))
;; find the indentation column of each line
(save-excursion
(dotimes (_ line-count)
(back-to-indentation)
(push (- (point) (pos-bol)) indent-cols)
(forward-line))
(cl-callf nreverse indent-cols))
(cl-loop repeat line-count
for indent-col in indent-cols
for bol = (pos-bol)
do (back-to-indentation)
;; skip this line if the indentation has changed
when (= (- (point) bol) indent-col) do
(lisp-indent-adjust-parens)
;; if the indent failed, stop
(when (= (- (point) bol) indent-col)
(cl-return))
do (forward-line)))))
(defun my/lisp-dedent-adjust-parens ()
"Like `lisp-dedent-adjust-parens', but got to first char on line first.
Also, this works even if the region is active (it just jumps to the first line
in the region and indents once)."
(interactive) (interactive)
(back-to-indentation) (save-mark-and-excursion
(lisp-dedent-adjust-parens)) (let ((end (mark t)))
(evil-define-key 'normal adjust-parens-mode-map (when (and (region-active-p) end)
(kbd "<tab>") #'my/normal-state-lisp-indent-adjust-parens (setq mark-active nil)
(kbd "<backtab>") #'my/normal-state-lisp-dedent-adjust-parens)) (when (> (point) end)
(goto-char end))))
(back-to-indentation)
(lisp-dedent-adjust-parens)))
(evil-define-key '(normal visual) adjust-parens-mode-map
(kbd "<tab>") #'my/lisp-indent-adjust-parens
(kbd "<backtab>") #'my/lisp-dedent-adjust-parens))
;; for when the files are just too large ;; for when the files are just too large
(use-package vlf (use-package vlf