From: "Robert J. Chassell" <bob@rattlesnake.com>
Subject: Re: count-words-region and count-words-buffer
Date: Tue, 26 Sep 2006 15:34:01 +0000 (UTC) [thread overview]
Message-ID: <m1GSEwb-0004FyC@rattlesnake.com> (raw)
In-Reply-To: <87y7s6iv8a.fsf@xemacs.org> (message from Hrvoje Niksic on Tue, 26 Sep 2006 16:00:05 +0200)
Hrvoje Niksic <hniksic@xemacs.org> wrote
The XEmacs functions `count-words-region' and `count-words-buffer'
have proven extremely useful over the years.
Yes, true. For whatever reason, perhaps because the function is easy
to write or perhaps because hackers do not count words but necessity,
a word count function does not appear as a default command. My
`Introduction to Emacs Lisp', which is part of the distribution, has
two versions of the `count-words-region' command, one using a while
loop and one recursive.
Here is a while loop version of `count-words-region' that I have kept
in my .emacs file for the past seventeen years:
;;; Word Count Command
;;; 26 August 1989
(defun count-words-region (beginning end)
"Print number of words in the region."
(interactive "r")
(message "Counting words in region ... ")
;;; 1. Set up appropriate conditions.
(save-excursion
(let ((count 0))
(goto-char beginning)
;;; 2. Run the while loop.
(while (and (< (point) end)
(re-search-forward "\\w+\\W*" end t))
(setq count (1+ count)))
;;; 3. Send a message to the user.
(cond ((zerop count)
(message "The region does NOT have any words."))
((= 1 count) (message "The region has 1 word."))
(t (message "The region has %d words." count))))))
(global-set-key "\C-c=" 'count-words-region)
--
Robert J. Chassell GnuPG Key ID: 004B4AC8
bob@rattlesnake.com bob@gnu.org
http://www.rattlesnake.com http://www.teak.cc
next prev parent reply other threads:[~2006-09-26 15:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-26 14:00 count-words-region and count-words-buffer Hrvoje Niksic
2006-09-26 15:34 ` Robert J. Chassell [this message]
2006-09-27 8:08 ` Hrvoje Niksic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1GSEwb-0004FyC@rattlesnake.com \
--to=bob@rattlesnake.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.