]> git.eshelyaron.com Git - emacs.git/commitdiff
Preserve all `eval' elements from both .dir-locals files
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 20 Oct 2020 11:07:25 +0000 (13:07 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 20 Oct 2020 11:07:25 +0000 (13:07 +0200)
* lisp/files.el (dir-locals-read-from-dir): Preserve all `eval'
elements from both .dir-locals files (bug#44066).

lisp/emacs-lisp/seq.el
lisp/files.el

index 9073f9c7a51a266e87b8b73a67861a2a3aace353..4656277ea16f2c70586834a7ee480cda3d6d5b68 100644 (file)
@@ -474,6 +474,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil."
               (seq-reverse sequence1)
               '()))
 
+;;;###autoload
 (cl-defgeneric seq-group-by (function sequence)
   "Apply FUNCTION to each element of SEQUENCE.
 Separate the elements of SEQUENCE into an alist using the results as
index c2c58dae934593efdbc2b2990daa5573dafca50d..bbc8f881590559aaf93b02e40ebf8c0a2a1f7e29 100644 (file)
@@ -4301,9 +4301,27 @@ Return the new class name, which is a symbol named DIR."
                   (if (not (and newvars variables))
                       (or newvars variables)
                     (require 'map)
-                    (map-merge-with 'list (lambda (a b) (map-merge 'list a b))
-                                    variables
-                                    newvars))))))
+                    ;; We want to make the variable setting from
+                    ;; newvars (the second .dir-locals file) take
+                    ;; presedence over the old variables, but we also
+                    ;; want to preserve all `eval' elements as is from
+                    ;; both lists.
+                    (map-merge-with
+                     'list
+                     (lambda (a b)
+                       (let ((ag
+                              (seq-group-by
+                               (lambda (e) (eq (car e) 'eval)) a))
+                             (bg
+                              (seq-group-by
+                               (lambda (e) (eq (car e) 'eval)) b)))
+                         (append (map-merge 'list
+                                            (assoc-default nil ag)
+                                            (assoc-default nil bg))
+                                 (assoc-default t ag)
+                                 (assoc-default t bg))))
+                     variables
+                     newvars))))))
       (setq success latest))
     (setq variables (dir-locals--sort-variables variables))
     (dir-locals-set-class-variables class-name variables)