branch: master
commit 1171a763e515cd929a864f164734eb9104e4edab
Author: Ian Dunn <du...@gnu.org>
Commit: Ian Dunn <du...@gnu.org>

    Added support for excluding words past a certain character limit
    
    * paced.el (paced-character-limit): New defcustom.
      (paced-length-of-thing-at-point):
      (paced-thing-meets-limit-p): New helper defuns.
      (paced-excluded-p): Use them.
    
    * paced-tests.el (paced-character-limit): Test for new feature.
---
 paced-tests.el | 14 ++++++++++++++
 paced.el       | 42 +++++++++++++++++++++++++++++++++---------
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/paced-tests.el b/paced-tests.el
index d88bb4b..e7b5552 100644
--- a/paced-tests.el
+++ b/paced-tests.el
@@ -477,6 +477,20 @@
       (let ((paced-point-in-thing-at-point-for-exclusion 'end))
         (should-not (paced-excluded-p))))))
 
+(ert-deftest paced-character-limit ()
+  "Test character limit."
+  (let* ((paced-exclude-function (lambda () nil))
+         (buffer-one (find-file-noselect paced-first-test-file)))
+    (with-current-buffer buffer-one
+      (goto-char (point-min))
+      (should (equal (paced-thing-at-point) "one"))
+      (let* ((paced-character-limit 0))
+        (should-not (paced-excluded-p)))
+      (let* ((paced-character-limit 1))
+        (should (paced-excluded-p)))
+      (let* ((paced-character-limit 3))
+        (should-not (paced-excluded-p))))))
+
 (provide 'paced-tests)
 
 ;;; paced-tests.el ends here
diff --git a/paced.el b/paced.el
index 337386a..81bd748 100644
--- a/paced.el
+++ b/paced.el
@@ -131,6 +131,14 @@ information on exclusion."
   :type 'symbol
   :options '(beginning end))
 
+(defcustom paced-character-limit 0
+  "Character limit for including things in paced.
+
+If set to 0, impose no limit.  Otherwise, include words whose
+length is less than or equal to the value."
+  :group 'paced
+  :type 'number)
+
 
 
 (defun paced--default-dictionary-sort-func (usage-hash)
@@ -522,21 +530,37 @@ Thing is based on `paced-thing-at-point-constituent'."
 Thing is based on `paced-thing-at-point-constituent'."
   (goto-char (cdr (paced-bounds-of-thing-at-point))))
 
+(defun paced-length-of-thing-at-point ()
+  "Return the length, in characters, of the current thing at point."
+  (length (paced-thing-at-point)))
+
+(defun paced-thing-meets-limit-p ()
+  "Return non-nil if the current thing at point meets the limit requirement.
+
+The limit requirement is set with `paced-character-limit'."
+  (or (eq paced-character-limit 0)
+      (<= (paced-length-of-thing-at-point) paced-character-limit)))
+
 (defun paced-excluded-p ()
   "Return non-nil to exclude current thing at point.
 
 See `paced-exclude-function' for more.
 
 Exclusion can be performed from either the beginning or end of
-the thing at point.  See `paced-point-in-thing-at-point-for-exclusion' for how
-to set this."
-  (save-excursion
-    (pcase paced-point-in-thing-at-point-for-exclusion
-      (`beginning
-       (paced-goto-beginning-of-thing-at-point))
-      (`end
-       (paced-goto-end-of-thing-at-point)))
-    (funcall paced-exclude-function)))
+the thing at point.  See
+`paced-point-in-thing-at-point-for-exclusion' for how to set
+this.
+
+This also handles character limits set by
+`paced-character-limit'."
+  (or (not (paced-thing-meets-limit-p))
+      (save-excursion
+        (pcase paced-point-in-thing-at-point-for-exclusion
+          (`beginning
+           (paced-goto-beginning-of-thing-at-point))
+          (`end
+           (paced-goto-end-of-thing-at-point)))
+        (funcall paced-exclude-function))))
 
 (defun paced-mixed-case-word-p (word)
   "Return non-nil if WORD is mixed-case.

Reply via email to