From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.devel Subject: Re: [wenbinye@gmail.com: hexl-max-address in hexl-mode is incorrect] Date: Wed, 22 Nov 2006 10:15:01 -0700 Organization: IHS Message-ID: References: <87bqmzo4fl.fsf@cyd.mit.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1164216236 19524 80.91.229.2 (22 Nov 2006 17:23:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Nov 2006 17:23:56 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 22 18:23:52 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 1GmvoW-0002ze-4x for ged-emacs-devel@m.gmane.org; Wed, 22 Nov 2006 18:23:12 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GmvoV-00054c-A5 for ged-emacs-devel@m.gmane.org; Wed, 22 Nov 2006 12:23:11 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Gmvi5-00074r-9d for emacs-devel@gnu.org; Wed, 22 Nov 2006 12:16:33 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Gmvi2-00071d-DZ for emacs-devel@gnu.org; Wed, 22 Nov 2006 12:16:32 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Gmvi2-00071G-85 for emacs-devel@gnu.org; Wed, 22 Nov 2006 12:16:30 -0500 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Gmvi2-0000sY-1b for emacs-devel@gnu.org; Wed, 22 Nov 2006 12:16:30 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Gmvhj-0001Ne-N0 for emacs-devel@gnu.org; Wed, 22 Nov 2006 18:16:11 +0100 Original-Received: from 207.167.42.206 ([207.167.42.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Nov 2006 18:16:11 +0100 Original-Received: from ihs_4664 by 207.167.42.206 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Nov 2006 18:16:11 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Lines: 35 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.206 User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) In-Reply-To: <87bqmzo4fl.fsf@cyd.mit.edu> 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:62679 Archived-At: Chong Yidong wrote: >> 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. How about: (- (position-bytes (point-max)) (position-bytes (point-min))) -- Kevin