Skip to content

Smarter projectile-edit-dir-locals #1135

Description

@basil-conto

Expected behaviour

More control over location of and workflow around dir-locals-files.

In this issue I wish to:

  1. Draw attention to some of the more obvious limitations of the command projectile-edit-dir-locals.
  2. 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-file name is currently hard-coded as ".dir-locals.el", which does not take dir-locals-file-2 or MS-DOS limitations into account.

  • The dir-locals-file is expanded relative to (projectile-project-root) and thus does not support nested dir-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-file by 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 between default-directory and (projectile-project-root).

  • A customisation variable could determine whether to prefer the root vs nearest dir-locals-file found, 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!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions