all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* count-words-region and count-words-buffer
@ 2006-09-26 14:00 Hrvoje Niksic
  2006-09-26 15:34 ` Robert J. Chassell
  2006-09-27  8:08 ` Hrvoje Niksic
  0 siblings, 2 replies; 3+ messages in thread
From: Hrvoje Niksic @ 2006-09-26 14:00 UTC (permalink / raw)


The XEmacs functions `count-words-region' and `count-words-buffer'
have proven extremely useful over the years.  This implementation is
mine, but the behavior should be the same.

(defun count-words-region (b e)
  "Print the number of words in the region.
When called interactively, the word count is printed in echo area."
  (interactive "r")
  (let ((cnt 0))
    (save-excursion
      (save-restriction
	(narrow-to-region b e)
	(goto-char (point-min))
	(while (forward-word 1)
	  (setq cnt (1+ cnt)))))
    (if (interactive-p)
	(message "Region has %d words" cnt))
    cnt))

(defun count-words-buffer ()
  "Print the number of words in the buffer.
When called interactively, the word count is printed in echo area."
  (interactive)
  (let ((cnt (count-words-region (point-min) (point-max))))
    (if (interactive-p)
	(message "Buffer has %d words" cnt))
    cnt))

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-09-27  8:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-26 14:00 count-words-region and count-words-buffer Hrvoje Niksic
2006-09-26 15:34 ` Robert J. Chassell
2006-09-27  8:08 ` Hrvoje Niksic

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.