GNU bug report logs -
#66663
30.0.50; Allow dir locals file selection in *-dir-local-variable functions
Previous Next
Reported by: Mauro Aranda <maurooaranda <at> gmail.com>
Date: Sat, 21 Oct 2023 12:10:02 UTC
Severity: wishlist
Tags: patch
Fixed in version 30.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 66663 in the body.
You can then email your comments to 66663 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sat, 21 Oct 2023 12:10:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mauro Aranda <maurooaranda <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 21 Oct 2023 12:10:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Severity: wishlist
This is a feature request, which is a part of trying to land an Easy
Customization interface to editing dir locals files:
https://lists.gnu.org/archive/html/emacs-devel/2023-09/msg01306.html
The need is to be able to specify the file to modify, so that the
.dir-locals.el or .dir-locals-2.el can be customized. Currently, the
situation is:
emacs -Q
Go to a directory without a .dir-locals.el file
Use add-directory-local-variable to add a variable. It goes to
.dir-locals.el, which is fine. But it would be nice if I could select
to add it to .dir-locals-2.el instead.
Similarly, if both .dir-locals.el and .dir-locals-2.el exist, only the
.dir-locals-2.el can be modified with *-dir-local-variables, according
to my testing. It'd be nice to be able to modify either.
The patch I'll send once I get assigned a Bug# is my first approach to
it. I made the commands take an optional argument, which indicates: "I
want to modify that other file". The intention is:
With no prefix arg:
- If no dir locals file exists, modify .dir-locals.el
- If one of them exists, modify that one.
- If the two exists, modify .dir-locals-2.el
This is just how today everything works, AFAICT.
With a prefix arg:
- If no dir locals file exists, modify .dir-locals-2.el
- If one of them exists, modify the other one.
- If the two exists, modify .dir-locals.el
Additionally, I made modify-dir-local-variable take a 5th argument,
optional, which can be a boolean or a string (a filename). The string
use case is to be able to directly specify the file to modify, which is
useful so one doesn't have to check which file exists and which doesn't
(it'll prove useful in the customize code). I'm not posting the code
for cus-edit.el because some part of the code depends if this proposed
change gets accepted.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sat, 21 Oct 2023 12:18:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 66663 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
tags 66663 patch
quit
Here's the patch. Juri, could you take a look to see if this approach
is fine? Thank you.
[0001-Allow-specifying-the-dir-locals-file-to-edit-Bug-666.patch (text/x-patch, attachment)]
Added tag(s) patch.
Request was from
Mauro Aranda <maurooaranda <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sat, 21 Oct 2023 12:18:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sat, 21 Oct 2023 12:47:01 GMT)
Full text and
rfc822 format available.
Message #13 received at 66663 <at> debbugs.gnu.org (full text, mbox):
> Cc: Juri Linkov <juri <at> linkov.net>
> Date: Sat, 21 Oct 2023 09:16:28 -0300
> From: Mauro Aranda <maurooaranda <at> gmail.com>
>
> +Since both @file{.dir-locals.el} and @file{.dir-locals-2.el} file
> +might exist in the same directory, there may be some clash about which
> +file you want to modify when executing the above three commands. To
> +solve that, all three of them take a prefix argument, to indicate
> +which file you want to modify. When both files exist, a prefix
> +argument means to prefer to modify @file{.dir-locals.el} instead of
> +@file{.dir-locals-2.el}. When one of the files doesn't exist, and
> +you're adding a variable or copying the file-local variables, a prefix
> +argument means to modify (i.e., create) the file that doesn't yet
> +exist.
I think a better UI is to ask the user when the command is invoked
with a prefix argument.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sat, 21 Oct 2023 13:51:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 66663 <at> debbugs.gnu.org (full text, mbox):
On 21/10/23 09:45, Eli Zaretskii wrote:
>> Cc: Juri Linkov <juri <at> linkov.net>
>> Date: Sat, 21 Oct 2023 09:16:28 -0300
>> From: Mauro Aranda <maurooaranda <at> gmail.com>
>>
>> +Since both @file{.dir-locals.el} and @file{.dir-locals-2.el} file
>> +might exist in the same directory, there may be some clash about which
>> +file you want to modify when executing the above three commands. To
>> +solve that, all three of them take a prefix argument, to indicate
>> +which file you want to modify. When both files exist, a prefix
>> +argument means to prefer to modify @file{.dir-locals.el} instead of
>> +@file{.dir-locals-2.el}. When one of the files doesn't exist, and
>> +you're adding a variable or copying the file-local variables, a prefix
>> +argument means to modify (i.e., create) the file that doesn't yet
>> +exist.
>
> I think a better UI is to ask the user when the command is invoked
> with a prefix argument.
Yes, that makes sense. I'll try that approach.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sat, 21 Oct 2023 14:08:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 66663 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 21/10/23 10:49, Mauro Aranda wrote:
> On 21/10/23 09:45, Eli Zaretskii wrote:
> >> Cc: Juri Linkov <juri <at> linkov.net>
> >> Date: Sat, 21 Oct 2023 09:16:28 -0300
> >> From: Mauro Aranda <maurooaranda <at> gmail.com>
> >>
> >> +Since both @file{.dir-locals.el} and @file{.dir-locals-2.el} file
> >> +might exist in the same directory, there may be some clash about
which
> >> +file you want to modify when executing the above three commands. To
> >> +solve that, all three of them take a prefix argument, to indicate
> >> +which file you want to modify. When both files exist, a prefix
> >> +argument means to prefer to modify @file{.dir-locals.el} instead of
> >> +@file{.dir-locals-2.el}. When one of the files doesn't exist, and
> >> +you're adding a variable or copying the file-local variables, a
prefix
> >> +argument means to modify (i.e., create) the file that doesn't yet
> >> +exist.
> >
> > I think a better UI is to ask the user when the command is invoked
> > with a prefix argument.
>
> Yes, that makes sense. I'll try that approach.
I reworked the patch to implement that UI instead. Patch attached.
[0001-Allow-specifying-the-dir-locals-file-to-edit-Bug-666.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sat, 21 Oct 2023 18:25:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 66663 <at> debbugs.gnu.org (full text, mbox):
> I reworked the patch to implement that UI instead. Patch attached.
Thanks, some comments:
> +(defun read-dir-locals-file ()
> + "Read a dir-locals filename using completion.
> +Intended to be used in the `interactive' spec of `add-dir-local-variable',
> +`delete-dir-local-variable' and `copy-file-locals-to-dir-locals'.
> +
> +Returns the filename, expanded."
> + (expand-file-name
> + (read-file-name "File" nil nil
The prompt needs a colon.
> + (lambda (fname)
> + (member (file-name-nondirectory fname)
> + (list dir-locals-file
> + (replace-regexp-in-string
> + ".el$" "-2.el" dir-locals-file))))
> + dir-locals-file)))
This needs to be run in the project's root directory
where the dir-locals file is saved. Probably it's not easy
to find the root without using project.el. But when one of the
files already exists (either .dir-locals.el or .dir-locals-2.el),
then better to use the directory of the existing file by default.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sat, 21 Oct 2023 22:11:02 GMT)
Full text and
rfc822 format available.
Message #25 received at 66663 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 21/10/23 15:21, Juri Linkov wrote:
>> +(defun read-dir-locals-file ()
>> + "Read a dir-locals filename using completion.
>> +Intended to be used in the `interactive' spec of
`add-dir-local-variable',
>> +`delete-dir-local-variable' and `copy-file-locals-to-dir-locals'.
>> +
>> +Returns the filename, expanded."
>> + (expand-file-name
>> + (read-file-name "File" nil nil
>
> The prompt needs a colon.
Fixed.
>> + (lambda (fname)
>> + (member (file-name-nondirectory fname)
>> + (list dir-locals-file
>> + (replace-regexp-in-string
>> + ".el$" "-2.el" dir-locals-file))))
>> + dir-locals-file)))
>
> This needs to be run in the project's root directory
> where the dir-locals file is saved. Probably it's not easy
> to find the root without using project.el. But when one of the
> files already exists (either .dir-locals.el or .dir-locals-2.el),
> then better to use the directory of the existing file by default.
In this new patch, I went for using it if already available and we
couldn't find an existing file by other means.
[0001-Allow-specifying-the-dir-locals-file-to-edit-Bug-666.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#66663
; Package
emacs
.
(Sun, 22 Oct 2023 17:57:01 GMT)
Full text and
rfc822 format available.
Message #28 received at 66663 <at> debbugs.gnu.org (full text, mbox):
close 66663 30.0.50
thanks
>> This needs to be run in the project's root directory
>> where the dir-locals file is saved. Probably it's not easy
>> to find the root without using project.el. But when one of the
>> files already exists (either .dir-locals.el or .dir-locals-2.el),
>> then better to use the directory of the existing file by default.
>
> In this new patch, I went for using it if already available and we
> couldn't find an existing file by other means.
Thanks, I've tested your patch, and it works nicely, so now pushed to master.
bug marked as fixed in version 30.0.50, send any further explanations to
66663 <at> debbugs.gnu.org and Mauro Aranda <maurooaranda <at> gmail.com>
Request was from
Juri Linkov <juri <at> linkov.net>
to
control <at> debbugs.gnu.org
.
(Sun, 22 Oct 2023 17:57:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 20 Nov 2023 12:24:10 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 209 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.