unofficial mirror of emacs-orgmode@gnu.org
 help / color / mirror / Atom feed
* [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
@ 2020-06-13  7:49 stardiviner
  2020-06-13 14:51 ` Nicolas Goaziou
  2020-09-05  7:52 ` [BUG] [C-u C-u C-c C-o] open link with external program invalid to " Bastien
  0 siblings, 2 replies; 15+ messages in thread
From: stardiviner @ 2020-06-13  7:49 UTC (permalink / raw)
  To: Org Mode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


When I press =[C-u C-u C-c C-o]= to open an image file link with system external
program. It can't open the image file.

I tested on minimal Emacs config, confirmed this problem.

Org Mode version: latest "master" branch

Org mode version 9.3.4 (release_9.3.4-644-g14d358.dirty @ /home/stardiviner/Code/Emacs/org-mode/lisp/)

Emacs version:

GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.17.3) of 2020-06-12

- -- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
-----BEGIN PGP SIGNATURE-----

iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl7khQcUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsNM3ggAjWkVKAhnsmue0BZq9gxq390UHSan
QsiOQN/BzYkUAHHtuY0Jwh5e8u6QO0TXa44v/K/8O4hNMXe7HV59SD2VIs1TvzCA
QFCqtGXeJZyeNizh9SS6A4R35KM8e6pg5LjruPEyekkUplaFf5qUJX0sn5x9SY9Z
tTZO3Bzd4nW2k8joX1DSqFURK+7WNO7en1XRFjF2FjkBp/J4e5aZwHHhLkGxGR4Q
Jn8Xvyf8c3nhrhE+HypwreRexBgiHKhoTK6DIJ9ztXD97/3s2RQ/qbXxVIeqm58U
Vivn5XqQDFxgBeOeOhgKVRSmC1/x83CwkxBDSGXHT4U0BKSPt07MPm1L7w==
=w8gz
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  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
                     ` (2 more replies)
  2020-09-05  7:52 ` [BUG] [C-u C-u C-c C-o] open link with external program invalid to " Bastien
  1 sibling, 3 replies; 15+ messages in thread
From: Nicolas Goaziou @ 2020-06-13 14:51 UTC (permalink / raw)
  To: stardiviner; +Cc: Org Mode

Hello,

stardiviner <numbchild@gmail.com> writes:

> When I press =[C-u C-u C-c C-o]= to open an image file link with system external
> program. It can't open the image file.

Is it really an Org bug? I.e., is your mailcap file properly set up?

If you think this is really an Org bug, could you provide an ECM,
including your .mailcap?

Regards,
-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  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>
  2 siblings, 1 reply; 15+ messages in thread
From: stardiviner @ 2020-06-14  9:08 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> When I press =[C-u C-u C-c C-o]= to open an image file link with system external
>> program. It can't open the image file.
>
> Is it really an Org bug? I.e., is your mailcap file properly set up?
>
> If you think this is really an Org bug, could you provide an ECM,
> including your .mailcap?

I tested with command "emacs -q" and an minimal Emacs config. Both failed to
started. I also record an screen video to show this problem.

Link: https://pan.baidu.com/s/1iBbcStvNCwdN1vB8ivISdw  password code: r6ws

And I don't have file ~/.mailcap setup. But I can open image in command-line
with command "xdg-open". And I'm sure Org link image file exist and normal.

Emacs version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.17.3) of 2020-06-12
Org Mode version: Org mode version 9.3.4 (release_9.3.4-644-g14d358.dirty @ /home/stardiviner/Code/Emacs/org-mode/lisp/)

>
> Regards,


- -- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
-----BEGIN PGP SIGNATURE-----

iQFIBAEBCAAyFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAl7l6RQUHG51bWJjaGls
ZEBnbWFpbC5jb20ACgkQG13xyVromsM3HggAo1IJQZUTgLYO/xY47DusHP95jD78
vH2IXreE0ahumDVpPPOQd9o8VKeCpgwMf4/0/1HAn9u2UDmiT27T/5TRo9oeipFr
+E/lMdpWudnewJfLzBbkDekyEqQjbeRQuj1vT/dTW4Viu9YsFKx2v4z6rOYglvsN
yKRx8OI5nXCqLDNcIqYIvk3VfCx4ShjF/n03Qzd1RQVjSEpP86kpk2qCdPMQzXNy
my7ZrZ/KTXAhAfm+n/4GB1E8T8D49rc669BawV/9ctBFvZrRyrm8auLg+53i3j32
YLYt9Tlq8jNL1/IGxY+R2NlU5dTNDtQmdt8RcELFHYp4hICI6cUXshRiUw==
=6MuC
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2020-06-14  9:08   ` stardiviner
@ 2020-06-14 21:06     ` Nicolas Goaziou
  0 siblings, 0 replies; 15+ messages in thread
