This was my approximation, it's a simple function that take care of the main nodes and updates the content when the buffer is save. Explained below
(defun sb/expand-tags ()
"Expand current `sr-speedbar' buffer file."
(interactive)
;; We assume that the speedbar name is the same as the file of the buffer
(let* ((current-buffer-name (file-name-nondirectory (buffer-file-name)))
(file-point nil)
(line-list '()))
(with-current-buffer speedbar-buffer
;; Refresh the current speedbar buffer
(speedbar-refresh)
(goto-char (point-min))
(re-search-forward current-buffer-name)
(setq file-point (point))
;; This function make the point go backwards so we have to save the location
(speedbar-flush-expand-line)
(goto-char file-point)
;; We enter the "expanded" attributes
(forward-line)
(while
;; Check if we reach another file, or the end of the buffer.
(and (not (speedbar-line-file))
(not (equal (point) (point-max))))
(push (point) line-list)
(forward-line))
;; Once we have the point of the main branches, we iterate
;; and expand his content
(seq-map (lambda (line)
(goto-char line)
(speedbar-flush-expand-line))
line-list))))
;; Add it to the save-hook
(add-hook 'after-save-hook 'sb/expand-tags)
There is a couple of things that I had to take into account in order to create this function:
- I assume that the important nodes are the main ones just in the first depth.
- When the speedbar buffer is refresh, it will only show the expanded information of the current file
- The speedbar file node has the same name as the current buffer file.
This function can be added to the main file and has no external dependencies (except for sr-speedbar of course)
If it is necessary I can change the above points to fit the requirements.
Good luck!