emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat ef2ec232b8 3/3: compat-29: Add count-sentences


From: ELPA Syncer
Subject: [elpa] externals/compat ef2ec232b8 3/3: compat-29: Add count-sentences
Date: Sat, 21 Jan 2023 06:57:27 -0500 (EST)

branch: externals/compat
commit ef2ec232b8cbaa942ab6bcdd7887fc7cf5ef429a
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-29: Add count-sentences
---
 NEWS.org        |  1 +
 compat-29.el    | 16 ++++++++++++++++
 compat-tests.el |  6 ++++++
 compat.texi     |  7 +++++--
 4 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/NEWS.org b/NEWS.org
index 92f7a1a4f0..0feece8f92 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -17,6 +17,7 @@
 - compat-28: Add ~with-window-non-dedicated~.
 - compat-29: Add ~buffer-local-set-state~ and ~buffer-local-restore-state~.
 - compat-29: Add ~compiled-function-p~.
+- compat-29: Add ~count-sentences~.
 - compat-29: Add ~delete-line~.
 - compat-29: Add ~get-scratch-buffer-create~.
 - compat-29: Add ~list-of-strings-p~.
diff --git a/compat-29.el b/compat-29.el
index 6c85933f7e..495ede7e90 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -1211,5 +1211,21 @@ Also see `buttonize'."
           (when (equal answer (cadr c))
             (throw 'found c)))))))
 
+;;;; Defined in paragraphs.el
+
+(compat-defun count-sentences (start end) ;; <compat-tests:count-sentences>
+  "Count sentences in current buffer from START to END."
+  (let ((sentences 0)
+        (inhibit-field-text-motion t))
+    (save-excursion
+      (save-restriction
+        (narrow-to-region start end)
+        (goto-char (point-min))
+        (while (ignore-errors (forward-sentence))
+          (setq sentences (1+ sentences)))
+        (when (/= (skip-chars-backward " \t\n") 0)
+          (setq sentences (1- sentences)))
+        sentences))))
+
 (provide 'compat-29)
 ;;; compat-29.el ends here
diff --git a/compat-tests.el b/compat-tests.el
index 5b217f6da2..e221f8534f 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -2803,5 +2803,11 @@
   (should-not (readablep (list (make-marker))))
   (should-not (readablep (make-marker))))
 
+(ert-deftest count-sentences ()
+  (with-temp-buffer
+    (insert "First sentence.  Second sentence.  Third sentence.  Fourth 
sentence.")
+    (should-equal 4 (count-sentences (point-min) (point-max)))
+    (should-equal 2 (count-sentences 16 50))))
+
 (provide 'compat-tests)
 ;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index da33097d39..efc88ac306 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2101,6 +2101,11 @@ older than 29.1.  Note that due to upstream changes, it 
might happen
 that there will be the need for changes, so use these functions with
 care.
 
+@c based on lisp/textmodes/paragraphs.el
+@defun count-sentences start end
+Count sentences in current buffer from @var{start} to @var{end}.
+@end defun
+
 @c copied from lispref/streams.texi
 @defun readablep object
 This predicate says whether @var{object} has @dfn{readable syntax},
@@ -2838,8 +2843,6 @@ The function @code{imagep}.
 @item
 The function @code{function-documentation}.
 @item
-The function @code{count-sentences}.
-@item
 The command @code{string-edit} and @code{read-string-from-buffer}.
 @item
 The macro @code{with-undo-amalgamate}.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]