unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: emacs-devel@gnu.org, casouri@gmail.com
Subject: Difficulties and confusion associated with .dir-locals.el
Date: Tue, 07 Mar 2023 12:12:20 +0000	[thread overview]
Message-ID: <87y1o8squ3.fsf@gmail.com> (raw)

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ão



                 reply	other threads:[~2023-03-07 12:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87y1o8squ3.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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).