Function: majutsu-selection-find-section
majutsu-selection-find-section is a natively compiled function defined
in majutsu-selection.el.
Signature
(majutsu-selection-find-section VALUE &optional TYPE ROOT)
Documentation
Return the closest section matching VALUE.
When ROOT is non-nil, traverse from that section, otherwise from
magit-root-section. TYPE defaults to the current section's type.
Exact matches are preferred; otherwise choose the nearest prefix match.
Source Code
;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-selection.el
(defun majutsu-selection-find-section (value &optional type root)
"Return the closest section matching VALUE.
When ROOT is non-nil, traverse from that section, otherwise from
`magit-root-section'. TYPE defaults to the current section's type.
Exact matches are preferred; otherwise choose the nearest prefix match."
(let* ((root (or root magit-root-section))
(anchor (or (and-let* ((cur (magit-current-section)))
(oref cur start))
(point)))
(type (or type
(when-let* ((cur (magit-current-section)))
(oref cur type))))
(exact (and root value type
(magit-get-section
(append `((,type . ,value)) (magit-section-ident root)))))
best
best-dist)
(or exact
(progn
(magit-map-sections
(##let ((id (magit-section-value-if type %)))
(when (and (stringp value)
(stringp id)
(or (string-prefix-p id value)
(string-prefix-p value id)))
(let* ((pos (oref % start))
(dist (abs (- pos anchor))))
(when (or (null best-dist) (< dist best-dist))
(setq best %)
(setq best-dist dist)))))
root))
best)))