magit-insert-headers: don't assume headers come first
Previously a function that uses `magit-insert-headers' had to be
the first function on a section hook. Now it can anywhere on a
hook, which allows inserting multiple separate groups of headers,
or to display some other information first.
Jonas Bernoulli
6 years ago
785 | 785 | (magit-maybe-make-margin-overlay) |
786 | 786 | (setf (magit-section-content magit-insert-section--current) (point-marker))) |
787 | 787 | |
788 | (defvar magit-insert-headers-hook nil "For internal use only.") | |
788 | (defvar magit-insert-headers--hook nil "For internal use only.") | |
789 | (defvar magit-insert-headers--beginning nil "For internal use only.") | |
789 | 790 | |
790 | 791 | (defun magit-insert-headers (hooks) |
791 | 792 | (let ((magit-insert-section-hook |
793 | 794 | (if (listp magit-insert-section-hook) |
794 | 795 | magit-insert-section-hook |
795 | 796 | (list magit-insert-section-hook)))) |
796 | (magit-insert-headers-hook hooks) | |
797 | (magit-insert-headers--hook hooks) | |
797 | 798 | wrapper) |
798 | (while (and (setq wrapper (pop magit-insert-headers-hook)) | |
799 | (= (point) (point-min))) | |
799 | (setq magit-insert-headers--beginning (point)) | |
800 | (while (and (setq wrapper (pop magit-insert-headers--hook)) | |
801 | (= (point) magit-insert-headers--beginning)) | |
800 | 802 | (funcall wrapper)))) |
801 | 803 | |
802 | 804 | (defun magit-insert-remaining-headers () |
803 | (if (= (point) (point-min)) | |
805 | (if (= (point) magit-insert-headers--beginning) | |
804 | 806 | (magit-cancel-section) |
805 | 807 | (magit-insert-heading) |
806 | 808 | (remove-hook 'magit-insert-section-hook 'magit-insert-remaining-headers) |
807 | (mapc #'funcall magit-insert-headers-hook) | |
809 | (mapc #'funcall magit-insert-headers--hook) | |
808 | 810 | (insert "\n"))) |
809 | 811 | |
810 | 812 | (defun magit-insert-child-count (section) |