1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

Rewrite Speedbar expansion for all descendants (bug#73533)

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.  The
narrowing per item introduced by the fix for bug#35014 is
removed because it prevented expanded descendant items when the
top-level item was already expanded.
* lisp/speedbar.el (speedbar--get-line-indent-level): New
function to return the indentation level of the current line.
(speedbar-expand-line-descendants): Use simpler line motion and
no recursion.  Output messages indicating when expansion is in
progress and when it is completed.  Fix expansion of descendants
where the top-level item was already expanded.
This commit is contained in:
Morgan Willcock 2024-10-05 18:33:51 +01:00 committed by Eli Zaretskii
parent 9dcc32f10c
commit bcc4e64fa7

View File

@ -3168,25 +3168,32 @@ With universal argument ARG, flush cached data."
(speedbar-do-function-pointer)) (speedbar-do-function-pointer))
(error (speedbar-position-cursor-on-line)))) (error (speedbar-position-cursor-on-line))))
(defun speedbar--get-line-indent-level ()
"Return the indentation level of the current line."
(save-excursion
(beginning-of-line)
(if (looking-at "[0-9]+:")
(string-to-number (match-string 0))
0)))
(defun speedbar-expand-line-descendants (&optional arg) (defun speedbar-expand-line-descendants (&optional arg)
"Expand the line under the cursor and all descendants. "Expand the line under the cursor and all descendants.
Optional argument ARG indicates that any cache should be flushed." Optional argument ARG indicates that any cache should be flushed."
(interactive "P") (interactive "P")
(save-restriction (dframe-message "Expanding all descendants...")
(narrow-to-region (line-beginning-position) (save-excursion
(line-beginning-position 2)) (let ((top-depth (speedbar--get-line-indent-level)))
(speedbar-expand-line arg) ;; Attempt to expand the top-level item.
;; Now, inside the area expanded here, expand all subnodes of (speedbar-expand-line arg)
;; the same descendant type. ;; Move forwards, either into the newly expanded list, onto an
(save-excursion ;; already expanded list, onto a sibling item, or to the end of
(speedbar-next 1) ;; Move into the list. ;; the buffer.
(let ((err nil)) (while (and (zerop (forward-line 1))
(while (not err) (not (eobp))
(condition-case nil (> (speedbar--get-line-indent-level) top-depth)
(progn (speedbar-expand-line arg)))))
(speedbar-expand-line-descendants arg) (dframe-message "Expanding all descendants...done")
(speedbar-restricted-next 1)) (speedbar-position-cursor-on-line))
(error (setq err t))))))))
(defun speedbar-contract-line-descendants () (defun speedbar-contract-line-descendants ()
"Expand the line under the cursor and all descendants." "Expand the line under the cursor and all descendants."