arnested/drupal-mode — pull request #42 by arnested (2014-01-27 22:39:04+00:00)
Title: .dir-locals.el is difficult to use with drupal-mode

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!