* Word count in Emacs
@ 2012-09-14 17:55 B. T. Raven
2012-09-14 18:14 ` Jambunathan K
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: B. T. Raven @ 2012-09-14 17:55 UTC (permalink / raw
To: help-gnu-emacs
Can anyone give me a clue why the following doesn't print a number in
the mini-buffer or to the *Messages* buffer?:
(defun count-words (start end) ;; alias wce
"Print number of words in the region."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(count-matches "\\sw+"))))
an alias is assigned so that I can invoke with
M-x wce (word count emacs)
Thanks,
Ed
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Word count in Emacs
2012-09-14 17:55 Word count in Emacs B. T. Raven
@ 2012-09-14 18:14 ` Jambunathan K
2012-09-14 19:28 ` Alp Aker
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jambunathan K @ 2012-09-14 18:14 UTC (permalink / raw
To: B. T. Raven; +Cc: help-gnu-emacs
M-x count- TAB
or
M-= (does exactly what you are trying to do here, I suppose)
"B. T. Raven" <btraven@nihilo.net> writes:
> Can anyone give me a clue why the following doesn't print a number in
> the mini-buffer or to the *Messages* buffer?:
>
> (defun count-words (start end) ;; alias wce
> "Print number of words in the region."
> (interactive "r")
> (save-excursion
> (save-restriction
> (narrow-to-region start end)
> (goto-char (point-min))
> (count-matches "\\sw+"))))
>
> an alias is assigned so that I can invoke with
>
> M-x wce (word count emacs)
>
> Thanks,
>
> Ed
>
--
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Word count in Emacs
2012-09-14 17:55 Word count in Emacs B. T. Raven
2012-09-14 18:14 ` Jambunathan K
@ 2012-09-14 19:28 ` Alp Aker
[not found] ` <mailman.8893.1347650994.855.help-gnu-emacs@gnu.org>
[not found] ` <mailman.8880.1347646427.855.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 5+ messages in thread
From: Alp Aker @ 2012-09-14 19:28 UTC (permalink / raw
To: B. T. Raven; +Cc: help-gnu-emacs
> Can anyone give me a clue why the following doesn't print a number in
> the mini-buffer or to the *Messages* buffer?:
>
> (defun count-words (start end) ;; alias wce
> "Print number of words in the region."
> (interactive "r")
> (save-excursion
> (save-restriction
> (narrow-to-region start end)
> (goto-char (point-min))
> (count-matches "\\sw+"))))
As you've defined it, the function returns a number, but it's not the
case that the return value of an interactive command is automatically
echoed in the mini-buffer. Compare:
(defun count-words (start end) ;; alias wce
"Print number of words in the region."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(message (number-to-string (count-matches "\\sw+"))))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Word count in Emacs
[not found] ` <mailman.8893.1347650994.855.help-gnu-emacs@gnu.org>
@ 2012-09-15 23:11 ` B. T. Raven
0 siblings, 0 replies; 5+ messages in thread
From: B. T. Raven @ 2012-09-15 23:11 UTC (permalink / raw
To: help-gnu-emacs
Die Fri Sep 14 2012 14:28:55 GMT-0500 (Central Daylight Time) Alp Aker
<alptekin.aker@gmail.com> scripsit:
>> Can anyone give me a clue why the following doesn't print a number in
>> the mini-buffer or to the *Messages* buffer?:
>>
>> (defun count-words (start end) ;; alias wce
>> "Print number of words in the region."
>> (interactive "r")
>> (save-excursion
>> (save-restriction
>> (narrow-to-region start end)
>> (goto-char (point-min))
>> (count-matches "\\sw+"))))
>
> As you've defined it, the function returns a number, but it's not the
> case that the return value of an interactive command is automatically
> echoed in the mini-buffer. Compare:
>
> (defun count-words (start end) ;; alias wce
> "Print number of words in the region."
> (interactive "r")
> (save-excursion
> (save-restriction
> (narrow-to-region start end)
> (goto-char (point-min))
> (message (number-to-string (count-matches "\\sw+"))))))
>
Thanks, Alp. That did it.
Ed
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Word count in Emacs
[not found] ` <mailman.8880.1347646427.855.help-gnu-emacs@gnu.org>
@ 2012-09-15 23:23 ` B. T. Raven
0 siblings, 0 replies; 5+ messages in thread
From: B. T. Raven @ 2012-09-15 23:23 UTC (permalink / raw
To: help-gnu-emacs
>
> M-x count- TAB
Using this I just find my own function. I think I looked at C-h f count
tab before defining this. Am I masking an original count-words function
in ver. 23.3?
>
> or
>
> M-= (does exactly what you are trying to do here, I suppose)
That is count-lines-regions, returning no. of lines and chars, not words
unless it's been enhanced in ver. 24
Thanks, anyway
Ed
>
> "B. T. Raven" <btraven@nihilo.net> writes:
>
>> Can anyone give me a clue why the following doesn't print a number in
>> the mini-buffer or to the *Messages* buffer?:
>>
>> (defun count-words (start end) ;; alias wce
>> "Print number of words in the region."
>> (interactive "r")
>> (save-excursion
>> (save-restriction
>> (narrow-to-region start end)
>> (goto-char (point-min))
>> (count-matches "\\sw+"))))
>>
>> an alias is assigned so that I can invoke with
>>
>> M-x wce (word count emacs)
>>
>> Thanks,
>>
>> Ed
>>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-15 23:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-14 17:55 Word count in Emacs B. T. Raven
2012-09-14 18:14 ` Jambunathan K
2012-09-14 19:28 ` Alp Aker
[not found] ` <mailman.8893.1347650994.855.help-gnu-emacs@gnu.org>
2012-09-15 23:11 ` B. T. Raven
[not found] ` <mailman.8880.1347646427.855.help-gnu-emacs@gnu.org>
2012-09-15 23:23 ` B. T. Raven
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.