On 19/01/2021 08:53, Christopher Miles wrote:
For this problem, do you have any workable solution patch?
Maybe for a while it is better to avoid xdg-open or other handlers that
launch actual viewers in background. E.g. to replace xdg-open with
actual handlers in mailcap.
I attach a draft patch that just demonstrates my intention to use
make-process. It intentionally does not use shell to run the command and
such change could be breaking for some part of users. I have not tested
if regexp substitutions for org-file-apps entries are not broken.
In kubuntu-18.04 I do not have any xdg-open entries in the system
mailcap file. Even if I add such line to the user's file, I could not
reproduce the problem with any of the real handler configured for the
image/png type and launched by xdg-open: geeqie, gwenview, feh. I have
no idea concerning the reason: older xdg-open version, other code
working in xdg-open for kde desktop, or limited resources allocated to
qemu virtual machine with ubuntu-20.04 where I can reproduce the problem.
diff --git a/lisp/org.el b/lisp/org.el
index 5b1443c4e..299f39949 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8743,29 +8743,34 @@ If the file does not exist, throw an error."
(cond
((and (stringp cmd) (not (string-match "^\\s-*$" cmd)))
;; Remove quotes around the file name - we'll use shell-quote-argument.
- (while (string-match "['\"]%s['\"]" cmd)
- (setq cmd (replace-match "%s" t t cmd)))
- (setq cmd (replace-regexp-in-string
- "%s"
- (shell-quote-argument (convert-standard-filename file))
- cmd
- nil t))
-
- ;; Replace "%1", "%2" etc. in command with group matches from regex
- (save-match-data
- (let ((match-index 1)
- (number-of-groups (- (/ (length link-match-data) 2) 1)))
- (set-match-data link-match-data)
- (while (<= match-index number-of-groups)
- (let ((regex (concat "%" (number-to-string match-index)))
- (replace-with (match-string match-index dlink)))
- (while (string-match regex cmd)
- (setq cmd (replace-match replace-with t t cmd))))
- (setq match-index (+ match-index 1)))))
-
- (save-window-excursion
- (message "Running %s...done" cmd)
- (start-process-shell-command cmd nil cmd)
+ (let* ((command (split-string-and-unquote cmd))
+ (command (mapcar (lambda (arg)
+ (while (string-match "['\"]%s['\"]" arg)
+ (setq arg (replace-match "%s" t t arg)))
+ arg)
+ command)))
+ ;; Replace "%1", "%2" etc. in command with group matches from regex
+ (save-match-data
+ (let ((match-index 1)
+ (number-of-groups (- (/ (length link-match-data) 2) 1)))
+ (set-match-data link-match-data)
+ (while (<= match-index number-of-groups)
+ (let ((regex (concat "%" (number-to-string match-index)))
+ (replace-with (match-string match-index dlink)))
+ (setq command
+ (mapcar (lambda (arg)
+ (while (string-match regex arg)
+ (setq arg (replace-match replace-with t t arg)))
+ arg)
+ command)))
+ (setq match-index (+ match-index 1)))))
+ (setq command (mapcar (lambda (arg) (format-spec arg (list (cons ?s file)))) command))
+ (save-window-excursion
+ (message "Running %S...done" command)
+ (make-process :name "org-open-file" :connection-type 'pipe
+ :buffer "*Messages*"
+ :filter (lambda (proc string) (message "org-open-file: %s" string))
+ :noquery 't :command command))
(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
((or (stringp cmd)
(eq cmd 'emacs))