1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

New command vc-working-tree-switch-project (bug#79024)

* lisp/vc/vc.el (vc-working-tree-switch-project): New command.
* lisp/vc/vc-hooks.el (vc-prefix-map): Bind it to C-x v w s.
* doc/emacs/vc1-xtra.texi (Other Working Trees):
* etc/NEWS: Document it.
This commit is contained in:
Sean Whitton 2025-08-10 11:22:15 +01:00
parent e79f38b662
commit 38c5742cba
4 changed files with 39 additions and 7 deletions

View file

@ -285,7 +285,11 @@ tree.
Add a new working tree.
@item C-x v w w
Visit this file in another working tree.
Visit this file or directory in another working tree.
@item C-x v w s
Invoke @kbd{C-x p p} (@code{project-switch-project}) but limited to
other working trees.
@item C-x v w x
Delete a working tree you no longer need.
@ -313,12 +317,24 @@ new working tree.
@findex vc-switch-working-tree
Once your repository has other working trees, you can use the command
@kbd{C-x v w w} (@code{vc-switch-working-tree}) to switch between them.
It tries to find the analogue of the current buffer's file
under another working tree. Typically the sets of workfiles
under different working trees differ more in file contents than in which
files do and do not exist. In other words, the file the
current buffer visits probably exists in other working trees too, and
this command lets you switch to those versions of the file.
It tries to find the analogue of the current buffer's file or directory
under another working tree. Typically the sets of workfiles under
different working trees differ more in file contents than in which files
do and do not exist. In other words, the file or directory the current
buffer visits probably exists in other working trees too, and this
command lets you switch to those versions of the file.
@kindex C-x v w s
@findex vc-working-tree-switch-project
An alternative way to switch between working trees is @kbd{C-x v w s}
(@code{vc-working-tree-switch-project}). This prompts you to select a
working tree, and then displays a menu of commands to operate on it.
This is in fact just @kbd{C-x p p} (@code{project-switch-project})
(@pxref{Switching Projects}) but with the selection of projects limited
to other working trees. The main difference between @kbd{C-x v w w} and
@kbd{C-x v w s} is that the former looks for an analogue of the current
buffer in the other working tree while the latter considers the other
working tree as a whole, independent project.
@kindex C-x v w x
@kindex C-x v w R

View file

@ -1946,6 +1946,7 @@ other working trees:
- 'C-x v w c': Add a new working tree.
- 'C-x v w w': Visit this file in another working tree.
- 'C-x v w s': Like 'C-x p p' but limited to other working trees.
- 'C-x v w x': Delete a working tree you no longer need.
- 'C-x v w R': Relocate a working tree to another file name.

View file

@ -968,6 +968,7 @@ In the latter case, VC mode is deactivated for this buffer."
"!" #'vc-edit-next-command
"w c" #'vc-add-working-tree
"w w" #'vc-switch-working-tree
"w s" #'vc-working-tree-switch-project
"w x" #'vc-delete-working-tree
"w R" #'vc-move-working-tree)
(fset 'vc-prefix-map vc-prefix-map)

View file

@ -4443,6 +4443,20 @@ to the root of this working tree."
(let ((project-current-directory-override directory))
(project-find-matching-buffer)))
;;;###autoload
(defun vc-working-tree-switch-project (dir)
"Like \\[project-switch-project] but limited to projects with the same backing repository.
Must be called from within an existing VC working tree.
Prompts for the directory file name of the other working tree."
;; There is no point in calling this from Lisp as opposed to calling
;; `project-switch-project' directly because it is a trivial wrapper.
(declare (interactive-only project-switch-project))
(interactive
(list
(vc--prompt-other-working-tree (vc-responsible-backend default-directory)
"Other working tree to switch to")))
(project-switch-project dir))
;;;###autoload
(defun vc-delete-working-tree (backend directory)
"Delete working tree DIRECTORY with same backing repository as this tree.