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@
This commit is contained in:
Ihor Radchenko 2024-04-10 15:42:52 +03:00
parent 129a18abf3
commit 78e9dd0c42
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
9 changed files with 39 additions and 17 deletions

View File

@ -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)))))

View File

@ -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."

View File

@ -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)))

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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."))))

View File

@ -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)

View File

@ -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))