|
| 1 | +;;; git-dired.el --- Hacks to dired for it to play nicer with Git |
| 2 | + |
| 3 | +;; Copyright (C) 2008-2009 John Wiegley <johnw@newartisans.com> |
| 4 | + |
| 5 | +;; Emacs Lisp Archive Entry |
| 6 | +;; Filename: git-dired.el |
| 7 | +;; Version: 1.0 |
| 8 | +;; Keywords: git dvcs vc |
| 9 | +;; Author: John Wiegley <johnw@newartisans.com> |
| 10 | +;; Maintainer: John Wiegley <johnw@newartisans.com> |
| 11 | +;; Description: Hacks to dired for it to play nicer with Git |
| 12 | +;; URL: http://github.com/jwiegley/git-scripts/tree/master |
| 13 | +;; Compatibility: Emacs22, Emacs23 |
| 14 | + |
| 15 | +;; This file is not part of GNU Emacs. |
| 16 | + |
| 17 | +;; This is free software; you can redistribute it and/or modify it under |
| 18 | +;; the terms of the GNU General Public License as published by the Free |
| 19 | +;; Software Foundation; either version 2, or (at your option) any later |
| 20 | +;; version. |
| 21 | +;; |
| 22 | +;; This is distributed in the hope that it will be useful, but WITHOUT |
| 23 | +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 24 | +;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 25 | +;; for more details. |
| 26 | +;; |
| 27 | +;; You should have received a copy of the GNU General Public License |
| 28 | +;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 29 | +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 30 | +;; MA 02111-1307, USA. |
| 31 | + |
| 32 | +;;; Commentary: |
| 33 | + |
| 34 | +(eval-after-load "dired-x" |
| 35 | + '(progn |
| 36 | + (defvar dired-omit-regexp-orig (symbol-function 'dired-omit-regexp)) |
| 37 | + |
| 38 | + (defun dired-omit-regexp () |
| 39 | + (let ((file (expand-file-name ".git")) |
| 40 | + parent-dir) |
| 41 | + (while (and (not (file-exists-p file)) |
| 42 | + (progn |
| 43 | + (setq parent-dir |
| 44 | + (file-name-directory |
| 45 | + (directory-file-name |
| 46 | + (file-name-directory file)))) |
| 47 | + ;; Give up if we are already at the root dir. |
| 48 | + (not (string= (file-name-directory file) |
| 49 | + parent-dir)))) |
| 50 | + ;; Move up to the parent dir and try again. |
| 51 | + (setq file (expand-file-name ".git" parent-dir))) |
| 52 | + ;; If we found a change log in a parent, use that. |
| 53 | + (if (file-exists-p file) |
| 54 | + (let ((regexp (funcall dired-omit-regexp-orig)) |
| 55 | + (omitted-files (shell-command-to-string |
| 56 | + "git clean -d -x -n"))) |
| 57 | + (if (= 0 (length omitted-files)) |
| 58 | + regexp |
| 59 | + (concat |
| 60 | + regexp |
| 61 | + (if (> (length regexp) 0) |
| 62 | + "\\|" "") |
| 63 | + "\\(" |
| 64 | + (mapconcat |
| 65 | + #'(lambda (str) |
| 66 | + (concat "^" |
| 67 | + (regexp-quote |
| 68 | + (substring str 13 |
| 69 | + (if (= ?/ (aref str (1- (length str)))) |
| 70 | + (1- (length str)) |
| 71 | + nil))) |
| 72 | + "$")) |
| 73 | + (split-string omitted-files "\n" t) |
| 74 | + "\\|") |
| 75 | + "\\)"))) |
| 76 | + (funcall dired-omit-regexp-orig)))) |
| 77 | + |
| 78 | + (defun dired-delete-file (file &optional recursive) |
| 79 | + (if recursive |
| 80 | + (call-process "/Users/johnw/bin/del" nil nil nil "-fr" file) |
| 81 | + (call-process "/Users/johnw/bin/del" nil nil nil file))))) |
| 82 | + |
| 83 | +(provide 'git-dired) |
| 84 | + |
| 85 | +;;; git-dired.el ends here |
0 commit comments