Subject: bug#12972: 24.3.50; Move `org-open-file' and associated code out of Org mode

From: Maxim Nikulin <[email-masked]>
Date: Fri, 30 Jul 2021 19:24:47 +0700

On 30/07/2021 19:01, Lars Ingebrigtsen wrote:
> Maxim Nikulin writes:
> 
>> I am attaching a patch similar to proposed to Org mode that should
>> help to avoid obscure failures of viewers due to unnecessary terminal
>> sessions.
> 
> Thanks; makes sense to me (and seems to fix these persistent issues with
> xgd-open etc), so I've applied it to Emacs 28.

Thanks for looking into this issue. Please, consider the following 
additional change:

----- 8< -----
diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
index f64897ac9b..aeeb9bd8d3 100644
--- a/lisp/net/mailcap.el
+++ b/lisp/net/mailcap.el
@@ -1186,7 +1186,6 @@ See \"~/.mailcap\", `mailcap-mime-data' and 
related files and variables."
      (make-process
       :name "mailcap-view-file"
       :connection-type 'pipe
-     :noquery t
       :buffer nil ; "*Messages*" may be suitable for debugging
       :sentinel (lambda (proc event)
                   (when (and (memq (process-status proc) '(exit signal))
---- >8 ----

I did not update the patch since Eli had some objections (unclear to 
me). I wrongly added :noquery expecting to get a process completely 
detached from Emacs, something like result of "synchronous"

     (process-file-shell-command command nil 0 nil)

on linux (on stackoverflow I have seen a note that w32 requires special 
treatment).

Notice that "pipe" asynchronous Emacs processes have a problem with CPU 
consumption if a process does something like

#!/bin/sh
exec 1>&-
exec 2>&-
sleep 30

Though I believe even silently killed on exit children and CPU-hungry 
Emacs in rare cases are better than decade old pseudoterminal+SIGHUP 
problem with xdg-open. I suppose, it is an Emacs bug, note Gnome or KDE 
issue.
https://lists.gnu.org/archive/html/emacs-devel/2009-07/msg00279.html