branch: elpa/git-commit commit be371711f521b95321e34ac59c9f04e86989d069 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
magit-section-at: New function --- docs/magit-section.org | 4 ++++ docs/magit-section.texi | 5 +++++ lisp/magit-bisect.el | 2 +- lisp/magit-section.el | 16 ++++++++++------ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/docs/magit-section.org b/docs/magit-section.org index deb8769f2f..292512887f 100644 --- a/docs/magit-section.org +++ b/docs/magit-section.org @@ -151,6 +151,10 @@ source for suitable examples before asking me for help. Thanks! Return the section at point. +- Function magit-section-at &optional position :: + + Return the section at POSITION, defaulting to point. + - Function: magit-section-ident section :: Return an unique identifier for SECTION. The return value has the diff --git a/docs/magit-section.texi b/docs/magit-section.texi index ed865d841f..05d22b1f97 100644 --- a/docs/magit-section.texi +++ b/docs/magit-section.texi @@ -196,6 +196,11 @@ buffer is reached. FUNCTION has to move point forward or return Return the section at point. @end defun +@table @asis +@item Function magit-section-at &optional position +Return the section at POSITION, defaulting to point. +@end table + @defun magit-section-ident section Return an unique identifier for SECTION@. The return value has the form @code{((TYPE . VALUE)...)}. diff --git a/lisp/magit-bisect.el b/lisp/magit-bisect.el index 63de453204..0ddfd39acf 100644 --- a/lisp/magit-bisect.el +++ b/lisp/magit-bisect.el @@ -224,7 +224,7 @@ bisect run'." (magit-process-sentinel process event) (when (buffer-live-p (process-buffer process)) (with-current-buffer (process-buffer process) - (when-let ((section (get-text-property (point) 'magit-section)) + (when-let ((section (magit-section-at)) (output (buffer-substring-no-properties (oref section content) (oref section end)))) diff --git a/lisp/magit-section.el b/lisp/magit-section.el index 3b4511bcd3..89b75e4eb9 100644 --- a/lisp/magit-section.el +++ b/lisp/magit-section.el @@ -395,7 +395,11 @@ never modify it.") (defun magit-current-section () "Return the section at point." - (or (get-text-property (point) 'magit-section) magit-root-section)) + (or (magit-section-at) magit-root-section)) + +(defun magit-section-at (&optional position) + "Return the section at POSITION, defaulting to point." + (get-text-property (or position (point)) 'magit-section)) (defun magit-section-ident (section) "Return an unique identifier for SECTION. @@ -1118,7 +1122,7 @@ anything this time around. (let ((next (or (next-single-property-change (point) 'magit-section) end))) - (unless (get-text-property (point) 'magit-section) + (unless (magit-section-at) (put-text-property (point) next 'magit-section ,s) (when map (put-text-property (point) next 'keymap map))) @@ -1625,8 +1629,8 @@ forms CONDITION can take." (when (region-active-p) (let* ((rbeg (region-beginning)) (rend (region-end)) - (sbeg (get-text-property rbeg 'magit-section)) - (send (get-text-property rend 'magit-section))) + (sbeg (magit-section-at rbeg)) + (send (magit-section-at rend))) (when (and send (not (eq send magit-root-section)) (not (and multiple (eq send sbeg)))) @@ -1663,8 +1667,8 @@ current section." If optional SECTION is nil, use the current section." (and (region-active-p) (or section (setq section (magit-current-section))) - (let ((beg (get-text-property (region-beginning) 'magit-section))) - (and (eq beg (get-text-property (region-end) 'magit-section)) + (let ((beg (magit-section-at (region-beginning)))) + (and (eq beg (magit-section-at (region-end))) (eq beg section))) (not (or (magit-section-position-in-heading-p section (region-beginning)) (magit-section-position-in-heading-p section (region-end))))