Function: magit-todos--insert-groups
magit-todos--insert-groups is a natively compiled function defined in
magit-todos.el.
Signature
(magit-todos--insert-groups &key DEPTH GROUP-FNS HEADING TYPE ITEMS)
Documentation
Insert ITEMS into grouped Magit section and return the section.
DEPTH sets indentation and should be 0 for a top-level group. It is automatically incremented when this function calls itself.
GROUP-FNS may be a list of functions to which ITEMS are applied
with -group-by to group them. Items are grouped
hierarchically, i.e. when GROUP-FNS has more than one function,
items are first grouped by the first function, then subgroups are
created which group items by subsequent functions.
HEADING is a string which is the group's heading. The count of items in each group is automatically appended.
TYPE is a symbol which is used by Magit internally to identify sections.
Source Code
;; Defined in /nix/store/xy37aj9089qvbs5clw0qszpi3hrh3mxx-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-todos-20250928.1611/magit-todos.el
(cl-defun magit-todos--insert-groups (&key depth group-fns heading type items)
"Insert ITEMS into grouped Magit section and return the section.
DEPTH sets indentation and should be 0 for a top-level group. It
is automatically incremented when this function calls itself.
GROUP-FNS may be a list of functions to which ITEMS are applied
with `-group-by' to group them. Items are grouped
hierarchically, i.e. when GROUP-FNS has more than one function,
items are first grouped by the first function, then subgroups are
created which group items by subsequent functions.
HEADING is a string which is the group's heading. The count of
items in each group is automatically appended.
TYPE is a symbol which is used by Magit internally to identify
sections."
;; NOTE: `magit-insert-section' seems to bind `magit-section-visibility-cache' to nil, so setting
;; visibility within calls to it probably won't work as intended.
(declare (indent defun))
(let* ((indent (propertize (s-repeat (* 2 depth) " ") 'face nil 'font-lock-face nil))
(heading (concat indent heading))
(magit-insert-section--parent (if (= 0 depth)
magit-root-section
magit-insert-section--parent)))
(if (and (consp group-fns)
(> (length group-fns) 0))
;; Insert more groups
(let* ((groups (--> (-group-by (car group-fns) items)
(cl-loop for group in-ref it
;; HACK: Set ":" keys to nil so they'll be grouped together.
do (pcase (car group)
(":" (setf (car group) nil)))
finally return it)
(magit-todos--coalesce-groups it)))
(section (magit-insert-section ((eval type))
(magit-insert-heading heading)
(cl-loop for (group-type . items) in groups
for group-name = (pcase group-type
;; Use "[Other]" instead of empty group name.
;; HACK: ":" is hard-coded, even though the
;; suffix regexp could differ. If users change
;; the suffix so this doesn't apply, it
;; shouldn't cause any problems, it just won't
;; look as pretty.
((or "" ":" 'nil) "[Other]")
(_ (s-chop-suffix ":" group-type)))
do (magit-todos--insert-groups
:depth (1+ depth) :group-fns (cdr group-fns)
:type (intern group-name) :items items
:heading (concat
(if (and magit-todos-fontify-keyword-headers
(member group-name magit-todos-keywords-list))
(let ((face (magit-todos--keyword-face group-name)))
(propertize group-name 'face face 'font-lock-face face))
group-name)
;; Item count
(if (= 1 (length group-fns))
":" ; Let Magit add the count.
;; Add count ourselves.
(concat " " (format "(%s)" (length items)))))))
(when (= 0 depth)
;; Insert a blank line only in the body of the top-level section, so it
;; will appear only when the section is expanded, matching other sections.
(insert "\n")))))
(magit-todos--set-visibility :depth depth :num-items (length items) :section section)
;; Add top-level section to root section's children
(when (= 0 depth)
(push section (oref magit-root-section children)))
;; Don't forget to return the section!
section)
;; Insert individual to-do items
(magit-todos--insert-group :depth (1+ depth) :type type :items items :heading heading))))