From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#66649: 29.1; `project-remember-projects-under' behavior doesn't match its doc Date: Wed, 01 Nov 2023 21:36:25 +0000 Message-ID: <87y1fhxijq.fsf@posteo.net> References: <87v8b18qh7.fsf@cassou.me> <057a5ddf-2974-ce53-f795-b146e205db1e@yandex.ru> <87bkcd1utg.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34230"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Damien Cassou , 66649@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 01 22:37:59 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qyIuS-0008WS-RI for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Nov 2023 22:37:57 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyIu5-0007lE-Kb; Wed, 01 Nov 2023 17:37:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyIu0-0007e1-Ja for bug-gnu-emacs@gnu.org; Wed, 01 Nov 2023 17:37:30 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyItz-0004bO-K7 for bug-gnu-emacs@gnu.org; Wed, 01 Nov 2023 17:37:28 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyIuX-000637-Pt for bug-gnu-emacs@gnu.org; Wed, 01 Nov 2023 17:38:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 Nov 2023 21:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66649 X-GNU-PR-Package: emacs Original-Received: via spool by 66649-submit@debbugs.gnu.org id=B66649.169887463123182 (code B ref 66649); Wed, 01 Nov 2023 21:38:01 +0000 Original-Received: (at 66649) by debbugs.gnu.org; 1 Nov 2023 21:37:11 +0000 Original-Received: from localhost ([127.0.0.1]:52824 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyIti-00061q-Sb for submit@debbugs.gnu.org; Wed, 01 Nov 2023 17:37:11 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:37589) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyItf-00061Z-Pa for 66649@debbugs.gnu.org; Wed, 01 Nov 2023 17:37:09 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id D8281240101 for <66649@debbugs.gnu.org>; Wed, 1 Nov 2023 22:36:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1698874586; bh=rogWbQVCj2Uy7F3kDJS1xHkcR7BxP+P9xo/NVqeoDuo=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=U8prMiFQAci1aSGLKBmteAS9ZOQ7zBBRvA+DDjE98F9Awnzek7jaB/sw7bw/R65o9 rjPqKlivBi5bRT1QWp0IulKcrGy7GBcqLKRurXtCH5I5S46JuVjWHhR9WIafqITkTk x597901ZOfQ/mTieiH0CLwrDGtenjeeVvO/Q81GDVHKJBVizLl3XrcrszB7O+OP6rJ b/NMFay1TQHMLOmeb56RsGw1ANYP29zxgFwhUxGAsnDWARMh53yJ5zvNlHhyPIaw+c 35hp4VyuM5x8tXvbQXRdNb1idY8eoKBboe9O18taA4biWxZ6x6MJLdyfIIZbaqzI0Y AIyNvZuh66JMA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4SLL156zN2z9rxF; Wed, 1 Nov 2023 22:36:25 +0100 (CET) In-Reply-To: (Dmitry Gutov's message of "Wed, 1 Nov 2023 21:04:00 +0200") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273624 Archived-At: --=-=-= Content-Type: text/plain Dmitry Gutov 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Simplify-project-remember-projects-under.patch >From cf1541ddba61e3c6106a133a9b6b662f0f34749d Mon Sep 17 00:00:00 2001 From: Philip Kaludercic 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 --=-=-= Content-Type: text/plain > 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. --=-=-=--