Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /foo/bar/baz/.dir-locals.el
- /foo/bar/.dir-locals.el
- /foo/.dir-locals.el
- (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) "" ()))
- (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")
- (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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement