unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* 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

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).