From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Andr=C3=A9?= A. Gomes Newsgroups: gmane.emacs.bugs Subject: bug#56844: [PATCH] Refactor repunctuate-sentences to accommodate corner case. Date: Sat, 30 Jul 2022 21:06:16 +0300 Message-ID: <87r122eaqv.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29459"; mail-complaints-to="usenet@ciao.gmane.io" To: 56844@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 30 20:07:26 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1oHqs1-0007TK-K5 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Jul 2022 20:07:25 +0200 Original-Received: from localhost ([::1]:45994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHqs0-00017Q-0B for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Jul 2022 14:07:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHqre-00015y-Vd for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:07:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45978) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHqre-0000Hi-N2 for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oHqre-0007qM-Gz for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Andr=C3=A9?= A. Gomes Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Jul 2022 18:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 56844 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.165920438630098 (code B ref -1); Sat, 30 Jul 2022 18:07:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Jul 2022 18:06:26 +0000 Original-Received: from localhost ([127.0.0.1]:35727 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oHqr4-0007pO-5n for submit@debbugs.gnu.org; Sat, 30 Jul 2022 14:06:26 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:33082) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oHqr1-0007pE-Rv for submit@debbugs.gnu.org; Sat, 30 Jul 2022 14:06:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHqr1-0000v3-IN for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:06:23 -0400 Original-Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]:45694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHqqz-00009T-Mv for bug-gnu-emacs@gnu.org; Sat, 30 Jul 2022 14:06:23 -0400 Original-Received: by mail-lj1-x22e.google.com with SMTP id p21so8235703ljh.12 for ; Sat, 30 Jul 2022 11:06:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=ccfpEvPKJJ898w+BVl+X6zfnCbDUoY6RbbUZKfonmQ4=; b=e2zbVxCUkVPYVSytYS70eCLKyEIL+ErVoo0fuTEbZJfFBtIo4McPFZkvBaV32whc0w HihcqyOPEEd94gLkrpAWhVeNPQ1x+gqkQngpKG30SK6PcaBTBo9TDbeoyDfvudjLME2y uJ3FfETiSGGLiKCBuxc3KDdIAxOVH1VFd/c3JtSdqg9QTE9xR1/Ax5ikbvfxtoL80t2j 7wB+H1oh60BwXBMA+zh6R0U70orWfHaZ45yQM7WCZ8MPjPd7jS0k0TVJAj+SL2UAyP+N a0XFPFhc+NHHYiD6tGuvrXnPfAlNvqIAwlCE6M6nD9axfDj43RIqO5aQ+328S2ZmVE4N VO7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=ccfpEvPKJJ898w+BVl+X6zfnCbDUoY6RbbUZKfonmQ4=; b=4nk+CbfNfRUV/MQL+QXLWNklg1LXbqQhvFzEsyLYf5jLvpw/bA7AgUvx7ZT4biq/hD effrqZnIAPUyw/G4vmXxQx1nlL2DezPui3XR7SFP4leuWIEvMDlP5mtepLvcn4nr9G+9 KzA5aoDz+OzvXJjnr4mhOaQ7TSHiHLWOB0yJM9ffsdWhHATIlzQlcSut0J2/imyIE3kV Ez/vO83xOgdKVXYLjPjjIa2NvnKb27Espne0GbG3RqJ1q4lbLd/vfE1bEU7JyxllxojL xUa3pqOOShLMAj47fneeWUizrgmkICoQJlMMkZUIB0d7tl9QVmZFMifISpa3liE1eN2g dZ/w== X-Gm-Message-State: AJIora8nDKLG/z1VRh1O6thekzG1xDCetbq1tgWDj5/HKBGiHcfyJueU qaw9bx5G864RPIS6/Y2XDiLKGtEDxF3tgJ5U X-Google-Smtp-Source: AGRyM1uPFpGQjLkrsQtm8X29nm0k53gC7eHztwdm/daJa8woom3HISrwC32Le22QiT7917Ro2xgN3Q== X-Received: by 2002:a2e:9e9a:0:b0:25d:8553:d794 with SMTP id f26-20020a2e9e9a000000b0025d8553d794mr2678416ljk.22.1659204379187; Sat, 30 Jul 2022 11:06:19 -0700 (PDT) Original-Received: from guix-xps13 (95-29-44-32.broadband.corbina.ru. [95.29.44.32]) by smtp.gmail.com with ESMTPSA id u5-20020a05651206c500b0048a7c86f4e7sm426757lff.291.2022.07.30.11.06.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 11:06:18 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=andremegafone@gmail.com; helo=mail-lj1-x22e.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:238305 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Hi Emacs, Please find the patch below. In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0) Windowing system distributor 'The X.Org Foundation', version 11.0.12101004 System Description: Guix System Configured using: 'configure CONFIG_SHELL=/gnu/store/4y5m9lb8k3qkb1y9m02sw9w9a6hacd16-bash-minimal-5.1.8/bin/bash SHELL=/gnu/store/4y5m9lb8k3qkb1y9m02sw9w9a6hacd16-bash-minimal-5.1.8/bin/bash --prefix=/gnu/store/7a6fnkqrxb0chmvj63f7ddr6wg3pq9g5-emacs-next-29.0.50-1.0a5477b --enable-fast-install --with-modules --with-cairo --disable-build-details' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Refactor-repunctuate-sentences-to-accommodate-corner.patch >From c57f51b7bfec3e3e5c9c2f680d7936c3e546bb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20A=2E=20Gomes?= Date: Sat, 30 Jul 2022 21:01:38 +0300 Subject: [PATCH] Refactor repunctuate-sentences to accommodate corner case. It now gracefully handles the case when abbreviations such as e.g. or i.e. are used in sentences. --- lisp/textmodes/paragraphs.el | 32 +++++++++++++------------ test/lisp/textmodes/paragraphs-tests.el | 5 ++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el index cd726ad4776..89624b66318 100644 --- a/lisp/textmodes/paragraphs.el +++ b/lisp/textmodes/paragraphs.el @@ -506,29 +506,31 @@ It is advised to use `add-function' on this 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.") -(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, -if the mark is active, operate on the contents of the region. -Second and third arg START and END specify the region to operate on. -If optional argument NO-QUERY is non-nil, make changes without asking -for confirmation. You can use `repunctuate-sentences-filter' to add -filters to skip occurrences of spaces that don't need to be replaced." - (interactive (list nil - (if (use-region-p) (region-beginning)) - (if (use-region-p) (region-end)))) - (let ((regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +") - (to-string "\\1\\2\\3 ")) +(defun repunctuate-sentences (&optional no-query) + "Put two spaces at the end of sentences. + +In Transient Mark mode, if the mark is active, operate on the +contents of the region. If optional argument NO-QUERY is +non-nil, make changes without asking for confirmation. + +Use `repunctuate-sentences-filter' to add filters to skip +occurrences of spaces that don't need to be replaced." + (interactive "P") + (let ((beg (if (use-region-p) (region-beginning) (point-min))) + (end (if (use-region-p) (region-end) (point-max))) + (case-fold-search nil) + (regexp "\\([]\"')]?\\)\\([.?!]\\)\\([]\"')]?\\) +\\([\"')[:upper:]]\\)") + (to-string "\\1\\2\\3 \\4")) (if no-query (progn - (when start (goto-char start)) + (goto-char beg) (while (re-search-forward regexp end t) (replace-match to-string))) (unwind-protect (progn (add-function :after-while isearch-filter-predicate repunctuate-sentences-filter) - (query-replace-regexp regexp to-string nil start end)) + (query-replace-regexp regexp to-string nil beg end)) (remove-function isearch-filter-predicate repunctuate-sentences-filter))))) diff --git a/test/lisp/textmodes/paragraphs-tests.el b/test/lisp/textmodes/paragraphs-tests.el index e54b459b20e..53735b4bf4b 100644 --- a/test/lisp/textmodes/paragraphs-tests.el +++ b/test/lisp/textmodes/paragraphs-tests.el @@ -101,10 +101,11 @@ (ert-deftest paragraphs-tests-repunctuate-sentences () (with-temp-buffer - (insert "Just. Some. Sentences.") + (insert "Just. Some. Sentences. Yet another, e.g. this one.") (goto-char (point-min)) (repunctuate-sentences t) - (should (equal (buffer-string) "Just. Some. Sentences.")))) + (should (equal (buffer-string) + "Just. Some. Sentences. Yet another, e.g. this one.")))) (ert-deftest paragraphs-tests-backward-sentence () (with-temp-buffer -- 2.37.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 Andr=C3=A9 A. Gomes "You cannot even find the ruins..." --=-=-=--