From 189f8a1b344d185d98156e976ab9564c2d4702bd Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Sun, 10 Aug 2025 11:55:57 -0500 Subject: [PATCH] Though, this is more my style I think --- config-emacs.org | 28 ++++++------ .../my-org-capture-shouldnt-mess-windows.el | 45 ++++++++++++------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/config-emacs.org b/config-emacs.org index 4b2939e..75c9168 100644 --- a/config-emacs.org +++ b/config-emacs.org @@ -78,22 +78,22 @@ (slot . 6) (window-width . 80))) - (require 'org-capture) + ;; (require 'org-capture) - (defun my/is-org-capture-buffer (buffer &optional _rest) - (with-current-buffer buffer - (and (eq major-mode 'org-mode) - org-capture-mode))) + ;; (defun my/is-org-capture-buffer (buffer &optional _rest) + ;; (with-current-buffer (get-buffer buffer) + ;; (and (eq major-mode 'org-mode) + ;; org-capture-mode))) - (add-to-list 'display-buffer-alist - `(my/is-org-capture-buffer - display-buffer-in-side-window - (side . left) - (select . t) - (window-width . 85) - (window-parameters - . ((no-delete-other-windows . t) - (dedicated . t))))) + ;; (add-to-list 'display-buffer-alist + ;; `(my/is-org-capture-buffer + ;; display-buffer-in-side-window + ;; (side . left) + ;; (select . t) + ;; (window-width . 85) + ;; (window-parameters + ;; . ((no-delete-other-windows . t) + ;; (dedicated . t))))) ;; (defun my/is-org-capture-buffer (buffer &optional _rest) ;; (with-current-buffer buffer diff --git a/lisp/org-config/my-org-capture-shouldnt-mess-windows.el b/lisp/org-config/my-org-capture-shouldnt-mess-windows.el index a439cdd..75d4b18 100644 --- a/lisp/org-config/my-org-capture-shouldnt-mess-windows.el +++ b/lisp/org-config/my-org-capture-shouldnt-mess-windows.el @@ -27,26 +27,41 @@ (defun my/side-window-p (window) (window-parameter window 'window-side)) -(defun my/org-capture-shouldnt-mess-windows (fun &rest args) - (set-window-parameter (selected-window) 'window-side nil) - (cl-letf* ((original-pop-to-buffer - (symbol-function 'pop-to-buffer)) +(defun my/org-capture-display-use-side-window (buffer alist) + ;; I think the alist argument is never used + (pop-to-buffer + buffer - ((symbol-function 'pop-to-buffer) - (lambda (buffer &optional action norecord) - (if (equal action '(org-display-buffer-split)) - (funcall original-pop-to-buffer buffer) - (funcall original-pop-to-buffer buffer action norecord))))) - (let ((window--sides-inhibit-check t)) - (apply fun args)))) + '(display-buffer-in-side-window + (side . left) + (window-width . 85) + (window-parameters + . ((no-delete-other-windows . t) + ;;(dedicated . t) + ))))) -(advice-add #'org-capture +(advice-add #'org-display-buffer-split + :override + #'my/org-capture-display-use-side-window) + +(defun my/window-dedicated-p (orig &optional window) + ;; Excuse me? Side windows are not dedicated. + (or (and (not org-capture-mode) + (funcall orig window)) + (eq (funcall orig window) + t))) + +(advice-add #'window-dedicated-p :around - #'my/org-capture-shouldnt-mess-windows) + #'my/window-dedicated-p) (defun my/org-capture-finalize-shouldnt-mess-windows (orig &rest args) - (cl-letf (((symbol-function 'set-window-configuration) - #'ignore)) + (cl-letf* ((orig-set-window-configuration (symbol-function 'set-window-configuration)) + + ((symbol-function 'set-window-configuration) + #'(lambda (&rest args) + (unless (equal (car args) (org-capture-get :return-to-wconf 'local)) + (apply orig-set-window-configuration args))))) (apply orig args))) (advice-add #'org-capture-finalize