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

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

[elpa] master a9d3d12 07/13: Added support for choosing which side of th


From: Ian Dunn
Subject: [elpa] master a9d3d12 07/13: Added support for choosing which side of thing-at-point to consider for exclusion
Date: Sun, 4 Feb 2018 12:32:34 -0500 (EST)

branch: master
commit a9d3d125eaf0b9654a5653d3e91ffba8510962db
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>

    Added support for choosing which side of thing-at-point to consider for 
exclusion
    
    * paced.el (paced-point-in-thing-at-point): New defcustom.
      (paced-goto-beginning-of-thing-at-point):
      (paced-goto-end-of-thing-at-point): New helper defuns.
      (paced-excluded-p): Use them.
---
 paced-tests.el | 14 ++++++++++++++
 paced.el       | 53 ++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/paced-tests.el b/paced-tests.el
index 700af1c..d88bb4b 100644
--- a/paced-tests.el
+++ b/paced-tests.el
@@ -463,6 +463,20 @@
     (should (equal (map-elt merged-2 'a) '("def")))
     (should (equal (map-elt merged-2 'c) '("ghi")))))
 
+(ert-deftest paced-beginning-end-of-thing-at-point ()
+  "Test exclusion and `paced-point-in-thing-at-point-for-exclusion'."
+  (let* ((paced-exclude-function (lambda () (looking-at-p "one")))
+         (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-point-in-thing-at-point-for-exclusion 'beginning))
+        (should (paced-excluded-p)))
+      (paced-forward-thing)
+      (should (equal (paced-thing-at-point) "one"))
+      (let ((paced-point-in-thing-at-point-for-exclusion 'end))
+        (should-not (paced-excluded-p))))))
+
 (provide 'paced-tests)
 
 ;;; paced-tests.el ends here
diff --git a/paced.el b/paced.el
index 3f40176..337386a 100644
--- a/paced.el
+++ b/paced.el
@@ -118,6 +118,19 @@ allowing all files."
   :group 'paced
   :type 'boolean)
 
+(defcustom paced-point-in-thing-at-point-for-exclusion 'beginning
+  "Symbol to indicate from where exclusion should occur.
+
+If 'beginning, exclusion is checked at the beginning of the thing
+at point.  If 'end, exclusion is checked at the end of the thing
+at point.
+
+See `paced-excluded-p' and `paced-exclude-function' for more
+information on exclusion."
+  :group 'paced
+  :type 'symbol
+  :options '(beginning end))
+
 
 
 (defun paced--default-dictionary-sort-func (usage-hash)
@@ -460,7 +473,11 @@ since population mostly uses temporary buffers.")
   "Local predicate to determine if thing at point should be excluded.
 
 This should be a function of no arguments that returns non-nil if
-the current thing-at-point should be excluded from paced dictionaries.
+the current thing-at-point should be excluded from paced
+dictionaries.  Exclusion is checked from the start or the end of
+the current thing, depending on `paced-point-in-thing-at-point-for-exclusion'.
+Point returns to its original position after the function is
+called.
 
 By default, this allows everything.
 
@@ -472,12 +489,6 @@ A useful function for this is `paced-in-comment-p'.")
 If POS is not specified, defaults to `point'."
   (nth 8 (syntax-ppss (or pos (point)))))
 
-(defun paced-excluded-p ()
-  "Return non-nil to exclude current thing at point.
-
-See `paced-exclude-function' for more."
-  (funcall paced-exclude-function))
-
 (defun paced-bounds-of-thing-at-point ()
   "Get the bounds of the thing at point."
   (bounds-of-thing-at-point paced-thing-at-point-constituent))
@@ -499,6 +510,34 @@ Things is based on `paced-thing-at-point-constituent'."
   (interactive "p")
   (forward-thing paced-thing-at-point-constituent number))
 
+(defun paced-goto-beginning-of-thing-at-point ()
+  "Move to the start of the current thing at point.
+
+Thing is based on `paced-thing-at-point-constituent'."
+  (goto-char (car (paced-bounds-of-thing-at-point))))
+
+(defun paced-goto-end-of-thing-at-point ()
+  "Move to the end of the current thing at point.
+
+Thing is based on `paced-thing-at-point-constituent'."
+  (goto-char (cdr (paced-bounds-of-thing-at-point))))
+
+(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)))
+
 (defun paced-mixed-case-word-p (word)
   "Return non-nil if WORD is mixed-case.
 



reply via email to

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