diff options
author | Yuchen Pei <id@ypei.org> | 2025-01-01 18:09:32 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2025-01-01 18:09:32 +1100 |
commit | 000c991a71e92400d0a31e7c65b5c9bb8f3ef192 (patch) | |
tree | 761400fd6b57a634a1c9e77cbefcebf08edbaff5 /emacs/.emacs.d | |
parent | 82cf9a13134204b87b7fe01d1cebdf5771d7cebb (diff) |
[emacs] Enhance epub reading
* emacs/.emacs.d/init/ycp-markup.el: set text-width to be a bit less
than my-org-focus-write width (76 vs 80); increase
next-screen-context-lines in nov mode; set left text margin to 2 in
nov mode
* emacs/.emacs.d/init/ycp-org.el: Add keybindings to nov-mode when
org-remark is available. Unfortunately org-remark-nov-mode is a global
minor mode
* emacs/.emacs.d/lisp/my/my-buffer.el: update my-toggle-focus-write to
use empty buffers on both sides
* emacs/.emacs.d/lisp/my/my-nov.el: a function to set left margin in
nov mode
* emacs/.emacs.d/lisp/my/my-org-remark.el: a convenience function to
org-remark to mark or open depending on active mark
Also use my custom nov.el repo
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r-- | emacs/.emacs.d/init/ycp-markup.el | 5 | ||||
-rw-r--r-- | emacs/.emacs.d/init/ycp-org.el | 15 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-buffer.el | 45 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-nov.el | 3 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-org-remark.el | 36 | ||||
m--------- | emacs/.emacs.d/lisp/nov.el | 0 |
6 files changed, 98 insertions, 6 deletions
diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el index d55586d..2225621 100644 --- a/emacs/.emacs.d/init/ycp-markup.el +++ b/emacs/.emacs.d/init/ycp-markup.el @@ -89,8 +89,11 @@ (my-package nov (:delay 15) (add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)) - (setq nov-text-width fill-column) + (setq nov-text-width 76) (add-hook 'nov-mode-hook 'follow-mode) + (add-hook 'nov-mode-hook (lambda () + (setq next-screen-context-lines 4))) + (add-hook 'nov-post-html-render-hook 'my-nov-set-left-margin) (require 'my-nov) (my-override nov-render-title) (my-override nov-scroll-up) diff --git a/emacs/.emacs.d/init/ycp-org.el b/emacs/.emacs.d/init/ycp-org.el index bb1b828..a4b9e87 100644 --- a/emacs/.emacs.d/init/ycp-org.el +++ b/emacs/.emacs.d/init/ycp-org.el @@ -518,5 +518,20 @@ (:delay 60) (require 'my-ox-jira)) +(my-package org-remark + (:install t) + (:delay 60) + (setq org-remark-notes-display-buffer-action + '(display-buffer-reuse-mode-window)) + (require 'nov) + (my-keybind nov-mode-map + "M-n" #'org-remark-next + "M-p" #'org-remark-prev + "<return>" #'my-org-remark-open-or-create + "o" #'org-remark-view + "d" #'org-remark-delete) + (with-eval-after-load 'nov + (org-remark-nov-mode +1))) + (provide 'ycp-org) ;;; ycp-org.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-buffer.el b/emacs/.emacs.d/lisp/my/my-buffer.el index f06956f..c17e765 100644 --- a/emacs/.emacs.d/lisp/my/my-buffer.el +++ b/emacs/.emacs.d/lisp/my/my-buffer.el @@ -239,24 +239,54 @@ that point." (setq buffer temp-buffer)) (set-window-buffer first-window buffer))) +(defun my-set-left-buffer () + "Generate and switch to an empty buffer." + (interactive) + (set-window-buffer + (window-left (get-buffer-window)) + (with-current-buffer (get-buffer-create "*my-left*") + (read-only-mode t) + (current-buffer)))) + +(defun my-set-right-buffer () + "Generate and switch to an empty buffer." + (interactive) + (set-window-buffer + (window-right (get-buffer-window)) + (with-current-buffer (get-buffer-create "*my-right*") + (read-only-mode t) + (current-buffer)))) + (defun my-toggle-focus-write () "Toggle focus write mode. Focus write: make the current window the only one centered with -width 80. If in org-mode, also narrow to current subtree." +width 80. If in org-mode, also narrow to current subtree. Make +buffers on both sides empty read-only buffers." (interactive) ;; Only one window in the current frame indicates we are in focus ;; write mode. - (if (length= (window-list) 1) + (if (and (equal + (buffer-name + (window-buffer (window-left (get-buffer-window)))) + "*my-left*") + (equal + (buffer-name + (window-buffer (window-right (get-buffer-window)))) + "*my-right*")) (progn (winner-undo) (when (derived-mode-p 'org-mode) (widen))) (when (derived-mode-p 'org-mode) (org-narrow-to-subtree)) - (delete-other-windows) - (let ((margin (/ (- (window-width) 80) 2))) - (set-window-margins nil margin margin)))) + (my-set-left-buffer) + (my-set-right-buffer) + (let ((margin (/ (- 80 (window-width)) 2))) + (enlarge-window margin t) + (windmove-left) + (enlarge-window (- margin) t) + (windmove-right)))) (defun my-select-new-window-matching-mode (mode) "Select a new window." @@ -415,6 +445,11 @@ for the given MAJOR-MODE, any text is appended to it." (4 (my-buffer-scratch-setup region default-mode)) (_ (my-buffer-scratch-setup region))))) +(defun my-new-empty-buffer () + "Generate and switch to an empty buffer." + (interactive) + (switch-to-buffer (generate-new-buffer "empty"))) + (defcustom my-scratch-buffer-default-mode 'org-mode "Default major mode for `my-buffer-create-scratch'." :type 'symbol diff --git a/emacs/.emacs.d/lisp/my/my-nov.el b/emacs/.emacs.d/lisp/my/my-nov.el index 4e2f60a..d893017 100644 --- a/emacs/.emacs.d/lisp/my/my-nov.el +++ b/emacs/.emacs.d/lisp/my/my-nov.el @@ -64,5 +64,8 @@ chapter title." (my-copy-file-with-staging nov-file-name dest staging))) +(defun my-nov-set-left-margin () + (set-left-margin (point-min) (point-max) 2)) + (provide 'my-nov) ;;; my-nov.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-org-remark.el b/emacs/.emacs.d/lisp/my/my-org-remark.el new file mode 100644 index 0000000..3e0ef0a --- /dev/null +++ b/emacs/.emacs.d/lisp/my/my-org-remark.el @@ -0,0 +1,36 @@ +;;; my-org-remark.el -- customization to org-remark -*- lexical-binding: t -*- + +;; Copyright (C) 2025 Free Software Foundation, Inc. + +;; Author: Yuchen Pei <id@ypei.org> +;; Package-Requires: ((emacs "29.4")) + +;; This file is part of dotted. + +;; dotted is free software: you can redistribute it and/or modify it under +;; the terms of the GNU Affero General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; dotted is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with dotted. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; customization to org-remark. + +;;; Code: + +(defun my-org-remark-open-or-create () + (interactive) + (if mark-active + (call-interactively 'org-remark-mark) + (call-interactively 'org-remark-open))) + +(provide 'my-org-remark) +;;; my-org-remark.el ends here diff --git a/emacs/.emacs.d/lisp/nov.el b/emacs/.emacs.d/lisp/nov.el -Subproject bbb5c60bfd6b09cffe0406a56930105335f0788 +Subproject c0d30da504fb0b68d8c28ff61a5e0095acda7f5 |