Patch to fix.
Changelog:
2019-03-26 Kieran Barry <kieranb@....com>
* 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."