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