emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Re: Bug in 9.5.3 org--file-default-apps


From: Ihor Radchenko
Subject: [PATCH] Re: Bug in 9.5.3 org--file-default-apps
Date: Sun, 22 May 2022 12:10:05 +0800

Max Nikulin <manikulin@gmail.com> writes:

> On 21/05/2022 08:44, Ihor Radchenko wrote:
>> Max Nikulin writes:
>> 
>>> It is the same with and without -Q and no, I have not customized
>>> `mailcap-user-mime-data', its value is nil, easy customization interface
>>> tells that it is the standard value. There is a chance that debian has
>>> some patch, but most of debian specific is disabled when -Q option is used.
>> 
>> Interesting. In any case, it confirms that mailcap behaviour depends on
>> both Emacs settings and also system settings.
>
> You should be even more surprised, if I say that [[file:~/tstorg]] link 
> is opened in emacs buffer in shell-script mode (emacs-27.1, org main 
> HEAD) despite
>
>     (mailcap-mime-info nil)
>     nil

>
> The source of the problem is that Emacs-27 was released with the 
> following bug:
>
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40247
> mailcap-mime-data erased when parsing mime parts
>
> So `mailcap-parse-mailcaps' called from `mailcap-mime-info' erases 
> predefined associations in Emacs-27.

If I understand correctly, this extra complication does not affect most
of the systems. I am not sure if we need to work around it.

Also, I am attaching a patch to address the original issue. We can just
use file command when available. WDYT?

Best,
Ihor

>From f69824559d62cb6963ff30f11ceb46303bf1b3d4 Mon Sep 17 00:00:00 2001
Message-Id: 
<f69824559d62cb6963ff30f11ceb46303bf1b3d4.1653192368.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sun, 22 May 2022 12:04:35 +0800
Subject: [PATCH] org-open-file: Use file command to determine mime type, when
 available

* lisp/org.el (org-open-file): Prefer file command to determine file
type instead of relying on `mailcap-extension-to-mime'.  Only fallback
to the latter when file command is not available on the system.

Fixes 
https://list.orgmode.org/874k1n2hpv.fsf@localhost/T/#mcc10df4ea7937360671e6dea8061153dee518807
---
 lisp/org.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index d7da8efc4..3102fe611 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7975,7 +7975,12 @@ (defun org-open-file (path &optional in-emacs line 
search)
     (when (eq cmd 'mailcap)
       (require 'mailcap)
       (mailcap-parse-mailcaps)
-      (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 %s"
+                                     (executable-find "file")
+                                     file))
+                          (mailcap-extension-to-mime (or ext ""))))
             (command (mailcap-mime-info mime-type)))
        (if (stringp command)
            (setq cmd command)
-- 
2.35.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]