From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Pascal Bourguignon Newsgroups: gmane.emacs.help Subject: Re: automatically turn on hexl-mode Date: 05 Jun 2003 01:37:42 +0200 Organization: informatimago.com Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87y90hpg6x.fsf@thalassa.informatimago.com> 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 1054770081 15865 80.91.224.249 (4 Jun 2003 23:41:21 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 4 Jun 2003 23:41:21 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 05 01:41:17 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 19Nhs0-000455-00 for ; Thu, 05 Jun 2003 01:40: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 19Nhs2-0007Zl-ST for gnu-help-gnu-emacs@m.gmane.org; Wed, 04 Jun 2003 19:40:42 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!thalassa.informatimago.COM!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 41 Original-NNTP-Posting-Host: thalassa.informatimago.com (195.114.85.198) Original-X-Trace: fu-berlin.de 1054769862 11718617 195.114.85.198 (16 [41911]) User-Agent: Gnus/5.09 (Gnus v5.9.0) 21.3.50.pjb1.1 Original-Xref: shelby.stanford.edu gnu.emacs.help:114152 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:10646 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:10646 Kin Cho writes: > Hi, > > 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? > > -kin There's no universal reasonable implementation for that function. If your non binary files are pure ASCII, then you could check for the presence of character greater than 127. If they're ISO-8859, you could check for the presence of characters between 128 and 144. For virtally all the other encoding, you can't say anything because all the codes are used. You may trust file: (defun buffer-content-looks-binary () (file-content-looks-binary (buffer-file-name))) (defun file-content-looks-binary (filename) (/= 0 (shell-command (format "file %s | grep -q -s text" (shell-quote-argument filename))))) -- __Pascal_Bourguignon__ http://www.informatimago.com/ ---------------------------------------------------------------------- Do not adjust your mind, there is a fault in reality.