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

  ViewVC Help
Powered by ViewVC 1.1.5