From: Dmitry Gutov Date: Wed, 12 Feb 2025 17:17:29 +0000 (+0200) Subject: New command project-find-matching-file X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5feb78ce7fda711dfd5e332bb04c951d312baadb;p=emacs.git New command project-find-matching-file * lisp/progmodes/project.el (project--read-project-list): Ensure that the directory has a trailing '/' (bug#75983). (cherry picked from commit 82da36286265bb34baf39425a880dc11285648f2) --- diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 59da1b89211..12e934e0fa5 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1286,6 +1286,34 @@ directories listed in `vc-directory-exclusion-list'." (user-error "You didn't specify the file") (find-file file)))) +;;;###autoload +(defun project-find-matching-file () + "Visit the file that matches the current one, in another project. +It will skip to the same line number as well. +A matching file has the same file name relative to the project root. +When called during switching to another project, this command will +detect it and use the override. Otherwise, it prompts for the project +to use from the known list." + (interactive) + (let* ((pr (project-current)) + (line (line-number-at-pos nil t)) + relative-name mirror-name) + (if project-current-directory-override + (let* (project-current-directory-override + (real-project (project-current t))) + (setq relative-name (file-relative-name buffer-file-name + (project-root real-project)))) + (setq relative-name (file-relative-name buffer-file-name (project-root pr))) + (setq pr (project-read-project))) + (setq mirror-name (expand-file-name relative-name (project-root pr))) + (if (not (file-exists-p mirror-name)) + (user-error "File `%s' not found in `%s'" relative-name (project-root pr)) + (find-file mirror-name) + (save-restriction + (widen) + (goto-char (point-min)) + (forward-line (1- line)))))) + (defun project--completing-read-strict (prompt collection &optional predicate hist mb-default