Browse Source

Add proper justification to epub in #emacs

Colin Powell 5 years ago
parent
commit
c9e8196eb6
3 changed files with 35 additions and 3 deletions
  1. 28 0
      emacs/.config/doom/+nov.el
  2. 3 3
      emacs/.config/doom/config.el
  3. 4 0
      emacs/.config/doom/packages.el

+ 28 - 0
emacs/.config/doom/+nov.el

@@ -0,0 +1,28 @@
+;;; ~/.dotfiles/emacs/.config/doom/+nov.el -*- lexical-binding: t; -*-
+(require 'justify-kp)
+(setq nov-text-width t)
+
+(defun my-nov-window-configuration-change-hook ()
+  (my-nov-post-html-render-hook)
+  (remove-hook 'window-configuration-change-hook
+               'my-nov-window-configuration-change-hook
+               t))
+
+(defun my-nov-post-html-render-hook ()
+  (if (get-buffer-window)
+      (let ((max-width (pj-line-width))
+            buffer-read-only)
+        (save-excursion
+          (goto-char (point-min))
+          (while (not (eobp))
+            (when (not (looking-at "^[[:space:]]*$"))
+              (goto-char (line-end-position))
+              (when (> (shr-pixel-column) max-width)
+                (goto-char (line-beginning-position))
+                (pj-justify)))
+            (forward-line 1))))
+    (add-hook 'window-configuration-change-hook
+              'my-nov-window-configuration-change-hook
+              nil t)))
+
+(add-hook 'nov-post-html-render-hook 'my-nov-post-html-render-hook)

+ 3 - 3
emacs/.config/doom/config.el

@@ -15,7 +15,6 @@
 (if (display-graphic-p)
     (setq doom-theme 'doom-peacock))
 
-
 ;; Fonts
 (setq doom-font (font-spec :family "IBM Plex Mono" :size 14))
 (setq doom-big-font (font-spec :family "IBM Plex Mono" :size 21))
@@ -170,12 +169,13 @@
 (add-to-list 'auto-mode-alist '("\\.plantuml\\'" . planetuml-mode))
 
 (load! "+ui.el")
-(load! "+org")      ;; Org mode stuff like todos and rebindings
+(load! "+org")     ;; Org mode stuff like todos and rebindings
 (load! "+org-cal")
 ;(load! "+elfeed")
+(load! "+nov")     ;; nov.el epub mode settings
 (load! "+mail")    ;; Mail stuff
 (load! "+ranger")
-(load! "+wttrin")     ;; Weather config
+(load! "+wttrin")  ;; Weather config
 
 (defun mpdel-playlist-play ()
   "Start playing the song at point."

+ 4 - 0
emacs/.config/doom/packages.el

@@ -16,6 +16,10 @@
   :recipe (:host github
            :repo "redguardtoo/evil-matchit"))
 
+(package! justify-kp
+  :recipe (:host github
+           :repo "Fuco1/justify-kp"))
+
 ;; eglot instead of lsp
 (package! eglot)