org-roam icon indicating copy to clipboard operation
org-roam copied to clipboard

How can I have a two-windows mode?

Open alienbogart opened this issue 2 years ago • 4 comments

Brief Abstract

I wish for an option that makes buffers opened from the side buffer to always occupy the other window instead of splitting it so that I always have a maximum of two windows open: the buffer and the roam side buffer.

Long Description

By default, org-roam2 works with three windows: the side buffer to the right, and two horizontal splits to the left. If I open a node from the roam side-buffer, it will open in a third window, in such a way that I have the side-buffer to the right, and two horizontal splits on the left. I wish for the buffer opened in that manner to always occupy the window to the left so there are always only two windows on my screen at all times.

Proposed Implementation (if any)

Any buffer opened from the roam side buffer or any other command will occupy the same window to the left, like this: shot_roam

Please check the following:

  • [X ] No similar feature requests

alienbogart avatar Jun 08 '22 19:06 alienbogart

Note that this is only an issue when using the org-roam buffer as a side-window. In a normal window, C-u C-RET works like you want it.

For the side-window case, something like this works:

(defun org-roam-node-visit (node &optional other-window force)
  "From the current buffer, visit NODE. Return the visited buffer.
Display the buffer in the selected window.  With a prefix
argument OTHER-WINDOW display the buffer in another window
instead.

If NODE is already visited, this won't automatically move the
point to the beginning of the NODE, unless FORCE is non-nil. In
interactive calls FORCE always set to t."
  (interactive (list (org-roam-node-at-point t) current-prefix-arg t))
  (org-roam-node-open node
                      #'(lambda (buffer)
                          (select-window (window-main-window))
                          (switch-to-buffer buffer))
                      ;; (if other-windnot sureow
                      ;;          #'switch-to-buffer-other-window
                      ;;        #'pop-to-buffer-same-window)
                      force))

(As it is, this breaks the non-side-window case, however, and a lot of other situations.)

We could potentially add a user option for this – it's a pretty intuitive behavior, I think. I could figure out the details and do a PR. But since the manual states that buffer customization is left to the user, I'm skeptical as to whether that's really wanted?

leinfink avatar Jun 10 '22 16:06 leinfink

I understand!

Personally, this way feels very natural to me, I tend to prefer vertical splits for most things, probably because my screen is quite small and I have more horizontal space than vertical.

I'd personally welcome the option of using org-roam with a sidebar, but I can understand that it may not feel as natural to others. I'm actually using Doom Emacs, I was not aware that using org-roam buffer as a side window was not the default, so I apologize for that.

The solution that you presented works just fine as a replacement for org-roam-node-visit, and I appreciate it very much! It would be great if the same treatment could be given org-roam-preview-visit. As you can imagine, I'm not really a programming person, I'm just a regular person that follows instructions.

Again, thank you so much!

alienbogart avatar Jun 14 '22 04:06 alienbogart

Glad to help! Be careful, I think my snippet broke something else, like I got errors opening a note with org-roam-find-node or so, I think. I may have a look at org-roam-preview-visit later.

As I understand it, org-roam just doesn't prescribe any default way of configuring the buffer. The manual gives both examples for side-window and normal-window configs. I do think it would be good to have some little options to tweak it easily. But I'm not involved in the project at all, so I will defer to the maintainers 😃

leinfink avatar Jun 14 '22 08:06 leinfink

Glad to help! Be careful, I think my snippet broke something else, like I got errors opening a note with org-roam-find-node or so, I think. I may have a look at org-roam-preview-visit later.

Thanks! I did not experience any breakage myself, but I'll keep an eye on it. To avoid that I could simply rename the function you gave me to my-org-roam-node-visit and mat RET to it org-roam-node-map instead.

alienbogart avatar Jun 15 '22 07:06 alienbogart

Not sure if this is a bug, but I'm finding that using org-roam is using side-window even though the expected behavior is regular window. I used the config that is in the documentation for a regular window.

Using the same .emacs in another machine (native linux) behavior works as expected. But running on a different machine using Debian (emacs compiled from source using git, straight.el for packages), it defaults to side-window behavior.

Seems like a bug?

code-SL avatar Dec 20 '22 00:12 code-SL