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

Contents of /src/hemlock/lispbuf.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed May 9 13:04:57 1990 UTC (23 years, 11 months ago) by ram
Branch: MAIN
Initial revision
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 ((and (characterp thing) (string-char-p 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 (declare (simple-string current))
309 (when (or (mark< point mark) (zerop length)) (editor-error))
310 (cond
311 ((eq (last-command-type) :interactive-history)
312 (let ((base (mod (+ (value interactive-pointer) p) length)))
313 (delete-region (region mark point))
314 (insert-region point (ring-ref ring base))
315 (setf (value interactive-pointer) base)))
316 (t
317 (let ((base (mod (if (minusp p) p (1- p)) length))
318 (region (delete-and-save-region (region mark point))))
319 (insert-region point (ring-ref ring base))
320 (when (mark/= (region-start region) (region-end region))
321 (ring-push region ring)
322 (incf base))
323 (setf (value interactive-pointer) base)))))
324 (setf (last-command-type) :interactive-history))
325
326 (defcommand "Next Interactive Input" (p)
327 "Rotate the interactive history backwards. The region is left around the
328 inserted text. With prefix argument, rotate that many times."
329 "Call previous-interactive-input-command with negated arg."
330 (previous-interactive-input-command (- (or p 1))))
331
332 (defcommand "Kill Interactive Input" (p)
333 "Kill any input to an interactive mode (Eval or Typescript)."
334 "Kill any input to an interactive mode (Eval or Typescript)."
335 (declare (ignore p))
336 (let ((point (buffer-point (current-buffer)))
337 (mark (value buffer-input-mark)))
338 (when (mark< point mark) (editor-error))
339 (kill-region (region mark point) :kill-backward)))
340
341 (defcommand "Interactive Beginning of Line" (p)
342 "If on line with current prompt, go to after it, otherwise do what
343 \"Beginning of Line\" always does."
344 "Go to after prompt when on prompt line."
345 (let ((mark (value buffer-input-mark))
346 (point (current-point)))
347 (if (and (same-line-p point mark) (or (not p) (= p 1)))
348 (move-mark point mark)
349 (beginning-of-line-command p))))
350
351 (defcommand "Reenter Interactive Input" (p)
352 "Copies the form to the left of point to be after the interactive buffer's
353 input mark. When the current region is active, it is copied instead."
354 "Copies the form to the left of point to be after the interactive buffer's
355 input mark. When the current region is active, it is copied instead."
356 (declare (ignore p))
357 (unless (hemlock-bound-p 'buffer-input-mark)
358 (editor-error "Not in an interactive buffer."))
359 (let ((point (current-point)))
360 (let ((region (if (region-active-p)
361 ;; Copy this, so moving point doesn't affect the region.
362 (copy-region (current-region))
363 (with-mark ((start point)
364 (end point))
365 (pre-command-parse-check start)
366 (unless (form-offset start -1)
367 (editor-error "Not after complete form."))
368 (region (copy-mark start) (copy-mark end))))))
369 (buffer-end point)
370 (push-buffer-mark (copy-mark point))
371 (insert-region point region)
372 (setf (last-command-type) :ephemerally-active))))
373
374
375
376 ;;; Other stuff.
377
378 (defmode "Editor")
379
380 (defcommand "Editor Mode" (p)
381 "Turn on \"Editor\" mode in the current buffer. If it is already on, turn it
382 off. When in editor mode, most lisp compilation and evaluation commands
383 manipulate the editor process instead of the current eval server."
384 "Toggle \"Editor\" mode in the current buffer."
385 (declare (ignore p))
386 (setf (buffer-minor-mode (current-buffer) "Editor")
387 (not (buffer-minor-mode (current-buffer) "Editor"))))
388
389 (define-file-option "Editor" (buffer value)
390 (declare (ignore value))
391 (setf (buffer-minor-mode buffer "Editor") t))
392
393 (defhvar "Editor Definition Info"
394 "When this is non-nil, the editor Lisp is used to determine definition
395 editing information; otherwise, the slave Lisp is used."
396 :value t
397 :mode "Editor")
398
399 (defcommand "Editor Compile Defun" (p)
400 "Compiles the current or next top-level form in the editor Lisp.
401 First the form is evaluated, then the result of this evaluation
402 is passed to compile. If the current region is active, this
403 compiles the region."
404 "Evaluates the current or next top-level form in the editor Lisp."
405 (declare (ignore p))
406 (if (region-active-p)
407 (editor-compile-region (current-region))
408 (editor-compile-region (defun-region (current-point)) t)))
409
410 (defcommand "Editor Compile Region" (p)
411 "Compiles lisp forms between the point and the mark in the editor Lisp."
412 "Compiles lisp forms between the point and the mark in the editor Lisp."
413 (declare (ignore p))
414 (editor-compile-region (current-region)))
415
416 (defun defun-region (mark)
417 "This returns a region around the current or next defun with respect to mark.
418 Mark is not used to form the region. If there is no appropriate top level
419 form, this signals an editor-error. This calls PRE-COMMAND-PARSE-CHECK."
420 (with-mark ((start mark)
421 (end mark))
422 (pre-command-parse-check start)
423 (cond ((not (mark-top-level-form start end))
424 (editor-error "No current or next top level form."))
425 (t (region start end)))))
426
427 (defun editor-compile-region (region &optional quiet)
428 (unless quiet (message "Compiling region ..."))
429 (in-lisp
430 (with-input-from-region (stream region)
431 (with-pop-up-display (*error-output* :height 19)
432 (compile-from-stream stream
433 :defined-from-pathname
434 (buffer-pathname (current-buffer)))))))
435
436
437 (defcommand "Editor Evaluate Defun" (p)
438 "Evaluates the current or next top-level form in the editor Lisp.
439 If the current region is active, this evaluates the region."
440 "Evaluates the current or next top-level form in the editor Lisp."
441 (declare (ignore p))
442 (if (region-active-p)
443 (editor-evaluate-region-command nil)
444 (with-input-from-region (stream (defun-region (current-point)))
445 (clear-echo-area)
446 (in-lisp
447 (message "Editor Evaluation returned ~S"
448 (eval (read stream)))))))
449
450 (defcommand "Editor Evaluate Region" (p)
451 "Evaluates lisp forms between the point and the mark in the editor Lisp."
452 "Evaluates lisp forms between the point and the mark in the editor Lisp."
453 (declare (ignore p))
454 (with-input-from-region (stream (current-region))
455 (clear-echo-area)
456 (write-string "Evaluating region in the editor ..." *echo-area-stream*)
457 (finish-output *echo-area-stream*)
458 (in-lisp
459 (do ((object (read stream nil lispbuf-eof)
460 (read stream nil lispbuf-eof)))
461 ((eq object lispbuf-eof))
462 (eval object)))
463 (message "Evaluation complete.")))
464
465 (defcommand "Editor Re-evaluate Defvar" (p)
466 "Evaluate the current or next top-level form if it is a DEFVAR. Treat the
467 form as if the variable is not bound. This occurs in the editor Lisp."
468 "Evaluate the current or next top-level form if it is a DEFVAR. Treat the
469 form as if the variable is not bound. This occurs in the editor Lisp."
470 (declare (ignore p))
471 (with-input-from-region (stream (defun-region (current-point)))
472 (clear-echo-area)
473 (in-lisp
474 (let ((form (read stream)))
475 (unless (eq (car form) 'defvar) (editor-error "Not a DEFVAR."))
476 (makunbound (cadr form))
477 (message "Evaluation returned ~S" (eval form))))))
478
479 (defcommand "Editor Macroexpand Expression" (p)
480 "Show the macroexpansion of the current expression in the null environment.
481 With an argument, use MACROEXPAND instead of MACROEXPAND-1."
482 "Show the macroexpansion of the current expression in the null environment.
483 With an argument, use MACROEXPAND instead of MACROEXPAND-1."
484 (let ((point (buffer-point (current-buffer))))
485 (with-mark ((start point))
486 (pre-command-parse-check start)
487 (with-mark ((end start))
488 (unless (form-offset end 1) (editor-error))
489 (in-lisp
490 (with-pop-up-display (rts)
491 (write-string (with-input-from-region (s (region start end))
492 (prin1-to-string (funcall (if p
493 'macroexpand
494 'macroexpand-1)
495 (read s))))
496 rts)))))))
497
498 (defcommand "Editor Evaluate Expression" (p)
499 "Prompt for an expression to evaluate in the editor Lisp."
500 "Prompt for an expression to evaluate in the editor Lisp."
501 (declare (ignore p))
502 (in-lisp
503 (multiple-value-call #'message "=> ~@{~#[~;~S~:;~S, ~]~}"
504 (eval (prompt-for-expression
505 :prompt "Editor Eval: "
506 :help "Expression to evaluate")))))
507
508 (defcommand "Editor Evaluate Buffer" (p)
509 "Evaluates the text in the current buffer in the editor Lisp."
510 "Evaluates the text in the current buffer redirecting *Standard-Output* to
511 the echo area. This occurs in the editor Lisp. The prefix argument is
512 ignored."
513 (declare (ignore p))
514 (clear-echo-area)
515 (write-string "Evaluating buffer in the editor ..." *echo-area-stream*)
516 (finish-output *echo-area-stream*)
517 (with-input-from-region (stream (buffer-region (current-buffer)))
518 (let ((*standard-output* *echo-area-stream*))
519 (in-lisp
520 (do ((object (read stream nil lispbuf-eof)
521 (read stream nil lispbuf-eof)))
522 ((eq object lispbuf-eof))
523 (eval object))))
524 (message "Evaluation complete.")))
525
526
527
528 ;;; With-Output-To-Window -- Internal
529 ;;;
530 ;;;
531 (defmacro with-output-to-window ((stream name) &body forms)
532 "With-Output-To-Window (Stream Name) {Form}*
533 Bind Stream to a stream that writes into the buffer named Name a la
534 With-Output-To-Mark. The buffer is created if it does not exist already
535 and a window is created to display the buffer if it is not displayed.
536 For the duration of the evaluation this window is made the current window."
537 (let ((nam (gensym)) (buffer (gensym)) (point (gensym))
538 (window (gensym)) (old-window (gensym)))
539 `(let* ((,nam ,name)
540 (,buffer (or (getstring ,nam *buffer-names*) (make-buffer ,nam)))
541 (,point (buffer-end (buffer-point ,buffer)))
542 (,window (or (car (buffer-windows ,buffer)) (make-window ,point)))
543 (,old-window (current-window)))
544 (unwind-protect
545 (progn (setf (current-window) ,window)
546 (buffer-end ,point)
547 (with-output-to-mark (,stream ,point) ,@forms))
548 (setf (current-window) ,old-window)))))
549
550 (defcommand "Editor Compile File" (p)
551 "Prompts for file to compile in the editor Lisp. Does not compare source
552 and binary write dates. Does not check any buffer for that file for
553 whether the buffer needs to be saved."
554 "Prompts for file to compile."
555 (declare (ignore p))
556 (let ((pn (prompt-for-file :default
557 (buffer-default-pathname (current-buffer))
558 :prompt "File to compile: ")))
559 (with-output-to-window (*error-output* "Compiler Warnings")
560 (in-lisp (compile-file (namestring pn) :error-file nil)))))
561
562 (defcommand "Editor Compile Buffer File" (p)
563 "Compile the file in the current buffer in the editor Lisp if its associated
564 binary file (of type .fasl) is older than the source or doesn't exist. When
565 the binary file is up to date, the user is asked if the source should be
566 compiled anyway. When the prefix argument is supplied, compile the file
567 without checking the binary file. When \"Compile Buffer File Confirm\" is
568 set, this command will ask for confirmation when it otherwise would not."
569 "Compile the file in the current buffer in the editor Lisp if the fasl file
570 isn't up to date. When p, always do it."
571 (let* ((buf (current-buffer))
572 (pn (buffer-pathname buf)))
573 (unless pn (editor-error "Buffer has no associated pathname."))
574 (cond ((buffer-modified buf)
575 (when (or (not (value compile-buffer-file-confirm))
576 (prompt-for-y-or-n
577 :default t :default-string "Y"
578 :prompt (list "Save and compile file ~A? "
579 (namestring pn))))
580 (write-buffer-file buf pn)
581 (with-output-to-window (*error-output* "Compiler Warnings")
582 (in-lisp (compile-file (namestring pn) :error-file nil)))))
583 ((older-or-non-existent-fasl-p pn p)
584 (when (or (not (value compile-buffer-file-confirm))
585 (prompt-for-y-or-n
586 :default t :default-string "Y"
587 :prompt (list "Compile file ~A? " (namestring pn))))
588 (with-output-to-window (*error-output* "Compiler Warnings")
589 (in-lisp (compile-file (namestring pn) :error-file nil)))))
590 (t (when (or p
591 (prompt-for-y-or-n
592 :default t :default-string "Y"
593 :prompt
594 "Fasl file up to date, compile source anyway? "))
595 (with-output-to-window (*error-output* "Compiler Warnings")
596 (in-lisp (compile-file (namestring pn) :error-file nil))))))))
597
598 (defcommand "Editor Compile Group" (p)
599 "Compile each file in the current group which needs it in the editor Lisp.
600 If a file has type LISP and there is a curresponding file with type
601 FASL which has been written less recently (or it doesn't exit), then
602 the file is compiled, with error output directed to the \"Compiler Warnings\"
603 buffer. If a prefix argument is provided, then all the files are compiled.
604 All modified files are saved beforehand."
605 "Do a Compile-File in each file in the current group that seems to need it
606 in the editor Lisp."
607 (save-all-files-command ())
608 (unless *active-file-group* (editor-error "No active file group."))
609 (dolist (file *active-file-group*)
610 (when (string-equal (pathname-type file) "lisp")
611 (let ((tn (probe-file file)))
612 (cond ((not tn)
613 (message "File ~A not found." (namestring file)))
614 ((older-or-non-existent-fasl-p tn p)
615 (with-output-to-window (*error-output* "Compiler Warnings")
616 (in-lisp (compile-file (namestring tn) :error-file nil)))))))))
617
618 (defcommand "List Compile Group" (p)
619 "List any files that would be compiled by \"Compile Group\". All Modified
620 files are saved before checking to generate a consistent list."
621 "Do a Compile-File in each file in the current group that seems to need it."
622 (declare (ignore p))
623 (save-all-files-command ())
624 (unless *active-file-group* (editor-error "No active file group."))
625 (with-pop-up-display (s)
626 (write-line "\"Compile Group\" would compile the following files:" s)
627 (force-output s)
628 (dolist (file *active-file-group*)
629 (when (string-equal (pathname-type file) "lisp")
630 (let ((tn (probe-file file)))
631 (cond ((not tn)
632 (format s "File ~A not found.~%" (namestring file)))
633 ((older-or-non-existent-fasl-p tn)
634 (write-line (namestring tn) s)))
635 (force-output s))))))
636
637 (defhvar "Load Pathname Defaults"
638 "The default pathname used by the load command.")
639
640 (defcommand "Editor Load File" (p)
641 "Prompt for a file to load into Editor Lisp."
642 "Prompt for a file to load into the Editor Lisp."
643 (declare (ignore p))
644 (let ((name (truename (prompt-for-file
645 :default
646 (or (value load-pathname-defaults)
647 (buffer-default-pathname (current-buffer)))
648 :prompt "Editor file to load: "
649 :help "The name of the file to load"))))
650 (setv load-pathname-defaults name)
651 (in-lisp (load name))))
652
653
654
655 ;;;; Lisp documentation stuff.
656
657 ;;; FUNCTION-TO-DESCRIBE is used in "Editor Describe Function Call" and
658 ;;; "Describe Function Call".
659 ;;;
660 (defmacro function-to-describe (var error-name)
661 `(cond ((not (symbolp ,var))
662 (,error-name "~S is not a symbol." ,var))
663 ((macro-function ,var))
664 ((fboundp ,var)
665 (if (listp (symbol-function ,var))
666 ,var
667 (symbol-function ,var)))
668 (t
669 (,error-name "~S is not a function." ,var))))
670
671 (defcommand "Editor Describe Function Call" (p)
672 "Describe the most recently typed function name in the editor Lisp."
673 "Describe the most recently typed function name in the editor Lisp."
674 (declare (ignore p))
675 (with-mark ((mark1 (current-point))
676 (mark2 (current-point)))
677 (pre-command-parse-check mark1)
678 (unless (backward-up-list mark1) (editor-error))
679 (form-offset (move-mark mark2 (mark-after mark1)) 1)
680 (with-input-from-region (s (region mark1 mark2))
681 (in-lisp
682 (let* ((sym (read s))
683 (fun (function-to-describe sym editor-error)))
684 (with-pop-up-display (*standard-output*)
685 (editor-describe-function fun sym)))))))
686
687
688 (defcommand "Editor Describe Symbol" (p)
689 "Describe the previous s-expression if it is a symbol in the editor Lisp."
690 "Describe the previous s-expression if it is a symbol in the editor Lisp."
691 (declare (ignore p))
692 (with-mark ((mark1 (current-point))
693 (mark2 (current-point)))
694 (mark-symbol mark1 mark2)
695 (with-input-from-region (s (region mark1 mark2))
696 (in-lisp
697 (let ((thing (read s)))
698 (if (symbolp thing)
699 (with-pop-up-display (*standard-output*)
700 (describe thing))
701 (if (and (consp thing)
702 (or (eq (car thing) 'quote)
703 (eq (car thing) 'function))
704 (symbolp (cadr thing)))
705 (with-pop-up-display (*standard-output*)
706 (describe (cadr thing)))
707 (editor-error "~S is not a symbol, or 'symbol, or #'symbol."
708 thing))))))))
709
710 ;;; MARK-SYMBOL moves mark1 and mark2 around the previous or current symbol.
711 ;;; However, if the marks are immediately before the first constituent char
712 ;;; of the symbol name, we use the next symbol since the marks probably
713 ;;; correspond to the point, and Hemlock's cursor display makes it look like
714 ;;; the point is within the symbol name. This also tries to ignore :prefix
715 ;;; characters such as quotes, commas, etc.
716 ;;;
717 (defun mark-symbol (mark1 mark2)
718 (pre-command-parse-check mark1)
719 (with-mark ((tmark1 mark1)
720 (tmark2 mark1))
721 (cond ((and (form-offset tmark1 1)
722 (form-offset (move-mark tmark2 tmark1) -1)
723 (or (mark= mark1 tmark2)
724 (and (find-attribute tmark2 :lisp-syntax
725 #'(lambda (x) (not (eq x :prefix))))
726 (mark= mark1 tmark2))))
727 (form-offset mark2 1))
728 (t
729 (form-offset mark1 -1)
730 (find-attribute mark1 :lisp-syntax
731 #'(lambda (x) (not (eq x :prefix))))
732 (form-offset (move-mark mark2 mark1) 1)))))
733
734
735 (defcommand "Editor Describe" (p)
736 "Call Describe on a Lisp object.
737 Prompt for an expression which is evaluated to yield the object."
738 "Prompt for an object to describe."
739 (declare (ignore p))
740 (in-lisp
741 (let* ((exp (prompt-for-expression
742 :prompt "Object: "
743 :help "Expression to evaluate to get object to describe."))
744 (obj (eval exp)))
745 (with-pop-up-display (*standard-output*)
746 (describe obj)))))
747
748 (defcommand "Filter Region" (p)
749 "Apply a Lisp function to each line of the region.
750 An expression is prompted for which should evaluate to a Lisp function
751 from a string to a string. The function must neither modify its argument
752 nor modify the return value after it is returned."
753 "Call prompt for a function, then call Filter-Region with it and the region."
754 (declare (ignore p))
755 (let* ((exp (prompt-for-expression
756 :prompt "Function: "
757 :help "Expression to evaluate to get function to use as filter."))
758 (fun (in-lisp (eval exp)))
759 (region (current-region)))
760 (check-region-query-size region)
761 (let* ((start (copy-mark (region-start region) :left-inserting))
762 (end (copy-mark (region-end region) :left-inserting))
763 (region (region start end))
764 (undo-region (copy-region region)))
765 (filter-region fun region)
766 (make-region-undo :twiddle "Filter Region" region undo-region))))

  ViewVC Help
Powered by ViewVC 1.1.5