emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: suggestion: function: buffer-bytes


From: Stefan Monnier
Subject: Re: suggestion: function: buffer-bytes
Date: Sat, 30 Jun 2007 21:39:33 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

> 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?

> (defsubst buffer-bytes (&optional buffer)
>   "Return number of bytes in a buffer."
>   (save-excursion
>     (and buffer (set-buffer buffer))
>     (1- (position-bytes (point-max)))))

This function is very unlikely to ever be useful: the number of bytes to
represent a particular sequence of characters depends on the encoding used.
So for example the result will be different for the exact same text when run
in Emacs-22 or in Emacs-unicode.  And it most likely will different from the
number of bytes of the file associated with the buffer.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]