localauthor / org-side-tree

Navigate Org-mode outlines in Emacs via side window
GNU General Public License v3.0
42 stars 4 forks source link

[Question] How to enable truncate-lines only for org-side-tree window? (Continuous lines actually caused by visual-line-mode) #8

Closed IceAsteroid closed 9 months ago

IceAsteroid commented 9 months ago

Hi, greetings!

First off, I did try to add truncate-lines to the org-side-tree-mode-hook as follows, but it didn't take affect either for org-side-tree window nor did it affect other buffers.

Like this: (add-hook 'org-side-tree-mode-hook (lambda () (toggle-truncate-lines 1)))

Or: (add-hook` 'org-side-tree-mode-hook 'toggle-truncate-lines)

I've also tried it outside of use-package, but it sill didn't work.

After that, I defined the before & after hooks with defadvice, it worked for before hook but not after hook, and it'd affect all other buffers when org-side-tree is open.

Like this:

    defadvice org-side-tree (before run-org-side-tree activate)
      "Run `before-org-side-tree-hook'."
      (run-hooks 'before-org-side-tree-hook))
    ;;(defadvice org-side-tree (after run-org-side-tree activate)
    ;;  "Run `after-org-side-tree-hook'."
    ;;  (run-hooks 'before-org-side-tree-hook))
    (add-hook 'before-org-side-tree-hook (lambda () (setq-local org-hide-leading-stars t)))
    (add-hook 'before-org-side-tree-hook (lambda () (setq-local truncate-lines t)
                                (setq-local  truncate-partial-width-windows t)
                                (toggle-truncate-lines 1)))

Any ideas?

localauthor commented 9 months ago

After some digging, it looks like the issue is caused by the variable truncate-partial-width-windows.

When that variable is non-nil, it overrides the variable truncate-lines, and thereby nullifies all your valiant efforts --- deeply frustratingly.

From the doctring of truncate-lines: "Note that this is overridden by the variable truncate-partial-width-windows if that variable is non-nil and this buffer is not full-frame width."

So, try something like this:

(add-hook 'org-side-tree-mode-hook
          (lambda ()
            (setq-local truncate-lines nil)
            (setq-local truncate-partial-width-windows nil)))
IceAsteroid commented 9 months ago

It seems that it is the org-side-tree-mode-hook's problem. It's because that simply setting setq truncate-lines t for global just as a try, or setq-local truncate-lines t, both do not work at all.

It's why I set (setq-local truncate-partial-width-windows t) for another try.

Expressions added to the hook do not work at all, weird.

Moreover, what I did was trying to enable truncate-lines solely for org-side-tree's window, what's the point of setting truncate-lines to nil as follows?

(add-hook 'org-side-tree-mode-hook (lambda () (setq-local truncate-lines nil) (setq-local truncate-partial-width-windows nil)))

To put it more plain, I want it to not display continuation lines for headings, but cut it off at the edge of a heading, in org-side-tree window

localauthor commented 9 months ago

Sorry, I'm having a hard time understanding the result you want.

When you open anorg-side-tree buffer, by default you should not see continuation lines. That is, the local value of truncate-lines should be t. Is the local value nil?

IceAsteroid commented 9 months ago

I'm very sorry for the trouble caused, It was me forgetting that I've setup a global mode (global-visual-line-mode 1) in the init file, so I thought the org-side-tree was by default meant to be a line continuously in next line if longer than the window, but actually it was not.

So I searched in internet and messed up with truncate-lines, but it was not caused by this anyway.

After setting (add-hook 'org-side-tree-mode-hook (lambda () (visual-line-mode -1))), the problem has then been solved.

It's indeed frustrating, fewww, since I have over 700 lines of my init file. :(

Tips for viewers, I should've used "C-h m" to inspect enabled modes for the org-side-tree's buffer, it was gonna be really helpful to find out the cause.

Again, I apologize for the trouble that I caused, and I'm grateful for the patience that you've given to help me :)

localauthor commented 9 months ago

That was going to be my next question! visual-line-mode is known to cause some problems ;)

Glad you figured it out. And no worries about any "trouble". On the contrary, thank you for raising the issue --- it will help if anyone has a similar issue in the future.

Cheers!