From 0e25d28bfbef31c20ec22c2e508933b3824a8172 Mon Sep 17 00:00:00 2001 From: Morgan Willcock Date: Sat, 28 Sep 2024 19:11:11 +0100 Subject: [PATCH] Rewrite speedbar expansion for all descendants Rewrite 'speedbar-expand-line-descendants' to avoid getting into an infinite loop by reaching max-lisp-eval-depth. The new method avoids querying and displaying information for every movement, instead using a single message to indicate that expansion is in progress, and so is significantly faster. * lisp/speedbar.el (speedbar-expand-line-descendants): Use simpler line motion and no recursion. Output messages indicating when expansion is in progress and when it is completed. --- lisp/speedbar.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lisp/speedbar.el b/lisp/speedbar.el index c13c977938b..11e11e1e56c 100644 --- a/lisp/speedbar.el +++ b/lisp/speedbar.el @@ -3172,21 +3172,22 @@ speedbar-expand-line-descendants "Expand the line under the cursor and all descendants. Optional argument ARG indicates that any cache should be flushed." (interactive "P") - (save-restriction - (narrow-to-region (line-beginning-position) - (line-beginning-position 2)) - (speedbar-expand-line arg) - ;; Now, inside the area expanded here, expand all subnodes of - ;; the same descendant type. - (save-excursion - (speedbar-next 1) ;; Move into the list. - (let ((err nil)) - (while (not err) - (condition-case nil - (progn - (speedbar-expand-line-descendants arg) - (speedbar-restricted-next 1)) - (error (setq err t)))))))) + (dframe-message "Expanding all descendants...") + (save-excursion + (with-restriction + ;; Narrow around the top-level item. + (line-beginning-position) + (condition-case nil + (save-excursion + (speedbar-restricted-move 1) + (line-beginning-position)) + (error (line-beginning-position 2))) + ;; Expand every line until the end of the restriction. + (while (zerop (progn + (speedbar-expand-line arg) + (forward-line 1)))))) + (dframe-message "Expanding all descendants...done") + (speedbar-position-cursor-on-line)) (defun speedbar-contract-line-descendants () "Expand the line under the cursor and all descendants." -- 2.39.5