feat(emacs): recreate my old hydra menu for writeroom with transient
Create a Transient menu to adapt on the fly the width of my buffers when using writeroom-mode. This commit also adds two other functions: - `my/writeroom-reset` which resets the width of the buffer to its default state - `my/writeroom-fit-buffer` which sets the width of the buffer to be exactly what is needed to fit the longest line of the buffer
This commit is contained in:
@@ -505,7 +505,7 @@ A couple of keybindings are hidden from which-key, otherwise there’s not
|
||||
much to say. The prefix here is ~w~.
|
||||
#+name: keybindings-windows
|
||||
| Key | Function | Description | Package |
|
||||
|-----+-------------------------------+-------------+----------------|
|
||||
|-----+-------------------------------+----------------+----------------|
|
||||
| | | windows | |
|
||||
| c | evil-window-left | | evil |
|
||||
| t | evil-window-down | | evil |
|
||||
@@ -530,7 +530,9 @@ much to say. The prefix here is ~w~.
|
||||
| o | other-window | | |
|
||||
| D | delete-other-windows | | |
|
||||
| w | | writeroom | |
|
||||
| w. | writeroom-buffer-width/body | | writeroom-mode |
|
||||
| w. | my/writeroom-transient | adapt width | |
|
||||
| w= | my/writeroom-reset | reset width | |
|
||||
| wf | my/writeroom-fit-buffer | fit to content | |
|
||||
| ww | writeroom-mode | | writeroom-mode |
|
||||
|
||||
** Quit
|
||||
|
||||
@@ -176,4 +176,30 @@ is a bit too small for me, and I prefer not to go full-screen.
|
||||
writeroom-maximize-window nil
|
||||
writeroom-mode-line t
|
||||
writeroom-major-modes '(text-mode org-mode markdown-mode nov-mode Info-mode)))
|
||||
|
||||
(with-eval-after-load 'transient
|
||||
(defun my/writeroom-reset ()
|
||||
(interactive)
|
||||
(setq writeroom-width 100)
|
||||
(writeroom-adjust-width nil))
|
||||
|
||||
(defun my/writeroom-fit-buffer ()
|
||||
"Set writeroom to fit the longest line in the current buffer."
|
||||
(interactive)
|
||||
(when writeroom-mode
|
||||
(let ((max-width 0))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (not (eobp))
|
||||
(end-of-line)
|
||||
(setq max-width (max max-width (current-column)))
|
||||
(forward-line 1)))
|
||||
(writeroom-adjust-width (- max-width visual-fill-column-width)))))
|
||||
|
||||
(transient-define-prefix my/writeroom-transient ()
|
||||
"Writewroom Transient"
|
||||
["Adjust"
|
||||
("r" "widen" writeroom-increase-width :transient t)
|
||||
("c" "tighten" writeroom-decrease-width :transient t)
|
||||
("q" "quit" transient-quit-all)]))
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user