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 03:22:33 +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="------------B58A981BA8E68E443A635214" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17599"; 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 02:23: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 1mUHwk-0004L1-K6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Sep 2021 02:23:10 +0200 Original-Received: from localhost ([::1]:41870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUHwi-0006KE-Rt for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Sep 2021 20:23:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUHwc-0006K5-21 for bug-gnu-emacs@gnu.org; Sat, 25 Sep 2021 20:23:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUHwb-0006xn-RP for bug-gnu-emacs@gnu.org; Sat, 25 Sep 2021 20:23:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mUHwb-0001fH-Mq for bug-gnu-emacs@gnu.org; Sat, 25 Sep 2021 20:23:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 Sep 2021 00:23:01 +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.16326157656376 (code B ref 41572); Sun, 26 Sep 2021 00:23:01 +0000 Original-Received: (at 41572) by debbugs.gnu.org; 26 Sep 2021 00:22:45 +0000 Original-Received: from localhost ([127.0.0.1]:35146 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mUHwL-0001el-6H for submit@debbugs.gnu.org; Sat, 25 Sep 2021 20:22:45 -0400 Original-Received: from mail-wr1-f50.google.com ([209.85.221.50]:41881) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mUHwJ-0001eV-Dc for 41572@debbugs.gnu.org; Sat, 25 Sep 2021 20:22:44 -0400 Original-Received: by mail-wr1-f50.google.com with SMTP id w29so39158819wra.8 for <41572@debbugs.gnu.org>; Sat, 25 Sep 2021 17:22:43 -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=SjWfTar/kX2u97meKkfQsnhKKWoCnEX9udcQmXMZ+Ac=; b=nXRaqwv7aCb+00fOzN9FuQG69xaJEQFZQhul7VBPzAzap2dPFdMB4MXL68y5m+8yTs JsE+uIY32HU9rSXXsIt2+Y81EFTRwQyRjU6P9BAktSobrs9Qd9Ttd36S1B9/cGGVKLQU WCsHDuYjE3U0rBvqOdZB8AKUaT9IIyt9Tc6xmGHc2gulype/U45dnadshYEzjFRBhWbQ khEkPuSzdEm0iMiAMStdSyXNte0DJ84iSQGyt1BaGjei4LSR+vlPc9lTUY1+PKTSvlMR laR1vsRJNNKzPbNCmYtiLF3Yh+HELWA1uGfg2i8clRhC12k+znjyX4OUraLrBYNjMhRb 6bZQ== 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=SjWfTar/kX2u97meKkfQsnhKKWoCnEX9udcQmXMZ+Ac=; b=k77WTuA1QBDsSoahDieCeQxbdfCA1/XmB3H25PNIWjIxQnEbQEGVEkInEoatbcR0tD go6f64cOwQ6YFY/ZMyFktUSj4aoFCQQTtopi6+wjcCy6iksfi0fAP65at1qPAAktiTaj sWY8hDDn2Eio1FWqBa/2hIKVongmKBis44o+KRb+OUoxq5yBsZsu1o7mVW27M0fNVJ7D GzLwQtvNVAqQCgpXvk3E3GlRXaTiR52Zd5BU8tKKsK7L7dtRODAm+6JUjuK0uo64YjVv WdMj64oaMZps2oZVThWjAMEpNTWLFtRj5h+U910M1j1CEHcakY4WErkhc7pTwfrjO5je v8zA== X-Gm-Message-State: AOAM533gklWtt6pNpiiNsiQoE8EJZw79LWfCr6cFzPad3NOILgziw7+S xdwXM/5oApvIcmcosH+n1lU= X-Google-Smtp-Source: ABdhPJw/kPOzBRSuaQknogYzggig0SdGTqmZsZ1HfQusoNucu7vZ0JACM7cVbFMgBn+KeN47k7Ku2w== X-Received: by 2002:a05:6000:1446:: with SMTP id v6mr20072502wrx.427.1632615757564; Sat, 25 Sep 2021 17:22:37 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id x14sm12512481wmc.10.2021.09.25.17.22.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 25 Sep 2021 17:22:36 -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:215540 Archived-At: This is a multi-part message in MIME format. --------------B58A981BA8E68E443A635214 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Another issue is people working on monorepos (often backed by Git) sometimes want to split them into separate projects. Either because they only work on a certain part of the whole project, or because they want to use Eglot, and that package has tied LSP roots detection to project roots (but the language server might expect some project configuration files in the root which reside in a subdirectory). Here's a typical question/request for this functionality: https://emacs.stackexchange.com/questions/58463/project-el-override-project-root-with-dir-local-var/58468 Patch attached, it adds new user option project-vc-subprojects which alters the root-finding logic and cuts out the subproject contents from the parent project with the mechanism of "ignores". The latter capability (excluding subproject's files) informed the choice of the approach. Which is altering the vc project backend's behavior, rather that offering this feature through another backend, like the one added in the previous patch, for example. I don't know if all users of this feature will want them excluded, though. The attached implementation does, and maybe another option could be added to disable this. Or we could drop this part of the behavior, insisting that users who want it could add the corresponding entries to project-vc-ignores. This way they would be listing the subprojects twice, however. And the project-vc-merge-submodules=nil behavior matches the other option (submodule files are excluded from the parent). Again, thoughts welcome. --------------B58A981BA8E68E443A635214 Content-Type: text/x-patch; charset=UTF-8; name="project-vc-subprojects.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="project-vc-subprojects.diff" diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 57a961c260..e45667ed15 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -369,6 +369,23 @@ project-vc-merge-submodules :package-version '(project . "0.2.0") :safe #'booleanp) +(defcustom project-vc-subprojects nil + "List of relative directory names to consider separate projects. +Each entry should a string, name of a subproject root directory +relative to the VC root. + +Every entry in this list will be considered a separate project +for the purposes of files listings, searches, etc, and the parent +project will exclude those files. + +One would usually set this variable through .dir-locals.el. + +If subprojects are Git submodules, you can use the variable +`project-vc-merge-submodules' instead." + :type 'list + :version "28.1" + :safe (lambda (val) (and (listp val) (seq-every-p #'stringp val)))) + ;; FIXME: Using the current approach, major modes are supposed to set ;; this variable to a buffer-local value. So we don't have access to ;; the "external roots" of language A from buffers of language B, which @@ -428,7 +445,22 @@ project-try-vc root))))) ('nil nil) (_ (ignore-errors (vc-call-backend backend 'root dir)))))) - (and root (cons 'vc root)))) + (when root + (let* ((relative-dir (file-relative-name dir root)) + (subproject (seq-find + (lambda (sub-dir) + (string-prefix-p (file-name-as-directory sub-dir) + relative-dir)) + (project--value-in-dir + 'project-vc-subprojects + dir)))) + (if subproject + (cons 'vc (propertize + (concat root subproject) + ;; Side-channel so we don't change the value format. + ;; But we could do that instead. + 'vc-subproject t)) + (cons 'vc root)))))) (defun project--submodule-p (root) ;; XXX: We only support Git submodules for now. @@ -467,7 +499,9 @@ project-external-roots (cl-defmethod project-files ((project (head vc)) &optional dirs) (mapcan (lambda (dir) - (let ((ignores (project--value-in-dir 'project-vc-ignores dir)) + (let ((ignores + (nconc (project--vc-subproject-ignores dir) + (project--value-in-dir 'project-vc-ignores dir))) backend) (if (and (file-equal-p dir (cdr project)) (setq backend (vc-responsible-backend dir)) @@ -579,6 +613,12 @@ project--git-submodules (nreverse res))) (file-missing nil))) +(defun project--vc-subproject-ignores (dir) + (unless (get-text-property 0 'vc-subproject dir) + (mapcar + (lambda (supb) (format "./%s" (file-name-as-directory supb))) + (project--value-in-dir 'project-vc-subprojects dir)))) + (cl-defmethod project-ignores ((project (head vc)) dir) (let* ((root (cdr project)) backend) @@ -608,6 +648,7 @@ project-ignores (vc-call-backend backend 'ignore-completion-table root) (vc-not-supported () nil))))) (project--value-in-dir 'project-vc-ignores root) + (project--vc-subproject-ignores root) (mapcar (lambda (dir) (concat dir "/")) --------------B58A981BA8E68E443A635214--