;; -*- emacs-lisp -*- ;;; mst-arch.el --- functions for managing arch projects ;; Author: Mark Triggs ;; This file 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 2, or (at your option) ;; any later version. ;; This file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Nothing fancy. Just a few hacks to save me time. ;;; Code: (defun arch-diff-buffer () (interactive) (shell-command (format "tla file-diffs %s" (buffer-file-name)) "*arch diffs*" nil)) (defun arch-make-log () (interactive) (find-file (subseq (shell-command-to-string "tla make-log") 0 -1)) (let ((map (copy-keymap (current-local-map)))) (define-key map (kbd "C-c C-c") (lambda () (interactive) (save-buffer) (arch-commit) (kill-buffer nil))) (use-local-map map))) (defun arch-commit () (interactive) (shell-command "tla commit" "*arch commit*")) (defmacro with-working-directory (dir &rest body) (let ((old (gensym))) `(let ((,old default-directory)) (cd ,dir) (unwind-protect (progn ,@body) (cd ,old))))) (put 'with-working-directory 'lisp-indent-function 1) (defvar *arch-pending-setup* nil) (defun arch-import () (interactive) (let ((base (read-file-name "Project root: " (file-name-directory (buffer-file-name)))) (project (read-from-minibuffer "Project name (eg hello--dev--1.0): "))) (find-name-dired base "*") (setq mode-line-format "Select files to add with 'm'. Press C-c C-c to finish") (let ((map (copy-keymap (current-local-map)))) (define-key map (kbd "C-c C-c") `(lambda () (interactive) (with-working-directory ,base (shell-command (format "tla init-tree %s" ,project))) (let ((files (dired-get-marked-files))) (mapc (lambda (file) (shell-command (format "tla add %s" file))) files) (kill-buffer (current-buffer))) (setq *arch-pending-setup* ,base) (arch-do-import))) (use-local-map map)))) (defun arch-do-import () (interactive) (if *arch-pending-setup* (with-working-directory *arch-pending-setup* (cond ((zerop (shell-command "tla tree-lint" "*tree-lint*" "*tree-lint*")) (shell-command "tla import --setup") (setq *arch-pending-setup* nil)) (t (message (concat "Tree lint failed. Please correct and run" " M-x arch-do-import (see buffer " "*tree-lint*)"))))) (error "Nothing to do!"))) (provide 'mst-arch) ;;; mst-arch.el ends here