home *** CD-ROM | disk | FTP | other *** search
- ;;; display.el - GnuTest Display Package
- ;;; Copyright (c) 1987 Wang Institute of Graduate Studies
- ;;; Andy Bliven <bliven@wanginst>
-
- (provide 'tst-display)
- (require 'tst-annotate)
-
- ;;; ----------------------------------------------------------------------
- ;;; Public Variables--
-
- (defconst tst-display-window-width 10
- "* Width of each display window, in columns")
-
- (defconst tst-display-attributes (list 'zero 'constant)
- "* List of attributes to be displayed in batch mode.")
-
- ;;; ----------------------------------------------------------------------
- ;;; Private Variables--
-
- (defvar tst-display-buffer-alist nil
- "An alist of attribute names and buffer objects")
-
- (defvar tst-display-lisp-buffer nil
- "The buffer of emacs lisp code that has been annotated.")
-
- (defvar tst-display-lisp-window nil
- "The window containing emacs lisp code.")
-
- (defvar tst-display-mode-map nil
- "Keymap for GnuTest Display major mode.")
- (or tst-display-mode-map
- (progn
- (setq tst-display-mode-map (make-keymap))
- (suppress-keymap tst-display-mode-map) ; requires full keymap, not sparse
- ; key definitions
- (define-key tst-display-mode-map "\C-n" 'tst-display-next-line)
- (define-key tst-display-mode-map "\C-p" 'tst-display-previous-line)
- (define-key tst-display-mode-map "\C-v" 'tst-display-scroll-up)
- (define-key tst-display-mode-map "\M-v" 'tst-display-scroll-down)
- (define-key tst-display-mode-map "\C-c\C-h" 'tst-display-mode-help)
- (define-key tst-display-mode-map "\C-cc" 'tst-display-constant)
- (define-key tst-display-mode-map "\C-cl" 'tst-display-redraw)
- (define-key tst-display-mode-map "\C-cn" 'tst-display-next)
- (define-key tst-display-mode-map "\C-cp" 'tst-display-previous)
- (define-key tst-display-mode-map "\C-cq" 'tst-display-mode-exit)
- (define-key tst-display-mode-map "\C-cz" 'tst-display-zero)
- )
- )
-
- (defvar tst-display-window-alist nil
- "An alist of attribute names and window objects")
-
- (defvar tst-batch-results "tst-batch-results"
- "* a kluge")
-
- (defvar tst-display-saved-variables nil
- "The property list of this variable contains values of all variables
- saved on entry to tst-display-mode.")
-
-
-
- ;;; ----------------------------------------------------------------------
- ;;; Public Functions--
-
- (defun tst-display-batch (&optional lisp-buffer)
- " Batch mode execution of the annotation display package. Writes the
- summary reports 'zero' and 'constant' generated by the tst-analyze
- package into a 'compilation' style buffer named '*compilation*'. If
- called interactively this is available for viewing with the '^X`' key,
- otherwise it is saved to the file named in tst-batch-results. If
- LISP-BUFFER is not specified, current-buffer is used instead as the
- label on each line of the report."
- (interactive)
- ; body
- (let ((lisp-buffer (or lisp-buffer (current-buffer)))
- (save-window (selected-window)))
- (pop-to-buffer "*compilation*")
- (erase-buffer)
- (insert "# GnuTest analysis of " (buffer-name lisp-buffer) "\n"
- "# (lines which were never evaluated during tests or returned\n"
- "# the same value every time they were evaluated.)\n")
- (mapcar '(lambda (line)
- (insert (tst-display-batch-string lisp-buffer
- line
- 'zero
- 'constant)))
- (tst-ann-get-lines))
- (if (interactive-p)
- (progn
- (goto-char (point-min)) ; top of results buffer
- (switch-to-buffer "*compilation*")
- (select-window save-window) ; go back to original window
- )
- ;; else
- (write-file tst-batch-results) ; write buffer to disk
- )
- )
- )
-
- (defun tst-display-mode ()
- "* Major mode for displaying GnuTest annotation with associated
- emacs-lisp code buffer. Precondition: tst-instrument and tst-analyze
- have already been evaluated for this buffer.
- C-n tst-display-next-line
- C-p tst-display-previous-line
- C-v tst-display-scroll-up
- M-v tst-display-scroll-down
- C-c C-h tst-display-mode-help
- C-c c tst-display-constant
- C-c l tst-display-redraw
- C-c n tst-display-next
- C-c p tst-display-previous
- C-c q tst-display-mode-exit
- C-c z tst-display-zero
- "
- (interactive)
- ; body
- (if (equal major-mode 'tst-display-mode)
- (tst-display-mode-exit)
- (put 'tst-display-saved-variables 'mode-name mode-name)
- (put 'tst-display-saved-variables 'major-mode major-mode)
- (put 'tst-display-saved-variables 'local-map (current-local-map))
- (put 'tst-display-saved-variables 'buffer-read-only buffer-read-only)
- (put 'tst-display-saved-variables 'truncate-lines truncate-lines)
- (setq mode-name "Test Display")
- (setq major-mode 'tst-display-mode)
- (use-local-map tst-display-mode-map) ; setup keymap
- (set-buffer-modified-p (buffer-modified-p)) ; Idiom to reset modeline.
- (setq truncate-lines t)
- (setq buffer-read-only t)
- (setq tst-display-lisp-buffer (current-buffer))
- (setq tst-display-lisp-window (selected-window))
- )
- )
-
- (defun tst-display-mode-help ()
- "Help screen for Test Display Mode."
- (interactive)
- (with-output-to-temp-buffer "*Help*"
- (princ (car (cdr (cdr (symbol-function 'tst-display-mode)))))
- )
- )
-
- (defun tst-display-mode-exit ()
- "exit Test Display Mode"
- (interactive)
- ; close annotation windows
- (let ((buflist (mapcar 'cdr tst-display-buffer-alist)))
- (mapcar '(lambda (buf)
- (and (get-buffer-window buf)
- (delete-window (get-buffer-window buf))))
- buflist)
- ) ; let
- ; clean up global variables
- (setq tst-display-buffer-alist nil)
- ; restore old state
- (setq mode-name (get 'tst-display-saved-variables 'mode-name))
- (setq major-mode (get 'tst-display-saved-variables 'major-mode))
- (use-local-map (get 'tst-display-saved-variables 'local-map))
- (set-buffer-modified-p (buffer-modified-p)) ; Idiom to reset modeline.
- (setq truncate-lines (get 'tst-display-saved-variables 'truncate-lines))
- (setq buffer-read-only (get 'tst-display-saved-variables 'buffer-read-only))
- )
-
- (defun tst-display-constant ()
- "Display values which never changed during test runs."
- (interactive)
- ;body
- (tst-display-open-buffer 'constant)
- (tst-display-open-window 'constant)
- )
-
- (defun tst-display-zero ()
- "Display values which were never evaluated during test runs."
- (interactive)
- ;body
- (tst-display-open-buffer 'zero)
- (tst-display-open-window 'zero)
- )
-
- (defun tst-display-next-line (&optional lines)
- "Move point down one line in lisp buffer and any annotation buffers."
- (interactive "p")
- (let ((nlines (or lines 1))
- (savewindow (selected-window))
- (buflist (mapcar 'cdr tst-display-buffer-alist)))
- (mapcar '(lambda (buf)
- (let ((win (get-buffer-window buf)))
- (if win
- (progn (select-window win)
- (next-line nlines)))))
- (cons tst-display-lisp-buffer buflist)
- )
- (select-window savewindow)
- )
- )
-
- (defun tst-display-previous-line (&optional lines)
- "Move point up LINES lines (1 if nil) in lisp buffer and any annotation
- buffers."
- (interactive "p")
- (let ((nlines (- (or lines 1))))
- (tst-display-next-line nlines)
- )
- )
-
- (defun tst-display-scroll-down (&optional lines)
- "Scroll down LINES lines in lisp buffer and any annotation buffers."
- (interactive "P")
- (let ((nlines (and lines (prefix-numeric-value lines)))
- (savewindow (selected-window))
- (buflist (mapcar 'cdr tst-display-buffer-alist)))
- (mapcar '(lambda (buf)
- (let ((win (get-buffer-window buf)))
- (if win
- (progn (select-window win)
- (scroll-down nlines)))))
- (cons tst-display-lisp-buffer buflist)
- )
- (select-window savewindow)
- )
- )
-
- (defun tst-display-scroll-up (&optional lines)
- "Scroll up LINES lines in lisp buffer and any annotation buffers."
- (interactive "P")
- (let ((nlines (and lines (- (prefix-numeric-value lines))))
- (savewindow (selected-window))
- (buflist (mapcar 'cdr tst-display-buffer-alist)))
- (mapcar '(lambda (buf)
- (let ((win (get-buffer-window buf)))
- (if win
- (progn (select-window win)
- (scroll-up nlines)))))
- (cons tst-display-lisp-buffer buflist)
- )
- (select-window savewindow)
- )
- )
-
- (defun tst-display-open-buffer (attribute)
- "Create a buffer named *display-ATTRIBUTE*. Fill it with values from
- the annotation database."
- (interactive "Sattribute name: ")
- (let ((newbuffer nil)
- (bufname (concat "*tst-"
- (prin1-to-string attribute)
- "*")))
- (save-excursion
- ; get buffer
- (setq newbuffer (get-buffer-create bufname))
- (setq tst-display-buffer-alist
- (tst-alist-put tst-display-buffer-alist
- attribute
- newbuffer))
- ; fill buffer
- (set-buffer newbuffer)
- (let ((buffer-read-only nil))
- (setq mode-line-format (prin1-to-string attribute))
- (erase-buffer)
- (newline (tst-display-maxline))
- (mapcar '(lambda (line)
- (goto-line line)
- (insert (tst-display-get-string line attribute)))
- (tst-ann-get-lines))
- ; setup keymap
- (use-local-map tst-display-mode-map)
- (setq truncate-lines t)
- )
- (setq buffer-read-only t)))
- )
-
- (defun tst-display-save-buffer (attribute)
- "Save a buffer given ATTRIBUTE name."
- (set-buffer (tst-alist-get tst-display-buffer-alist attribute))
- (set-visited-file-name (buffer-name))
- (save-buffer)
- )
-
- (defun tst-display-open-window (attribute)
- "Open a window onto an attribute."
- (interactive "Sattribute name: ")
- ; body
- (let ((saved-line (tst-display-current-line)))
- (split-window-horizontally tst-display-window-width)
- (setq tst-display-window-alist
- (tst-alist-put tst-display-window-alist
- attribute
- (selected-window)))
- (switch-to-buffer (tst-alist-get tst-display-buffer-alist attribute))
- (other-window 1)
- (tst-display-redraw)
- ; (goto-line saved-line)
- ; (recenter)
- ; (recenter)
- )
- )
-
- (defun tst-display-close-window (attribute)
- "Close a window onto an attribute."
- (interactive "Sattribute name: ")
-
- (let ((win (tst-alist-get tst-display-window-alist attribute)))
- (and win
- (progn (delete-window win)
- (tst-alist-rem tst-display-window-alist attribute)))
- )
- )
-
- (defun tst-display-redraw (&optional line)
- "Redraw all windows after moving to same line in display-windows
- as in current window."
- (interactive)
- (let ((curline (or line (tst-display-current-line)))
- (savewindow (selected-window))
- (buflist (mapcar 'cdr tst-display-buffer-alist)))
- (mapcar '(lambda (buf)
- (let ((win (get-buffer-window buf)))
- (select-window win)
- (goto-line curline)
- (recenter)))
- buflist)
- (select-window savewindow)
- (goto-line curline)
- (recenter)
- )
- )
-
-
- ;;; ----------------------------------------------------------------------
- ;;; Private Functions--
-
- (defun tst-display-batch-string (buffer line &rest attrlist)
- "Returns a string 'buffer-name:line-number:values\n'."
- (let (value string)
- (setq string (apply 'concat
- (mapcar '(lambda (attr)
- (tst-display-get-string line attr))
- attrlist))
- )
- (if (equal "" string)
- ""
- (concat (buffer-name buffer)
- ":"
- (prin1-to-string line)
- "== "
- string
- "\n"))
- )
- )
-
- (defun tst-display-get-string (line attribute)
- " return a string representation of the value <LINE ATTRIBUTE> from
- the annotation database."
- ; body
- (let ((value (tst-ann-get line attribute)))
- (cond
- ((null value) "")
- ((and (listp value)
- (= 1 (length value))) (prin1-to-string (car value)))
- (t (prin1-to-string value))
- )
- )
- )
-
- (defun tst-display-maxline ()
- "Returns number of lines in lisp-buffer"
- (save-excursion
- (set-buffer tst-display-lisp-buffer)
- (count-lines (point-min) (point-max))
- )
- )
-
- (defun tst-display-current-line ()
- "Returns current line number"
- (1+ (count-lines (point-min) (point)))
- )
-
- (defun tst-display-test-init ()
- "Test driver for package functions."
- (interactive)
-
- (let ((attr-list tst-display-attributes)
- (line-list nil)
- (line 1)
- )
- ; Create a database (cheap)
- (tst-ann-set-db nil)
- (goto-char (point-min))
- (while (not (eobp))
- (tst-ann-put line 'constant (list line line line))
- (tst-ann-put line 'zero 'NEVER->>)
- (next-line 1)
- (setq line (1+ line))
- )
- )
- )
-