unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 70996@debbugs.gnu.org
Cc: Dmitry Gutov <dmitry@gutov.dev>
Subject: bug#70996: project-find-file defaults
Date: Fri, 17 May 2024 09:36:22 +0300	[thread overview]
Message-ID: <867cft2ggx.fsf@mail.linkov.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

(thing-at-point 'filename) in project-find-file is a very useful feature
that often helps to use a string under point as a partial file name
to match a project file name as substring.  So it's like 'M-.'
that navigates by file names instead of identifiers.

But the problem is that in this case it drops the current file name
as the default value that is also useful in many cases.

Fortunately, the minibuffer supports a list of default values,
like in the following patch:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: project-find-file-at-point.patch --]
[-- Type: text/x-diff, Size: 2389 bytes --]

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index a95d1267dd2..5e6516b3b64 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1077,8 +1130,9 @@ project-find-file
          (dirs (list root))
          (project-files-relative-names t))
     (project-find-file-in
-     (or (thing-at-point 'filename)
-         (and buffer-file-name (project--find-default-from buffer-file-name pr)))
+     (delq nil (list (and buffer-file-name (project--find-default-from
+                                            buffer-file-name pr))
+                     (thing-at-point 'filename)))
      dirs pr include-all)))
 
 ;;;###autoload
@@ -1100,8 +1154,9 @@ project-or-external-find-file
                 (project-external-roots pr)))
          (project-file-history-behavior t))
     (project-find-file-in
-     (or (thing-at-point 'filename)
-         (and buffer-file-name (project--find-default-from buffer-file-name pr)))
+     (delq nil (list (and buffer-file-name (project--find-default-from
+                                            buffer-file-name pr))
+                     (thing-at-point 'filename)))
      dirs pr include-all)))
 
 (defcustom project-read-file-name-function #'project--read-file-cpd-relative
@@ -1163,11 +1218,14 @@ project--read-file-cpd-relative
                          (setq all-files
                                (delete common-parent-directory all-files))
                          t))
-         (mb-default (if (and common-parent-directory
-                              mb-default
-                              (file-name-absolute-p mb-default))
-                         (file-relative-name mb-default common-parent-directory)
-                       mb-default))
+         (mb-default (mapcar (lambda (mb-default)
+                               (if (and common-parent-directory
+                                        mb-default
+                                        (file-name-absolute-p mb-default))
+                                   (file-relative-name
+                                    mb-default common-parent-directory)
+                                 mb-default))
+                             (ensure-list mb-default)))
          (substrings (mapcar (lambda (s) (substring s cpd-length)) all-files))
          (_ (when included-cpd
               (setq substrings (cons "./" substrings))))

             reply	other threads:[~2024-05-17  6:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17  6:36 Juri Linkov [this message]
2024-05-28 16:32 ` bug#70996: project-find-file defaults Juri Linkov
2024-06-08  0:28 ` Dmitry Gutov
2024-06-09 16:51   ` Juri Linkov
2024-06-11  0:02     ` Dmitry Gutov
2024-06-11 16:58       ` Juri Linkov
2024-06-11 20:04         ` Dmitry Gutov
2024-06-12  0:11       ` Spencer Baugh
2024-06-12 13:52         ` Dmitry Gutov
2024-06-12 20:04           ` Dmitry Gutov
2024-06-14 17:00           ` Juri Linkov
2024-06-14 17:24             ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=867cft2ggx.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=70996@debbugs.gnu.org \
    --cc=dmitry@gutov.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).