From: Reuben Thomas <rrt@sc3d.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 9429@debbugs.gnu.org
Subject: bug#9429: 24.0.50; Extended count-words
Date: Wed, 7 Sep 2011 12:20:47 +0100 [thread overview]
Message-ID: <CAOnWdoioOZM7brWZP9UQg=p7yWxCqEZebK9OywTXMBxngpW0yQ@mail.gmail.com> (raw)
In-Reply-To: <jwvehztt9ch.fsf-monnier+emacs@gnu.org>
On 7 September 2011 02:51, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> It seems to me that it could, however, replace count-words-region
>> (ideally, from my point of view, with a “wc” convenience alias), and I’d
>> be happy to supply such a definition.
>
> That would be good, yes. I don't see a need for a `wc' alias, tho.
The point of the alias is that it's quick to type. This is a command
which, like cd, is unlikely to be bound to a keystroke, but is used
often enough that having a short name is beneficial. Also like cd, it
has a common short name.
> PS: Note that the (use-region-p) check should be within the `interactive'
> spec rather than within the function body
Wow, I had no idea you could do that!
Revised version:
(defun count-words-region (start end)
"Print the number of words in the region or buffer.
When called interactively, the word count is printed in echo area,
unless a prefix argument is given."
(interactive (if (use-region-p) (list (region-beginning) (region-end))
(list (point-min) (point-max))))
(let ((count 0))
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(while (forward-word 1)
(setq count (1+ count)))))
(if (or (not (called-interactively-p 'interactive)) current-prefix-arg)
(insert-string (number-to-string count))
(message "%s has %d words"
(if (use-region-p) "Region" "Buffer")
count))))
--
http://rrt.sc3d.org
next prev parent reply other threads:[~2011-09-07 11:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-03 16:41 bug#9429: 24.0.50; Extended count-words Reuben Thomas
2011-09-07 1:51 ` Stefan Monnier
2011-09-07 11:20 ` Reuben Thomas [this message]
2011-09-10 3:03 ` Stefan Monnier
2011-09-10 3:18 ` Lars Magne Ingebrigtsen
2011-09-10 4:01 ` Stefan Monnier
2011-09-10 7:59 ` Reuben Thomas
2011-09-11 22:55 ` Reuben Thomas
2011-09-12 2:40 ` Stefan Monnier
2011-09-14 18:55 ` Juri Linkov
2011-10-07 20:20 ` Glenn Morris
2011-10-08 19:29 ` Juri Linkov
2012-04-12 19:48 ` Lars Magne Ingebrigtsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOnWdoioOZM7brWZP9UQg=p7yWxCqEZebK9OywTXMBxngpW0yQ@mail.gmail.com' \
--to=rrt@sc3d.org \
--cc=9429@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).