joostkremers / writeroom-mode

Writeroom-mode: distraction-free writing for Emacs.
BSD 3-Clause "New" or "Revised" License
610 stars 28 forks source link

Option to hide fringes #44

Closed winny- closed 4 years ago

winny- commented 6 years ago

It would be cool to hide fringes as an option in writeroom-mode, such that it is restored after exiting writeroom-mode. I can take a stab at it, mainly writing this issue in case I missed something :)

joostkremers commented 6 years ago

You didn't miss anything. :smiley:

It shouldn't be difficult to implement this. The buffer-local variables left-fringe-width and right-fringe-width control the window's fringes, they just need to be set to the right values.

emacsomancer commented 6 years ago

A mode-hook seems to work (the one below does a few other things as well):

  (add-hook 'writeroom-mode-hook
      (lambda ()
        (if writeroom-mode
        (progn
          (blink-cursor-mode 0)  ; turn off blinky cursor
          (fringe-mode 0)  ; hide fringes
          (setq-local inhibit-message t))  ; don't distract
          (progn
        (blink-cursor-mode t)
        (fringe-mode nil)
        (setq-local inhibit-message t)))))
joostkremers commented 6 years ago

Global effects such as blink-cursor-mode and fringe-mode can also be set as global options in writeroom-global-effects.

However, fringe-mode affects all current and future frames, so strictly speaking it does more than what writeroom-mode allows itself. But I guess that's mainly important to nitpickers such as myself. :wink: To have a frame-only effect, you'd need set-fringe-style (which is problematic as well, because you can't pass it a frame argument), and for a window-only effect, you could use set-window-fringes.

set-window-fringes would have to be activated in writeroom-mode-hook, so something like this:

(defun my-writeroom-mode-function ()
  "Function for `writeroom-mode-hook'."
  (set-window-fringes (selected-window) 0 0))

(add-hook 'writeroom-mode-hook #'my-writeroom-mode-function)

BTW, @emacsomancer you may want to set inhibit-message to nil rather than t in the second progn block. :wink:

templateK commented 6 years ago
(defun my-writeroom-mode-function ()
  "Function for `writeroom-mode-hook'."
  (set-window-fringes (selected-window) 0 0))

(add-hook 'writeroom-mode-hook #'my-writeroom-mode-function)

@joostkremers When I save a buffer, the fringes comes back. Is that a expected behavior? If then, what is the solution for persist hiding fringes when activated writeroom mode after the save? the solution I can come up with is after-save-hook but I hope there's better way.

joostkremers commented 6 years ago

Hmm, I have no idea why the fringes come back after saving the file. writeroom-mode (or actually its dependency visual-fill-column-mode used to have the ability to disable the fringes and the way it was done was to use set-window-fringes. I never had any problems with it back then.

I removed that option at some point, and replaced it with writeroom-fringes-outside-margins, which I found superior: the fringes are still displayed, but they are at the window edges, where they don't bother me. Isn't that an option for you?

templateK commented 6 years ago

I use this mode in the multi column layout as well because I really like text alignment of the mode. then the fringe bothers me a lot. so writeroom-fringes-outside-margins is not an option. If this is not a expected behavior then maybe my emacs configuration messed up on somewhere else. I suppose I have to use fringe-mode. thanks for the reply.