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#50297: 28.0.50; Aggregate project functions for project.el Date: Wed, 22 Sep 2021 18:55:37 +0000 Message-ID: <87lf3ophhy.fsf@posteo.net> References: <87h7f5ok5l.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="24290"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 50297@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 22 21:01:34 2021 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 1mT7Us-0006AB-64 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Sep 2021 21:01:34 +0200 Original-Received: from localhost ([::1]:44286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT7Up-0004Te-K9 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Sep 2021 15:01:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT7PX-00046t-KP for bug-gnu-emacs@gnu.org; Wed, 22 Sep 2021 14:56:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40159) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mT7PW-0002bT-AZ for bug-gnu-emacs@gnu.org; Wed, 22 Sep 2021 14:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mT7PW-0004DR-7x for bug-gnu-emacs@gnu.org; Wed, 22 Sep 2021 14:56: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, 22 Sep 2021 18:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50297 X-GNU-PR-Package: emacs Original-Received: via spool by 50297-submit@debbugs.gnu.org id=B50297.163233694716177 (code B ref 50297); Wed, 22 Sep 2021 18:56:02 +0000 Original-Received: (at 50297) by debbugs.gnu.org; 22 Sep 2021 18:55:47 +0000 Original-Received: from localhost ([127.0.0.1]:51705 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mT7PH-0004Cr-79 for submit@debbugs.gnu.org; Wed, 22 Sep 2021 14:55:47 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:48301) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mT7PF-0004Cb-Jx for 50297@debbugs.gnu.org; Wed, 22 Sep 2021 14:55:46 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id A5C8D240101 for <50297@debbugs.gnu.org>; Wed, 22 Sep 2021 20:55:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1632336938; bh=NKNFQF3Dw8m9eKiFx6T4hAzxMVpYkyNh7Pq0o5+GSqo=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=ixUeVZx7oVdLWkqT6EPfqBxj3Fkwv8jy+nCZKuKPh6FV41ShpS/5ULzyaqNMRRN0f x7VbtHj8tFO+gzk+N+qHqGtrOd2uknN0Srma1wGyRd1vjRN+RfWor5fFLa/H9IMDSw A6Hr6/ZQIOmCc699QyRDVQ+5haPpY+Zcsn5V2prp7MHlBhQVIlwF2oTQPm6dZKm0Pv J+FM/BJQdSC8LqrV4rvUevFwFWnXbeKa2wiY9+Eox1c9KaqiZ3dXZqksKSm7Ridu2D Luvg+EwyJJOSKuq4bSJzE04TK/zCIHVMyftqTP0KE8KAN7jm7c+dDjkO/D7LPd6nfv REY5l3SGw/o0A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4HF6tx6yQQz9rxV; Wed, 22 Sep 2021 20:55:37 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB In-Reply-To: (Dmitry Gutov's message of "Wed, 22 Sep 2021 03:31:42 +0300") 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" Xref: news.gmane.io gmane.emacs.bugs:215115 Archived-At: --=-=-= Content-Type: text/plain Here is the updated patch, with the new names and optional recursion: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-aggregate-project-discovery-and-maintenance-func.patch >From 4779aae9d1c18cd2dc2b8f54322b48b0e11ac5fb Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 31 Aug 2021 14:12:13 +0200 Subject: [PATCH] Add aggregate project discovery and maintenance functions * project.el (project-remember-project): Add optional no-write argument (project-remember-projects-under): Add command (project-forget-zombie-projects): Add command (project-forget-known-projects): Add command --- lisp/progmodes/project.el | 72 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index ebd21d4b60..977b1ae185 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1290,9 +1290,10 @@ project--write-project-list (write-region nil nil filename nil 'silent)))) ;;;###autoload -(defun project-remember-project (pr) +(defun project-remember-project (pr &optional no-write) "Add project PR to the front of the project list. -Save the result in `project-list-file' if the list of projects has changed." +Save the result in `project-list-file' if the list of projects +has changed, and NO-WRITE is nil." (project--ensure-read-project-list) (let ((dir (project-root pr))) (unless (equal (caar project--list) dir) @@ -1300,7 +1301,8 @@ project-remember-project (when (equal dir (car ent)) (setq project--list (delq ent project--list)))) (push (list dir) project--list) - (project--write-project-list)))) + (unless no-write + (project--write-project-list))))) (defun project--remove-from-project-list (project-root report-message) "Remove directory PROJECT-ROOT of a missing project from the project list. @@ -1357,6 +1359,70 @@ project-execute-extended-command (let ((default-directory (project-root (project-current t)))) (call-interactively #'execute-extended-command))) +(defun project-remember-projects-under (dir &optional recursive) + "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." + (interactive "DDirectory: \nP") + (project--ensure-read-project-list) + (let ((queue (directory-files dir t nil t)) (count 0) + (known (make-hash-table + :size (* 2 (length project--list)) + :test #'equal ))) + (dolist (project (mapcar #'car project--list)) + (puthash project t known)) + (while queue + (when-let ((subdir (pop queue)) + ((file-directory-p subdir)) + ((not (gethash subdir known)))) + (when-let (pr (project--find-in-directory subdir)) + (project-remember-project pr t) + (message "Found %s..." (project-root pr)) + (setq count (1+ count))) + (when (and recursive (file-symlink-p subdir)) + (setq queue (nconc (directory-files subdir t nil t) queue)) + (puthash subdir t known)))) + (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")))) + count)) + +(defun project-forget-zombie-projects () + "Forget all known projects that don't exist any more." + (interactive) + (dolist (proj (project-known-project-roots)) + (unless (file-exists-p proj) + (project-remove-known-project proj)))) + +(defun project-forget-known-projects (dir &optional recursive) + "Forget all known projects below a directory DIR. +If RECURSIVE is non-nil, recurse into all subdirectories to +remove all known projects. After finishing, a message is printed +summarizing the progress. The function returns the number of +forgotten projects." + (interactive "DDirectory: \nP") + (let ((count 0)) + (if recursive + (dolist (proj (project-known-project-roots)) + (when (file-in-directory-p proj dir) + (project-remove-known-project proj) + (setq count (1+ count)))) + (dolist (proj (project-known-project-roots)) + (when (file-equal-p (file-name-directory proj) dir) + (project-remove-known-project proj) + (setq count (1+ count))))) + (if (zerop count) + (message "No projects were forgotten") + (project--write-project-list) + (message "%d project%s were forgotten" + count (if (= count 1) "" "s"))) + count)) + ;;; Project switching -- 2.30.2 --=-=-= Content-Type: text/plain -- Philip Kaludercic --=-=-=--