Function: magit-diff-scope
magit-diff-scope is a byte-compiled function defined in magit-diff.el.
Signature
(magit-diff-scope &optional (SECTION nil SSECTION) STRICT)
Documentation
Return the diff scope of SECTION or the selected section(s).
A diff's "scope" describes what part of a diff is selected, it is
a symbol, one of region, hunk, hunks, file, files, or
list. Do not confuse this with the diff "type", as returned by
magit-diff-type.
If optional SECTION is non-nil, then return the scope of that,
ignoring the sections selected by the region. Otherwise return
the scope of the current section, or if the region is active and
selects a valid group of diff related sections, the type of these
sections, i.e., hunks or files. If SECTION, or if that is nil
the current section, is a hunk section; and the region region
starts and ends inside the body of a that section, then the type
is region. If the region is empty after a mouse click, then
hunk is returned instead of region.
If optional STRICT is non-nil, then return nil if the diff type of
the section at point is untracked or the section at point is not
actually a diff but a diffstat section.
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-diff.el
(cl-defun magit-diff-scope (&optional (section nil ssection) strict)
"Return the diff scope of SECTION or the selected section(s).
A diff's \"scope\" describes what part of a diff is selected, it is
a symbol, one of `region', `hunk', `hunks', `file', `files', or
`list'. Do not confuse this with the diff \"type\", as returned by
`magit-diff-type'.
If optional SECTION is non-nil, then return the scope of that,
ignoring the sections selected by the region. Otherwise return
the scope of the current section, or if the region is active and
selects a valid group of diff related sections, the type of these
sections, i.e., `hunks' or `files'. If SECTION, or if that is nil
the current section, is a `hunk' section; and the region region
starts and ends inside the body of a that section, then the type
is `region'. If the region is empty after a mouse click, then
`hunk' is returned instead of `region'.
If optional STRICT is non-nil, then return nil if the diff type of
the section at point is `untracked' or the section at point is not
actually a `diff' but a `diffstat' section."
(let ((siblings (and (not ssection) (magit-region-sections nil t))))
(setq section (or section (car siblings) (magit-current-section)))
(when (and section
(or (not strict)
(and (not (eq (magit-diff-type section) 'untracked))
(not (eq (and$ (oref section parent)
(oref $ type))
'diffstat)))))
(pcase (list (oref section type)
(and siblings t)
(magit-diff-use-hunk-region-p)
ssection)
(`(hunk nil t ,_)
(if (magit-section-internal-region-p section) 'region 'hunk))
('(hunk t t nil) 'hunks)
(`(hunk ,_ ,_ ,_) 'hunk)
('(file t t nil) 'files)
(`(file ,_ ,_ ,_) 'file)
('(module t t nil) 'files)
(`(module ,_ ,_ ,_) 'file)
(`(,(or 'staged 'unstaged 'untracked) nil ,_ ,_) 'list)))))