1 ;;; vc-dispatcher.el -- generic command-dispatcher facility.
3 ;; Copyright (C) 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: FSF (see below for full credits)
7 ;; Maintainer: Eric S. Raymond <esr@thyrsus.com>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; Designed and implemented by Eric S. Raymond, originally as part of VC mode.
28 ;; Stefan Monnier and Dan Nicolaescu contributed substantial work on the
35 ;; There is a class of front-ending problems that Emacs might be used
36 ;; to address that involves selecting sets of files, or possibly
37 ;; directories, and passing the selection set to slave commands. The
38 ;; prototypical example, from which this code is derived, is talking
39 ;; to version-control systems.
41 ;; vc-dispatcher.el is written to decouple the UI issues in such front
42 ;; ends from their application-specific logic. It also provides a
43 ;; service layer for running the slave commands either synchronously
44 ;; or asynchronously and managing the message/error logs from the
47 ;; Similar UI problems can be expected to come up in applications
48 ;; areas other than VCSes; IDEs and document search are two obvious ones.
49 ;; This mode is intended to ensure that the Emacs interfaces for all such
50 ;; beasts are consistent and carefully designed. But even if nothing
51 ;; but VC ever uses it, getting the layer separation right will be
54 ;; Dispatcher's universe:
56 ;; The universe consists of the file tree rooted at the current
57 ;; directory. The dispatcher's upper layer deduces some subset
58 ;; of the file tree from the state of the currently visited buffer
59 ;; and returns that subset, presumably to a client mode.
61 ;; The user may be looking at either of two different views; a buffer
62 ;; visiting a file, or a directory buffer generated by vc-dispatcher.
64 ;; The lower layer of this mode runs commands in subprocesses, either
65 ;; synchronously or asynchronously. Commands may be launched in one
66 ;; of two ways: they may be run immediately, or the calling mode can
67 ;; create a closure associated with a text-entry buffer, to be
68 ;; executed when the user types C-c to ship the buffer contents. In
69 ;; either case the command messages and error (if any) will remain
70 ;; available in a status buffer.
72 ;; Special behavior of dispatcher directory buffers:
74 ;; In dispatcher directory buffers, facilities to perform basic
75 ;; navigation and selection operations are provided by keymap and menu
76 ;; entries that dispatcher sets up itself, so they'll be uniform
77 ;; across all dispatcher-using client modes. Client modes are
78 ;; expected to append to these to provide mode-specific bindings.
80 ;; The standard map associates a 'state' slot (that the client mode
81 ;; may set) with each directory entry. The dispatcher knows nothing
82 ;; about the semantics of individual states, but mark and unmark commands
83 ;; treat all entries with the same state as the currently selected one as
88 ;; The main interface to the lower level is vc-do-command. This launches a
89 ;; command, synchronously or asynchronously, making the output available
90 ;; in a command log buffer. Two other functions, (vc-start-annotation) and
91 ;; (vc-finish-logentry), allow you to associate a command closure with an
92 ;; annotation buffer so that when the user confirms the comment the closure
93 ;; is run (with the comment as part of its context).
95 ;; The interface to the upper level has the two main entry points (vc-dir)
96 ;; and (vc-dispatcher-selection-set) and a couple of convenience functions.
97 ;; (vc-dir) sets up a dispatcher browsing buffer; (vc-dispatcher-selection-set)
98 ;; returns a selection set of files, either the marked files in a browsing
99 ;; buffer or the singleton set consisting of the file visited by the current
100 ;; buffer (when that is appropriate). It also does what is needed to ensure
101 ;; that on-disk files and the contents of their visiting Emacs buffers
104 ;; When the client mode adds a local mode-line-hook to a buffer, it
105 ;; will be called with the buffer file name as argument whenever the
106 ;; dispatcher resynchs the buffer.
110 ;; - log buffers need font-locking.
113 ;; General customization
114 (defcustom vc-logentry-check-hook nil
115 "Normal hook run by `vc-finish-logentry'.
116 Use this to impose your own rules on the entry in addition to any the
117 dispatcher client mode imposes itself."
121 (defcustom vc-delete-logbuf-window t
122 "If non-nil, delete the log buffer and window after each logical action.
123 If nil, bury that buffer instead.
124 This is most useful if you have multiple windows on a frame and would like to
125 preserve the setting."
129 (defcustom vc-command-messages nil
130 "If non-nil, display run messages from back-end commands."
134 (defcustom vc-suppress-confirm nil
135 "If non-nil, treat user as expert; suppress yes-no prompts on some things."
139 ;; Variables the user doesn't need to know about.
141 (defvar vc-log-operation nil
)
142 (defvar vc-log-after-operation-hook nil
)
143 (defvar vc-log-fileset
)
144 (defvar vc-log-extra
)
146 ;; In a log entry buffer, this is a local variable
147 ;; that points to the buffer for which it was made
148 ;; (either a file, or a directory buffer).
149 (defvar vc-parent-buffer nil
)
150 (put 'vc-parent-buffer
'permanent-local t
)
151 (defvar vc-parent-buffer-name nil
)
152 (put 'vc-parent-buffer-name
'permanent-local t
)
154 ;; Common command execution logic
156 (defun vc-process-filter (p s
)
157 "An alternative output filter for async process P.
158 One difference with the default filter is that this inserts S after markers.
159 Another is that undo information is not kept."
160 (let ((buffer (process-buffer p
)))
161 (when (buffer-live-p buffer
)
162 (with-current-buffer buffer
164 (let ((buffer-undo-list t
)
165 (inhibit-read-only t
))
166 (goto-char (process-mark p
))
168 (set-marker (process-mark p
) (point))))))))
170 (defun vc-setup-buffer (buf)
171 "Prepare BUF for executing a slave command and make it current."
172 (let ((camefrom (current-buffer))
173 (olddir default-directory
))
174 (set-buffer (get-buffer-create buf
))
175 (kill-all-local-variables)
176 (set (make-local-variable 'vc-parent-buffer
) camefrom
)
177 (set (make-local-variable 'vc-parent-buffer-name
)
178 (concat " from " (buffer-name camefrom
)))
179 (setq default-directory olddir
)
180 (let ((buffer-undo-list t
)
181 (inhibit-read-only t
))
184 (defvar vc-sentinel-movepoint
) ;Dynamically scoped.
186 (defun vc-process-sentinel (p s
)
187 (let ((previous (process-get p
'vc-previous-sentinel
))
188 (buf (process-buffer p
)))
189 ;; Impatient users sometime kill "slow" buffers; check liveness
190 ;; to avoid "error in process sentinel: Selecting deleted buffer".
191 (when (buffer-live-p buf
)
192 (when previous
(funcall previous p s
))
193 (with-current-buffer buf
194 (setq mode-line-process
195 (let ((status (process-status p
)))
196 ;; Leave mode-line uncluttered, normally.
197 (unless (eq 'exit status
)
198 (format " (%s)" status
))))
199 (let (vc-sentinel-movepoint)
200 ;; Normally, we want async code such as sentinels to not move point.
202 (goto-char (process-mark p
))
203 (let ((cmds (process-get p
'vc-sentinel-commands
)))
204 (process-put p
'vc-sentinel-commands nil
)
206 ;; Each sentinel may move point and the next one should be run
207 ;; at that new point. We could get the same result by having
208 ;; each sentinel read&set process-mark, but since `cmd' needs
209 ;; to work both for async and sync processes, this would be
210 ;; difficult to achieve.
211 (vc-exec-after cmd
))))
212 ;; But sometimes the sentinels really want to move point.
213 (when vc-sentinel-movepoint
214 (let ((win (get-buffer-window (current-buffer) 0)))
216 (goto-char vc-sentinel-movepoint
)
217 (with-selected-window win
218 (goto-char vc-sentinel-movepoint
))))))))))
220 (defun vc-set-mode-line-busy-indicator ()
221 (setq mode-line-process
222 (concat " " (propertize "[waiting...]"
223 'face
'mode-line-emphasis
225 "A command is in progress in this buffer"))))
227 (defun vc-exec-after (code)
228 "Eval CODE when the current buffer's process is done.
229 If the current buffer has no process, just evaluate CODE.
230 Else, add CODE to the process' sentinel."
231 (let ((proc (get-buffer-process (current-buffer))))
233 ;; If there's no background process, just execute the code.
234 ;; We used to explicitly call delete-process on exited processes,
235 ;; but this led to timing problems causing process output to be
236 ;; lost. Terminated processes get deleted automatically
238 ((or (null proc
) (eq (process-status proc
) 'exit
))
239 ;; Make sure we've read the process's output before going further.
240 (when proc
(accept-process-output proc
))
242 ;; If a process is running, add CODE to the sentinel
243 ((eq (process-status proc
) 'run
)
244 (vc-set-mode-line-busy-indicator)
245 (let ((previous (process-sentinel proc
)))
246 (unless (eq previous
'vc-process-sentinel
)
247 (process-put proc
'vc-previous-sentinel previous
))
248 (set-process-sentinel proc
'vc-process-sentinel
))
249 (process-put proc
'vc-sentinel-commands
250 ;; We keep the code fragments in the order given
251 ;; so that vc-diff-finish's message shows up in
252 ;; the presence of non-nil vc-command-messages.
253 (append (process-get proc
'vc-sentinel-commands
)
255 (t (error "Unexpected process state"))))
258 (defvar vc-post-command-functions nil
259 "Hook run at the end of `vc-do-command'.
260 Each function is called inside the buffer in which the command was run
261 and is passed 3 arguments: the COMMAND, the FILES and the FLAGS.")
263 (defvar w32-quote-process-args
)
265 (defun vc-delistify (filelist)
266 "Smash a FILELIST into a file list string suitable for info messages."
267 ;; FIXME what about file names with spaces?
268 (if (not filelist
) "." (mapconcat 'identity filelist
" ")))
271 (defun vc-do-command (buffer okstatus command file-or-list
&rest flags
)
272 "Execute a slave command, notifying user and checking for errors.
273 Output from COMMAND goes to BUFFER, or the current buffer if
274 BUFFER is t. If the destination buffer is not already current,
275 set it up properly and erase it. The command is considered
276 successful if its exit status does not exceed OKSTATUS (if
277 OKSTATUS is nil, that means to ignore error status, if it is
278 `async', that means not to wait for termination of the
279 subprocess; if it is t it means to ignore all execution errors).
280 FILE-OR-LIST is the name of a working file; it may be a list of
281 files or be nil (to execute commands that don't expect a file
282 name or set of files). If an optional list of FLAGS is present,
283 that is inserted into the command line before the filename."
284 ;; FIXME: file-relative-name can return a bogus result because
285 ;; it doesn't look at the actual file-system to see if symlinks
288 (mapcar (lambda (f) (file-relative-name (expand-file-name f
)))
289 (if (listp file-or-list
) file-or-list
(list file-or-list
))))
291 ;; What we're doing here is preparing a version of the command
292 ;; for display in a debug-progress message. If it's fewer than
293 ;; 20 characters display the entire command (without trailing
294 ;; newline). Otherwise display the first 20 followed by an ellipsis.
295 (concat (if (string= (substring command -
1) "\n")
296 (substring command
0 -
1)
299 (vc-delistify (mapcar (lambda (s) (if (> (length s
) 20) (concat (substring s
0 2) "...") s
)) flags
))
300 " " (vc-delistify files
))))
302 (unless (or (eq buffer t
)
303 (and (stringp buffer
)
304 (string= (buffer-name) buffer
))
305 (eq buffer
(current-buffer)))
306 (vc-setup-buffer buffer
))
307 ;; If there's some previous async process still running, just kill it.
308 (let ((oldproc (get-buffer-process (current-buffer))))
309 ;; If we wanted to wait for oldproc to finish before doing
310 ;; something, we'd have used vc-eval-after.
311 ;; Use `delete-process' rather than `kill-process' because we don't
312 ;; want any of its output to appear from now on.
313 (if oldproc
(delete-process oldproc
)))
314 (let ((squeezed (remq nil flags
))
315 (inhibit-read-only t
)
318 (setq squeezed
(nconc squeezed files
)))
319 (let ((exec-path (append vc-path exec-path
))
320 ;; Add vc-path to PATH for the execution of this command.
322 (cons (concat "PATH=" (getenv "PATH")
324 (mapconcat 'identity vc-path path-separator
))
325 process-environment
))
326 (w32-quote-process-args t
))
327 (if (eq okstatus
'async
)
328 ;; Run asynchronously.
330 (let ((process-connection-type nil
))
331 (apply 'start-file-process command
(current-buffer)
333 (if vc-command-messages
334 (message "Running %s in background..." full-command
))
335 ;;(set-process-sentinel proc (lambda (p msg) (delete-process p)))
336 (set-process-filter proc
'vc-process-filter
)
338 `(if vc-command-messages
339 (message "Running %s in background... done" ',full-command
))))
341 (when vc-command-messages
342 (message "Running %s in foreground..." full-command
))
343 (let ((buffer-undo-list t
))
344 (setq status
(apply 'process-file command nil t nil squeezed
)))
345 (when (and (not (eq t okstatus
))
346 (or (not (integerp status
))
347 (and okstatus
(< okstatus status
))))
348 (unless (eq ?\s
(aref (buffer-name (current-buffer)) 0))
349 (pop-to-buffer (current-buffer))
350 (goto-char (point-min))
351 (shrink-window-if-larger-than-buffer))
352 (error "Running %s...FAILED (%s)" full-command
353 (if (integerp status
) (format "status %d" status
) status
))))
354 ;; We're done. But don't emit a status message if running
355 ;; asynchronously, it would just mislead.
356 (if (and vc-command-messages
(not (eq okstatus
'async
)))
357 (message "Running %s...OK = %d" full-command status
)))
359 `(run-hook-with-args 'vc-post-command-functions
360 ',command
',file-or-list
',flags
))
363 ;; These functions are used to ensure that the view the user sees is up to date
364 ;; even if the dispatcher client mode has messed with file contents (as in,
365 ;; for example, VCS keyword expansion).
367 (declare-function view-mode-exit
"view" (&optional return-to-alist exit-action all-win
))
369 (defun vc-position-context (posn)
370 "Save a bit of the text around POSN in the current buffer.
371 Used to help us find the corresponding position again later
372 if markers are destroyed or corrupted."
373 ;; A lot of this was shamelessly lifted from Sebastian Kremer's
377 (buffer-substring posn
378 (min (point-max) (+ posn
100)))))
380 (defun vc-find-position-by-context (context)
381 "Return the position of CONTEXT in the current buffer.
382 If CONTEXT cannot be found, return nil."
383 (let ((context-string (nth 2 context
)))
384 (if (equal "" context-string
)
387 (let ((diff (- (nth 1 context
) (buffer-size))))
388 (when (< diff
0) (setq diff
(- diff
)))
389 (goto-char (nth 0 context
))
390 (if (or (search-forward context-string nil t
)
391 ;; Can't use search-backward since the match may continue
393 (progn (goto-char (- (point) diff
(length context-string
)))
394 ;; goto-char doesn't signal an error at
395 ;; beginning of buffer like backward-char would
396 (search-forward context-string nil t
)))
397 ;; to beginning of OSTRING
398 (- (point) (length context-string
))))))))
400 (defun vc-context-matches-p (posn context
)
401 "Return t if POSN matches CONTEXT, nil otherwise."
402 (let* ((context-string (nth 2 context
))
403 (len (length context-string
))
405 (if (> end
(1+ (buffer-size)))
407 (string= context-string
(buffer-substring posn end
)))))
409 (defun vc-buffer-context ()
410 "Return a list (POINT-CONTEXT MARK-CONTEXT REPARSE).
411 Used by `vc-restore-buffer-context' to later restore the context."
412 (let ((point-context (vc-position-context (point)))
413 ;; Use mark-marker to avoid confusion in transient-mark-mode.
414 (mark-context (when (eq (marker-buffer (mark-marker)) (current-buffer))
415 (vc-position-context (mark-marker))))
416 ;; Make the right thing happen in transient-mark-mode.
418 (list point-context mark-context nil
)))
420 (defun vc-restore-buffer-context (context)
421 "Restore point/mark, and reparse any affected compilation buffers.
422 CONTEXT is that which `vc-buffer-context' returns."
423 (let ((point-context (nth 0 context
))
424 (mark-context (nth 1 context
)))
425 ;; if necessary, restore point and mark
426 (if (not (vc-context-matches-p (point) point-context
))
427 (let ((new-point (vc-find-position-by-context point-context
)))
428 (when new-point
(goto-char new-point
))))
431 (not (vc-context-matches-p (mark) mark-context
))
432 (let ((new-mark (vc-find-position-by-context mark-context
)))
433 (when new-mark
(set-mark new-mark
))))))
435 (defun vc-revert-buffer-internal (&optional arg no-confirm
)
436 "Revert buffer, keeping point and mark where user expects them.
437 Try to be clever in the face of changes due to expanded version-control
438 key words. This is important for typeahead to work as expected.
439 ARG and NO-CONFIRM are passed on to `revert-buffer'."
442 (let ((context (vc-buffer-context)))
443 ;; Use save-excursion here, because it may be able to restore point
444 ;; and mark properly even in cases where vc-restore-buffer-context
445 ;; would fail. However, save-excursion might also get it wrong --
446 ;; in this case, vc-restore-buffer-context gives it a second try.
448 ;; t means don't call normal-mode;
449 ;; that's to preserve various minor modes.
450 (revert-buffer arg no-confirm t
))
451 (vc-restore-buffer-context context
)))
453 (defun vc-resynch-window (file &optional keep noquery
)
454 "If FILE is in the current buffer, either revert or unvisit it.
455 The choice between revert (to see expanded keywords) and unvisit
456 depends on KEEP. NOQUERY if non-nil inhibits confirmation for
457 reverting. NOQUERY should be t *only* if it is known the only
458 difference between the buffer and the file is due to
459 modifications by the dispatcher client code, rather than user
461 (and (string= buffer-file-name file
)
464 (vc-revert-buffer-internal t noquery
)
465 ;; TODO: Adjusting view mode might no longer be necessary
466 ;; after RMS change to files.el of 1999-08-08. Investigate
467 ;; this when we install the new VC.
469 (if (file-writable-p file
)
471 (let ((view-old-buffer-read-only nil
))
474 (not (eq (get major-mode
'mode-class
) 'special
))
476 (run-hook-with-args 'mode-line-hook buffer-file-name
))
477 (kill-buffer (current-buffer)))))
479 (declare-function vc-dir-resynch-file
"vc-dir" (&optional fname
))
480 (declare-function vc-string-prefix-p
"vc" (prefix string
))
482 (defun vc-resynch-buffers-in-directory (directory &optional keep noquery
)
483 "Resync all buffers that visit files in DIRECTORY."
484 (dolist (buffer (buffer-list))
485 (let ((fname (buffer-file-name buffer
)))
486 (when (and fname
(vc-string-prefix-p directory fname
))
487 (vc-resynch-buffer fname keep noquery
)))))
489 (defun vc-resynch-buffer (file &optional keep noquery
)
490 "If FILE is currently visited, resynch its buffer."
491 (if (string= buffer-file-name file
)
492 (vc-resynch-window file keep noquery
)
493 (if (file-directory-p file
)
494 (vc-resynch-buffers-in-directory file keep noquery
)
495 (let ((buffer (get-file-buffer file
)))
497 (with-current-buffer buffer
498 (vc-resynch-window file keep noquery
))))))
499 ;; Try to avoid unnecessary work, a *vc-dir* buffer is only present
501 (when (memq 'vc-dir-resynch-file after-save-hook
)
502 (vc-dir-resynch-file file
)))
504 (defun vc-buffer-sync (&optional not-urgent
)
505 "Make sure the current buffer and its working file are in sync.
506 NOT-URGENT means it is ok to continue if the user says not to save."
507 (when (buffer-modified-p)
508 (if (or vc-suppress-confirm
509 (y-or-n-p (format "Buffer %s modified; save it? " (buffer-name))))
512 (error "Aborted")))))
516 ;; Set up key bindings for use while editing log messages
518 (defun vc-log-edit (fileset)
519 "Set up `log-edit' for use on FILE."
520 (setq default-directory
521 (with-current-buffer vc-parent-buffer default-directory
))
522 (log-edit 'vc-finish-logentry
524 `((log-edit-listfun .
(lambda () ',fileset
))
525 (log-edit-diff-function .
(lambda () (vc-diff nil
)))))
526 (set (make-local-variable 'vc-log-fileset
) fileset
)
527 (make-local-variable 'vc-log-extra
)
528 (set-buffer-modified-p nil
)
529 (setq buffer-file-name nil
))
531 (defun vc-start-logentry (files extra comment initial-contents msg logbuf action
&optional after-hook
)
532 "Accept a comment for an operation on FILES with extra data EXTRA.
533 If COMMENT is nil, pop up a LOGBUF buffer, emit MSG, and set the
534 action on close to ACTION. If COMMENT is a string and
535 INITIAL-CONTENTS is non-nil, then COMMENT is used as the initial
536 contents of the log entry buffer. If COMMENT is a string and
537 INITIAL-CONTENTS is nil, do action immediately as if the user had
538 entered COMMENT. If COMMENT is t, also do action immediately with an
539 empty comment. Remember the file's buffer in `vc-parent-buffer'
540 \(current one if no file). AFTER-HOOK specifies the local value
541 for `vc-log-after-operation-hook'."
543 (if (vc-dispatcher-browsing)
544 ;; If we are called from a directory browser, the parent buffer is
545 ;; the current buffer.
547 (if (and files
(equal (length files
) 1))
548 (get-file-buffer (car files
))
550 (if (and comment
(not initial-contents
))
551 (set-buffer (get-buffer-create logbuf
))
552 (pop-to-buffer (get-buffer-create logbuf
)))
553 (set (make-local-variable 'vc-parent-buffer
) parent
)
554 (set (make-local-variable 'vc-parent-buffer-name
)
555 (concat " from " (buffer-name vc-parent-buffer
)))
557 (make-local-variable 'vc-log-after-operation-hook
)
559 (setq vc-log-after-operation-hook after-hook
))
560 (setq vc-log-operation action
)
561 (setq vc-log-extra extra
)
564 (when (stringp comment
) (insert comment
)))
565 (if (or (not comment
) initial-contents
)
566 (message "%s Type C-c C-c when done" msg
)
567 (vc-finish-logentry (eq comment t
)))))
569 (declare-function vc-dir-move-to-goal-column
"vc-dir" ())
571 (defun vc-finish-logentry (&optional nocomment
)
572 "Complete the operation implied by the current log entry.
573 Use the contents of the current buffer as a check-in or registration
574 comment. If the optional arg NOCOMMENT is non-nil, then don't check
575 the buffer contents as a comment."
577 ;; Check and record the comment, if any.
579 (run-hooks 'vc-logentry-check-hook
))
580 ;; Sync parent buffer in case the user modified it while editing the comment.
581 ;; But not if it is a vc-dir buffer.
582 (with-current-buffer vc-parent-buffer
583 (or (vc-dispatcher-browsing) (vc-buffer-sync)))
584 (unless vc-log-operation
585 (error "No log operation is pending"))
586 ;; save the parameters held in buffer-local variables
587 (let ((logbuf (current-buffer))
588 (log-operation vc-log-operation
)
589 (log-fileset vc-log-fileset
)
590 (log-extra vc-log-extra
)
591 (log-entry (buffer-string))
592 (after-hook vc-log-after-operation-hook
)
593 (tmp-vc-parent-buffer vc-parent-buffer
))
594 (pop-to-buffer vc-parent-buffer
)
597 (funcall log-operation
601 ;; Remove checkin window (after the checkin so that if that fails
602 ;; we don't zap the log buffer and the typing therein).
603 ;; -- IMO this should be replaced with quit-window
604 (cond ((and logbuf vc-delete-logbuf-window
)
605 (delete-windows-on logbuf
(selected-frame))
606 ;; Kill buffer and delete any other dedicated windows/frames.
607 (kill-buffer logbuf
))
608 (logbuf (pop-to-buffer logbuf
)
610 (pop-to-buffer tmp-vc-parent-buffer
)))
611 ;; Now make sure we see the expanded headers
614 (lambda (file) (vc-resynch-buffer file vc-keep-workfiles t
))
616 (when (vc-dispatcher-browsing)
617 (vc-dir-move-to-goal-column))
618 (run-hooks after-hook
'vc-finish-logentry-hook
)))
620 (defun vc-dispatcher-browsing ()
621 "Are we in a directory browser buffer?"
622 (derived-mode-p 'vc-dir-mode
))
625 ;; (defun vc-dispatcher-in-fileset-p (fileset)
626 ;; (let ((member nil))
627 ;; (while (and (not member) fileset)
628 ;; (let ((elem (pop fileset)))
629 ;; (if (if (file-directory-p elem)
630 ;; (eq t (compare-strings buffer-file-name nil (length elem)
632 ;; (eq (current-buffer) (get-file-buffer elem)))
633 ;; (setq member t))))
636 ;; (defun vc-dispatcher-selection-set (&optional observer)
637 ;; "Deduce a set of files to which to apply an operation. Return a cons
638 ;; cell (SELECTION . FILESET), where SELECTION is what the user chose
639 ;; and FILES is the flist with any directories replaced by the listed files
642 ;; If we're in a directory display, the fileset is the list of marked files (if
643 ;; there is one) else the file on the current line. If not in a directory
644 ;; display, but the current buffer visits a file, the fileset is a singleton
645 ;; containing that file. Otherwise, throw an error."
648 ;; ;; Browsing with vc-dir
649 ;; ((vc-dispatcher-browsing)
650 ;; ;; If no files are marked, temporarily mark current file
651 ;; ;; and choose on that basis (so we get subordinate files)
652 ;; (if (not (vc-dir-marked-files))
654 ;; (vc-dir-mark-file)
655 ;; (cons (vc-dir-marked-files) (vc-dir-marked-only-files))
656 ;; (vc-dir-unmark-all-files t))
657 ;; (cons (vc-dir-marked-files) (vc-dir-marked-only-files))))
658 ;; ;; Visiting an eligible file
659 ;; ((buffer-file-name)
660 ;; (cons (list buffer-file-name) (list buffer-file-name)))
661 ;; ;; No eligible file -- if there's a parent buffer, deduce from there
662 ;; ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer)
663 ;; (with-current-buffer vc-parent-buffer
664 ;; (vc-dispatcher-browsing))))
665 ;; (with-current-buffer vc-parent-buffer
666 ;; (vc-dispatcher-selection-set)))
667 ;; ;; No good set here, throw error
668 ;; (t (error "No fileset is available here")))))
669 ;; ;; We assume, in order to avoid unpleasant surprises to the user,
670 ;; ;; that a fileset is not in good shape to be handed to the user if the
671 ;; ;; buffers visiting the fileset don't match the on-disk contents.
673 ;; (save-some-buffers
674 ;; nil (lambda () (vc-dispatcher-in-fileset-p (cdr selection)))))
677 (provide 'vc-dispatcher
)
679 ;; arch-tag: 7d08b17f-5470-4799-914b-bfb9fcf6a246
680 ;;; vc-dispatcher.el ends here