[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: suggestion: function: buffer-bytes
From: |
Kenichi Handa |
Subject: |
Re: suggestion: function: buffer-bytes |
Date: |
Sun, 01 Jul 2007 17:22:29 +0900 |
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) |
In article <address@hidden>, "T. V. Raman" <address@hidden> 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
address@hidden
Re: suggestion: function: buffer-bytes, Eli Zaretskii, 2007/07/01