1 ;;; vc-dir.el --- Directory status display under VC -*- lexical-binding: t -*-
3 ;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
5 ;; Author: Dan Nicolaescu <dann@ics.uci.edu>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; The original VC directory status implementation was based on dired.
27 ;; This implementation was inspired by PCL-CVS.
28 ;; Many people contributed comments, ideas and code to this
29 ;; implementation. These include:
31 ;; Alexandre Julliard <julliard@winehq.org>
32 ;; Stefan Monnier <monnier@iro.umontreal.ca>
33 ;; Tom Tromey <tromey@redhat.com>
46 (eval-when-compile (require 'cl-lib
))
48 (defcustom vc-dir-mode-hook nil
49 "Normal hook run by `vc-dir-mode'.
54 ;; Used to store information for the files displayed in the directory buffer.
55 ;; Each item displayed corresponds to one of these defstructs.
56 (cl-defstruct (vc-dir-fileinfo
58 (:type list
) ;So we can use `member' on lists of FIs.
60 ;; We could define it as an alias for `list'.
61 vc-dir-create-fileinfo
(name state
&optional extra marked directory
))
62 (:conc-name vc-dir-fileinfo-
>))
63 name
;Keep it as first, for `member'.
65 ;; For storing backend specific information.
68 ;; To keep track of not updated files during a global refresh
70 ;; To distinguish files and directories.
75 (defvar vc-dir-process-buffer nil
76 "The buffer used for the asynchronous call that computes status.")
78 (defvar vc-dir-backend nil
79 "The backend used by the current *vc-dir* buffer.")
81 (defun vc-dir-move-to-goal-column ()
82 ;; Used to keep the cursor on the file name column.
85 ;; Must be in sync with vc-default-dir-printer.
88 (defun vc-dir-prepare-status-buffer (bname dir backend
&optional create-new
)
89 "Find a buffer named BNAME showing DIR, or create a new one."
90 (setq dir
(file-name-as-directory (expand-file-name dir
)))
91 (let* ;; Look for another buffer name BNAME visiting the same directory.
94 (cl-dolist (buffer vc-dir-buffers
)
95 (when (buffer-live-p buffer
)
97 (when (and (derived-mode-p 'vc-dir-mode
)
98 (eq vc-dir-backend backend
)
99 (string= default-directory dir
))
100 (cl-return buffer
))))))))
102 ;; Create a new buffer named BNAME.
103 ;; We pass a filename to create-file-buffer because it is what
104 ;; the function expects, and also what uniquify needs (if active)
105 (with-current-buffer (create-file-buffer (expand-file-name bname dir
))
106 (setq default-directory dir
)
107 (vc-setup-buffer (current-buffer))
108 ;; Reset the vc-parent-buffer-name so that it does not appear
110 (setq vc-parent-buffer-name nil
)
113 (defvar vc-dir-menu-map
114 (let ((map (make-sparse-keymap "VC-dir")))
115 (define-key map
[quit]
116 '(menu-item "Quit" quit-window
118 (define-key map [kill]
119 '(menu-item "Kill Update Command" vc-dir-kill-dir-status-process
120 :enable (vc-dir-busy)
121 :help "Kill the command that updates the directory buffer"))
122 (define-key map [refresh]
123 '(menu-item "Refresh" revert-buffer
124 :enable (not (vc-dir-busy))
125 :help "Refresh the contents of the directory buffer"))
126 (define-key map [remup]
127 '(menu-item "Hide Up-to-date" vc-dir-hide-up-to-date
128 :help "Hide up-to-date items from display"))
130 (define-key map [sepmv] '("--"))
131 (define-key map [next-line]
132 '(menu-item "Next Line" vc-dir-next-line
133 :help "Go to the next line" :keys "n"))
134 (define-key map [previous-line]
135 '(menu-item "Previous Line" vc-dir-previous-line
136 :help "Go to the previous line"))
138 (define-key map [sepmrk] '("--"))
139 (define-key map [unmark-all]
140 '(menu-item "Unmark All" vc-dir-unmark-all-files
141 :help "Unmark all files that are in the same state as the current file\
142 \nWith prefix argument unmark all files"))
143 (define-key map [unmark-previous]
144 '(menu-item "Unmark Previous " vc-dir-unmark-file-up
145 :help "Move to the previous line and unmark the file"))
147 (define-key map [mark-all]
148 '(menu-item "Mark All" vc-dir-mark-all-files
149 :help "Mark all files that are in the same state as the current file\
150 \nWith prefix argument mark all files"))
151 (define-key map [unmark]
152 '(menu-item "Unmark" vc-dir-unmark
153 :help "Unmark the current file or all files in the region"))
155 (define-key map [mark]
156 '(menu-item "Mark" vc-dir-mark
157 :help "Mark the current file or all files in the region"))
159 (define-key map [sepopn] '("--"))
161 '(menu-item "Query Replace in Files..." vc-dir-query-replace-regexp
162 :help "Replace a string in the marked files"))
164 '(menu-item "Search Files..." vc-dir-search
165 :help "Search a regexp in the marked files"))
166 (define-key map [ires]
167 '(menu-item "Isearch Regexp Files..." vc-dir-isearch-regexp
168 :help "Incremental search a regexp in the marked files"))
169 (define-key map [ise]
170 '(menu-item "Isearch Files..." vc-dir-isearch
171 :help "Incremental search a string in the marked files"))
172 (define-key map [open-other]
173 '(menu-item "Open in Other Window" vc-dir-find-file-other-window
174 :help "Find the file on the current line, in another window"))
175 (define-key map [open]
176 '(menu-item "Open File" vc-dir-find-file
177 :help "Find the file on the current line"))
178 (define-key map [sepvcdet] '("--"))
179 ;; FIXME: This needs a key binding. And maybe a better name
180 ;; ("Insert" like PCL-CVS uses does not sound that great either)...
181 (define-key map [ins]
182 '(menu-item "Show File" vc-dir-show-fileentry
183 :help "Show a file in the VC status listing even though it might be up to date"))
184 (define-key map [annotate]
185 '(menu-item "Annotate" vc-annotate
186 :help "Display the edit history of the current file using colors"))
187 (define-key map [diff]
188 '(menu-item "Compare with Base Version" vc-diff
189 :help "Compare file set with the base version"))
190 (define-key map [logo]
191 '(menu-item "Show Outgoing Log" vc-log-outgoing
192 :help "Show a log of changes that will be sent with a push operation"))
193 (define-key map [logi]
194 '(menu-item "Show Incoming Log" vc-log-incoming
195 :help "Show a log of changes that will be received with a pull operation"))
196 (define-key map [log]
197 '(menu-item "Show History" vc-print-log
198 :help "List the change log of the current file set in a window"))
199 (define-key map [rlog]
200 '(menu-item "Show Top of the Tree History " vc-print-root-log
201 :help "List the change log for the current tree in a window"))
203 (define-key map [sepvccmd] '("--"))
204 (define-key map [update]
205 '(menu-item "Update to Latest Version" vc-update
206 :help "Update the current fileset's files to their tip revisions"))
207 (define-key map [revert]
208 '(menu-item "Revert to Base Version" vc-revert
209 :help "Revert working copies of the selected fileset to their repository contents."))
210 (define-key map [next-action]
211 ;; FIXME: This really really really needs a better name!
212 ;; And a key binding too.
213 '(menu-item "Check In/Out" vc-next-action
214 :help "Do the next logical version control operation on the current fileset"))
215 (define-key map [register]
216 '(menu-item "Register" vc-register
217 :help "Register file set into the version control system"))
221 ;; VC backends can use this to add mode-specific menu items to
223 (defun vc-dir-menu-map-filter (orig-binding)
224 (when (and (symbolp orig-binding) (fboundp orig-binding))
225 (setq orig-binding (indirect-function orig-binding)))
227 (when (derived-mode-p 'vc-dir-mode)
228 (vc-call-backend vc-dir-backend 'extra-status-menu))))
229 (if (null ext-binding)
235 (defvar vc-dir-mode-map
236 (let ((map (make-sparse-keymap)))
238 (define-key map "v" 'vc-next-action) ;; C-x v v
239 (define-key map "=" 'vc-diff) ;; C-x v =
240 (define-key map "i" 'vc-register) ;; C-x v i
241 (define-key map "+" 'vc-update) ;; C-x v +
242 (define-key map "l" 'vc-print-log) ;; C-x v l
243 ;; More confusing than helpful, probably
244 ;;(define-key map "R" 'vc-revert) ;; u is taken by vc-dir-unmark.
245 ;;(define-key map "A" 'vc-annotate) ;; g is taken by revert-buffer
246 ;; bound by `special-mode'.
248 (define-key map "m" 'vc-dir-mark)
249 (define-key map "M" 'vc-dir-mark-all-files)
250 (define-key map "u" 'vc-dir-unmark)
251 (define-key map "U" 'vc-dir-unmark-all-files)
252 (define-key map "\C-?" 'vc-dir-unmark-file-up)
253 (define-key map "\M-\C-?" 'vc-dir-unmark-all-files)
255 (define-key map "n" 'vc-dir-next-line)
256 (define-key map " " 'vc-dir-next-line)
257 (define-key map "\t" 'vc-dir-next-directory)
258 (define-key map "p" 'vc-dir-previous-line)
259 (define-key map [backtab] 'vc-dir-previous-directory)
260 ;;; Rebind paragraph-movement commands.
261 (define-key map "\M-}" 'vc-dir-next-directory)
262 (define-key map "\M-{" 'vc-dir-previous-directory)
263 (define-key map [C-down] 'vc-dir-next-directory)
264 (define-key map [C-up] 'vc-dir-previous-directory)
266 (define-key map "f" 'vc-dir-find-file)
267 (define-key map "e" 'vc-dir-find-file) ; dired-mode compatibility
268 (define-key map "\C-m" 'vc-dir-find-file)
269 (define-key map "o" 'vc-dir-find-file-other-window)
270 (define-key map "\C-c\C-c" 'vc-dir-kill-dir-status-process)
271 (define-key map [down-mouse-3] 'vc-dir-menu)
272 (define-key map [mouse-2] 'vc-dir-toggle-mark)
273 (define-key map [follow-link] 'mouse-face)
274 (define-key map "x" 'vc-dir-hide-up-to-date)
275 (define-key map [?\C-k] 'vc-dir-kill-line)
276 (define-key map "S" 'vc-dir-search) ;; FIXME: Maybe use A like dired?
277 (define-key map "Q" 'vc-dir-query-replace-regexp)
278 (define-key map (kbd "M-s a C-s") 'vc-dir-isearch)
279 (define-key map (kbd "M-s a M-C-s") 'vc-dir-isearch-regexp)
282 (define-key map [menu-bar vc-dir-mode]
284 ;; VC backends can use this to add mode-specific menu items to
286 "VC-dir" ,vc-dir-menu-map :filter vc-dir-menu-map-filter))
288 "Keymap for directory buffer.")
290 (defmacro vc-dir-at-event (event &rest body)
291 "Evaluate BODY with point located at event-start of EVENT.
292 If BODY uses EVENT, it should be a variable,
293 otherwise it will be evaluated twice."
294 (let ((posn (make-symbol "vc-dir-at-event-posn")))
296 (unless (equal ,event '(tool-bar))
297 (let ((,posn (event-start ,event)))
298 (set-buffer (window-buffer (posn-window ,posn)))
299 (goto-char (posn-point ,posn))))
302 (defun vc-dir-menu (e)
303 "Popup the VC dir menu."
305 (vc-dir-at-event e (popup-menu vc-dir-menu-map e)))
307 (defvar vc-dir-tool-bar-map
308 (let ((map (make-sparse-keymap)))
309 (tool-bar-local-item-from-menu 'find-file "new" map nil
310 :label "New File" :vert-only t)
311 (tool-bar-local-item-from-menu 'menu-find-file-existing "open" map nil
312 :label "Open" :vert-only t)
313 (tool-bar-local-item-from-menu 'dired "diropen" map nil
315 (tool-bar-local-item-from-menu 'quit-window "close" map vc-dir-mode-map
317 (tool-bar-local-item-from-menu 'vc-next-action "saveas" map
318 vc-dir-mode-map :label "Commit")
319 (tool-bar-local-item-from-menu 'vc-print-log "info"
322 (define-key-after map [separator-1] menu-bar-separator)
323 (tool-bar-local-item-from-menu 'vc-dir-kill-dir-status-process "cancel"
325 :label "Stop" :vert-only t)
326 (tool-bar-local-item-from-menu 'revert-buffer "refresh"
327 map vc-dir-mode-map :vert-only t)
328 (define-key-after map [separator-2] menu-bar-separator)
329 (tool-bar-local-item-from-menu (lookup-key menu-bar-edit-menu [cut])
330 "cut" map nil :vert-only t)
331 (tool-bar-local-item-from-menu (lookup-key menu-bar-edit-menu [copy])
332 "copy" map nil :vert-only t)
333 (tool-bar-local-item-from-menu (lookup-key menu-bar-edit-menu [paste])
334 "paste" map nil :vert-only t)
335 (define-key-after map [separator-3] menu-bar-separator)
336 (tool-bar-local-item-from-menu 'isearch-forward
338 :label "Search" :vert-only t)
341 (defun vc-dir-node-directory (node)
342 ;; Compute the directory for NODE.
343 ;; If it's a directory node, get it from the node.
344 (let ((data (ewoc-data node)))
345 (or (vc-dir-fileinfo->directory data)
346 ;; Otherwise compute it from the file name.
350 (vc-dir-fileinfo->name data)))))))
352 (defun vc-dir-update (entries buffer &optional noinsert)
353 "Update BUFFER's ewoc from the list of ENTRIES.
354 If NOINSERT, ignore elements on ENTRIES which are not in the ewoc."
355 ;; Add ENTRIES to the vc-dir buffer BUFFER.
356 (with-current-buffer buffer
357 ;; Insert the entries sorted by name into the ewoc.
358 ;; We assume the ewoc is sorted too, which should be the
359 ;; case if we always add entries with vc-dir-update.
361 ;; Sort: first files and then subdirectories.
362 ;; XXX: this is VERY inefficient, it computes the directory
363 ;; names too many times
365 (lambda (entry1 entry2)
366 (let ((dir1 (file-name-directory
367 (directory-file-name (expand-file-name (car entry1)))))
368 (dir2 (file-name-directory
369 (directory-file-name (expand-file-name (car entry2))))))
371 ((string< dir1 dir2) t)
372 ((not (string= dir1 dir2)) nil)
373 ((string< (car entry1) (car entry2))))))))
374 ;; Insert directory entries in the right places.
375 (let ((entry (car entries))
376 (node (ewoc-nth vc-ewoc 0))
378 (dotname (file-relative-name default-directory)))
379 ;; Insert . if it is not present.
382 vc-ewoc (vc-dir-create-fileinfo
383 dotname nil nil nil default-directory))
384 (setq node (ewoc-nth vc-ewoc 0)))
386 (while (and entry node)
387 (let* ((entryfile (car entry))
388 (entrydir (file-name-directory (directory-file-name
389 (expand-file-name entryfile))))
390 (nodedir (vc-dir-node-directory node)))
392 ;; First try to find the directory.
393 ((string-lessp nodedir entrydir)
394 (setq node (ewoc-next vc-ewoc node)))
395 ((string-equal nodedir entrydir)
396 ;; Found the directory, find the place for the file name.
397 (let ((nodefile (vc-dir-fileinfo->name (ewoc-data node))))
399 ((string= nodefile dotname)
400 (setq node (ewoc-next vc-ewoc node)))
401 ((string-lessp nodefile entryfile)
402 (setq node (ewoc-next vc-ewoc node)))
403 ((string-equal nodefile entryfile)
406 (setf (vc-dir-fileinfo->state (ewoc-data node)) (nth 1 entry))
407 (setf (vc-dir-fileinfo->extra (ewoc-data node)) (nth 2 entry))
408 (setf (vc-dir-fileinfo->needs-update (ewoc-data node)) nil)
409 (ewoc-invalidate vc-ewoc node))
410 ;; If the state is nil, the file does not exist
411 ;; anymore, so remember the entry so we can remove
412 ;; it after we are done inserting all ENTRIES.
413 (push node to-remove))
414 (setq entries (cdr entries))
415 (setq entry (car entries))
416 (setq node (ewoc-next vc-ewoc node)))
419 (ewoc-enter-before vc-ewoc node
420 (apply 'vc-dir-create-fileinfo entry)))
421 (setq entries (cdr entries))
422 (setq entry (car entries))))))
425 ;; We might need to insert a directory node if the
426 ;; previous node was in a different directory.
427 (let* ((rd (file-relative-name entrydir))
428 (prev-node (ewoc-prev vc-ewoc node))
429 (prev-dir (vc-dir-node-directory prev-node)))
430 (unless (string-equal entrydir prev-dir)
432 vc-ewoc node (vc-dir-create-fileinfo rd nil nil nil entrydir))))
433 ;; Now insert the node itself.
434 (ewoc-enter-before vc-ewoc node
435 (apply 'vc-dir-create-fileinfo entry)))
436 (setq entries (cdr entries) entry (car entries))))))
437 ;; We're past the last node, all remaining entries go to the end.
438 (unless (or node noinsert)
439 (let ((lastdir (vc-dir-node-directory (ewoc-nth vc-ewoc -1))))
440 (dolist (entry entries)
441 (let ((entrydir (file-name-directory
442 (directory-file-name (expand-file-name (car entry))))))
443 ;; Insert a directory node if needed.
444 (unless (string-equal lastdir entrydir)
445 (setq lastdir entrydir)
446 (let ((rd (file-relative-name entrydir)))
448 vc-ewoc (vc-dir-create-fileinfo rd nil nil nil entrydir))))
449 ;; Now insert the node itself.
450 (ewoc-enter-last vc-ewoc
451 (apply 'vc-dir-create-fileinfo entry))))))
453 (let ((inhibit-read-only t))
454 (apply 'ewoc-delete vc-ewoc (nreverse to-remove)))))))
456 (defun vc-dir-busy ()
457 (and (buffer-live-p vc-dir-process-buffer)
458 (get-buffer-process vc-dir-process-buffer)))
460 (defun vc-dir-kill-dir-status-process ()
461 "Kill the temporary buffer and associated process."
463 (when (buffer-live-p vc-dir-process-buffer)
464 (let ((proc (get-buffer-process vc-dir-process-buffer)))
465 (when proc (delete-process proc))
466 (setq vc-dir-process-buffer nil)
467 (setq mode-line-process nil))))
469 (defun vc-dir-kill-query ()
470 ;; Make sure that when the status buffer is killed the update
471 ;; process running in background is also killed.
473 (when (y-or-n-p "Status update process running, really kill status buffer? ")
474 (vc-dir-kill-dir-status-process)
478 (defun vc-dir-next-line (arg)
479 "Go to the next line.
480 If a prefix argument is given, move by that many lines."
483 (ewoc-goto-next vc-ewoc arg)
484 (vc-dir-move-to-goal-column)))
486 (defun vc-dir-previous-line (arg)
487 "Go to the previous line.
488 If a prefix argument is given, move by that many lines."
490 (ewoc-goto-prev vc-ewoc arg)
491 (vc-dir-move-to-goal-column))
493 (defun vc-dir-next-directory ()
494 "Go to the next directory."
496 (let ((orig (point)))
500 (let* ((next (ewoc-next vc-ewoc (ewoc-locate vc-ewoc))))
505 (ewoc-goto-node vc-ewoc next)
506 (vc-dir-move-to-goal-column)
507 (if (vc-dir-fileinfo->directory (ewoc-data next))
508 (throw 'foundit nil))))))))
511 (defun vc-dir-previous-directory ()
512 "Go to the previous directory."
514 (let ((orig (point)))
518 (let* ((prev (ewoc-prev vc-ewoc (ewoc-locate vc-ewoc))))
523 (ewoc-goto-node vc-ewoc prev)
524 (vc-dir-move-to-goal-column)
525 (if (vc-dir-fileinfo->directory (ewoc-data prev))
526 (throw 'foundit nil))))))))
529 (defun vc-dir-mark-unmark (mark-unmark-function)
531 (let (;; (firstl (line-number-at-pos (region-beginning)))
532 (lastl (line-number-at-pos (region-end))))
534 (goto-char (region-beginning))
535 (while (<= (line-number-at-pos) lastl)
537 (funcall mark-unmark-function)
538 ;; `vc-dir-mark-file' signals an error if we try marking
539 ;; a directory containing marked files in its tree, or a
540 ;; file in a marked directory tree. Just continue.
541 (error (vc-dir-next-line 1))))))
542 (funcall mark-unmark-function)))
544 (defun vc-dir-parent-marked-p (arg)
545 ;; Non-nil iff a parent directory of arg is marked.
546 ;; Return value, if non-nil is the `ewoc-data' for the marked parent.
547 (let* ((argdir (vc-dir-node-directory arg))
548 ;; (arglen (length argdir))
551 ;; Go through the predecessors, checking if any directory that is
552 ;; a parent is marked.
553 (while (and (null found)
554 (setq crt (ewoc-prev vc-ewoc crt)))
555 (let ((data (ewoc-data crt))
556 (dir (vc-dir-node-directory crt)))
557 (and (vc-dir-fileinfo->directory data)
558 (string-prefix-p dir argdir)
559 (vc-dir-fileinfo->marked data)
563 (defun vc-dir-children-marked-p (arg)
564 ;; Non-nil iff a child of ARG is marked.
565 ;; Return value, if non-nil, is the `ewoc-data' for the marked child.
566 (let* ((argdir-re (concat "\\`" (regexp-quote (vc-dir-node-directory arg))))
572 (setq crt (ewoc-next vc-ewoc crt)))
573 (let ((data (ewoc-data crt))
574 (dir (vc-dir-node-directory crt)))
575 (if (string-match argdir-re dir)
576 (if (vc-dir-fileinfo->marked data)
578 ;; We are done, we got to an entry that is not a child of `arg'.
579 (setq is-child nil))))
582 (defun vc-dir-mark-file (&optional arg)
583 ;; Mark ARG or the current file and move to the next line.
584 (let* ((crt (or arg (ewoc-locate vc-ewoc)))
585 (file (ewoc-data crt))
586 (isdir (vc-dir-fileinfo->directory file))
587 ;; Forbid marking a directory containing marked files in its
588 ;; tree, or a file in a marked directory tree.
590 (vc-dir-children-marked-p crt)
591 (vc-dir-parent-marked-p crt))))
594 "File `%s' in this directory is already marked"
595 "Parent directory `%s' is already marked")
596 (vc-dir-fileinfo->name conflict)))
597 (setf (vc-dir-fileinfo->marked file) t)
598 (ewoc-invalidate vc-ewoc crt)
599 (unless (or arg (mouse-event-p last-command-event))
600 (vc-dir-next-line 1))))
602 (defun vc-dir-mark ()
603 "Mark the current file or all files in the region.
604 If the region is active, mark all the files in the region.
605 Otherwise mark the file on the current line and move to the next
608 (vc-dir-mark-unmark 'vc-dir-mark-file))
610 (defun vc-dir-mark-all-files (arg)
611 "Mark all files with the same state as the current one.
612 With a prefix argument mark all files.
613 If the current entry is a directory, mark all child files.
615 The commands operate on files that are on the same state.
616 This command is intended to make it easy to select all files that
617 share the same state."
622 ;; First check that no directory is marked, we can't mark
623 ;; files in that case.
626 (when (and (vc-dir-fileinfo->directory filearg)
627 (vc-dir-fileinfo->marked filearg))
628 (error "Cannot mark all files, directory `%s' marked"
629 (vc-dir-fileinfo->name filearg))))
633 (unless (vc-dir-fileinfo->marked filearg)
634 (setf (vc-dir-fileinfo->marked filearg) t)
637 (let* ((crt (ewoc-locate vc-ewoc))
638 (data (ewoc-data crt)))
639 (if (vc-dir-fileinfo->directory data)
640 ;; It's a directory, mark child files.
642 (while (and (setq crt (ewoc-next vc-ewoc crt))
643 (setq crt-data (ewoc-data crt))
644 (not (vc-dir-fileinfo->directory crt-data)))
645 (setf (vc-dir-fileinfo->marked crt-data) t)
646 (ewoc-invalidate vc-ewoc crt)))
648 (let ((state (vc-dir-fileinfo->state data)))
649 (setq crt (ewoc-nth vc-ewoc 0))
651 (let ((crt-data (ewoc-data crt)))
652 (when (and (not (vc-dir-fileinfo->marked crt-data))
653 (eq (vc-dir-fileinfo->state crt-data) state)
654 (not (vc-dir-fileinfo->directory crt-data)))
655 (vc-dir-mark-file crt)))
656 (setq crt (ewoc-next vc-ewoc crt))))))))
658 (defun vc-dir-unmark-file ()
659 ;; Unmark the current file and move to the next line.
660 (let* ((crt (ewoc-locate vc-ewoc))
661 (file (ewoc-data crt)))
662 (setf (vc-dir-fileinfo->marked file) nil)
663 (ewoc-invalidate vc-ewoc crt)
664 (unless (mouse-event-p last-command-event)
665 (vc-dir-next-line 1))))
667 (defun vc-dir-unmark ()
668 "Unmark the current file or all files in the region.
669 If the region is active, unmark all the files in the region.
670 Otherwise mark the file on the current line and move to the next
673 (vc-dir-mark-unmark 'vc-dir-unmark-file))
675 (defun vc-dir-unmark-file-up ()
676 "Move to the previous line and unmark the file."
678 ;; If we're on the first line, we won't move up, but we will still
679 ;; remove the mark. This seems a bit odd but it is what buffer-menu
681 (let* ((prev (ewoc-goto-prev vc-ewoc 1))
682 (file (ewoc-data prev)))
683 (setf (vc-dir-fileinfo->marked file) nil)
684 (ewoc-invalidate vc-ewoc prev)
685 (vc-dir-move-to-goal-column)))
687 (defun vc-dir-unmark-all-files (arg)
688 "Unmark all files with the same state as the current one.
689 With a prefix argument unmark all files.
690 If the current entry is a directory, unmark all the child files.
692 The commands operate on files that are on the same state.
693 This command is intended to make it easy to deselect all files
694 that share the same state."
699 (when (vc-dir-fileinfo->marked filearg)
700 (setf (vc-dir-fileinfo->marked filearg) nil)
703 (let* ((crt (ewoc-locate vc-ewoc))
704 (data (ewoc-data crt)))
705 (if (vc-dir-fileinfo->directory data)
706 ;; It's a directory, unmark child files.
707 (while (setq crt (ewoc-next vc-ewoc crt))
708 (let ((crt-data (ewoc-data crt)))
709 (unless (vc-dir-fileinfo->directory crt-data)
710 (setf (vc-dir-fileinfo->marked crt-data) nil)
711 (ewoc-invalidate vc-ewoc crt))))
713 (let ((crt-state (vc-dir-fileinfo->state (ewoc-data crt))))
716 (when (and (vc-dir-fileinfo->marked filearg)
717 (eq (vc-dir-fileinfo->state filearg) crt-state))
718 (setf (vc-dir-fileinfo->marked filearg) nil)
722 (defun vc-dir-toggle-mark-file ()
723 (let* ((crt (ewoc-locate vc-ewoc))
724 (file (ewoc-data crt)))
725 (if (vc-dir-fileinfo->marked file)
727 (vc-dir-mark-file))))
729 (defun vc-dir-toggle-mark (e)
731 (vc-dir-at-event e (vc-dir-mark-unmark 'vc-dir-toggle-mark-file)))
733 (defun vc-dir-delete-file ()
734 "Delete the marked files, or the current file if no marks."
736 (mapc 'vc-delete-file (or (vc-dir-marked-files)
737 (list (vc-dir-current-file)))))
739 (defun vc-dir-find-file ()
740 "Find the file on the current line."
742 (find-file (vc-dir-current-file)))
744 (defun vc-dir-find-file-other-window (&optional event)
745 "Find the file on the current line, in another window."
746 (interactive (list last-nonmenu-event))
747 (if event (posn-set-point (event-end event)))
748 (find-file-other-window (vc-dir-current-file)))
750 (defun vc-dir-isearch ()
751 "Search for a string through all marked buffers using Isearch."
754 (mapcar 'car (vc-dir-marked-only-files-and-states))))
756 (defun vc-dir-isearch-regexp ()
757 "Search for a regexp through all marked buffers using Isearch."
759 (multi-isearch-files-regexp
760 (mapcar 'car (vc-dir-marked-only-files-and-states))))
762 (defun vc-dir-search (regexp)
763 "Search through all marked files for a match for REGEXP.
764 For marked directories, use the files displayed from those directories.
765 Stops when a match is found.
766 To continue searching for next match, use command \\[tags-loop-continue]."
767 (interactive "sSearch marked files (regexp): ")
768 (tags-search regexp '(mapcar 'car (vc-dir-marked-only-files-and-states))))
770 (defun vc-dir-query-replace-regexp (from to &optional delimited)
771 "Do `query-replace-regexp' of FROM with TO, on all marked files.
772 If a directory is marked, then use the files displayed for that directory.
773 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
774 If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
775 with the command \\[tags-loop-continue]."
776 ;; FIXME: this is almost a copy of `dired-do-query-replace-regexp'. This
777 ;; should probably be made generic and used in both places instead of
778 ;; duplicating it here.
781 (query-replace-read-args
782 "Query replace regexp in marked files" t t)))
783 (list (nth 0 common) (nth 1 common) (nth 2 common))))
784 (dolist (file (mapcar 'car (vc-dir-marked-only-files-and-states)))
785 (let ((buffer (get-file-buffer file)))
786 (if (and buffer (with-current-buffer buffer
788 (error "File `%s' is visited read-only" file))))
789 (tags-query-replace from to delimited
790 '(mapcar 'car (vc-dir-marked-only-files-and-states))))
792 (defun vc-dir-current-file ()
793 (let ((node (ewoc-locate vc-ewoc)))
795 (error "No file available"))
796 (expand-file-name (vc-dir-fileinfo->name (ewoc-data node)))))
798 (defun vc-dir-marked-files ()
799 "Return the list of marked files."
801 (lambda (elem) (expand-file-name (vc-dir-fileinfo->name elem)))
802 (ewoc-collect vc-ewoc 'vc-dir-fileinfo->marked)))
804 (defun vc-dir-marked-only-files-and-states ()
805 "Return the list of conses (FILE . STATE) for the marked files.
806 For marked directories return the corresponding conses for the
808 (let ((crt (ewoc-nth vc-ewoc 0))
811 (let ((crt-data (ewoc-data crt)))
812 (if (vc-dir-fileinfo->marked crt-data)
813 ;; FIXME: use vc-dir-child-files-and-states here instead of duplicating it.
814 (if (vc-dir-fileinfo->directory crt-data)
815 (let* ((dir (vc-dir-fileinfo->directory crt-data))
816 ;; (dirlen (length dir))
819 (and (setq crt (ewoc-next vc-ewoc crt))
822 (setq data (ewoc-data crt))
823 (vc-dir-node-directory crt))))
824 (unless (vc-dir-fileinfo->directory data)
826 (cons (expand-file-name (vc-dir-fileinfo->name data))
827 (vc-dir-fileinfo->state data))
829 (push (cons (expand-file-name (vc-dir-fileinfo->name crt-data))
830 (vc-dir-fileinfo->state crt-data))
832 (setq crt (ewoc-next vc-ewoc crt)))
833 (setq crt (ewoc-next vc-ewoc crt)))))
836 (defun vc-dir-child-files-and-states ()
837 "Return the list of conses (FILE . STATE) for child files of the current entry if it's a directory.
838 If it is a file, return the corresponding cons for the file itself."
839 (let* ((crt (ewoc-locate vc-ewoc))
840 (crt-data (ewoc-data crt))
842 (if (vc-dir-fileinfo->directory crt-data)
843 (let* ((dir (vc-dir-fileinfo->directory crt-data))
844 ;; (dirlen (length dir))
847 (and (setq crt (ewoc-next vc-ewoc crt))
848 (string-prefix-p dir (progn
849 (setq data (ewoc-data crt))
850 (vc-dir-node-directory crt))))
851 (unless (vc-dir-fileinfo->directory data)
853 (cons (expand-file-name (vc-dir-fileinfo->name data))
854 (vc-dir-fileinfo->state data))
857 (cons (expand-file-name (vc-dir-fileinfo->name crt-data))
858 (vc-dir-fileinfo->state crt-data)) result))
861 (defun vc-dir-recompute-file-state (fname def-dir)
862 (let* ((file-short (file-relative-name fname def-dir))
863 (_remove-me-when-CVS-works
864 (when (eq vc-dir-backend 'CVS)
865 ;; FIXME: Warning: UGLY HACK. The CVS backend caches the state
866 ;; info, this forces the backend to update it.
867 (vc-call-backend vc-dir-backend 'registered fname)))
868 (state (vc-call-backend vc-dir-backend 'state fname))
869 (extra (vc-call-backend vc-dir-backend
870 'status-fileinfo-extra fname)))
871 (list file-short state extra)))
873 (defun vc-dir-find-child-files (dirname)
874 ;; Give a DIRNAME string return the list of all child files shown in
875 ;; the current *vc-dir* buffer.
876 (let ((crt (ewoc-nth vc-ewoc 0))
879 (while (and crt (not (string-prefix-p
880 dirname (vc-dir-node-directory crt))))
881 (setq crt (ewoc-next vc-ewoc crt)))
882 (while (and crt (string-prefix-p
884 (vc-dir-node-directory crt)))
885 (let ((data (ewoc-data crt)))
886 (unless (vc-dir-fileinfo->directory data)
887 (push (expand-file-name (vc-dir-fileinfo->name data)) children)))
888 (setq crt (ewoc-next vc-ewoc crt)))
891 (defun vc-dir-resync-directory-files (dirname)
892 ;; Update the entries for all the child files of DIRNAME shown in
893 ;; the current *vc-dir* buffer.
894 (let ((files (vc-dir-find-child-files dirname))
895 (ddir default-directory)
899 (push (vc-dir-recompute-file-state crt ddir)
901 (vc-dir-update fileentries (current-buffer)))))
903 (defun vc-dir-resynch-file (&optional fname)
904 "Update the entries for FNAME in any directory buffers that list it."
905 (let ((file (or fname (expand-file-name buffer-file-name)))
908 ;; look for a vc-dir buffer that might show this file.
909 (dolist (status-buf vc-dir-buffers)
910 (if (not (buffer-live-p status-buf))
911 (push status-buf drop)
912 (set-buffer status-buf)
913 (if (not (derived-mode-p 'vc-dir-mode))
914 (push status-buf drop)
915 (let ((ddir default-directory))
916 (when (string-prefix-p ddir file)
917 (if (file-directory-p file)
919 (vc-dir-resync-directory-files file)
921 (vc-dir-headers vc-dir-backend default-directory) ""))
922 (let* ((complete-state (vc-dir-recompute-file-state file ddir))
923 (state (cadr complete-state)))
925 (list complete-state)
926 status-buf (or (not state)
927 (eq state 'up-to-date)))))))))))
928 ;; Remove out-of-date entries from vc-dir-buffers.
929 (dolist (b drop) (setq vc-dir-buffers (delq b vc-dir-buffers)))))
931 (defvar use-vc-backend) ;; dynamically bound
933 (define-derived-mode vc-dir-mode special-mode "VC dir"
934 "Major mode for VC directory buffers.
935 Marking/Unmarking key bindings and actions:
936 m - mark a file/directory
937 - if the region is active, mark all the files in region.
938 Restrictions: - a file cannot be marked if any parent directory is marked
939 - a directory cannot be marked if any child file or
941 u - unmark a file/directory
942 - if the region is active, unmark all the files in region.
943 M - if the cursor is on a file: mark all the files with the same state as
945 - if the cursor is on a directory: mark all child files
946 - with a prefix argument: mark all files
947 U - if the cursor is on a file: unmark all the files with the same state
949 - if the cursor is on a directory: unmark all child files
950 - with a prefix argument: unmark all files
951 mouse-2 - toggles the mark state
954 VC commands in the `C-x v' prefix can be used.
955 VC commands act on the marked entries. If nothing is marked, VC
956 commands act on the current entry.
959 S - searches the marked files
960 Q - does a query replace on the marked files
961 M-s a C-s - does an isearch on the marked files
962 M-s a C-M-s - does a regexp isearch on the marked files
963 If nothing is marked, these commands act on the current entry.
964 When a directory is current or marked, the Search & Replace
965 commands act on the child files of that directory that are displayed in
969 (set (make-local-variable 'vc-dir-backend) use-vc-backend)
970 (set (make-local-variable 'desktop-save-buffer)
971 'vc-dir-desktop-buffer-misc-data)
972 (setq buffer-read-only t)
973 (when (boundp 'tool-bar-map)
974 (set (make-local-variable 'tool-bar-map) vc-dir-tool-bar-map))
975 (let ((buffer-read-only nil))
977 (set (make-local-variable 'vc-dir-process-buffer) nil)
978 (set (make-local-variable 'vc-ewoc) (ewoc-create #'vc-dir-printer))
979 (set (make-local-variable 'revert-buffer-function)
980 'vc-dir-revert-buffer-function)
981 (setq list-buffers-directory (expand-file-name "*vc-dir*" default-directory))
982 (add-to-list 'vc-dir-buffers (current-buffer))
983 ;; Make sure that if the directory buffer is killed, the update
984 ;; process running in the background is also killed.
985 (add-hook 'kill-buffer-query-functions 'vc-dir-kill-query nil t)
986 (hack-dir-local-variables-non-file-buffer)
989 (defun vc-dir-headers (backend dir)
990 "Display the headers in the *VC dir* buffer.
991 It calls the `dir-extra-headers' backend method to display backend
994 ;; First layout the common headers.
995 (propertize "VC backend : " 'face 'font-lock-type-face)
996 (propertize (format "%s\n" backend) 'face 'font-lock-variable-name-face)
997 (propertize "Working dir: " 'face 'font-lock-type-face)
998 (propertize (format "%s\n" (abbreviate-file-name dir))
999 'face 'font-lock-variable-name-face)
1000 ;; Then the backend specific ones.
1001 (vc-call-backend backend 'dir-extra-headers dir)
1004 (defun vc-dir-refresh-files (files default-state)
1005 "Refresh some files in the *VC-dir* buffer."
1006 (let ((def-dir default-directory)
1007 (backend vc-dir-backend))
1008 (vc-set-mode-line-busy-indicator)
1009 ;; Call the `dir-status-files' backend function.
1010 ;; `dir-status-files' is supposed to be asynchronous.
1011 ;; It should compute the results, and then call the function
1012 ;; passed as an argument in order to update the vc-dir buffer
1013 ;; with the results.
1014 (unless (buffer-live-p vc-dir-process-buffer)
1015 (setq vc-dir-process-buffer
1016 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
1017 (let ((buffer (current-buffer)))
1018 (with-current-buffer vc-dir-process-buffer
1019 (setq default-directory def-dir)
1022 backend 'dir-status-files def-dir files default-state
1023 (lambda (entries &optional more-to-come)
1024 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
1025 ;; If MORE-TO-COME is true, then more updates will come from
1026 ;; the asynchronous process.
1027 (with-current-buffer buffer
1028 (vc-dir-update entries buffer)
1029 (unless more-to-come
1030 (setq mode-line-process nil)
1031 ;; Remove the ones that haven't been updated at all.
1032 ;; Those not-updated are those whose state is nil because the
1033 ;; file/dir doesn't exist and isn't versioned.
1034 (ewoc-filter vc-ewoc
1036 ;; The state for directory entries might
1037 ;; have been changed to 'up-to-date,
1038 ;; reset it, otherwise it will be removed when doing 'x'
1040 ;; FIXME: There should be a more elegant way to do this.
1041 (when (and (vc-dir-fileinfo->directory info)
1042 (eq (vc-dir-fileinfo->state info)
1044 (setf (vc-dir-fileinfo->state info) nil))
1046 (not (vc-dir-fileinfo->needs-update info))))))))))))
1048 (defun vc-dir-revert-buffer-function (&optional _ignore-auto _noconfirm)
1051 (defun vc-dir-refresh ()
1052 "Refresh the contents of the *VC-dir* buffer.
1053 Throw an error if another update process is in progress."
1056 (error "Another update process is in progress, cannot run two at a time")
1057 (let ((def-dir default-directory)
1058 (backend vc-dir-backend))
1059 (vc-set-mode-line-busy-indicator)
1060 ;; Call the `dir-status' backend function.
1061 ;; `dir-status' is supposed to be asynchronous.
1062 ;; It should compute the results, and then call the function
1063 ;; passed as an argument in order to update the vc-dir buffer
1064 ;; with the results.
1066 ;; Create a buffer that can be used by `dir-status' and call
1067 ;; `dir-status' with this buffer as the current buffer. Use
1068 ;; `vc-dir-process-buffer' to remember this buffer, so that
1069 ;; it can be used later to kill the update process in case it
1071 (unless (buffer-live-p vc-dir-process-buffer)
1072 (setq vc-dir-process-buffer
1073 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
1074 ;; set the needs-update flag on all non-directory entries
1075 (ewoc-map (lambda (info)
1076 (unless (vc-dir-fileinfo->directory info)
1077 (setf (vc-dir-fileinfo->needs-update info) t) nil))
1079 ;; Bzr has serious locking problems, so setup the headers first (this is
1080 ;; synchronous) rather than doing it while dir-status is running.
1081 (ewoc-set-hf vc-ewoc (vc-dir-headers backend def-dir) "")
1082 (let ((buffer (current-buffer)))
1083 (with-current-buffer vc-dir-process-buffer
1084 (setq default-directory def-dir)
1087 backend 'dir-status def-dir
1088 (lambda (entries &optional more-to-come)
1089 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
1090 ;; If MORE-TO-COME is true, then more updates will come from
1091 ;; the asynchronous process.
1092 (with-current-buffer buffer
1093 (vc-dir-update entries buffer)
1094 (unless more-to-come
1097 vc-ewoc 'vc-dir-fileinfo->needs-update)))
1099 (vc-dir-refresh-files
1100 (mapcar 'vc-dir-fileinfo->name remaining)
1102 (setq mode-line-process nil))))))))))))
1104 (defun vc-dir-show-fileentry (file)
1105 "Insert an entry for a specific file into the current *VC-dir* listing.
1106 This is typically used if the file is up-to-date (or has been added
1107 outside of VC) and one wants to do some operation on it."
1108 (interactive "fShow file: ")
1109 (vc-dir-update (list (list (file-relative-name file) (vc-state file))) (current-buffer)))
1111 (defun vc-dir-hide-state (&optional state)
1112 "Hide items that are in STATE from display.
1113 See `vc-state' for valid values of STATE.
1115 If STATE is nil, default it to up-to-date.
1117 Interactively, if `current-prefix-arg' is non-nil, set STATE to
1118 state of item at point. Otherwise, set STATE to up-to-date."
1120 (and current-prefix-arg
1121 ;; Command is prefixed. Infer STATE from point.
1122 (let ((node (ewoc-locate vc-ewoc)))
1123 (and node (vc-dir-fileinfo->state (ewoc-data node)))))))
1124 ;; If STATE is un-specified, use up-to-date.
1125 (setq state (or state 'up-to-date))
1126 (message "Hiding items in state \"%s\"" state)
1127 (let ((crt (ewoc-nth vc-ewoc -1))
1128 (first (ewoc-nth vc-ewoc 0)))
1129 ;; Go over from the last item to the first and remove the
1130 ;; up-to-date files and directories with no child files.
1131 (while (not (eq crt first))
1132 (let* ((data (ewoc-data crt))
1133 (dir (vc-dir-fileinfo->directory data))
1134 (next (ewoc-next vc-ewoc crt))
1135 (prev (ewoc-prev vc-ewoc crt))
1136 ;; ewoc-delete does not work without this...
1137 (inhibit-read-only t))
1139 ;; Remove directories with no child files.
1142 ;; Nothing follows this directory.
1144 ;; Next item is a directory.
1145 (vc-dir-fileinfo->directory (ewoc-data next))))
1146 ;; Remove files in specified STATE. STATE can be a
1147 ;; symbol or a user-name.
1148 (equal (vc-dir-fileinfo->state data) state))
1149 (ewoc-delete vc-ewoc crt))
1152 (defalias 'vc-dir-hide-up-to-date 'vc-dir-hide-state)
1154 (defun vc-dir-kill-line ()
1155 "Remove the current line from display."
1157 (let ((crt (ewoc-locate vc-ewoc))
1158 (inhibit-read-only t))
1159 (ewoc-delete vc-ewoc crt)))
1161 (defun vc-dir-printer (fileentry)
1162 (vc-call-backend vc-dir-backend 'dir-printer fileentry))
1164 (defun vc-dir-deduce-fileset (&optional state-model-only-files)
1165 (let ((marked (vc-dir-marked-files))
1173 (when state-model-only-files
1174 (setq only-files-list (vc-dir-marked-only-files-and-states))))
1175 (let ((crt (vc-dir-current-file)))
1176 (setq files (list crt))
1177 (when state-model-only-files
1178 (setq only-files-list (vc-dir-child-files-and-states)))))
1180 (when state-model-only-files
1181 (setq state (cdar only-files-list))
1182 ;; Check that all files are in a consistent state, since we use that
1183 ;; state to decide which operation to perform.
1184 (dolist (crt (cdr only-files-list))
1185 (unless (vc-compatible-state (cdr crt) state)
1186 (error "When applying VC operations to multiple files, the files are required\nto be in similar VC states.\n%s in state %s clashes with %s in state %s"
1187 (car crt) (cdr crt) (caar only-files-list) state)))
1188 (setq only-files-list (mapcar 'car only-files-list))
1189 (when (and state (not (eq state 'unregistered)))
1190 (setq model (vc-checkout-model vc-dir-backend only-files-list))))
1191 (list vc-dir-backend files only-files-list state model)))
1194 (defun vc-dir (dir &optional backend)
1195 "Show the VC status for \"interesting\" files in and below DIR.
1196 This allows you to mark files and perform VC operations on them.
1197 The list omits files which are up to date, with no changes in your copy
1198 or the repository, if there is nothing in particular to say about them.
1200 Preparing the list of file status takes time; when the buffer
1201 first appears, it has only the first few lines of summary information.
1202 The file lines appear later.
1204 Optional second argument BACKEND specifies the VC backend to use.
1205 Interactively, a prefix argument means to ask for the backend.
1207 These are the commands available for use in the file status buffer:
1209 \\{vc-dir-mode-map}"
1213 ;; When you hit C-x v d in a visited VC file,
1214 ;; the *vc-dir* buffer visits the directory under its truename;
1215 ;; therefore it makes sense to always do that.
1216 ;; Otherwise if you do C-x v d -> C-x C-f -> C-c v d
1217 ;; you may get a new *vc-dir* buffer, different from the original
1218 (file-truename (read-directory-name "VC status for directory: "
1219 default-directory default-directory t
1221 (if current-prefix-arg
1225 (mapcar (lambda (b) (list (symbol-name b)))
1226 vc-handled-backends)
1229 (setq backend (vc-responsible-backend dir)))
1230 (let (pop-up-windows) ; based on cvs-examine; bug#6204
1231 (pop-to-buffer (vc-dir-prepare-status-buffer "*vc-dir*" dir backend)))
1232 (if (derived-mode-p 'vc-dir-mode)
1234 ;; FIXME: find a better way to pass the backend to `vc-dir-mode'.
1235 (let ((use-vc-backend backend))
1238 (defun vc-default-dir-extra-headers (_backend _dir)
1239 ;; Be loud by default to remind people to add code to display
1240 ;; backend specific headers.
1241 ;; XXX: change this to return nil before the release.
1243 (propertize "Extra : " 'face 'font-lock-type-face)
1244 (propertize "Please add backend specific headers here. It's easy!"
1245 'face 'font-lock-warning-face)))
1247 (defvar vc-dir-filename-mouse-map
1248 (let ((map (make-sparse-keymap)))
1249 (define-key map [mouse-2] 'vc-dir-find-file-other-window)
1251 "Local keymap for visiting a file.")
1253 (defun vc-default-dir-printer (_backend fileentry)
1254 "Pretty print FILEENTRY."
1255 ;; If you change the layout here, change vc-dir-move-to-goal-column.
1256 ;; VC backends can implement backend specific versions of this
1257 ;; function. Changes here might need to be reflected in the
1258 ;; vc-BACKEND-dir-printer functions.
1259 (let* ((isdir (vc-dir-fileinfo->directory fileentry))
1260 (state (if isdir "" (vc-dir-fileinfo->state fileentry)))
1261 (filename (vc-dir-fileinfo->name fileentry)))
1264 (format "%c" (if (vc-dir-fileinfo->marked fileentry) ?* ? ))
1265 'face 'font-lock-type-face)
1268 (format "%-20s" state)
1269 'face (cond ((eq state 'up-to-date) 'font-lock-builtin-face)
1270 ((memq state '(missing conflict)) 'font-lock-warning-face)
1271 ((eq state 'edited) 'font-lock-constant-face)
1272 (t 'font-lock-variable-name-face))
1273 'mouse-face 'highlight)
1276 (format "%s" filename)
1278 (if isdir 'font-lock-comment-delimiter-face 'font-lock-function-name-face)
1281 "Directory\nVC operations can be applied to it\nmouse-3: Pop-up menu"
1282 "File\nmouse-3: Pop-up menu")
1283 'mouse-face 'highlight
1284 'keymap vc-dir-filename-mouse-map))))
1286 (defun vc-default-extra-status-menu (_backend)
1289 (defun vc-default-status-fileinfo-extra (_backend _file)
1290 "Default absence of extra information returned for a file."
1294 ;;; Support for desktop.el (adapted from what dired.el does).
1296 (declare-function desktop-file-name "desktop" (filename dirname))
1298 (defun vc-dir-desktop-buffer-misc-data (dirname)
1299 "Auxiliary information to be saved in desktop file."
1300 (cons (desktop-file-name default-directory dirname) vc-dir-backend))
1302 (defvar desktop-missing-file-warning)
1304 (defun vc-dir-restore-desktop-buffer (_filename _buffername misc-data)
1305 "Restore a `vc-dir' buffer specified in a desktop file."
1306 (let ((dir (car misc-data))
1307 (backend (cdr misc-data)))
1308 (if (file-directory-p dir)
1310 (vc-dir dir backend)
1312 (message "Desktop: Directory %s no longer exists." dir)
1313 (when desktop-missing-file-warning (sit-for 1))
1316 (add-to-list 'desktop-buffer-mode-handlers
1317 '(vc-dir-mode . vc-dir-restore-desktop-buffer))
1322 ;;; vc-dir.el ends here