Initial Commit
[packages] / xemacs-packages / ilisp / ilisp-cmt.el
1 ;;; -*- Mode: Emacs-Lisp -*-
2
3 ;;; ilisp-cmt.el --
4 ;;; ILISP comint interface code.
5 ;;;
6 ;;; This file is part of ILISP.
7 ;;; Please refer to the file COPYING for copyrights and licensing
8 ;;; information.
9 ;;; Please refer to the file ACKNOWLEGDEMENTS for an (incomplete) list
10 ;;; of present and past contributors.
11 ;;;
12 ;;; $Id: ilisp-cmt.el,v 1.3 2001-07-02 09:40:46 youngs Exp $
13
14
15 ;;;%Process interface
16 ;;;%%Comint 
17 (defun ilisp-get-old-input ()
18   "Snarf the sexp starting at the nearest previous prompt, or NIL if none."
19   (save-excursion
20     (let* ((begin (lisp-defun-begin))
21            (pmark (process-mark (get-buffer-process (current-buffer))))
22            (once (if (< (point) pmark)
23                      (save-excursion (end-of-line) (point))))
24            (end nil)
25            (done nil))
26       (condition-case ()
27           (while (and (not done) (< (point) (point-max)))
28             (forward-sexp)
29             (setq end (point))
30             (skip-chars-forward " \t\n")
31             (if (and once (>= (point) once)) (setq done t)))
32         (error (setq end nil)))
33       (if end (buffer-substring begin end)))))
34
35 ;;;
36 (defun ilisp-input-filter (str)
37   "Don't save anything matching ilisp-filter-regexp or less than
38 ilisp-filter-length long."
39   (and (not (string-match ilisp-filter-regexp str))
40        (> (length str) ilisp-filter-length)))
41
42 ;;;
43 (defun ilisp-error-filter (output)
44   "Keep from OUTPUT only what matches ilisp-error-regexp or everything
45 if there is no match."
46   (if (string-match (ilisp-value 'ilisp-error-regexp) output)
47       (substring output (match-beginning 0) (match-end 0))
48       output))
49
50
51
52 (defun newline-and-indent-lisp ()
53   "If at the end of the buffer, send the string back to the process
54 mark with no newline.  Otherwise, insert a newline, then indent.  In
55 an ilisp buffer the region is narrowed first.  See newline-and-indent
56 for more information."
57   (interactive "*")
58   (if ilisp-complete
59       (exit-minibuffer)
60       (let (input)
61         (if (and (= (point) (point-max)) 
62                  (memq major-mode ilisp-modes)
63                  (setq input (ilisp-get-old-input)))
64             (let ((process (ilisp-process))
65                   (comint-send-newline (not comint-send-newline)))
66               (funcall comint-input-sender process input)
67               (set-marker (process-mark process) (point)))
68             (save-restriction
69               (if (memq major-mode ilisp-modes)
70                   (narrow-to-region (save-excursion (lisp-input-start))
71                                     (point-max)))
72               (newline-and-indent))))))
73