From 38991574c7b479e24a39bc314e8b51123b645984 Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Sun, 25 Feb 2024 22:21:56 +0100 Subject: [PATCH] Fix removing our format entry if it comes last in a list If our element appeared last in a list, then we ended up replacing it with nil, instead of deleting it completely. --- auto-compile.el | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/auto-compile.el b/auto-compile.el index 7050c2c..2956f34 100644 --- a/auto-compile.el +++ b/auto-compile.el @@ -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))