emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH v3] Re: Bug in 9.5.3 org--file-default-apps
Date: Mon, 30 May 2022 22:38:13 +0700	[thread overview]
Message-ID: <t72od7$12gv$1@ciao.gmane.io> (raw)
In-Reply-To: <8735gr15ok.fsf@localhost>

On 30/05/2022 21:00, Ihor Radchenko wrote:
> -      (let* ((mime-type (mailcap-extension-to-mime (or ext "")))
> +      (let* ((mime-type (if (executable-find "file")
> +                            (shell-command-to-string
> +                             (format "%s --brief --mime-type --dereference %s"
> +                                     (executable-find "file")

     (shell-quote-argument (executable-find "file"))

For the case of a directory with spaces or other characters interpreted 
by shell in the PATH environment.

Unsure if "file" command variants exist that do not support 
--dereference. Another pitfalls with `shell-command-to-string' is that 
it provides no way to handle errors. I would consider 2>/dev/null to not 
consider error message as MIME type and `mailcap-extension-to-mime' as 
fallback when "file" command fails.

(let* ((file-executable (executable-find "file"))
        (mime-type-file
         (and file-executable
          (shell-command-to-string
           (format "%s --brief --mime-type --dereference %s 2>/dev/null"
                  ; ...
         )))
        (mime-type (if (org-string-nw-p mime-type-file)
                       mime-type-file
                     (mailcap-extension-to-mime (or ext "")))

> +                                     (shell-quote-argument (convert-standard-filename file))))
> +                          (mailcap-extension-to-mime (or ext ""))))

> Max Nikulin writes:
> 
>> 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 am confused here. org-file-apps-gnu says that we rely on mailcap:
> 
> ((remote . emacs)
>   (system . mailcap)
>   (t . mailcap))
> 
> So, is (3) following what you would expect from mailcap (regardless
> whether it is incorrectly configured or not)? Wrong configuration of
> mailcap is none of Org business - we need not to be "smart" and fix user
> "errors". They may be deliberate.

Ihor, I am afraid that your patch may break some subtle equilibrium 
existing despite discrepancy in MIME type names for shell script. Worst 
scenario: without the patch shell scripts are opened in the same Emacs 
session, with it attempt to open a script silently fails due to "less" 
handler requiring a terminal.

I admit that your patch may improve handling of e.g. images, however it 
is more rare case when an image file has no suffix, while it is quite 
common for various scripts (shell, python, perl, etc.)

I have not tried emacs-28 yet or some other full fledged desktop 
environment (in VM).

There is no official MIME type for shell scripts
http://www.iana.org/assignments/media-types/media-types.xhtml
so definitions "text" or "application", "x-sh" or "x-shellscript" vary. 
E.g. https://wiki.debian.org/ShellScript :
"The MIME type of shell scripts is nowadays text/x-shellscript but other 
systems may still use application/x-shellscript."

Emacs uses application/x-sh for the .sh suffix. There is no association 
for this type in `mailcap-mime-data'. The "file" command reports 
"text/x-shellscript". I have neither "application/x-sh" nor 
"text/x-shellscript" in /etc/mailcap (Ubuntu-20.04), there are only 
several entries for "application/x-shellscript". That is why your patch 
should not make handling of shell scripts worse... till mailcap and 
"file" will start to use the same type.

>> In some cases
>> it may be handy to launch remote viewer from a host accessed through
>> ssh, but let's leave it aside.
> 
> This is exactly why you can always customize org-file-apps.

I am confused by this phrase. `org-file-apps' is ignored for remote 
files, otherwise more care would be required for executing "file".

> I added the extra argument as you suggested. See the new version of the
> patch. Though my man tells me that --dereference is the default. Not on
> your system apparently.

I have no idea. Quick search have not provided a changelog, but I have 
noticed https://bugs.astron.com/view.php?id=29

>> (mailcap-extension-to-mime "sh") => "text/x-sh"
>>
>> run-mailcap --norun examples/org/script/tstorg.sh
>> Error: no "view" mailcap rules found for type "application/x-sh"
>>
>> And "text/x-shellscript" as above.
> 
> This should not matter for us. As long as mailcap-mime-info returns
> something meaningful, we should be good to go. Unless mailcap-mime-info
> itself is buggy.

Following a link to a shell script from an org file (without 
customization) I expect that it is opened in the same Emacs session. 
Maybe my expectation is wrong and system-wide handler (gedit, kate, 
etc.) should be launched. It seems current status quo (at least for some 
linux distributions) is consistent with my expectations, but only due to 
inconsistency in naming of the MIME type.



  reply	other threads:[~2022-05-30 15:39 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
2022-05-30 14:00                                     ` [PATCH v3] " Ihor Radchenko
2022-05-30 15:38                                       ` Max Nikulin [this message]
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='t72od7$12gv$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).