From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Benjamin Riefenstahl Newsgroups: gmane.emacs.help Subject: Re: automatically turn on hexl-mode Date: Thu, 05 Jun 2003 17:27:38 +0200 Organization: None Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <7i8yshfs8u.fsf@neoscale.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1054827570 26152 80.91.224.249 (5 Jun 2003 15:39:30 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 5 Jun 2003 15:39:30 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 05 17:39:29 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19Nwp6-0006iz-00 for ; Thu, 05 Jun 2003 17:38:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19Nwqv-0005KD-Ux for gnu-help-gnu-emacs@m.gmane.org; Thu, 05 Jun 2003 11:40:33 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-post-01!supernews.com!news.supernews.com!seneca.benny.turtle-trading.net!nobody Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.1001 (Gnus v5.10.1) Emacs/21.3.50 (gnu/linux) Cancel-Lock: sha1:r1ayahaegvnIvRc5oBhkd3ngGB8= Original-X-Complaints-To: abuse@supernews.com Original-Lines: 27 Original-Xref: shelby.stanford.edu gnu.emacs.help:114175 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:10668 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:10668 Hi Kin, Kin Cho writes: > In my find-file-hooks function, I want to turn on hexl-mode > automatically based on content. I.e., > > (and (buffer-content-looks-binary) (hexl-mode)) > > What's a reasonable implementation of buffer-content-looks-binary? It's not easy to define formally what "binary" is. Is an MS Word document binary? An UTF-16 document? A gzipped text file? And all of these can be shown in Emacs, even though some of them need external helpers. Also for some purposes the actual question behind "is it binary?" may be different than for others. E.g. what CVS actually needs to know is "Can I change the line ends and expand RCS keywords?" I recently had to find all binary files in a development project, a collection of 13186 files. Several methods said that there were 897 binary files in between. The simplest and still reliable criterium was to just look for a NUL byte in the first 1K of the file. Hope this helps, benny