alphapapa / org-sidebar

A helpful sidebar for Org mode
GNU General Public License v3.0
527 stars 16 forks source link

Sidebar does not open if body-text is not wide enough #51

Open tefkah opened 3 years ago

tefkah commented 3 years ago

Hi! Thank you for the great package, I've found it very useful so far. I've come across a rather strange issue however.

I like to use olivetti-mode to make org-buffers somewhat "narrower" (different than narrowing the buffer) to make it nicer to write in, like so image

However, when this is active, neither org-sidebar nor org-sidebar-toggle do anything. It does run, as it toggles truncate-lines image If I turn it off it works just as you'd expect. image

The issue does not seem to be with any specific olivetti-mode implementation, but with the fact that it changes the width of the margins/fringes/text. In fact, when I set the character width of olivetti-mode > 110 characters, the sidebar appears. image

Do you know how I could fix this? I've tried to understand why this happens by looking at org-sidebar.el, but no luck so far. There do seem to be checks for the narrowness of buffers, but if I understand correctly this has little to do with the width of the buffer-text.

Thanks in advance!

PS. Amazing that you managed to split side-windows, I struggled for a long time to do so and eventually gave up, but this made me realize it's possible!

alphapapa commented 3 years ago

Hi,

Thanks for the kind words. I'm glad it's useful to you.

The issue does not seem to be with any specific olivetti-mode implementation, but with the fact that it changes the width of the margins/fringes/text. In fact, when I set the character width of olivetti-mode > 110 characters, the sidebar appears.

Do you know how I could fix this? I've tried to understand why this happens by looking at org-sidebar.el, but no luck so far. There do seem to be checks for the narrowness of buffers, but if I understand correctly this has little to do with the width of the buffer-text.

I don't know how Olivetti works its magic. I guess something it does precludes side windows from working properly. Whatever that might be probably would affect any use of side windows, not just this package's. I'd suggest that you experiment with calling the relevant functions (see link below for example) to display side windows manually while experimenting with various margins, fringes, etc. and see if you can narrow it down. You might also ask Paul Rankin (the author of Olivetti); I'm guessing he will have some insight.

PS. Amazing that you managed to split side-windows, I struggled for a long time to do so and eventually gave up, but this made me realize it's possible!

They aren't actually split, rather the buffers are displayed in side window slots. See the Elisp manual and https://github.com/alphapapa/org-sidebar/blob/1b37069e47d1ea4745eacdf2dec2bdad756ee235/org-sidebar.el#L305 for details.

Sabicool commented 5 months ago

If anyone comes across this problem in the future, here is a quick fix that you can use:

Can define a function with this:

(if (bound-and-true-p olivetti-mode)
      (progn 
        (olivetti-mode 0)
        (org-sidebar-toggle)
        (olivetti-mode 1))
    (org-sidebar-toggle))

Or just bind it directly:

(my/local-leader-keys
      :keymaps 'org-mode-map
      "S" '((lambda () (interactive)
              (if (bound-and-true-p olivetti-mode)
                  (progn 
                    (olivetti-mode 0)
                    (org-sidebar-toggle)
                    (olivetti-mode 1))
                (org-sidebar-toggle)))
            :wk "Toggle sidebar"))

Quickly realised that this resets the olivetti width if its been changed. More complete solution is to bind this function:

(lambda () (interactive)
                (let
                    ((width olivetti-body-width))
                  (if (bound-and-true-p olivetti-mode)
                      (progn 
                        (olivetti-mode 0)
                        (org-sidebar-toggle)
                        (olivetti-mode 1)
                        (olivetti-set-width width))
                    (org-sidebar-toggle))))