arnested / drupal-mode

Advanced Emacs minor mode for Drupal development
https://melpa.org/#/drupal-mode
GNU General Public License v3.0
32 stars 14 forks source link

.dir-locals.el is difficult to use with drupal-mode #42

Closed joddie closed 10 years ago

joddie commented 10 years ago

I experience problems trying to set directory-local variables for a Drupal project using a .dir-locals.el file when drupal-mode is enabled.

Here is a test case: create a .dir-locals.el file at the root of a Drupal project with the following contents:

((nil
  (my-test-variable . foo)))

This should set the variable my-test-variable to the symbol foo for files in any mode within the directory. (Because my-test-variable lacks a defvar declaring it a safe varaiable, Emacs will also pop up a warning whenever these variables are applied).

Starting from a new Emacs instance with drupal-mode installed, before any PHP files within the project are visited, the dir-locals are applied as expected (and cause a warning for each file opened). They are also applied the first PHP file visited within the project. However, after this, the dir-locals are not applied to any subsequent files opened within the project (whether they are in PHP or any other mode).

I suspect this problem arises because of the way that drupal-mode's drupal-detect-drupal-version uses the dir-locals-set-directory-class and dir-locals-set-class-variables functions: the "directory class" set for the directory then takes precedence over the contents of .dir-locals.el files in the filesystem. If this is the case, a possible fix might be for drupal-detect-drupal-version to merge any existing variables from dir-local-variables-alist together with its own dir-local values before calling dir-locals-set-class-variables. If you like, I can try this out and submit a patch. Otherwise, let me know if you can reproduce this or would like more information.

Thanks for drupal-mode!

joddie commented 10 years ago

My mistake, I see this is mostly a duplicate of issue #12. Feel free to close it so that any other discussion happens over there.

arnested commented 10 years ago

Hi, @joddie.

You are right this is a duplicate of #12. Trying to use dir-locals in `drupal-detect-drupal-version' was a choice I made a long time ago.

I have been wanting do a cleanup but never got around to it - until now! Thank you for beating me to it!

Please have a look at the feature/no-dir-locals branch - it doesn't use dir-locals. I'll try out the branch for a few days myself before applying it to develop and creating a new release.

I'll continue the work in #12 (and hope you don't mind I accidentally turned this issue into a pull request against the master branch).

joddie commented 10 years ago

Sorry I took so long to reply to this, but thank you for the fix! This will be really useful to me.