diff options
author | jao <jao@gnu.org> | 2020-12-29 21:56:49 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2020-12-29 21:56:49 +0000 |
commit | 42c26033db101beb2ccac5342c1cf56f266cadc5 (patch) | |
tree | 23e461319b8fe82b123c4ab1834fe8129c5f06b9 | |
parent | 38f38cfa01fbb2d755e933b7a5c8e350055c3607 (diff) | |
download | elibs-42c26033db101beb2ccac5342c1cf56f266cadc5.tar.gz elibs-42c26033db101beb2ccac5342c1cf56f266cadc5.tar.bz2 |
jao-compilation (and old stuff removed)
-rw-r--r-- | prog/jao-cabal.el | 22 | ||||
-rw-r--r-- | prog/jao-compilation.el | 115 | ||||
-rw-r--r-- | prog/jao-dominating-file.el | 34 | ||||
-rw-r--r-- | prog/jao-java-ant.el | 20 | ||||
-rw-r--r-- | readme.org | 2 |
5 files changed, 116 insertions, 77 deletions
diff --git a/prog/jao-cabal.el b/prog/jao-cabal.el deleted file mode 100644 index 5f5fd99..0000000 --- a/prog/jao-cabal.el +++ /dev/null @@ -1,22 +0,0 @@ -(require 'jao-dominating-file) - -(defun jao-haskell-locate-cabal-file () - (jao-locate-dominating-file ".+\\.cabal")) - -(eval-after-load 'haskell-mode - '(add-hook 'haskell-mode-hook - (lambda () - (set (make-local-variable 'compile-command) "cabal install")))) - -(defun jao-haskell-cabal-build () - (interactive) - (let ((cabal-file (jao-haskell-locate-cabal-file))) - (unless cabal-file - (error "Couldn't find associated cabal file")) - (let ((default-directory (file-name-directory cabal-file))) - (call-interactively 'compile)))) - -;;(eval-after-load 'haskell-mode -;; '(define-key haskell-mode-map [?\C-c ?c] 'jao-haskell-cabal-build)) - -(provide 'jao-cabal) diff --git a/prog/jao-compilation.el b/prog/jao-compilation.el new file mode 100644 index 0000000..7efbd63 --- /dev/null +++ b/prog/jao-compilation.el @@ -0,0 +1,115 @@ +;;; jao-compilation.el --- utilities to lauch compilations -*- lexical-binding: t; -*- + +;; Copyright (C) 2020 jao + +;; Author: jao <mail@jao.io> +;; Keywords: convenience + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Utilities to launch compilation processes from adequate root directories + +;;; Code: + +(defvar jao-compilation-dominating-files nil) +(defvar jao-compilation-dominating-file-rxs '(".*\\.cabal")) +(defvar jao-compilation-environment ()) + +(defun jao-compilation--environment () + (let (result) + (dolist (v jao-compilation-environment result) + (let ((vv (getenv v))) + (when vv (add-to-list 'result (format "%s=%s" v vv))))))) + +;;;###autoload +(defun jao-compilation-add-dominating (&rest fs) + (dolist (f fs) (add-to-list 'jao-compilation-dominating-files f)) + (setq jao-compilation-dominating-rx + (concat "\\(" + (regexp-opt jao-compilation-dominating-files) + "\\|" + (mapconcat 'identity + jao-compilation-dominating-file-rxs + "\\|") + "\\)$"))) + +;;;###autoload +(defun jao-path-relative-to (path base) + (let* ((path (file-name-directory path)) + (base (file-name-directory base)) + (blen (length base))) + (if (<= (length path) blen) + path + (if (string-equal base (substring path 0 blen)) + (substring path blen) + path)))) + +;;;###autoload +(defun jao-compilation-find-root (file doms) + (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)) + (rel-path (jao-path-relative-to dir default-directory))) + (if (and (file-directory-p "build") + (not (file-exists-p "build.xml")) + (not (file-exists-p "setup.py"))) + (expand-file-name rel-path (expand-file-name "build/")) + default-directory)))) + +;;;###autoload +(defun jao-compilation-root-file () + (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) + (when-let ((root (jao-compilation-root dir))) + (cons 'transient root))) + (add-to-list 'project-find-functions #'jao-find-compilation-root)) + +;;;###autoload +(defun jao-compilation-env (v) + "Add new environment variables to the compilation environment + used by `jao-compile'" + (add-to-list 'jao-compilation-environment v)) + +;;;###autoload +(defun jao-compile () + "Find the root of current file's project and issue a + compilation command" + (interactive) + (let ((default-directory (jao-compilation-root)) + (compilation-environment (jao-compilation--environment)) + (compilation-read-command 'compilation-read-command)) + (call-interactively 'compile))) + +;;;###autoload +(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")) + + +(provide 'jao-compilation) +;;; jao-compilation.el ends here diff --git a/prog/jao-dominating-file.el b/prog/jao-dominating-file.el deleted file mode 100644 index f845abc..0000000 --- a/prog/jao-dominating-file.el +++ /dev/null @@ -1,34 +0,0 @@ -(defun jao-locate-dominating-files (regexp &optional file) - "Look up the directory hierarchy from FILE for a file matching REGEXP. - Stop at the first parent where a matching file is found and return the list - of files that that match in this directory." - (catch 'found - (let ((dir (file-name-as-directory (or file (buffer-file-name)))) - files) - (while (and dir - (not (string-match locate-dominating-stop-dir-regexp - dir))) - (if (setq files (condition-case nil - (directory-files dir 'full regexp 'nosort) - (error nil))) - (throw 'found files) - (if (equal dir - (setq dir (file-name-directory - (directory-file-name dir)))) - (setq dir nil)))) - nil))) - - -(defun jao-locate-dominating-file (regexp &optional from) - (car (jao-locate-dominating-files regexp from))) - -(defun jao-relative-path (regexp &optional from) - (let* ((from (or from (buffer-file-name))) - (dfile (jao-locate-dominating-file regexp from)) - (ddir (and dfile (file-name-directory dfile))) - (fdir (file-name-directory from))) - (when ddir - (and (string-match (format "%s\\(.+\\)/" (regexp-quote ddir)) fdir) - (match-string-no-properties 1 fdir))))) - -(provide 'jao-dominating-file) diff --git a/prog/jao-java-ant.el b/prog/jao-java-ant.el deleted file mode 100644 index 27c6420..0000000 --- a/prog/jao-java-ant.el +++ /dev/null @@ -1,20 +0,0 @@ -(require 'jao-dominating-file) - -(eval-after-load 'cc-mode - '(progn - (add-hook 'java-mode-hook - (lambda () - (set (make-local-variable 'compile-command) "ant"))) - (define-key java-mode-map "\C-cc" 'jao-java-ant-build))) - -(defun jao-java-ant-build () - (interactive) - (let ((build-file (jao-locate-dominating-file "build\\.xml"))) - (unless build-file - (error "Couldn't find associated build file")) - (let ((default-directory (file-name-directory build-file))) - (call-interactively 'compile)))) - -(provide 'jao-java-ant) - -;; End of jao-java-ant.el @@ -3,7 +3,7 @@ - *themes* color themes based on Emacs builtin custom themes - *org* utilities for org-mode - *media* utilities for music players and the like - - *prog* utilities for programming modes + - *prog* utilities for compilation and programming modes - *skels* skeletons for source files - *net* utilities for networking (w3m, weather &c.) - *sys* generic utilities for external programs |