[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Counting sentences in `count-words'
From: |
Manuel Giraud |
Subject: |
Re: Counting sentences in `count-words' |
Date: |
Sat, 21 May 2022 19:07:26 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) |
Eli Zaretskii <eliz@gnu.org> writes:
>> - 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?
Yes. I did that and it works as intended. And `forward-sentence' still
prints an error at the end of buffer. Thanks!
>> --- 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?
I've made this last change because otherwise a call to
`forward-sentence' does not return t if it has move and nil if it has
not (like `forward-word' does) so I could not count in a while loop.
In fact, I've just discovered that my counting is not correct (if ! is
the point and @ is the mark):
!I do. Have.
Three sentences.@ -- count--words --> 3 sentences
but:
!I do. Have.
Three sentences. -- count--words --> 4 sentences (and I think it
@ still should be 3)
> Finally, I think this addition warrants a NEWS entry.
Ok. I don't know how to write them but I could try to mimic what was
done in another patch. I've also modified the info manual and the
docstring.
--
Manuel Giraud
- Counting sentences in `count-words', Manuel Giraud, 2022/05/20
- Re: Counting sentences in `count-words', Eli Zaretskii, 2022/05/21
- Re: Counting sentences in `count-words',
Manuel Giraud <=
- Re: Counting sentences in `count-words', Eli Zaretskii, 2022/05/21
- Re: Counting sentences in `count-words', Manuel Giraud, 2022/05/22
- Re: Counting sentences in `count-words', Visuwesh, 2022/05/22
- Re: Counting sentences in `count-words', Manuel Giraud, 2022/05/23
- Re: Counting sentences in `count-words', Eli Zaretskii, 2022/05/23
- Re: Counting sentences in `count-words', Lars Ingebrigtsen, 2022/05/23
- Re: Counting sentences in `count-words', Manuel Giraud, 2022/05/23
- Re: Counting sentences in `count-words', Eli Zaretskii, 2022/05/23
- Re: Counting sentences in `count-words', Manuel Giraud, 2022/05/23
- Re: Counting sentences in `count-words', Filipp Gunbin, 2022/05/24