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

Contents of /src/hemlock/main.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (hide annotations)
Sat May 23 00:32:32 1992 UTC (21 years, 11 months ago) by ram
Branch: MAIN
Changes since 1.10: +2 -3 lines
Fixed version hackery.
1 ram 1.1 ;;; -*- Log: hemlock.log; Package: Hemlock-Internals -*-
2     ;;;
3     ;;; **********************************************************************
4 ram 1.3 ;;; 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 ram 1.11 "$Header: /tiger/var/lib/cvsroots/cmucl/src/hemlock/main.lisp,v 1.11 1992/05/23 00:32:32 ram Exp $")
11 ram 1.3 ;;;
12 ram 1.1 ;;; **********************************************************************
13     ;;;
14     ;;; Hemlock initialization code and random debugging stuff.
15     ;;;
16     ;;; Written by Bill Chiles and Rob MacLachlan
17     ;;;
18    
19     (in-package "HEMLOCK-INTERNALS")
20    
21     (export '(*global-variable-names* *mode-names* *buffer-names*
22     *character-attribute-names* *command-names* *buffer-list*
23 ram 1.2 *window-list* *last-key-event-typed* after-editor-initializations))
24 ram 1.1
25    
26     (in-package "EXTENSIONS")
27     (export '(save-all-buffers *hemlock-version*))
28     (in-package "HEMLOCK-INTERNALS")
29    
30    
31    
32     ;;;; Definition of *hemlock-version*.
33    
34 ram 1.10 (defvar *hemlock-version*
35 ram 1.11 (concatenate 'string "3.5 (" lisp::*lisp-implementation-version* ")"))
36 ram 1.1
37    
38    
39     ;;;; %INIT-HEMLOCK.
40    
41 ram 1.10 (defvar *hemlock-initialized* nil)
42    
43 ram 1.1 (defun %init-hemlock ()
44     "Initialize hemlock's internal data structures."
45     ;;
46     ;; This function is defined in Buffer.Lisp. It creates fundamental mode
47     ;; and the buffer main. Until this is done it is not possible to define
48     ;; or use Hemlock variables.
49     (setup-initial-buffer)
50     ;;
51     ;; Define some of the system variables.
52     (define-some-variables)
53     ;;
54     ;; Site initializations such as window system variables.
55     (site-init)
56     ;;
57     ;; Set up syntax table data structures.
58     (%init-syntax-table)
59     ;;
60     ;; Define print representations for funny characters.
61 ram 1.10 (%init-line-image)
62     (setq *hemlock-initialized* t))
63 ram 1.1
64    
65     ;;;; Define some globals.
66    
67     ;;; These globals cannot be defined in the appropriate file due to compilation
68     ;;; or load time constraints.
69     ;;;
70    
71     ;;; The following belong in other files, but those files are loaded before
72     ;;; table.lisp which defines MAKE-STRING-TABLE.
73     ;;;
74     ;;; vars.lisp
75     (defvar *global-variable-names* (make-string-table)
76     "A String Table of global variable names, the values are the symbol names.")
77     ;;;
78     ;;; buffer.lisp
79     (defvar *mode-names* (make-string-table) "A String Table of Mode names.")
80     (defvar *buffer-names* (make-string-table)
81     "A String Table of Buffer names and their corresponding objects.")
82     ;;;
83     ;;; interp.lisp
84     (defvar *command-names* (make-string-table) "String table of command names.")
85     ;;;
86     ;;; syntax.lisp
87     (defvar *character-attribute-names* (make-string-table)
88     "String Table of character attribute names and their corresponding keywords.")
89    
90    
91    
92     ;;;; DEFINE-SOME-VARIABLES.
93    
94     ;;; This is necessary to define "Default Status Line Fields" which belongs
95     ;;; beside the other modeline variables. This DEFVAR would live in
96     ;;; Morecoms.Lisp, but it is compiled and loaded after this file.
97     ;;;
98     (proclaim '(special ed::*recursive-edit-count*))
99     ;;;
100     (make-modeline-field
101     :name :edit-level :width 15
102     :function #'(lambda (buffer window)
103     (declare (ignore buffer window))
104     (if (zerop ed::*recursive-edit-count*)
105     ""
106     (format nil "Edit Level: ~2,'0D "
107     ed::*recursive-edit-count*))))
108    
109     ;;; This is necessary to define "Default Status Line Fields" which belongs
110     ;;; beside the other modeline variables. This DEFVAR would live in
111     ;;; Completion.Lisp, but it is compiled and loaded after this file.
112     ;;;
113     (proclaim '(special ed::*completion-mode-possibility*))
114     ;;; Hack for now until completion mode is added.
115     (defvar ed::*completion-mode-possibility* "")
116     ;;;
117     (make-modeline-field
118     :name :completion :width 40
119     :function #'(lambda (buffer window)
120     (declare (ignore buffer window))
121     ed::*completion-mode-possibility*))
122    
123    
124     (defun define-some-variables ()
125     (defhvar "Default Modes"
126     "This variable contains the default list of modes for new buffers."
127     :value '("Fundamental" "Save"))
128     (defhvar "Echo Area Height"
129     "Number of lines in the echo area window."
130     :value 3)
131     (defhvar "Make Buffer Hook"
132     "This hook is called with the new buffer whenever a buffer is created.")
133     (defhvar "Delete Buffer Hook"
134     "This hook is called with the buffer whenever a buffer is deleted.")
135     (defhvar "Enter Recursive Edit Hook"
136     "This hook is called with the new buffer when a recursive edit is
137     entered.")
138     (defhvar "Exit Recursive Edit Hook"
139     "This hook is called with the value returned when a recursive edit
140     is exited.")
141     (defhvar "Abort Recursive Edit Hook"
142     "This hook is called with the editor-error args when a recursive
143     edit is aborted.")
144     (defhvar "Buffer Major Mode Hook"
145     "This hook is called with the buffer and the new mode when a buffer's
146     major mode is changed.")
147     (defhvar "Buffer Minor Mode Hook"
148     "This hook is called a minor mode is changed. The arguments are
149     the buffer, the mode affected and T or NIL depending on when the
150     mode is being turned on or off.")
151     (defhvar "Buffer Writable Hook"
152     "This hook is called whenever someone sets whether the buffer is
153     writable.")
154     (defhvar "Buffer Name Hook"
155     "This hook is called with the buffer and the new name when the name of a
156     buffer is changed.")
157     (defhvar "Buffer Pathname Hook"
158     "This hook is called with the buffer and the new Pathname when the Pathname
159     associated with the buffer is changed.")
160     (defhvar "Buffer Modified Hook"
161     "This hook is called whenever a buffer changes from unmodified to modified
162     and vice versa. It takes the buffer and the new value for modification
163     flag.")
164     (defhvar "Set Buffer Hook"
165     "This hook is called with the new buffer when the current buffer is set.")
166     (defhvar "After Set Buffer Hook"
167     "This hook is invoked with the old buffer after the current buffer has
168     been changed.")
169     (defhvar "Set Window Hook"
170     "This hook is called with the new window when the current window
171     is set.")
172     (defhvar "Make Window Hook"
173     "This hook is called with a new window when one is created.")
174     (defhvar "Delete Window Hook"
175     "This hook is called with a window before it is deleted.")
176     (defhvar "Window Buffer Hook"
177     "This hook is invoked with the window and new buffer when a window's
178     buffer is changed.")
179     (defhvar "Delete Variable Hook"
180     "This hook is called when a variable is deleted with the args to
181     delete-variable.")
182     (defhvar "Entry Hook"
183     "this hook is called when the editor is entered.")
184     (defhvar "Exit Hook"
185     "This hook is called when the editor is exited.")
186     (defhvar "Redisplay Hook"
187     "This is called on the current window from REDISPLAY after checking the
188     window display start, window image, and recentering. After calling the
189     functions in this hook, we do the above stuff and call the smart
190     redisplay method for the device."
191     :value nil)
192     (defhvar "Key Echo Delay"
193     "Wait this many seconds before echoing keys in the command loop. This
194     feature is inhibited when nil."
195     :value 1.0)
196     (defhvar "Input Hook"
197     "The functions in this variable are invoked each time a character enters
198     Hemlock."
199     :value nil)
200     (defhvar "Abort Hook"
201     "These functions are invoked when ^G is typed. No arguments are passed."
202     :value nil)
203     (defhvar "Command Abort Hook"
204     "These functions get called when commands are aborted, such as with
205     EDITOR-ERROR."
206     :value nil)
207     (defhvar "Character Attribute Hook"
208     "This hook is called with the attribute, character and new value
209     when the value of a character attribute is changed.")
210     (defhvar "Shadow Attribute Hook"
211     "This hook is called when a mode character attribute is made.")
212     (defhvar "Unshadow Attribute Hook"
213     "This hook is called when a mode character attribute is deleted.")
214     (defhvar "Default Modeline Fields"
215     "The default list of modeline-fields for MAKE-WINDOW."
216     :value *default-modeline-fields*)
217     (defhvar "Default Status Line Fields"
218     "This is the default list of modeline-fields for the echo area window's
219     modeline which is used for general information."
220     :value (list (make-modeline-field
221 chiles 1.8 :name :hemlock-banner :width 27
222 ram 1.1 :function #'(lambda (buffer window)
223     (declare (ignore buffer window))
224     (format nil "Hemlock ~A "
225     *hemlock-version*)))
226     (modeline-field :edit-level)
227     (modeline-field :completion)))
228     (defhvar "Maximum Modeline Pathname Length"
229     "When set, this variable is the maximum length of the display of a pathname
230     in a modeline. When the pathname is too long, the :buffer-pathname
231     modeline-field function chops off leading directory specifications until
232     the pathname fits. \"...\" indicates a truncated pathname."
233     :value nil
234     :hooks (list 'maximum-modeline-pathname-length-hook)))
235    
236    
237    
238     ;;;; ED.
239    
240     (defvar *editor-has-been-entered* ()
241     "True if and only if the editor has been entered.")
242     (defvar *in-the-editor* ()
243     "True if we are inside the editor. This is used to prevent ill-advised
244     \"recursive\" edits.")
245    
246     (defvar *after-editor-initializations-funs* nil
247     "A list of functions to be called after the editor has been initialized upon
248     entering the first time.")
249    
250     (defmacro after-editor-initializations (&rest forms)
251     "Causes forms to be executed after the editor has been initialized.
252     Forms supplied with successive uses of this macro will be executed after
253     forms supplied with previous uses."
254     `(push #'(lambda () ,@forms)
255     *after-editor-initializations-funs*))
256    
257     (defun ed (&optional x
258     &key (init t)
259     (display (cdr (assoc :display ext:*environment-list*))))
260     "Invokes the editor, Hemlock. If X is supplied and is a symbol, the
261 ram 1.9 definition of X is put into a buffer, and that buffer is selected. If X is
262     a pathname, the file specified by X is visited in a new buffer. If X is not
263     supplied or Nil, the editor is entered in the same state as when last
264     exited. When :init is supplied as t (the default), the file
265     \"hemlock-init.lisp\", or \".hemlock-init.lisp\" is loaded from the home
266     directory, but the Lisp command line switch -hinit can be used to specify a
267     different name. Any compiled version of the source is preferred when
268     choosing the file to load. If the argument is non-nil and not t, then it
269     should be a pathname that will be merged with the home directory."
270 ram 1.1 (when *in-the-editor* (error "You are already in the editor, you bogon!"))
271     (let ((*in-the-editor* t)
272     (display (unless *editor-has-been-entered*
273     (maybe-load-hemlock-init init)
274     ;; Device dependent initializaiton.
275     (init-raw-io display))))
276     (catch 'editor-top-level-catcher
277     (site-wrapper-macro
278     (unless *editor-has-been-entered*
279     ;; Make an initial window, and set up redisplay's internal
280     ;; data structures.
281     (%init-redisplay display)
282     (setq *editor-has-been-entered* t)
283     ;; Pick up user initializations to be done after initialization.
284     (invoke-hook (reverse *after-editor-initializations-funs*)))
285     (catch 'hemlock-exit
286     (catch 'editor-top-level-catcher
287     (cond ((and x (symbolp x))
288     (let* ((name (nstring-capitalize
289     (concatenate 'simple-string "Edit " (string x))))
290     (buffer (or (getstring name *buffer-names*)
291     (make-buffer name)))
292     (*print-case* :downcase))
293     (delete-region (buffer-region buffer))
294     (with-output-to-mark
295     (*standard-output* (buffer-point buffer))
296     (eval `(grindef ,x)) ; hackish, I know...
297     (terpri)
298     (ed::change-to-buffer buffer)
299     (buffer-start (buffer-point buffer)))))
300     ((or (stringp x) (pathnamep x))
301     (ed::find-file-command () x))
302     (x
303     (error
304     "~S is not a symbol or pathname. I can't edit it!" x))))
305    
306     (invoke-hook ed::entry-hook)
307     (unwind-protect
308     (loop
309     (catch 'editor-top-level-catcher
310     (handler-bind ((error #'(lambda (condition)
311     (lisp-error-error-handler condition
312     :internal))))
313     (invoke-hook ed::abort-hook)
314     (%command-loop))))
315     (invoke-hook ed::exit-hook)))))))
316    
317     (defun maybe-load-hemlock-init (init)
318     (when init
319 ram 1.9 (let* ((switch (find "hinit" *command-line-switches*
320     :test #'string-equal
321     :key #'cmd-switch-name))
322     (spec-name
323     (if (not (eq init t))
324     init
325     (and switch
326     (or (cmd-switch-value switch)
327     (car (cmd-switch-words switch)))))))
328     (if spec-name
329     (load (merge-pathnames spec-name (user-homedir-pathname))
330     :if-does-not-exist nil)
331     (or (load "home:hemlock-init" :if-does-not-exist nil)
332     (load "home:.hemlock-init" :if-does-not-exist nil))))))
333 ram 1.1
334    
335     ;;;; SAVE-ALL-BUFFERS.
336    
337 chiles 1.4 ;;; SAVE-ALL-BUFFERS -- Public.
338     ;;;
339 ram 1.1 (defun save-all-buffers (&optional (list-unmodified-buffers nil))
340 chiles 1.4 "This prompts users with each modified buffer as to whether they want to
341     write it out. If the buffer has no associated file, this will also prompt
342     for a file name. Supplying the optional argument non-nil causes this
343     to prompt for every buffer."
344 ram 1.1 (dolist (buffer *buffer-list*)
345     (when (or list-unmodified-buffers (buffer-modified buffer))
346     (maybe-save-buffer buffer))))
347    
348     (defun maybe-save-buffer (buffer)
349     (let* ((modified (buffer-modified buffer))
350     (pathname (buffer-pathname buffer))
351     (name (buffer-name buffer))
352     (string (if pathname (namestring pathname))))
353     (format t "Buffer ~S is ~:[UNmodified~;modified~], Save it? "
354     name modified)
355 chiles 1.6 (force-output)
356 ram 1.1 (when (y-or-n-p)
357     (let ((name (read-line-default "File to write" string)))
358     (format t "Writing file ~A..." name)
359     (force-output)
360     (write-file (buffer-region buffer) name)
361     (write-line "write WON")))))
362    
363     (defun read-line-default (prompt default)
364     (format t "~A:~@[ [~A]~] " prompt default)
365 chiles 1.6 (force-output)
366 ram 1.1 (do ((result (read-line) (read-line)))
367     (())
368     (declare (simple-string result))
369     (when (plusp (length result)) (return result))
370     (when default (return default))
371 chiles 1.6 (format t "~A:~@[ [~A]~] " prompt default)
372     (force-output)))
373 ram 1.10
374     (unless *hemlock-initialized*
375     (%init-hemlock))

  ViewVC Help
Powered by ViewVC 1.1.5