Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /foo/bar/baz/.dir-locals.el
  2. /foo/bar/.dir-locals.el
  3. /foo/.dir-locals.el
  4.  
  5. (defun file-name-directory-nesting-helper (name previous-name accumulator)
  6. (if (string= name previous-name)
  7. accumulator ; stop when names stop changing (at the top)
  8. (file-name-directory-nesting-helper
  9. (directory-file-name (file-name-directory name))
  10. name
  11. (cons name accumulator))))
  12.  
  13. (defun file-name-directory-nesting (name)
  14. (file-name-directory-nesting-helper (expand-file-name name) "" ()))
  15.  
  16. (file-name-directory-nesting "/foo/bar/baz/quux/foo.el")
  17. ;; => ("/" "/foo" "/foo/bar" "/foo/bar/baz" "/foo/bar/baz/quux" "/foo/bar/baz/quux/foo.el")
  18.  
  19. (defun hack-dir-local-variables-chained-advice (orig)
  20. "Apply dir-local settings from the whole directory hierarchy,
  21. from the top down."
  22. (let ((original-buffer-file-name (buffer-file-name))
  23. (nesting (file-name-directory-nesting (or (buffer-file-name)
  24. default-directory))))
  25. (unwind-protect
  26. (dolist (name nesting)
  27. ;; make it look like we're in a directory higher up in the
  28. ;; hierarchy; note that the file we're "visiting" does not
  29. ;; have to exist
  30. (setq buffer-file-name (expand-file-name "ignored" name))
  31. (funcall orig))
  32. ;; cleanup
  33. (setq buffer-file-name original-buffer-file-name))))
  34.  
  35. (advice-add 'hack-dir-local-variables :around
  36. #'hack-dir-local-variables-chained-advice)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement