From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: master fb4f2aa038: * lisp/textmodes/paragraphs.el (repunctuate-sentences-filter): New function. Date: Tue, 04 Jan 2022 20:03:36 +0200 Organization: LINKOV.NET Message-ID: <86y23vml8n.fsf@mail.linkov.net> References: <87r19ns9fv.fsf@miha-pc> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28766"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: emacs-devel@gnu.org To: jakanakaevangeli@chiru.no Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 04 19:12:20 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 1n4oIG-0007Mj-15 for ged-emacs-devel@m.gmane-mx.org; Tue, 04 Jan 2022 19:12:20 +0100 Original-Received: from localhost ([::1]:43328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4oIE-0005WT-T0 for ged-emacs-devel@m.gmane-mx.org; Tue, 04 Jan 2022 13:12:18 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4oHD-0003TF-E2 for emacs-devel@gnu.org; Tue, 04 Jan 2022 13:11:15 -0500 Original-Received: from relay10.mail.gandi.net ([217.70.178.230]:38065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4oHA-0007Yh-TJ for emacs-devel@gnu.org; Tue, 04 Jan 2022 13:11:15 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay10.mail.gandi.net (Postfix) with ESMTPSA id B2FE5240003; Tue, 4 Jan 2022 18:11:07 +0000 (UTC) In-Reply-To: <87r19ns9fv.fsf@miha-pc> (jakanakaevangeli@chiru.no's message of "Tue, 04 Jan 2022 18:21:56 +0100") Received-SPF: pass client-ip=217.70.178.230; envelope-from=juri@linkov.net; helo=relay10.mail.gandi.net X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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:284189 Archived-At: >> +(defun repunctuate-sentences-filter (_start _end) >> + "Search filter used by `repunctuate-sentences' to skip unneeded spaces. >> +By default, it skips occurrences that already have two spaces. >> +It is advised to put `advice-add' on this function to add more filters, >> +for example, `(looking-back (rx (or \"e.g.\" \"i.e.\") \" \") 5)' >> +with a set of predefined abbreviations to skip from adding two spaces." >> + (not (length= (match-string 4) 2))) > > Similarly to filter-buffer-substring-function, I believe it would be > better if this was a variable, on which 'add-function' could be used. > This would make it easier to set buffer locally if needed. Thanks, good idea. Then, for example, #+begin_src emacs-lisp (add-function :after-while (local 'repunctuate-sentences-filter) (lambda (start end) (not (looking-back (rx (or "e.g." "i.e.") " ") 5)))) #+end_src will be possible with: diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el index fc10a0dd1b..e3b5ecbcca 100644 --- a/lisp/textmodes/paragraphs.el +++ b/lisp/textmodes/paragraphs.el @@ -487,6 +487,8 @@ repunctuate-sentences-filter with a set of predefined abbreviations to skip from adding two spaces." (not (length= (match-string 4) 2))) +(defvar repunctuate-sentences-filter #'repunctuate-sentences-filter) + (defun repunctuate-sentences (&optional no-query start end) "Put two spaces at the end of sentences from point to the end of buffer. It works using `query-replace-regexp'. In Transient Mark mode, @@ -507,10 +509,10 @@ repunctuate-sentences (unwind-protect (progn (add-function :after-while isearch-filter-predicate - #'repunctuate-sentences-filter) + repunctuate-sentences-filter) (query-replace-regexp regexp to-string nil start end)) (remove-function isearch-filter-predicate - #'repunctuate-sentences-filter))))) + repunctuate-sentences-filter))))) --