From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud Newsgroups: gmane.emacs.devel Subject: Re: Counting sentences in `count-words' Date: Sat, 21 May 2022 19:07:26 +0200 Message-ID: <878rquizld.fsf@elite.giraud> References: <87o7zsiekm.fsf@elite.giraud> <83y1yv8cdp.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10616"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat May 21 19:09:24 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nsSbT-0002Zz-Vf for ged-emacs-devel@m.gmane-mx.org; Sat, 21 May 2022 19:09:24 +0200 Original-Received: from localhost ([::1]:43832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsSbS-0002QJ-Fo for ged-emacs-devel@m.gmane-mx.org; Sat, 21 May 2022 13:09:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsSZm-0001gK-9J for emacs-devel@gnu.org; Sat, 21 May 2022 13:07:38 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:5381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsSZh-0002sp-5v; Sat, 21 May 2022 13:07:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=9FXy1ivy3q/Ao/WB PhUwGxLw9ShZdu72aCN8cjKqXOw=; h=in-reply-to:date:references:subject: cc:to:from; d=ledu-giraud.fr; b=H94kOKnlvnSu/89ERamjGIig195gSUMf/fcWdf N8e9AyBcSIMCVgDR2T93C98Ielbe0n4UB232hGdwHD/z9I9/DcEUh41Y64Y3noDdH7BWrg y2MBQRjsf2gJGuREpSo5yPtiRIAHP+uH1/qXVTSoI1y7uESRFj06DoX7ZbSlnj+CbmSLEc CYfy1YgGSmzaaLTLzir+21u1o4kvj+Zg/UYgYoOkkHyR2HXbhGcBlLN26FGvXRvT+fNX7p cf1797B9ESK/U5eRAiNAgxTdGPMU8tbzx1QNB8/wKYnAGBC4or8Fxamye7QdiIrKeFD7Cf QayKjolCMH2NSHrcETUsEJYQ== Original-Received: from elite.giraud ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id c7fe2253 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 21 May 2022 19:07:28 +0200 (CEST) In-Reply-To: <83y1yv8cdp.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 21 May 2022 12:26:42 +0300") Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@ledu-giraud.fr; helo=ledu-giraud.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:290056 Archived-At: Eli Zaretskii 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