From: Manuel Giraud <manuel@ledu-giraud.fr>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Counting sentences in `count-words'
Date: Sat, 21 May 2022 19:07:26 +0200 [thread overview]
Message-ID: <878rquizld.fsf@elite.giraud> (raw)
In-Reply-To: <83y1yv8cdp.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 21 May 2022 12:26:42 +0300")
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
next prev parent reply other threads:[~2022-05-21 17:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-20 12:16 Counting sentences in `count-words' Manuel Giraud
2022-05-21 9:26 ` Eli Zaretskii
2022-05-21 17:07 ` Manuel Giraud [this message]
2022-05-21 17:32 ` Eli Zaretskii
2022-05-22 12:42 ` Manuel Giraud
2022-05-22 16:52 ` Visuwesh
2022-05-23 8:16 ` Manuel Giraud
2022-05-23 11:06 ` Eli Zaretskii
2022-05-23 11:09 ` Lars Ingebrigtsen
2022-05-23 12:23 ` Manuel Giraud
2022-05-23 12:39 ` Eli Zaretskii
2022-05-23 13:18 ` Manuel Giraud
2022-05-24 15:57 ` Filipp Gunbin
2022-05-25 8:17 ` Manuel Giraud
2022-05-25 10:13 ` Filipp Gunbin
2022-05-29 8:02 ` Eli Zaretskii
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878rquizld.fsf@elite.giraud \
--to=manuel@ledu-giraud.fr \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).