From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#41572: 28.0.50; [PATCH] Support plain project marked with file .emacs-project Date: Sun, 26 Sep 2021 02:13:39 +0300 Message-ID: References: <5f584d83-ef45-9912-bfbc-d2f00b24b9fd@yandex.ru> <87pnahjgdr.fsf@linkov.net> <87ftb92u8q.fsf@thornhill.no> <0ab90cf2-eab2-6fea-6698-4164d7753cd7@yandex.ru> <87d06ck2b0.fsf@thornhill.no> <2fbe5d5d-03a1-212b-9dd7-4723e168ad06@yandex.ru> <5EpzudgjedeKADsX4_Tq-2WtNm3XKXmZjnEI7Y1lmw-Pcn_KrzKPD1o31Ele0JOIrZ1ITDdeQrOsJTHfGVPJlzyLhmqjxP3rmVVzou8KEBo=@thornhill.no> <2a70c748-e250-2f96-5d74-712b6d71e8be@yandex.ru> <871riitzch.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------8889971C46DE9C778BB18D39" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32965"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 Cc: Zhu Zihao , Theodor Thornhill , 41572@debbugs.gnu.org, Juri Linkov To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 26 01:14:11 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 1mUGrz-0008RQ-18 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Sep 2021 01:14:11 +0200 Original-Received: from localhost ([::1]:48070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUGrx-00048K-4G for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Sep 2021 19:14:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUGrq-00047w-Hv for bug-gnu-emacs@gnu.org; Sat, 25 Sep 2021 19:14:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUGrq-0002mn-A1 for bug-gnu-emacs@gnu.org; Sat, 25 Sep 2021 19:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mUGrq-0008MM-2q for bug-gnu-emacs@gnu.org; Sat, 25 Sep 2021 19:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Sep 2021 23:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41572 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 41572-submit@debbugs.gnu.org id=B41572.163261163032103 (code B ref 41572); Sat, 25 Sep 2021 23:14:02 +0000 Original-Received: (at 41572) by debbugs.gnu.org; 25 Sep 2021 23:13:50 +0000 Original-Received: from localhost ([127.0.0.1]:35096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mUGrd-0008Lj-Tp for submit@debbugs.gnu.org; Sat, 25 Sep 2021 19:13:50 -0400 Original-Received: from mail-wr1-f48.google.com ([209.85.221.48]:44690) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mUGrc-0008LT-6m for 41572@debbugs.gnu.org; Sat, 25 Sep 2021 19:13:48 -0400 Original-Received: by mail-wr1-f48.google.com with SMTP id d6so38848262wrc.11 for <41572@debbugs.gnu.org>; Sat, 25 Sep 2021 16:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=3QNX3ntMhZb0ls26odfk48nxG7WM5TsFRBN/18B6MJo=; b=mcpfSKrB2gy+8bTYlZyDkKAKabgVkTZ0iA8fQlwa3LBBDw3Gwts5CeAPEM+ycngwz1 TItX17ICK8a+VqBjQpRAVEt0GDCTXcUe/MxGYyBkm6SP6IK6l0BOibWxxLHTQkd8rZzU WAy8/YZhVAJyr0M0PUsry8gxYKf6Z4Wnap8GqCAOV/diIdw7Fu7YV8f/e5mbKfmFhvNi TCoqp/z3XIqzHCl+CdsTbbaPDF3nSsb51HENXe0FyQ+qm3zgydbB9a8grYrg0xWUU3s/ N95YFc0DZr0LXnjsqHrOMBy2qFyQVLaLcmrCn57ZpPPvKtwOkBGvWD2AEO+wwDjMgj74 o2jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=3QNX3ntMhZb0ls26odfk48nxG7WM5TsFRBN/18B6MJo=; b=e3wvGuoLFE9qIdjskU1BaeOb74gjjOWDzy71wRwmaMZyPH9Rne4a+zoaykUtSPoxbv /CFAKSuFwKvhZvQLVjv7/uCdWfbfLAX2JjtCztSzjKcQ8xRrJlu+2AYdOKfDY9IjsTdG 4rVlZEplYmKXKuWycQFeCT0YZ4BpY4veuxeCqtZU7BFE1KOyehH6rVotxOp+JaezYb0T 0uCTCD2mHh5E2A4r8FpkLsv929Ujft++kgQ3rQeutCLLszFgXnkZ8YvSkTo0SKQ/3P8M 9bNNNjBGIEua16NF1YPFT02CySqQe8DwDSUWYXfCEbfbIlfjblTT2oKuH0Dmqmy8AFlj wL4A== X-Gm-Message-State: AOAM530qYt0IvousApuPZjsoIYuD+smHaLnftbEm4vJPhuglmzh/oKy7 WN71BrPpD0O960peCfmxSCbKCKlvTXM= X-Google-Smtp-Source: ABdhPJwybYJ+B66CSt7cje1eNQ0BCqbasIi0KUJtah8xrWB2nDzGdSwgNFbWoOron6aPqSYHAl0r/w== X-Received: by 2002:a5d:4608:: with SMTP id t8mr19504043wrq.136.1632611622343; Sat, 25 Sep 2021 16:13:42 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id z8sm2134709wrm.63.2021.09.25.16.13.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 25 Sep 2021 16:13:41 -0700 (PDT) In-Reply-To: <871riitzch.fsf@gnus.org> Content-Language: en-US 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:215537 Archived-At: This is a multi-part message in MIME format. --------------8889971C46DE9C778BB18D39 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 01.10.2020 06:11, Lars Ingebrigtsen wrote: > If I'm skimming this thread correctly, there wasn't much enthusiasm for > the proposed new functionality, so I'm closing this bug report. If > there's further progress to be made here, please respond to the debbugs > address and we'll reopen. There are valid issues here, but there was no clear picture of how to solve them best. But it would be good to try to do that (at least to some extent) before Emacs 28 is released. The first issue is that projects that don't use any of the supported VCS are not recognized at all. Since these days most large projects do use version control, we can expect that projects which do not, should be relatively small. And our find-based implementation will generally be fast enough. Also, looking at the home-grown project definitions out there, people often don't bother with the 'ignores' method, so maybe a backend which provides no way to specify them will still cover most of the needs. It could be extended with such feature later anyway. Patch adding such backend with a customizable list of "markers" is attached. I wasn't sure whether to add support for wildcards there, because file-expand-wildcards does not optimize for the trivial case, and directory-files is slower than file-exists-p. I'm mostly worried about Tramp performance here, but some pathologically huge directory could be a problem as well, IDK. project-fallback-markers only includes .dir-locals.el, but it can be easily customized. Not sure if it should include other standard file names, such as Makefile, Gemfile, mix.exs, and so on. The first version doesn't have them. Another question is the name. 'plain' sounds not very descriptive. I've considered 'fallback' and 'novc', eventually settling on the former. Opinions welcome, though. --------------8889971C46DE9C778BB18D39 Content-Type: text/x-patch; charset=UTF-8; name="project-fallback.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="project-fallback.diff" diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 57a961c260..8eee0c7d27 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -165,7 +165,7 @@ project :version "28.1" :group 'tools) -(defvar project-find-functions (list #'project-try-vc) +(defvar project-find-functions (list #'project-try-vc #'project-try-fallback) "Special hook to find the project containing a given directory. Each functions on this hook is called in turn with one argument, the directory in which to look, and should return @@ -662,6 +662,27 @@ project-buffers (push buf bufs))) (nreverse bufs))) +(defcustom project-fallback-markers '(".dir-locals.el") + "List of file name to use as fallback project root markers. + +Each entry should be a relative file name (no directory part). + +The fallback project backend detects a project as a directory +containing one of these files." + :type 'list) + +(defun project-try-fallback (dir) + (let ((root (locate-dominating-file dir #'project-fallback--root-p))) + (and root (cons 'fallback root)))) + +(defun project-fallback--root-p (dir) + (let ((default-directory dir)) + (seq-some (lambda (marker) (file-exists-p marker)) + project-fallback-markers))) + +(cl-defmethod project-root ((project (head fallback))) + (cdr project)) + ;;; Project commands --------------8889971C46DE9C778BB18D39--