bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#35014: speedbar-expand-line-descendants opens non-descendant tree en


From: Kieran Barry
Subject: bug#35014: speedbar-expand-line-descendants opens non-descendant tree entries
Date: Tue, 26 Mar 2019 20:55:51 +0000

Patch to fix.

Changelog:
2019-03-26  Kieran Barry  <address@hidden>
* lisp/speedbar.el: speedbar-expand-line-descendants fixed to only expand descendants of current node.

diff --git a/lisp/speedbar.el b/lisp/speedbar.el
index 399ef4557b..81ab8d2306 100644
--- a/lisp/speedbar.el
+++ b/lisp/speedbar.el
@@ -3271,6 +3271,18 @@ With universal argument ARG, flush cached data."
        (speedbar-do-function-pointer))
     (error (speedbar-position-cursor-on-line))))
 
+(defun speedbar--get-entry-depth ()
+    "Extract the depth parameter from speedbar line.
+Returns depth as a string.
+Raises error when line doesn't match speedbar format."
+  (interactive)
+  (save-match-data
+    (save-excursion
+      (beginning-of-line)
+      (if (looking-at "\\([0-9]+\\):")
+          (match-string-no-properties 1)
+        (user-error "Incorrect format for speedbar entry")))))
+
 (defun speedbar-expand-line-descendants (&optional arg)
   "Expand the line under the cursor and all descendants.
 Optional argument ARG indicates that any cache should be flushed."
@@ -3279,15 +3291,29 @@ Optional argument ARG indicates that any cache should be flushed."
   ;; 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))))))
-  )
+    (let ((starting-depth (speedbar--get-entry-depth)))
+      (speedbar-next 1) ;; Move into the list.
+      ;; Expand all descendants of the "next entry" provided they are at
+      ;; depth greater than the initial entry.
+      (speedbar--expand-line-descendants-impl starting-depth)
+  )))
+
+(defun speedbar--expand-line-descendants-impl (calling-depth &optional arg)
+  "Expand the line under the cursor and all descendants recursively.
+Finish if the line to be expanded is not at the same depth as CALLING-DEPTH.
+Optional argument ARG indicates that any cache should be flushed."
+  (interactive "P")
+  (let ((current-depth (speedbar--get-entry-depth)))
+    (unless (equal current-depth calling-depth)
+      (speedbar-expand-line arg)
+      (speedbar-next 1)
+      (let ((err nil))
+        (while (not err)
+          (condition-case nil
+              (progn
+                (speedbar--expand-line-descendants-impl calling-depth)
+                (speedbar-restricted-next 1))
+            (error (setq err t))))))))
 
 (defun speedbar-contract-line-descendants ()
   "Expand the line under the cursor and all descendants."


On Tue, Mar 26, 2019 at 8:28 PM Kieran Barry <address@hidden> wrote:
Current behaviour:
speedbar-expand-line-descendants incorrectly recursively expands all nodes below the current node.

Expected behaviour:
Should only recursively expand descendants of the current node.

Steps to reproduce:
emacs -Q ~
M-x speedbar
<focus to speedbar>
<cursor over a directory that is not the last in list>
[

("[" is bound to `speedbar-expand-line-descendants')

Found in: GNU Emacs 26.1

--
Kieran Barry -- address@hidden
EU Directive 2003/58/EC compliance:
Google Ireland Ltd., Gordon House, Barrow Street, Dublin 4 Ireland
Registered in Dublin, Ireland with # 368047


--
Kieran Barry -- address@hidden
EU Directive 2003/58/EC compliance:
Google Ireland Ltd., Gordon House, Barrow Street, Dublin 4 Ireland
Registered in Dublin, Ireland with # 368047

reply via email to

[Prev in Thread] Current Thread [Next in Thread]