9

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.

14
  • 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? Feb 23, 2015 at 19:52
  • @JonathanLeech-Pepin That's what is pictured, but faces are easy enough to M-x customize :) Feb 23, 2015 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. Feb 23, 2015 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). Feb 23, 2015 at 20:04
  • 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, 2015 at 14:21

3 Answers 3

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

5
  • Woah! Also, sorry! I checked back here almost by accident :) 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? Mar 21, 2015 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, 2015 at 17:58
  • Naturally :) Though I will note that 'public functionality' is difficult to determine in emacs lisp :) Mar 21, 2015 at 18:01
  • 1
    @SeanAllred Well, vars and hook in this case, I guess. :)
    – Dmitry
    Mar 21, 2015 at 18:14
  • I'm accepting this because it answers the question I asked as written, but future readers should note the additional answer I provided for neotree's new support of this. Apr 29, 2015 at 16:26
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.")
1
  • 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, 2016 at 0:32
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.

2
  • That looks nice, but without any info about your configuration … Mar 18, 2017 at 15:13
  • Belatedly addressed Jan 7, 2019 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.