/[cmucl]/src/hemlock/lispbuf.lisp
ViewVC logotype

Contents of /src/hemlock/lispbuf.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1.1.1 - (show annotations) (vendor branch)
Fri Aug 3 10:17:19 1990 UTC (23 years, 8 months ago) by wlott
Changes since 1.1.1.1: +1 -1 lines
Changed uses of ``string-char'' to ``base-character''
1 ;;; -*- Log: hemlock.log; Package: Hemlock -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the Spice Lisp project at
5 ;;; Carnegie-Mellon University, and has been placed in the public domain.
6 ;;; Spice Lisp is currently incomplete and under active development.
7 ;;; If you want to use this code or any part of Spice Lisp, please contact
8 ;;; Scott Fahlman (FAHLMAN@CMUC).
9 ;;; **********************************************************************
10 ;;;
11 ;;; Stuff to do a little lisp hacking in the editor's Lisp environment.
12 ;;;
13
14 (in-package "HEMLOCK")
15
16
17 (defmacro in-lisp (&body body)
18 "Evaluates body inside HANDLE-LISP-ERRORS. *package* is bound to the package
19 named by \"Current Package\" if it is non-nil."
20 (let ((name (gensym)) (package (gensym)))
21 `(handle-lisp-errors
22 (let* ((,name (value current-package))
23 (,package (and ,name (find-package ,name))))
24 (progv (if ,package '(*package*)) (if ,package (list ,package))
25 ,@body)))))
26
27
28 (define-file-option "Package" (buffer value)
29 (defhvar "Current Package"
30 "The package used for evaluation of Lisp in this buffer."
31 :buffer buffer
32 :value
33 (let* ((eof (list nil))
34 (thing (read-from-string value nil eof)))
35 (when (eq thing eof) (error "Bad package file option value."))
36 (cond
37 ((stringp thing)
38 thing)
39 ((symbolp thing)
40 (symbol-name thing))
41 ((characterp thing)
42 (string thing))
43 (t
44 (message
45 "Ignoring \"package\" file option -- cannot convert to a string."))))))
46
47
48 ;;;; Eval Mode Interaction.
49
50 (proclaim '(special * ** *** - + ++ +++ / // /// *prompt*))
51
52 (defun setup-eval-mode (buffer)
53 (let ((point (buffer-point buffer)))
54 (setf (buffer-minor-mode buffer "Eval") t)
55 (setf (buffer-minor-mode buffer "Editor") t)
56 (setf (buffer-major-mode buffer) "Lisp")
57 (buffer-end point)
58 (defhvar "Current Package"
59 "This variable holds the name of the package currently used for Lisp
60 evaluation and compilation. If it is Nil, the value of *Package* is used
61 instead."
62 :value nil
63 :buffer buffer)
64 (unless (hemlock-bound-p 'buffer-input-mark :buffer buffer)
65 (defhvar "Buffer Input Mark"
66 "Mark used for Eval Mode input."
67 :buffer buffer
68 :value (copy-mark point :right-inserting))
69 (defhvar "Eval Output Stream"
70 "Output stream used for Eval Mode output in this buffer."
71 :buffer buffer
72 :value (make-hemlock-output-stream point))
73 (defhvar "Interactive History"
74 "A ring of the regions input to an interactive mode (Eval or Typescript)."
75 :buffer buffer
76 :value (make-ring (value interactive-history-length)))
77 (defhvar "Interactive Pointer"
78 "Pointer into \"Interactive History\"."
79 :buffer buffer
80 :value 0)
81 (defhvar "Searching Interactive Pointer"
82 "Pointer into \"Interactive History\"."
83 :buffer buffer
84 :value 0))
85 (let ((*standard-output*
86 (variable-value 'eval-output-stream :buffer buffer)))
87 (fresh-line)
88 (princ (if (functionp *prompt*)
89 (funcall *prompt*)
90 *prompt*)))
91 (move-mark (variable-value 'buffer-input-mark :buffer buffer) point)))
92
93 (defmode "Eval" :major-p nil :setup-function #'setup-eval-mode)
94
95 (defun eval-mode-lisp-mode-hook (buffer on)
96 "Turn on Lisp mode when we go into Eval Mode."
97 (when on
98 (setf (buffer-major-mode buffer) "Lisp")))
99 ;;;
100 (add-hook eval-mode-hook 'eval-mode-lisp-mode-hook)
101
102 (defhvar "Editor Definition Info"
103 "When this is non-nil, the editor Lisp is used to determine definition
104 editing information; otherwise, the slave Lisp is used."
105 :value t
106 :mode "Eval")
107
108
109 (defvar *selected-eval-buffer* nil)
110
111 (defcommand "Select Eval Buffer" (p)
112 "Goto buffer in \"Eval\" mode, creating one if necessary."
113 "Goto buffer in \"Eval\" mode, creating one if necessary."
114 (declare (ignore p))
115 (unless *selected-eval-buffer*
116 (when (getstring "Eval" *buffer-names*)
117 (editor-error "There is already a buffer named \"Eval\"!"))
118 (setf *selected-eval-buffer*
119 (make-buffer "Eval"
120 :delete-hook
121 (list #'(lambda (buf)
122 (declare (ignore buf))
123 (setf *selected-eval-buffer* nil)))))
124 (setf (buffer-minor-mode *selected-eval-buffer* "Eval") t))
125 (change-to-buffer *selected-eval-buffer*))
126
127
128 (defvar lispbuf-eof '(nil))
129
130 (defhvar "Unwedge Interactive Input Confirm"
131 "When set (the default), trying to confirm interactive input when the
132 point is not after the input mark causes Hemlock to ask the user if he
133 needs to be unwedged. When not set, an editor error is signaled
134 informing the user that the point is before the input mark."
135 :value t)
136
137 (defun unwedge-eval-buffer ()
138 (abort-eval-input-command nil))
139
140 (defhvar "Unwedge Interactive Input Fun"
141 "Function to call when input is confirmed, but the point is not past the
142 input mark."
143 :value #'unwedge-eval-buffer
144 :mode "Eval")
145
146 (defhvar "Unwedge Interactive Input String"
147 "String to add to \"Point not past input mark. \" explaining what will
148 happen if the the user chooses to be unwedged."
149 :value "Prompt again at the end of the buffer? "
150 :mode "Eval")
151
152 (defcommand "Confirm Eval Input" (p)
153 "Evaluate Eval Mode input between point and last prompt."
154 "Evaluate Eval Mode input between point and last prompt."
155 (declare (ignore p))
156 (let ((input-region (get-interactive-input)))
157 (when input-region
158 (let* ((output (value eval-output-stream))
159 (*standard-output* output)
160 (*error-output* output)
161 (*trace-output* output))
162 (fresh-line)
163 (in-lisp
164 ;; Copy the region to keep the output and input streams from interacting
165 ;; since input-region is made of permanent marks into the buffer.
166 (with-input-from-region (stream (copy-region input-region))
167 (loop
168 (let ((form (read stream nil lispbuf-eof)))
169 (when (eq form lispbuf-eof)
170 ;; Move the buffer's input mark to the end of the buffer.
171 (move-mark (region-start input-region)
172 (region-end input-region))
173 (return))
174 (setq +++ ++ ++ + + - - form)
175 (let ((this-eval (multiple-value-list (eval form))))
176 (fresh-line)
177 (dolist (x this-eval) (prin1 x) (terpri))
178 (princ (if (functionp *prompt*)
179 (funcall *prompt*)
180 *prompt*))
181 (setq /// // // / / this-eval)
182 (setq *** ** ** * * (car this-eval)))))))))))
183
184 (defcommand "Abort Eval Input" (p)
185 "Move to the end of the buffer and prompt."
186 "Move to the end of the buffer and prompt."
187 (declare (ignore p))
188 (let ((point (current-point)))
189 (buffer-end point)
190 (insert-character point #\newline)
191 (insert-string point "Aborted.")
192 (insert-character point #\newline)
193 (insert-string point
194 (if (functionp *prompt*)
195 (funcall *prompt*)
196 *prompt*))
197 (move-mark (value buffer-input-mark) point)))
198
199
200
201 ;;;; General interactive commands used in eval and typescript buffers.
202
203 (defun get-interactive-input ()
204 "Tries to return a region. When the point is not past the input mark, and
205 the user has \"Unwedge Interactive Input Confirm\" set, the buffer is
206 optionally fixed up, and nil is returned. Otherwise, an editor error is
207 signalled. When a region is returned, the start is the current buffer's
208 input mark, and the end is the current point moved to the end of the buffer."
209 (let ((point (current-point))
210 (mark (value buffer-input-mark)))
211 (cond
212 ((mark>= point mark)
213 (buffer-end point)
214 (let* ((input-region (region mark point))
215 (string (region-to-string input-region))
216 (ring (value interactive-history)))
217 (when (and (or (zerop (ring-length ring))
218 (string/= string (region-to-string (ring-ref ring 0))))
219 (> (length string) (value minimum-interactive-input-length)))
220 (ring-push (copy-region input-region) ring))
221 input-region))
222 ((value unwedge-interactive-input-confirm)
223 (beep)
224 (when (prompt-for-y-or-n
225 :prompt (concatenate 'simple-string
226 "Point not past input mark. "
227 (value unwedge-interactive-input-string))
228 :must-exist t :default t :default-string "yes")
229 (funcall (value unwedge-interactive-input-fun))
230 (message "Unwedged."))
231 nil)
232 (t
233 (editor-error "Point not past input mark.")))))
234
235 (defhvar "Interactive History Length"
236 "This is the length used for the history ring in interactive buffers.
237 It must be set before turning on the mode."
238 :value 10)
239
240 (defhvar "Minimum Interactive Input Length"
241 "When the number of characters in an interactive buffer exceeds this value,
242 it is pushed onto the interactive history, otherwise it is lost forever."
243 :value 2)
244
245
246 (defvar *previous-input-search-string* "ignore")
247
248 (defvar *previous-input-search-pattern*
249 ;; Give it a bogus string since you can't give it the empty string.
250 (new-search-pattern :string-insensitive :forward "ignore"))
251
252 (defun get-previous-input-search-pattern (string)
253 (if (string= *previous-input-search-string* string)
254 *previous-input-search-pattern*
255 (new-search-pattern :string-insensitive :forward
256 (setf *previous-input-search-string* string)
257 *previous-input-search-pattern*)))
258
259 (defcommand "Search Previous Interactive Input" (p)
260 "Search backward through the interactive history using the current input as
261 a search string. Consecutive invocations repeat the previous search."
262 "Search backward through the interactive history using the current input as
263 a search string. Consecutive invocations repeat the previous search."
264 (declare (ignore p))
265 (let* ((mark (value buffer-input-mark))
266 (ring (value interactive-history))
267 (point (current-point))
268 (just-invoked (eq (last-command-type) :searching-interactive-input)))
269 (when (mark<= point mark)
270 (editor-error "Point not past input mark."))
271 (when (zerop (ring-length ring))
272 (editor-error "No previous input in this buffer."))
273 (unless just-invoked
274 (get-previous-input-search-pattern (region-to-string (region mark point))))
275 (let ((found-it (find-previous-input ring just-invoked)))
276 (unless found-it
277 (editor-error "Couldn't find ~a." *previous-input-search-string*))
278 (delete-region (region mark point))
279 (insert-region point (ring-ref ring found-it))
280 (setf (value searching-interactive-pointer) found-it))
281 (setf (last-command-type) :searching-interactive-input)))
282
283 (defun find-previous-input (ring againp)
284 (let ((ring-length (ring-length ring))
285 (base (if againp
286 (+ (value searching-interactive-pointer) 1)
287 0)))
288 (loop
289 (when (= base ring-length)
290 (if againp
291 (setf base 0)
292 (return nil)))
293 (with-mark ((m (region-start (ring-ref ring base))))
294 (when (find-pattern m *previous-input-search-pattern*)
295 (return base)))
296 (incf base))))
297
298 (defcommand "Previous Interactive Input" (p)
299 "Insert the previous input in an interactive mode (Eval or Typescript).
300 If repeated, keep rotating the history. With prefix argument, rotate
301 that many times."
302 "Pop the *interactive-history* at the point."
303 (let* ((point (current-point))
304 (mark (value buffer-input-mark))
305 (ring (value interactive-history))
306 (length (ring-length ring))
307 (p (or p 1)))
308 (when (or (mark< point mark) (zerop length)) (editor-error))
309 (cond
310 ((eq (last-command-type) :interactive-history)
311 (let ((base (mod (+ (value interactive-pointer) p) length)))
312 (delete-region (region mark point))
313 (insert-region point (ring-ref ring base))
314 (setf (value interactive-pointer) base)))
315 (t
316 (let ((base (mod (if (minusp p) p (1- p)) length))
317 (region (delete-and-save-region (region mark point))))
318 (insert-region point (ring-ref ring base))
319 (when (mark/= (region-start region) (region-end region))
320 (ring-push region ring)
321 (incf base))
322 (setf (value interactive-pointer) base)))))
323 (setf (last-command-type) :interactive-history))
324
325 (defcommand "Next Interactive Input" (p)
326 "Rotate the interactive history backwards. The region is left around the
327 inserted text. With prefix argument, rotate that many times."
328 "Call previous-interactive-input-command with negated arg."
329 (previous-interactive-input-command (- (or p 1))))
330
331 (defcommand "Kill Interactive Input" (p)
332 "Kill any input to an interactive mode (Eval or Typescript)."
333 "Kill any input to an interactive mode (Eval or Typescript)."
334 (declare (ignore p))
335 (let ((point (buffer-point (current-buffer)))
336 (mark (value buffer-input-mark)))
337 (when (mark< point mark) (editor-error))
338 (kill-region (region mark point) :kill-backward)))
339
340 (defcommand "Interactive Beginning of Line" (p)
341 "If on line with current prompt, go to after it, otherwise do what
342 \"Beginning of Line\" always does."
343 "Go to after prompt when on prompt line."
344 (let ((mark (value buffer-input-mark))
345 (point (current-point)))
346 (if (and (same-line-p point mark) (or (not p) (= p 1)))
347 (move-mark point mark)
348 (beginning-of-line-command p))))
349
350 (defcommand "Reenter Interactive Input" (p)
351 "Copies the form to the left of point to be after the interactive buffer's
352 input mark. When the current region is active, it is copied instead."
353 "Copies the form to the left of point to be after the interactive buffer's
354 input mark. When the current region is active, it is copied instead."
355 (declare (ignore p))
356 (unless (hemlock-bound-p 'buffer-input-mark)
357 (editor-error "Not in an interactive buffer."))
358 (let ((point (current-point)))
359 (let ((region (if (region-active-p)
360 ;; Copy this, so moving point doesn't affect the region.
361 (copy-region (current-region))
362 (with-mark ((start point)
363 (end point))
364 (pre-command-parse-check start)
365 (unless (form-offset start -1)
366 (editor-error "Not after complete form."))
367 (region (copy-mark start) (copy-mark end))))))
368 (buffer-end point)
369 (push-buffer-mark (copy-mark point))
370 (insert-region point region)
371 (setf (last-command-type) :ephemerally-active))))
372
373
374
375 ;;; Other stuff.
376
377 (defmode "Editor")
378
379 (defcommand "Editor Mode" (p)
380 "Turn on \"Editor\" mode in the current buffer. If it is already on, turn it
381 off. When in editor mode, most lisp compilation and evaluation commands
382 manipulate the editor process instead of the current eval server."
383 "Toggle \"Editor\" mode in the current buffer."
384 (declare (ignore p))
385 (setf (buffer-minor-mode (current-buffer) "Editor")
386 (not (buffer-minor-mode (current-buffer) "Editor"))))
387
388 (define-file-option "Editor" (buffer value)
389 (declare (ignore value))
390 (setf (buffer-minor-mode buffer "Editor") t))
391
392 (defhvar "Editor Definition Info"
393 "When this is non-nil, the editor Lisp is used to determine definition
394 editing information; otherwise, the slave Lisp is used."
395 :value t
396 :mode "Editor")
397
398 (defcommand "Editor Compile Defun" (p)
399 "Compiles the current or next top-level form in the editor Lisp.
400 First the form is evaluated, then the result of this evaluation
401 is passed to compile. If the current region is active, this
402 compiles the region."
403 "Evaluates the current or next top-level form in the editor Lisp."
404 (declare (ignore p))
405 (if (region-active-p)
406 (editor-compile-region (current-region))
407 (editor-compile-region (defun-region (current-point)) t)))
408
409 (defcommand "Editor Compile Region" (p)
410 "Compiles lisp forms between the point and the mark in the editor Lisp."
411 "Compiles lisp forms between the point and the mark in the editor Lisp."
412 (declare (ignore p))
413 (editor-compile-region (current-region)))
414
415 (defun defun-region (mark)
416 "This returns a region around the current or next defun with respect to mark.
417 Mark is not used to form the region. If there is no appropriate top level
418 form, this signals an editor-error. This calls PRE-COMMAND-PARSE-CHECK."
419 (with-mark ((start mark)
420 (end mark))
421 (pre-command-parse-check start)
422 (cond ((not (mark-top-level-form start end))
423 (editor-error "No current or next top level form."))
424 (t (region start end)))))
425
426 (defun editor-compile-region (region &optional quiet)
427 (unless quiet (message "Compiling region ..."))
428 (in-lisp
429 (with-input-from-region (stream region)
430 (with-pop-up-display (*error-output* :height 19)
431 (c::compile-from-stream stream
432 :defined-from-pathname
433 (buffer-pathname (current-buffer)))))))
434
435
436 (defcommand "Editor Evaluate Defun" (p)
437 "Evaluates the current or next top-level form in the editor Lisp.
438 If the current region is active, this evaluates the region."
439 "Evaluates the current or next top-level form in the editor Lisp."
440 (declare (ignore p))
441 (if (region-active-p)
442 (editor-evaluate-region-command nil)
443 (with-input-from-region (stream (defun-region (current-point)))
444 (clear-echo-area)
445 (in-lisp
446 (message "Editor Evaluation returned ~S"
447 (eval (read stream)))))))
448
449 (defcommand "Editor Evaluate Region" (p)
450 "Evaluates lisp forms between the point and the mark in the editor Lisp."
451 "Evaluates lisp forms between the point and the mark in the editor Lisp."
452 (declare (ignore p))
453 (with-input-from-region (stream (current-region))
454 (clear-echo-area)
455 (write-string "Evaluating region in the editor ..." *echo-area-stream*)
456 (finish-output *echo-area-stream*)
457 (in-lisp
458 (do ((object (read stream nil lispbuf-eof)
459 (read stream nil lispbuf-eof)))
460 ((eq object lispbuf-eof))
461 (eval object)))
462 (message "Evaluation complete.")))
463
464 (defcommand "Editor Re-evaluate Defvar" (p)
465 "Evaluate the current or next top-level form if it is a DEFVAR. Treat the
466 form as if the variable is not bound. This occurs in the editor Lisp."
467 "Evaluate the current or next top-level form if it is a DEFVAR. Treat the
468 form as if the variable is not bound. This occurs in the editor Lisp."
469 (declare (ignore p))
470 (with-input-from-region (stream (defun-region (current-point)))
471 (clear-echo-area)
472 (in-lisp
473 (let ((form (read stream)))
474 (unless (eq (car form) 'defvar) (editor-error "Not a DEFVAR."))
475 (makunbound (cadr form))
476 (message "Evaluation returned ~S" (eval form))))))
477
478 (defcommand "Editor Macroexpand Expression" (p)
479 "Show the macroexpansion of the current expression in the null environment.
480 With an argument, use MACROEXPAND instead of MACROEXPAND-1."
481 "Show the macroexpansion of the current expression in the null environment.
482 With an argument, use MACROEXPAND instead of MACROEXPAND-1."
483 (let ((point (buffer-point (current-buffer))))
484 (with-mark ((start point))
485 (pre-command-parse-check start)
486 (with-mark ((end start))
487 (unless (form-offset end 1) (editor-error))
488 (in-lisp
489 (with-pop-up-display (rts)
490 (write-string (with-input-from-region (s (region start end))
491 (prin1-to-string (funcall (if p
492 'macroexpand
493 'macroexpand-1)
494 (read s))))
495 rts)))))))
496
497 (defcommand "Editor Evaluate Expression" (p)
498 "Prompt for an expression to evaluate in the editor Lisp."
499 "Prompt for an expression to evaluate in the editor Lisp."
500 (declare (ignore p))
501 (in-lisp
502 (multiple-value-call #'message "=> ~@{~#[~;~S~:;~S, ~]~}"
503 (eval (prompt-for-expression
504 :prompt "Editor Eval: "
505 :help "Expression to evaluate")))))
506
507 (defcommand "Editor Evaluate Buffer" (p)
508 "Evaluates the text in the current buffer in the editor Lisp."
509 "Evaluates the text in the current buffer redirecting *Standard-Output* to
510 the echo area. This occurs in the editor Lisp. The prefix argument is
511 ignored."
512 (declare (ignore p))
513 (clear-echo-area)
514 (write-string "Evaluating buffer in the editor ..." *echo-area-stream*)
515 (finish-output *echo-area-stream*)
516 (with-input-from-region (stream (buffer-region (current-buffer)))
517 (let ((*standard-output* *echo-area-stream*))
518 (in-lisp
519 (do ((object (read stream nil lispbuf-eof)
520 (read stream nil lispbuf-eof)))
521 ((eq object lispbuf-eof))
522 (eval object))))
523 (message "Evaluation complete.")))
524
525
526
527 ;;; With-Output-To-Window -- Internal
528 ;;;
529 ;;;
530 (defmacro with-output-to-window ((stream name) &body forms)
531 "With-Output-To-Window (Stream Name) {Form}*
532 Bind Stream to a stream that writes into the buffer named Name a la
533 With-Output-To-Mark. The buffer is created if it does not exist already
534 and a window is created to display the buffer if it is not displayed.
535 For the duration of the evaluation this window is made the current window."
536 (let ((nam (gensym)) (buffer (gensym)) (point (gensym))
537 (window (gensym)) (old-window (gensym)))
538 `(let* ((,nam ,name)
539 (,buffer (or (getstring ,nam *buffer-names*) (make-buffer ,nam)))
540 (,point (buffer-end (buffer-point ,buffer)))
541 (,window (or (car (buffer-windows ,buffer)) (make-window ,point)))
542 (,old-window (current-window)))
543 (unwind-protect
544 (progn (setf (current-window) ,window)
545 (buffer-end ,point)
546 (with-output-to-mark (,stream ,point) ,@forms))
547 (setf (current-window) ,old-window)))))
548
549 (defcommand "Editor Compile File" (p)
550 "Prompts for file to compile in the editor Lisp. Does not compare source
551 and binary write dates. Does not check any buffer for that file for
552 whether the buffer needs to be saved."
553 "Prompts for file to compile."
554 (declare (ignore p))
555 (let ((pn (prompt-for-file :default
556 (buffer-default-pathname (current-buffer))
557 :prompt "File to compile: ")))
558 (with-output-to-window (*error-output* "Compiler Warnings")
559 (in-lisp (compile-file (namestring pn) :error-file nil)))))
560
561 (defcommand "Editor Compile Buffer File" (p)
562 "Compile the file in the current buffer in the editor Lisp if its associated
563 binary file (of type .fasl) is older than the source or doesn't exist. When
564 the binary file is up to date, the user is asked if the source should be
565 compiled anyway. When the prefix argument is supplied, compile the file
566 without checking the binary file. When \"Compile Buffer File Confirm\" is
567 set, this command will ask for confirmation when it otherwise would not."
568 "Compile the file in the current buffer in the editor Lisp if the fasl file
569 isn't up to date. When p, always do it."
570 (let* ((buf (current-buffer))
571 (pn (buffer-pathname buf)))
572 (unless pn (editor-error "Buffer has no associated pathname."))
573 (cond ((buffer-modified buf)
574 (when (or (not (value compile-buffer-file-confirm))
575 (prompt-for-y-or-n
576 :default t :default-string "Y"
577 :prompt (list "Save and compile file ~A? "
578 (namestring pn))))
579 (write-buffer-file buf pn)
580 (with-output-to-window (*error-output* "Compiler Warnings")
581 (in-lisp (compile-file (namestring pn) :error-file nil)))))
582 ((older-or-non-existent-fasl-p pn p)
583 (when (or (not (value compile-buffer-file-confirm))
584 (prompt-for-y-or-n
585 :default t :default-string "Y"
586 :prompt (list "Compile file ~A? " (namestring pn))))
587 (with-output-to-window (*error-output* "Compiler Warnings")
588 (in-lisp (compile-file (namestring pn) :error-file nil)))))
589 (t (when (or p
590 (prompt-for-y-or-n
591 :default t :default-string "Y"
592 :prompt
593 "Fasl file up to date, compile source anyway? "))
594 (with-output-to-window (*error-output* "Compiler Warnings")
595 (in-lisp (compile-file (namestring pn) :error-file nil))))))))
596
597 (defcommand "Editor Compile Group" (p)
598 "Compile each file in the current group which needs it in the editor Lisp.
599 If a file has type LISP and there is a curresponding file with type
600 FASL which has been written less recently (or it doesn't exit), then
601 the file is compiled, with error output directed to the \"Compiler Warnings\"
602 buffer. If a prefix argument is provided, then all the files are compiled.
603 All modified files are saved beforehand."
604 "Do a Compile-File in each file in the current group that seems to need it
605 in the editor Lisp."
606 (save-all-files-command ())
607 (unless *active-file-group* (editor-error "No active file group."))
608 (dolist (file *active-file-group*)
609 (when (string-equal (pathname-type file) "lisp")
610 (let ((tn (probe-file file)))
611 (cond ((not tn)
612 (message "File ~A not found." (namestring file)))
613 ((older-or-non-existent-fasl-p tn p)
614 (with-output-to-window (*error-output* "Compiler Warnings")
615 (in-lisp (compile-file (namestring tn) :error-file nil)))))))))
616
617 (defcommand "List Compile Group" (p)
618 "List any files that would be compiled by \"Compile Group\". All Modified
619 files are saved before checking to generate a consistent list."
620 "Do a Compile-File in each file in the current group that seems to need it."
621 (declare (ignore p))
622 (save-all-files-command ())
623 (unless *active-file-group* (editor-error "No active file group."))
624 (with-pop-up-display (s)
625 (write-line "\"Compile Group\" would compile the following files:" s)
626 (force-output s)
627 (dolist (file *active-file-group*)
628 (when (string-equal (pathname-type file) "lisp")
629 (let ((tn (probe-file file)))
630 (cond ((not tn)
631 (format s "File ~A not found.~%" (namestring file)))
632 ((older-or-non-existent-fasl-p tn)
633 (write-line (namestring tn) s)))
634 (force-output s))))))
635
636 (defhvar "Load Pathname Defaults"
637 "The default pathname used by the load command.")
638
639 (defcommand "Editor Load File" (p)
640 "Prompt for a file to load into Editor Lisp."
641 "Prompt for a file to load into the Editor Lisp."
642 (declare (ignore p))
643 (let ((name (truename (prompt-for-file
644 :default
645 (or (value load-pathname-defaults)
646 (buffer-default-pathname (current-buffer)))
647 :prompt "Editor file to load: "
648 :help "The name of the file to load"))))
649 (setv load-pathname-defaults name)
650 (in-lisp (load name))))
651
652
653
654 ;;;; Lisp documentation stuff.
655
656 ;;; FUNCTION-TO-DESCRIBE is used in "Editor Describe Function Call" and
657 ;;; "Describe Function Call".
658 ;;;
659 (defmacro function-to-describe (var error-name)
660 `(cond ((not (symbolp ,var))
661 (,error-name "~S is not a symbol." ,var))
662 ((macro-function ,var))
663 ((fboundp ,var)
664 (if (listp (symbol-function ,var))
665 ,var
666 (symbol-function ,var)))
667 (t
668 (,error-name "~S is not a function." ,var))))
669
670 (defcommand "Editor Describe Function Call" (p)
671 "Describe the most recently typed function name in the editor Lisp."
672 "Describe the most recently typed function name in the editor Lisp."
673 (declare (ignore p))
674 (with-mark ((mark1 (current-point))
675 (mark2 (current-point)))
676 (pre-command-parse-check mark1)
677 (unless (backward-up-list mark1) (editor-error))
678 (form-offset (move-mark mark2 (mark-after mark1)) 1)
679 (with-input-from-region (s (region mark1 mark2))
680 (in-lisp
681 (let* ((sym (read s))
682 (fun (function-to-describe sym editor-error)))
683 (with-pop-up-display (*standard-output*)
684 (editor-describe-function fun sym)))))))
685
686
687 (defcommand "Editor Describe Symbol" (p)
688 "Describe the previous s-expression if it is a symbol in the editor Lisp."
689 "Describe the previous s-expression if it is a symbol in the editor Lisp."
690 (declare (ignore p))
691 (with-mark ((mark1 (current-point))
692 (mark2 (current-point)))
693 (mark-symbol mark1 mark2)
694 (with-input-from-region (s (region mark1 mark2))
695 (in-lisp
696 (let ((thing (read s)))
697 (if (symbolp thing)
698 (with-pop-up-display (*standard-output*)
699 (describe thing))
700 (if (and (consp thing)
701 (or (eq (car thing) 'quote)
702 (eq (car thing) 'function))
703 (symbolp (cadr thing)))
704 (with-pop-up-display (*standard-output*)
705 (describe (cadr thing)))
706 (editor-error "~S is not a symbol, or 'symbol, or #'symbol."
707 thing))))))))
708
709 ;;; MARK-SYMBOL moves mark1 and mark2 around the previous or current symbol.
710 ;;; However, if the marks are immediately before the first constituent char
711 ;;; of the symbol name, we use the next symbol since the marks probably
712 ;;; correspond to the point, and Hemlock's cursor display makes it look like
713 ;;; the point is within the symbol name. This also tries to ignore :prefix
714 ;;; characters such as quotes, commas, etc.
715 ;;;
716 (defun mark-symbol (mark1 mark2)
717 (pre-command-parse-check mark1)
718 (with-mark ((tmark1 mark1)
719 (tmark2 mark1))
720 (cond ((and (form-offset tmark1 1)
721 (form-offset (move-mark tmark2 tmark1) -1)
722 (or (mark= mark1 tmark2)
723 (and (find-attribute tmark2 :lisp-syntax
724 #'(lambda (x) (not (eq x :prefix))))
725 (mark= mark1 tmark2))))
726 (form-offset mark2 1))
727 (t
728 (form-offset mark1 -1)
729 (find-attribute mark1 :lisp-syntax
730 #'(lambda (x) (not (eq x :prefix))))
731 (form-offset (move-mark mark2 mark1) 1)))))
732
733
734 (defcommand "Editor Describe" (p)
735 "Call Describe on a Lisp object.
736 Prompt for an expression which is evaluated to yield the object."
737 "Prompt for an object to describe."
738 (declare (ignore p))
739 (in-lisp
740 (let* ((exp (prompt-for-expression
741 :prompt "Object: "
742 :help "Expression to evaluate to get object to describe."))
743 (obj (eval exp)))
744 (with-pop-up-display (*standard-output*)
745 (describe obj)))))
746
747 (defcommand "Filter Region" (p)
748 "Apply a Lisp function to each line of the region.
749 An expression is prompted for which should evaluate to a Lisp function
750 from a string to a string. The function must neither modify its argument
751 nor modify the return value after it is returned."
752 "Call prompt for a function, then call Filter-Region with it and the region."
753 (declare (ignore p))
754 (let* ((exp (prompt-for-expression
755 :prompt "Function: "
756 :help "Expression to evaluate to get function to use as filter."))
757 (fun (in-lisp (eval exp)))
758 (region (current-region)))
759 (check-region-query-size region)
760 (let* ((start (copy-mark (region-start region) :left-inserting))
761 (end (copy-mark (region-end region) :left-inserting))
762 (region (region start end))
763 (undo-region (copy-region region)))
764 (filter-region fun region)
765 (make-region-undo :twiddle "Filter Region" region undo-region))))

  ViewVC Help
Powered by ViewVC 1.1.5