diff options
Diffstat (limited to 'prog')
-rw-r--r-- | prog/jao-cabal.el | 22 | ||||
-rw-r--r-- | prog/jao-dominating-file.el | 34 | ||||
-rw-r--r-- | prog/jao-java-ant.el | 20 |
3 files changed, 76 insertions, 0 deletions
diff --git a/prog/jao-cabal.el b/prog/jao-cabal.el new file mode 100644 index 0000000..699fa1b --- /dev/null +++ b/prog/jao-cabal.el @@ -0,0 +1,22 @@ +(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 build")))) + +(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-dominating-file.el b/prog/jao-dominating-file.el new file mode 100644 index 0000000..f845abc --- /dev/null +++ b/prog/jao-dominating-file.el @@ -0,0 +1,34 @@ +(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 new file mode 100644 index 0000000..27c6420 --- /dev/null +++ b/prog/jao-java-ant.el @@ -0,0 +1,20 @@ +(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 |