aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-buffer.el
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-01-01 18:09:32 +1100
committerYuchen Pei <id@ypei.org>2025-01-01 18:09:32 +1100
commit000c991a71e92400d0a31e7c65b5c9bb8f3ef192 (patch)
tree761400fd6b57a634a1c9e77cbefcebf08edbaff5 /emacs/.emacs.d/lisp/my/my-buffer.el
parent82cf9a13134204b87b7fe01d1cebdf5771d7cebb (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/lisp/my/my-buffer.el')
-rw-r--r--emacs/.emacs.d/lisp/my/my-buffer.el45
1 files changed, 40 insertions, 5 deletions
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