From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: [wenbinye@gmail.com: hexl-max-address in hexl-mode is incorrect] Date: Wed, 22 Nov 2006 11:02:22 -0500 Message-ID: <87bqmzo4fl.fsf@cyd.mit.edu> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1164212159 3685 80.91.229.2 (22 Nov 2006 16:15:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Nov 2006 16:15:59 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 22 17:15:55 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Gmukw-0003xn-Bk for ged-emacs-devel@m.gmane.org; Wed, 22 Nov 2006 17:15:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gmukv-00006Z-8v for ged-emacs-devel@m.gmane.org; Wed, 22 Nov 2006 11:15:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GmuYH-0005ym-OY for emacs-devel@gnu.org; Wed, 22 Nov 2006 11:02:21 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GmuYG-0005yA-JO for emacs-devel@gnu.org; Wed, 22 Nov 2006 11:02:20 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GmuYG-0005y2-BZ for emacs-devel@gnu.org; Wed, 22 Nov 2006 11:02:20 -0500 Original-Received: from [18.19.1.138] (helo=cyd.mit.edu) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GmuYB-0005po-RK; Wed, 22 Nov 2006 11:02:16 -0500 Original-Received: by cyd.mit.edu (Postfix, from userid 1000) id E6EE24E453; Wed, 22 Nov 2006 11:02:22 -0500 (EST) Original-To: "Ye Wenbin" , rms@gnu.org In-Reply-To: (Richard Stallman's message of "Sun\, 19 Nov 2006 02\:59\:53 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.91 (gnu/linux) 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:62677 Archived-At: > The hexl-max-address usually set to buffer-size, but when the buffer > contain a multiple byte character or the file associated to the buffer > is encoded by multibyte coding system such as utf-16, the > hexl-max-address is usually less the the real byte of buffer. > > You can test like this: > > Test case 2: > Open a new file, such as /tmp/test.txt. Use C-x RET f to set the file > coding system to utf-16. Input any letters such as "ab", and save the > buffer. Then change mode to hexl-mode. C-h v hexl-max-address show the > value is still 2 which is the buffer-size rather than the sizze of the > file. > > Here is my solution to set hexl-max-address which might help: > (setq hexl-max-address > (1- (if buffer-file-name > (nth 7 (file-attributes buffer-file-name)) > (length > (decode-coding-string (buffer-string) > buffer-file-coding-system))))) The (nth 7 (file-attributes buffer-file-name)) method returns the correct byte count. However, the (decode-coding-string (buffer-string) buffer-file-coding-system) method doesn't seem to work for me; it returns erratic incorrect results. In the case of a utf-16 buffer containing just "ab" without an associated file, it returns 1; if there is an associated buffer, it returns 0.