Smarter projectile-edit-dir-locals
Expected behaviour
More control over location of and workflow around dir-locals-files.
In this issue I wish to:
- Draw attention to some of the more obvious limitations of the command
projectile-edit-dir-locals. - Clarify in what way and to what extent Projectile aims to support per-directory local variables.
Actual behaviour
Limitations of command projectile-edit-dir-locals:
-
The
dir-locals-filename is currently hard-coded as".dir-locals.el", which does not takedir-locals-file-2or MS-DOS limitations into account. -
The
dir-locals-fileis expanded relative to(projectile-project-root)and thus does not support nesteddir-locals-files.
Steps to reproduce the problem
$ cd
$ emacs --quick
;; Create project root
C-x C-f test-project/.projectile
C-o C-x C-s y
;; Create root `dir-locals-file'
C-x C-f .dir-locals.el
C-o C-x C-s
;; Create leaf `dir-locals-file'
C-x C-f lisp/.dir-locals.el
C-o C-x C-s y
;; Create project source file
C-x C-f foo.el
C-o C-x C-s
$ tree -a ~/test-project/
test-project/
├── .dir-locals.el
├── lisp
│ ├── .dir-locals.el
│ └── foo.el
└── .projectile
1 directory, 4 files
;; Edit `dir-locals-file' via Projectile
M-x package-initialize
M-x projectile-edit-dir-locals
;; Check current file
M-: (abbreviate-file-name (buffer-file-name)) ; => "~/test-project/.dir-locals.el"
Environment & Version information
Projectile version information
ELISP> (projectile-version)
"20170416.148"
$ cd /path/to/projectile/repo/
$ git describe --abbrev=0 --tags # latest tag
v0.14.0
Emacs version
ELISP> (emacs-version)
"GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
of 2017-03-26"
Operating system
$ uname --kernel-name --kernel-release --machine --operating-system
Linux 4.9.0-2-amd64 x86_64 GNU/Linux
$ cat /etc/debian_version
9.0
Request for Comments
The following suggestions address some of the aforementioned limitations.
- Projectile could first try to find the nearest
dir-locals-fileby default, e.g.
;; Note: this does not stop at (projectile-project-root)
(let ((locals (dir-locals-find-file default-directory)))
(when locals
(find-file (car (last (dir-locals--all-files
(or (car-safe locals) locals)))))))
-
The user could be offered a list of all
dir-locals-files found betweendefault-directoryand(projectile-project-root). -
A customisation variable could determine whether to prefer the root vs nearest
dir-locals-filefound, whether to ask the user or whether to offer possible completions. -
If no
dir-locals-files are found, the user could be prompted for a directory in which to create one.
I would appreciate feedback on the given issues and suggestions. I would also be happy to work on a patch for any ensuing decisions, if I am given some initial pointers.
Thank you for this excellent and useful package!
[
projectile-edit-dir-locals] does not take MS-DOS limitations into account
Actually, expand-file-name could be doing the necessary dosification of the filename ".dir-locals.el", but I am unable to test this. Either way, I think it may be wiser to delegate as many file operations as possible to built-in functions.
PRs welcome! :-)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
Testing whether this comment counts as activity. ;)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
Ping.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
Ping.
@basil-conto It'd be even better if you tried to implement some of your ideas. Unfortunately I'm short on time for Projectile these days and this issue is fairly low in my todo list.
Same here, and I've since switched from using Projectile to the built-in project.el. I'll try looking into this later today or over the coming weekend.