From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "T. V. Raman" Newsgroups: gmane.emacs.devel Subject: Re: suggestion: function: buffer-bytes Date: Sat, 30 Jun 2007 19:40:07 -0700 Message-ID: <18055.5127.154758.705881@gargle.gargle.HOWL> References: <18054.62174.507770.924924@gargle.gargle.HOWL> Reply-To: raman@users.sf.net NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1183257622 14845 80.91.229.12 (1 Jul 2007 02:40:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 1 Jul 2007 02:40:22 +0000 (UTC) Cc: raman@users.sf.net, emacs-devel@gnu.org To: monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 01 04:40:19 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 1I4pMF-0006GT-CQ for ged-emacs-devel@m.gmane.org; Sun, 01 Jul 2007 04:40:15 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4pME-0002p1-Na for ged-emacs-devel@m.gmane.org; Sat, 30 Jun 2007 22:40:14 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I4pMA-0002ki-5f for emacs-devel@gnu.org; Sat, 30 Jun 2007 22:40:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I4pM9-0002jG-7R for emacs-devel@gnu.org; Sat, 30 Jun 2007 22:40:09 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I4pM8-0002ip-Sr for emacs-devel@gnu.org; Sat, 30 Jun 2007 22:40:08 -0400 Original-Received: from alnrmhc13.comcast.net ([204.127.225.93]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I4pM8-00009d-EW for emacs-devel@gnu.org; Sat, 30 Jun 2007 22:40:08 -0400 Original-Received: from localhost (c-71-202-191-236.hsd1.ca.comcast.net[71.202.191.236]) by comcast.net (alnrmhc13) with ESMTP id <20070701024007b1300jddode>; Sun, 1 Jul 2007 02:40:07 +0000 Original-Received: by localhost (Postfix, from userid 1000) id 31CAE12A4145; Sat, 30 Jun 2007 19:40:07 -0700 (PDT) In-Reply-To: X-Mailer: VM alpha-457 under Emacs 22.1.50.14 (i686-pc-linux-gnu) x-attribution: tvr X-detected-kernel: NetCache Data OnTap 5.x 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:74088 Archived-At: Stephane, Where I used this: 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? >>>>> "Stefan" == Stefan Monnier writes: >> Emacs built-in buffer-size returns the number of >> characters --- in some situations one needs the count of >> bytes. Here is a small function that does this --- >> perhaps it could be ncluded in subr.el? Stefan> >> (defsubst buffer-bytes (&optional buffer) "Return number >> of bytes in a buffer." (save-excursion (and buffer >> (set-buffer buffer)) (1- (position-bytes (point-max))))) Stefan> Stefan> This function is very unlikely to ever be useful: the Stefan> number of bytes to represent a particular sequence of Stefan> characters depends on the encoding used. So for Stefan> example the result will be different for the exact Stefan> same text when run in Emacs-22 or in Emacs-unicode. Stefan> And it most likely will different from the number of Stefan> bytes of the file associated with the buffer. Stefan> Stefan> Stefan> Stefan Stefan> Stefan> Stefan> _______________________________________________ Stefan> Emacs-devel mailing list Emacs-devel@gnu.org Stefan> http://lists.gnu.org/mailman/listinfo/emacs-devel -- Best Regards, --raman Email: raman@users.sf.net WWW: http://emacspeak.sf.net/raman/ AIM: emacspeak GTalk: tv.raman.tv@gmail.com PGP: http://emacspeak.sf.net/raman/raman-almaden.asc Google: tv+raman IRC: irc://irc.freenode.net/#emacs