Path: utzoo!news-server.csri.toronto.edu!rutgers!ucsd!casbah.acns.nwu.edu!ils.nwu.edu!krulwich From: krulwich@ils.nwu.edu (Bruce Krulwich) Newsgroups: comp.emacs Subject: Re: count words region Message-ID: <1136@anaxagoras.ils.nwu.edu> Date: 14 Mar 91 16:57:48 GMT References: Sender: news@ils.nwu.edu Reply-To: krulwich@ils.nwu.edu (Bruce Krulwich) Organization: Institute for the Learning Sciences, Northwestern University, Evanston, IL 60201 Lines: 27 In-reply-to: jj@medulla.cis.ohio-state.edu (John Josephson) jj@medulla (John Josephson) writes: >Has anyone written a count-words-region command? I'm sure I'm not the >only one who would find it very useful. Thanks, .. jj ; ----------------------------------------------------------------------------- ; COUNT-WORDS-REGION ; Bruce Krulwich, 8/18/89 (defun count-words-region (beg end) "Counts words in region. If called interactively, prints the result. If called from a program (with args BEG and END), returns the count." (interactive "r") (save-excursion (let ((count 0)) (goto-char beg) (while (and (< (point) end) (forward-word 1)) (setq count (1+ count)) (if (forward-word 1) (backward-word 1)) ) (if (interactive-p) (message "%d words in region" count)) count))) ; -----------------------------------------------------------------------------