emacs-devel
[Top][All Lists]
Advanced

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

Re: Counting sentences in `count-words'


From: Eli Zaretskii
Subject: Re: Counting sentences in `count-words'
Date: Sat, 21 May 2022 12:26:42 +0300

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Date: Fri, 20 May 2022 14:16:57 +0200
> 
> Why not have emacs to count sentences besides lines, words and
> characters? So far, here is the patch that I end up with.

Thanks, looks like a useful addition.

>     - I had to ignore-errors on (end-of-paragraph-text) in
>       `forward-sentence' otherwise `count-words' won't work on a buffer
>       without a terminal new line. But now `forward-sentence' won't
>       error out at the end of buffer. Maybe there is a way around it
>       that I don't know.

Why not use ignore-errors where you call forward-sentence?

> --- a/lisp/textmodes/paragraphs.el
> +++ b/lisp/textmodes/paragraphs.el
> @@ -472,12 +472,13 @@ forward-sentence
>         (goto-char par-text-beg)))
>        (setq arg (1+ arg)))
>      (while (> arg 0)
> -      (let ((par-end (save-excursion (end-of-paragraph-text) (point))))
> +      (let ((par-end (save-excursion (ignore-errors (end-of-paragraph-text)) 
> (point))))
>       (if (re-search-forward sentence-end par-end t)
>           (skip-chars-backward " \t\n")
>         (goto-char par-end)))
>        (setq arg (1- arg)))
> -    (constrain-to-field nil opoint t)))
> +    (let ((npoint (constrain-to-field nil opoint t)))
> +      (not (= npoint opoint)))))

And why this change?

Finally, I think this addition warrants a NEWS entry.



reply via email to

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