1

I'd like to use a single function (and later keybind it to a single key) that would do the following:

  • if treemacs is visible in the frame, focus to its window;
  • if not, call treemacs.

I took a look at window-buffer and get-buffer-window, however it's not clear how would I utilize those functions: I don't have a buffer in a variable to start with, and programmatically predicting a treemacs buffer name kinda seems like an non-trivial task (buffer-name gives me something like " *Treemacs-Scoped-Buffer-#<framec *scratch* (projectile-project) - GNU Emacs at HOST 0x555ed35d4cc8>*").

Do I have to loop through all the visible windows, get displayed buffer names and match them against " *Treemacs-Scoped-Buffer" instead? Is there a better way, say a treemacs specific treemacs-visible-p that would tell me the info I need? Or do I approach the problem incorrectly?

1 Answer 1

2

The function treemacs-select-window may do what you are looking for.

From treemacs.el:

(treemacs-select-window)

Select the treemacs window if it is visible.
Bring it to the foreground if it is not visible.
Initialise a new treemacs buffer as calling ‘treemacs’ would if there is no
treemacs buffer for this frame.
1
  • Awesome! Thank you so much! Dec 17, 2021 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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