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

Contents of /src/hemlock/main.lisp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5