annotate lisp/ilisp/ilisp-snd.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*- Mode: Emacs-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; ilisp-snd.el --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; This file is part of ILISP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Version: 5.7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Copyright (C) 1990, 1991, 1992, 1993 Chris McConnell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; 1993, 1994 Ivan Vasquez
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; 1994, 1995 Marco Antoniotti and Rick Busdiecker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; Other authors' names for which this Copyright notice also holds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; may appear later in this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; Send mail to 'ilisp-request@lehman.com' to be included in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; ILISP mailing list. 'ilisp@lehman.com' is the general ILISP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; mailing list were bugs and improvements are discussed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; ILISP is freely redistributable under the terms found in the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; COPYING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; ILISP send and support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;;%% Package / Symbol support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (defun lisp-buffer-package ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 "Return the package for this buffer. The package name is a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 If there is none, return NIL. This caches the package unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ilisp-dont-cache-package is non-nil, so calling this more than once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 is cheap."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (cond ((and (not (eq buffer-package 'not-yet-computed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (null lisp-dont-cache-package))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 buffer-package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (ilisp-completion-package ilisp-completion-package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (lisp-dont-cache-package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Refind the package each time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (let ((package (lisp-buffer-package-internal nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (setq buffer-package 'not-yet-computed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (if package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (setq mode-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (or buffer-mode-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (setq buffer-mode-name mode-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ":" package)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 package))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ((or lisp-buffer-package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (memq major-mode ilisp-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (not (memq major-mode lisp-source-modes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (make-local-variable 'buffer-package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (make-local-variable 'buffer-mode-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (let ((package (lisp-buffer-package-internal t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (setq buffer-package package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; Display package in mode line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (if package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (setq mode-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (concat (or buffer-mode-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq buffer-mode-name mode-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ":" buffer-package)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 buffer-package))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defun lisp-buffer-package-internal (search-from-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "Returns the package of the buffer. If SEARCH-FROM-START is T then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 will search from the beginning of the buffer, otherwise will search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 backwards from current point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setq mode-line-process 'ilisp-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (let* ((lisp-buffer-package t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (regexp (ilisp-value 'ilisp-package-regexp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (spec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (if (or (and search-from-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (re-search-backward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (buffer-substring (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (str (format (ilisp-value 'ilisp-package-command) spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if spec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (ilisp-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 str
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Finding buffer package"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 'pkg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (if (ilisp-value 'comint-errorp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (lisp-display-output package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (error "No package"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (if (and package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; There was a bug here, used to have the second *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; outside of the parens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (string-match "[ \n\t:\"]*\\([^ \n\t\"]*\\)" package))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (substring package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (match-beginning 1) (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 package))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (defun package-lisp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 "Show current inferior LISP package."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (message "Inferior LISP package is %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (ilisp-send (ilisp-value 'ilisp-package-name-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "Finding inferior LISP package" 'pkg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (defun set-package-lisp (package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 "Set inferior LISP to package of buffer or a named package with prefix."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (let ((default (lisp-buffer-package)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (if (or current-prefix-arg (null default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (let ((name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (format "Package [%s]: " (lisp-buffer-package)) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (list (if (equal name "") default name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (list default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (if package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (ilisp-send (format (ilisp-value 'ilisp-in-package-command) package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (format "Set %s's package to %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (buffer-name (ilisp-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 'pkg 'dispatch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (error "No package")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defun set-buffer-package-lisp (package)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "Reset the current package of the current buffer. With prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 specify manually."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (interactive (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (list (read-from-minibuffer "Package: " ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (list nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (setq buffer-package package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 mode-name (concat (or buffer-mode-name mode-name) ":" package))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq buffer-package 'not-yet-computed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (lisp-buffer-package)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;;%Interface functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;;;%%Symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (defun lisp-string-to-symbol (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 "Convert STRING to a symbol, (package delimiter symbol) where the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 package is either package:symbol or from the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (let* ((start (string-match ":+" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (end (if start (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (if start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (lisp-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (if (= start 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (substring string 0 start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (substring string start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (substring string end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (let ((package (lisp-buffer-package)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (lisp-symbol package (if package "::") string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defun lisp-symbol-to-string (symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Convert SYMBOL to a string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (apply 'concat symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (defun lisp-buffer-symbol (symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "Return SYMBOL as a string qualified for the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (let ((symbol-name (lisp-symbol-name symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (pkg (lisp-symbol-package symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (delimiter (lisp-symbol-delimiter symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (cond ((string= pkg (lisp-buffer-package)) symbol-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ((string= pkg "") (concat ":" symbol-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (pkg (concat pkg delimiter symbol-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (t symbol-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (defun lisp-previous-symbol (&optional stay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 "Return the immediately preceding symbol as ((package delimiter symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 function-p start end). If STAY is T, the end of the symbol will be point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (if (or (and (memq major-mode ilisp-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (= (point) (process-mark (get-buffer-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (or (bobp) (memq (char-after (1- (point))) '(?\) ?\")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (let* ((delimiters (ilisp-value 'ilisp-symbol-delimiters))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (end (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (if (not stay) (skip-chars-forward delimiters))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (start (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (skip-chars-backward delimiters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (prefix (if (not (bobp)) (1- start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (function-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (and prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (or (eq (char-after prefix) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (and (eq (char-after prefix) ?')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (eq (char-after (1- prefix)) ?#)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (not (looking-at "[^: \t\n]*:*\\*[^ \t\n]")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (cons (lisp-string-to-symbol (buffer-substring start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (list function-p start end))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun lisp-function-name ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Return the previous function symbol. This is either after a #' or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 at the start of the current sexp. If there is no current sexp, return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (let ((symbol (lisp-previous-symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if (car (cdr symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (car symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (and (memq major-mode ilisp-modes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (= (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (process-mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (get-buffer-process (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (backward-up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (down-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (lisp-string-to-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (progn (forward-sexp 1) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (error nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun lisp-defun-name ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Return the name of the current defun."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (lisp-defun-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (lisp-string-to-symbol (lisp-def-name t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;;;%% ILISP initializations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defun ilisp-initialized ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 "Return T if the current inferior LISP has been initialized."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (memq (buffer-name (ilisp-buffer)) ilisp-initialized))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (defun ilisp-load-init (dialect file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 "Add FILE to the files to be loaded into the inferior LISP when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 dialect is initialized. If FILE is NIL, the entry will be removed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (let ((old (assoc dialect ilisp-load-inits)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (rplacd old file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq ilisp-load-inits (nconc ilisp-load-inits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (list (cons dialect file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (if old (setq ilisp-load-inits (delq old ilisp-load-inits))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun ilisp-binary (init var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "Initialize VAR to the result of INIT if VAR is NIL."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (if (not (ilisp-value var t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (let ((binary (ilisp-value init t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (if binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (ilisp-process) binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 t nil 'binary nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (` (lambda (error wait message output last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if (or error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (not (string-match "\"[^\"]*\"" output)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (lisp-display-output output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (abort-commands-lisp "No binary"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq (, var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (substring output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (1+ (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (1- (match-end 0))))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (defun ilisp-done-init ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 "Make sure that initialization is done and if not dispatch another check."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if ilisp-load-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (comint-send-code (get-buffer-process (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 'ilisp-done-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (if ilisp-initializing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (message "Finished initializing %s" (car ilisp-dialect))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (setq ilisp-initializing nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ilisp-initialized
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (cons (buffer-name (current-buffer)) ilisp-initialized))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (defun ilisp-init-internal (&optional sync)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 "Send all of the stuff necessary to initialize."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (if sync
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (comint-sync
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (ilisp-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "\"Start sync\"" "[ \t\n]*\"Start sync\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "\"End sync\"" "\"End sync\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (ilisp-binary 'ilisp-binary-command 'ilisp-binary-extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (ilisp-binary 'ilisp-init-binary-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 'ilisp-init-binary-extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; This gets executed in the process buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (comint-send-code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (ilisp-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (let ((files ilisp-load-inits)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if (not ilisp-init-binary-extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (setq ilisp-init-binary-extension
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ilisp-binary-extension))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (while files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (ilisp-load-or-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (cdr (car files)) ilisp-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (setq files (cdr files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (comint-send-code (ilisp-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 'ilisp-done-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (setq done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (if (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq ilisp-initializing nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (abort-commands-lisp))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (set-ilisp-value 'ilisp-initializing t)) ; progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (if (not (ilisp-value 'ilisp-initializing t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (abort-commands-lisp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defun ilisp-init (&optional waitp forcep sync)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 "Initialize the current inferior LISP if necessary by loading the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 files in ilisp-load-inits. Optional WAITP waits for initialization to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 finish. When called interactively, force reinitialization. With a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 prefix, get the binary extensions again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (list (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (set-ilisp-value 'ilisp-init-binary-extension nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (set-ilisp-value 'ilisp-binary-extension nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (if (or forcep (not (ilisp-initialized)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (message "Started initializing ILISP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (if (not ilisp-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setq ilisp-directory (or (ilisp-directory "ilisp.elc" load-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (ilisp-directory "ilisp.el" load-path))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if (not (ilisp-value 'ilisp-initializing t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (ilisp-init-internal sync))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (if waitp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (while (ilisp-value 'ilisp-initializing t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (sit-for 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (defun ilisp-init-and-sync ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 "Synchronize with the inferior LISP and then initialize."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (ilisp-init nil nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (defun call-defun-lisp (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 "Put a call of the current defun in the inferior LISP and go there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 If it is a \(def* name form, look up reasonable forms of name in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 input history unless called with prefix ARG. If not found, use \(name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 or *name* as the call. If is not a def* form, put the whole form in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if (save-excursion (lisp-defun-begin) (looking-at "(def"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (let* ((symbol (lisp-defun-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (name (lisp-symbol-name symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (package (if (lisp-symbol-package symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (concat "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (lisp-symbol-package symbol) ":+\\)?")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (variablep (string-match "^\\*" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (setfp (string-match "(setf \\([^\)]+\\)" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (switch-to-lisp t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (cond (setfp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (setq name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (substring name (match-beginning 1) (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (lisp-match-ring (if (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (concat "(setf[ \t\n]*("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 package name "[ \t\n]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (concat "(setf (" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (variablep (lisp-match-ring (if (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (concat package name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (let ((fun (concat "(" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (setq name (regexp-quote name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (or (lisp-match-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (if (not arg) (concat "(" package name "[ \t\n\)]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 fun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (not arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (lisp-match-ring (concat "(" package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 "[^ \t\n]*-*" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 fun))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (let ((form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (buffer-substring (lisp-defun-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (lisp-end-defun-text t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (switch-to-lisp t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (comint-kill-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (insert form))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (defun ilisp-send (string &optional message status and-go handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 "Send STRING to the ILISP buffer, print MESSAGE set STATUS and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 return the result if AND-GO is NIL, otherwise switch to ilisp if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 and-go is T and show message and results. If AND-GO is 'dispatch,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 then the command will be executed without waiting for results. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 AND-GO is 'call, then a call will be generated. If this is the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 time an ilisp command has been executed, the lisp will also be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 initialized from the files in ilisp-load-inits. If there is an error,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 comint-errorp will be T and it will be handled by HANDLER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (ilisp-init t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (let ((process (ilisp-process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (dispatch (eq and-go 'dispatch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (message "%s" (if dispatch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (concat "Started " message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 message)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;; No completion table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq ilisp-original nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (if (memq and-go '(t call))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (progn (comint-send process string nil nil status message handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (if (eq and-go 'call)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (call-defun-lisp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (switch-to-lisp t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (let* ((save (ilisp-value 'ilisp-save-command t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (if save (format save string) string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;; Interrupt without waiting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 t (if (not dispatch) 'wait) status message handler)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (if save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (ilisp-value 'ilisp-restore-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 t nil 'restore "Restore" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (if (not dispatch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (while (not (cdr result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (accept-process-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (comint-remove-whitespace (car result))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defun ilisp-load-or-send (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 "Try to load FILE into the inferior LISP. If the file is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 accessible in the inferior LISP as determined by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ilisp-load-or-send-command, then visit the file and send the file over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 the process interface."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (let* ((command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (format (ilisp-value 'ilisp-load-or-send-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (lisp-file-extension
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (ilisp-value 'ilisp-init-binary-extension t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (set-ilisp-value 'ilisp-load-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (nconc (ilisp-value 'ilisp-load-files t) (list file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (ilisp-process) command t nil 'load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (format "Loading %s" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (function (lambda (error wait message output last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (let* ((file (lisp-last ilisp-load-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (process (get-buffer-process (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (if (and output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (string-match "nil" (car (lisp-last-line output))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (let* ((old-buffer (get-file-buffer file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (buffer (find-file-noselect file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (string (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (buffer-string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (if (not old-buffer) (kill-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (if (string= "" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (abort-commands-lisp (format "Can't find file %s" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (format ilisp-block-command string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 t nil 'send (format "Sending %s" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (function (lambda (error wait message output last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (if error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (comint-display-error output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (abort-commands-lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (format "Error sending %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (lisp-last ilisp-load-files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (setq ilisp-load-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (delq (lisp-last ilisp-load-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ilisp-load-files))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (if error (ilisp-handler error wait message output last))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (setq ilisp-load-files (delq file ilisp-load-files)))))))))