Cleaned up section creation a bit.

* magit.el (magit-section-hidden-default): New.
(magit-new-section): Only expect type as argument, not a general list
of slots.  Take 'hidden' value from magit-section-hidden-default.
(magit-with-section): Likewise.
(magit-wash-diff): Adapted.
This commit is contained in:
Marius Vollmer 2009-01-25 00:39:03 +02:00
parent 583ecc7a12
commit a6bc339e9c

119
magit.el
View file

@ -384,11 +384,13 @@ Many Magit faces inherit from this one by default."
(defvar magit-old-top-section nil) (defvar magit-old-top-section nil)
(defun magit-new-section (title &rest args) (defvar magit-section-hidden-default nil)
(let* ((s (apply #'make-magit-section
:parent magit-top-section (defun magit-new-section (title type)
:title title (let* ((s (make-magit-section :parent magit-top-section
args)) :title title
:type type
:hidden magit-section-hidden-default))
(old (and magit-old-top-section (old (and magit-old-top-section
(magit-find-section (magit-section-path s) (magit-find-section (magit-section-path s)
magit-old-top-section)))) magit-old-top-section))))
@ -409,13 +411,10 @@ Many Magit faces inherit from this one by default."
(delq section (magit-section-children parent))) (delq section (magit-section-children parent)))
(setq magit-top-section nil)))) (setq magit-top-section nil))))
(defmacro magit-with-section (title args &rest body) (defmacro magit-with-section (title type &rest body)
(declare (indent 2)) (declare (indent 2))
(let ((s (gensym))) (let ((s (gensym)))
`(let* ((,s (magit-new-section ,title ,@(if (and (listp args) `(let* ((,s (magit-new-section ,title ,type))
(keywordp (car args)))
args
`(:type ,args))))
(magit-top-section ,s)) (magit-top-section ,s))
(setf (magit-section-beginning ,s) (point)) (setf (magit-section-beginning ,s) (point))
,@body ,@body
@ -1211,56 +1210,56 @@ Please see the manual for a complete description of Magit.
(defun magit-wash-diff () (defun magit-wash-diff ()
(cond ((looking-at "^diff") (cond ((looking-at "^diff")
(magit-with-section (let ((magit-section-hidden-default magit-hide-diffs))
(magit-current-line) (magit-with-section (magit-current-line) 'diff
(:type 'diff :hidden magit-hide-diffs) (let ((file (magit-diff-line-file))
(let ((file (magit-diff-line-file)) (end (save-excursion
(end (save-excursion (forward-line) ;; skip over "diff" line
(forward-line) ;; skip over "diff" line (if (search-forward-regexp "^diff\\|^@@" nil t)
(if (search-forward-regexp "^diff\\|^@@" nil t) (goto-char (match-beginning 0))
(goto-char (match-beginning 0)) (goto-char (point-max)))
(goto-char (point-max))) (point-marker))))
(point-marker)))) (let* ((status (cond
(let* ((status (cond ((looking-at "^diff --cc")
((looking-at "^diff --cc") 'unmerged)
'unmerged) ((save-excursion
((save-excursion (search-forward-regexp "^new" end t))
(search-forward-regexp "^new" end t)) 'new)
'new) ((save-excursion
((save-excursion (search-forward-regexp "^deleted" end t))
(search-forward-regexp "^deleted" end t)) 'deleted)
'deleted) ((save-excursion
((save-excursion (search-forward-regexp "^rename" end t))
(search-forward-regexp "^rename" end t)) 'renamed)
'renamed) (t
(t 'modified)))
'modified))) (file2 (cond
(file2 (cond ((save-excursion
((save-excursion (search-forward-regexp "^rename from \\(.*\\)"
(search-forward-regexp "^rename from \\(.*\\)" end t))
end t)) (match-string-no-properties 1))))
(match-string-no-properties 1)))) (status-text (case status
(status-text (case status ((unmerged)
((unmerged) (format "Unmerged %s" file))
(format "Unmerged %s" file)) ((new)
((new) (format "New %s" file))
(format "New %s" file)) ((deleted)
((deleted) (format "Deleted %s" file))
(format "Deleted %s" file)) ((renamed)
((renamed) (format "Renamed %s (from %s)"
(format "Renamed %s (from %s)" file file2))
file file2)) ((modified)
((modified) (format "Modified %s" file))
(format "Modified %s" file)) (
( (format "? %s" file)))))
(format "? %s" file))))) (magit-set-section-info (list status file file2))
(magit-set-section-info (list status file file2)) (insert "\t" status-text "\n")
(insert "\t" status-text "\n") (goto-char end)
(goto-char end) (let ((magit-section-hidden-default nil))
(magit-wash-sequence #'magit-wash-hunk) (magit-wash-sequence #'magit-wash-hunk))
t)))) t)))))
(t (t
nil))) nil)))
(defun magit-diff-item-kind (diff) (defun magit-diff-item-kind (diff)
(car (magit-section-info diff))) (car (magit-section-info diff)))