branch: elpa/magit commit f6f25e6566592934f61834abab795bd3de2665e4 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
magit-insert-section-body: Set section properties on delayed insertion Often when `magit-insert-section-body' is used, the section body consists of a list of child section, followed by an empty line belonging to the list section. On delayed insertion of the body we did not set the properties of that empty line. Split out `magit--set-section-properties' from `magit-insert-section--finish', so that we can use it in `magit-insert-section-body' as well. --- lisp/magit-section.el | 85 ++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/lisp/magit-section.el b/lisp/magit-section.el index 572f401c4c..6bf93ea094 100644 --- a/lisp/magit-section.el +++ b/lisp/magit-section.el @@ -1447,47 +1447,33 @@ anything this time around. (defun magit-insert-section--finish (obj) (run-hooks 'magit-insert-section-hook) - (let ((beg (oref obj start)) - (end (oset obj end - (if magit-section-inhibit-markers - (point) - (point-marker)))) - (props `( magit-section ,obj - ,@(and-let* ((map (symbol-value (oref obj keymap)))) - (list 'keymap map))))) - (unless magit-section-inhibit-markers - (set-marker-insertion-type beg t)) - (cond ((eq obj magit-root-section)) - ((oref obj children) - (magit-insert-child-count obj) - (magit-section-maybe-add-heading-map obj) - (save-excursion - (goto-char beg) - (while (< (point) end) - (let ((next (or (next-single-property-change - (point) 'magit-section) - end))) - (unless (magit-section-at) - (add-text-properties (point) next props)) - (goto-char next))))) - ((add-text-properties beg end props))) - (cond ((eq obj magit-root-section) - (when (eq magit-section-inhibit-markers 'delay) - (setq magit-section-inhibit-markers nil) - (magit-map-sections - (lambda (section) - (oset section start (copy-marker (oref section start) t)) - (oset section end (copy-marker (oref section end) t))))) - (let ((magit-section-cache-visibility nil)) - (magit-section-show obj))) - (magit-section-insert-in-reverse - (push obj (oref (oref obj parent) children))) - ((let ((parent (oref obj parent))) - (oset parent children - (nconc (oref parent children) - (list obj)))))) - (when magit-section-insert-in-reverse - (oset obj children (nreverse (oref obj children)))))) + (if magit-section-inhibit-markers + (oset obj end (point)) + (oset obj end (point-marker)) + (set-marker-insertion-type (oref obj start) t)) + (cond + ((eq obj magit-root-section) + (when (eq magit-section-inhibit-markers 'delay) + (setq magit-section-inhibit-markers nil) + (magit-map-sections + (lambda (section) + (oset section start (copy-marker (oref section start) t)) + (oset section end (copy-marker (oref section end) t))))) + (let ((magit-section-cache-visibility nil)) + (magit-section-show obj))) + (t + (when (oref obj children) + (magit-insert-child-count obj) + (magit-section-maybe-add-heading-map obj)) + (magit-section--set-section-properties obj) + (if magit-section-insert-in-reverse + (push obj (oref (oref obj parent) children)) + (let ((parent (oref obj parent))) + (oset parent children + (nconc (oref parent children) + (list obj))))))) + (when magit-section-insert-in-reverse + (oset obj children (nreverse (oref obj children))))) (defun magit-cancel-section (&optional if-empty) "Cancel inserting the section that is currently being inserted. @@ -1587,6 +1573,7 @@ is explicitly expanded." (funcall ,f) (dolist (s ,l) (set-marker-insertion-type (oref s end) nil)) + (magit-section--set-section-properties ,s) (magit-section-maybe-remove-heading-map ,s) (magit-section-maybe-remove-visibility-indicator ,s))))) (funcall ,f))))) @@ -1614,6 +1601,22 @@ is explicitly expanded." (magit-section-maybe-add-heading-map 1st-header))))) (remove-hook 'magit-insert-section-hook fn t)))) +(defun magit-section--set-section-properties (section) + (pcase-let* (((eieio start end children keymap) section) + (props `( magit-section ,section + ,@(and-let* ((map (symbol-value keymap))) + (list 'keymap map))))) + (if children + (save-excursion + (goto-char start) + (while (< (point) end) + (let ((next (or (next-single-property-change (point) 'magit-section) + end))) + (unless (magit-section-at) + (add-text-properties (point) next props)) + (goto-char next)))) + (add-text-properties start end props)))) + (defun magit-section-maybe-add-heading-map (section) (when (magit-section-content-p section) (let ((start (oref section start))