diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2025-05-18 08:53:23 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2025-05-18 08:53:23 +0200 |
| commit | bd7b7f143c006f698e6e3d1901d1948eb78eddf6 (patch) | |
| tree | 7a0a9530f83af603fda8f7dd7aead221317b7d45 /lisp | |
| parent | 2b293e69f9c351f9d8d518a25621e0295bb7f226 (diff) | |
magit-focused-sections: New function
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/magit-section.el | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lisp/magit-section.el b/lisp/magit-section.el index 87d16fc..9410d86 100644 --- a/lisp/magit-section.el +++ b/lisp/magit-section.el @@ -308,6 +308,7 @@ no effect. This also has no effect for Emacs >= 28, where (defvar-local magit-section-highlight-overlays nil) (defvar-local magit-section-highlighted-sections nil) (defvar-local magit-section-unhighlight-sections nil) +(defvar-local magit-section-focused-sections nil) (defvar-local magit-section-inhibit-markers nil) (defvar-local magit-section-insert-in-reverse nil) @@ -1684,7 +1685,8 @@ evaluated its BODY. Admittedly that's a bit of a hack." ;; updated afterwards. (magit-menu-highlight-point-section)) (setq magit-section-pre-command-region-p (region-active-p)) - (setq magit-section-pre-command-section (magit-current-section))) + (setq magit-section-pre-command-section (magit-current-section)) + (setq magit-section-focused-sections nil)) (defun magit-section-post-command-hook () (let ((window (selected-window))) @@ -2046,6 +2048,23 @@ excluding SECTION itself." ('next (cdr (member section siblings))) (_ (remq section siblings))))) +(defun magit-focused-sections () + "Return a list of the selected sections and all their descendants. +If no sections are selected return a list of the current section and +its descendants, except if that is the root section, in which case +return nil." + (or magit-section-focused-sections + (setq magit-section-focused-sections + (let ((current (magit-current-section))) + (and (not (eq current magit-root-section)) + (let (sections) + (letrec ((collect (lambda (section) + (mapc collect (oref section children)) + (push section sections)))) + (mapc collect + (or (magit-region-sections) (list current)))) + sections)))))) + (defun magit-region-values (&optional condition multiple) "Return a list of the values of the selected sections. |
