Mercurial > emacs
annotate lisp/=cmulisp.el @ 17618:8d33666b1152
(iswitchb-visit-buffer): Handle `display' alternative.
(iswitchb-default-keybindings): Define C-x 4 C-o.
(iswitchb-display-buffer): New function.
(iswitchb-entryfn-p): Include iswitchb-display-buffer.
(iswitchb-method, iswitchb-default-method): Doc fixes.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 02 May 1997 00:25:25 +0000 |
parents | 507f64624555 |
children |
rev | line source |
---|---|
957 | 1 ;;; cmulisp.el --- improved version of standard inferior-lisp mode |
2 | |
3 ;;; Copyright Olin Shivers (1988). | |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2229
diff
changeset
|
4 |
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2229
diff
changeset
|
5 ;; Keywords: processes, lisp |
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2229
diff
changeset
|
6 |
957 | 7 ;;; Please imagine a long, tedious, legalistic 5-page gnu-style copyright |
8 ;;; notice appearing here to the effect that you may use this code any | |
9 ;;; way you like, as long as you don't charge money for it, remove this | |
10 ;;; notice, or hold me liable for its results. | |
11 | |
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1368
diff
changeset
|
12 ;;; Commentary: |
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1368
diff
changeset
|
13 |
957 | 14 ;;; This replaces the standard inferior-lisp mode. |
15 ;;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88 | |
16 ;;; Please send me bug reports, bug fixes, and extensions, so that I can | |
17 ;;; merge them into the master source. | |
18 ;;; | |
19 ;;; Change log at end of file. | |
20 | |
21 ;;; This file defines a a lisp-in-a-buffer package (cmulisp mode) built on top | |
22 ;;; of comint mode. Cmulisp mode is similar to, and intended to replace, its | |
23 ;;; counterpart in the standard gnu emacs release. This replacements is more | |
24 ;;; featureful, robust, and uniform than the released version. The key | |
25 ;;; bindings are also more compatible with the bindings of Hemlock and Zwei | |
26 ;;; (the Lisp Machine emacs). | |
27 | |
28 ;;; Since this mode is built on top of the general command-interpreter-in- | |
29 ;;; a-buffer mode (comint mode), it shares a common base functionality, | |
30 ;;; and a common set of bindings, with all modes derived from comint mode. | |
31 ;;; This makes these modes easier to use. | |
32 | |
33 ;;; For documentation on the functionality provided by comint mode, and | |
34 ;;; the hooks available for customising it, see the file comint.el. | |
35 ;;; For further information on cmulisp mode, see the comments below. | |
36 | |
37 ;;; Needs fixin: | |
38 ;;; The load-file/compile-file default mechanism could be smarter -- it | |
39 ;;; doesn't know about the relationship between filename extensions and | |
40 ;;; whether the file is source or executable. If you compile foo.lisp | |
41 ;;; with compile-file, then the next load-file should use foo.bin for | |
42 ;;; the default, not foo.lisp. This is tricky to do right, particularly | |
43 ;;; because the extension for executable files varies so much (.o, .bin, | |
44 ;;; .lbin, .mo, .vo, .ao, ...). | |
45 ;;; | |
46 ;;; It would be nice if cmulisp (and inferior scheme, T, ...) modes | |
47 ;;; had a verbose minor mode wherein sending or compiling defuns, etc. | |
48 ;;; would be reflected in the transcript with suitable comments, e.g. | |
49 ;;; ";;; redefining fact". Several ways to do this. Which is right? | |
50 ;;; | |
51 ;;; When sending text from a source file to a subprocess, the process-mark can | |
52 ;;; move off the window, so you can lose sight of the process interactions. | |
53 ;;; Maybe I should ensure the process mark is in the window when I send | |
54 ;;; text to the process? Switch selectable? | |
55 | |
56 (require 'comint) | |
57 ;; YOUR .EMACS FILE | |
58 ;;============================================================================= | |
59 ;; Some suggestions for your .emacs file. | |
60 ;; | |
61 ;; ; If cmulisp lives in some non-standard directory, you must tell emacs | |
62 ;; ; where to get it. This may or may not be necessary. | |
63 ;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path)) | |
64 ;; | |
65 ;; ; Autoload cmulisp from file cmulisp.el | |
66 ;; (autoload 'cmulisp "cmulisp" | |
67 ;; "Run an inferior Lisp process." | |
68 ;; t) | |
69 ;; | |
70 ;; ; Define C-c t to run my favorite command in cmulisp mode: | |
71 ;; (setq cmulisp-load-hook | |
72 ;; '((lambda () | |
73 ;; (define-key cmulisp-mode-map "\C-ct" 'favorite-cmd)))) | |
74 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
75 ;; Brief Command Documentation: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
76 ;;============================================================================ |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
77 ;; Comint Mode Commands: (common to cmulisp and all comint-derived modes) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
78 ;; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
79 ;; m-p comint-previous-input Cycle backwards in input history |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
80 ;; m-n comint-next-input Cycle forwards |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
81 ;; m-c-r comint-previous-input-matching Search backwards in input history |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
82 ;; return comint-send-input |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
83 ;; c-a comint-bol Beginning of line; skip prompt. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
84 ;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
85 ;; c-c c-u comint-kill-input ^u |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
86 ;; c-c c-w backward-kill-word ^w |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
87 ;; c-c c-c comint-interrupt-subjob ^c |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
88 ;; c-c c-z comint-stop-subjob ^z |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
89 ;; c-c c-\ comint-quit-subjob ^\ |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
90 ;; c-c c-o comint-kill-output Delete last batch of process output |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
91 ;; c-c c-r comint-show-output Show last batch of process output |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
92 ;; send-invisible Read line w/o echo & send to proc |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
93 ;; comint-continue-subjob Useful if you accidentally suspend |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
94 ;; top-level job. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
95 ;; comint-mode-hook is the comint mode hook. |
957 | 96 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
97 ;; CMU Lisp Mode Commands: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
98 ;; c-m-x lisp-send-defun This binding is a gnu convention. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
99 ;; c-c c-l lisp-load-file Prompt for file name; tell Lisp to load it. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
100 ;; c-c c-k lisp-compile-file Prompt for file name; tell Lisp to kompile it. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
101 ;; Filename completion is available, of course. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
102 ;; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
103 ;; Additionally, these commands are added to the key bindings of Lisp mode: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
104 ;; c-m-x lisp-eval-defun This binding is a gnu convention. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
105 ;; c-c c-e lisp-eval-defun Send the current defun to Lisp process. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
106 ;; c-x c-e lisp-eval-last-sexp Send the previous sexp to Lisp process. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
107 ;; c-c c-r lisp-eval-region Send the current region to Lisp process. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
108 ;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
109 ;; c-c c-z switch-to-lisp Switch to the Lisp process buffer. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
110 ;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
111 ;; c-c c-k lisp-compile-file is to load/compile the current file.) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
112 ;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
113 ;; c-c c-a lisp-show-arglist Query Lisp for function's arglist. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
114 ;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
115 ;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc. |
957 | 116 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
117 ;; cmulisp Fires up the Lisp process. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
118 ;; lisp-compile-region Compile all forms in the current region. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
119 ;; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
120 ;; CMU Lisp Mode Variables: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
121 ;; cmulisp-filter-regexp Match this => don't get saved on input hist |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
122 ;; inferior-lisp-program Name of Lisp program run-lisp executes |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
123 ;; inferior-lisp-load-command Customises lisp-load-file |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
124 ;; cmulisp-mode-hook |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
125 ;; inferior-lisp-prompt Initialises comint-prompt-regexp. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
126 ;; Backwards compatibility. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
127 ;; lisp-source-modes Anything loaded into a buffer that's in |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
128 ;; one of these modes is considered Lisp |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
129 ;; source by lisp-load/compile-file. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
130 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
131 ;;; Code: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
132 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2247
diff
changeset
|
133 (require 'comint) |
957 | 134 |
135 ;;; Read the rest of this file for more information. | |
136 | |
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1368
diff
changeset
|
137 |
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1368
diff
changeset
|
138 ;;; Code: |
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1368
diff
changeset
|
139 |
957 | 140 (defvar cmulisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'" |
141 "*What not to save on inferior Lisp's input history | |
142 Input matching this regexp is not saved on the input history in cmulisp | |
143 mode. Default is whitespace followed by 0 or 1 single-letter :keyword | |
144 (as in :a, :c, etc.)") | |
145 | |
146 (defvar cmulisp-mode-map nil) | |
147 (cond ((not cmulisp-mode-map) | |
148 (setq cmulisp-mode-map | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
149 (nconc (full-copy-sparse-keymap comint-mode-map) |
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
150 shared-lisp-mode-map)) |
957 | 151 (define-key cmulisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) |
152 (define-key cmulisp-mode-map "\C-c\C-l" 'lisp-load-file) | |
153 (define-key cmulisp-mode-map "\C-c\C-k" 'lisp-compile-file) | |
154 (define-key cmulisp-mode-map "\C-c\C-a" 'lisp-show-arglist) | |
155 (define-key cmulisp-mode-map "\C-c\C-d" 'lisp-describe-sym) | |
156 (define-key cmulisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation) | |
157 (define-key cmulisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation))) | |
158 | |
159 ;;; These commands augment Lisp mode, so you can process Lisp code in | |
160 ;;; the source files. | |
161 (define-key lisp-mode-map "\M-\C-x" 'lisp-eval-defun) ; Gnu convention | |
162 (define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention | |
163 (define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun) | |
164 (define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region) | |
165 (define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun) | |
166 (define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp) | |
167 (define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file) | |
168 (define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file) ; "kompile" file | |
169 (define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist) | |
170 (define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym) | |
171 (define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation) | |
172 (define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation) | |
173 | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
174 (defvar cmulisp-buffer) |
957 | 175 |
176 ;;; This function exists for backwards compatibility. | |
177 ;;; Previous versions of this package bound commands to C-c <letter> | |
178 ;;; bindings, which is not allowed by the gnumacs standard. | |
179 | |
180 (defun cmulisp-install-letter-bindings () | |
181 "This function binds many cmulisp commands to C-c <letter> bindings, | |
182 where they are more accessible. C-c <letter> bindings are reserved for the | |
183 user, so these bindings are non-standard. If you want them, you should | |
184 have this function called by the cmulisp-load-hook: | |
185 (setq cmulisp-load-hook '(cmulisp-install-letter-bindings)) | |
186 You can modify this function to install just the bindings you want." | |
187 | |
188 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go) | |
189 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go) | |
190 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go) | |
191 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp) | |
192 (define-key lisp-mode-map "\C-cl" 'lisp-load-file) | |
193 (define-key lisp-mode-map "\C-ck" 'lisp-compile-file) | |
194 (define-key lisp-mode-map "\C-ca" 'lisp-show-arglist) | |
195 (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym) | |
196 (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation) | |
197 (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation) | |
198 | |
199 (define-key cmulisp-mode-map "\C-cl" 'lisp-load-file) | |
200 (define-key cmulisp-mode-map "\C-ck" 'lisp-compile-file) | |
201 (define-key cmulisp-mode-map "\C-ca" 'lisp-show-arglist) | |
202 (define-key cmulisp-mode-map "\C-cd" 'lisp-describe-sym) | |
203 (define-key cmulisp-mode-map "\C-cf" 'lisp-show-function-documentation) | |
204 (define-key cmulisp-mode-map "\C-cv" 'lisp-show-variable-documentation)) | |
205 | |
206 | |
207 (defvar inferior-lisp-program "lisp" | |
208 "*Program name for invoking an inferior Lisp with `cmulisp'.") | |
209 | |
210 (defvar inferior-lisp-load-command "(load \"%s\")\n" | |
211 "*Format-string for building a Lisp expression to load a file. | |
212 This format string should use %s to substitute a file name | |
213 and should result in a Lisp expression that will command the inferior Lisp | |
214 to load that file. The default works acceptably on most Lisps. | |
215 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\" | |
216 produces cosmetically superior output for this application, | |
217 but it works only in Common Lisp.") | |
218 | |
219 (defvar inferior-lisp-prompt "^[^> ]*>+:? *" | |
220 "Regexp to recognise prompts in the inferior Lisp. | |
221 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl, | |
222 and franz. This variable is used to initialise comint-prompt-regexp in the | |
223 cmulisp buffer. | |
224 | |
225 More precise choices: | |
226 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\" | |
227 franz: \"^\\(->\\|<[0-9]*>:\\) *\" | |
228 kcl: \"^>+ *\" | |
229 | |
230 This is a fine thing to set in your .emacs file.") | |
231 | |
232 (defvar cmulisp-mode-hook '() | |
233 "*Hook for customising cmulisp mode") | |
234 | |
235 (defun cmulisp-mode () | |
236 "Major mode for interacting with an inferior Lisp process. | |
237 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an | |
238 Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter | |
239 is run. Variables inferior-lisp-prompt, cmulisp-filter-regexp and | |
240 inferior-lisp-load-command can customize this mode for different Lisp | |
241 interpreters. | |
242 | |
243 For information on running multiple processes in multiple buffers, see | |
244 documentation for variable cmulisp-buffer. | |
245 | |
246 \\{cmulisp-mode-map} | |
247 | |
248 Customisation: Entry to this mode runs the hooks on comint-mode-hook and | |
249 cmulisp-mode-hook (in that order). | |
250 | |
251 You can send text to the inferior Lisp process from other buffers containing | |
252 Lisp source. | |
253 switch-to-lisp switches the current buffer to the Lisp process buffer. | |
254 lisp-eval-defun sends the current defun to the Lisp process. | |
255 lisp-compile-defun compiles the current defun. | |
256 lisp-eval-region sends the current region to the Lisp process. | |
257 lisp-compile-region compiles the current region. | |
258 | |
259 Prefixing the lisp-eval/compile-defun/region commands with | |
260 a \\[universal-argument] causes a switch to the Lisp process buffer after sending | |
261 the text. | |
262 | |
263 Commands: | |
264 Return after the end of the process' output sends the text from the | |
265 end of process to point. | |
266 Return before the end of the process' output copies the sexp ending at point | |
267 to the end of the process' output, and sends it. | |
268 Delete converts tabs to spaces as it moves back. | |
269 Tab indents for Lisp; with argument, shifts rest | |
270 of expression rigidly with the current line. | |
271 C-M-q does Tab on each line starting within following expression. | |
272 Paragraphs are separated only by blank lines. Semicolons start comments. | |
273 If you accidentally suspend your process, use \\[comint-continue-subjob] | |
274 to continue it." | |
275 (interactive) | |
276 (comint-mode) | |
277 (setq comint-prompt-regexp inferior-lisp-prompt) | |
278 (setq major-mode 'cmulisp-mode) | |
279 (setq mode-name "CMU Lisp") | |
280 (setq mode-line-process '(": %s")) | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
281 (lisp-mode-variables t) |
957 | 282 (use-local-map cmulisp-mode-map) ;c-c c-k for "kompile" file |
283 (setq comint-get-old-input (function lisp-get-old-input)) | |
284 (setq comint-input-filter (function lisp-input-filter)) | |
285 (setq comint-input-sentinel 'ignore) | |
286 (run-hooks 'cmulisp-mode-hook)) | |
287 | |
288 (defun lisp-get-old-input () | |
289 "Snarf the sexp ending at point" | |
290 (save-excursion | |
291 (let ((end (point))) | |
292 (backward-sexp) | |
293 (buffer-substring (point) end)))) | |
294 | |
295 (defun lisp-input-filter (str) | |
296 "Don't save anything matching cmulisp-filter-regexp" | |
297 (not (string-match cmulisp-filter-regexp str))) | |
298 | |
299 (defun cmulisp (cmd) | |
300 "Run an inferior Lisp process, input and output via buffer *cmulisp*. | |
301 If there is a process already running in *cmulisp*, just switch to that buffer. | |
302 With argument, allows you to edit the command line (default is value | |
303 of inferior-lisp-program). Runs the hooks from cmulisp-mode-hook (after the | |
304 comint-mode-hook is run). | |
305 \(Type \\[describe-mode] in the process buffer for a list of commands.)" | |
306 (interactive (list (if current-prefix-arg | |
307 (read-string "Run lisp: " inferior-lisp-program) | |
308 inferior-lisp-program))) | |
309 (if (not (comint-check-proc "*cmulisp*")) | |
310 (let ((cmdlist (cmulisp-args-to-list cmd))) | |
311 (set-buffer (apply (function make-comint) "cmulisp" (car cmdlist) nil | |
312 (cdr cmdlist))) | |
313 (cmulisp-mode))) | |
314 (setq cmulisp-buffer "*cmulisp*") | |
315 (switch-to-buffer "*cmulisp*")) | |
316 | |
317 ;;; Break a string up into a list of arguments. | |
318 ;;; This will break if you have an argument with whitespace, as in | |
319 ;;; string = "-ab +c -x 'you lose'". | |
320 (defun cmulisp-args-to-list (string) | |
321 (let ((where (string-match "[ \t]" string))) | |
322 (cond ((null where) (list string)) | |
323 ((not (= where 0)) | |
324 (cons (substring string 0 where) | |
325 (tea-args-to-list (substring string (+ 1 where) | |
326 (length string))))) | |
327 (t (let ((pos (string-match "[^ \t]" string))) | |
328 (if (null pos) | |
329 nil | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
330 (cmulisp-args-to-list (substring string pos |
957 | 331 (length string))))))))) |
332 | |
333 (defun lisp-eval-region (start end &optional and-go) | |
334 "Send the current region to the inferior Lisp process. | |
335 Prefix argument means switch-to-lisp afterwards." | |
336 (interactive "r\nP") | |
337 (comint-send-region (cmulisp-proc) start end) | |
338 (comint-send-string (cmulisp-proc) "\n") | |
339 (if and-go (switch-to-lisp t))) | |
340 | |
341 (defun lisp-eval-defun (&optional and-go) | |
342 "Send the current defun to the inferior Lisp process. | |
343 Prefix argument means switch-to-lisp afterwards." | |
344 (interactive "P") | |
345 (save-excursion | |
346 (end-of-defun) | |
347 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy | |
348 (let ((end (point))) | |
349 (beginning-of-defun) | |
350 (lisp-eval-region (point) end))) | |
351 (if and-go (switch-to-lisp t))) | |
352 | |
353 (defun lisp-eval-last-sexp (&optional and-go) | |
354 "Send the previous sexp to the inferior Lisp process. | |
355 Prefix argument means switch-to-lisp afterwards." | |
356 (interactive "P") | |
357 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go)) | |
358 | |
359 ;;; Common Lisp COMPILE sux. | |
360 (defun lisp-compile-region (start end &optional and-go) | |
361 "Compile the current region in the inferior Lisp process. | |
362 Prefix argument means switch-to-lisp afterwards." | |
363 (interactive "r\nP") | |
364 (comint-send-string (cmulisp-proc) | |
365 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n" | |
366 (buffer-substring start end))) | |
367 (if and-go (switch-to-lisp t))) | |
368 | |
369 (defun lisp-compile-defun (&optional and-go) | |
370 "Compile the current defun in the inferior Lisp process. | |
371 Prefix argument means switch-to-lisp afterwards." | |
372 (interactive "P") | |
373 (save-excursion | |
374 (end-of-defun) | |
375 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy | |
376 (let ((e (point))) | |
377 (beginning-of-defun) | |
378 (lisp-compile-region (point) e))) | |
379 (if and-go (switch-to-lisp t))) | |
380 | |
381 (defun switch-to-lisp (eob-p) | |
382 "Switch to the inferior Lisp process buffer. | |
383 With argument, positions cursor at end of buffer." | |
384 (interactive "P") | |
385 (if (get-buffer cmulisp-buffer) | |
386 (pop-to-buffer cmulisp-buffer) | |
387 (error "No current process buffer. See variable cmulisp-buffer.")) | |
388 (cond (eob-p | |
389 (push-mark) | |
390 (goto-char (point-max))))) | |
391 | |
392 | |
393 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg, | |
394 ;;; these commands are redundant. But they are kept around for the user | |
395 ;;; to bind if he wishes, for backwards functionality, and because it's | |
396 ;;; easier to type C-c e than C-u C-c C-e. | |
397 | |
398 (defun lisp-eval-region-and-go (start end) | |
399 "Send the current region to the inferior Lisp, | |
400 and switch to the process buffer." | |
401 (interactive "r") | |
402 (lisp-eval-region start end t)) | |
403 | |
404 (defun lisp-eval-defun-and-go () | |
405 "Send the current defun to the inferior Lisp, | |
406 and switch to the process buffer." | |
407 (interactive) | |
408 (lisp-eval-defun t)) | |
409 | |
410 (defun lisp-compile-region-and-go (start end) | |
411 "Compile the current region in the inferior Lisp, | |
412 and switch to the process buffer." | |
413 (interactive "r") | |
414 (lisp-compile-region start end t)) | |
415 | |
416 (defun lisp-compile-defun-and-go () | |
417 "Compile the current defun in the inferior Lisp, | |
418 and switch to the process buffer." | |
419 (interactive) | |
420 (lisp-compile-defun t)) | |
421 | |
422 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust. | |
423 ;(defun lisp-compile-sexp (start end) | |
424 ; "Compile the s-expression bounded by START and END in the inferior lisp. | |
425 ;If the sexp isn't a DEFUN form, it is evaluated instead." | |
426 ; (cond ((looking-at "(defun\\s +") | |
427 ; (goto-char (match-end 0)) | |
428 ; (let ((name-start (point))) | |
429 ; (forward-sexp 1) | |
430 ; (process-send-string "cmulisp" (format "(compile '%s #'(lambda " | |
431 ; (buffer-substring name-start | |
432 ; (point))))) | |
433 ; (let ((body-start (point))) | |
434 ; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun. | |
435 ; (process-send-region "cmulisp" (buffer-substring body-start (point)))) | |
436 ; (process-send-string "cmulisp" ")\n")) | |
437 ; (t (lisp-eval-region start end))))) | |
438 ; | |
439 ;(defun lisp-compile-region (start end) | |
440 ; "Each s-expression in the current region is compiled (if a DEFUN) | |
441 ;or evaluated (if not) in the inferior lisp." | |
442 ; (interactive "r") | |
443 ; (save-excursion | |
444 ; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check | |
445 ; (if (< (point) start) (error "region begins in middle of defun")) | |
446 ; (goto-char start) | |
447 ; (let ((s start)) | |
448 ; (end-of-defun) | |
449 ; (while (<= (point) end) ; Zip through | |
450 ; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks. | |
451 ; (setq s (point)) | |
452 ; (end-of-defun)) | |
453 ; (if (< s end) (lisp-compile-sexp s end))))) | |
454 ;;; | |
455 ;;; End of HS-style code | |
456 | |
457 | |
458 (defvar lisp-prev-l/c-dir/file nil | |
459 "Saves the (directory . file) pair used in the last lisp-load-file or | |
460 lisp-compile-file command. Used for determining the default in the | |
461 next one.") | |
462 | |
463 (defvar lisp-source-modes '(lisp-mode) | |
464 "*Used to determine if a buffer contains Lisp source code. | |
465 If it's loaded into a buffer that is in one of these major modes, it's | |
466 considered a Lisp source file by lisp-load-file and lisp-compile-file. | |
467 Used by these commands to determine defaults.") | |
468 | |
469 (defun lisp-load-file (file-name) | |
470 "Load a Lisp file into the inferior Lisp process." | |
471 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file | |
472 lisp-source-modes nil)) ; NIL because LOAD | |
473 ; doesn't need an exact name | |
474 (comint-check-source file-name) ; Check to see if buffer needs saved. | |
475 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name) | |
476 (file-name-nondirectory file-name))) | |
477 (comint-send-string (cmulisp-proc) | |
478 (format inferior-lisp-load-command file-name)) | |
479 (switch-to-lisp t)) | |
480 | |
481 | |
482 (defun lisp-compile-file (file-name) | |
483 "Compile a Lisp file in the inferior Lisp process." | |
484 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file | |
485 lisp-source-modes nil)) ; NIL = don't need | |
486 ; suffix .lisp | |
487 (comint-check-source file-name) ; Check to see if buffer needs saved. | |
488 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name) | |
489 (file-name-nondirectory file-name))) | |
490 (comint-send-string (cmulisp-proc) (concat "(compile-file \"" | |
491 file-name | |
492 "\"\)\n")) | |
493 (switch-to-lisp t)) | |
494 | |
495 | |
496 | |
497 ;;; Documentation functions: function doc, var doc, arglist, and | |
498 ;;; describe symbol. | |
499 ;;; =========================================================================== | |
500 | |
501 ;;; Command strings | |
502 ;;; =============== | |
503 | |
504 (defvar lisp-function-doc-command | |
505 "(let ((fn '%s)) | |
506 (format t \"Documentation for ~a:~&~a\" | |
507 fn (documentation fn 'function)) | |
508 (values))\n" | |
509 "Command to query inferior Lisp for a function's documentation.") | |
510 | |
511 (defvar lisp-var-doc-command | |
512 "(let ((v '%s)) | |
513 (format t \"Documentation for ~a:~&~a\" | |
514 v (documentation v 'variable)) | |
515 (values))\n" | |
516 "Command to query inferior Lisp for a variable's documentation.") | |
517 | |
518 (defvar lisp-arglist-command | |
519 "(let ((fn '%s)) | |
520 (format t \"Arglist for ~a: ~a\" fn (arglist fn)) | |
521 (values))\n" | |
522 "Command to query inferior Lisp for a function's arglist.") | |
523 | |
524 (defvar lisp-describe-sym-command | |
525 "(describe '%s)\n" | |
526 "Command to query inferior Lisp for a variable's documentation.") | |
527 | |
528 | |
529 ;;; Ancillary functions | |
530 ;;; =================== | |
531 | |
532 ;;; Reads a string from the user. | |
533 (defun lisp-symprompt (prompt default) | |
534 (list (let* ((prompt (if default | |
535 (format "%s (default %s): " prompt default) | |
536 (concat prompt ": "))) | |
537 (ans (read-string prompt))) | |
538 (if (zerop (length ans)) default ans)))) | |
539 | |
540 | |
541 ;;; Adapted from function-called-at-point in help.el. | |
542 (defun lisp-fn-called-at-pt () | |
543 "Returns the name of the function called in the current call. | |
544 Nil if it can't find one." | |
545 (condition-case nil | |
546 (save-excursion | |
547 (save-restriction | |
548 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max)) | |
549 (backward-up-list 1) | |
550 (forward-char 1) | |
551 (let ((obj (read (current-buffer)))) | |
552 (and (symbolp obj) obj)))) | |
553 (error nil))) | |
554 | |
555 | |
556 ;;; Adapted from variable-at-point in help.el. | |
557 (defun lisp-var-at-pt () | |
558 (condition-case () | |
559 (save-excursion | |
560 (forward-sexp -1) | |
561 (skip-chars-forward "'") | |
562 (let ((obj (read (current-buffer)))) | |
563 (and (symbolp obj) obj))) | |
564 (error nil))) | |
565 | |
566 | |
567 ;;; Documentation functions: fn and var doc, arglist, and symbol describe. | |
568 ;;; ====================================================================== | |
569 | |
570 (defun lisp-show-function-documentation (fn) | |
571 "Send a command to the inferior Lisp to give documentation for function FN. | |
572 See variable lisp-function-doc-command." | |
573 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt))) | |
574 (comint-proc-query (cmulisp-proc) (format lisp-function-doc-command fn))) | |
575 | |
576 (defun lisp-show-variable-documentation (var) | |
577 "Send a command to the inferior Lisp to give documentation for function FN. | |
578 See variable lisp-var-doc-command." | |
579 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt))) | |
580 (comint-proc-query (cmulisp-proc) (format lisp-var-doc-command var))) | |
581 | |
582 (defun lisp-show-arglist (fn) | |
583 "Sends an query to the inferior Lisp for the arglist for function FN. | |
584 See variable lisp-arglist-command." | |
585 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt))) | |
586 (comint-proc-query (cmulisp-proc) (format lisp-arglist-command fn))) | |
587 | |
588 (defun lisp-describe-sym (sym) | |
589 "Send a command to the inferior Lisp to describe symbol SYM. | |
590 See variable lisp-describe-sym-command." | |
591 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt))) | |
592 (comint-proc-query (cmulisp-proc) (format lisp-describe-sym-command sym))) | |
593 | |
594 | |
595 (defvar cmulisp-buffer nil "*The current cmulisp process buffer. | |
596 | |
597 MULTIPLE PROCESS SUPPORT | |
598 =========================================================================== | |
599 Cmulisp.el supports, in a fairly simple fashion, running multiple Lisp | |
600 processes. To run multiple Lisp processes, you start the first up with | |
601 \\[cmulisp]. It will be in a buffer named *cmulisp*. Rename this buffer | |
602 with \\[rename-buffer]. You may now start up a new process with another | |
603 \\[cmulisp]. It will be in a new buffer, named *cmulisp*. You can | |
604 switch between the different process buffers with \\[switch-to-buffer]. | |
605 | |
606 Commands that send text from source buffers to Lisp processes -- | |
607 like lisp-eval-defun or lisp-show-arglist -- have to choose a process | |
608 to send to, when you have more than one Lisp process around. This | |
609 is determined by the global variable cmulisp-buffer. Suppose you | |
610 have three inferior lisps running: | |
611 Buffer Process | |
612 foo cmulisp | |
613 bar cmulisp<2> | |
614 *cmulisp* cmulisp<3> | |
615 If you do a \\[lisp-eval-defun] command on some Lisp source code, | |
616 what process do you send it to? | |
617 | |
618 - If you're in a process buffer (foo, bar, or *cmulisp*), | |
619 you send it to that process. | |
620 - If you're in some other buffer (e.g., a source file), you | |
621 send it to the process attached to buffer cmulisp-buffer. | |
622 This process selection is performed by function cmulisp-proc. | |
623 | |
624 Whenever \\[cmulisp] fires up a new process, it resets cmulisp-buffer | |
625 to be the new process's buffer. If you only run one process, this will | |
626 do the right thing. If you run multiple processes, you can change | |
627 cmulisp-buffer to another process buffer with \\[set-variable]. | |
628 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2307
diff
changeset
|
629 More sophisticated approaches are, of course, possible. If you find yourself |
957 | 630 needing to switch back and forth between multiple processes frequently, |
631 you may wish to consider ilisp.el, a larger, more sophisticated package | |
632 for running inferior Lisp processes. The approach taken here is for a | |
633 minimal, simple implementation. Feel free to extend it.") | |
634 | |
635 (defun cmulisp-proc () | |
636 "Returns the current cmulisp process. See variable cmulisp-buffer." | |
637 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode) | |
638 (current-buffer) | |
639 cmulisp-buffer)))) | |
640 (or proc | |
641 (error "No current process. See variable cmulisp-buffer")))) | |
642 | |
643 | |
644 ;;; Do the user's customisation... | |
645 ;;;=============================== | |
646 (defvar cmulisp-load-hook nil | |
647 "This hook is run when cmulisp is loaded in. | |
648 This is a good place to put keybindings.") | |
649 | |
650 (run-hooks 'cmulisp-load-hook) | |
651 | |
652 ;;; CHANGE LOG | |
653 ;;; =========================================================================== | |
654 ;;; 5/24/90 Olin | |
655 ;;; - Split cmulisp and cmushell modes into separate files. | |
656 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19. | |
657 ;;; - Upgraded process sends to use comint-send-string instead of | |
658 ;;; process-send-string. | |
659 ;;; - Explicit references to process "cmulisp" have been replaced with | |
660 ;;; (cmulisp-proc). This allows better handling of multiple process bufs. | |
661 ;;; - Added process query and var/function/symbol documentation | |
662 ;;; commands. Based on code written by Douglas Roberts. | |
663 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e. | |
664 ;;; | |
665 ;;; 9/20/90 Olin | |
666 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix | |
667 ;;; reported by Lennart Staflin. | |
668 ;;; | |
669 ;;; 3/12/90 Olin | |
670 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp. | |
671 ;;; Tale suggested this. | |
672 ;;; - Reversed this decision 7/15/91. You need the visual feedback. | |
673 ;;; | |
674 ;;; 7/25/91 Olin | |
675 ;;; Changed all keybindings of the form C-c <letter>. These are | |
676 ;;; supposed to be reserved for the user to bind. This affected | |
677 ;;; mainly the compile/eval-defun/region[-and-go] commands. | |
678 ;;; This was painful, but necessary to adhere to the gnumacs standard. | |
679 ;;; For some backwards compatibility, see the | |
680 ;;; cmulisp-install-letter-bindings | |
681 ;;; function. | |
682 ;;; | |
683 ;;; 8/2/91 Olin | |
684 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg, | |
685 ;;; which means switch-to-lisp after sending the text to the Lisp process. | |
686 ;;; This obsoletes all the -and-go commands. The -and-go commands are | |
687 ;;; kept around for historical reasons, and because the user can bind | |
688 ;;; them to key sequences shorter than C-u C-c C-<letter>. | |
689 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to | |
690 ;;; edit the command line. | |
691 | |
692 (provide 'cmulisp) | |
693 | |
694 ;;; cmulisp.el ends here |