emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit d1a3c60a9e 4/7: sparse-checkout: Add insert-hea


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit d1a3c60a9e 4/7: sparse-checkout: Add insert-header function
Date: Sun, 23 Jan 2022 16:58:07 -0500 (EST)

branch: elpa/git-commit
commit d1a3c60a9eee28c4678d81aef93392c3283ddc22
Author: Kyle Meyer <kyle@kyleam.com>
Commit: Kyle Meyer <kyle@kyleam.com>

    sparse-checkout: Add insert-header function
    
    It's useful to have some indication that you're in a sparse checkout.
    Add a function that inserts a header similar in style to the "Filter!"
    header inserted by magit-insert-diff-filter-header.
    
    It may end up being useful to add this to magit-status-headers-hook by
    default, in which case we'll probably need to rework where things are
    defined.  But for now, just add the function and let interested users
    add it to magit-status-headers-hook.
---
 docs/magit.org                |  4 ++++
 lisp/magit-sparse-checkout.el | 17 +++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/docs/magit.org b/docs/magit.org
index da53f5c756..a1c766c001 100644
--- a/docs/magit.org
+++ b/docs/magit.org
@@ -7045,6 +7045,10 @@ version.
   This command restores the full checkout.  To return to the previous
   sparse checkout, call ~magit-sparse-checkout-enable~.
 
+If you want the status buffer to indicate when a sparse checkout is
+enabled, add the function ~magit-sparse-checkout-insert-header~ to
+~magit-status-headers-hook~.
+
 ** Bundle
 
 Also see [[man:git-bundle]]
diff --git a/lisp/magit-sparse-checkout.el b/lisp/magit-sparse-checkout.el
index f029756f54..0a2c6c4e21 100644
--- a/lisp/magit-sparse-checkout.el
+++ b/lisp/magit-sparse-checkout.el
@@ -151,6 +151,23 @@ restore the previous sparse checkout."
   (magit-sparse-checkout--assert-version)
   (magit-run-git-async "sparse-checkout" "disable"))
 
+;;; Miscellaneous
+
+(defun magit-sparse-checkout-insert-header ()
+  "Insert header line with sparse checkout information.
+This header is not inserted by default.  To enable it, add it to
+`magit-status-headers-hook'."
+  (when (magit-sparse-checkout-enabled-p)
+    (insert (propertize (format "%-10s" "Sparse! ")
+                        'font-lock-face 'magit-section-heading))
+    (insert
+     (let ((dirs (magit-sparse-checkout-directories)))
+       (pcase (length dirs)
+         (0 "top-level directory")
+         (1 (car dirs))
+         (n (format "%d directories" n)))))
+    (insert ?\n)))
+
 ;;; _
 (provide 'magit-sparse-checkout)
 ;;; magit-sparse-checkout.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]