emacs-devel
[Top][All Lists]
Advanced

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

Re: using libmagic in Emacs?


From: Juri Linkov
Subject: Re: using libmagic in Emacs?
Date: Sun, 30 Aug 2009 02:19:12 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

> If some other Lisp code is interested in the mime type of a file,
> there is a much easier way to find it out: run `file'.

I agree that running `file' is a simpler solution.  So I propose
at least the following patch to add content-based MIME-type identification
to one particular function `mailcap-file-default-commands' that needs
this when filename extension-based identification fails:

Index: lisp/gnus/mailcap.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/gnus/mailcap.el,v
retrieving revision 1.26
diff -c -r1.26 mailcap.el
*** lisp/gnus/mailcap.el        5 Jan 2009 03:22:07 -0000       1.26
--- lisp/gnus/mailcap.el        29 Aug 2009 23:18:45 -0000
***************
*** 1030,1037 ****
          ;; All unique MIME types from file extensions
          (mailcap-delete-duplicates
           (mapcar (lambda (file)
!                    (mailcap-extension-to-mime
!                     (file-name-extension file t)))
                   files)))
         (all-mime-info
          ;; All MIME info lists
--- 1030,1042 ----
          ;; All unique MIME types from file extensions
          (mailcap-delete-duplicates
           (mapcar (lambda (file)
!                    (or (mailcap-extension-to-mime
!                         (file-name-extension file t))
!                        (replace-regexp-in-string
!                         ".*:\\s-*\\(.*\\)\\s-*" "\\1"
!                         (shell-command-to-string
!                          (concat "file --mime "
!                                  (shell-quote-argument file))))))
                   files)))
         (all-mime-info
          ;; All MIME info lists

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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