* bitmaps/README:
[bpt/emacs.git] / lisp / vc-dir.el
1 ;;; vc-dir.el --- Directory status display under VC
2
3 ;; Copyright (C) 2007, 2008
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: Dan Nicolaescu <dann@ics.uci.edu>
7 ;; Keywords: tools
8
9 ;; This file is part of GNU Emacs.
10
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.
15
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.
20
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/>.
23
24 ;;; Credits:
25
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:
30 ;;
31 ;; Alexandre Julliard <julliard@winehq.org>
32 ;; Stefan Monnier <monnier@iro.umontreal.ca>
33 ;; Tom Tromey <tromey@redhat.com>
34
35 ;;; Commentary:
36 ;;
37
38 ;;; Todo: see vc.el.
39
40 (require 'vc-hooks)
41 (require 'vc)
42 (require 'tool-bar)
43 (require 'ewoc)
44
45 ;;; Code:
46 (eval-when-compile
47 (require 'cl))
48
49 (defcustom vc-dir-mode-hook nil
50 "Normal hook run by `vc-dir-mode'.
51 See `run-hooks'."
52 :type 'hook
53 :group 'vc)
54
55 ;; Used to store information for the files displayed in the directory buffer.
56 ;; Each item displayed corresponds to one of these defstructs.
57 (defstruct (vc-dir-fileinfo
58 (:copier nil)
59 (:type list) ;So we can use `member' on lists of FIs.
60 (:constructor
61 ;; We could define it as an alias for `list'.
62 vc-dir-create-fileinfo (name state &optional extra marked directory))
63 (:conc-name vc-dir-fileinfo->))
64 name ;Keep it as first, for `member'.
65 state
66 ;; For storing backend specific information.
67 extra
68 marked
69 ;; To keep track of not updated files during a global refresh
70 needs-update
71 ;; To distinguish files and directories.
72 directory)
73
74 (defvar vc-ewoc nil)
75
76 (defvar vc-dir-process-buffer nil
77 "The buffer used for the asynchronous call that computes status.")
78
79 (defvar vc-dir-backend nil
80 "The backend used by the current *vc-dir* buffer.")
81
82 (defun vc-dir-move-to-goal-column ()
83 ;; Used to keep the cursor on the file name column.
84 (beginning-of-line)
85 (unless (eolp)
86 ;; Must be in sync with vc-default-status-printer.
87 (forward-char 25)))
88
89 (defun vc-dir-prepare-status-buffer (bname dir backend &optional create-new)
90 "Find a buffer named BNAME showing DIR, or create a new one."
91 (setq dir (expand-file-name dir))
92 (let*
93 ;; Look for another buffer name BNAME visiting the same directory.
94 ((buf (save-excursion
95 (unless create-new
96 (dolist (buffer (buffer-list))
97 (set-buffer buffer)
98 (when (and (derived-mode-p 'vc-dir-mode)
99 (eq vc-dir-backend backend)
100 (string= (expand-file-name default-directory) dir))
101 (return buffer)))))))
102 (or buf
103 ;; Create a new buffer named BNAME.
104 (with-current-buffer (create-file-buffer bname)
105 (cd dir)
106 (vc-setup-buffer (current-buffer))
107 ;; Reset the vc-parent-buffer-name so that it does not appear
108 ;; in the mode-line.
109 (setq vc-parent-buffer-name nil)
110 (current-buffer)))))
111
112 (defvar vc-dir-menu-map
113 (let ((map (make-sparse-keymap "VC-dir")))
114 (define-key map [quit]
115 '(menu-item "Quit" quit-window
116 :help "Quit"))
117 (define-key map [kill]
118 '(menu-item "Kill Update Command" vc-dir-kill-dir-status-process
119 :enable (vc-dir-busy)
120 :help "Kill the command that updates the directory buffer"))
121 (define-key map [refresh]
122 '(menu-item "Refresh" revert-buffer
123 :enable (not (vc-dir-busy))
124 :help "Refresh the contents of the directory buffer"))
125 (define-key map [remup]
126 '(menu-item "Hide up-to-date" vc-dir-hide-up-to-date
127 :help "Hide up-to-date items from display"))
128 ;; Movement.
129 (define-key map [sepmv] '("--"))
130 (define-key map [next-line]
131 '(menu-item "Next line" vc-dir-next-line
132 :help "Go to the next line" :keys "n"))
133 (define-key map [previous-line]
134 '(menu-item "Previous line" vc-dir-previous-line
135 :help "Go to the previous line"))
136 ;; Marking.
137 (define-key map [sepmrk] '("--"))
138 (define-key map [unmark-all]
139 '(menu-item "Unmark All" vc-dir-unmark-all-files
140 :help "Unmark all files that are in the same state as the current file\
141 \nWith prefix argument unmark all files"))
142 (define-key map [unmark-previous]
143 '(menu-item "Unmark previous " vc-dir-unmark-file-up
144 :help "Move to the previous line and unmark the file"))
145
146 (define-key map [mark-all]
147 '(menu-item "Mark All" vc-dir-mark-all-files
148 :help "Mark all files that are in the same state as the current file\
149 \nWith prefix argument mark all files"))
150 (define-key map [unmark]
151 '(menu-item "Unmark" vc-dir-unmark
152 :help "Unmark the current file or all files in the region"))
153
154 (define-key map [mark]
155 '(menu-item "Mark" vc-dir-mark
156 :help "Mark the current file or all files in the region"))
157
158 (define-key map [sepopn] '("--"))
159 (define-key map [qr]
160 '(menu-item "Query Replace in Files..." vc-dir-query-replace-regexp
161 :help "Replace a string in the marked files"))
162 (define-key map [se]
163 '(menu-item "Search Files..." vc-dir-search
164 :help "Search a regexp in the marked files"))
165 (define-key map [ires]
166 '(menu-item "Isearch Regexp Files..." vc-dir-isearch-regexp
167 :help "Incremental search a regexp in the marked files"))
168 (define-key map [ise]
169 '(menu-item "Isearch Files..." vc-dir-isearch
170 :help "Incremental search a string in the marked files"))
171 (define-key map [open-other]
172 '(menu-item "Open in other window" vc-dir-find-file-other-window
173 :help "Find the file on the current line, in another window"))
174 (define-key map [open]
175 '(menu-item "Open file" vc-dir-find-file
176 :help "Find the file on the current line"))
177 (define-key map [sepvcdet] '("--"))
178 ;; FIXME: This needs a key binding. And maybe a better name
179 ;; ("Insert" like PCL-CVS uses does not sound that great either)...
180 (define-key map [ins]
181 '(menu-item "Show File" vc-dir-show-fileentry
182 :help "Show a file in the VC status listing even though it might be up to date"))
183 (define-key map [annotate]
184 '(menu-item "Annotate" vc-annotate
185 :help "Display the edit history of the current file using colors"))
186 (define-key map [diff]
187 '(menu-item "Compare with Base Version" vc-diff
188 :help "Compare file set with the base version"))
189 (define-key map [log]
190 '(menu-item "Show history" vc-print-log
191 :help "List the change log of the current file set in a window"))
192 ;; VC commands.
193 (define-key map [sepvccmd] '("--"))
194 (define-key map [update]
195 '(menu-item "Update to latest version" vc-update
196 :help "Update the current fileset's files to their tip revisions"))
197 (define-key map [revert]
198 '(menu-item "Revert to base version" vc-revert
199 :help "Revert working copies of the selected fileset to their repository contents."))
200 (define-key map [next-action]
201 ;; FIXME: This really really really needs a better name!
202 ;; And a key binding too.
203 '(menu-item "Check In/Out" vc-next-action
204 :help "Do the next logical version control operation on the current fileset"))
205 (define-key map [register]
206 '(menu-item "Register" vc-register
207 :help "Register file set into the version control system"))
208 map)
209 "Menu for dispatcher status")
210
211 ;; VC backends can use this to add mode-specific menu items to
212 ;; vc-dir-menu-map.
213 (defun vc-dir-menu-map-filter (orig-binding)
214 (when (and (symbolp orig-binding) (fboundp orig-binding))
215 (setq orig-binding (indirect-function orig-binding)))
216 (let ((ext-binding
217 (when (derived-mode-p 'vc-dir-mode)
218 (vc-call-backend vc-dir-backend 'extra-status-menu))))
219 (if (null ext-binding)
220 orig-binding
221 (append orig-binding
222 '("----")
223 ext-binding))))
224
225 (defvar vc-dir-mode-map
226 (let ((map (make-sparse-keymap)))
227 ;; VC commands
228 (define-key map "v" 'vc-next-action) ;; C-x v v
229 (define-key map "=" 'vc-diff) ;; C-x v =
230 (define-key map "i" 'vc-register) ;; C-x v i
231 (define-key map "+" 'vc-update) ;; C-x v +
232 (define-key map "l" 'vc-print-log) ;; C-x v l
233 ;; More confusing than helpful, probably
234 ;;(define-key map "R" 'vc-revert) ;; u is taken by dispatcher unmark.
235 ;;(define-key map "A" 'vc-annotate) ;; g is taken by dispatcher refresh
236 ;; Marking.
237 (define-key map "m" 'vc-dir-mark)
238 (define-key map "M" 'vc-dir-mark-all-files)
239 (define-key map "u" 'vc-dir-unmark)
240 (define-key map "U" 'vc-dir-unmark-all-files)
241 (define-key map "\C-?" 'vc-dir-unmark-file-up)
242 (define-key map "\M-\C-?" 'vc-dir-unmark-all-files)
243 ;; Movement.
244 (define-key map "n" 'vc-dir-next-line)
245 (define-key map " " 'vc-dir-next-line)
246 (define-key map "\t" 'vc-dir-next-directory)
247 (define-key map "p" 'vc-dir-previous-line)
248 (define-key map [backtab] 'vc-dir-previous-directory)
249 ;;; Rebind paragraph-movement commands.
250 (define-key map "\M-}" 'vc-dir-next-directory)
251 (define-key map "\M-{" 'vc-dir-previous-directory)
252 (define-key map [C-down] 'vc-dir-next-directory)
253 (define-key map [C-up] 'vc-dir-previous-directory)
254 ;; The remainder.
255 (define-key map "f" 'vc-dir-find-file)
256 (define-key map "\C-m" 'vc-dir-find-file)
257 (define-key map "o" 'vc-dir-find-file-other-window)
258 (define-key map "\C-c\C-c" 'vc-dir-kill-dir-status-process)
259 (define-key map [down-mouse-3] 'vc-dir-menu)
260 (define-key map [mouse-2] 'vc-dir-toggle-mark)
261 (define-key map "x" 'vc-dir-hide-up-to-date)
262 (define-key map "S" 'vc-dir-search) ;; FIXME: Maybe use A like dired?
263 (define-key map "Q" 'vc-dir-query-replace-regexp)
264 (define-key map (kbd "M-s a C-s") 'vc-dir-isearch)
265 (define-key map (kbd "M-s a M-C-s") 'vc-dir-isearch-regexp)
266
267 ;; Hook up the menu.
268 (define-key map [menu-bar vc-dir-mode]
269 `(menu-item
270 ;; VC backends can use this to add mode-specific menu items to
271 ;; vc-dir-menu-map.
272 "VC-dir" ,vc-dir-menu-map :filter vc-dir-menu-map-filter))
273 map)
274 "Keymap for directory buffer.")
275
276 (defmacro vc-at-event (event &rest body)
277 "Evaluate `body' with point located at event-start of `event'.
278 If `body' uses `event', it should be a variable,
279 otherwise it will be evaluated twice."
280 (let ((posn (make-symbol "vc-at-event-posn")))
281 `(let ((,posn (event-start ,event)))
282 (save-excursion
283 (set-buffer (window-buffer (posn-window ,posn)))
284 (goto-char (posn-point ,posn))
285 ,@body))))
286
287 (defun vc-dir-menu (e)
288 "Popup the dispatcher status menu."
289 (interactive "e")
290 (vc-at-event e (popup-menu vc-dir-menu-map e)))
291
292 (defvar vc-dir-tool-bar-map
293 (let ((map (make-sparse-keymap)))
294 (tool-bar-local-item-from-menu 'vc-dir-find-file "open"
295 map vc-dir-mode-map)
296 (tool-bar-local-item "bookmark_add"
297 'vc-dir-toggle-mark 'vc-dir-toggle-mark map
298 :help "Toggle mark on current item")
299 (tool-bar-local-item-from-menu 'vc-dir-previous-line "left-arrow"
300 map vc-dir-mode-map
301 :rtl "right-arrow")
302 (tool-bar-local-item-from-menu 'vc-dir-next-line "right-arrow"
303 map vc-dir-mode-map
304 :rtl "left-arrow")
305 (tool-bar-local-item-from-menu 'vc-print-log "info"
306 map vc-dir-mode-map)
307 (tool-bar-local-item-from-menu 'revert-buffer "refresh"
308 map vc-dir-mode-map)
309 (tool-bar-local-item-from-menu 'nonincremental-search-forward
310 "search" map)
311 (tool-bar-local-item-from-menu 'vc-dir-query-replace-regexp
312 "search-replace" map vc-dir-mode-map)
313 (tool-bar-local-item-from-menu 'vc-dir-kill-dir-status-process "cancel"
314 map vc-dir-mode-map)
315 (tool-bar-local-item-from-menu 'quit-window "exit"
316 map vc-dir-mode-map)
317 map))
318
319 (defun vc-dir-node-directory (node)
320 ;; Compute the directory for NODE.
321 ;; If it's a directory node, get it from the the node.
322 (let ((data (ewoc-data node)))
323 (or (vc-dir-fileinfo->directory data)
324 ;; Otherwise compute it from the file name.
325 (file-name-directory
326 (expand-file-name
327 (vc-dir-fileinfo->name data))))))
328
329 (defun vc-dir-update (entries buffer &optional noinsert)
330 "Update BUFFER's ewoc from the list of ENTRIES.
331 If NOINSERT, ignore elements on ENTRIES which are not in the ewoc."
332 ;; Add ENTRIES to the vc-dir buffer BUFFER.
333 (with-current-buffer buffer
334 ;; Insert the entries sorted by name into the ewoc.
335 ;; We assume the ewoc is sorted too, which should be the
336 ;; case if we always add entries with vc-dir-update.
337 (setq entries
338 ;; Sort: first files and then subdirectories.
339 ;; XXX: this is VERY inefficient, it computes the directory
340 ;; names too many times
341 (sort entries
342 (lambda (entry1 entry2)
343 (let ((dir1 (file-name-directory (expand-file-name (car entry1))))
344 (dir2 (file-name-directory (expand-file-name (car entry2)))))
345 (cond
346 ((string< dir1 dir2) t)
347 ((not (string= dir1 dir2)) nil)
348 ((string< (car entry1) (car entry2))))))))
349 ;; Insert directory entries in the right places.
350 (let ((entry (car entries))
351 (node (ewoc-nth vc-ewoc 0)))
352 ;; Insert . if it is not present.
353 (unless node
354 (let ((rd (file-relative-name default-directory)))
355 (ewoc-enter-last
356 vc-ewoc (vc-dir-create-fileinfo
357 rd nil nil nil (expand-file-name default-directory))))
358 (setq node (ewoc-nth vc-ewoc 0)))
359
360 (while (and entry node)
361 (let* ((entryfile (car entry))
362 (entrydir (file-name-directory (expand-file-name entryfile)))
363 (nodedir (vc-dir-node-directory node)))
364 (cond
365 ;; First try to find the directory.
366 ((string-lessp nodedir entrydir)
367 (setq node (ewoc-next vc-ewoc node)))
368 ((string-equal nodedir entrydir)
369 ;; Found the directory, find the place for the file name.
370 (let ((nodefile (vc-dir-fileinfo->name (ewoc-data node))))
371 (cond
372 ((string-lessp nodefile entryfile)
373 (setq node (ewoc-next vc-ewoc node)))
374 ((string-equal nodefile entryfile)
375 (setf (vc-dir-fileinfo->state (ewoc-data node)) (nth 1 entry))
376 (setf (vc-dir-fileinfo->extra (ewoc-data node)) (nth 2 entry))
377 (setf (vc-dir-fileinfo->needs-update (ewoc-data node)) nil)
378 (ewoc-invalidate vc-ewoc node)
379 (setq entries (cdr entries))
380 (setq entry (car entries))
381 (setq node (ewoc-next vc-ewoc node)))
382 (t
383 (ewoc-enter-before vc-ewoc node
384 (apply 'vc-dir-create-fileinfo entry))
385 (setq entries (cdr entries))
386 (setq entry (car entries))))))
387 (t
388 ;; We might need to insert a directory node if the
389 ;; previous node was in a different directory.
390 (let* ((rd (file-relative-name entrydir))
391 (prev-node (ewoc-prev vc-ewoc node))
392 (prev-dir (vc-dir-node-directory prev-node)))
393 (unless (string-equal entrydir prev-dir)
394 (ewoc-enter-before
395 vc-ewoc node (vc-dir-create-fileinfo rd nil nil nil entrydir))))
396 ;; Now insert the node itself.
397 (ewoc-enter-before vc-ewoc node
398 (apply 'vc-dir-create-fileinfo entry))
399 (setq entries (cdr entries) entry (car entries))))))
400 ;; We're past the last node, all remaining entries go to the end.
401 (unless (or node noinsert)
402 (let ((lastdir (vc-dir-node-directory (ewoc-nth vc-ewoc -1))))
403 (dolist (entry entries)
404 (let ((entrydir (file-name-directory (expand-file-name (car entry)))))
405 ;; Insert a directory node if needed.
406 (unless (string-equal lastdir entrydir)
407 (setq lastdir entrydir)
408 (let ((rd (file-relative-name entrydir)))
409 (ewoc-enter-last
410 vc-ewoc (vc-dir-create-fileinfo rd nil nil nil entrydir))))
411 ;; Now insert the node itself.
412 (ewoc-enter-last vc-ewoc
413 (apply 'vc-dir-create-fileinfo entry)))))))))
414
415 (defun vc-dir-busy ()
416 (and (buffer-live-p vc-dir-process-buffer)
417 (get-buffer-process vc-dir-process-buffer)))
418
419 (defun vc-dir-kill-dir-status-process ()
420 "Kill the temporary buffer and associated process."
421 (interactive)
422 (when (buffer-live-p vc-dir-process-buffer)
423 (let ((proc (get-buffer-process vc-dir-process-buffer)))
424 (when proc (delete-process proc))
425 (setq vc-dir-process-buffer nil)
426 (setq mode-line-process nil))))
427
428 (defun vc-dir-kill-query ()
429 ;; Make sure that when the status buffer is killed the update
430 ;; process running in background is also killed.
431 (if (vc-dir-busy)
432 (when (y-or-n-p "Status update process running, really kill status buffer? ")
433 (vc-dir-kill-dir-status-process)
434 t)
435 t))
436
437 (defun vc-dir-next-line (arg)
438 "Go to the next line.
439 If a prefix argument is given, move by that many lines."
440 (interactive "p")
441 (with-no-warnings
442 (ewoc-goto-next vc-ewoc arg)
443 (vc-dir-move-to-goal-column)))
444
445 (defun vc-dir-previous-line (arg)
446 "Go to the previous line.
447 If a prefix argument is given, move by that many lines."
448 (interactive "p")
449 (ewoc-goto-prev vc-ewoc arg)
450 (vc-dir-move-to-goal-column))
451
452 (defun vc-dir-next-directory ()
453 "Go to the next directory."
454 (interactive)
455 (let ((orig (point)))
456 (if
457 (catch 'foundit
458 (while t
459 (let* ((next (ewoc-next vc-ewoc (ewoc-locate vc-ewoc))))
460 (cond ((not next)
461 (throw 'foundit t))
462 (t
463 (progn
464 (ewoc-goto-node vc-ewoc next)
465 (vc-dir-move-to-goal-column)
466 (if (vc-dir-fileinfo->directory (ewoc-data next))
467 (throw 'foundit nil))))))))
468 (goto-char orig))))
469
470 (defun vc-dir-previous-directory ()
471 "Go to the previous directory."
472 (interactive)
473 (let ((orig (point)))
474 (if
475 (catch 'foundit
476 (while t
477 (let* ((prev (ewoc-prev vc-ewoc (ewoc-locate vc-ewoc))))
478 (cond ((not prev)
479 (throw 'foundit t))
480 (t
481 (progn
482 (ewoc-goto-node vc-ewoc prev)
483 (vc-dir-move-to-goal-column)
484 (if (vc-dir-fileinfo->directory (ewoc-data prev))
485 (throw 'foundit nil))))))))
486 (goto-char orig))))
487
488 (defun vc-dir-mark-unmark (mark-unmark-function)
489 (if (use-region-p)
490 (let ((firstl (line-number-at-pos (region-beginning)))
491 (lastl (line-number-at-pos (region-end))))
492 (save-excursion
493 (goto-char (region-beginning))
494 (while (<= (line-number-at-pos) lastl)
495 (funcall mark-unmark-function))))
496 (funcall mark-unmark-function)))
497
498 (defun vc-dir-parent-marked-p (arg)
499 ;; Return nil if none of the parent directories of arg is marked.
500 (let* ((argdir (vc-dir-node-directory arg))
501 (arglen (length argdir))
502 (crt arg)
503 data dir)
504 ;; Go through the predecessors, checking if any directory that is
505 ;; a parent is marked.
506 (while (setq crt (ewoc-prev vc-ewoc crt))
507 (setq data (ewoc-data crt))
508 (setq dir (vc-dir-node-directory crt))
509 (when (and (vc-dir-fileinfo->directory data)
510 (vc-string-prefix-p dir argdir))
511 (when (vc-dir-fileinfo->marked data)
512 (error "Cannot mark `%s', parent directory `%s' marked"
513 (vc-dir-fileinfo->name (ewoc-data arg))
514 (vc-dir-fileinfo->name data)))))
515 nil))
516
517 (defun vc-dir-children-marked-p (arg)
518 ;; Return nil if none of the children of arg is marked.
519 (let* ((argdir-re (concat "\\`" (regexp-quote (vc-dir-node-directory arg))))
520 (is-child t)
521 (crt arg)
522 data dir)
523 (while (and is-child (setq crt (ewoc-next vc-ewoc crt)))
524 (setq data (ewoc-data crt))
525 (setq dir (vc-dir-node-directory crt))
526 (if (string-match argdir-re dir)
527 (when (vc-dir-fileinfo->marked data)
528 (error "Cannot mark `%s', child `%s' marked"
529 (vc-dir-fileinfo->name (ewoc-data arg))
530 (vc-dir-fileinfo->name data)))
531 ;; We are done, we got to an entry that is not a child of `arg'.
532 (setq is-child nil)))
533 nil))
534
535 (defun vc-dir-mark-file (&optional arg)
536 ;; Mark ARG or the current file and move to the next line.
537 (let* ((crt (or arg (ewoc-locate vc-ewoc)))
538 (file (ewoc-data crt))
539 (isdir (vc-dir-fileinfo->directory file)))
540 (when (or (and isdir (not (vc-dir-children-marked-p crt)))
541 (and (not isdir) (not (vc-dir-parent-marked-p crt))))
542 (setf (vc-dir-fileinfo->marked file) t)
543 (ewoc-invalidate vc-ewoc crt)
544 (unless (or arg (mouse-event-p last-command-event))
545 (vc-dir-next-line 1)))))
546
547 (defun vc-dir-mark ()
548 "Mark the current file or all files in the region.
549 If the region is active, mark all the files in the region.
550 Otherwise mark the file on the current line and move to the next
551 line."
552 (interactive)
553 (vc-dir-mark-unmark 'vc-dir-mark-file))
554
555 (defun vc-dir-mark-all-files (arg)
556 "Mark all files with the same state as the current one.
557 With a prefix argument mark all files.
558 If the current entry is a directory, mark all child files.
559
560 The commands operate on files that are on the same state.
561 This command is intended to make it easy to select all files that
562 share the same state."
563 (interactive "P")
564 (if arg
565 ;; Mark all files.
566 (progn
567 ;; First check that no directory is marked, we can't mark
568 ;; files in that case.
569 (ewoc-map
570 (lambda (filearg)
571 (when (and (vc-dir-fileinfo->directory filearg)
572 (vc-dir-fileinfo->marked filearg))
573 (error "Cannot mark all files, directory `%s' marked"
574 (vc-dir-fileinfo->name filearg))))
575 vc-ewoc)
576 (ewoc-map
577 (lambda (filearg)
578 (unless (vc-dir-fileinfo->marked filearg)
579 (setf (vc-dir-fileinfo->marked filearg) t)
580 t))
581 vc-ewoc))
582 (let ((data (ewoc-data (ewoc-locate vc-ewoc))))
583 (if (vc-dir-fileinfo->directory data)
584 ;; It's a directory, mark child files.
585 (let ((crt (ewoc-locate vc-ewoc)))
586 (unless (vc-dir-children-marked-p crt)
587 (while (setq crt (ewoc-next vc-ewoc crt))
588 (let ((crt-data (ewoc-data crt)))
589 (unless (vc-dir-fileinfo->directory crt-data)
590 (setf (vc-dir-fileinfo->marked crt-data) t)
591 (ewoc-invalidate vc-ewoc crt))))))
592 ;; It's a file
593 (let ((state (vc-dir-fileinfo->state data))
594 (crt (ewoc-nth vc-ewoc 0)))
595 (while crt
596 (let ((crt-data (ewoc-data crt)))
597 (when (and (not (vc-dir-fileinfo->marked crt-data))
598 (eq (vc-dir-fileinfo->state crt-data) state)
599 (not (vc-dir-fileinfo->directory crt-data)))
600 (vc-dir-mark-file crt)))
601 (setq crt (ewoc-next vc-ewoc crt))))))))
602
603 (defun vc-dir-unmark-file ()
604 ;; Unmark the current file and move to the next line.
605 (let* ((crt (ewoc-locate vc-ewoc))
606 (file (ewoc-data crt)))
607 (setf (vc-dir-fileinfo->marked file) nil)
608 (ewoc-invalidate vc-ewoc crt)
609 (unless (mouse-event-p last-command-event)
610 (vc-dir-next-line 1))))
611
612 (defun vc-dir-unmark ()
613 "Unmark the current file or all files in the region.
614 If the region is active, unmark all the files in the region.
615 Otherwise mark the file on the current line and move to the next
616 line."
617 (interactive)
618 (vc-dir-mark-unmark 'vc-dir-unmark-file))
619
620 (defun vc-dir-unmark-file-up ()
621 "Move to the previous line and unmark the file."
622 (interactive)
623 ;; If we're on the first line, we won't move up, but we will still
624 ;; remove the mark. This seems a bit odd but it is what buffer-menu
625 ;; does.
626 (let* ((prev (ewoc-goto-prev vc-ewoc 1))
627 (file (ewoc-data prev)))
628 (setf (vc-dir-fileinfo->marked file) nil)
629 (ewoc-invalidate vc-ewoc prev)
630 (vc-dir-move-to-goal-column)))
631
632 (defun vc-dir-unmark-all-files (arg)
633 "Unmark all files with the same state as the current one.
634 With a prefix argument unmark all files.
635 If the current entry is a directory, unmark all the child files.
636
637 The commands operate on files that are on the same state.
638 This command is intended to make it easy to deselect all files
639 that share the same state."
640 (interactive "P")
641 (if arg
642 (ewoc-map
643 (lambda (filearg)
644 (when (vc-dir-fileinfo->marked filearg)
645 (setf (vc-dir-fileinfo->marked filearg) nil)
646 t))
647 vc-ewoc)
648 (let* ((crt (ewoc-locate vc-ewoc))
649 (data (ewoc-data crt)))
650 (if (vc-dir-fileinfo->directory data)
651 ;; It's a directory, unmark child files.
652 (while (setq crt (ewoc-next vc-ewoc crt))
653 (let ((crt-data (ewoc-data crt)))
654 (unless (vc-dir-fileinfo->directory crt-data)
655 (setf (vc-dir-fileinfo->marked crt-data) nil)
656 (ewoc-invalidate vc-ewoc crt))))
657 ;; It's a file
658 (let ((crt-state (vc-dir-fileinfo->state (ewoc-data crt))))
659 (ewoc-map
660 (lambda (filearg)
661 (when (and (vc-dir-fileinfo->marked filearg)
662 (eq (vc-dir-fileinfo->state filearg) crt-state))
663 (setf (vc-dir-fileinfo->marked filearg) nil)
664 t))
665 vc-ewoc))))))
666
667 (defun vc-dir-toggle-mark-file ()
668 (let* ((crt (ewoc-locate vc-ewoc))
669 (file (ewoc-data crt)))
670 (if (vc-dir-fileinfo->marked file)
671 (vc-dir-unmark-file)
672 (vc-dir-mark-file))))
673
674 (defun vc-dir-toggle-mark (e)
675 (interactive "e")
676 (vc-at-event e (vc-dir-mark-unmark 'vc-dir-toggle-mark-file)))
677
678 (defun vc-dir-delete-file ()
679 "Delete the marked files, or the current file if no marks."
680 (interactive)
681 (mapc 'vc-delete-file (or (vc-dir-marked-files)
682 (list (vc-dir-current-file)))))
683
684 (defun vc-dir-find-file ()
685 "Find the file on the current line."
686 (interactive)
687 (find-file (vc-dir-current-file)))
688
689 (defun vc-dir-find-file-other-window ()
690 "Find the file on the current line, in another window."
691 (interactive)
692 (find-file-other-window (vc-dir-current-file)))
693
694 (defun vc-dir-isearch ()
695 "Search for a string through all marked buffers using Isearch."
696 (interactive)
697 (multi-isearch-files
698 (mapcar 'car (vc-dir-marked-only-files-and-states))))
699
700 (defun vc-dir-isearch-regexp ()
701 "Search for a regexp through all marked buffers using Isearch."
702 (interactive)
703 (multi-isearch-files-regexp
704 (mapcar 'car (vc-dir-marked-only-files-and-states))))
705
706 (defun vc-dir-search (regexp)
707 "Search through all marked files for a match for REGEXP.
708 For marked directories, use the files displayed from those directories.
709 Stops when a match is found.
710 To continue searching for next match, use command \\[tags-loop-continue]."
711 (interactive "sSearch marked files (regexp): ")
712 (tags-search regexp '(mapcar 'car (vc-dir-marked-only-files-and-states))))
713
714 (defun vc-dir-query-replace-regexp (from to &optional delimited)
715 "Do `query-replace-regexp' of FROM with TO, on all marked files.
716 For marked directories, use the files displayed from those directories.
717 If a directory is marked, then use the files displayed for that directory.
718 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
719 If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
720 with the command \\[tags-loop-continue]."
721 ;; FIXME: this is almost a copy of `dired-do-replace-regexp'. This
722 ;; should probably be made generic and used in both places instead of
723 ;; duplicating it here.
724 (interactive
725 (let ((common
726 (query-replace-read-args
727 "Query replace regexp in marked files" t t)))
728 (list (nth 0 common) (nth 1 common) (nth 2 common))))
729 (dolist (file (mapcar 'car (vc-dir-marked-only-files-and-states)))
730 (let ((buffer (get-file-buffer file)))
731 (if (and buffer (with-current-buffer buffer
732 buffer-read-only))
733 (error "File `%s' is visited read-only" file))))
734 (tags-query-replace from to delimited
735 '(mapcar 'car (vc-dir-marked-only-files-and-states))))
736
737 (defun vc-dir-current-file ()
738 (let ((node (ewoc-locate vc-ewoc)))
739 (unless node
740 (error "No file available"))
741 (expand-file-name (vc-dir-fileinfo->name (ewoc-data node)))))
742
743 (defun vc-dir-marked-files ()
744 "Return the list of marked files."
745 (mapcar
746 (lambda (elem) (expand-file-name (vc-dir-fileinfo->name elem)))
747 (ewoc-collect vc-ewoc 'vc-dir-fileinfo->marked)))
748
749 (defun vc-dir-marked-only-files-and-states ()
750 "Return the list of conses (FILE . STATE) for the marked files.
751 For marked directories return the corresponding conses for the
752 child files."
753 (let ((crt (ewoc-nth vc-ewoc 0))
754 result)
755 (while crt
756 (let ((crt-data (ewoc-data crt)))
757 (if (vc-dir-fileinfo->marked crt-data)
758 ;; FIXME: use vc-dir-child-files-and-states here instead of duplicating it.
759 (if (vc-dir-fileinfo->directory crt-data)
760 (let* ((dir (vc-dir-fileinfo->directory crt-data))
761 (dirlen (length dir))
762 data)
763 (while
764 (and (setq crt (ewoc-next vc-ewoc crt))
765 (vc-string-prefix-p dir
766 (progn
767 (setq data (ewoc-data crt))
768 (vc-dir-node-directory crt))))
769 (unless (vc-dir-fileinfo->directory data)
770 (push
771 (cons (expand-file-name (vc-dir-fileinfo->name data))
772 (vc-dir-fileinfo->state data))
773 result))))
774 (push (cons (expand-file-name (vc-dir-fileinfo->name crt-data))
775 (vc-dir-fileinfo->state crt-data))
776 result)
777 (setq crt (ewoc-next vc-ewoc crt)))
778 (setq crt (ewoc-next vc-ewoc crt)))))
779 result))
780
781 (defun vc-dir-child-files-and-states ()
782 "Return the list of conses (FILE . STATE) for child files of the current entry if it's a directory.
783 If it is a file, return the corresponding cons for the file itself."
784 (let* ((crt (ewoc-locate vc-ewoc))
785 (crt-data (ewoc-data crt))
786 result)
787 (if (vc-dir-fileinfo->directory crt-data)
788 (let* ((dir (vc-dir-fileinfo->directory crt-data))
789 (dirlen (length dir))
790 data)
791 (while
792 (and (setq crt (ewoc-next vc-ewoc crt))
793 (vc-string-prefix-p dir (progn
794 (setq data (ewoc-data crt))
795 (vc-dir-node-directory crt))))
796 (unless (vc-dir-fileinfo->directory data)
797 (push
798 (cons (expand-file-name (vc-dir-fileinfo->name data))
799 (vc-dir-fileinfo->state data))
800 result))))
801 (push
802 (cons (expand-file-name (vc-dir-fileinfo->name crt-data))
803 (vc-dir-fileinfo->state crt-data)) result))
804 result))
805
806 (defun vc-dir-recompute-file-state (fname def-dir)
807 (let* ((file-short (file-relative-name fname def-dir))
808 (remove-me-when-CVS-works
809 (when (eq vc-dir-backend 'CVS)
810 ;; FIXME: Warning: UGLY HACK. The CVS backend caches the state
811 ;; info, this forces the backend to update it.
812 (vc-call-backend vc-dir-backend 'registered fname)))
813 (state (vc-call-backend vc-dir-backend 'state fname))
814 (extra (vc-call-backend vc-dir-backend
815 'status-fileinfo-extra fname)))
816 (list file-short state extra)))
817
818 (defun vc-dir-find-child-files (dirname)
819 ;; Give a DIRNAME string return the list of all child files shown in
820 ;; the current *vc-dir* buffer.
821 (let ((crt (ewoc-nth vc-ewoc 0))
822 children
823 dname)
824 ;; Find DIR
825 (while (and crt (not (vc-string-prefix-p
826 dirname (vc-dir-node-directory crt))))
827 (setq crt (ewoc-next vc-ewoc crt)))
828 (while (and crt (vc-string-prefix-p
829 dirname
830 (setq dname (vc-dir-node-directory crt))))
831 (let ((data (ewoc-data crt)))
832 (unless (vc-dir-fileinfo->directory data)
833 (push (expand-file-name (vc-dir-fileinfo->name data)) children)))
834 (setq crt (ewoc-next vc-ewoc crt)))
835 children))
836
837 (defun vc-dir-resync-directory-files (dirname)
838 ;; Update the entries for all the child files of DIRNAME shown in
839 ;; the current *vc-dir* buffer.
840 (let ((files (vc-dir-find-child-files dirname))
841 (ddir (expand-file-name default-directory))
842 fileentries)
843 (when files
844 (dolist (crt files)
845 (push (vc-dir-recompute-file-state crt ddir)
846 fileentries))
847 (vc-dir-update fileentries (current-buffer)))))
848
849 (defun vc-dir-resynch-file (&optional fname)
850 "Update the entries for FILE in any directory buffers that list it."
851 (let ((file (or fname (expand-file-name buffer-file-name)))
852 (found-vc-dir-buf nil))
853 (save-excursion
854 (dolist (status-buf (buffer-list))
855 (set-buffer status-buf)
856 ;; look for a vc-dir buffer that might show this file.
857 (when (derived-mode-p 'vc-dir-mode)
858 (setq found-vc-dir-buf t)
859 (let ((ddir (expand-file-name default-directory)))
860 (when (vc-string-prefix-p ddir file)
861 (if (file-directory-p file)
862 (vc-dir-resync-directory-files file)
863 (vc-dir-update
864 (list (vc-dir-recompute-file-state file ddir))
865 status-buf)))))))
866 ;; We didn't find any vc-dir buffers, remove the hook, it is
867 ;; not needed.
868 (unless found-vc-dir-buf
869 (remove-hook 'after-save-hook 'vc-dir-resynch-file))))
870
871 (defvar use-vc-backend) ;; dynamically bound
872
873 (define-derived-mode vc-dir-mode special-mode "VC dir"
874 "Major mode for dispatcher directory buffers.
875 Marking/Unmarking key bindings and actions:
876 m - marks a file/directory or if the region is active, mark all the files
877 in region.
878 Restrictions: - a file cannot be marked if any parent directory is marked
879 - a directory cannot be marked if any child file or
880 directory is marked
881 u - marks a file/directory or if the region is active, unmark all the files
882 in region.
883 M - if the cursor is on a file: mark all the files with the same state as
884 the current file
885 - if the cursor is on a directory: mark all child files
886 - with a prefix argument: mark all files
887 U - if the cursor is on a file: unmark all the files with the same state
888 as the current file
889 - if the cursor is on a directory: unmark all child files
890 - with a prefix argument: unmark all files
891
892
893 \\{vc-dir-mode-map}"
894 (set (make-local-variable 'vc-dir-backend) use-vc-backend)
895 (setq buffer-read-only t)
896 (when (boundp 'tool-bar-map)
897 (set (make-local-variable 'tool-bar-map) vc-dir-tool-bar-map))
898 (let ((buffer-read-only nil))
899 (erase-buffer)
900 (set (make-local-variable 'vc-dir-process-buffer) nil)
901 (set (make-local-variable 'vc-ewoc)
902 (ewoc-create #'vc-dir-status-printer
903 (vc-dir-headers vc-dir-backend default-directory)))
904 (set (make-local-variable 'revert-buffer-function)
905 'vc-dir-revert-buffer-function)
906 (set (make-local-variable 'list-buffers-directory)
907 (expand-file-name default-directory))
908 (add-hook 'after-save-hook 'vc-dir-resynch-file)
909 ;; Make sure that if the directory buffer is killed, the update
910 ;; process running in the background is also killed.
911 (add-hook 'kill-buffer-query-functions 'vc-dir-kill-query nil t)
912 (vc-dir-refresh)))
913
914 (defun vc-dir-headers (backend dir)
915 "Display the headers in the *VC dir* buffer.
916 It calls the `status-extra-headers' backend method to display backend
917 specific headers."
918 (concat
919 (propertize "VC backend : " 'face 'font-lock-type-face)
920 (propertize (format "%s\n" backend) 'face 'font-lock-variable-name-face)
921 (propertize "Working dir: " 'face 'font-lock-type-face)
922 (propertize (format "%s\n" dir) 'face 'font-lock-variable-name-face)
923 (vc-call-backend backend 'status-extra-headers dir)
924 "\n"))
925
926 (defun vc-dir-refresh-files (files default-state)
927 "Refresh some files in the *VC-dir* buffer."
928 (let ((def-dir default-directory)
929 (backend vc-dir-backend))
930 (vc-set-mode-line-busy-indicator)
931 ;; Call the `dir-status-file' backend function.
932 ;; `dir-status-file' is supposed to be asynchronous.
933 ;; It should compute the results, and then call the function
934 ;; passed as an argument in order to update the vc-dir buffer
935 ;; with the results.
936 (unless (buffer-live-p vc-dir-process-buffer)
937 (setq vc-dir-process-buffer
938 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
939 (lexical-let ((buffer (current-buffer)))
940 (with-current-buffer vc-dir-process-buffer
941 (cd def-dir)
942 (erase-buffer)
943 (vc-call-backend
944 backend 'dir-status-files def-dir files default-state
945 (lambda (entries &optional more-to-come)
946 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
947 ;; If MORE-TO-COME is true, then more updates will come from
948 ;; the asynchronous process.
949 (with-current-buffer buffer
950 (vc-dir-update entries buffer)
951 (unless more-to-come
952 (setq mode-line-process nil)
953 ;; Remove the ones that haven't been updated at all.
954 ;; Those not-updated are those whose state is nil because the
955 ;; file/dir doesn't exist and isn't versioned.
956 (ewoc-filter vc-ewoc
957 (lambda (info)
958 ;; The state for directory entries might
959 ;; have been changed to 'up-to-date,
960 ;; reset it, othewise it will be removed when doing 'x'
961 ;; next time.
962 ;; FIXME: There should be a more elegant way to do this.
963 (when (and (vc-dir-fileinfo->directory info)
964 (eq (vc-dir-fileinfo->state info)
965 'up-to-date))
966 (setf (vc-dir-fileinfo->state info) nil))
967
968 (not (vc-dir-fileinfo->needs-update info))))))))))))
969
970 (defun vc-dir-revert-buffer-function (&optional ignore-auto noconfirm)
971 (vc-dir-refresh))
972
973 (defun vc-dir-refresh ()
974 "Refresh the contents of the *VC-dir* buffer.
975 Throw an error if another update process is in progress."
976 (interactive)
977 (if (vc-dir-busy)
978 (error "Another update process is in progress, cannot run two at a time")
979 (let ((def-dir default-directory)
980 (backend vc-dir-backend))
981 (vc-set-mode-line-busy-indicator)
982 ;; Call the `dir-status' backend function.
983 ;; `dir-status' is supposed to be asynchronous.
984 ;; It should compute the results, and then call the function
985 ;; passed as an argument in order to update the vc-dir buffer
986 ;; with the results.
987
988 ;; Create a buffer that can be used by `dir-status' and call
989 ;; `dir-status' with this buffer as the current buffer. Use
990 ;; `vc-dir-process-buffer' to remember this buffer, so that
991 ;; it can be used later to kill the update process in case it
992 ;; takes too long.
993 (unless (buffer-live-p vc-dir-process-buffer)
994 (setq vc-dir-process-buffer
995 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
996 ;; set the needs-update flag on all non-directory entries
997 (ewoc-map (lambda (info)
998 (unless (vc-dir-fileinfo->directory info)
999 (setf (vc-dir-fileinfo->needs-update info) t) nil))
1000 vc-ewoc)
1001 (lexical-let ((buffer (current-buffer)))
1002 (with-current-buffer vc-dir-process-buffer
1003 (cd def-dir)
1004 (erase-buffer)
1005 (vc-call-backend
1006 backend 'dir-status def-dir
1007 (lambda (entries &optional more-to-come)
1008 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
1009 ;; If MORE-TO-COME is true, then more updates will come from
1010 ;; the asynchronous process.
1011 (with-current-buffer buffer
1012 (vc-dir-update entries buffer)
1013 (unless more-to-come
1014 (let ((remaining
1015 (ewoc-collect
1016 vc-ewoc 'vc-dir-fileinfo->needs-update)))
1017 (if remaining
1018 (vc-dir-refresh-files
1019 (mapcar 'vc-dir-fileinfo->name remaining)
1020 'up-to-date)
1021 (setq mode-line-process nil))))))))))))
1022
1023 (defun vc-dir-show-fileentry (file)
1024 "Insert an entry for a specific file into the current *VC-dir* listing.
1025 This is typically used if the file is up-to-date (or has been added
1026 outside of VC) and one wants to do some operation on it."
1027 (interactive "fShow file: ")
1028 (vc-dir-update (list (list (file-relative-name file) (vc-state file))) (current-buffer)))
1029
1030 (defun vc-dir-hide-up-to-date ()
1031 "Hide up-to-date items from display."
1032 (interactive)
1033 (let ((crt (ewoc-nth vc-ewoc -1))
1034 (first (ewoc-nth vc-ewoc 0)))
1035 ;; Go over from the last item to the first and remove the
1036 ;; up-to-date files and directories with no child files.
1037 (while (not (eq crt first))
1038 (let* ((data (ewoc-data crt))
1039 (dir (vc-dir-fileinfo->directory data))
1040 (next (ewoc-next vc-ewoc crt))
1041 (prev (ewoc-prev vc-ewoc crt))
1042 ;; ewoc-delete does not work without this...
1043 (inhibit-read-only t))
1044 (when (or
1045 ;; Remove directories with no child files.
1046 (and dir
1047 (or
1048 ;; Nothing follows this directory.
1049 (not next)
1050 ;; Next item is a directory.
1051 (vc-dir-fileinfo->directory (ewoc-data next))))
1052 ;; Remove files in the up-to-date state.
1053 (eq (vc-dir-fileinfo->state data) 'up-to-date))
1054 (ewoc-delete vc-ewoc crt))
1055 (setq crt prev)))))
1056
1057 (defun vc-dir-status-printer (fileentry)
1058 (vc-call-backend vc-dir-backend 'status-printer fileentry))
1059
1060 (defun vc-dir-deduce-fileset (&optional state-model-only-files)
1061 (let ((marked (vc-dir-marked-files))
1062 files
1063 only-files-list
1064 state
1065 model)
1066 (if marked
1067 (progn
1068 (setq files marked)
1069 (when state-model-only-files
1070 (setq only-files-list (vc-dir-marked-only-files-and-states))))
1071 (let ((crt (vc-dir-current-file)))
1072 (setq files (list crt))
1073 (when state-model-only-files
1074 (setq only-files-list (vc-dir-child-files-and-states)))))
1075
1076 (when state-model-only-files
1077 (setq state (cdar only-files-list))
1078 ;; Check that all files are in a consistent state, since we use that
1079 ;; state to decide which operation to perform.
1080 (dolist (crt (cdr only-files-list))
1081 (unless (vc-compatible-state (cdr crt) state)
1082 (error "%s:%s clashes with %s:%s"
1083 (car crt) (cdr crt) (caar only-files-list) state)))
1084 (setq only-files-list (mapcar 'car only-files-list))
1085 (when (and state (not (eq state 'unregistered)))
1086 (setq model (vc-checkout-model vc-dir-backend only-files-list))))
1087 (list vc-dir-backend files only-files-list state model)))
1088
1089 ;;;###autoload
1090 (defun vc-dir (dir &optional backend)
1091 "Show the VC status for DIR.
1092 Optional second argument BACKEND specifies the VC backend to use.
1093 Interactively, a prefix argument means to ask for the backend."
1094 (interactive
1095 (list
1096 ;; When you hit C-x v d in a visited VC file,
1097 ;; the *vc-dir* buffer visits the directory under its truename;
1098 ;; therefore it makes sense to always do that.
1099 ;; Otherwise if you do C-x v d -> C-x C-f -> C-c v d
1100 ;; you may get a new *vc-dir* buffer, different from the original
1101 (file-truename (read-file-name "VC status for directory: "
1102 default-directory default-directory t
1103 nil #'file-directory-p))
1104 (if current-prefix-arg
1105 (intern
1106 (completing-read
1107 "Use VC backend: "
1108 (mapcar (lambda (b) (list (symbol-name b)))
1109 vc-handled-backends)
1110 nil t nil nil)))))
1111 (unless backend
1112 (setq backend (vc-responsible-backend dir)))
1113 (pop-to-buffer (vc-dir-prepare-status-buffer "*vc-dir*" dir backend))
1114 (if (derived-mode-p 'vc-dir-mode)
1115 (vc-dir-refresh)
1116 ;; FIXME: find a better way to pass the backend to `vc-dir-mode'.
1117 (let ((use-vc-backend backend))
1118 (vc-dir-mode))))
1119
1120 (defun vc-default-status-extra-headers (backend dir)
1121 ;; Be loud by default to remind people to add code to display
1122 ;; backend specific headers.
1123 ;; XXX: change this to return nil before the release.
1124 (concat
1125 (propertize "Extra : " 'face 'font-lock-type-face)
1126 (propertize "Please add backend specific headers here. It's easy!"
1127 'face 'font-lock-warning-face)))
1128
1129 (defun vc-default-status-printer (backend fileentry)
1130 "Pretty print FILEENTRY."
1131 ;; If you change the layout here, change vc-dir-move-to-goal-column.
1132 (let* ((isdir (vc-dir-fileinfo->directory fileentry))
1133 (state (if isdir "" (vc-dir-fileinfo->state fileentry)))
1134 (filename (vc-dir-fileinfo->name fileentry)))
1135 (insert
1136 (propertize
1137 (format "%c" (if (vc-dir-fileinfo->marked fileentry) ?* ? ))
1138 'face 'font-lock-type-face)
1139 " "
1140 (propertize
1141 (format "%-20s" state)
1142 'face (cond ((eq state 'up-to-date) 'font-lock-builtin-face)
1143 ((memq state '(missing conflict)) 'font-lock-warning-face)
1144 (t 'font-lock-variable-name-face))
1145 'mouse-face 'highlight)
1146 " "
1147 (propertize
1148 (format "%s" filename)
1149 'face
1150 (if isdir 'font-lock-comment-delimiter-face 'font-lock-function-name-face)
1151 'help-echo
1152 (if isdir
1153 "Directory\nVC operations can be applied to it\nmouse-3: Pop-up menu"
1154 "File\nmouse-3: Pop-up menu")
1155 'mouse-face 'highlight))))
1156
1157 (defun vc-default-extra-status-menu (backend)
1158 nil)
1159
1160 (defun vc-default-status-fileinfo-extra (backend file)
1161 "Default absence of extra information returned for a file."
1162 nil)
1163
1164 (provide 'vc-dir)
1165
1166 ;; arch-tag: 0274a2e3-e8e9-4b1a-a73c-e8b9129d5d15
1167 ;;; vc-dir.el ends here