joaotavora / darkroom

Simple distraction-free editing
147 stars 12 forks source link

After `desktop-read`, the font is too big #16

Open hapst3r opened 10 months ago

hapst3r commented 10 months ago

Hej fellow(s),

I use text-mode-hook to activate darkroom-mode when I am in an org-mode buffer. This approach works quite alright, but I am struggling to make it work with another recent addition to my workflow, desktop.el.

I want to use desktop to save opened files, window and tab bar configurations. After some tinkering this works out fine, however, when I use desktop-read on a constellation that contains org-mode buffers, it seems like darkroom-mode is applied twice, i.e. the font is even bigger than with normal darkroom-mode applied.

I have tried to use desktop-after-read-hook to re-initialize darkroom-mode:

(defun or/re-initialize-darkroom ()
  (interactive)
  (darkroom-mode -1)
  (darkroom-mode +1)))

However, this does not seem to work, because the text still is oversized. If it were only for one tab or buffer where this is the case, I'd swallow that pill. However, it is the case in all org buffers, which is a tad too annoying with four tabs containing four different org files.

EDIT-1: I have found an approach involving ibuffer, selecting all buffers with a major mode that invokes darkroom-mode via ibuffer-mark-by-mode and then applying my fix via ibuffer-do-eval on those buffers. It is still way too manual for my tastes, but it will work for now.

EDIT-2: After some more research, I have now found a workable solution. It involves filtering the buffer by whether they are derived from text-mode (my criterion for applying darkroom). If they do, I apply my fix from above to them. The function is then called by the desktop-after-read-hook. Better than the other solution, I would still prefer one that doesn't require me doing stuff :P

(defun or/re-initialize-darkroom-programmatically ()
  (dolist (buffer (buffer-list (current-buffer)))
    (with-current-buffer buffer
      (when (or (derived-mode-p 'text-mode))
        (or/re-initialize-darkroom)))))

Have a good day!