From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Difficulties and confusion associated with .dir-locals.el Date: Tue, 07 Mar 2023 12:12:20 +0000 Message-ID: <87y1o8squ3.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21330"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org, casouri@gmail.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Mar 07 13:11:16 2023 Return-path: Envelope-to: ged-emacs-devel@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 1pZW9z-0005Mr-Fh for ged-emacs-devel@m.gmane-mx.org; Tue, 07 Mar 2023 13:11:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZW9F-0002ED-JG; Tue, 07 Mar 2023 07:10:29 -0500 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 1pZW9D-0002Dv-Sb for emacs-devel@gnu.org; Tue, 07 Mar 2023 07:10:27 -0500 Original-Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pZW9C-0006OC-2o for emacs-devel@gnu.org; Tue, 07 Mar 2023 07:10:27 -0500 Original-Received: by mail-wr1-x436.google.com with SMTP id f11so11868823wrv.8 for ; Tue, 07 Mar 2023 04:10:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678191023; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=JCEnrPDz77RBFzOsb56XCitvuTHeBwzoMyB3vm54kv8=; b=T2/YytHAxJnnjXg5ACkaUEkKVnzaGKDsMNVDjlI9Ov/OeDdS3DFASYW1Rv9NwJF5WL fxr6aHilO59zZSV4KPKKEqFEKmMHlA2ynT69HKuvmRrMbia+6b98bxXVE9dO0JlMM8QA JO3KUoHMAIGiBWNe729b6kDhOp1W8mt8vDi7pv0oaGI9pcd7+e1oCEVEDKmUnPQMdbOG d62WvhFvvltFnpF3DPY0KI9NmH7I9EBlUgGOLpLCvApFnJXtWbU+WOtVtQ/9NDmH2gSC 6W1ixxkXGX8N7dJMLZvHCT2TtbOkE9V3hSLvA2UN/GZF2Cgqmdwfv0x61yXKOlwuBzqK cBag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678191023; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JCEnrPDz77RBFzOsb56XCitvuTHeBwzoMyB3vm54kv8=; b=Sy1w1sCz0XTR/qk/szskq6t4dZqUU0P4yaYYK0J6GjwH64x+/sEWBNZYc9nqncFyRs hurGfJoUDi1lo4cb1xfQO3wKQvc6DO254BUQGJOq4WJXq2x8xRQrsEfAx9C2LFZWcoXy tBLyt2+cOYHMuHWe2be9rbZ43yIwxdHFBhfVLD+xZCKLg9V8Q3FodS5P/YnJjyCoq0Nx uuJS9Sl6indhKM2PLbChm0kvC7VwHWiIHjWEXIwfl/tNxfsMCdVxS7/pIfThm0GaspaU qcs+oRgVaDvRzzlWzvAmU7wUh+IOpJkjs+oz4HhVNZU/2mH4IaqMCNtHgIW6+NwgQwDx Sjpg== X-Gm-Message-State: AO0yUKVZpwkeJl95zuYRtHaMFQU5A28EZkU7O/ZUyrQHQKGCdyuNQMOZ RTbC6Wg+lrNwqVwmUJ0rsZq4K4fdPXU= X-Google-Smtp-Source: AK7set8i5D2SGaqWxm+m0kzEqmciOlm4/Blb3MRI0AZyspTui2F44SARI94QBDCoxns+DqFFPVL1yg== X-Received: by 2002:a5d:6210:0:b0:2c8:f78:2772 with SMTP id y16-20020a5d6210000000b002c80f782772mr9520997wru.19.1678191023097; Tue, 07 Mar 2023 04:10:23 -0800 (PST) Original-Received: from krug ([87.196.72.142]) by smtp.gmail.com with ESMTPSA id p13-20020a056000018d00b002c5691f13eesm12237713wrx.50.2023.03.07.04.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 04:10:22 -0800 (PST) Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=joaotavora@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:304077 Archived-At: Yuan Fu writes: >> Reading the docs, rust-analyzer allows per-user configuration via >> :initializationOptions. The syntax and supported options are >> usually the same but the difficulties and confusion associated >> with ~/.dir-locals.el are not there. Yes, ~/.dir-locals.el is confusing to many. A minor point of confusion is the ".el" extension: it's _not_ an Emacs Lisp program. A bigger one in the "dir locals" name: accurate but somewhat removed from its main use which is "project preferences". An even bigger are its syntax, the various ways to add to it, the scope of the variables. As a first idea, I think a menu command "Edit project preferences" somewhere in the menu could alleviate the situation, bringing the user into a new or existing ~/.dir-locals.el file in the current project's root, maybe with a nice template. Maybe the project.el people can make this happen. Then there's this simple enhancement of the current M-x add-dir-local-variable could be a slight improvement, also geared towards guiding the user to the file that she probably wants to change. --- a/lisp/files-x.el +++ b/lisp/files-x.el @@ -439,7 +439,9 @@ modify-dir-local-variable (car (last (dir-locals--all-files (car dir-or-cache= )))) (cadr dir-or-cache))) ;; Try to make a proper file-name. - (t (expand-file-name dir-locals-file)))) + (t (expand-file-name dir-locals-file + (let ((p (project-current))) + (and p (project-root p))))))) variables) ;; I can't be bothered to handle this case right now. ;; Dir locals were set directly from a class. You need to But 'add-dir-local-variable' and 'add-file-local-variable' remain very daunting ways to do edits to a .dir-locals.el file. They ask you three questions in that cramped minibuffer (mode, variable and value), and there's no way to go back if you make a mistake. There's doesn't seem to be good way to say "all major modes" (the nil value). It's also not clear that the value is going to be read, not evaluated. And there's no way to tell it to evaluate a value. When you're done, there is no good way to understand what has happened (is the file saved? Are my variables applied?) People have expressed desire for a better dir/file-local setting mechanism for a single specific directory-local variable (one from Eglot), but I think we should look at the problem generally. Here are a some more ideas. 1. Enhance a-d-l-v and a-f-l-v with an option to pop to the ~/.dir-locals.el directly to edit the value of the given variable, with point in place. 2. Make a new major mode for ~/.dir-locals. For example, C-c C-c would save the file and offer to revert the affected buffers. 3. A Flymake backend for that major mode which informs which variables have safe or risky values. This backend could also check the top level schema (the form must be an alist). 4. In the a-d-l-v minifuffer, possiblity to use evaluation instead of reading via some simple syntax, like starting the expression with a ',' (comma). Jo=C3=A3o