diff options
| author | Morgan Willcock | 2024-10-05 18:33:51 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2024-10-19 10:33:35 +0300 |
| commit | bcc4e64fa7aab9f44e3a7bcdf651a32ec52866c2 (patch) | |
| tree | 00b048925678d9f4b7d8b18e5edd9f367ff8d160 | |
| parent | 9dcc32f10cbae9497d6b33fcc739b75c1d5e411c (diff) | |
| download | emacs-bcc4e64fa7aab9f44e3a7bcdf651a32ec52866c2.tar.gz emacs-bcc4e64fa7aab9f44e3a7bcdf651a32ec52866c2.zip | |
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.
| -rw-r--r-- | lisp/speedbar.el | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lisp/speedbar.el b/lisp/speedbar.el index c13c977938b..38fb641acf7 100644 --- a/lisp/speedbar.el +++ b/lisp/speedbar.el | |||
| @@ -3168,25 +3168,32 @@ With universal argument ARG, flush cached data." | |||
| 3168 | (speedbar-do-function-pointer)) | 3168 | (speedbar-do-function-pointer)) |
| 3169 | (error (speedbar-position-cursor-on-line)))) | 3169 | (error (speedbar-position-cursor-on-line)))) |
| 3170 | 3170 | ||
| 3171 | (defun speedbar--get-line-indent-level () | ||
| 3172 | "Return the indentation level of the current line." | ||
| 3173 | (save-excursion | ||
| 3174 | (beginning-of-line) | ||
| 3175 | (if (looking-at "[0-9]+:") | ||
| 3176 | (string-to-number (match-string 0)) | ||
| 3177 | 0))) | ||
| 3178 | |||
| 3171 | (defun speedbar-expand-line-descendants (&optional arg) | 3179 | (defun speedbar-expand-line-descendants (&optional arg) |
| 3172 | "Expand the line under the cursor and all descendants. | 3180 | "Expand the line under the cursor and all descendants. |
| 3173 | Optional argument ARG indicates that any cache should be flushed." | 3181 | Optional argument ARG indicates that any cache should be flushed." |
| 3174 | (interactive "P") | 3182 | (interactive "P") |
| 3175 | (save-restriction | 3183 | (dframe-message "Expanding all descendants...") |
| 3176 | (narrow-to-region (line-beginning-position) | 3184 | (save-excursion |
| 3177 | (line-beginning-position 2)) | 3185 | (let ((top-depth (speedbar--get-line-indent-level))) |
| 3178 | (speedbar-expand-line arg) | 3186 | ;; Attempt to expand the top-level item. |
| 3179 | ;; Now, inside the area expanded here, expand all subnodes of | 3187 | (speedbar-expand-line arg) |
| 3180 | ;; the same descendant type. | 3188 | ;; Move forwards, either into the newly expanded list, onto an |
| 3181 | (save-excursion | 3189 | ;; already expanded list, onto a sibling item, or to the end of |
| 3182 | (speedbar-next 1) ;; Move into the list. | 3190 | ;; the buffer. |
| 3183 | (let ((err nil)) | 3191 | (while (and (zerop (forward-line 1)) |
| 3184 | (while (not err) | 3192 | (not (eobp)) |
| 3185 | (condition-case nil | 3193 | (> (speedbar--get-line-indent-level) top-depth) |
| 3186 | (progn | 3194 | (speedbar-expand-line arg))))) |
| 3187 | (speedbar-expand-line-descendants arg) | 3195 | (dframe-message "Expanding all descendants...done") |
| 3188 | (speedbar-restricted-next 1)) | 3196 | (speedbar-position-cursor-on-line)) |
| 3189 | (error (setq err t)))))))) | ||
| 3190 | 3197 | ||
| 3191 | (defun speedbar-contract-line-descendants () | 3198 | (defun speedbar-contract-line-descendants () |
| 3192 | "Expand the line under the cursor and all descendants." | 3199 | "Expand the line under the cursor and all descendants." |