My very unexpected journey into Emacs continues...
As I mentioned previously I have been a user of Emacs for decades but never taken the time to truly learn it. I would just use a hacked together init file pulling in packages without much thought. Occasionally I would follow a blog post and it would improve. Ever few years I would try something like Doom emacs but find a reason to not like it.
Complicated development I usually do with an IDE, these days Clion.
After playing with Omarchy and realising it was providing an awesome shell orientated approach to using a computer it seemed sensible to build my computing life around the shell using TUI style apps and things like neovim.
I didn't bother installing my usual emacs config and just left it bare bones. Occasionally I would use it to edit a file but nothing more. One evening I copied over my basic config to make the toolbar disappear but didn't download any packages. My plan was really to just use it to write blog posts. Like this one.
Unexpectedly I found myself really enjoying using Emacs. Enough that I started to read the doc. This lead to me wondering if I could write a function to increase the size of the margins on a window to create a "focused" writing mode.
Turns out that was not that hard, from there creating a minor mode and configuring that was also easy.
I don't think it is perfect but my current goal is to keep downloaded packages to a minimum so this serves as an alternative to doing that.
I think I finally get what they mean by you shape emacs into the editor you want.
Will this continue I am not sure.
There are much better packages available that do this type of thing so actually publishing for all to use isn't worth it. It does serve as to how small a minor mode can be. Here's the code.
(make-variable-buffer-local
(defvar focus-mode nil))
(make-variable-buffer-local
(defvar prev-left-margin-width nil))
(make-variable-buffer-local
(defvar prev-right-margin-width nil))
(defun store-margins ()
(setq prev-left-margin-width left-margin-width)
(setq prev-right-margin-width right-margin-width)
)
(defun set-margins-to (left-width right-width)
(setq left-margin-width left-width)
(setq right-margin-width right-width)
(set-window-buffer nil (current-buffer))
)
(defun restore-margins ()
(interactive)
(when prev-right-margin-width
(progn
(set-margins-to prev-left-margin-width prev-right-margin-width)
(setq prev-left-margin-width nil)
(setq prev-right-margin-width nil)
)))
(defun toggle-focus ()
; (message "State (%s) (%s) (%s)" focus-mode
; prev-left-margin-width
; prev-right-margin-width)
(if (not focus-mode)
(let ((margin-width (/ (- (window-body-width) (current-fill-column)) 2)))
(when (> margin-width 1) (progn
(store-margins)
(setq left-margin-width margin-width)
(setq right-margin-width margin-width)
(set-window-buffer nil (current-buffer))
(setq focus-mode t)
)))
; else
(progn
(restore-margins)
(setq focus-mode nil))
))
;;; ###autoload
(define-minor-mode sf-focus-mode
"Lets get focussed."
:lighter " focus"
(toggle-focus)
)
(provide `sf-focus-mode)