From: Nicolas Goaziou @ 2020-06-14 21:06 UTC (permalink / raw)
  To: stardiviner; +Cc: Org Mode

stardiviner <numbchild@gmail.com> writes:

> I tested with command "emacs -q" and an minimal Emacs config. Both failed to
> started. I also record an screen video to show this problem.
>
> Link: https://pan.baidu.com/s/1iBbcStvNCwdN1vB8ivISdw  password code:
> r6ws

I cannot see the video. But this isn't an ECM either. I can open images
with C-u C-u here.

> And I don't have file ~/.mailcap setup. But I can open image in command-line
> with command "xdg-open". And I'm sure Org link image file exist and
> normal.

Then look for a mailcap file somewhere, e.g., in /etc/mailcap. The
application associated to the MIME type may not exist, i.e., this is
a configuration issue.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  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-09-05  7:52 ` Bastien
  2021-01-18 16:32   ` Maxim Nikulin
  1 sibling, 1 reply; 15+ messages in thread
From: Bastien @ 2020-09-05  7:52 UTC (permalink / raw)
  To: stardiviner; +Cc: Org Mode

Hi,

stardiviner <numbchild@gmail.com> writes:

> When I press =[C-u C-u C-c C-o]= to open an image file link with system external
> program. It can't open the image file.

I cannot reproduce the problem here.

If you still have this issue, can you provide a minimal reproducible
example?

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program auto exited before child process open file
  2020-06-13 14:51 ` Nicolas Goaziou
  2020-06-14  9:08   ` stardiviner
@ 2021-01-10 11:26   ` Christopher Miles
       [not found]   ` <87sg799gnx.fsf@numbchild>
  2 siblings, 0 replies; 15+ messages in thread
From: Christopher Miles @ 2021-01-10 11:26 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode

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


I found exactly same problem and some answer on this question:

https://askubuntu.com/questions/646631/emacs-doesnot-work-with-xdg-open

But I hope Org Mode can provide solution by default. Based on the description in
answers. Is there something Org Mode can do to get around this problem?

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> When I press =[C-u C-u C-c C-o]= to open an image file link with system external
>> program. It can't open the image file.
>
> Is it really an Org bug? I.e., is your mailcap file properly set up?
>
> If you think this is really an Org bug, could you provide an ECM,
> including your .mailcap?
>
> Regards,


-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program auto exited before child process open file
       [not found]   ` <87sg799gnx.fsf@numbchild>
@ 2021-01-10 12:13     ` Christopher Miles
  0 siblings, 0 replies; 15+ messages in thread
From: Christopher Miles @ 2021-01-10 12:13 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode

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


I tested with following code:

#+begin_src emacs-lisp
(let ((cmd (format
            "%s %s"
            "xdg-open"
            (shell-quote-argument
             (expand-file-name
              "~/Downloads/伦敦底层社会 1,2章.doc")))))
  (start-process-shell-command cmd "*org-open-file*" cmd))

(start-process "org-open-file"
               " *org-open-file*"
               "xdg-open"
               (expand-file-name "~/Downloads/伦敦底层社会 1,2章.doc"))
#+end_src

Both has same problem, xdg-open exited automatically and before really open file.

So maybe I should ask question in Emacs-help mailing list? Because this problem
seems on ~start-process~ / ~start-process-shell-command~.

Christopher M. Miles <numbchild@gmail.com> writes:

> I found exactly same problem and some answer on this question:
>
> https://askubuntu.com/questions/646631/emacs-doesnot-work-with-xdg-open
>
> But I hope Org Mode can provide solution by default. Based on the description in
> answers. Is there something Org Mode can do to get around this problem?
>
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Hello,
>>
>> stardiviner <numbchild@gmail.com> writes:
>>
>>> When I press =[C-u C-u C-c C-o]= to open an image file link with system external
>>> program. It can't open the image file.
>>
>> Is it really an Org bug? I.e., is your mailcap file properly set up?
>>
>> If you think this is really an Org bug, could you provide an ECM,
>> including your .mailcap?
>>
>> Regards,


-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Maxim Nikulin @ 2021-01-18 16:32 UTC (permalink / raw)
  To: emacs-orgmode

