unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Spencer Baugh <sbaugh@janestreet.com>
Cc: 63870@debbugs.gnu.org
Subject: bug#63870: 29.0.90; project.el can't dynamically populate the project list
Date: Wed, 28 Jun 2023 14:24:46 +0300	[thread overview]
Message-ID: <83sfabvngh.fsf@gnu.org> (raw)
In-Reply-To: <ierbkh01za5.fsf@janestreet.com> (message from Spencer Baugh on Tue, 27 Jun 2023 15:27:30 -0400)

> From: Spencer Baugh <sbaugh@janestreet.com>
> 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.

> +(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.

> +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?)

Thanks.





  reply	other threads:[~2023-06-28 11:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-03 11:55 bug#63870: 29.0.90; project.el can't dynamically populate the project list Spencer Baugh
2023-06-15 19:30 ` Spencer Baugh
2023-06-16  5:45   ` Eli Zaretskii
2023-06-17  2:55 ` Dmitry Gutov
2023-06-27 19:29   ` Spencer Baugh
2023-06-27 19:27 ` Spencer Baugh
2023-06-28 11:24   ` Eli Zaretskii [this message]
2023-06-28 12:05     ` Spencer Baugh
2023-06-28 12:18       ` Eli Zaretskii
2023-06-28 12:37         ` Spencer Baugh
2023-06-28 12:56           ` Eli Zaretskii
2023-07-18  2:21             ` Dmitry Gutov
2023-07-18 16:28               ` Spencer Baugh
2023-07-18 17:41                 ` Juri Linkov
2023-07-27  1:59                   ` Dmitry Gutov
2023-07-27  1:57                 ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83sfabvngh.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=63870@debbugs.gnu.org \
    --cc=sbaugh@janestreet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).