all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Reuben Thomas <rrt@sc3d.org>
Cc: 9429@debbugs.gnu.org
Subject: bug#9429: 24.0.50; Extended count-words
Date: Fri, 09 Sep 2011 23:03:20 -0400	[thread overview]
Message-ID: <jwv62l1f9r8.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAOnWdoioOZM7brWZP9UQg=p7yWxCqEZebK9OywTXMBxngpW0yQ@mail.gmail.com> (Reuben Thomas's message of "Wed, 7 Sep 2011 12:20:47 +0100")

>>> 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.

I'm not completely sure yet, and we're already in feature freeze, so I'd
rather not commit on giving away such a short name.

You can use M-x c-w <minibuffer-force-complete> (which I've bound to
M-TAB) which doesn't seem that bad.  It won't work at first (because it
will just use the shortest completion) but on the second use it will
(because it will give preference to the most recently matching
completion).  If we rename count-word-region to count-words then it may
even work right away.

> 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))))

I installed a half-way version (see below) which lacks the "insert count
at point" feature, because I'm not completely sure I want to spend the
C-u on this feature.  And since we're in feature freeze, I wanted to
keep it to the very minimum "obviously good".


        Stefan


=== modified file 'lisp/simple.el'
--- lisp/simple.el	2011-09-09 08:59:51 +0000
+++ lisp/simple.el	2011-09-10 03:00:26 +0000
@@ -938,9 +938,10 @@
       (forward-line (1- line)))))
 
 (defun count-words-region (start end)
-  "Print the number of words in the region.
-When called interactively, the word count is printed in echo area."
-  (interactive "r")
+  "Count the number of words in the active region.
+If the region is not active, counts the number of words in the buffer."
+  (interactive (if (use-region-p) (list (region-beginning) (region-end))
+                 (list (point-min) (point-max))))
   (let ((count 0))
     (save-excursion
       (save-restriction
@@ -948,8 +949,10 @@
         (goto-char (point-min))
         (while (forward-word 1)
           (setq count (1+ count)))))
-    (if (called-interactively-p 'interactive)
-        (message "Region has %d words" count))
+    (when (called-interactively-p 'interactive)
+      (message "%s has %d words"
+               (if (use-region-p) "Region" "Buffer")
+               count))
     count))
 
 (defun count-lines-region (start end)






  reply	other threads:[~2011-09-10  3:03 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
2011-09-10  3:03     ` Stefan Monnier [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv62l1f9r8.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=9429@debbugs.gnu.org \
    --cc=rrt@sc3d.org \
    /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.