From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kenichi Handa Newsgroups: gmane.emacs.devel Subject: Re: suggestion: function: buffer-bytes Date: Sun, 01 Jul 2007 17:22:29 +0900 Message-ID: References: <18054.62174.507770.924924@gargle.gargle.HOWL> <18055.5127.154758.705881@gargle.gargle.HOWL> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII X-Trace: sea.gmane.org 1183278172 18852 80.91.229.12 (1 Jul 2007 08:22:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 1 Jul 2007 08:22:52 +0000 (UTC) Cc: emacs-devel@gnu.org, monnier@iro.umontreal.ca, raman@users.sourceforge.net To: raman@users.sourceforge.net Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 01 10:22:50 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I4uhk-0001ON-RG for ged-emacs-devel@m.gmane.org; Sun, 01 Jul 2007 10:22:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4uhk-00036R-9V for ged-emacs-devel@m.gmane.org; Sun, 01 Jul 2007 04:22:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I4uhg-0002y2-F1 for emacs-devel@gnu.org; Sun, 01 Jul 2007 04:22:44 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I4uhe-0002um-T4 for emacs-devel@gnu.org; Sun, 01 Jul 2007 04:22:44 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4uhe-0002uN-Qd for emacs-devel@gnu.org; Sun, 01 Jul 2007 04:22:42 -0400 Original-Received: from mx1.aist.go.jp ([150.29.246.133]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I4uhd-0001jF-Uq for emacs-devel@gnu.org; Sun, 01 Jul 2007 04:22:42 -0400 Original-Received: from rqsmtp1.aist.go.jp (rqsmtp1.aist.go.jp [150.29.254.115]) by mx1.aist.go.jp with ESMTP id l618MVvx009854; Sun, 1 Jul 2007 17:22:31 +0900 (JST) env-from (handa@m17n.org) Original-Received: from smtp1.aist.go.jp by rqsmtp1.aist.go.jp with ESMTP id l618MU5T009019; Sun, 1 Jul 2007 17:22:30 +0900 (JST) env-from (handa@m17n.org) Original-Received: by smtp1.aist.go.jp with ESMTP id l618MTKW006395; Sun, 1 Jul 2007 17:22:29 +0900 (JST) env-from (handa@m17n.org) Original-Received: from handa by etlken.m17n.org with local (Exim 4.67) (envelope-from ) id 1I4uhR-0004Gf-45; Sun, 01 Jul 2007 17:22:29 +0900 In-reply-to: <18055.5127.154758.705881@gargle.gargle.HOWL> (raman@users.sourceforge.net) User-Agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/23.0.0 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) X-detected-kernel: Solaris 8 (1) 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:74091 Archived-At: In article <18055.5127.154758.705881@gargle.gargle.HOWL>, "T. V. Raman" writes: > Package g-client > http://emacspeak.googlecode.com/svn/trunk/lisp/g-client > I use curl to talk HTTP in that package -- uses Atom Publishing > Protocol to talk to servers -- > and I needed the byte count for computing HTTP headers > correctly. > It does appear to work, but also because I do set buffer-encoding > appropriately in those buffers where I am building up the HTTP > message being posted. > buffer-size definitely bombs in that use case -- do you have a > better suggestion for how one might count bytes? Then perhaps what you need is this. (defun buffer-encoded-size (&optional buffer coding) "Return the encoded size of the current byffer in bytes. ..." (save-excursion (and buffer (set-buffer buffer)) (or coding (setq coding buffer-file-coding-system)) (length (encode-coding-string (buffer-string) coding)))) In emacs-unicode-2, you can use a little bit faster version. (defun buffer-encoded-size (&optional buffer coding) "Return the encoded size of the current byffer in bytes. ..." (save-excursion (and buffer (set-buffer buffer)) (or coding (setq coding buffer-file-coding-system)) (length (encode-coding-region (point-min) (point-max) coding t)))) --- Kenichi Handa handa@m17n.org