10

I'm particularly concerned with git, but I imagine this is a good place to use vc. I want to emulate Atom's git integration with its file explorer:

atom-git-integration

How can I get something like this in dired? I understand there are other tools for simulating a proper tree structure, but the normal i/RET workflow should work just fine.

Sean Allred
  • 6,861
  • 16
  • 85
  • Just to clarify (since I'm not familiar with Atom): Green would be untracked/new files. Dark Grey is files in `.gitignore`, light grey is up-to-date and orange is modified? – Jonathan Leech-Pepin Feb 23 '15 at 19:52
  • @JonathanLeech-Pepin That's what is pictured, but faces are easy enough to `M-x customize` :) – Sean Allred Feb 23 '15 at 19:53
  • @JonathanLeech-Pepin I don't use Atom myself so I don't know if even *it* does this, but it would really neat if dired knew when things had been deleted in the work tree. – Sean Allred Feb 23 '15 at 20:00
  • 1
    I'm guessing this will need to end up being a `dired-vc` package that adjusts the faces of the files. Google doesn't seem to come up with anything. -> `dired-after-readin-hook` looks like an entry point for it (each listing is narrowed to after reading). – Jonathan Leech-Pepin Feb 23 '15 at 20:04
  • @JonathanLeech-Pepin After a bit of play, I think the trick will be parsing out the actual file names from that listing. (Note that `(buffer-string)` is effectively the entire output of `ls`.) Could potentially use `dired-get-filename`. – Sean Allred Feb 23 '15 at 20:14
  • It's funny, the hook says it runs narrowed, but the `.el` file says run unnarrowed because you don't need to narrow. – Jonathan Leech-Pepin Feb 23 '15 at 20:23
  • @JonathanLeech-Pepin It will at any rate be narrowed to the current directory listing – might be useful when inserting directories. But then again, the ability to refresh the tree's status would be good – might *have* to be done all-together. – Sean Allred Feb 23 '15 at 20:25
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/21383/discussion-between-jonathan-leech-pepin-and-sean-allred). – Jonathan Leech-Pepin Feb 23 '15 at 20:26
  • 1
    A simple way is to use `M-x vc-dir`. It isn't quite the same as dired but it's pretty nice anyway. If you really want VC on dired, I think the only option is to write elisp to do it. Maybe not super hard since VC can already provide the information you need. – Tom Tromey Feb 24 '15 at 14:21
  • @TomTromey It doesn't seem that `vc-dir` will display unchanged files. While I apropos for a controlling variable, do you know if there is one? – Sean Allred Feb 24 '15 at 14:22
  • I looked but didn't immediately see one, sorry. – Tom Tromey Feb 24 '15 at 14:25
  • It looks like `vc-dir.el:1282` is responsible for highlighting entries, but it looks like the function doesn't even get called. – Sean Allred Feb 24 '15 at 14:26
  • One could modify `vc-dir.el:1110` to do this, but @TomTromey is right: there is no actual toggle. – Sean Allred Feb 24 '15 at 14:31
  • See also [this pull request](https://github.com/jaypei/emacs-neotree/pull/93) for Neotree. – Sean Allred Mar 23 '15 at 02:21

3 Answers3

9

You can install diff-hl from GNU ELPA and add the following to your init file:

(add-hook 'dired-mode-hook 'diff-hl-dired-mode)

But it doesn't color the lines. Instead, it shows statuses in the fringe (or the margin, if diff-hl-margin-mode is on). Looks like this:

enter image description here

Dmitry
  • 3,508
  • 15
  • 20
  • Woah! Also, sorry! I checked back here [almost by accident](http://redd.it/2zt08q) :) I'll give this a go today and see if it can be modified to suit my needs. In the event that I can get something working, would you mind if I edited the necessary patches into your answer so it can be complete? – Sean Allred Mar 21 '15 at 13:58
  • @SeanAllred Sure, as long as the added code uses the public functionality, and does not redefine any of the functions. In case you find you absolutely need that, better file a feature request. – Dmitry Mar 21 '15 at 17:58
  • Naturally :) Though I will note that 'public functionality' is difficult to determine in emacs lisp :) – Sean Allred Mar 21 '15 at 18:01
  • 1
    @SeanAllred Well, vars and hook in this case, I guess. :) – Dmitry Mar 21 '15 at 18:14
  • I'm accepting this because it answers the question I asked as written, but future readers should note the [additional answer](http://emacs.stackexchange.com/a/10931/2264) I provided for neotree's new support of this. – Sean Allred Apr 29 '15 at 16:26
2

Not actually dired-based, but it is closer to the Atom screenshot provided. As of PR#93, neotree can display VCS status as part of the listing:

screenshot

Here is the configuration that would effect the screenshot above:

(setq neo-vc-integration '(char face))

The presence of char controls the ? and E that you see. The presence of face controls the highlighting.

Sean Allred
  • 6,861
  • 16
  • 85
2

This is an 'incomplete' set of elisp that will provide the feature set. Implementing a full list is left as an exercise (and/or as a full package to develop dired-vc (time-permitting)) for the reader.

Steps to complete the below with missing information:

  1. Obtain a list of all symbols returned by vc-state
  2. Define faces (defface) for each missing symbol
  3. Adjust the cond block to include all those symbols
(defun dired-fontify-vc ()
  (while (not (eobp))
    (let* ((inhibit-read-only t)
           (file (ignore-errors (file-name-nondirectory
                                 (dired-get-filename))))
           (state (ignore-errors (vc-state file))))
      (when (and file
                 state)
        ; (message "%s>%s" file state)
        (let ((beg (dired-move-to-filename))
              (end (dired-move-to-end-of-filename)))
          (cond
           ((eq state 'edited)
            (add-text-properties beg end '(font-lock-face edited-face)))
           ((eq state 'up-to-date)
            (add-text-properties beg end '(font-lock-face update-face)))))
        ))
    (dired-next-line 1)))

(add-hook 'dired-after-readin-hook 'dired-fontify-vc)

(defface edited-face
  '((t :foreground "orange"))
  "Foreground color for edited files")
(defface update-face
  '((t :foreground "white"))
  "Foreground color for up-to-date files.")
Jonathan Leech-Pepin
  • 4,307
  • 1
  • 19
  • 32
  • Two things: 1) This is a much slower solution, compared to what `diff-hl-dired` does (it uses the `dir-status-files` backend command), 2) this `update-face` is unreadable in the default theme. – Dmitry Jan 13 '16 at 00:32