Skip to content

Instantly share code, notes, and snippets.

@ieure
Created November 15, 2011 21:49
Show Gist options
  • Save ieure/1368482 to your computer and use it in GitHub Desktop.
Save ieure/1368482 to your computer and use it in GitHub Desktop.
(defmacro absolute-dirname (path)
"Return the directory name portion of a path.
If PATH is local, return it unaltered.
If PATH is remote, return the remote diretory portion of the path."
`(cond ((tramp-tramp-file-p ,path)
(elt (tramp-dissect-file-name ,path) 3))
(t ,path)))
(defmacro dir-locals (dir vars)
"Set local variables for a directory.
DIR is the base diretory to set variables on.
VARS is an alist of variables to set on files opened under DIR,
in the same format as `dir-locals-set-class-variables' expects."
(let ((dir (eval dir)))
`(let ((dir (if (tramp-tramp-file-p ,dir) ,dir (file-truename ,dir))))
(let ((name (intern (concat "dir-locals-"
,(md5 (expand-file-name dir)))))
(base-dir ,dir)
(base-abs-dir ,(absolute-dirname dir)))
(dir-locals-set-class-variables name ,vars)
(dir-locals-set-directory-class ,dir name nil)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment