Is there a way to jump to a given directory in speedbar?

For example, when I open up emacs and speedbar, it begins in ~/. Which is fine most of the time, but sometimes I'll want to jump to a remote system using tramp such as /sshx:raspberrypi:/home/raspberry. I'd like to make it easy to jump there.

One possible solution is to use a variation of the solution that Ren Wenshan proposed and add a hook to the start of speedbar-mode, but that only solves if I want to go to the same directory every time I start speedbar:

(add-hook 'speedbar-mode-hook
           (lambda ()
             (cd "/sshx:raspberrypi:/home/raspberry")))

Ideally there'd be a function I can call to just change the visible directory in speedbar.

1 Answer 1


The following function will update an open speedbar file/folder buffer with DIRECTORY being the top level. [At some point, it may be a good idea to add support to programmatically check to verify the speedbar buffer is in files mode ... at this time, there is no such check.]

(defun speedbar-jump-to-directory (&optional directory)
"Update the speedbar directory."
  (let ((default-directory (if directory
                               (file-name-as-directory directory)
                                 (read-directory-name "DIRECTORY:  ")))))
  • 1
    I was going to say M-x cd in the speedbar frame, followed by g :-)
    – NickD
    Aug 17, 2021 at 23:29
  • @NickD: Wow, yeah. Why do something straightforward when a custom function will be more complex and still work? I think part of this was just me getting used to working in Speedbar again for the first time in a decade. Thanks for the gentle reminder. Seriously, thank you.
    – Pridkett
    Aug 22, 2021 at 14:56

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.