diff options
| author | Eric S. Raymond | 2008-05-05 22:33:44 +0000 |
|---|---|---|
| committer | Eric S. Raymond | 2008-05-05 22:33:44 +0000 |
| commit | b236ab0da995fa79a16298d9094e748c09cb9f9c (patch) | |
| tree | 6bca45c499a0c42730bb5b3deac9ca6917fb8c87 | |
| parent | 834ee1313076b3fb4e1e4cc6d960c026f1f72d6e (diff) | |
| download | emacs-b236ab0da995fa79a16298d9094e748c09cb9f9c.tar.gz emacs-b236ab0da995fa79a16298d9094e748c09cb9f9c.zip | |
More policy-mechanism separation.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/vc-dispatcher.el | 68 | ||||
| -rw-r--r-- | lisp/vc.el | 57 |
3 files changed, 81 insertions, 49 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 415981c8e13..92bb56f5392 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2008-05-05 Eric S. Raymond <esr@snark.thyrsus.com> | ||
| 2 | |||
| 3 | * vc.el (vc-deduce-fileset): Lift all the policy and UI | ||
| 4 | stuff out of this function, move it to vc-dispatcher-selection-set.k | ||
| 5 | |||
| 1 | 2008-05-05 Sam Steingold <sds@gnu.org> | 6 | 2008-05-05 Sam Steingold <sds@gnu.org> |
| 2 | 7 | ||
| 3 | * window.el (delete-other-windows-vertically): New function. | 8 | * window.el (delete-other-windows-vertically): New function. |
diff --git a/lisp/vc-dispatcher.el b/lisp/vc-dispatcher.el index b2484ec6b75..6dd459ddf74 100644 --- a/lisp/vc-dispatcher.el +++ b/lisp/vc-dispatcher.el | |||
| @@ -1602,5 +1602,73 @@ U - if the cursor is on a file: unmark all the files with the same VC state | |||
| 1602 | 1602 | ||
| 1603 | (put 'vc-dir-mode 'mode-class 'special) | 1603 | (put 'vc-dir-mode 'mode-class 'special) |
| 1604 | 1604 | ||
| 1605 | (defun vc-dispatcher-browsing () | ||
| 1606 | "Are we in a directory browser buffer?" | ||
| 1607 | (or vc-dired-mode (eq major-mode 'vc-dir-mode))) | ||
| 1608 | |||
| 1609 | (defun vc-dispatcher-selection-set (eligible | ||
| 1610 | &optional | ||
| 1611 | allow-directory-wildcard | ||
| 1612 | allow-inegible | ||
| 1613 | include-files-not-directories) | ||
| 1614 | "Deduce a set of files to which to apply an operation. Return the fileset. | ||
| 1615 | If we're in VC-dired mode, the fileset is the list of marked files. | ||
| 1616 | Otherwise, if we're looking at a buffer for which ELIGIBLE returns non-NIL, | ||
| 1617 | the fileset is a singleton containing this file. | ||
| 1618 | If neither of these things is true, but ALLOW-DIRECTORY-WILDCARD is on | ||
| 1619 | and we're in a dired buffer, select the current directory. | ||
| 1620 | If none of these conditions is met, but ALLOW-INELIGIBLE is on and the | ||
| 1621 | visited file is not registered, return a singleton fileset containing it. | ||
| 1622 | If INCLUDE-FILES-NOT-DIRECTORIES then if directories are marked, | ||
| 1623 | return the list of VC files in those directories instead of | ||
| 1624 | the directories themselves. | ||
| 1625 | Otherwise, throw an error." | ||
| 1626 | (cond | ||
| 1627 | ;; Browsing with dired | ||
| 1628 | (vc-dired-mode | ||
| 1629 | (let ((marked (dired-map-over-marks (dired-get-filename) nil))) | ||
| 1630 | (if marked | ||
| 1631 | marked | ||
| 1632 | (error "No files have been selected.")))) | ||
| 1633 | ;; Browsing with vc-dir | ||
| 1634 | ((eq major-mode 'vc-dir-mode) | ||
| 1635 | (or | ||
| 1636 | (if include-files-not-directories | ||
| 1637 | (vc-dir-marked-only-files) | ||
| 1638 | (vc-dir-marked-files)) | ||
| 1639 | (list (vc-dir-current-file)))) | ||
| 1640 | ;; Visiting an eligible file | ||
| 1641 | ((funcall eligible buffer-file-name) | ||
| 1642 | (list buffer-file-name)) | ||
| 1643 | ;; No eligible file -- if there's a parent buffer, deuce from there | ||
| 1644 | ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer) | ||
| 1645 | (with-current-buffer vc-parent-buffer | ||
| 1646 | (vc-dispatcher-browsing)))) | ||
| 1647 | (progn | ||
| 1648 | (set-buffer vc-parent-buffer) | ||
| 1649 | (vc-dispatcher-selection-set))) | ||
| 1650 | ;; No parent buffer, we may want to select entire directory | ||
| 1651 | ;; | ||
| 1652 | ;; This is guarded by an enabling arg so users won't potentially | ||
| 1653 | ;; shoot themselves in the foot by modifying a fileset they can't | ||
| 1654 | ;; verify by eyeball. Allow it for nondestructive commands like | ||
| 1655 | ;; making diffs, or possibly for destructive ones that have | ||
| 1656 | ;; confirmation prompts. | ||
| 1657 | ((and allow-directory-wildcard | ||
| 1658 | ;; I think this is a misfeature. For now, I'll leave it in, but | ||
| 1659 | ;; I'll disable it anywhere else than in dired buffers. --Stef | ||
| 1660 | (and (derived-mode-p 'dired-mode) | ||
| 1661 | (equal buffer-file-name nil) | ||
| 1662 | (equal list-buffers-directory default-directory))) | ||
| 1663 | (progn | ||
| 1664 | (message "All eligible files below %s selected." | ||
| 1665 | default-directory) | ||
| 1666 | (list default-directory))) | ||
| 1667 | ;; Last, if we're allowing ineligible files and visiting one, select it. | ||
| 1668 | ((and allow-ineligible (not (eligible buffer-file-name))) | ||
| 1669 | (list buffer-file-name)) | ||
| 1670 | ;; No good set here, throw error | ||
| 1671 | (t (error "No fileset is available here.")))) | ||
| 1672 | |||
| 1605 | ;; arch-tag: 7d08b17f-5470-4799-914b-bfb9fcf6a246 | 1673 | ;; arch-tag: 7d08b17f-5470-4799-914b-bfb9fcf6a246 |
| 1606 | ;;; vc-dispatcher.el ends here | 1674 | ;;; vc-dispatcher.el ends here |
diff --git a/lisp/vc.el b/lisp/vc.el index 8e9d0469b27..830951538ea 100644 --- a/lisp/vc.el +++ b/lisp/vc.el | |||
| @@ -1059,58 +1059,17 @@ If INCLUDE-FILES-NOT-DIRECTORIES then if directories are marked, | |||
| 1059 | return the list of files VC files in those directories instead of | 1059 | return the list of files VC files in those directories instead of |
| 1060 | the directories themselves. | 1060 | the directories themselves. |
| 1061 | Otherwise, throw an error." | 1061 | Otherwise, throw an error." |
| 1062 | (let (backend) | 1062 | (let* ((fileset (vc-dispatcher-selection-set |
| 1063 | (cond | 1063 | #'vc-registered |
| 1064 | (vc-dired-mode | 1064 | allow-directory-wildcard |
| 1065 | (let ((marked (dired-map-over-marks (dired-get-filename) nil))) | 1065 | allow-unregistered |
| 1066 | (unless marked | 1066 | include-files-not-directories)) |
| 1067 | (error "No files have been selected.")) | 1067 | (backend (vc-backend (car fileset)))) |
| 1068 | ;; All members of the fileset must have the same backend | 1068 | ;; All members of the fileset must have the same backend |
| 1069 | (setq backend (vc-backend (car marked))) | 1069 | (dolist (f (cdr fileset)) |
| 1070 | (dolist (f (cdr marked)) | ||
| 1071 | (unless (eq (vc-backend f) backend) | 1070 | (unless (eq (vc-backend f) backend) |
| 1072 | (error "All members of a fileset must be under the same version-control system."))) | 1071 | (error "All members of a fileset must be under the same version-control system."))) |
| 1073 | (cons backend marked))) | 1072 | (cons backend fileset))) |
| 1074 | ((eq major-mode 'vc-dir-mode) | ||
| 1075 | ;; FIXME: Maybe the backend should be stored in a buffer-local | ||
| 1076 | ;; variable? | ||
| 1077 | (cons (vc-responsible-backend default-directory) | ||
| 1078 | (or | ||
| 1079 | (if include-files-not-directories | ||
| 1080 | (vc-dir-marked-only-files) | ||
| 1081 | (vc-dir-marked-files)) | ||
| 1082 | (list (vc-dir-current-file))))) | ||
| 1083 | ((setq backend (vc-backend buffer-file-name)) | ||
| 1084 | (cons backend (list buffer-file-name))) | ||
| 1085 | ((and vc-parent-buffer (or (buffer-file-name vc-parent-buffer) | ||
| 1086 | (with-current-buffer vc-parent-buffer | ||
| 1087 | (or vc-dired-mode (eq major-mode 'vc-dir-mode))))) | ||
| 1088 | (progn | ||
| 1089 | (set-buffer vc-parent-buffer) | ||
| 1090 | (vc-deduce-fileset))) | ||
| 1091 | ;; This is guarded by an enabling arg so users won't potentially | ||
| 1092 | ;; shoot themselves in the foot by modifying a fileset they can't | ||
| 1093 | ;; verify by eyeball. Allow it for nondestructive commands like | ||
| 1094 | ;; making diffs, or possibly for destructive ones that have | ||
| 1095 | ;; confirmation prompts. | ||
| 1096 | ((and allow-directory-wildcard | ||
| 1097 | ;; I think this is a misfeature. For now, I'll leave it in, but | ||
| 1098 | ;; I'll disable it anywhere else than in dired buffers. --Stef | ||
| 1099 | (and (derived-mode-p 'dired-mode) | ||
| 1100 | (equal buffer-file-name nil) | ||
| 1101 | (equal list-buffers-directory default-directory))) | ||
| 1102 | (progn | ||
| 1103 | (message "All version-controlled files below %s selected." | ||
| 1104 | default-directory) | ||
| 1105 | (cons | ||
| 1106 | (vc-responsible-backend default-directory) | ||
| 1107 | (list default-directory)))) | ||
| 1108 | ;; If we're allowing unregistered fiiles and visiting one, select it. | ||
| 1109 | ((and allow-unregistered (not (vc-registered buffer-file-name))) | ||
| 1110 | (cons (vc-responsible-backend | ||
| 1111 | (file-name-directory (buffer-file-name))) | ||
| 1112 | (list buffer-file-name))) | ||
| 1113 | (t (error "No fileset is available here."))))) | ||
| 1114 | 1073 | ||
| 1115 | (defun vc-ensure-vc-buffer () | 1074 | (defun vc-ensure-vc-buffer () |
| 1116 | "Make sure that the current buffer visits a version-controlled file." | 1075 | "Make sure that the current buffer visits a version-controlled file." |