From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: using libmagic in Emacs? Date: Tue, 25 Aug 2009 23:37:19 +0300 Organization: JURTA Message-ID: <87r5uz4um0.fsf@mail.jurta.org> References: <87ocqco7fi.fsf@mail.jurta.org> <87y6pb8lqh.fsf@mail.jurta.org> <87my5qngab.fsf@mail.jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1251233127 9667 80.91.229.12 (25 Aug 2009 20:45:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Aug 2009 20:45:27 +0000 (UTC) Cc: monnier@IRO.UMontreal.CA, joakim@verona.se, emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 25 22:45:20 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mg2tK-0000S2-UY for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2009 22:45:19 +0200 Original-Received: from localhost ([127.0.0.1]:52981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mg2tK-0005Az-9U for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2009 16:45:18 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mg2qy-0003ze-Rs for emacs-devel@gnu.org; Tue, 25 Aug 2009 16:42:52 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mg2qs-0003wi-I3 for emacs-devel@gnu.org; Tue, 25 Aug 2009 16:42:51 -0400 Original-Received: from [199.232.76.173] (port=51479 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mg2qr-0003wV-RA for emacs-devel@gnu.org; Tue, 25 Aug 2009 16:42:46 -0400 Original-Received: from smtp-out2.starman.ee ([85.253.0.4]:49771 helo=mx2.starman.ee) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mg2qj-0005D2-EF; Tue, 25 Aug 2009 16:42:37 -0400 X-Virus-Scanned: by Amavisd-New at mx2.starman.ee Original-Received: from mail.starman.ee (82.131.53.219.cable.starman.ee [82.131.53.219]) by mx2.starman.ee (Postfix) with ESMTP id 375FA3F40C3; Tue, 25 Aug 2009 23:42:24 +0300 (EEST) In-Reply-To: (Richard Stallman's message of "Mon, 24 Aug 2009 22:08:02 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:114595 Archived-At: > For instance, Java archive files have the .jar extension but build on > the ZIP file format, so they can be visited in Emacs with the help of > `archive-mode'. Enterprise Java archives with the .ear extension > and Web application Java archives with the .war extension all are > based on the ZIP file format as well as OpenDocument files with > extensions .odt .ods .odb .odp .odg .odf, Firefox add-ons (.xpi), > Keyhole Markup (.kmz), and many other file types that can be potentially > opened in Emacs if were identified as archive files by libmagic. > > How hard would it be to change the code in Emacs to recognize these > using the existing mechanism? Not hard at all. For the ZIP file format it's just one line in `magic-fallback-mode-alist'. Unlike `image-type-auto-detected-p' from the preloaded image.el, we can't use `archive-find-type' in `magic-fallback-mode-alist' because arc-mode.el is not preloaded. So we have to copy archive magic numbers manually from arc-mode.el to `magic-fallback-mode-alist'. Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.1069 diff -u -r1.1069 files.el --- lisp/files.el 17 Aug 2009 23:40:22 -0000 1.1069 +++ lisp/files.el 25 Aug 2009 20:36:28 -0000 @@ -2399,6 +2399,7 @@ (defvar magic-fallback-mode-alist `((image-type-auto-detected-p . image-mode) + ("\\(PK00\\)?[P]K\003\004" . archive-mode) ; zip ;; The < comes before the groups (but the first) to reduce backtracking. ;; TODO: UTF-16