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:
parent
9dcc32f10c
commit
bcc4e64fa7
@ -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)
|
|
||||||
(line-beginning-position 2))
|
|
||||||
(speedbar-expand-line arg)
|
|
||||||
;; Now, inside the area expanded here, expand all subnodes of
|
|
||||||
;; the same descendant type.
|
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(speedbar-next 1) ;; Move into the list.
|
(let ((top-depth (speedbar--get-line-indent-level)))
|
||||||
(let ((err nil))
|
;; Attempt to expand the top-level item.
|
||||||
(while (not err)
|
(speedbar-expand-line arg)
|
||||||
(condition-case nil
|
;; Move forwards, either into the newly expanded list, onto an
|
||||||
(progn
|
;; already expanded list, onto a sibling item, or to the end of
|
||||||
(speedbar-expand-line-descendants arg)
|
;; the buffer.
|
||||||
(speedbar-restricted-next 1))
|
(while (and (zerop (forward-line 1))
|
||||||
(error (setq err t))))))))
|
(not (eobp))
|
||||||
|
(> (speedbar--get-line-indent-level) top-depth)
|
||||||
|
(speedbar-expand-line arg)))))
|
||||||
|
(dframe-message "Expanding all descendants...done")
|
||||||
|
(speedbar-position-cursor-on-line))
|
||||||
|
|
||||||
(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."
|
||||||
|
Loading…
Reference in New Issue
Block a user