From 1228164acf5bd3afcda3ab0cba761adccf34c88c Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 9 Jan 2021 01:09:29 +0000 Subject: compilation: fixes to not break anything with jao-compilation-root --- prog/jao-compilation.el | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'prog') diff --git a/prog/jao-compilation.el b/prog/jao-compilation.el index 7efbd63..25a27aa 100644 --- a/prog/jao-compilation.el +++ b/prog/jao-compilation.el @@ -1,6 +1,6 @@ ;;; jao-compilation.el --- utilities to lauch compilations -*- lexical-binding: t; -*- -;; Copyright (C) 2020 jao +;; Copyright (C) 2020, 2021 jao ;; Author: jao ;; Keywords: convenience @@ -25,7 +25,7 @@ ;;; Code: (defvar jao-compilation-dominating-files nil) -(defvar jao-compilation-dominating-file-rxs '(".*\\.cabal")) +(defvar jao-compilation-dominating-file-rxs '(".+\\.cabal")) (defvar jao-compilation-environment ()) (defun jao-compilation--environment () @@ -59,17 +59,17 @@ ;;;###autoload (defun jao-compilation-find-root (file doms) - (locate-dominating-file file `(lambda (d) - (when (file-directory-p d) - (directory-files d nil ,doms))))) + (when file + (locate-dominating-file file `(lambda (d) + (when (file-directory-p d) + (directory-files d nil ,doms)))))) ;;;###autoload (defun jao-compilation-root (&optional dir) - (let* ((fn (or dir (buffer-file-name) default-directory)) - (default-directory - (expand-file-name - (jao-compilation-find-root fn jao-compilation-dominating-rx)))) - (let* ((dir (file-name-directory fn)) + (when-let ((rfn (jao-compilation-find-root (or dir (buffer-file-name)) + jao-compilation-dominating-rx))) + (let* ((default-directory (expand-file-name rfn)) + (dir (file-name-directory rfn)) (rel-path (jao-path-relative-to dir default-directory))) (if (and (file-directory-p "build") (not (file-exists-p "build.xml")) @@ -79,14 +79,14 @@ ;;;###autoload (defun jao-compilation-root-file () - (let ((dir (jao-compilation-root))) + (when-let ((dir (jao-compilation-root))) (car (directory-files dir nil jao-compilation-dominating-rx)))) -(with-eval-after-load "project" - (defun jao-find-compilation-root (dir) +;;;###autoload +(defun jao-find-compilation-root (dir) + (when (and (stringp dir) (file-exists-p dir)) (when-let ((root (jao-compilation-root dir))) - (cons 'transient root))) - (add-to-list 'project-find-functions #'jao-find-compilation-root)) + (cons 'transient root)))) ;;;###autoload (defun jao-compilation-env (v) @@ -108,7 +108,9 @@ (defun jao-compilation-setup () (jao-compilation-add-dominating "Makefile" "makefile" "configure.ac" "bootstrap.sh" "aclocal.m4" - "project.clj" "build.xml" "pom.xml" "setup.py" "stack.yaml")) + "project.clj" "build.xml" "pom.xml" "setup.py" "stack.yaml") + (with-eval-after-load "project" + (add-to-list 'project-find-functions #'jao-find-compilation-root))) (provide 'jao-compilation) -- cgit v1.2.3