* counting chars in buffer
@ 2017-06-12 18:53 Emanuel Berg
2017-06-12 19:16 ` Yuri Khan
0 siblings, 1 reply; 3+ messages in thread
From: Emanuel Berg @ 2017-06-12 18:53 UTC (permalink / raw)
To: help-gnu-emacs
How would one do that?
Using 'wc -c' on the file isn't allowed as I've
heard some systems (?) don't come with that.
Here are two suggestions:
(require 'cl-lib)
(defun count-chars ()
(interactive)
(save-excursion
(let ((start (point-min))
(end (point-max))
(chars 0) )
(goto-char start)
(while (< (point) end)
(forward-char)
(cl-incf chars) )
chars) ))
;; (count-chars)
(defun count-chars-2 ()
(interactive)
(length (buffer-string) ))
;; (count-chars-2)
One could also do a DWIM function which acts on
the region if there, otherwise the whole buffer...
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: counting chars in buffer
2017-06-12 18:53 counting chars in buffer Emanuel Berg
@ 2017-06-12 19:16 ` Yuri Khan
2017-06-12 19:28 ` Emanuel Berg
0 siblings, 1 reply; 3+ messages in thread
From: Yuri Khan @ 2017-06-12 19:16 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
On Tue, Jun 13, 2017 at 1:53 AM, Emanuel Berg <moasen@zoho.com> wrote:
> How would one do that?
Interactively, M-= (count-words-region) displays region or buffer size
in characters as part of its output.
Programmatically, (buffer-size) is documented to return a character
count (as opposed to an octet count). Also, any positions are
specified in characters so you can just subtract them.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: counting chars in buffer
2017-06-12 19:16 ` Yuri Khan
@ 2017-06-12 19:28 ` Emanuel Berg
0 siblings, 0 replies; 3+ messages in thread
From: Emanuel Berg @ 2017-06-12 19:28 UTC (permalink / raw)
To: help-gnu-emacs
Yuri Khan wrote:
> Programmatically, (buffer-size)
Yes, I found the "count-" set, so it is just
a matter of wrapping `buffer-size'
interactively into "count-chars"!
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-06-12 19:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-12 18:53 counting chars in buffer Emanuel Berg
2017-06-12 19:16 ` Yuri Khan
2017-06-12 19:28 ` Emanuel Berg
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.