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: Thu, 23 Sep 2021 10:46:18 +0000 Message-ID: <87czoz7eo5.fsf@posteo.net> References: <87h7f5ok5l.fsf@posteo.net> <87lf3ophhy.fsf@posteo.net> <0e6238a4-9a35-f70e-051a-3a75ac6fc583@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="10934"; 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 Thu Sep 23 12:48:12 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 1mTMGx-0002a2-DW for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 12:48:11 +0200 Original-Received: from localhost ([::1]:56846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTMGw-0007BP-Cg for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 06:48:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTMGo-00079X-Fw for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:48:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTMGo-0002ja-8Z for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mTMGo-0006OO-5s for bug-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:48:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87h7f5ok5l.fsf@posteo.net> Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 23 Sep 2021 10:48: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.163239407824558 (code B ref 50297); Thu, 23 Sep 2021 10:48:02 +0000 Original-Received: (at 50297) by debbugs.gnu.org; 23 Sep 2021 10:47:58 +0000 Original-Received: from localhost ([127.0.0.1]:52799 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mTMGj-0006O2-Jk for submit@debbugs.gnu.org; Thu, 23 Sep 2021 06:47:58 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:43771) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mTMGg-0006Nj-Kg for 50297@debbugs.gnu.org; Thu, 23 Sep 2021 06:47:56 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 0C82A240107 for <50297@debbugs.gnu.org>; Thu, 23 Sep 2021 12:47:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1632394067; bh=c3Kw7iUUohHmsvbKAfRtmsz+JFBBBq4xFbHTcddLYew=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=K/+X7lDCAIruU7IPha8syQ1blIfSvOavAjkYlbSzE9GKdWdnrVZbviceRjJSv1wGJ EMm73cSfRT7pk9e3zSnJKH7QW+iVwkJgRU4HlDa+AZOi7SCXdYwf7dMraYArdfEfai OG+1D4F/7StbL/tCV6LEHfwrKLOMwhfVVBqcO3Eyqv+XpbPW5NYDTKdLh9GAAh8rU9 Gv2WUgUi/1Yeo6+/Y7YQL1J2jREN5ipbYkndQodNBi4oscghZDFqrWP2sEE0F/DYB1 Yq834+jJ/MST/TgSBGjWj76ibW9ih+MqGtngMJkeo0+03W5nN46t9Uz+sP/laDT455 vMva0bnjhLKiQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4HFX14258yz9rxB; Thu, 23 Sep 2021 12:47:20 +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 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:215178 Archived-At: --=-=-= Content-Type: text/plain Dmitry Gutov writes: > On 22.09.2021 21:55, Philip Kaludercic wrote: >> + (project-remove-known-project proj)))) > > This one is called 'project-forget-project' now. > >> +(defun project-forget-known-projects (dir &optional recursive) > > And let's call this one 'project-forget-projects-under'. > > Looks good otherwise, thanks. Sorry about that, forgot to byte-compile before preparing the patch. This should fix the issues: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-aggregate-project-discovery-and-maintenance-func.patch >From 45492ec9fb9f2706f6ac0e7317ec1b0f7ce25091 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-projects-under): 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 9b63f4b1bc..57a961c260 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1296,9 +1296,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) @@ -1306,7 +1307,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. @@ -1363,6 +1365,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-forget-project proj)))) + +(defun project-forget-projects-under (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-forget-project proj) + (setq count (1+ count)))) + (dolist (proj (project-known-project-roots)) + (when (file-equal-p (file-name-directory proj) dir) + (project-forget-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 --=-=-=--