+nov.el 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. ;;; ~/.dotfiles/emacs/.config/doom/+nov.el -*- lexical-binding: t; -*-
  2. (require 'justify-kp)
  3. ;(setq nov-text-width t)
  4. (setq nov-text-width 80)
  5. (defun my-nov-window-configuration-change-hook ()
  6. (my-nov-post-html-render-hook)
  7. (remove-hook 'window-configuration-change-hook
  8. 'my-nov-window-configuration-change-hook
  9. t))
  10. (defun my-nov-post-html-render-hook ()
  11. (if (get-buffer-window)
  12. (let ((max-width (pj-line-width))
  13. buffer-read-only)
  14. (save-excursion
  15. (goto-char (point-min))
  16. (while (not (eobp))
  17. (when (not (looking-at "^[[:space:]]*$"))
  18. (goto-char (line-end-position))
  19. (when (> (shr-pixel-column) max-width)
  20. (goto-char (line-beginning-position))
  21. (pj-justify)))
  22. (forward-line 1))))
  23. (add-hook 'window-configuration-change-hook
  24. 'my-nov-window-configuration-change-hook
  25. nil t)))
  26. (add-hook 'nov-post-html-render-hook 'my-nov-post-html-render-hook)
  27. (add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode))
  28. (defun my-nov-font-setup ()
  29. (face-remap-add-relative 'variable-pitch :family "Liberation Serif"
  30. :size 20
  31. :height 1.0))
  32. (add-hook 'nov-mode-hook 'my-nov-font-setup)