Automatically collapse big "Changes" sections.

* magit.el (magit-collapse-threshold): New.
(magit-insert-section): Take threshold argument.  Updated all callers.
This commit is contained in:
Marius Vollmer 2008-08-31 20:04:02 +03:00
parent 05174053c5
commit db06a91204

View file

@ -51,6 +51,11 @@
:prefix "magit-" :prefix "magit-"
:group 'tools) :group 'tools)
(defcustom magit-collapse-threshold 50
"Sections with more lines than this are collapsed automatically."
:group 'magit
:type '(integer))
(defface magit-header (defface magit-header
'((t)) '((t))
"Face for generic header lines. "Face for generic header lines.
@ -461,7 +466,7 @@ Many Magit faces inherit from this one by default."
'visible)))) 'visible))))
(magit-section-set-visibility (point) state))) (magit-section-set-visibility (point) state)))
(defun magit-insert-section (id title washer cmd &rest args) (defun magit-insert-section (id title washer threshold cmd &rest args)
(let ((chapter-beg (point))) (let ((chapter-beg (point)))
(if title (if title
(insert (propertize title 'face 'magit-section-title) "\n")) (insert (propertize title 'face 'magit-section-title) "\n"))
@ -475,7 +480,10 @@ Many Magit faces inherit from this one by default."
(funcall washer status)) (funcall washer status))
(goto-char (point-max)))) (goto-char (point-max))))
(if (/= beg (point)) (if (/= beg (point))
(insert "\n") (let ((lines (count-lines beg (point))))
(insert "\n")
(if (and threshold (> lines threshold))
(magit-section-set-visibility chapter-beg 'collapsed)))
(delete-region chapter-beg (point)))))) (delete-region chapter-beg (point))))))
(defun magit-next-section () (defun magit-next-section ()
@ -777,19 +785,23 @@ Please see the manual for a complete description of Magit.
(insert "\n") (insert "\n")
(magit-insert-section 'untracked (magit-insert-section 'untracked
"Untracked files:" 'magit-wash-untracked-files "Untracked files:" 'magit-wash-untracked-files
nil
"git" "ls-files" "--others" "--exclude-standard") "git" "ls-files" "--others" "--exclude-standard")
(let ((staged (magit-anything-staged-p))) (let ((staged (magit-anything-staged-p)))
(magit-insert-section 'unstaged (magit-insert-section 'unstaged
(if staged "Unstaged changes:" "Changes:") (if staged "Unstaged changes:" "Changes:")
'magit-wash-diff 'magit-wash-diff
magit-collapse-threshold
"git" "diff") "git" "diff")
(if staged (if staged
(magit-insert-section 'staged (magit-insert-section 'staged
"Staged changes:" 'magit-wash-diff "Staged changes:" 'magit-wash-diff
magit-collapse-threshold
"git" "diff" "--cached"))) "git" "diff" "--cached")))
(if remote (if remote
(magit-insert-section 'unpushed (magit-insert-section 'unpushed
"Unpushed commits:" 'magit-wash-log "Unpushed commits:" 'magit-wash-log
nil
"git" "log" "--graph" "--pretty=oneline" "git" "log" "--graph" "--pretty=oneline"
(format "%s/%s..HEAD" remote branch)))) (format "%s/%s..HEAD" remote branch))))
(magit-goto-line old-line) (magit-goto-line old-line)
@ -1238,7 +1250,7 @@ Please see the manual for a complete description of Magit.
(magit-mode-init dir 'commit) (magit-mode-init dir 'commit)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(erase-buffer) (erase-buffer)
(magit-insert-section 'commit nil 'magit-wash-diff (magit-insert-section 'commit nil 'magit-wash-diff nil
"git" "log" "--max-count=1" "--cc" "-p" "git" "log" "--max-count=1" "--cc" "-p"
commit))))))) commit)))))))
@ -1272,7 +1284,7 @@ Please see the manual for a complete description of Magit.
(erase-buffer) (erase-buffer)
(magit-insert-section 'history (magit-insert-section 'history
(magit-rev-range-describe range "Commits") (magit-rev-range-describe range "Commits")
'magit-wash-log 'magit-wash-log nil
"git" "log" "--graph" "--max-count=10000" "git" "log" "--graph" "--max-count=10000"
"--pretty=oneline" args))) "--pretty=oneline" args)))
(magit-refresh-marks-in-buffer (current-buffer))))) (magit-refresh-marks-in-buffer (current-buffer)))))
@ -1295,7 +1307,7 @@ Please see the manual for a complete description of Magit.
(erase-buffer) (erase-buffer)
(magit-insert-section 'reflog (magit-insert-section 'reflog
(format "Local history of head %s" head) (format "Local history of head %s" head)
'magit-wash-log 'magit-wash-log nil
"git" "log" "--walk-reflogs" "git" "log" "--walk-reflogs"
"--max-count=10000" "--max-count=10000"
"--pretty=oneline" args))) "--pretty=oneline" args)))
@ -1321,7 +1333,7 @@ Please see the manual for a complete description of Magit.
(erase-buffer) (erase-buffer)
(magit-insert-section 'diff (magit-insert-section 'diff
(magit-rev-range-describe range "Changes") (magit-rev-range-describe range "Changes")
'magit-wash-diff 'magit-wash-diff nil
"git" "diff" args)))))) "git" "diff" args))))))
(defun magit-diff-working-tree (rev) (defun magit-diff-working-tree (rev)