Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
<#secure method=pgpmime mode=sign> I see, I added your patch to my Emacs config. Really thanks for your work. And wait for maintainer response. Maxim Nikulin writes: Christopher, if your are still interested in a patch against this issue then you could find one in https://orgmode.org/list/eff43744-12e1-a359-39f2-6d8169350...@gmail.com/ It managed to pass unnoticed by Bastien's dog somehow. I have realized that I used "'" for function references, that should be replaced by "#'". I have not posted updated version waiting for more comments. On the other hand there was a suggestion by Eli Zaretskii to just surround start-process-shell-command with (let ((process-connection-type nil)) …). -- [ 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
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
Christopher, if your are still interested in a patch against this issue then you could find one in https://orgmode.org/list/eff43744-12e1-a359-39f2-6d8169350...@gmail.com/ It managed to pass unnoticed by Bastien's dog somehow. I have realized that I used "'" for function references, that should be replaced by "#'". I have not posted updated version waiting for more comments. On the other hand there was a suggestion by Eli Zaretskii to just surround start-process-shell-command with (let ((process-connection-type nil)) ...).
Re: [PATCH] Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
Maxim Nikulin 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 signature.asc Description: PGP signature
Re: [PATCH] Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
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. 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))
[PATCH] Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
Maxim Nikulin 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 signature.asc Description: PGP signature
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
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. 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))
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
Maxim Nikulin 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 signature.asc Description: PGP signature
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
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))
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
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 writes: > On 05/09/2020 14:52, Bastien wrote: >> >> stardiviner 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 */ > 24116 21:39:51 execve("/usr/bin/eog", ["eog", > "/usr/share/icons/gnome/256x256/a"...], 0x55d009672ec8 /* 57 vars */ > > 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 signature.asc Description: PGP signature
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
On 05/09/2020 14:52, Bastien wrote: stardiviner 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 */ 24116 21:39:51 execve("/usr/bin/eog", ["eog", "/usr/share/icons/gnome/256x256/a"...], 0x55d009672ec8 /* 57 vars */ 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.
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
Hi, stardiviner 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
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
stardiviner 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.
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Nicolas Goaziou writes: > Hello, > > stardiviner 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-
Re: [BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
Hello, stardiviner 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
[BUG] [C-u C-u C-c C-o] open link with external program invalid to open file
-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-