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

Contents of /src/hemlock/lispbuf.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Mon Oct 31 04:50:12 1994 UTC (19 years, 5 months ago) by ram
Branch: MAIN
CVS Tags: RELEASE_18a, RELEASE_18b, RELEASE_18c
Branch point for: RELENG_18
Changes since 1.2: +1 -3 lines
Fix headed boilerplate.
1 ram 1.1 ;;; -*- Log: hemlock.log; Package: Hemlock -*-
2     ;;;
3     ;;; **********************************************************************
4 ram 1.2 ;;; 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     ;;;
7     (ext:file-comment
8 ram 1.3 "$Header: /tiger/var/lib/cvsroots/cmucl/src/hemlock/lispbuf.lisp,v 1.3 1994/10/31 04:50:12 ram Exp $")
9 ram 1.2 ;;;
10 ram 1.1 ;;; **********************************************************************
11     ;;;
12     ;;; Stuff to do a little lisp hacking in the editor's Lisp environment.
13     ;;;
14    
15     (in-package "HEMLOCK")
16    
17    
18     (defmacro in-lisp (&body body)
19     "Evaluates body inside HANDLE-LISP-ERRORS. *package* is bound to the package
20     named by \"Current Package\" if it is non-nil."
21     (let ((name (gensym)) (package (gensym)))
22     `(handle-lisp-errors
23     (let* ((,name (value current-package))
24     (,package (and ,name (find-package ,name))))
25     (progv (if ,package '(*package*)) (if ,package (list ,package))
26     ,@body)))))
27    
28    
29     (define-file-option "Package" (buffer value)
30     (defhvar "Current Package"
31     "The package used for evaluation of Lisp in this buffer."
32     :buffer buffer
33     :value
34     (let* ((eof (list nil))
35     (thing (read-from-string value nil eof)))
36     (when (eq thing eof) (error "Bad package file option value."))
37     (cond
38     ((stringp thing)
39     thing)
40     ((symbolp thing)
41     (symbol-name thing))
42 ram 1.2 ((characterp thing)
43 ram 1.1 (string thing))
44     (t
45     (message
46     "Ignoring \"package\" file option -- cannot convert to a string."))))))
47    
48    
49     ;;;; Eval Mode Interaction.
50    
51     (proclaim '(special * ** *** - + ++ +++ / // /// *prompt*))
52    
53     (defun setup-eval-mode (buffer)
54     (let ((point (buffer-point buffer)))
55     (setf (buffer-minor-mode buffer "Eval") t)
56     (setf (buffer-minor-mode buffer "Editor") t)
57     (setf (buffer-major-mode buffer) "Lisp")
58     (buffer-end point)
59     (defhvar "Current Package"
60     "This variable holds the name of the package currently used for Lisp
61     evaluation and compilation. If it is Nil, the value of *Package* is used
62     instead."
63     :value nil
64     :buffer buffer)
65     (unless (hemlock-bound-p 'buffer-input-mark :buffer buffer)
66     (defhvar "Buffer Input Mark"
67     "Mark used for Eval Mode input."
68     :buffer buffer
69     :value (copy-mark point :right-inserting))
70     (defhvar "Eval Output Stream"
71     "Output stream used for Eval Mode output in this buffer."
72     :buffer buffer
73     :value (make-hemlock-output-stream point))
74     (defhvar "Interactive History"
75     "A ring of the regions input to an interactive mode (Eval or Typescript)."
76     :buffer buffer
77     :value (make-ring (value interactive-history-length)))
78     (defhvar "Interactive Pointer"
79     "Pointer into \"Interactive History\"."
80     :buffer buffer
81     :value 0)
82     (defhvar "Searching Interactive Pointer"
83     "Pointer into \"Interactive History\"."
84     :buffer buffer
85     :value 0))
86     (let ((*standard-output*
87     (variable-value 'eval-output-stream :buffer buffer)))
88     (fresh-line)
89     (princ (if (functionp *prompt*)
90     (funcall *prompt*)
91     *prompt*)))
92     (move-mark (variable-value 'buffer-input-mark :buffer buffer) point)))
93    
94     (defmode "Eval" :major-p nil :setup-function #'setup-eval-mode)
95    
96     (defun eval-mode-lisp-mode-hook (buffer on)
97     "Turn on Lisp mode when we go into Eval Mode."
98     (when on
99     (setf (buffer-major-mode buffer) "Lisp")))
100     ;;;
101     (add-hook eval-mode-hook 'eval-mode-lisp-mode-hook)
102    
103     (defhvar "Editor Definition Info"
104     "When this is non-nil, the editor Lisp is used to determine definition
105     editing information; otherwise, the slave Lisp is used."
106     :value t
107     :mode "Eval")
108    
109    
110     (defvar *selected-eval-buffer* nil)
111    
112     (defcommand "Select Eval Buffer" (p)
113     "Goto buffer in \"Eval\" mode, creating one if necessary."
114     "Goto buffer in \"Eval\" mode, creating one if necessary."
115     (declare (ignore p))
116     (unless *selected-eval-buffer*
117     (when (getstring "Eval" *buffer-names*)
118     (editor-error "There is already a buffer named \"Eval\"!"))
119     (setf *selected-eval-buffer*
120     (make-buffer "Eval"
121     :delete-hook
122     (list #'(lambda (buf)
123     (declare (ignore buf))
124     (setf *selected-eval-buffer* nil)))))
125     (setf (buffer-minor-mode *selected-eval-buffer* "Eval") t))
126     (change-to-buffer *selected-eval-buffer*))
127    
128    
129     (defvar lispbuf-eof '(nil))
130    
131     (defhvar "Unwedge Interactive Input Confirm"
132     "When set (the default), trying to confirm interactive input when the
133     point is not after the input mark causes Hemlock to ask the user if he
134     needs to be unwedged. When not set, an editor error is signaled
135     informing the user that the point is before the input mark."
136     :value t)
137    
138     (defun unwedge-eval-buffer ()
139     (abort-eval-input-command nil))
140    
141     (defhvar "Unwedge Interactive Input Fun"
142     "Function to call when input is confirmed, but the point is not past the
143     input mark."
144     :value #'unwedge-eval-buffer
145     :mode "Eval")
146    
147     (defhvar "Unwedge Interactive Input String"
148     "String to add to \"Point not past input mark. \" explaining what will
149     happen if the the user chooses to be unwedged."
150     :value "Prompt again at the end of the buffer? "
151     :mode "Eval")
152    
153     (defcommand "Confirm Eval Input" (p)
154     "Evaluate Eval Mode input between point and last prompt."
155     "Evaluate Eval Mode input between point and last prompt."
156     (declare (ignore p))
157     (let ((input-region (get-interactive-input)))
158     (when input-region
159     (let* ((output (value eval-output-stream))
160     (*standard-output* output)
161     (*error-output* output)
162     (*trace-output* output))
163     (fresh-line)
164     (in-lisp
165     ;; Copy the region to keep the output and input streams from interacting
166     ;; since input-region is made of permanent marks into the buffer.
167     (with-input-from-region (stream (copy-region input-region))
168     (loop
169     (let ((form (read stream nil lispbuf-eof)))
170     (when (eq form lispbuf-eof)
171     ;; Move the buffer's input mark to the end of the buffer.
172     (move-mark (region-start input-region)
173     (region-end input-region))
174     (return))
175     (setq +++ ++ ++ + + - - form)
176     (let ((this-eval (multiple-value-list (eval form))))
177     (fresh-line)
178     (dolist (x this-eval) (prin1 x) (terpri))
179     (princ (if (functionp *prompt*)
180     (funcall *prompt*)
181     *prompt*))
182     (setq /// // // / / this-eval)
183     (setq *** ** ** * * (car this-eval)))))))))))
184    
185     (defcommand "Abort Eval Input" (p)
186     "Move to the end of the buffer and prompt."
187     "Move to the end of the buffer and prompt."
188     (declare (ignore p))
189     (let ((point (current-point)))
190     (buffer-end point)
191     (insert-character point #\newline)
192     (insert-string point "Aborted.")
193     (insert-character point #\newline)
194     (insert-string point
195     (if (functionp *prompt*)
196     (funcall *prompt*)
197     *prompt*))
198     (move-mark (value buffer-input-mark) point)))
199    
200    
201    
202     ;;;; General interactive commands used in eval and typescript buffers.
203    
204     (defun get-interactive-input ()
205     "Tries to return a region. When the point is not past the input mark, and
206     the user has \"Unwedge Interactive Input Confirm\" set, the buffer is
207     optionally fixed up, and nil is returned. Otherwise, an editor error is
208     signalled. When a region is returned, the start is the current buffer's
209     input mark, and the end is the current point moved to the end of the buffer."
210     (let ((point (current-point))
211     (mark (value buffer-input-mark)))
212     (cond
213     ((mark>= point mark)
214     (buffer-end point)
215     (let* ((input-region (region mark point))
216     (string (region-to-string input-region))
217     (ring (value interactive-history)))
218     (when (and (or (zerop (ring-length ring))
219     (string/= string (region-to-string (ring-ref ring 0))))
220     (> (length string) (value minimum-interactive-input-length)))
221     (ring-push (copy-region input-region) ring))
222     input-region))
223     ((value unwedge-interactive-input-confirm)
224     (beep)
225     (when (prompt-for-y-or-n
226     :prompt (concatenate 'simple-string
227     "Point not past input mark. "
228     (value unwedge-interactive-input-string))
229     :must-exist t :default t :default-string "yes")
230     (funcall (value unwedge-interactive-input-fun))
231     (message "Unwedged."))
232     nil)
233     (t
234     (editor-error "Point not past input mark.")))))
235    
236     (defhvar "Interactive History Length"
237     "This is the length used for the history ring in interactive buffers.
238     It must be set before turning on the mode."
239     :value 10)
240    
241     (defhvar "Minimum Interactive Input Length"
242     "When the number of characters in an interactive buffer exceeds this value,
243     it is pushed onto the interactive history, otherwise it is lost forever."
244     :value 2)
245    
246    
247     (defvar *previous-input-search-string* "ignore")
248    
249     (defvar *previous-input-search-pattern*
250     ;; Give it a bogus string since you can't give it the empty string.
251     (new-search-pattern :string-insensitive :forward "ignore"))
252    
253     (defun get-previous-input-search-pattern (string)
254     (if (string= *previous-input-search-string* string)
255     *previous-input-search-pattern*
256     (new-search-pattern :string-insensitive :forward
257     (setf *previous-input-search-string* string)
258     *previous-input-search-pattern*)))
259    
260     (defcommand "Search Previous Interactive Input" (p)
261     "Search backward through the interactive history using the current input as
262     a search string. Consecutive invocations repeat the previous search."
263     "Search backward through the interactive history using the current input as
264     a search string. Consecutive invocations repeat the previous search."
265     (declare (ignore p))
266     (let* ((mark (value buffer-input-mark))
267     (ring (value interactive-history))
268     (point (current-point))
269     (just-invoked (eq (last-command-type) :searching-interactive-input)))
270     (when (mark<= point mark)
271     (editor-error "Point not past input mark."))
272     (when (zerop (ring-length ring))
273     (editor-error "No previous input in this buffer."))
274     (unless just-invoked
275     (get-previous-input-search-pattern (region-to-string (region mark point))))
276     (let ((found-it (find-previous-input ring just-invoked)))
277     (unless found-it
278     (editor-error "Couldn't find ~a." *previous-input-search-string*))
279     (delete-region (region mark point))
280     (insert-region point (ring-ref ring found-it))
281     (setf (value searching-interactive-pointer) found-it))
282     (setf (last-command-type) :searching-interactive-input)))
283    
284     (defun find-previous-input (ring againp)
285     (let ((ring-length (ring-length ring))
286     (base (if againp
287     (+ (value searching-interactive-pointer) 1)
288     0)))
289     (loop
290     (when (= base ring-length)
291     (if againp
292     (setf base 0)
293     (return nil)))
294     (with-mark ((m (region-start (ring-ref ring base))))
295     (when (find-pattern m *previous-input-search-pattern*)
296     (return base)))
297     (incf base))))
298    
299     (defcommand "Previous Interactive Input" (p)
300     "Insert the previous input in an interactive mode (Eval or Typescript).
301     If repeated, keep rotating the history. With prefix argument, rotate
302     that many times."
303     "Pop the *interactive-history* at the point."
304     (let* ((point (current-point))
305     (mark (value buffer-input-mark))
306     (ring (value interactive-history))
307     (length (ring-length ring))
308     (p (or p 1)))
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 ram 1.2 (c::compile-from-stream stream
433     :source-info
434     (buffer-pathname (current-buffer)))))))
435 ram 1.1
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