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: Mon, 11 Oct 2021 03:40:47 +0300 Message-ID: <564eb0ed-21c0-f298-a7e9-30d7caf7517f@yandex.ru> References: <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> <87zgrq2ctj.fsf@mail.linkov.net> <7cf254bf-a7e4-0121-3d0c-3a1b5dfabe0b@yandex.ru> <87r1d0at40.fsf@mail.linkov.net> <87wnmr793j.fsf@mail.linkov.net> <878rz6wrdp.fsf@mail.linkov.net> <9a74b6ac-14f4-c5f9-8d7e-91c1595d8a02@yandex.ru> <87wnmppdmr.fsf@mail.linkov.net> <966ef00b-fc7a-cd52-5fd8-600842797f65@yandex.ru> <87v925f6ee.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24839"; 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 , Lars Ingebrigtsen , Theodor Thornhill , 41572@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 11 02:41: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 1mZjNO-0006JR-VX for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Oct 2021 02:41:11 +0200 Original-Received: from localhost ([::1]:50934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZjNN-0006Ak-Hb for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Oct 2021 20:41:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZjNH-0006Aa-2B for bug-gnu-emacs@gnu.org; Sun, 10 Oct 2021 20:41:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mZjNG-0000yt-Q5 for bug-gnu-emacs@gnu.org; Sun, 10 Oct 2021 20:41:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mZjNG-0000Bi-Ad for bug-gnu-emacs@gnu.org; Sun, 10 Oct 2021 20:41: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: Mon, 11 Oct 2021 00:41: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.1633912859706 (code B ref 41572); Mon, 11 Oct 2021 00:41:02 +0000 Original-Received: (at 41572) by debbugs.gnu.org; 11 Oct 2021 00:40:59 +0000 Original-Received: from localhost ([127.0.0.1]:56119 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZjNC-0000BJ-TU for submit@debbugs.gnu.org; Sun, 10 Oct 2021 20:40:59 -0400 Original-Received: from mail-lf1-f53.google.com ([209.85.167.53]:33316) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZjN9-0000B2-5T for 41572@debbugs.gnu.org; Sun, 10 Oct 2021 20:40:57 -0400 Original-Received: by mail-lf1-f53.google.com with SMTP id j21so48457362lfe.0 for <41572@debbugs.gnu.org>; Sun, 10 Oct 2021 17:40:55 -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:content-transfer-encoding; bh=qIliTL0cIqgA1UGFsyOf/KbZIejwSEtSADCmlmijcKw=; b=SnbIyCcJZkjfHhCZZ55fMblfn9NnZ3JwjO9mJ2UPBfE8dZV2g59rZwy8QufIaC4nfQ G1zQuHRqldoQqEd/pV8mOkZ9OI3LTedYrS0+AyHeE2fs8gWVyN2YbGRJgxVV7x14HTxZ oc9Q0QzVbDGqDAmEWAOuNEgnBlAXEX+wsGYdUdQuv4Ypa9nP8O8EWFu0N1hSNtRSfcp2 RkR8LSIQI889yP4FKyHWOrNrXeLgeHlKcR9MlI0BTbvIXHEKt4WNdAvmg6kZTGBPiOgY iROrCXCG+dcwOF8b0fRpWYJRBUJCI3ynx8gccV+wzioIhqbJyCs1qVcWLJmQ3bd3OtN2 LiZw== 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 :content-transfer-encoding; bh=qIliTL0cIqgA1UGFsyOf/KbZIejwSEtSADCmlmijcKw=; b=sSILdvw3TrZuYaaHdEtaYeJ1b/C49eXojxRxpX813dz6BADADKrDptRKuCTMYpdN6G zdUW828NXGmH5S2MR5pnYPBmWO2IDRVmexyvk8kwgXv4ARSkDRMfDiMI8mwS1Fd3a0qA HuFdGmwpxcLBnGHNf8v7B/BeAvK8FmU10sWDZ3asvgy/OO252JutDlg7LgG0gjuBnydt l/BqumcfzhCJP98+sv7NOHhHOP7UNL5VPyGBG+sC/U/VO4E7bc2kW5QSARafj998dCd5 yyQ3AtglszYywrvQeg0kcfYzGPZnH7idH6fBELCDR9doPfn2/rEHtykln9+5m9CQUXlG /pbQ== X-Gm-Message-State: AOAM531CtTbPvEvip9twND0HjXDwuWnMMVrtkYe2yV8nwM0QGPuzPMyc LzEoGuYLnZFzhBOV5tz/65Zq+DyxefU= X-Google-Smtp-Source: ABdhPJwlCmVdoBtzbZjF5CW8g+1ZWgsU+zoeqz+iKbNg9VFO43/oGuc2DrrBG3aVfv4uOloqdmJpXQ== X-Received: by 2002:a05:6512:ba6:: with SMTP id b38mr8228808lfv.355.1633912849007; Sun, 10 Oct 2021 17:40:49 -0700 (PDT) Original-Received: from [192.168.0.103] ([5.18.248.29]) by smtp.googlemail.com with ESMTPSA id q187sm661974ljb.6.2021.10.10.17.40.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Oct 2021 17:40:48 -0700 (PDT) In-Reply-To: <87v925f6ee.fsf@mail.linkov.net> 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:216845 Archived-At: On 10.10.2021 19:47, Juri Linkov wrote: >>> Then maybe the backend could be named 'project-file' >>> since a special file defines the project root. >> >> That's a little more meaningful, though too close to >> 'project-files'. 'project-markered' or 'project-markerfile' would probably >> be less ambiguous. > > In 'project-filemarker' I misread "filemarker" as "filmmaker" :-) Right. :-) > Another possible name would be "fileroot". Also sounds more like a method than a project type name. Maybe project-markered or project-marked, or project-dominated (along the lines of 'locate-dominating-file'?). Or something noncommittal like project-dirtee. But all of those sounds like one could put them at any position in project-find-functions, which project-fallback explicitly discourages. >> Suppose somebody puts it before 'vc' to use if for a purpose we did not >> design it for: make sure that some subproject 'foo' in their monorepo is >> considered a separate project. 'foo/Makefile' exists, so they add >> "Makefile" to project-fallback-markers, and it kind of seems to work. > > There are two contradictory needs: > > 1. When a marker list contains both ".dir-locals.el" and "Makefile", > it should ignore Makefile files in vc-based project subdirs, e.g. > emacs/lisp/Makefile, etc. Right. That says project-try-fallback going after project-try-vc is a good thing. > 2. OTOH, I often type 'C-x p g' to search all gems of the same > ruby version in e.g. ~/.rbenv/versions/2.7.4/lib/ruby/gems > But it finds ~/.rbenv/.git and tries to search all ruby versions. > I could manually add .dir-locals.el only to a particular version's > subdir. I'm using this setup, FWIW: (defun project-try-gem (dir) (when (string-match "/\\.rbenv/versions/.*/gems/.*/gems/[^/]+/" dir) (cons 'rubygem (substring dir 0 (match-end 0))))) (cl-defmethod project-root ((project (head rubygem))) (cdr project)) (with-eval-after-load 'project (add-hook 'project-find-functions #'project-try-gem)) Which avoids the whole directory-walking routine, probably saving on a number of CPU cycles. > But how to override ~/.rbenv/.git? Maybe by changing > the order of backends in project-find-functions? > Then the fallback won't be the last backend anymore. > Also the backend priorities will be changed globally > for all other projects, and 'C-x p g' in emacs/lisp > will find emacs/lisp/Makefile to override emacs/.git. If we keep the same tool to ensure the priorities (order of functions in project-try-vc), that would seem like we should use two different backends for these two different purposes. Say, the first one would be called project-dominating, and the other one - still project-fallback. project-find-functions will be '(project-try-dominating project-try-vc project-try-fallback Alternatively, one backend could combine these, but it would have, like, configurable logic with two different sets of predicates -- one universal (whether the file is inside a VCS repo or not), and another for when the file is strictly outside of VCS repos. But that sounds trickier, both to configure and to understand. Also, it seems like with this approach the backend *should* ignore the .gitignore entires, which is fine for .rbenv/versions/.*/gems, but it's bound not to work for some other purposes some users are going to try to use it for. So, since I don't know of any other use cases for the project-dominating code path rather than Ruby gems inside ~/.rbenv, I figured not to try to solve this use case yet. But we can catalogue similar use cases (maybe other versions switchers, for Ruby and other languages?; not sure if installed libraries for other languages also fit this approach) and add another backend for them later. Help welcome, of course.