]> git.eshelyaron.com Git - emacs.git/commitdiff
New command project-find-matching-file
authorDmitry Gutov <dmitry@gutov.dev>
Wed, 12 Feb 2025 17:17:29 +0000 (19:17 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 13 Feb 2025 11:51:29 +0000 (12:51 +0100)
* lisp/progmodes/project.el (project--read-project-list):
Ensure that the directory has a trailing '/' (bug#75983).

(cherry picked from commit 82da36286265bb34baf39425a880dc11285648f2)

lisp/progmodes/project.el

index 59da1b89211ffdb775b13abd5e237f7920336fbb..12e934e0fa569acf893663e09aabd0bebfedb0b6 100644 (file)
@@ -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