git.el: Allow selecting whether to display uptodate/unknown/ignored files.
The default behavior for each state can be customized, and it can also be toggled directly from the status buffer. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alexandre Julliard committed
Sep 13, 2007 at 11:50 UTC
98acc3fabc2d197525f1b0119382a00a664014b7
1 file changed
+77
-15
contrib/emacs/git.el
+77
-15
@@ -97,6 +97,21 @@ if there is already one that displays the same directory."
97
:group 'git
98
:type 'string)
99
100
+(defcustom git-show-uptodate nil
101
+ "Whether to display up-to-date files."
102
+ :group 'git
103
+ :type 'boolean)
104
+
105
+(defcustom git-show-ignored nil
106
+ "Whether to display ignored files."
107
+ :group 'git
108
+ :type 'boolean)
109
+
110
+(defcustom git-show-unknown t
111
+ "Whether to display unknown files."
112
+ :group 'git
113
+ :type 'boolean)
114
+
115
116
(defface git-status-face
117
'((((class color) (background light)) (:foreground "purple"))
@@ -646,23 +661,30 @@ Return the list of files that haven't been handled."
661
(push config files))
662
files))
663
664
+(defun git-run-ls-files-with-excludes (status files default-state &rest options)
665
+ "Run git-ls-files on FILES with appropriate --exclude-from options."
666
+ (let ((exclude-files (git-get-exclude-files)))
667
+ (apply #'git-run-ls-files status files default-state
668
+ (concat "--exclude-per-directory=" git-per-dir-ignore-file)
669
+ (append options (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
670
+
671
(defun git-update-status-files (files &optional default-state)
672
"Update the status of FILES from the index."
673
(unless git-status (error "Not in git-status buffer."))
652
- (let* ((status git-status)
653
- (remaining-files
674
+ (unless files
675
+ (when git-show-uptodate (git-run-ls-files git-status nil 'uptodate "-c")))
676
+ (let* ((remaining-files
677
(if (git-empty-db-p) ; we need some special handling for an empty db
655
- (git-run-ls-files status files 'added "-c")
656
- (git-run-diff-index status files))))
657
- (git-run-ls-unmerged status files)
658
- (when (or (not files) remaining-files)
659
- (let ((exclude-files (git-get-exclude-files)))
660
- (setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o"
661
- (concat "--exclude-per-directory=" git-per-dir-ignore-file)
662
- (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files)))))
663
- (git-set-filenames-state status remaining-files default-state)
678
+ (git-run-ls-files git-status files 'added "-c")
679
+ (git-run-diff-index git-status files))))
680
+ (git-run-ls-unmerged git-status files)
681
+ (when (or remaining-files (and git-show-unknown (not files)))
682
+ (setq remaining-files (git-run-ls-files-with-excludes git-status remaining-files 'unknown "-o")))
683
+ (when (or remaining-files (and git-show-ignored (not files)))
684
+ (setq remaining-files (git-run-ls-files-with-excludes git-status remaining-files 'ignored "-o" "-i")))
685
+ (git-set-filenames-state git-status remaining-files default-state)
686
(git-refresh-files)
665
- (git-refresh-ewoc-hf status)))
687
+ (git-refresh-ewoc-hf git-status)))
688
689
(defun git-marked-files ()
690
"Return a list of all marked files, or if none a list containing just the file at cursor position."
@@ -943,11 +965,41 @@ Return the list of files that haven't been handled."
965
(interactive)
966
(ewoc-filter git-status
967
(lambda (info)
946
- (not (or (eq (git-fileinfo->state info) 'ignored)
947
- (eq (git-fileinfo->state info) 'uptodate)))))
968
+ (case (git-fileinfo->state info)
969
+ ('ignored git-show-ignored)
970
+ ('uptodate git-show-uptodate)
971
+ ('unknown git-show-unknown)
972
+ (t t))))
973
(unless (ewoc-nth git-status 0) ; refresh header if list is empty
974
(git-refresh-ewoc-hf git-status)))
975
976
+(defun git-toggle-show-uptodate ()
977
+ "Toogle the option for showing up-to-date files."
978
+ (interactive)
979
+ (if (setq git-show-uptodate (not git-show-uptodate))
980
+ (git-refresh-status)
981
+ (git-remove-handled)))
982
+
983
+(defun git-toggle-show-ignored ()
984
+ "Toogle the option for showing ignored files."
985
+ (interactive)
986
+ (if (setq git-show-ignored (not git-show-ignored))
987
+ (progn
988
+ (git-run-ls-files-with-excludes git-status nil 'ignored "-o" "-i")
989
+ (git-refresh-files)
990
+ (git-refresh-ewoc-hf git-status))
991
+ (git-remove-handled)))
992
+
993
+(defun git-toggle-show-unknown ()
994
+ "Toogle the option for showing unknown files."
995
+ (interactive)
996
+ (if (setq git-show-unknown (not git-show-unknown))
997
+ (progn
998
+ (git-run-ls-files-with-excludes git-status nil 'unknown "-o")
999
+ (git-refresh-files)
1000
+ (git-refresh-ewoc-hf git-status))
1001
+ (git-remove-handled)))
1002
+
1003
(defun git-setup-diff-buffer (buffer)
1004
"Setup a buffer for displaying a diff."
1005
(let ((dir default-directory))
@@ -1173,7 +1225,8 @@ Return the list of files that haven't been handled."
1225
1226
(unless git-status-mode-map
1227
(let ((map (make-keymap))
1176
- (diff-map (make-sparse-keymap)))
1228
+ (diff-map (make-sparse-keymap))
1229
+ (toggle-map (make-sparse-keymap)))
1230
(suppress-keymap map)
1231
(define-key map "?" 'git-help)
1232
(define-key map "h" 'git-help)
@@ -1197,6 +1250,7 @@ Return the list of files that haven't been handled."
1250
(define-key map "q" 'git-status-quit)
1251
(define-key map "r" 'git-remove-file)
1252
(define-key map "R" 'git-resolve-file)
1253
+ (define-key map "t" toggle-map)
1254
(define-key map "T" 'git-toggle-all-marks)
1255
(define-key map "u" 'git-unmark-file)
1256
(define-key map "U" 'git-revert-file)
@@ -1213,6 +1267,11 @@ Return the list of files that haven't been handled."
1267
(define-key diff-map "h" 'git-diff-file-merge-head)
1268
(define-key diff-map "m" 'git-diff-file-mine)
1269
(define-key diff-map "o" 'git-diff-file-other)
1270
+ ; the toggle submap
1271
+ (define-key toggle-map "u" 'git-toggle-show-uptodate)
1272
+ (define-key toggle-map "i" 'git-toggle-show-ignored)
1273
+ (define-key toggle-map "k" 'git-toggle-show-unknown)
1274
+ (define-key toggle-map "m" 'git-toggle-all-marks)
1275
(setq git-status-mode-map map)))
1276
1277
;; git mode should only run in the *git status* buffer
@@ -1234,6 +1293,9 @@ Commands:
1293
(let ((status (ewoc-create 'git-fileinfo-prettyprint "" "")))
1294
(set (make-local-variable 'git-status) status))
1295
(set (make-local-variable 'list-buffers-directory) default-directory)
1296
+ (make-local-variable 'git-show-uptodate)
1297
+ (make-local-variable 'git-show-ignored)
1298
+ (make-local-variable 'git-show-unknown)
1299
(run-hooks 'git-status-mode-hook)))
1300
1301
(defun git-find-status-buffer (dir)