(defun pony-rc ()
"Get The settings for the current project.
Read the current pony-project variable from the current buffer's .dir-locals.el"
(let ((settings
(if (memq 'pony-settings
(mapcar 'first dir-local-variables-alist))
(cdr (find-if (lambda (x) (equal (first x) 'pony-settings))
dir-local-variables-alist))
;; For backwards compatibility we also allow ourselves to use .ponyrc
(eval (pony-read-file (concat (pony-project-root) ".ponyrc"))))))
(eval settings)))
Four questions:
Why use equal when comparing against a symbol?
Why not use the built-in function assq for looking up a key in an association list?
In the .ponyrc case it looks the contents of the file get evaluated twice. Is this right?
The docstring refers to the pony-project variable but what actually gets looked up is the pony-settings variable. Which is right?
If the double evaluation is wrong, the function could be rewritten like this:
(defun pony-rc ()
"Get the settings for the current project.
Evaluate the pony-settings variable from the directory-local variables,
or if it does not exist, load .ponyrc instead."
(eval (cdr (or (assq 'pony-settings dir-local-variables-alist)
(cons nil (pony-read-file (concat (pony-project-root) ".ponyrc")))))))
The function
pony-rc
reads as follows:Four questions:
equal
when comparing against a symbol?assq
for looking up a key in an association list?.ponyrc
case it looks the contents of the file get evaluated twice. Is this right?pony-project
variable but what actually gets looked up is thepony-settings
variable. Which is right?If the double evaluation is wrong, the function could be rewritten like this: