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 13:12:27 +0000 Message-ID: <87bkcd1utg.fsf@posteo.net> References: <87v8b18qh7.fsf@cassou.me> <057a5ddf-2974-ce53-f795-b146e205db1e@yandex.ru> 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="17294"; 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 14:13:51 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 1qyB2d-0004Lm-81 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 01 Nov 2023 14:13:51 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyB2H-0008Ck-TE; Wed, 01 Nov 2023 09:13:29 -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 1qyB2G-0008CX-S1 for bug-gnu-emacs@gnu.org; Wed, 01 Nov 2023 09:13:29 -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 1qyB2G-0002xh-AD for bug-gnu-emacs@gnu.org; Wed, 01 Nov 2023 09:13:28 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyB2o-0007xC-DA for bug-gnu-emacs@gnu.org; Wed, 01 Nov 2023 09:14:02 -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 13:14:02 +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.169884439930493 (code B ref 66649); Wed, 01 Nov 2023 13:14:02 +0000 Original-Received: (at 66649) by debbugs.gnu.org; 1 Nov 2023 13:13:19 +0000 Original-Received: from localhost ([127.0.0.1]:50184 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyB23-0007vg-AW for submit@debbugs.gnu.org; Wed, 01 Nov 2023 09:13:19 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:49015) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyB1x-0007vM-5b for 66649@debbugs.gnu.org; Wed, 01 Nov 2023 09:13:13 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id A069F240101 for <66649@debbugs.gnu.org>; Wed, 1 Nov 2023 14:12:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1698844348; bh=zAetayvNN8n4NngJMzTw2J/DcJKh+oQ1JhFBaSblFGU=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=O2876bdVdwQuoNhhyigv12A2RgQHA5zL4lMDv1wYuPSLLbpgXqCpjTDsGSKaHTjOR lxLl+GQL+1OB/19HFfVRQeRzJSavjN3bHTRiQ1eui8wDbEJS+90lzkIBX6pwCgp/3U 27bPuSv6tipuzJbPVc1SNKZKzR5WijhdZPbqd4zKR3HnyCfHE/Pm46032erEY6ZgOB nKCXsnARNzgwye+h1OVsJKPqcnuNzPwKh9ISJ1uJGR3/COonn9PGDqkc5/KCJFGvsN 35zbCg9F1ylfbBbHd+LLiDQRC/nZ7EL1qw3MOV/fBhR+w7c5/v2q4ig/B6AN4AfIwU FSHvD/ZlNBKdg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4SL6qc0J9jz6tvv; Wed, 1 Nov 2023 14:12:27 +0100 (CET) In-Reply-To: <057a5ddf-2974-ce53-f795-b146e205db1e@yandex.ru> (Dmitry Gutov's message of "Fri, 20 Oct 2023 18:46:41 +0300") 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:273603 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Dmitry Gutov writes: > Hi Damien, thanks for the report. > > On 20/10/2023 14:48, Damien Cassou wrote: >> the documentation of `project-remember-projects-under' is: >> "Index all projects below a directory DIR. If RECURSIVE is >> non-nil, recurse into all subdirectories to find more projects. >> After finishing, a message is printed summarizing the progress. The >> function returns the number of detected projects." >> Regardless of the value of RECURSIVE, I understand from the above >> that >> all child directories of the DIR argument will be investigated. The doc >> doesn't say anything about investigating if DIR is itself a project or >> not so I think it would make sense if the function wasn't. >> But the code says otherwise (as far as I understand it): >> (defun project-remember-projects-under (dir &optional recursive) >> (let ((queue (list dir))) >> ;; =E2=80=A6 >> (while queue >> (when-let ((subdir (pop queue)) >> ((file-directory-p subdir))) >> ;; maybe register `subdir' as a project >> ;; =E2=80=A6 >> (when (and recursive (file-directory-p subdir)) >> (setq queue (nconc (directory-files subdir =E2=80=A6) queue))= ))))) >> The code above seems to investigate DIR first and, if RECURSIVE is >> non-nil, look at the directories below it. >> Also, the second check (file-directory-p subdir) seems unnecessary >> because of the first one. >> There is a part of the code I don't understand: >> (unless (eq recursive 'in-progress) >> It seems nowhere in the code nor in the documentation do we say >> anything >> about this 'in-progress special value. Is it a left over from a previous >> (recursive) version of the algorithm? > > Philip, could you look into this? One idea would be to just simplify the entire implementation by relying on directory-files and directory-files-recursively. Say something like this: --=-=-= Content-Type: text/plain Content-Disposition: inline diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index fda1081eb62..e0d5e706e82 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 #'file-directory-p) + (cl-delete-if-not #'file-directory-p (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 () --=-=-=--