unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Damien Cassou <damien@cassou.me>, 66649@debbugs.gnu.org
Subject: bug#66649: 29.1; `project-remember-projects-under' behavior doesn't match its doc
Date: Wed, 01 Nov 2023 21:36:25 +0000	[thread overview]
Message-ID: <87y1fhxijq.fsf@posteo.net> (raw)
In-Reply-To: <af172fc0-8142-0110-d2f9-be5aed3a5655@yandex.ru> (Dmitry Gutov's message of "Wed, 1 Nov 2023 21:04:00 +0200")

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

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 01/11/2023 15:12, Philip Kaludercic wrote:
>> One idea would be to just simplify the entire implementation by relying
>> on directory-files and directory-files-recursively.  Say something like
>> this:
>
> Looks, good, just once thing:
>
>> +                  (directory-files-recursively dir "" t #'file-directory-p)
>
> The argument PREDICATE is not in Emacs 26.1 (which should remain
> compatible). But it doesn't help anyway, because that predicate is
> only used to determine whether to recurse into a subdirectory, and not
> to filter out files. So the full list of all files is generated
> anyway.

OK, here is the updated patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Simplify-project-remember-projects-under.patch --]
[-- Type: text/x-diff, Size: 2976 bytes --]

From cf1541ddba61e3c6106a133a9b6b662f0f34749d Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Wed, 1 Nov 2023 22:34:28 +0100
Subject: [PATCH] Simplify 'project-remember-projects-under'

* lisp/progmodes/project.el (project-remember-projects-under): Instead
of traversing the directories manually, re-use
`directory-files-recursively' to reduce complexity.  (Bug#66649)
---
 lisp/progmodes/project.el | 47 +++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index fda1081eb62..935f7a7b873 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1821,35 +1821,28 @@ project-remember-projects-under
 projects."
   (interactive "DDirectory: \nP")
   (project--ensure-read-project-list)
-  (let ((queue (list dir))
-        (count 0)
-        (known (make-hash-table
-                :size (* 2 (length project--list))
-                :test #'equal )))
+  (let ((dirs (if recursive
+                  (directory-files-recursively dir "" t)
+                (directory-files dir t)))
+        (known (make-hash-table :size (* 2 (length project--list))
+                                :test #'equal))
+        (count 0))
     (dolist (project (mapcar #'car project--list))
       (puthash project t known))
-    (while queue
-      (when-let ((subdir (pop queue))
-                 ((file-directory-p subdir)))
-        (when-let ((project (project--find-in-directory subdir))
-                   (project-root (project-root project))
-                   ((not (gethash project-root known))))
-          (project-remember-project project t)
-          (puthash project-root t known)
-          (message "Found %s..." project-root)
-          (setq count (1+ count)))
-        (when (and recursive (file-directory-p subdir))
-          (setq queue
-                (nconc
-                 (directory-files
-                  subdir t directory-files-no-dot-files-regexp t)
-                 queue)))))
-    (unless (eq recursive 'in-progress)
-      (if (zerop count)
-          (message "No projects were found")
-        (project--write-project-list)
-        (message "%d project%s were found"
-                 count (if (= count 1) "" "s"))))
+    (dolist (subdir dirs)
+      (when-let (((file-directory-p subdir))
+                 (project (project--find-in-directory subdir))
+                 (project-root (project-root project))
+                 ((not (gethash project-root known))))
+        (project-remember-project project t)
+        (puthash project-root t known)
+        (message "Found %s..." project-root)
+        (setq count (1+ count))))
+    (if (zerop count)
+        (message "No projects were found")
+      (project--write-project-list)
+      (message "%d project%s were found"
+               count (if (= count 1) "" "s")))
     count))
 
 (defun project-forget-zombie-projects ()
-- 
2.39.2


[-- Attachment #3: Type: text/plain, Size: 425 bytes --]



> If the performance still looks okay to you, I have no objections. Just
> remove that last argument, and it's good to install.

I'd say that Damien can try it out and report if it works well enough.
I worry that the files returned by `directory-files-recursively' might
slow down the function considerably.  Perhaps it might be better to
write a little function just for project.el to only generate a list of
directories.

  reply	other threads:[~2023-11-01 21:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20 11:48 bug#66649: 29.1; `project-remember-projects-under' behavior doesn't match its doc Damien Cassou
2023-10-20 15:46 ` Dmitry Gutov
2023-11-01 13:12   ` Philip Kaludercic
2023-11-01 19:04     ` Dmitry Gutov
2023-11-01 21:36       ` Philip Kaludercic [this message]
2023-11-01 22:39         ` Dmitry Gutov
2023-11-02 19:58           ` Damien Cassou
2023-11-02 20:41             ` Dmitry Gutov
2023-11-03 13:00               ` Damien Cassou
2023-11-08  8:13                 ` Philip Kaludercic
2023-11-08 19:56                   ` Dmitry Gutov
2023-11-08 19:58                     ` Philip Kaludercic
2023-11-08 20:16                       ` Dmitry Gutov
2023-11-08 21:13                         ` Damien Cassou
2023-11-08 21:16                           ` 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=87y1fhxijq.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=66649@debbugs.gnu.org \
    --cc=damien@cassou.me \
    --cc=dgutov@yandex.ru \
    /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).