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

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

[elpa] externals/compat 060b6632c4 1/2: compat-29: Add pos-bol and pos-e


From: ELPA Syncer
Subject: [elpa] externals/compat 060b6632c4 1/2: compat-29: Add pos-bol and pos-eol
Date: Sat, 7 Jan 2023 14:57:25 -0500 (EST)

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

    compat-29: Add pos-bol and pos-eol
---
 NEWS.org        |  3 ++-
 compat-29.el    | 29 +++++++++++++++++++++++++++++
 compat-tests.el | 37 +++++++++++++++++++++++++++++++++++++
 compat.texi     | 12 ++++++++++++
 4 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/NEWS.org b/NEWS.org
index f1539c3fdd..c2a4000409 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -18,12 +18,13 @@
 - compat-26: Fix and test ~image-property~ setter.
 - compat-26: Fix and test ~read-multiple-choice~.
 - compat-28: Fix and test ~with-existing-directory~.
+- compat-28: Drop obsolete function ~make-directory-autoloads~.
 - compat-29: Drop broken functions ~string-pixel-width~ and
   ~buffer-text-pixel-size~. These functions had poor performance which lead to 
a
   downstream issue in the doom-modeline package. If a more efficient solution 
is
   possible, the function will be added back.
 - compat-29: Drop broken function ~string-limit~.
-- compat-28: Drop obsolete function ~make-directory-autoloads~.
+- compat-29: Add ~pos-bol~ and ~pos-eol~.
 
 * Release of "Compat" Version 29.1.0.1
 
diff --git a/compat-29.el b/compat-29.el
index 5cc6b79251..0527ee6986 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -120,6 +120,35 @@ Unibyte strings are converted to multibyte for comparison."
           (throw 'found plist))
         (setq plist (cddr plist))))))
 
+;;;; Defined in editfns.c
+
+(compat-defun pos-bol (&optional n) ;; <OK>
+  "Return the position of the first character on the current line.
+With optional argument N, scan forward N - 1 lines first.
+If the scan reaches the end of the buffer, return that position.
+
+This function ignores text display directionality; it returns the
+position of the first character in logical order, i.e. the smallest
+character position on the logical line.  See `vertical-motion' for
+movement by screen lines.
+
+This function does not move point.  Also see `line-beginning-position'."
+  (let ((inhibit-field-text-motion t))
+    (line-beginning-position n)))
+
+(compat-defun pos-eol (&optional n) ;; <OK>
+  "Return the position of the last character on the current line.
+With argument N not nil or 1, move forward N - 1 lines first.
+If scan reaches end of buffer, return that position.
+
+This function ignores text display directionality; it returns the
+position of the last character in logical order, i.e. the largest
+character position on the line.
+
+This function does not move point.  Also see `line-end-position'."
+  (let ((inhibit-field-text-motion t))
+    (line-end-position n)))
+
 ;;;; Defined in keymap.c
 
 (compat-defun define-key (keymap key def &optional remove) ;; <UNTESTED>
diff --git a/compat-tests.el b/compat-tests.el
index eb646b3b2f..de4fc86c1a 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -60,6 +60,43 @@
     (setq list (funcall sym list "first" 1 #'string=))
     (should (eq (compat-call plist-get list "first" #'string=) 1))))
 
+(ert-deftest pos-bol ()
+  (with-temp-buffer
+    (insert (propertize "one" 'field 1)
+            (propertize "two" 'field 2)
+            (propertize "tri" 'field 3)
+            "\n")
+    (insert (propertize "one" 'field 1)
+            (propertize "two" 'field 2)
+            (propertize "tri" 'field 3)
+            "\n")
+    (goto-char 5)
+    (should-equal (line-beginning-position) 4)
+    (should-equal (line-end-position) 7)
+    (should-equal (pos-bol) 1)
+    (should-equal (pos-eol) 10)
+    (should-equal (line-beginning-position 1) 4)
+    (should-equal (line-end-position 1) 7)
+    (should-equal (pos-bol 1) 1)
+    (should-equal (pos-eol 1) 10)
+    (should-equal (line-beginning-position 2) 11)
+    (should-equal (line-end-position 2) 20)
+    (should-equal (pos-bol 2) 11)
+    (should-equal (pos-eol 2) 20)
+    (goto-char 15)
+    (should-equal (line-beginning-position) 14)
+    (should-equal (line-end-position) 17)
+    (should-equal (pos-bol) 11)
+    (should-equal (pos-eol) 20)
+    (should-equal (line-beginning-position 1) 14)
+    (should-equal (line-end-position 1) 17)
+    (should-equal (pos-bol 1) 11)
+    (should-equal (pos-eol 1) 20)
+    (should-equal (line-beginning-position 0) 1)
+    (should-equal (line-end-position 0) 10)
+    (should-equal (pos-bol 0) 1)
+    (should-equal (pos-eol 0) 10)))
+
 (ert-deftest image-property ()
   (let ((image (list 'image)))
     ;; Add properties.
diff --git a/compat.texi b/compat.texi
index 0fa277e900..500fddd1b9 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2021,6 +2021,18 @@ provided by Compat. Note that due to upstream changes, 
it might happen
 that there will be the need for changes, so use these functions with
 care.
 
+@c copied from lispref/positions.texi
+@defun pos-bol &optional count
+Like @code{line-beginning-position}, but ignores fields (and is more
+efficient).
+@end defun
+
+@c copied from lispref/positions.texi
+@defun pos-eol &optional count
+Like @code{line-end-position}, but ignores fields (and is more
+efficient).
+@end defun
+
 @c copied from lispref/display.texi
 @defun get-display-property position prop &optional object properties
 This convenience function can be used to get a specific display



reply via email to

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