I'm using sr-speedbar.

I would like it to automatically full expand current file buffer, and update the bar content when I save the current buffer.

I tried something like : (add-hook 'after-save-hook 'speedbar-flush-expand-line) in my init file but it does not work since my cursor is in my file buffer window. The point is to have tags of file buffer always displayed and up to date with file content on disk.

  • Same question asked on SO
    – NickD
    Commented Oct 30, 2020 at 15:53
  • I deleted the one on SO but it reduces visibility. It only has 9 views in more that 24 hours...
    – Welgriv
    Commented Oct 30, 2020 at 16:34
  • 2
    The issue is not necessarily the number of views, but rather silent evaluations by some of the forum participants regarding the time needed to figure out an answer, test it and write it up -- with the understanding that there may be follow-up questions and/or problems encountered by the O.P. that require additional time. And, of course, the spare time available by the forum participants to do all that ...
    – lawlist
    Commented Oct 31, 2020 at 6:11

1 Answer 1


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."
  ;; 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
      (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
      (goto-char file-point)
      ;; We enter the "expanded" attributes
      ;; 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)
      ;; Once we have the point of the main branches, we iterate
      ;; and expand his content
      (seq-map (lambda (line)
         (goto-char line)

;; 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:

  1. I assume that the important nodes are the main ones just in the first depth.
  2. When the speedbar buffer is refresh, it will only show the expanded information of the current file
  3. 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!

  • Thanks for the trying. It does expand when save, but it does not refresh the content. Maybe I was unclear: there is a function accessible with GUI on the speed bar, you just right clic and select 'flush cash & expand'. I would like this to be executed on the after-save hook. I feel like your function does not flush the cache.
    – Welgriv
    Commented Nov 4, 2020 at 12:34
  • Ok, I change the function speedbar-expand-line with speedbar-flush-expand-line which is the function called when you use it in the pop-up menu, it seems to work with the semantic-speedbar implementation, if you find any problem, please tell me which language/implementation are you using, thanks.
    – Fermin MF
    Commented Nov 4, 2020 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.