branch: externals/org
commit 78e9dd0c4287851ae4ab6a6b7155c229b6e00dd7
Author: Ihor Radchenko <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    Fix when user customization makes Org dialogues pop up in new frames
    
    * lisp/ol.el (org-insert-link):
    * lisp/org-agenda.el (org-agenda-get-restriction-and-command):
    * lisp/org-attach.el (org-attach):
    * lisp/org-clock.el (org-clock-select-task):
    * lisp/org-goto.el (org-goto-location):
    * lisp/org-macs.el (org-mks):
    * lisp/org-table.el (org-table-fedit-finish):
    * lisp/org.el (org-offer-links-in-entry):
    * lisp/ox.el (org-export-dispatch): Arrange the dialogue window to be
    killed when it is displayed in a new frame.
    `save-window-configuration' is not enough in such scenarios.  Use
    `quit-window' instead.
    * lisp/org-table.el (org-table-edit-formulas): Prohibit popping up
    table editor in a new frame.  This is because the major mode for
    formula editing makes assumptions about where the editor window is
    located and does not work reliably in a separate frame.
    
    Reported-by: Björn Bidar <[email protected]>
    Link: https://orgmode.org/list/87jzlcoxuq.fsf@
---
 lisp/ol.el         |  5 ++++-
 lisp/org-agenda.el |  2 +-
 lisp/org-attach.el | 17 ++++++++++-------
 lisp/org-clock.el  |  7 +++++--
 lisp/org-goto.el   |  6 ++++--
 lisp/org-macs.el   |  6 ++++--
 lisp/org-table.el  |  9 +++++++--
 lisp/org.el        |  2 ++
 lisp/ox.el         |  2 ++
 9 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 1a6a844475..d8a9b92ad1 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -2040,8 +2040,11 @@ non-interactively, don't allow to edit the default 
description."
                           (setq link (substring link 0 -1))))
              (setq link (with-current-buffer origbuf
                           (org-link--try-special-completion link)))))
+        (when-let ((window (get-buffer-window "*Org Links*" t)))
+          (quit-window 'kill window))
        (set-window-configuration wcf)
-       (kill-buffer "*Org Links*"))
+       (when (get-buffer "*Org Links*")
+          (kill-buffer "*Org Links*")))
       (setq entry (assoc link org-stored-links))
       (or entry (push link org-link--insert-history))
       (setq desc (or desc (nth 1 entry)))))
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index fcf6eff71d..638f483a11 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3312,7 +3312,7 @@ s   Search for keywords                 S   Like s, but 
only TODO entries
               ((equal c ?q) (user-error "Abort"))
               (t (user-error "Invalid key %c" c))))
           ;; Close  *Agenda Commands* window.
