Aquí hay una forma diferente de hacer esto.
Defino una función que produce la lista de todos los directorios en la jerarquía de directorios actual.
(defun file-name-directory-nesting-helper (name previous-name accumulator)
(if (string= name previous-name)
accumulator ; stop when names stop changing (at the top)
(file-name-directory-nesting-helper
(directory-file-name (file-name-directory name))
name
(cons name accumulator))))
(defun file-name-directory-nesting (name)
(file-name-directory-nesting-helper (expand-file-name name) "" ()))
Un ejemplo está en orden:
(file-name-directory-nesting "/foo/bar/baz/quux/foo.el")
;; => ("/" "/foo" "/foo/bar" "/foo/bar/baz" "/foo/bar/baz/quux" "/foo/bar/baz/quux/foo.el")
Ahora puedo agregar consejos para hack-dir-local-variables
"simular" que estamos visitando un archivo en la parte superior del árbol, aplicar configuraciones locales de directorio, luego bajar un nivel, aplicar configuraciones nuevamente, y así sucesivamente.
(defun hack-dir-local-variables-chained-advice (orig)
"Apply dir-local settings from the whole directory hierarchy,
from the top down."
(let ((original-buffer-file-name (buffer-file-name))
(nesting (file-name-directory-nesting (or (buffer-file-name)
default-directory))))
(unwind-protect
(dolist (name nesting)
;; make it look like we're in a directory higher up in the
;; hierarchy; note that the file we're "visiting" does not
;; have to exist
(setq buffer-file-name (expand-file-name "ignored" name))
(funcall orig))
;; cleanup
(setq buffer-file-name original-buffer-file-name))))
(advice-add 'hack-dir-local-variables :around
#'hack-dir-local-variables-chained-advice)
.dir-locals
? .