1 ;;; vc-dir.el --- Directory status display under VC -*- lexical-binding: t -*-
3 ;; Copyright (C) 2007-2015 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 [display]
173 '(menu-item "Display in Other Window" vc-dir-display-file
174 :help "Display the file on the current line, in another window"))
175 (define-key map [open-other]
176 '(menu-item "Open in Other Window" vc-dir-find-file-other-window
177 :help "Find the file on the current line, in another window"))
178 (define-key map [open]
179 '(menu-item "Open File" vc-dir-find-file
180 :help "Find the file on the current line"))
181 (define-key map [sepvcdet] '("--"))
182 ;; FIXME: This needs a key binding. And maybe a better name
183 ;; ("Insert" like PCL-CVS uses does not sound that great either)...
184 (define-key map [ins]
185 '(menu-item "Show File" vc-dir-show-fileentry
186 :help "Show a file in the VC status listing even though it might be up to date"))
187 (define-key map [annotate]
188 '(menu-item "Annotate" vc-annotate
189 :help "Display the edit history of the current file using colors"))
190 (define-key map [diff]
191 '(menu-item "Compare with Base Version" vc-diff
192 :help "Compare file set with the base version"))
193 (define-key map [logo]
194 '(menu-item "Show Outgoing Log" vc-log-outgoing
195 :help "Show a log of changes that will be sent with a push operation"))
196 (define-key map [logi]
197 '(menu-item "Show Incoming Log" vc-log-incoming
198 :help "Show a log of changes that will be received with a pull operation"))
199 (define-key map [log]
200 '(menu-item "Show History" vc-print-log
201 :help "List the change log of the current file set in a window"))
202 (define-key map [rlog]
203 '(menu-item "Show Top of the Tree History " vc-print-root-log
204 :help "List the change log for the current tree in a window"))
206 (define-key map [sepvccmd] '("--"))
207 (define-key map [push]
208 '(menu-item "Push Changes" vc-push
209 :enable (vc-find-backend-function vc-dir-backend 'push)
210 :help "Push the current branch's changes"))
211 (define-key map [update]
212 '(menu-item "Update to Latest Version" vc-update
213 :help "Update the current fileset's files to their tip revisions"))
214 (define-key map [revert]
215 '(menu-item "Revert to Base Version" vc-revert
216 :help "Revert working copies of the selected fileset to their repository contents."))
217 (define-key map [next-action]
218 ;; FIXME: This really really really needs a better name!
219 ;; And a key binding too.
220 '(menu-item "Check In/Out" vc-next-action
221 :help "Do the next logical version control operation on the current fileset"))
222 (define-key map [register]
223 '(menu-item "Register" vc-register
224 :help "Register file set into the version control system"))
225 (define-key map [ignore]
226 '(menu-item "Ignore Current File" vc-dir-ignore
227 :help "Ignore the current file under current version control system"))
231 ;; VC backends can use this to add mode-specific menu items to
233 (defun vc-dir-menu-map-filter (orig-binding)
234 (when (and (symbolp orig-binding) (fboundp orig-binding))
235 (setq orig-binding (indirect-function orig-binding)))
237 (when (derived-mode-p 'vc-dir-mode)
238 (vc-call-backend vc-dir-backend 'extra-status-menu))))
239 (if (null ext-binding)
245 (defvar vc-dir-mode-map
246 (let ((map (make-sparse-keymap)))
248 (define-key map "v" 'vc-next-action) ;; C-x v v
249 (define-key map "=" 'vc-diff) ;; C-x v =
250 (define-key map "D" 'vc-root-diff) ;; C-x v D
251 (define-key map "i" 'vc-register) ;; C-x v i
252 (define-key map "+" 'vc-update) ;; C-x v +
253 ;; I'd prefer some kind of symmetry with vc-update:
254 (define-key map "P" 'vc-push) ;; C-x v P
255 (define-key map "l" 'vc-print-log) ;; C-x v l
256 (define-key map "L" 'vc-print-root-log) ;; C-x v L
257 (define-key map "I" 'vc-log-incoming) ;; C-x v I
258 ;; More confusing than helpful, probably
259 ;;(define-key map "R" 'vc-revert) ;; u is taken by vc-dir-unmark.
260 ;;(define-key map "A" 'vc-annotate) ;; g is taken by revert-buffer
261 ;; bound by `special-mode'.
263 (define-key map "m" 'vc-dir-mark)
264 (define-key map "M" 'vc-dir-mark-all-files)
265 (define-key map "u" 'vc-dir-unmark)
266 (define-key map "U" 'vc-dir-unmark-all-files)
267 (define-key map "\C-?" 'vc-dir-unmark-file-up)
268 (define-key map "\M-\C-?" 'vc-dir-unmark-all-files)
270 (define-key map "n" 'vc-dir-next-line)
271 (define-key map " " 'vc-dir-next-line)
272 (define-key map "\t" 'vc-dir-next-directory)
273 (define-key map "p" 'vc-dir-previous-line)
274 (define-key map [backtab] 'vc-dir-previous-directory)
275 ;;; Rebind paragraph-movement commands.
276 (define-key map "\M-}" 'vc-dir-next-directory)
277 (define-key map "\M-{" 'vc-dir-previous-directory)
278 (define-key map [C-down] 'vc-dir-next-directory)
279 (define-key map [C-up] 'vc-dir-previous-directory)
281 (define-key map "f" 'vc-dir-find-file)
282 (define-key map "e" 'vc-dir-find-file) ; dired-mode compatibility
283 (define-key map "\C-m" 'vc-dir-find-file)
284 (define-key map "o" 'vc-dir-find-file-other-window)
285 (define-key map "\C-o" 'vc-dir-display-file)
286 (define-key map "\C-c\C-c" 'vc-dir-kill-dir-status-process)
287 (define-key map [down-mouse-3] 'vc-dir-menu)
288 (define-key map [mouse-2] 'vc-dir-toggle-mark)
289 (define-key map [follow-link] 'mouse-face)
290 (define-key map "x" 'vc-dir-hide-up-to-date)
291 (define-key map [?\C-k] 'vc-dir-kill-line)
292 (define-key map "S" 'vc-dir-search) ;; FIXME: Maybe use A like dired?
293 (define-key map "Q" 'vc-dir-query-replace-regexp)
294 (define-key map (kbd "M-s a C-s") 'vc-dir-isearch)
295 (define-key map (kbd "M-s a M-C-s") 'vc-dir-isearch-regexp)
296 (define-key map "G" 'vc-dir-ignore)
299 (define-key map [menu-bar vc-dir-mode]
301 ;; VC backends can use this to add mode-specific menu items to
303 "VC-Dir" ,vc-dir-menu-map :filter vc-dir-menu-map-filter))
305 "Keymap for directory buffer.")
307 (defmacro vc-dir-at-event (event &rest body)
308 "Evaluate BODY with point located at event-start of EVENT.
309 If BODY uses EVENT, it should be a variable,
310 otherwise it will be evaluated twice."
311 (let ((posn (make-symbol "vc-dir-at-event-posn")))
313 (unless (equal ,event '(tool-bar))
314 (let ((,posn (event-start ,event)))
315 (set-buffer (window-buffer (posn-window ,posn)))
316 (goto-char (posn-point ,posn))))
319 (defun vc-dir-menu (e)
320 "Popup the VC dir menu."
322 (vc-dir-at-event e (popup-menu vc-dir-menu-map e)))
324 (defvar vc-dir-tool-bar-map
325 (let ((map (make-sparse-keymap)))
326 (tool-bar-local-item-from-menu 'find-file "new" map nil
327 :label "New File" :vert-only t)
328 (tool-bar-local-item-from-menu 'menu-find-file-existing "open" map nil
329 :label "Open" :vert-only t)
330 (tool-bar-local-item-from-menu 'dired "diropen" map nil
332 (tool-bar-local-item-from-menu 'quit-window "close" map vc-dir-mode-map
334 (tool-bar-local-item-from-menu 'vc-next-action "saveas" map
335 vc-dir-mode-map :label "Commit")
336 (tool-bar-local-item-from-menu 'vc-print-log "info"
339 (define-key-after map [separator-1] menu-bar-separator)
340 (tool-bar-local-item-from-menu 'vc-dir-kill-dir-status-process "cancel"
342 :label "Stop" :vert-only t)
343 (tool-bar-local-item-from-menu 'revert-buffer "refresh"
344 map vc-dir-mode-map :vert-only t)
345 (define-key-after map [separator-2] menu-bar-separator)
346 (tool-bar-local-item-from-menu (lookup-key menu-bar-edit-menu [cut])
347 "cut" map nil :vert-only t)
348 (tool-bar-local-item-from-menu (lookup-key menu-bar-edit-menu [copy])
349 "copy" map nil :vert-only t)
350 (tool-bar-local-item-from-menu (lookup-key menu-bar-edit-menu [paste])
351 "paste" map nil :vert-only t)
352 (define-key-after map [separator-3] menu-bar-separator)
353 (tool-bar-local-item-from-menu 'isearch-forward
355 :label "Search" :vert-only t)
358 (defun vc-dir-node-directory (node)
359 ;; Compute the directory for NODE.
360 ;; If it's a directory node, get it from the node.
361 (let ((data (ewoc-data node)))
362 (or (vc-dir-fileinfo->directory data)
363 ;; Otherwise compute it from the file name.
367 (vc-dir-fileinfo->name data)))))))
369 (defun vc-dir-update (entries buffer &optional noinsert)
370 "Update BUFFER's ewoc from the list of ENTRIES.
371 If NOINSERT, ignore elements on ENTRIES which are not in the ewoc."
372 ;; Add ENTRIES to the vc-dir buffer BUFFER.
373 (with-current-buffer buffer
374 ;; Insert the entries sorted by name into the ewoc.
375 ;; We assume the ewoc is sorted too, which should be the
376 ;; case if we always add entries with vc-dir-update.
378 ;; Sort: first files and then subdirectories.
379 ;; XXX: this is VERY inefficient, it computes the directory
380 ;; names too many times
382 (lambda (entry1 entry2)
383 (let ((dir1 (file-name-directory
384 (directory-file-name (expand-file-name (car entry1)))))
385 (dir2 (file-name-directory
386 (directory-file-name (expand-file-name (car entry2))))))
388 ((string< dir1 dir2) t)
389 ((not (string= dir1 dir2)) nil)
390 ((string< (car entry1) (car entry2))))))))
391 ;; Insert directory entries in the right places.
392 (let ((entry (car entries))
393 (node (ewoc-nth vc-ewoc 0))
395 (dotname (file-relative-name default-directory)))
396 ;; Insert . if it is not present.
399 vc-ewoc (vc-dir-create-fileinfo
400 dotname nil nil nil default-directory))
401 (setq node (ewoc-nth vc-ewoc 0)))
403 (while (and entry node)
404 (let* ((entryfile (car entry))
405 (entrydir (file-name-directory (directory-file-name
406 (expand-file-name entryfile))))
407 (nodedir (vc-dir-node-directory node)))
409 ;; First try to find the directory.
410 ((string-lessp nodedir entrydir)
411 (setq node (ewoc-next vc-ewoc node)))
412 ((string-equal nodedir entrydir)
413 ;; Found the directory, find the place for the file name.
414 (let ((nodefile (vc-dir-fileinfo->name (ewoc-data node))))
416 ((string= nodefile dotname)
417 (setq node (ewoc-next vc-ewoc node)))
418 ((string-lessp nodefile entryfile)
419 (setq node (ewoc-next vc-ewoc node)))
420 ((string-equal nodefile entryfile)
423 (setf (vc-dir-fileinfo->state (ewoc-data node)) (nth 1 entry))
424 (setf (vc-dir-fileinfo->extra (ewoc-data node)) (nth 2 entry))
425 (setf (vc-dir-fileinfo->needs-update (ewoc-data node)) nil)
426 (ewoc-invalidate vc-ewoc node))
427 ;; If the state is nil, the file does not exist
428 ;; anymore, so remember the entry so we can remove
429 ;; it after we are done inserting all ENTRIES.
430 (push node to-remove))
431 (setq entries (cdr entries))
432 (setq entry (car entries))
433 (setq node (ewoc-next vc-ewoc node)))
436 (ewoc-enter-before vc-ewoc node
437 (apply 'vc-dir-create-fileinfo entry)))
438 (setq entries (cdr entries))
439 (setq entry (car entries))))))
442 ;; We might need to insert a directory node if the
443 ;; previous node was in a different directory.
444 (let* ((rd (file-relative-name entrydir))
445 (prev-node (ewoc-prev vc-ewoc node))
446 (prev-dir (if prev-node
447 (vc-dir-node-directory prev-node))))
448 (unless (string-equal entrydir prev-dir)
450 vc-ewoc node (vc-dir-create-fileinfo rd nil nil nil entrydir))))
451 ;; Now insert the node itself.
452 (ewoc-enter-before vc-ewoc node
453 (apply 'vc-dir-create-fileinfo entry)))
454 (setq entries (cdr entries) entry (car entries))))))
455 ;; We're past the last node, all remaining entries go to the end.
456 (unless (or node noinsert)
457 (let ((lastdir (vc-dir-node-directory (ewoc-nth vc-ewoc -1))))
458 (dolist (entry entries)
459 (let ((entrydir (file-name-directory
460 (directory-file-name (expand-file-name (car entry))))))
461 ;; Insert a directory node if needed.
462 (unless (string-equal lastdir entrydir)
463 (setq lastdir entrydir)
464 (let ((rd (file-relative-name entrydir)))
466 vc-ewoc (vc-dir-create-fileinfo rd nil nil nil entrydir))))
467 ;; Now insert the node itself.
468 (ewoc-enter-last vc-ewoc
469 (apply 'vc-dir-create-fileinfo entry))))))
471 (let ((inhibit-read-only t))
472 (apply 'ewoc-delete vc-ewoc (nreverse to-remove)))))))
474 (defun vc-dir-busy ()
475 (and (buffer-live-p vc-dir-process-buffer)
476 (get-buffer-process vc-dir-process-buffer)))
478 (defun vc-dir-kill-dir-status-process ()
479 "Kill the temporary buffer and associated process."
481 (when (buffer-live-p vc-dir-process-buffer)
482 (let ((proc (get-buffer-process vc-dir-process-buffer)))
483 (when proc (delete-process proc))
484 (setq vc-dir-process-buffer nil)
485 (setq mode-line-process nil))))
487 (defun vc-dir-kill-query ()
488 ;; Make sure that when the status buffer is killed the update
489 ;; process running in background is also killed.
491 (when (y-or-n-p "Status update process running, really kill status buffer? ")
492 (vc-dir-kill-dir-status-process)
496 (defun vc-dir-next-line (arg)
497 "Go to the next line.
498 If a prefix argument is given, move by that many lines."
501 (ewoc-goto-next vc-ewoc arg)
502 (vc-dir-move-to-goal-column)))
504 (defun vc-dir-previous-line (arg)
505 "Go to the previous line.
506 If a prefix argument is given, move by that many lines."
508 (ewoc-goto-prev vc-ewoc arg)
509 (vc-dir-move-to-goal-column))
511 (defun vc-dir-next-directory ()
512 "Go to the next directory."
514 (let ((orig (point)))
518 (let* ((next (ewoc-next vc-ewoc (ewoc-locate vc-ewoc))))
523 (ewoc-goto-node vc-ewoc next)
524 (vc-dir-move-to-goal-column)
525 (if (vc-dir-fileinfo->directory (ewoc-data next))
526 (throw 'foundit nil))))))))
529 (defun vc-dir-previous-directory ()
530 "Go to the previous directory."
532 (let ((orig (point)))
536 (let* ((prev (ewoc-prev vc-ewoc (ewoc-locate vc-ewoc))))
541 (ewoc-goto-node vc-ewoc prev)
542 (vc-dir-move-to-goal-column)
543 (if (vc-dir-fileinfo->directory (ewoc-data prev))
544 (throw 'foundit nil))))))))
547 (defun vc-dir-mark-unmark (mark-unmark-function)
549 (let (;; (firstl (line-number-at-pos (region-beginning)))
550 (lastl (line-number-at-pos (region-end))))
552 (goto-char (region-beginning))
553 (while (<= (line-number-at-pos) lastl)
555 (funcall mark-unmark-function)
556 ;; `vc-dir-mark-file' signals an error if we try marking
557 ;; a directory containing marked files in its tree, or a
558 ;; file in a marked directory tree. Just continue.
559 (error (vc-dir-next-line 1))))))
560 (funcall mark-unmark-function)))
562 (defun vc-dir-parent-marked-p (arg)
563 ;; Non-nil iff a parent directory of arg is marked.
564 ;; Return value, if non-nil is the `ewoc-data' for the marked parent.
565 (let* ((argdir (vc-dir-node-directory arg))
566 ;; (arglen (length argdir))
569 ;; Go through the predecessors, checking if any directory that is
570 ;; a parent is marked.
571 (while (and (null found)
572 (setq crt (ewoc-prev vc-ewoc crt)))
573 (let ((data (ewoc-data crt))
574 (dir (vc-dir-node-directory crt)))
575 (and (vc-dir-fileinfo->directory data)
576 (string-prefix-p dir argdir)
577 (vc-dir-fileinfo->marked data)
581 (defun vc-dir-children-marked-p (arg)
582 ;; Non-nil iff a child of ARG is marked.
583 ;; Return value, if non-nil, is the `ewoc-data' for the marked child.
584 (let* ((argdir-re (concat "\\`" (regexp-quote (vc-dir-node-directory arg))))
590 (setq crt (ewoc-next vc-ewoc crt)))
591 (let ((data (ewoc-data crt))
592 (dir (vc-dir-node-directory crt)))
593 (if (string-match argdir-re dir)
594 (if (vc-dir-fileinfo->marked data)
596 ;; We are done, we got to an entry that is not a child of `arg'.
597 (setq is-child nil))))
600 (defun vc-dir-mark-file (&optional arg)
601 ;; Mark ARG or the current file and move to the next line.
602 (let* ((crt (or arg (ewoc-locate vc-ewoc)))
603 (file (ewoc-data crt))
604 (isdir (vc-dir-fileinfo->directory file))
605 ;; Forbid marking a directory containing marked files in its
606 ;; tree, or a file in a marked directory tree.
608 (vc-dir-children-marked-p crt)
609 (vc-dir-parent-marked-p crt))))
612 "File `%s' in this directory is already marked"
613 "Parent directory `%s' is already marked")
614 (vc-dir-fileinfo->name conflict)))
615 (setf (vc-dir-fileinfo->marked file) t)
616 (ewoc-invalidate vc-ewoc crt)
617 (unless (or arg (mouse-event-p last-command-event))
618 (vc-dir-next-line 1))))
620 (defun vc-dir-mark ()
621 "Mark the current file or all files in the region.
622 If the region is active, mark all the files in the region.
623 Otherwise mark the file on the current line and move to the next
626 (vc-dir-mark-unmark 'vc-dir-mark-file))
628 (defun vc-dir-mark-all-files (arg)
629 "Mark all files with the same state as the current one.
630 With a prefix argument mark all files.
631 If the current entry is a directory, mark all child files.
633 The commands operate on files that are on the same state.
634 This command is intended to make it easy to select all files that
635 share the same state."
640 ;; First check that no directory is marked, we can't mark
641 ;; files in that case.
644 (when (and (vc-dir-fileinfo->directory filearg)
645 (vc-dir-fileinfo->marked filearg))
646 (error "Cannot mark all files, directory `%s' marked"
647 (vc-dir-fileinfo->name filearg))))
651 (unless (vc-dir-fileinfo->marked filearg)
652 (setf (vc-dir-fileinfo->marked filearg) t)
655 (let* ((crt (ewoc-locate vc-ewoc))
656 (data (ewoc-data crt)))
657 (if (vc-dir-fileinfo->directory data)
658 ;; It's a directory, mark child files.
660 (while (and (setq crt (ewoc-next vc-ewoc crt))
661 (setq crt-data (ewoc-data crt))
662 (not (vc-dir-fileinfo->directory crt-data)))
663 (setf (vc-dir-fileinfo->marked crt-data) t)
664 (ewoc-invalidate vc-ewoc crt)))
666 (let ((state (vc-dir-fileinfo->state data)))
667 (setq crt (ewoc-nth vc-ewoc 0))
669 (let ((crt-data (ewoc-data crt)))
670 (when (and (not (vc-dir-fileinfo->marked crt-data))
671 (eq (vc-dir-fileinfo->state crt-data) state)
672 (not (vc-dir-fileinfo->directory crt-data)))
673 (vc-dir-mark-file crt)))
674 (setq crt (ewoc-next vc-ewoc crt))))))))
676 (defun vc-dir-unmark-file ()
677 ;; Unmark the current file and move to the next line.
678 (let* ((crt (ewoc-locate vc-ewoc))
679 (file (ewoc-data crt)))
680 (setf (vc-dir-fileinfo->marked file) nil)
681 (ewoc-invalidate vc-ewoc crt)
682 (unless (mouse-event-p last-command-event)
683 (vc-dir-next-line 1))))
685 (defun vc-dir-unmark ()
686 "Unmark the current file or all files in the region.
687 If the region is active, unmark all the files in the region.
688 Otherwise mark the file on the current line and move to the next
691 (vc-dir-mark-unmark 'vc-dir-unmark-file))
693 (defun vc-dir-unmark-file-up ()
694 "Move to the previous line and unmark the file."
696 ;; If we're on the first line, we won't move up, but we will still
697 ;; remove the mark. This seems a bit odd but it is what buffer-menu
699 (let* ((prev (ewoc-goto-prev vc-ewoc 1))
700 (file (ewoc-data prev)))
701 (setf (vc-dir-fileinfo->marked file) nil)
702 (ewoc-invalidate vc-ewoc prev)
703 (vc-dir-move-to-goal-column)))
705 (defun vc-dir-unmark-all-files (arg)
706 "Unmark all files with the same state as the current one.
707 With a prefix argument unmark all files.
708 If the current entry is a directory, unmark all the child files.
710 The commands operate on files that are on the same state.
711 This command is intended to make it easy to deselect all files
712 that share the same state."
717 (when (vc-dir-fileinfo->marked filearg)
718 (setf (vc-dir-fileinfo->marked filearg) nil)
721 (let* ((crt (ewoc-locate vc-ewoc))
722 (data (ewoc-data crt)))
723 (if (vc-dir-fileinfo->directory data)
724 ;; It's a directory, unmark child files.
725 (while (setq crt (ewoc-next vc-ewoc crt))
726 (let ((crt-data (ewoc-data crt)))
727 (unless (vc-dir-fileinfo->directory crt-data)
728 (setf (vc-dir-fileinfo->marked crt-data) nil)
729 (ewoc-invalidate vc-ewoc crt))))
731 (let ((crt-state (vc-dir-fileinfo->state (ewoc-data crt))))
734 (when (and (vc-dir-fileinfo->marked filearg)
735 (eq (vc-dir-fileinfo->state filearg) crt-state))
736 (setf (vc-dir-fileinfo->marked filearg) nil)
740 (defun vc-dir-toggle-mark-file ()
741 (let* ((crt (ewoc-locate vc-ewoc))
742 (file (ewoc-data crt)))
743 (if (vc-dir-fileinfo->marked file)
745 (vc-dir-mark-file))))
747 (defun vc-dir-toggle-mark (e)
749 (vc-dir-at-event e (vc-dir-mark-unmark 'vc-dir-toggle-mark-file)))
751 (defun vc-dir-delete-file ()
752 "Delete the marked files, or the current file if no marks."
754 (mapc 'vc-delete-file (or (vc-dir-marked-files)
755 (list (vc-dir-current-file)))))
757 (defun vc-dir-find-file ()
758 "Find the file on the current line."
760 (find-file (vc-dir-current-file)))
762 (defun vc-dir-find-file-other-window (&optional event)
763 "Find the file on the current line, in another window."
764 (interactive (list last-nonmenu-event))
765 (if event (posn-set-point (event-end event)))
766 (find-file-other-window (vc-dir-current-file)))
768 (defun vc-dir-display-file (&optional event)
769 "Display the file on the current line, in another window."
770 (interactive (list last-nonmenu-event))
771 (if event (posn-set-point (event-end event)))
772 (display-buffer (find-file-noselect (vc-dir-current-file))
775 (defun vc-dir-isearch ()
776 "Search for a string through all marked buffers using Isearch."
779 (mapcar 'car (vc-dir-marked-only-files-and-states))))
781 (defun vc-dir-isearch-regexp ()
782 "Search for a regexp through all marked buffers using Isearch."
784 (multi-isearch-files-regexp
785 (mapcar 'car (vc-dir-marked-only-files-and-states))))
787 (defun vc-dir-search (regexp)
788 "Search through all marked files for a match for REGEXP.
789 For marked directories, use the files displayed from those directories.
790 Stops when a match is found.
791 To continue searching for next match, use command \\[tags-loop-continue]."
792 (interactive "sSearch marked files (regexp): ")
793 (tags-search regexp '(mapcar 'car (vc-dir-marked-only-files-and-states))))
795 (defun vc-dir-query-replace-regexp (from to &optional delimited)
796 "Do `query-replace-regexp' of FROM with TO, on all marked files.
797 If a directory is marked, then use the files displayed for that directory.
798 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
799 If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
800 with the command \\[tags-loop-continue]."
801 ;; FIXME: this is almost a copy of `dired-do-query-replace-regexp'. This
802 ;; should probably be made generic and used in both places instead of
803 ;; duplicating it here.
806 (query-replace-read-args
807 "Query replace regexp in marked files" t t)))
808 (list (nth 0 common) (nth 1 common) (nth 2 common))))
809 (dolist (file (mapcar 'car (vc-dir-marked-only-files-and-states)))
810 (let ((buffer (get-file-buffer file)))
811 (if (and buffer (with-current-buffer buffer
813 (error "File `%s' is visited read-only" file))))
814 (tags-query-replace from to delimited
815 '(mapcar 'car (vc-dir-marked-only-files-and-states))))
817 (defun vc-dir-ignore ()
818 "Ignore the current file."
820 (vc-ignore (vc-dir-current-file)))
822 (defun vc-dir-current-file ()
823 (let ((node (ewoc-locate vc-ewoc)))
825 (error "No file available"))
826 (expand-file-name (vc-dir-fileinfo->name (ewoc-data node)))))
828 (defun vc-dir-marked-files ()
829 "Return the list of marked files."
831 (lambda (elem) (expand-file-name (vc-dir-fileinfo->name elem)))
832 (ewoc-collect vc-ewoc 'vc-dir-fileinfo->marked)))
834 (defun vc-dir-marked-only-files-and-states ()
835 "Return the list of conses (FILE . STATE) for the marked files.
836 For marked directories return the corresponding conses for the
838 (let ((crt (ewoc-nth vc-ewoc 0))
841 (let ((crt-data (ewoc-data crt)))
842 (if (vc-dir-fileinfo->marked crt-data)
843 ;; FIXME: use vc-dir-child-files-and-states here instead of duplicating it.
844 (if (vc-dir-fileinfo->directory crt-data)
845 (let* ((dir (vc-dir-fileinfo->directory crt-data))
846 ;; (dirlen (length dir))
849 (and (setq crt (ewoc-next vc-ewoc crt))
852 (setq data (ewoc-data crt))
853 (vc-dir-node-directory crt))))
854 (unless (vc-dir-fileinfo->directory data)
856 (cons (expand-file-name (vc-dir-fileinfo->name data))
857 (vc-dir-fileinfo->state data))
859 (push (cons (expand-file-name (vc-dir-fileinfo->name crt-data))
860 (vc-dir-fileinfo->state crt-data))
862 (setq crt (ewoc-next vc-ewoc crt)))
863 (setq crt (ewoc-next vc-ewoc crt)))))
866 (defun vc-dir-child-files-and-states ()
867 "Return the list of conses (FILE . STATE) for child files of the current entry if it's a directory.
868 If it is a file, return the corresponding cons for the file itself."
869 (let* ((crt (ewoc-locate vc-ewoc))
870 (crt-data (ewoc-data crt))
872 (if (vc-dir-fileinfo->directory crt-data)
873 (let* ((dir (vc-dir-fileinfo->directory crt-data))
874 ;; (dirlen (length dir))
877 (and (setq crt (ewoc-next vc-ewoc crt))
878 (string-prefix-p dir (progn
879 (setq data (ewoc-data crt))
880 (vc-dir-node-directory crt))))
881 (unless (vc-dir-fileinfo->directory data)
883 (cons (expand-file-name (vc-dir-fileinfo->name data))
884 (vc-dir-fileinfo->state data))
887 (cons (expand-file-name (vc-dir-fileinfo->name crt-data))
888 (vc-dir-fileinfo->state crt-data)) result))
891 (defun vc-dir-recompute-file-state (fname def-dir)
892 (let* ((file-short (file-relative-name fname def-dir))
893 (_remove-me-when-CVS-works
894 (when (eq vc-dir-backend 'CVS)
895 ;; FIXME: Warning: UGLY HACK. The CVS backend caches the state
896 ;; info, this forces the backend to update it.
897 (vc-call-backend vc-dir-backend 'registered fname)))
898 (state (vc-call-backend vc-dir-backend 'state fname))
899 (extra (vc-call-backend vc-dir-backend
900 'status-fileinfo-extra fname)))
901 (list file-short state extra)))
903 (defun vc-dir-find-child-files (dirname)
904 ;; Give a DIRNAME string return the list of all child files shown in
905 ;; the current *vc-dir* buffer.
906 (let ((crt (ewoc-nth vc-ewoc 0))
909 (while (and crt (not (string-prefix-p
910 dirname (vc-dir-node-directory crt))))
911 (setq crt (ewoc-next vc-ewoc crt)))
912 (while (and crt (string-prefix-p
914 (vc-dir-node-directory crt)))
915 (let ((data (ewoc-data crt)))
916 (unless (vc-dir-fileinfo->directory data)
917 (push (expand-file-name (vc-dir-fileinfo->name data)) children)))
918 (setq crt (ewoc-next vc-ewoc crt)))
921 (defun vc-dir-resync-directory-files (dirname)
922 ;; Update the entries for all the child files of DIRNAME shown in
923 ;; the current *vc-dir* buffer.
924 (let ((files (vc-dir-find-child-files dirname))
925 (ddir default-directory)
929 (push (vc-dir-recompute-file-state crt ddir)
931 (vc-dir-update fileentries (current-buffer)))))
933 (defun vc-dir-resynch-file (&optional fname)
934 "Update the entries for FNAME in any directory buffers that list it."
935 (let ((file (or fname (expand-file-name buffer-file-name)))
938 ;; look for a vc-dir buffer that might show this file.
939 (dolist (status-buf vc-dir-buffers)
940 (if (not (buffer-live-p status-buf))
941 (push status-buf drop)
942 (set-buffer status-buf)
943 (if (not (derived-mode-p 'vc-dir-mode))
944 (push status-buf drop)
945 (let ((ddir default-directory))
946 (when (string-prefix-p ddir file)
947 (if (file-directory-p file)
949 (vc-dir-resync-directory-files file)
951 (vc-dir-headers vc-dir-backend default-directory) ""))
952 (let* ((complete-state (vc-dir-recompute-file-state file ddir))
953 (state (cadr complete-state)))
955 (list complete-state)
956 status-buf (or (not state)
957 (eq state 'up-to-date)))))))))))
958 ;; Remove out-of-date entries from vc-dir-buffers.
959 (dolist (b drop) (setq vc-dir-buffers (delq b vc-dir-buffers)))))
961 (defvar use-vc-backend) ;; dynamically bound
963 (define-derived-mode vc-dir-mode special-mode "VC dir"
964 "Major mode for VC directory buffers.
965 Marking/Unmarking key bindings and actions:
966 m - mark a file/directory
967 - if the region is active, mark all the files in region.
968 Restrictions: - a file cannot be marked if any parent directory is marked
969 - a directory cannot be marked if any child file or
971 u - unmark a file/directory
972 - if the region is active, unmark all the files in region.
973 M - if the cursor is on a file: mark all the files with the same state as
975 - if the cursor is on a directory: mark all child files
976 - with a prefix argument: mark all files
977 U - if the cursor is on a file: unmark all the files with the same state
979 - if the cursor is on a directory: unmark all child files
980 - with a prefix argument: unmark all files
981 mouse-2 - toggles the mark state
984 VC commands in the `C-x v' prefix can be used.
985 VC commands act on the marked entries. If nothing is marked, VC
986 commands act on the current entry.
989 S - searches the marked files
990 Q - does a query replace on the marked files
991 M-s a C-s - does an isearch on the marked files
992 M-s a C-M-s - does a regexp isearch on the marked files
993 If nothing is marked, these commands act on the current entry.
994 When a directory is current or marked, the Search & Replace
995 commands act on the child files of that directory that are displayed in
999 (set (make-local-variable 'vc-dir-backend) use-vc-backend)
1000 (set (make-local-variable 'desktop-save-buffer)
1001 'vc-dir-desktop-buffer-misc-data)
1002 (setq buffer-read-only t)
1003 (when (boundp 'tool-bar-map)
1004 (set (make-local-variable 'tool-bar-map) vc-dir-tool-bar-map))
1005 (let ((buffer-read-only nil))
1007 (set (make-local-variable 'vc-dir-process-buffer) nil)
1008 (set (make-local-variable 'vc-ewoc) (ewoc-create #'vc-dir-printer))
1009 (set (make-local-variable 'revert-buffer-function)
1010 'vc-dir-revert-buffer-function)
1011 (setq list-buffers-directory (expand-file-name "*vc-dir*" default-directory))
1012 (add-to-list 'vc-dir-buffers (current-buffer))
1013 ;; Make sure that if the directory buffer is killed, the update
1014 ;; process running in the background is also killed.
1015 (add-hook 'kill-buffer-query-functions 'vc-dir-kill-query nil t)
1016 (hack-dir-local-variables-non-file-buffer)
1019 (defun vc-dir-headers (backend dir)
1020 "Display the headers in the *VC dir* buffer.
1021 It calls the `dir-extra-headers' backend method to display backend
1024 ;; First layout the common headers.
1025 (propertize "VC backend : " 'face 'font-lock-type-face)
1026 (propertize (format "%s\n" backend) 'face 'font-lock-variable-name-face)
1027 (propertize "Working dir: " 'face 'font-lock-type-face)
1028 (propertize (format "%s\n" (abbreviate-file-name dir))
1029 'face 'font-lock-variable-name-face)
1030 ;; Then the backend specific ones.
1031 (vc-call-backend backend 'dir-extra-headers dir)
1034 (defun vc-dir-refresh-files (files)
1035 "Refresh some files in the *VC-dir* buffer."
1036 (let ((def-dir default-directory)
1037 (backend vc-dir-backend))
1038 (vc-set-mode-line-busy-indicator)
1039 ;; Call the `dir-status-files' backend function.
1040 ;; `dir-status-files' is supposed to be asynchronous.
1041 ;; It should compute the results, and then call the function
1042 ;; passed as an argument in order to update the vc-dir buffer
1043 ;; with the results.
1044 (unless (buffer-live-p vc-dir-process-buffer)
1045 (setq vc-dir-process-buffer
1046 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
1047 (let ((buffer (current-buffer)))
1048 (with-current-buffer vc-dir-process-buffer
1049 (setq default-directory def-dir)
1052 backend 'dir-status-files def-dir files
1053 (lambda (entries &optional more-to-come)
1054 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
1055 ;; If MORE-TO-COME is true, then more updates will come from
1056 ;; the asynchronous process.
1057 (with-current-buffer buffer
1058 (vc-dir-update entries buffer)
1059 (unless more-to-come
1060 (setq mode-line-process nil)
1061 ;; Remove the ones that haven't been updated at all.
1062 ;; Those not-updated are those whose state is nil because the
1063 ;; file/dir doesn't exist and isn't versioned.
1064 (ewoc-filter vc-ewoc
1066 ;; The state for directory entries might
1067 ;; have been changed to 'up-to-date,
1068 ;; reset it, otherwise it will be removed when doing 'x'
1070 ;; FIXME: There should be a more elegant way to do this.
1071 (when (and (vc-dir-fileinfo->directory info)
1072 (eq (vc-dir-fileinfo->state info)
1074 (setf (vc-dir-fileinfo->state info) nil))
1076 (not (vc-dir-fileinfo->needs-update info))))))))))))
1078 (defun vc-dir-revert-buffer-function (&optional _ignore-auto _noconfirm)
1081 (defun vc-dir-refresh ()
1082 "Refresh the contents of the *VC-dir* buffer.
1083 Throw an error if another update process is in progress."
1086 (error "Another update process is in progress, cannot run two at a time")
1087 (let ((def-dir default-directory)
1088 (backend vc-dir-backend))
1089 (vc-set-mode-line-busy-indicator)
1090 ;; Call the `dir-status' backend function.
1091 ;; `dir-status' is supposed to be asynchronous.
1092 ;; It should compute the results, and then call the function
1093 ;; passed as an argument in order to update the vc-dir buffer
1094 ;; with the results.
1096 ;; Create a buffer that can be used by `dir-status' and call
1097 ;; `dir-status' with this buffer as the current buffer. Use
1098 ;; `vc-dir-process-buffer' to remember this buffer, so that
1099 ;; it can be used later to kill the update process in case it
1101 (unless (buffer-live-p vc-dir-process-buffer)
1102 (setq vc-dir-process-buffer
1103 (generate-new-buffer (format " *VC-%s* tmp status" backend))))
1104 ;; set the needs-update flag on all non-directory entries
1105 (ewoc-map (lambda (info)
1106 (unless (vc-dir-fileinfo->directory info)
1107 (setf (vc-dir-fileinfo->needs-update info) t) nil))
1109 ;; Bzr has serious locking problems, so setup the headers first (this is
1110 ;; synchronous) rather than doing it while dir-status is running.
1111 (ewoc-set-hf vc-ewoc (vc-dir-headers backend def-dir) "")
1112 (let ((buffer (current-buffer)))
1113 (with-current-buffer vc-dir-process-buffer
1114 (setq default-directory def-dir)
1117 backend 'dir-status-files def-dir nil
1118 (lambda (entries &optional more-to-come)
1119 ;; ENTRIES is a list of (FILE VC_STATE EXTRA) items.
1120 ;; If MORE-TO-COME is true, then more updates will come from
1121 ;; the asynchronous process.
1122 (with-current-buffer buffer
1123 (vc-dir-update entries buffer)
1124 (unless more-to-come
1127 vc-ewoc 'vc-dir-fileinfo->needs-update)))
1129 (vc-dir-refresh-files
1130 (mapcar 'vc-dir-fileinfo->name remaining))
1131 (setq mode-line-process nil))))))))))))
1133 (defun vc-dir-show-fileentry (file)
1134 "Insert an entry for a specific file into the current *VC-dir* listing.
1135 This is typically used if the file is up-to-date (or has been added
1136 outside of VC) and one wants to do some operation on it."
1137 (interactive "fShow file: ")
1138 (vc-dir-update (list (list (file-relative-name file) (vc-state file))) (current-buffer)))
1140 (defun vc-dir-hide-state (&optional state)
1141 "Hide items that are in STATE from display.
1142 See `vc-state' for valid values of STATE.
1144 If STATE is nil, hide both `up-to-date' and `ignored' items.
1146 Interactively, if `current-prefix-arg' is non-nil, set STATE to
1147 state of item at point, if any."
1149 (and current-prefix-arg
1150 ;; Command is prefixed. Infer STATE from point.
1151 (let ((node (ewoc-locate vc-ewoc)))
1152 (and node (vc-dir-fileinfo->state (ewoc-data node)))))))
1154 (message "Hiding items in state \"%s\"" state)
1155 (message "Hiding up-to-date and ignored items"))
1156 (let ((crt (ewoc-nth vc-ewoc -1))
1157 (first (ewoc-nth vc-ewoc 0)))
1158 ;; Go over from the last item to the first and remove the
1159 ;; up-to-date files and directories with no child files.
1160 (while (not (eq crt first))
1161 (let* ((data (ewoc-data crt))
1162 (dir (vc-dir-fileinfo->directory data))
1163 (next (ewoc-next vc-ewoc crt))
1164 (prev (ewoc-prev vc-ewoc crt))
1165 ;; ewoc-delete does not work without this...
1166 (inhibit-read-only t))
1168 ;; Remove directories with no child files.
1171 ;; Nothing follows this directory.
1173 ;; Next item is a directory.
1174 (vc-dir-fileinfo->directory (ewoc-data next))))
1175 ;; Remove files in specified STATE. STATE can be a
1176 ;; symbol, a user-name, or nil.
1178 (equal (vc-dir-fileinfo->state data) state)
1179 (memq (vc-dir-fileinfo->state data) '(up-to-date ignored))))
1180 (ewoc-delete vc-ewoc crt))
1183 (defalias 'vc-dir-hide-up-to-date 'vc-dir-hide-state)
1185 (defun vc-dir-kill-line ()
1186 "Remove the current line from display."
1188 (let ((crt (ewoc-locate vc-ewoc))
1189 (inhibit-read-only t))
1190 (ewoc-delete vc-ewoc crt)))
1192 (defun vc-dir-printer (fileentry)
1193 (vc-call-backend vc-dir-backend 'dir-printer fileentry))
1195 (defun vc-dir-deduce-fileset (&optional state-model-only-files)
1196 (let ((marked (vc-dir-marked-files))
1204 (when state-model-only-files
1205 (setq only-files-list (vc-dir-marked-only-files-and-states))))
1206 (let ((crt (vc-dir-current-file)))
1207 (setq files (list crt))
1208 (when state-model-only-files
1209 (setq only-files-list (vc-dir-child-files-and-states)))))
1211 (when state-model-only-files
1212 (setq state (cdar only-files-list))
1213 ;; Check that all files are in a consistent state, since we use that
1214 ;; state to decide which operation to perform.
1215 (dolist (crt (cdr only-files-list))
1216 (unless (vc-compatible-state (cdr crt) state)
1217 (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"
1218 (car crt) (cdr crt) (caar only-files-list) state)))
1219 (setq only-files-list (mapcar 'car only-files-list))
1220 (when (and state (not (eq state 'unregistered)))
1221 (setq model (vc-checkout-model vc-dir-backend only-files-list))))
1222 (list vc-dir-backend files only-files-list state model)))
1225 (defun vc-dir (dir &optional backend)
1226 "Show the VC status for \"interesting\" files in and below DIR.
1227 This allows you to mark files and perform VC operations on them.
1228 The list omits files which are up to date, with no changes in your copy
1229 or the repository, if there is nothing in particular to say about them.
1231 Preparing the list of file status takes time; when the buffer
1232 first appears, it has only the first few lines of summary information.
1233 The file lines appear later.
1235 Optional second argument BACKEND specifies the VC backend to use.
1236 Interactively, a prefix argument means to ask for the backend.
1238 These are the commands available for use in the file status buffer:
1240 \\{vc-dir-mode-map}"
1244 ;; When you hit C-x v d in a visited VC file,
1245 ;; the *vc-dir* buffer visits the directory under its truename;
1246 ;; therefore it makes sense to always do that.
1247 ;; Otherwise if you do C-x v d -> C-x C-f -> C-c v d
1248 ;; you may get a new *vc-dir* buffer, different from the original
1249 (file-truename (read-directory-name "VC status for directory: "
1252 (if current-prefix-arg
1256 (mapcar (lambda (b) (list (symbol-name b)))
1257 vc-handled-backends)
1260 (setq backend (vc-responsible-backend dir)))
1261 (let (pop-up-windows) ; based on cvs-examine; bug#6204
1262 (pop-to-buffer (vc-dir-prepare-status-buffer "*vc-dir*" dir backend)))
1263 (if (derived-mode-p 'vc-dir-mode)
1265 ;; FIXME: find a better way to pass the backend to `vc-dir-mode'.
1266 (let ((use-vc-backend backend))
1269 (defun vc-default-dir-extra-headers (_backend _dir)
1270 ;; Be loud by default to remind people to add code to display
1271 ;; backend specific headers.
1272 ;; XXX: change this to return nil before the release.
1274 (propertize "Extra : " 'face 'font-lock-type-face)
1275 (propertize "Please add backend specific headers here. It's easy!"
1276 'face 'font-lock-warning-face)))
1278 (defvar vc-dir-filename-mouse-map
1279 (let ((map (make-sparse-keymap)))
1280 (define-key map [mouse-2] 'vc-dir-find-file-other-window)
1282 "Local keymap for visiting a file.")
1284 (defun vc-default-dir-printer (_backend fileentry)
1285 "Pretty print FILEENTRY."
1286 ;; If you change the layout here, change vc-dir-move-to-goal-column.
1287 ;; VC backends can implement backend specific versions of this
1288 ;; function. Changes here might need to be reflected in the
1289 ;; vc-BACKEND-dir-printer functions.
1290 (let* ((isdir (vc-dir-fileinfo->directory fileentry))
1291 (state (if isdir "" (vc-dir-fileinfo->state fileentry)))
1292 (filename (vc-dir-fileinfo->name fileentry)))
1295 (format "%c" (if (vc-dir-fileinfo->marked fileentry) ?* ? ))
1296 'face 'font-lock-type-face)
1299 (format "%-20s" state)
1300 'face (cond ((eq state 'up-to-date) 'font-lock-builtin-face)
1301 ((memq state '(missing conflict)) 'font-lock-warning-face)
1302 ((eq state 'edited) 'font-lock-constant-face)
1303 (t 'font-lock-variable-name-face))
1304 'mouse-face 'highlight)
1307 (format "%s" filename)
1309 (if isdir 'font-lock-comment-delimiter-face 'font-lock-function-name-face)
1312 "Directory\nVC operations can be applied to it\nmouse-3: Pop-up menu"
1313 "File\nmouse-3: Pop-up menu")
1314 'mouse-face 'highlight
1315 'keymap vc-dir-filename-mouse-map))))
1317 (defun vc-default-extra-status-menu (_backend)
1320 (defun vc-default-status-fileinfo-extra (_backend _file)
1321 "Default absence of extra information returned for a file."
1325 ;;; Support for desktop.el (adapted from what dired.el does).
1327 (declare-function desktop-file-name "desktop" (filename dirname))
1329 (defun vc-dir-desktop-buffer-misc-data (dirname)
1330 "Auxiliary information to be saved in desktop file."
1331 (cons (desktop-file-name default-directory dirname) vc-dir-backend))
1333 (defvar desktop-missing-file-warning)
1335 (defun vc-dir-restore-desktop-buffer (_filename _buffername misc-data)
1336 "Restore a `vc-dir' buffer specified in a desktop file."
1337 (let ((dir (car misc-data))
1338 (backend (cdr misc-data)))
1339 (if (file-directory-p dir)
1341 (vc-dir dir backend)
1343 (message "Desktop: Directory %s no longer exists." dir)
1344 (when desktop-missing-file-warning (sit-for 1))
1347 (add-to-list 'desktop-buffer-mode-handlers
1348 '(vc-dir-mode . vc-dir-restore-desktop-buffer))
1353 ;;; vc-dir.el ends here