Ihor Radchenko <[email protected]> writes: > Björn Kettunen <[email protected]> writes: > >>> Just try >>> 1. make repro >>> 2. M-x find-file /tmp/test.org >>> You will have a single window in the Emacs frame >>> 3. Add a heading >>> * heading >>> 4. C-c C-z >>> 5. The note window will pop up >>> 6. type something >>> 7. C-c C-c >>> 8. There will be two windows in Emacs frame >> >> I could reproduce this issue. I think saving the window configuration >> after poping to the org-log-note marker but before poping the org-note >> buffer would work for both setups. >> >> In both cases the window configuration in that frame the org-note is >> taken should be saved and restored. >> >> Saving the window configuration of that frame the org-note is in would >> make sure the correct window configuration is restore no matter what >> frame is the frame of origin. > > This fixes my reproducer, but leave conceptually similar problem. > Try > > 1. make repro > 2. M-x find-file /tmp/test.org > 3. Add a heading > * TODO heading > 4. M-x org-agenda RET < t > 5. Agenda buffer will show up with TODO heading listed > 6. C-x 1 to maximize the agenda buffer > 7. Put cursor on TODO heading > 8. C-c C-z > 9. Type something > 10. C-c C-c > 11. Instead of returning to agenda buffer, the test.org buffer will be > displayed.
Thanks for the reproducer. Especially the make repro target. One note for it it didn't open a unless I removed the & on the repro target. I figure it would be best to store two window configuration, one for before and one for after moving to the note target. When the starting frame when pressing C-c C-z is the same as the one the note is taken in then the previous window configuration is restore, nothing else happens. If the starting and the note frame is different then the configuration from just before opening the note window is saved, i.e. from the frame the target org file is in and then the previous frame is activated with that previous's frame window configuration restored. I'm not sure if the starting frames window configuration has to be restored if it's not the org-note frame. I haven't updated any of the commit message or documentation yet.
>From 56533461429e0e93997f814e6c5514c8e357bd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Kettunen?= <[email protected]> Date: Sat, 25 Apr 2026 19:06:26 +0300 Subject: [PATCH] org: Fix restoring window configuration when the frame is different * lisp/org.el (org-add-log-note): Fix restoring the window configuration when where the command to take the note was started on is different to the frame where the note is taken in. * etc/ORG-NEWS: Document the change. * lisp/org.el (org-log-note-extra): (org-add-log-note): (org-store-log-note): Go back to the frame to the function is called from, if it is different to then one the note is taken in. --- etc/ORG-NEWS | 6 ++++++ lisp/org.el | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 8ffb95241..73898b7c9 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -308,6 +308,12 @@ Similarly, if filtered out, ~org-agenda-clock-goto~ would jump close to one of the invisible entries. Now, it jumps to the closest visible entry, or displays it in another window if filtered out. +*** ~org-add-note~ returns to the previous frame if it was different + +Go back to the frame the function or it's versions +i.e. ~org-agenda-add-note~ is called from, if it is different to the +one the note is taken in. + * Version 9.8 ** Important announcements and breaking changes diff --git a/lisp/org.el b/lisp/org.el index d00257fc8..fd7c5dc07 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -10914,6 +10914,8 @@ (defvar org-log-note-purpose nil) (defvar org-log-note-state nil) (defvar org-log-note-previous-state nil) (defvar org-log-note-extra nil) +(defvar org-log-note-previous-frame) +(defvar org-log-note-previous-window-configuration nil) (defvar org-log-note-window-configuration nil) (defvar org-log-note-return-to (make-marker)) (defvar org-log-note-effective-time nil @@ -11080,10 +11082,12 @@ (defun org-add-log-note (&optional _purpose) (when (and (equal org-log-note-this-command this-command) (= org-log-note-recursion-depth (recursion-depth))) (remove-hook 'post-command-hook 'org-add-log-note) + (setq org-log-note-previous-frame (selected-frame)) + (setq org-log-note-previous-window-configuration (current-window-configuration)) (setq org-log-setup nil) - (setq org-log-note-window-configuration (current-window-configuration)) (move-marker org-log-note-return-to (point)) (pop-to-buffer (marker-buffer org-log-note-marker) '(org-display-buffer-full-frame)) + (setq org-log-note-window-configuration (current-window-configuration)) (goto-char org-log-note-marker) (pop-to-buffer "*Org Note*" '(org-display-buffer-split)) (erase-buffer) @@ -11193,7 +11197,11 @@ (defun org-store-log-note () (message "Note stored") (org-back-to-heading t)))))) ;; Don't add undo information when called from `org-agenda-todo'. - (set-window-configuration org-log-note-window-configuration) + (if (equal org-log-note-previous-frame (selected-frame)) + (set-window-configuration org-log-note-previous-window-configuration) + (set-window-configuration org-log-note-window-configuration) + (raise-frame org-log-note-previous-frame) + (set-window-configuration org-log-note-previous-window-configuration)) (with-current-buffer (marker-buffer org-log-note-return-to) (goto-char org-log-note-return-to)) (move-marker org-log-note-return-to nil) -- 2.54.0
