Fix adjust-parens indent stuff
This commit is contained in:
parent
68aa9afd18
commit
34e599de92
55
init.el
55
init.el
@ -493,19 +493,56 @@ With NO-EDGE, return nil if beg or end fall on the edge of the range."
|
||||
(use-package adjust-parens
|
||||
:hook (prog-mode . adjust-parens-mode)
|
||||
:config
|
||||
(defun my/normal-state-lisp-indent-adjust-parens ()
|
||||
"Like `lisp-indent-adjust-parens', but got to first char on line first."
|
||||
(defun my/lisp-indent-adjust-parens ()
|
||||
"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)
|
||||
(save-mark-and-excursion
|
||||
(let ((end (mark t))
|
||||
(line-count 1)
|
||||
(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)
|
||||
(lisp-indent-adjust-parens))
|
||||
(defun my/normal-state-lisp-dedent-adjust-parens ()
|
||||
"Like `lisp-dedent-adjust-parens', but got to first char on line first."
|
||||
(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)
|
||||
(save-mark-and-excursion
|
||||
(let ((end (mark t)))
|
||||
(when (and (region-active-p) end)
|
||||
(setq mark-active nil)
|
||||
(when (> (point) end)
|
||||
(goto-char end))))
|
||||
(back-to-indentation)
|
||||
(lisp-dedent-adjust-parens))
|
||||
(evil-define-key 'normal adjust-parens-mode-map
|
||||
(kbd "<tab>") #'my/normal-state-lisp-indent-adjust-parens
|
||||
(kbd "<backtab>") #'my/normal-state-lisp-dedent-adjust-parens))
|
||||
(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
|
||||
(use-package vlf
|
||||
|
Loading…
Reference in New Issue
Block a user