Function: magit-region-sections

magit-region-sections is a byte-compiled function defined in magit-section.el.

Signature

(magit-region-sections &optional CONDITION MULTIPLE)

Documentation

Return a list of the selected sections.

When the region is active and constitutes a valid section selection, then return a list of all selected sections. This is the case when the region begins in the heading of a section and ends in the heading of the same section or in that of a sibling section. If optional MULTIPLE is non-nil, then the region cannot begin and end in the same section.

When the selection is not valid, then return nil. In this case, most commands that can act on the selected sections will instead act on the section at point.

When the region looks like it would in any other buffer then the selection is invalid. When the selection is valid then the region uses the magit-section-highlight face. This does not apply to diffs where things get a bit more complicated, but even here if the region looks like it usually does, then that's not a valid selection as far as this function is concerned.

If optional CONDITION is non-nil, then the selection not only has to be valid; all selected sections additionally have to match CONDITION, or nil is returned. See magit-section-match for the forms CONDITION can take.

Source Code

;; Defined in ~/.emacs.d/elpa/magit-section-20260330.1102/magit-section.el
(defun magit-region-sections (&optional condition multiple)
  "Return a list of the selected sections.

When the region is active and constitutes a valid section
selection, then return a list of all selected sections.  This is
the case when the region begins in the heading of a section and
ends in the heading of the same section or in that of a sibling
section.  If optional MULTIPLE is non-nil, then the region cannot
begin and end in the same section.

When the selection is not valid, then return nil.  In this case,
most commands that can act on the selected sections will instead
act on the section at point.

When the region looks like it would in any other buffer then
the selection is invalid.  When the selection is valid then the
region uses the `magit-section-highlight' face.  This does not
apply to diffs where things get a bit more complicated, but even
here if the region looks like it usually does, then that's not
a valid selection as far as this function is concerned.

If optional CONDITION is non-nil, then the selection not only
has to be valid; all selected sections additionally have to match
CONDITION, or nil is returned.  See `magit-section-match' for the
forms CONDITION can take."
  (and (region-active-p)
       (let* ((rbeg (region-beginning))
              (rend (region-end))
              (sbeg (magit-section-at rbeg))
              (send (magit-section-at rend)))
         ;; It should be possible to select a single section using
         ;; `set-mark-command', so don't use `use-region-p' above.
         ;; We still have to prevent the selection overlay from
         ;; being flashed when clicking inside a section, which
         ;; the first condition accomplishes:
         (and (or (not (eq this-command #'mouse-drag-region))
                  (> rend rbeg))
              send
              (not (eq send magit-root-section))
              (not (and (eq send sbeg)
                        (or multiple
                            (> rend rbeg))))
              (let ((siblings (cons sbeg (magit-section-siblings sbeg 'next)))
                    (sections ()))
                (and (memq send siblings)
                     (magit-section-position-in-heading-p sbeg rbeg)
                     (magit-section-position-in-heading-p send rend)
                     (progn
                       (while siblings
                         (push (car siblings) sections)
                         (when (eq (pop siblings) send)
                           (setq siblings nil)))
                       (setq sections (nreverse sections))
                       (and (or (not condition)
                                (seq-every-p (##magit-section-match condition %)
                                             sections))
                            sections))))))))