From 2a227faa3ec7a0677e5fa2c5ca89189ea4f517be Mon Sep 17 00:00:00 2001 From: technomancy Date: Mon, 22 Oct 2007 04:56:46 +0000 Subject: [PATCH] emacs frontend working roundtrip with only minor unreproducable bugs git-svn-id: svn+ssh://rubyforge.org/var/svn/augment@27 433cabc8-d307-4f6b-84b0-56fd43cf9f23 --- lib/backends/test_unit_backend.rb | 12 ++++++-- lib/frontends/augment.el | 58 +++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/lib/backends/test_unit_backend.rb b/lib/backends/test_unit_backend.rb index 77db29e..e18c53e 100644 --- a/lib/backends/test_unit_backend.rb +++ b/lib/backends/test_unit_backend.rb @@ -17,9 +17,10 @@ class TestUnitBackend < Backend def run(file) @file = file @layers = {} - + load(find_test_for(file)) - Test::Unit.autotest # this will call record_failure as needed + # this will call record_failure as needed + with_no_output { Test::Unit.autotest } write_layers end @@ -32,6 +33,13 @@ class TestUnitBackend < Backend # TODO: return test for implementation if possible file end + + def with_no_output + old_stdout = $stdout.clone + $stdout.reopen(File.new('/dev/null','w')) + yield + $stdout.reopen(old_stdout) + end end end diff --git a/lib/frontends/augment.el b/lib/frontends/augment.el index 8bb8e85..c0d6851 100644 --- a/lib/frontends/augment.el +++ b/lib/frontends/augment.el @@ -56,7 +56,7 @@ (defvar augment-incomplete-buffer "" "A buffer where we wait for a complete set of layers from the augment process.") -(defconst augment-filter-file-regex "End layers for [^\n]+\n" +(defconst augment-filter-file-regex "End layers for \\([^\n]+\\)\n" "The delimiter to let us know know when a file is done being output.") (defstruct layer begin end color message) @@ -109,40 +109,47 @@ :keymap (setq augment-mode-map (make-sparse-keymap)) + (define-key augment-mode-map (kbd "C-c C-s") 'augment-initiate) + (define-key augment-mode-map (kbd "C-c C-k") 'augment-clear) + (make-local-variable 'layers) (make-local-variable 'after-save-hook) (add-hook 'after-save-hook 'augment-initiate) (add-to-list 'augmented-buffers (buffer-file-name)) - (augment-start-process) (augment-initiate (buffer-file-name))) (defun augment-initiate (&optional file) - (process-send-string "augment" (or file (buffer-file-name)))) + (interactive) + (setq layers nil) + (augment-start-process) + (process-send-string "augment" (concat (or file (buffer-file-name)) "\n"))) (defun augment-start-process () (unless (get-process "augment") ;; only one should be running at a time - (set-process-filter (start-process "augment" nil ;; FIXME: don't hardcode path + (set-process-filter + (start-process "augment" "*augment-out*" ;; FIXME: don't hardcode path "/home/phil/projects/augment/bin/augment" "background") - 'augment-filter-buffer))) + 'augment-filter))) -;; TODO: test me (defun augment-filter (process output) - (if (string-match augment-filter-file-regex output) - (progn - ;; Send everything up to the first newline to the real filter - (augment-filter-buffer process (concat augment-incomplete-buffer (car (split-string output augment-filter-file-regex)))) - ;; Recurse on the rest - (augment-filter process (substring output (+ 1 (string-match augment-filter-file-regex output))))) - ;; Save the remainder to a buffer - (if (string-match "^Error augmenting \\(.*\\)" output) - (progn (message "Error augmenting %s." (match-string 1 output)) - (setq augment-incomplete-buffer "")) - (setq augment-incomplete-buffer (concat augment-incomplete-buffer output))))) - -(defun augment-filter-buffer (process output buffer) - (with-current-buffer buffer + (if (not (string-match augment-filter-file-regex output)) + ;; Haven't yet received all the file's layersn + (if (string-match "^Error augmenting \\(.*\\)" output) + (progn (setq augment-incomplete-buffer "") + (error "Error augmenting %s." (match-string 1 output))) + ;; Push it on to the incomplete buffer + (setq augment-incomplete-buffer (concat augment-incomplete-buffer output))) + ;; Send it to the real filter + (setq augment-incomplete-buffer "") + (augment-filter-buffer process + (concat augment-incomplete-buffer output) + (file-name-nondirectory (match-string 1 output))))) + +(defun augment-filter-buffer (process output &optional buffer) + (with-current-buffer (substring buffer 0 -1) + (setq out output) (setq layers (augment-layers-from-string (augment-strip-foot output))) (augment-buffer layers))) @@ -150,9 +157,18 @@ (apply #'concat (subseq (split-string output "\n") 0 -2))) (defun augment-buffer (layers) - (remove-overlays) + (augment-clear) (dolist (layer layers) (augment-render-layer layer))) +(defun augment-clear () + (interactive) + (remove-overlays)) + +(defun augment-reset () + (interactive) + (kill-process "augment") + (augment-clear)) + (provide 'augment) ;;; augment.el ends here \ No newline at end of file -- 2.11.4.GIT