emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Maxim Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
Date: Wed, 20 Jan 2021 00:00:42 +0700	[thread overview]
Message-ID: <ru737s$hu7$1@ciao.gmane.io> (raw)
In-Reply-To: <VI1PR1001MB10703E467731AA1558000F89A3A30@VI1PR1001MB1070.EURPRD10.PROD.OUTLOOK.COM>

[-- Attachment #1: Type: text/plain, Size: 1056 bytes --]

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.

[-- Attachment #2: org-open-file-make-process.patch --]
[-- Type: text/x-patch, Size: 2492 bytes --]

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

  reply	other threads:[~2021-01-19 17:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-13  7:49 [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file stardiviner
2020-06-13 14:51 ` Nicolas Goaziou
2020-06-14  9:08   ` stardiviner
2020-06-14 21:06     ` Nicolas Goaziou
2021-01-10 11:26   ` [BUG] [C-u C-u C-c C-o] open link with external program auto exited before child process " Christopher Miles
     [not found]   ` <87sg799gnx.fsf@numbchild>
2021-01-10 12:13     ` Christopher Miles
2020-09-05  7:52 ` [BUG] [C-u C-u C-c C-o] open link with external program invalid to " Bastien
2021-01-18 16:32   ` Maxim Nikulin
2021-01-19  1:53     ` Christopher Miles
2021-01-19 17:00       ` Maxim Nikulin [this message]
2021-01-20  3:21         ` Christopher Miles
2021-01-20 16:27           ` Maxim Nikulin
2021-01-21  0:58             ` [PATCH] " Christopher Miles
2021-01-21 17:12               ` Maxim Nikulin
2021-01-22  6:00                 ` Christopher Miles
2021-03-10 14:55                   ` Maxim Nikulin
2021-03-11  9:33                     ` Christopher Miles

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ru737s$hu7$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).