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