From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#63870: 29.0.90; project.el can't dynamically populate the project list Date: Wed, 28 Jun 2023 08:05:23 -0400 Message-ID: References: <83sfabvngh.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25186"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 63870@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 28 14:07:37 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 1qETxR-0006MU-4U for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 28 Jun 2023 14:07:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qETwR-0004je-Aq; Wed, 28 Jun 2023 08:06:35 -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 1qETvx-0004Jm-4V for bug-gnu-emacs@gnu.org; Wed, 28 Jun 2023 08:06:08 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qETvu-00005B-M9 for bug-gnu-emacs@gnu.org; Wed, 28 Jun 2023 08:06:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qETvu-0004v4-GE for bug-gnu-emacs@gnu.org; Wed, 28 Jun 2023 08:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Jun 2023 12:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63870 X-GNU-PR-Package: emacs Original-Received: via spool by 63870-submit@debbugs.gnu.org id=B63870.168795393318866 (code B ref 63870); Wed, 28 Jun 2023 12:06:02 +0000 Original-Received: (at 63870) by debbugs.gnu.org; 28 Jun 2023 12:05:33 +0000 Original-Received: from localhost ([127.0.0.1]:50208 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qETvR-0004uE-3F for submit@debbugs.gnu.org; Wed, 28 Jun 2023 08:05:33 -0400 Original-Received: from mxout6.mail.janestreet.com ([64.215.233.21]:58467) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qETvM-0004ts-Kx for 63870@debbugs.gnu.org; Wed, 28 Jun 2023 08:05:31 -0400 In-Reply-To: <83sfabvngh.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 28 Jun 2023 14:24:46 +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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:264208 Archived-At: Eli Zaretskii writes: >> From: Spencer Baugh >> Date: Tue, 27 Jun 2023 15:27:30 -0400 >> >> +(defun project-check-project (dir) >> + "If there's a project at DIR, remember it; otherwise, forget it. >> + >> +Return the found project, if any." >> + (let ((pr (project--find-in-directory dir))) >> + (if pr (project-remember-project pr) >> + (project-forget-project (file-name-as-directory dir))) >> + pr)) >> + >> +(defun project--watch-cb-children (recursive predicate event) >> + (unless (eq (cl-second event) 'stopped) >> + (dolist (file (cddr event)) >> + (condition-case _ (project-watch file recursive predicate) >> + ((file-error file-notify-error)))))) >> + >> +(defun project--watch-cb-this (dir event) >> + (unless (eq (cl-second event) 'stopped) >> + (when (project-check-project dir) >> + (file-notify-rm-watch (cl-first event))))) >> + >> +(defun project--file-notify-watch (dir callback &optional init) >> + "Like `file-notify-add-watch' but also calls CALLBACK immediately." >> + (let ((watch (file-notify-add-watch dir '(change) callback))) >> + (funcall callback (append (list watch 'started) init)))) > > Beware of watching a tree recursively: file notifications are not very > scalable, for more than one reason. For example, the inotify backend > consumes a file descriptor and a slot in the descriptor set monitored > by pselect per each file/directory you watch. And watching many > directories can overwhelm Emacs if some program (even unrelated to > Emacs) performs many file operations in that directory; VCS programs > are notorious in this regard, e.g., when you update from upstream. Absolutely. I am trying to be careful about this: project-watch shouldn't create watches on VCS directories. >> +(defun project-watch (dir &optional recursive predicate) >> + "Watch DIR until it becomes a project. >> + >> +We stop watching DIR once it becomes a project. > > This never explains what it means for a directory to "become a > project". It should, because this doc string begs that question. A directory "becomes a project" once some function on project-find-functions returns non-nil for it. I'll include this in the docstring of the next version of the patch. >> +If RECURSIVE is an integer greater than 0, we'll also run >> +`project-watch' on directories which appear inside DIR, >> +passing (1- RECURSIVE) as RECURSIVE. To achieve this, we'll >> +continue watching DIR even if it becomes a project. This can be >> +expensive, so it's better to pass small values of RECURSIVE, like >> +1 or 2. > > Are you sure this feature justifies the risks? When would someone > want to use it, while simultaneously limiting the value of RECURSIVE > to some small integer? (And what is considered "small" for these > purposes?) Imagine, for example, that a user has a directory ~/src. They make all their VCS clones directly under ~/src: ~/src/emacs, ~/src/glibc, etc. And when they work on a new project, they create that new clone under ~/src. If the user wanted all these VCS clones to show up in Emacs as soon as they're made, they could run (project-watch "~/src" 1). This would create a watch on ~/src, which would create watches on new empty directories under ~/src (e.g. ~/src/gdb); the watch on ~/src/gdb would stop if and when ~/src/gdb becomes a project (as defined above). So in the steady state, if ~/src contains only projects, Emacs would run exactly one watch, the one on ~/src. This is definitely okay. If, instead, ~/src has a two-level structure, where ~/src/emacs is not itself a clone but instead contains a clone for each branch, e.g. ~/src/emacs/emacs-29 and ~/src/emacs/trunk, then a user might run (project-watch "~/src" 2). Then in the steady state there would be one watch on ~/src and one watch on each subdirectory of ~/src, e.g. ~/src/emacs. (This is the setup I personally have.)