Skip to content

Commit

Permalink
Fix removing our format entry if it comes last in a list
Browse files Browse the repository at this point in the history
If our element appeared last in a list, then we ended up
replacing it with nil, instead of deleting it completely.
  • Loading branch information
tarsius committed Feb 25, 2024
1 parent c4a267d commit 3899157
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions auto-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,25 @@ non-nil."
:group 'auto-compile
:type 'boolean)

(defun auto-compile--tree-member (elt tree)
(defun auto-compile--tree-member (elt tree &optional delete)
;; Also known as keycast--tree-member.
(and (listp tree)
(or (member elt tree)
(catch 'found
(dolist (sub tree)
(when-let ((found (auto-compile--tree-member elt sub)))
(throw 'found found)))))))
(if-let* ((pos (cl-position elt tree))
(mem (nthcdr pos tree)))
(cond ((not delete) mem)
((cdr mem)
(setcar mem (cadr mem))
(setcdr mem (cddr mem))
nil)
((nbutlast tree) nil))
(catch 'found
(dolist (sub tree)
(when-let ((found (auto-compile--tree-member elt sub delete)))
(throw 'found found)))))))

(defun auto-compile-modify-mode-line (after)
(let ((format (default-value 'mode-line-format)))
(when-let ((mem (auto-compile--tree-member 'mode-line-auto-compile format)))
(setcar mem (cadr mem))
(setcdr mem (cddr mem)))
(auto-compile--tree-member 'mode-line-auto-compile format 'delete)
(when after
(if-let ((mem (auto-compile--tree-member after format)))
(push 'mode-line-auto-compile (cdr mem))
Expand Down

0 comments on commit 3899157

Please sign in to comment.