diff options
author | Yuchen Pei <id@ypei.org> | 2024-11-03 16:39:45 +1100 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2024-11-03 16:39:45 +1100 |
commit | 3755a65776e7f2bd921152dafb289365b31f8b9c (patch) | |
tree | 3ec7dc4d956d6ba9f66a849a244f7e0364cd3ed9 /emacs/.emacs.d/lisp/my | |
parent | a6a381db15ad5a2134746c92c5847c2808dbfc21 (diff) |
[emacs] Add org narrow or widen to focus write
Diffstat (limited to 'emacs/.emacs.d/lisp/my')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-buffer.el | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-buffer.el b/emacs/.emacs.d/lisp/my/my-buffer.el index 21401b5..f06956f 100644 --- a/emacs/.emacs.d/lisp/my/my-buffer.el +++ b/emacs/.emacs.d/lisp/my/my-buffer.el @@ -239,12 +239,24 @@ that point." (setq buffer temp-buffer)) (set-window-buffer first-window buffer))) -(defun my-focus-write () - "Make the current window the only one centered with width 80." +(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." (interactive) - (delete-other-windows) - (let ((margin (/ (- (window-width) 80) 2))) - (set-window-margins nil margin margin))) + ;; Only one window in the current frame indicates we are in focus + ;; write mode. + (if (length= (window-list) 1) + (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)))) (defun my-select-new-window-matching-mode (mode) "Select a new window." |