1.1--- a/emacs/lib/sk.el Tue Sep 24 16:47:38 2024 -0400
1.2+++ b/emacs/lib/sk.el Tue Sep 24 20:57:47 2024 -0400
1.3@@ -150,11 +150,59 @@
1.4 (add-to-list 'auto-mode-alist '("skelfile" . skel-mode))
1.5 (add-to-list 'auto-mode-alist '("\\.sk" . skel-mode)))
1.6
1.7+(defun project-skelfile-path (&optional project)
1.8+ "Find skelfile associated with PROJECT. Defaults to current
1.9+directory and returns name of skelfile. When PROJECT is T uses
1.10+`project-current'."
1.11+ (let* ((dir (unless (eql t project) (expand-file-name (or project default-directory))))
1.12+ (project-root (project-root (project-current nil dir))))
1.13+ (or
1.14+ (when dir
1.15+ (cl-find-if
1.16+ (lambda (x)
1.17+ (when (string-match
1.18+ (rx (or "skelfile" (and (* any) ".sk")))
1.19+ (file-name-nondirectory x))
1.20+ x))
1.21+ (directory-files dir t)))
1.22+ (when project
1.23+ (cl-find-if (lambda (x)
1.24+ (when (string-match (rx (or "skelfile" (and (* any) ".sk")))
1.25+ (file-name-nondirectory x))
1.26+ x))
1.27+ (directory-files project-root t))))))
1.28+
1.29+(defun read-skelfile-bind (&optional project)
1.30+ (let ((buffer (find-file-noselect (project-skelfile-path project))))
1.31+ (with-current-buffer buffer
1.32+ (goto-char (point-min))
1.33+ (goto-char (search-forward-regexp (rx bol ":bind" (* space))))
1.34+ (read buffer))))
1.35+
1.36+(defun project-skelfile-dir-locals (&optional project)
1.37+ "Return a list of dir-local bindings from a skelfile."
1.38+ (let ((form (read-skelfile-bind project)))
1.39+ (cl-loop for f in form
1.40+ do (cond
1.41+ ((eql (car f) :dir-locals) (cl-return (cdr f)))
1.42+ ;; when used as second element, the first is the name
1.43+ ;; of the CL-local binding, here we discard it and
1.44+ ;; just take the CDDR.
1.45+ ((eql (cadr f) :dir-locals) (cl-return (cddr f)))))))
1.46+
1.47 (defun skel-dir-local--get-variables ()
1.48 "Compute and return the list of :DIR-LOCAL bindings found in the current
1.49 project's skelfile, if any. Typically added to
1.50 `hack-dir-local--get-variables'."
1.51- )
1.52+ (let ((root (project-root (project-current))))
1.53+ (cons (expand-file-name root) (project-skelfile-dir-locals root))))
1.54+
1.55+(defun %skel-dir-local--get-variables ()
1.56+ (let ((root (expand-file-name (project-root (project-current)))))
1.57+ (unless (assoc-string root dir-locals-class-alist)
1.58+ (push (skel-dir-local--get-variables) dir-locals-class-alist))))
1.59+
1.60+(add-hook 'skel-minor-mode-hook '%skel-dir-local--get-variables)
1.61
1.62 (provide 'skel)
1.63 (provide 'sk)