diff options
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r-- | emacs/.emacs.d/init/ycp-buffer.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-buffer.el | 22 |
2 files changed, 18 insertions, 6 deletions
diff --git a/emacs/.emacs.d/init/ycp-buffer.el b/emacs/.emacs.d/init/ycp-buffer.el index 7e1128a..944a45e 100644 --- a/emacs/.emacs.d/init/ycp-buffer.el +++ b/emacs/.emacs.d/init/ycp-buffer.el @@ -225,7 +225,7 @@ (my-package my-buffer (:delay 10) (my-keybind global-map - "<f1>" #'my-focus-write + "<f1>" #'my-toggle-focus-write "<insert>" #'my-cycle-windows "C-M-<mouse-4>" #'my-increase-default-face-height "C-M-<mouse-5>" #'my-decrease-default-face-height) 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." |