On 05/09/2020 14:52, Bastien wrote:
> 
> stardiviner <numbchild@gmail.com> writes:
> 
>> When I press =[C-u C-u C-c C-o]= to open an image file link with system external
>> program. It can't open the image file.
> 
> I cannot reproduce the problem here.
> 
> If you still have this issue, can you provide a minimal reproducible
> example?

Christopher Miles recently posted a link to askubuntu that shed some 
light on the problem.

I have compared the following commands:

(start-process-shell-command "xdg-open" nil "xdg-open 
/usr/share/icons/gnome/256x256/actions/stock_print.png")
(start-process-shell-command "eog" nil "eog 
/usr/share/icons/gnome/256x256/actions/stock_print.png")

The latter works in my (test) case (Ubuntu-20.04, ubuntu session - 
gnome), the former does not. If I do not mistake, 
start-process-shell-command is what org mode uses to open file.

Meaningful lines from strace of the emacs process

24108 21:39:51 execve("/bin/bash", ["/bin/bash", "-c", "xdg-open 
/usr/share/icons/gnome/"...], 0x7ffcb1c1fdb0 /* 55 vars */ <unfinished...>
24116 21:39:51 execve("/usr/bin/eog", ["eog", 
"/usr/share/icons/gnome/256x256/a"...], 0x55d009672ec8 /* 57 vars */ 
<unfinished ...>
24108 21:39:51 +++ exited with 0 +++
24116 21:39:51 +++ killed by SIGHUP +++

I think, the problem is that start-process-shell-command creates a "pty" 
process. As soon as main command exits, all children, that belong to the 
same terminal session created by emacs for the process, got killed.

Calling eog directly works because of it does not attempt to go to 
background or demonize.

The solution could be (make-process :connection-type 'pipe ...). 
Personally I would prefer to avoid shell as well when it is not really 
necessary.

I am surprised that in the discussion of problem related to desktop 
integration and perhaps even order in which applications able to handle 
particular file format were installed, nobody mentioned such details, 
neither for "positive" nor for "negative" results. Probably output of 
the following commands (for the proper mime type) could be relevant. The 
complication is that there are several mime handler "databases".

grep image/png /etc/mailcap ~/.mailcap
xdg-mime query default image/png

(mailcap-parse-mailcaps)
(mailcap-mime-info "image/png")

For some handlers there might be even a race, sometimes it might work 
but might fail as well, depending if child could send a message to its 
server quickly enough. In such case providing of ECM might be a challenge.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2021-01-18 16:32   ` Maxim Nikulin
@ 2021-01-19  1:53     ` Christopher Miles
  2021-01-19 17:00       ` Maxim Nikulin
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Miles @ 2021-01-19  1:53 UTC (permalink / raw)
  To: Maxim Nikulin; +Cc: emacs-orgmode

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


Maxim, thanks for your detailed explanation.

I confirmed the problem:

#+begin_src emacs-lisp
;;; does not work
(start-process-shell-command "xdg-open" nil "xdg-open /usr/share/icons/gnome/256x256/actions/stock_print.png")

;;; works fine
(start-process-shell-command "feh" nil "feh /usr/share/icons/gnome/256x256/actions/stock_print.png")
#+end_src

For this problem, do you have any workable solution patch?

Here is my =/etc/mailcap=, don't have =~/.mailcap=.

#+begin_src conf
### 
### Begin Red Hat Mailcap
###

audio/*; /usr/bin/xdg-open %s

image/*; /usr/bin/xdg-open %s

application/msword; /usr/bin/xdg-open %s
application/pdf; /usr/bin/xdg-open %s
application/postscript ; /usr/bin/xdg-open %s

text/html; /usr/bin/xdg-open %s ; copiousoutput
#+end_src

Maxim Nikulin <manikulin@gmail.com> writes:

> On 05/09/2020 14:52, Bastien wrote:
>> 
>> stardiviner <numbchild@gmail.com> writes:
>> 
>>> When I press =[C-u C-u C-c C-o]= to open an image file link with system external
>>> program. It can't open the image file.
>> 
>> I cannot reproduce the problem here.
>> 
>> If you still have this issue, can you provide a minimal reproducible
>> example?
>
> Christopher Miles recently posted a link to askubuntu that shed some 
> light on the problem.
>
> I have compared the following commands:
>
> (start-process-shell-command "xdg-open" nil "xdg-open 
> /usr/share/icons/gnome/256x256/actions/stock_print.png")
> (start-process-shell-command "eog" nil "eog 
> /usr/share/icons/gnome/256x256/actions/stock_print.png")
>
> The latter works in my (test) case (Ubuntu-20.04, ubuntu session - 
> gnome), the former does not. If I do not mistake, 
> start-process-shell-command is what org mode uses to open file.
>
> Meaningful lines from strace of the emacs process
>
> 24108 21:39:51 execve("/bin/bash", ["/bin/bash", "-c", "xdg-open 
> /usr/share/icons/gnome/"...], 0x7ffcb1c1fdb0 /* 55 vars */ <unfinished...>
> 24116 21:39:51 execve("/usr/bin/eog", ["eog", 
> "/usr/share/icons/gnome/256x256/a"...], 0x55d009672ec8 /* 57 vars */ 
> <unfinished ...>
> 24108 21:39:51 +++ exited with 0 +++
> 24116 21:39:51 +++ killed by SIGHUP +++
>
> I think, the problem is that start-process-shell-command creates a "pty" 
> process. As soon as main command exits, all children, that belong to the 
> same terminal session created by emacs for the process, got killed.
>
> Calling eog directly works because of it does not attempt to go to 
> background or demonize.
>
> The solution could be (make-process :connection-type 'pipe ...). 
> Personally I would prefer to avoid shell as well when it is not really 
> necessary.
>
> I am surprised that in the discussion of problem related to desktop 
> integration and perhaps even order in which applications able to handle 
> particular file format were installed, nobody mentioned such details, 
> neither for "positive" nor for "negative" results. Probably output of 
> the following commands (for the proper mime type) could be relevant. The 
> complication is that there are several mime handler "databases".
>
> grep image/png /etc/mailcap ~/.mailcap
> xdg-mime query default image/png
>
> (mailcap-parse-mailcaps)
> (mailcap-mime-info "image/png")
>
> For some handlers there might be even a race, sometimes it might work 
> but might fail as well, depending if child could send a message to its 
> server quickly enough. In such case providing of ECM might be a challenge.


-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2021-01-19  1:53     ` Christopher Miles
@ 2021-01-19 17:00       ` Maxim Nikulin
  2021-01-20  3:21         ` Christopher Miles
  0 siblings, 1 reply; 15+ messages in thread
From: Maxim Nikulin @ 2021-01-19 17:00 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2021-01-19 17:00       ` Maxim Nikulin
@ 2021-01-20  3:21         ` Christopher Miles
  2021-01-20 16:27           ` Maxim Nikulin
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Miles @ 2021-01-20  3:21 UTC (permalink / raw)
  To: Maxim Nikulin; +Cc: emacs-orgmode

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


Maxim Nikulin <manikulin@gmail.com> writes:

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

Thanks for your working. I will modify my mailcap config temporary until Org
Mode fix this issue. You're right, this change might break some behavior of some
users. I don't understand Emacs sub-process mechanism. Can't help on this
problem. But I'm interested in this. I will take some time to study in. Anyway,
thanks for your work.

Regards,

-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2021-01-20  3:21         ` Christopher Miles
@ 2021-01-20 16:27           ` Maxim Nikulin
  2021-01-21  0:58             ` [PATCH] " Christopher Miles
  0 siblings, 1 reply; 15+ messages in thread
From: Maxim Nikulin @ 2021-01-20 16:27 UTC (permalink / raw)
  To: emacs-orgmode

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

On 20/01/2021 10:21, Christopher Miles wrote:
> 
> Thanks for your working. I will modify my mailcap config temporary until Org
> Mode fix this issue. You're right, this change might break some behavior of some
> users. I don't understand Emacs sub-process mechanism. Can't help on this
> problem. But I'm interested in this. I will take some time to study in. Anyway,
> thanks for your work.

Changes could be less intrusive, see another (untested) patch. However I 
am against shell where it is really necessary.

Personally, I am not comfortable with emacs subprocess functions as 
well. I just tried to avoid creation of a pseudoterminal that could make 
some harm to GUI application. I do not know if someone uses a handler 
that really require terminal features.

I have realized that :filter argument is not appropriate to arbitrary 
handler that could spam with various assert messages. Maybe :sentinel is 
better to report configuration problem to user when handler is called 
with inappropriate arguments.


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

diff --git a/lisp/org.el b/lisp/org.el
index 5b1443c4e..43838783b 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8765,7 +8765,9 @@ If the file does not exist, throw an error."
 
       (save-window-excursion
 	(message "Running %s...done" cmd)
-	(start-process-shell-command cmd nil cmd)
+	(make-process :name "org-open-file" :connection-type 'pipe
+		      :buffer "*Messages*" :noquery 't
+		      :command (list shell-command shell-commad-switch cmd))
 	(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2021-01-20 16:27           ` Maxim Nikulin
@ 2021-01-21  0:58             ` Christopher Miles
  2021-01-21 17:12               ` Maxim Nikulin
  0 siblings, 1 reply; 15+ messages in thread
From: Christopher Miles @ 2021-01-21  0:58 UTC (permalink / raw)
  To: Maxim Nikulin; +Cc: emacs-orgmode

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


Maxim Nikulin <manikulin@gmail.com> writes:

> I have realized that :filter argument is not appropriate to arbitrary 
> handler that could spam with various assert messages. Maybe :sentinel is 
> better to report configuration problem to user when handler is called 
> with inappropriate arguments.

Yes, use ~:sentinel~ is better for report problem when detect process failed or
configuration error. ~:filter~ usually used in handling process output.

I "=git am=" your first patch, but failed to apply your second patch. Seems not
continuous. So I modify code manually. I found I can't find the local variable
~shell-command~, and ~shell-command-switch~. Can your provide complete patch? So I
can test it.

I update subject to prefix with [PATCH] so that reader knows this thread is on
patch discussion.

-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2021-01-21  0:58             ` [PATCH] " Christopher Miles
@ 2021-01-21 17:12               ` Maxim Nikulin
  2021-01-22  6:00                 ` Christopher Miles
  0 siblings, 1 reply; 15+ messages in thread
From: Maxim Nikulin @ 2021-01-21 17:12 UTC (permalink / raw)
  To: emacs-orgmode

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

On 21/01/2021 07:58, Christopher Miles wrote:
> 
> I "=git am=" your first patch, but failed to apply your second patch. Seems not
> continuous. So I modify code manually. I found I can't find the local variable
> ~shell-command~, and ~shell-command-switch~. Can your provide complete patch? So I
> can test it.

Second patch is an alternative to the first one. I could do 'git apply 
org-open-file-make-process-min.patch' to the current master with no 
conflict. However you are right, it should be ~shell-file-name~, not 
~shell-command~. There is a typo in ~shell-command-switch~. Both 
~shell-file-name~ and ~shell-command-switch~ are defined in emacs 
sources, they are not local variables.

I do not think that the first patch could be accepted in any form. 
Launching a handler without shell is a serious change. However trying to 
rewrite that part, I realized that original code has a problem.

I intentionally do not add formal patch description since I suppose that 
error reporting should be improved.

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

diff --git a/lisp/org.el b/lisp/org.el
index 5b1443c4e..cf9e46525 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8765,7 +8765,9 @@ If the file does not exist, throw an error."
 
       (save-window-excursion
 	(message "Running %s...done" cmd)
-	(start-process-shell-command cmd nil cmd)
+	(make-process :name "org-open-file" :connection-type 'pipe
+		      :buffer "*Messages*" :noquery 't
+		      :command (list shell-file-name shell-command-switch cmd))
 	(and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))))
      ((or (stringp cmd)
 	  (eq cmd 'emacs))

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
  2021-01-21 17:12               ` Maxim Nikulin
@ 2021-01-22  6:00                 ` Christopher Miles
  0 siblings, 0 replies; 15+ messages in thread
From: Christopher Miles @ 2021-01-22  6:00 UTC (permalink / raw)
  To: Maxim Nikulin; +Cc: emacs-orgmode

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


Maxim Nikulin <manikulin@gmail.com> writes:

> On 21/01/2021 07:58, Christopher Miles wrote:
>> 
>> I "=git am=" your first patch, but failed to apply your second patch. Seems not
>> continuous. So I modify code manually. I found I can't find the local variable
>> ~shell-command~, and ~shell-command-switch~. Can your provide complete patch? So I
>> can test it.
>
> Second patch is an alternative to the first one. I could do 'git apply 
> org-open-file-make-process-min.patch' to the current master with no 
> conflict. However you are right, it should be ~shell-file-name~, not 
> ~shell-command~. There is a typo in ~shell-command-switch~. Both 
> ~shell-file-name~ and ~shell-command-switch~ are defined in emacs 
> sources, they are not local variables.

Indeed, I learned new stuff. 😄

>
> I do not think that the first patch could be accepted in any form. 
> Launching a handler without shell is a serious change. However trying to 
> rewrite that part, I realized that original code has a problem.
>
> I intentionally do not add formal patch description since I suppose that 
> error reporting should be improved.

You're right, the error handling can be improved.

-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-01-22  6:20 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

unofficial mirror of emacs-orgmode@gnu.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git