From: Morgan Willcock <morgan@ice9.digital>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 73533@debbugs.gnu.org
Subject: bug#73533: [PATCH] Rewrite speedbar expansion for all descendants
Date: Mon, 30 Sep 2024 10:03:18 +0100 [thread overview]
Message-ID: <87wmitfr8p.fsf@ice9.digital> (raw)
In-Reply-To: <87v7yeeqig.fsf@ice9.digital> (Morgan Willcock's message of "Sun, 29 Sep 2024 10:52:07 +0100")
[-- Attachment #1: Type: text/plain, Size: 502 bytes --]
Morgan Willcock <morgan@ice9.digital> writes:
> The old code with the fix for bug#35014 narrowed each item recursively
> with the narrowing around the top level preventing a top-level sibling
> being reached.
The change that was made in bug#35014 looks like it broke the expansion
when the item was already partially expanded, so attached is a modified
version of the patch that completely removes the narrowing-per-item
approach and also includes more comments.
Thanks,
Morgan
--
Morgan Willcock
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Rewrite-speedbar-expansion-for-all-descendants.patch --]
[-- Type: text/x-diff, Size: 3563 bytes --]
From aa17e562b9844a50b8b01777c83830d3c4ead963 Mon Sep 17 00:00:00 2001
From: Morgan Willcock <morgan@ice9.digital>
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. 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-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.
---
lisp/speedbar.el | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/lisp/speedbar.el b/lisp/speedbar.el
index c13c977938b..723a5595854 100644
--- a/lisp/speedbar.el
+++ b/lisp/speedbar.el
@@ -3172,21 +3172,36 @@ 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 to ensure that later sibling
+ ;; items will not be entered.
+ (line-beginning-position)
+ (condition-case nil
+ (save-excursion
+ (speedbar-restricted-move 1)
+ ;; Use the line beginning position of the next sibling
+ ;; item to apply the restriction.
+ (line-beginning-position))
+ ;; This was the last sibling item so just apply the
+ ;; restriction to the end of the buffer. This fixes the
+ ;; change applied in bug#35014 which prevented the top-level
+ ;; item from having its descendants expanded if it was already
+ ;; expanded.
+ (error (point-max)))
+ ;; Expand every line until the end of the restriction is reached.
+ (while (zerop (progn
+ ;; Assume that the line will expand and try to
+ ;; expand it.
+ (speedbar-expand-line arg)
+ ;; Moving forwards will be moving into the
+ ;; expanded lists if one opened, into an already
+ ;; expanded list if it was already open, to a
+ ;; sibling, or to the end of restriction.
+ (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
next prev parent reply other threads:[~2024-09-30 9:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-28 19:05 bug#73533: [PATCH] Rewrite speedbar expansion for all descendants Morgan Willcock
2024-09-29 4:46 ` Eli Zaretskii
2024-09-29 9:52 ` Morgan Willcock
2024-09-30 9:03 ` Morgan Willcock [this message]
2024-09-30 18:28 ` Morgan Willcock
2024-10-08 18:36 ` Morgan Willcock
2024-10-19 7:42 ` Eli Zaretskii
2024-10-19 17:30 ` Morgan Willcock
2024-10-19 17:41 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wmitfr8p.fsf@ice9.digital \
--to=morgan@ice9.digital \
--cc=73533@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).