From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH v2] Re: Bug in 9.5.3 org--file-default-apps
Date: Sun, 29 May 2022 13:07:06 +0700 [thread overview]
Message-ID: <t6v2ib$mft$1@ciao.gmane.io> (raw)
In-Reply-To: <87zgj46hwo.fsf@localhost>
Ihor,
Your patch may be an improvement, but it requires an additional fix, see
below.
However, in my opinion, it does not address original Craig's issue. The
patch improves handling of *non-text* files requiring *external*
viewers, while Craig complained that behavior for shell script is
incorrect and his problem is tightly bound to erased `mailcap-mime-data'.
I can not reproduce behavior he observed exactly, Org does not opens
shell scripts by less, but it tries and silently (it is expected) fails.
My results (emacs-27):
1. If there is no mailcap files at all, the script is opened
in the same emacs session that is correct from my point of view.
2. If I add ~/.mailcap
text/plain; less '%s'; needsterminal
then I get silent failures
Running less /etc/profile...done
3. With your patch and the following additional entry in ~/.mailcap
(notice "text" instead of "application" and just "emacs")
text/x-shellscript; emacs %s; test=test -n "$DISPLAY"
new Emacs session is started. It is a problem but partially
it is caused by incorrect mailcap configuration.
Unlike "text/plain" that would be handled by view-mode
unless `mailcap-mime-data' were erased in Emacs-27,
"text/x-shellscript" is handled by less on my main system
due to mailcap while I would expect same Emacs session.
I read implementation of `org-open-file' once more and now I see that
currently remote files can not be processed by mailcap code path even
with custom `org-file-apps', so thank you for explanation. In some cases
it may be handy to launch remote viewer from a host accessed through
ssh, but let's leave it aside.
> - (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
> + (let* ((mime-type (if (executable-find "file")
I would consider (and ... (not remp)) despite currently it is redundant.
Just to mitigate consequences if other parts of this complicated
function will be modified. On the other hand
`start-process-shell-command' is not ready for remote files anyway, so
major cleanup would be required.
> + (shell-command-to-string
> + (format "%s --brief --mime-type %s"
> + (executable-find "file")
> + (shell-quote-argument (convert-standard-filename file))))
It is not enough to cure my paranoia. However the following case is
rather pathological
mkdir 'Program Files'
ln -s /usr/bin/file 'Program Files'/
PATH="$HOME/Program Files:$PATH" \
emacs -Q -L ~/src/org-mode/lisp/ ~/examples/org/open-script.org &
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
string-match("/" nil 0)
split-string(nil "/")
mailcap-mime-info("/bin/bash: line 1: /home/ubuntu/Program: No such
f...")
(let* ((mime-type (if (executable-find "file")
(shell-command-to-string (format "%s --brief --mime-type %s"
(executable-find "file") (shell-quote-argument
(convert-standard-filename file)))) (mailcap-extension-to-mime (or ext
"")))) (command (mailcap-mime-info mime-type))) (if (stringp command)
(setq cmd command) (setq cmd 'emacs)))
> + (mailcap-extension-to-mime (or ext ""))))
> Agree. Though it is not directly related. Maybe you can bump that thread
> and mark is as a bug report to be listed on
> https://updates.orgmode.org/?
It is already tracked there as
"org-open-file & org-file-apps multiple substitution bug"
but my point was that great care is required otherwise a lot of issues
may happen with shell command.
Ihor Radchenko. Bug in 9.5.3 org--file-default-apps.
Wed, 25 May 2022 14:18:10 +0800.
https://list.orgmode.org/8735gy2l0d.fsf@localhost
>> '>$ run-mailcap myscript'
>
> One comment. I do not personally have run-mailcap command on my system,
> but searching for its docstring reveals
> (http://www.linux-commands-examples.com/run-mailcap):
>
>>> If the mime-type is omitted, an attempt to determine the type is
>>> made by trying to match the file’s extension with those in the
>>> mime.types files.
>
> So, run-mailcap itself does not look inside the file and only checks the
> extension. AFAIU. Correct me if I am wrong.
It is a Debian extension. Local man page has the following statement
(confirmed by code and strace):
> If no mime-type is found, a last attempt will be done by running the
> file command, if available.
next prev parent reply other threads:[~2022-05-29 6:10 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-15 16:49 Bug in 9.5.3 org--file-default-apps Craig STCR
2022-05-16 4:53 ` Ihor Radchenko
[not found] ` <6615610d-93ae-171f-b554-3f4cc79354cc@gmail.com>
2022-05-16 8:33 ` Ihor Radchenko
[not found] ` <86692975-4d5f-6933-3227-c6b208f76862@gmail.com>
2022-05-16 11:57 ` Ihor Radchenko
2022-05-16 15:14 ` Max Nikulin
2022-05-16 19:15 ` Craig STCR
2022-05-16 19:29 ` Craig STCR
2022-05-17 16:03 ` Max Nikulin
2022-05-18 11:36 ` Ihor Radchenko
2022-05-18 16:10 ` Max Nikulin
2022-05-19 13:39 ` Ihor Radchenko
2022-05-19 14:45 ` Max Nikulin
2022-05-20 8:22 ` Ihor Radchenko
2022-05-20 11:31 ` Max Nikulin
2022-05-21 1:44 ` Ihor Radchenko
2022-05-21 14:56 ` Max Nikulin
2022-05-22 4:10 ` [PATCH] " Ihor Radchenko
2022-05-22 7:40 ` Max Nikulin
2022-05-26 4:23 ` [PATCH v2] " Ihor Radchenko
2022-05-29 6:07 ` Max Nikulin [this message]
2022-05-30 14:00 ` [PATCH v3] " Ihor Radchenko
2022-05-30 15:38 ` Max Nikulin
2022-05-31 15:07 ` Max Nikulin
2022-06-04 13:42 ` [DISCUSSION, default settings] Using mailcap as default handler for opening file links (was: [PATCH v3] Re: Bug in 9.5.3 org--file-default-apps) Ihor Radchenko
2022-06-04 17:01 ` Greg Minshall
2022-06-06 12:50 ` [DISCUSSION, default settings] Using mailcap as default handler for opening file links Max Nikulin
2022-06-06 15:22 ` Max Nikulin
2022-06-06 17:47 ` Bhavin Gandhi
2022-06-10 16:38 ` Max Nikulin
2024-02-12 12:36 ` Ihor Radchenko
2024-02-13 10:59 ` Max Nikulin
2024-02-13 11:27 ` Ihor Radchenko
2024-02-13 15:44 ` Max Nikulin
2024-02-13 15:47 ` Max Nikulin
2024-02-14 14:51 ` Ihor Radchenko
2024-02-27 10:43 ` Max Nikulin
2022-05-29 7:07 ` [PATCH v2] Re: Bug in 9.5.3 org--file-default-apps Max Nikulin
2022-05-23 12:40 ` Craig STCR
2022-05-23 12:59 ` Craig STCR
2022-05-23 14:14 ` Craig STCR
2022-05-23 14:32 ` Craig STCR
2022-05-25 6:18 ` Ihor Radchenko
2022-05-23 15:28 ` Max Nikulin
2022-05-25 6:24 ` Ihor Radchenko
2022-05-25 11:38 ` Craig STCR
2022-05-25 6:10 ` Ihor Radchenko
[not found] ` <e9b4e88d-3807-9080-fa86-c297b17794cb@gmail.com>
2022-05-16 12:38 ` Craig STCR
2022-05-18 11:38 ` Ihor Radchenko
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='t6v2ib$mft$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).