help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: automatically turn on hexl-mode


From: Pascal Bourguignon
Subject: Re: automatically turn on hexl-mode
Date: 05 Jun 2003 01:37:42 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) 21.3.50.pjb1.1

Kin Cho <kin@neoscale.com> 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.


reply via email to

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