From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Counting sentences in `count-words' Date: Sat, 21 May 2022 12:26:42 +0300 Message-ID: <83y1yv8cdp.fsf@gnu.org> References: <87o7zsiekm.fsf@elite.giraud> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33141"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Manuel Giraud Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat May 21 11:27:47 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 1nsLOj-0008Sx-Rz for ged-emacs-devel@m.gmane-mx.org; Sat, 21 May 2022 11:27:46 +0200 Original-Received: from localhost ([::1]:55874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsLOi-0000iM-9B for ged-emacs-devel@m.gmane-mx.org; Sat, 21 May 2022 05:27:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsLNp-0008AA-Sl for emacs-devel@gnu.org; Sat, 21 May 2022 05:26:49 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:49542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsLNp-0002uc-8o; Sat, 21 May 2022 05:26:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=AKPo9EoqtOz9oQQXhW35nPqIIx4UsJ1nyI9TXZ/uAto=; b=ajIJqCm8lcWh PDbfVJ6/L/BdUUSC2+4EPpEXpEHV0O6tVeRZwrvyKHgF4d115H89SRWnh2oZB+t8UDRXimgBei1mx DkUjLfmT0VcjuZfhB/x+k0JOENbLaQkjZUbGeFlBhR/OhjDDHk+tDIGaodec3SkRcDgCd/VUltv2D i9aHsv48Ifrpzc43Ue9wzxnvbGEEy4R42HeVzkA4Siqm1bJr32I+5OSKkRa6BPDxmMB2o87QJvSNW POI9GV1L7i18bgZREbov9UGKsQU3pzbY8Tk6ShXXq/ZHabKdaY3v5sfqUXhp/Smsuu5e54NmcGSOQ N5FcynEsAjnX9ENWu6DBgA==; Original-Received: from [87.69.77.57] (port=4354 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsLNo-0008UK-O7; Sat, 21 May 2022 05:26:49 -0400 In-Reply-To: <87o7zsiekm.fsf@elite.giraud> (message from Manuel Giraud on Fri, 20 May 2022 14:16:57 +0200) 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:290041 Archived-At: > From: Manuel Giraud > 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.