-          (quit-window))))))
+          (quit-window 'kill))))))
 
 (defun org-agenda-fit-window-to-buffer ()
   "Fit the window to the buffer size."
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index c2b2e1fb2c..8a1b597619 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -350,13 +350,16 @@ Shows a list of commands and prompts for another key to 
execute a command."
                                "\n"))))
               (goto-char (point-min)))
            (org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
-           (let ((msg (format "Select command: [%s]"
-                              (concat (mapcar #'caar org-attach-commands)))))
-             (message msg)
-             (while (and (setq c (read-char-exclusive))
-                          (memq c '(?\C-n ?\C-p ?\C-v ?\M-v)))
-               (org-scroll c t)))
-           (and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*"))))
+            (unwind-protect
+               (let ((msg (format "Select command: [%s]"
+                                  (concat (mapcar #'caar 
org-attach-commands)))))
+                 (message msg)
+                 (while (and (setq c (read-char-exclusive))
+                              (memq c '(?\C-n ?\C-p ?\C-v ?\M-v)))
+                   (org-scroll c t)))
+              (when-let ((window (get-buffer-window "*Org Attach*" t)))
+                (quit-window 'kill window))
+             (and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*")))))
         (let ((command (cl-some (lambda (entry)
                                  (and (memq c (nth 0 entry)) (nth 1 entry)))
                                org-attach-commands)))
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 63c496778a..65a54579a5 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -695,8 +695,11 @@ there is no recent clock to choose from."
        ;; `fit-window-to-buffer'
        (fit-window-to-buffer nil nil (if (< chl 10) chl (+ 5 chl)))
        (message (or prompt "Select task for clocking:"))
-       (setq cursor-type nil rpl (read-char-exclusive))
-       (kill-buffer)
+       (unwind-protect (setq cursor-type nil rpl (read-char-exclusive))
+          (when-let ((window (get-buffer-window "*Clock Task Select*" t)))
+            (quit-window 'kill window))
+         (when (get-buffer "*Clock Task Select*")
+            (kill-buffer "*Clock Task Select*")))
        (cond
         ((eq rpl ?q) nil)
         ((eq rpl ?x) nil)
diff --git a/lisp/org-goto.el b/lisp/org-goto.el
index c1b3a3c0ba..94b709fc6e 100644
--- a/lisp/org-goto.el
+++ b/lisp/org-goto.el
@@ -238,8 +238,10 @@ position or nil."
        (let (org-special-ctrl-a/e) (org-beginning-of-line))
        (message "Select location and press RET")
        (use-local-map org-goto-map)
-       (recursive-edit)))
-    (kill-buffer "*org-goto*")
+       (unwind-protect (recursive-edit)
+          (when-let ((window (get-buffer-window "*Org Help*" t)))
+            (quit-window 'kill window)))))
+    (when (get-buffer "*org-goto*") (kill-buffer "*org-goto*"))
     (cons org-goto-selected-point org-goto-exit-command)))
 
 ;;;###autoload
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index c0332e068a..1254ddb541 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -572,8 +572,10 @@ is selected, only the bare key is returned."
                   ;; selection prefix.
                   ((assoc current specials) (throw 'exit current))
                   (t (error "No entry available")))))))
-        (quit-window)
-       (when buffer (kill-buffer buffer))))))
+        (when buffer
+          (when-let ((window (get-buffer-window buffer t)))
+            (quit-window 'kill window))
+          (kill-buffer buffer))))))
 
 
 ;;; List manipulation
diff --git a/lisp/org-table.el b/lisp/org-table.el
index bd8d59f45e..535d1b44c3 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -3369,7 +3369,10 @@ Parameters get priority."
          (titles '((column . "# Column Formulas\n")
                    (field . "# Field and Range Formulas\n")
                    (named . "# Named Field Formulas\n"))))
-      (switch-to-buffer-other-window "*Edit Formulas*")
+      (let ((pop-up-frames nil))
+        ;; We explicitly prohibit creating edit buffer in a new frame
+        ;; - such configuration is not supported.
+        (switch-to-buffer-other-window "*Edit Formulas*"))
       (erase-buffer)
       ;; Keep global-font-lock-mode from turning on font-lock-mode
       (let ((font-lock-global-modes '(not fundamental-mode)))
@@ -3690,7 +3693,9 @@ With prefix ARG, apply the new formulas to the table."
     (org-table-store-formulas eql)
     (set-marker pos nil)
     (set-marker source nil)
-    (kill-buffer "*Edit Formulas*")
+    (when-let ((window (get-buffer-window "*Edit Formulas*" t)))
+      (quit-window 'kill window))
+    (when (get-buffer "*Edit Formulas*") (kill-buffer "*Edit Formulas*"))
     (if arg
        (org-table-recalculate 'all)
       (message "New formulas installed - press C-u C-c C-c to apply."))))
diff --git a/lisp/org.el b/lisp/org.el
index d9d4290e90..1e5e1621db 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8788,6 +8788,8 @@ there is one, return it."
             (org-fit-window-to-buffer (get-buffer-window "*Select Link*"))
             (message "Select link to open, RET to open all:")
              (unwind-protect (setq c (read-char-exclusive))
+               (and (get-buffer-window "*Select Link*" t)
+                    (quit-window 'kill (get-buffer-window "*Select Link*" t)))
               (and (get-buffer "*Select Link*") (kill-buffer "*Select 
Link*")))))
         (when (equal c ?q) (user-error "Abort"))
         (if (equal c ?\C-m)
diff --git a/lisp/ox.el b/lisp/ox.el
index 95d046bbb9..ce0d3a1cb7 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -7135,6 +7135,8 @@ asynchronous export stack."
                                      (and org-export-in-background 'async))
                                nil
                                org-export-dispatch-use-expert-ui)))
+                     (and (get-buffer-window "*Org Export Dispatcher*" t)
+                          (quit-window 'kill (get-buffer-window "*Org Export 
Dispatcher*" t)))
                     (and (get-buffer "*Org Export Dispatcher*")
                          (kill-buffer "*Org Export Dispatcher*"))))))
         (action (car input))

Reply via email to