78e9dd0c4287851ae4ab6a6b7155c229b6e00dd7 — Ihor Radchenko a month ago 129a18a
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 <bjorn.bidar@thaodan.de>
Link: https://orgmode.org/list/87jzlcoxuq.fsf@
M lisp/ol.el => lisp/ol.el +4 -1
@@ 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)))))

M lisp/org-agenda.el => lisp/org-agenda.el +1 -1
@@ 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 'kill))))))

(defun org-agenda-fit-window-to-buffer ()
  "Fit the window to the buffer size."

M lisp/org-attach.el => lisp/org-attach.el +10 -7
@@ 350,13 350,16 @@ Shows a list of commands and prompts for another key to execute a command."
              (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*"))))
	        (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)))

M lisp/org-clock.el => lisp/org-clock.el +5 -2
@@ 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))
	(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*")))
	 ((eq rpl ?q) nil)
	 ((eq rpl ?x) nil)

M lisp/org-goto.el => lisp/org-goto.el +4 -2
@@ 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)
    (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)))


M lisp/org-macs.el => lisp/org-macs.el +4 -2
@@ 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")))))))
	(when buffer (kill-buffer buffer))))))
        (when buffer
          (when-let ((window (get-buffer-window buffer t)))
            (quit-window 'kill window))
          (kill-buffer buffer))))))

;;; List manipulation

M lisp/org-table.el => lisp/org-table.el +7 -2
@@ 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*"))
      ;; 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."))))

M lisp/org.el => lisp/org.el +2 -0
@@ 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)

M lisp/ox.el => lisp/ox.el +2 -0
@@ 7135,6 7135,8 @@ asynchronous export stack."
				      (and org-export-in-background 'async))
                     (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))