help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Word count in Emacs


From: Alp Aker
Subject: Re: Word count in Emacs
Date: Fri, 14 Sep 2012 15:28:55 -0400

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]