+nov.el 1.0 KB

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