branch: externals/objed
commit 4d1a4453a50fe21fd2de0ddb24871d14f33220b3
Author: Clemens Radermacher <[email protected]>
Commit: Clemens Radermacher <[email protected]>
Add public object bounds functions
---
objed-objects.el | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/objed-objects.el b/objed-objects.el
index 95f3b69..8d1f057 100644
--- a/objed-objects.el
+++ b/objed-objects.el
@@ -438,7 +438,7 @@ Either the symbol `whole' or `inner'.")
(defvar objed--marked-ovs nil
"List of overlays of marked objects.")
-;; * Get object positions
+;; * Internal object access functions
(defun objed--inside-object-p (obj)
"Return non-nil if point point inside object OBJ."
@@ -450,7 +450,6 @@ Either the symbol `whole' or `inner'.")
(when (and obj (not (objed--distant-p obj)))
obj)))
-
(defun objed--beg (&optional obj)
"Get beginning position of object.
@@ -459,7 +458,6 @@ defaults to `objed--current-obj'."
(let ((obj (or obj objed--current-obj)))
(caar obj)))
-
(defun objed--end (&optional obj)
"Get end position of object.
@@ -468,6 +466,18 @@ defaults to `objed--current-obj'."
(let ((obj (or obj objed--current-obj)))
(cadr (car obj))))
+(defun objed--object-at-point (obj &optional state)
+ "Return object data for OBJ and STATE a point.
+
+Does return nil when there is no such object."
+ (let* ((objed--object obj)
+ (objed--obj-state (or state 'whole))
+ (o (ignore-errors (objed--object :get-obj))))
+ (when o
+ (if (eq state 'inner)
+ (nreverse o)
+ o))))
+
(defun objed--other (&optional obj)
"Return object position opposite to point.
@@ -525,6 +535,7 @@ otherwise the its the head of object OBJ which defaults to
(t
(car obj)))))
+
(defun objed--bounds (&optional obj)
"Get the current object bounds.
@@ -896,6 +907,34 @@ Position POS defaults to point."
(cdr (assq inv buffer-invisibility-spec)))
(cl-return t))))))
+;; * Public access functions for objects
+
+(defun objed-bounds-at-point (obj &optional state)
+ "Return beg and end position of object at point.
+
+The positions are returned as a cons: (beg . end). OBJ is a
+symbol of a known object. STATE is either `whole' or `inner' and
+defaults to `whole'.
+
+Does return nil when there is no such object at point."
+ (let ((o (objed--object-at-point obj state)))
+ (when o
+ (cons (objed--beg o)
+ (objed--end o)))))
+
+
+(defun objed-bounds-at (pos obj &optional state)
+ "Return beg and end position of object at POS.
+
+The positions are returned as a cons: (beg . end). OBJ is a
+symbol of a known object. STATE is either `whole' or `inner' and
+defaults to `whole'.
+
+Does return nil when there is no such object at point."
+ (save-excursion
+ (goto-char pos)
+ (objed-bounds-at-point obj state)))
+
;; * Object creation/manipulation