0
|
1 ;;; startup.el --- process XEmacs shell arguments
|
|
2
|
144
|
3 ;; Copyright (C) 1985-1986, 1990, 1992-1997 Free Software Foundation, Inc.
|
0
|
4 ;; Copyright (c) 1993, 1994 Sun Microsystems, Inc.
|
|
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
|
|
6
|
|
7 ;; Maintainer: XEmacs
|
|
8 ;; Keywords: internal
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
16
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
70
|
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
16
|
25 ;; Boston, MA 02111-1307, USA.
|
0
|
26
|
70
|
27 ;;; Synched up with: FSF 19.34.
|
0
|
28
|
|
29 ;;; Code:
|
|
30
|
|
31 ;;; -batch, -t, and -nw are processed by main() in emacs.c and are
|
|
32 ;;; never seen by lisp code.
|
|
33
|
|
34 ;;; -version and -help are special-cased as well: they imply -batch,
|
|
35 ;;; but are left on the list for lisp code to process.
|
|
36
|
|
37
|
|
38 (setq top-level '(normal-top-level))
|
|
39
|
|
40 (defvar command-line-processed nil "t once command line has been processed")
|
|
41
|
76
|
42 (defconst startup-message-timeout 1200) ; More or less disable the timeout
|
0
|
43
|
|
44 (defconst inhibit-startup-message nil
|
|
45 "*Non-nil inhibits the initial startup message.
|
|
46 This is for use in your personal init file, once you are familiar
|
|
47 with the contents of the startup message.")
|
|
48
|
|
49 ;; #### FSFmacs randomness
|
70
|
50 ;;(defconst inhibit-startup-echo-area-message nil
|
|
51 ;; "*Non-nil inhibits the initial startup echo area message.
|
|
52 ;;Inhibition takes effect only if your `.emacs' file contains
|
|
53 ;;a line of this form:
|
|
54 ;; (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
|
|
55 ;;If your `.emacs' file is byte-compiled, use the following form instead:
|
|
56 ;; (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
|
|
57 ;;Thus, someone else using a copy of your `.emacs' file will see
|
|
58 ;;the startup message unless he personally acts to inhibit it.")
|
0
|
59
|
|
60 (defconst inhibit-default-init nil
|
|
61 "*Non-nil inhibits loading the `default' library.")
|
|
62
|
|
63 (defvar command-line-args-left nil
|
|
64 "List of command-line args not yet processed.") ; bound by `command-line'
|
|
65
|
|
66 (defvar command-line-default-directory nil
|
|
67 "Default directory to use for command line arguments.
|
|
68 This is normally copied from `default-directory' when XEmacs starts.")
|
|
69
|
|
70 (defvar before-init-hook nil
|
|
71 "Functions to call after handling urgent options but before init files.
|
|
72 The frame system uses this to open frames to display messages while
|
|
73 XEmacs loads the user's initialization file.")
|
|
74
|
|
75 (defvar after-init-hook nil
|
|
76 "Functions to call after loading the init file (`~/.emacs').
|
|
77 The call is not protected by a condition-case, so you can set `debug-on-error'
|
|
78 in `.emacs', and put all the actual code on `after-init-hook'.")
|
|
79
|
|
80 (defvar term-setup-hook nil
|
|
81 "Functions to be called after loading terminal-specific Lisp code.
|
|
82 See `run-hooks'. This variable exists for users to set,
|
|
83 so as to override the definitions made by the terminal-specific file.
|
|
84 XEmacs never sets this variable itself.")
|
|
85
|
|
86 (defvar keyboard-type nil
|
|
87 "The brand of keyboard you are using.
|
|
88 This variable is used to define
|
|
89 the proper function and keypad keys for use under X. It is used in a
|
|
90 fashion analogous to the environment value TERM.")
|
|
91
|
|
92 (defvar window-setup-hook nil
|
|
93 "Normal hook run to initialize window system display.
|
|
94 XEmacs runs this hook after processing the command line arguments and loading
|
|
95 the user's init file.")
|
|
96
|
|
97 (defconst initial-major-mode 'lisp-interaction-mode
|
|
98 "Major mode command symbol to use for the initial *scratch* buffer.")
|
|
99
|
|
100 (defvar init-file-user nil
|
|
101 "Identity of user whose `.emacs' file is or was read.
|
|
102 The value is nil if no init file is being used; otherwise, it may be either
|
|
103 the null string, meaning that the init file was taken from the user that
|
|
104 originally logged in, or it may be a string containing a user's name.
|
|
105
|
|
106 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
|
|
107 evaluates to the name of the directory where the `.emacs' file was
|
|
108 looked for.
|
|
109
|
|
110 Setting `init-file-user' does not prevent Emacs from loading
|
|
111 `site-start.el'. The only way to do that is to use `--no-site-file'.")
|
|
112
|
|
113 ;; #### called `site-run-file' in FSFmacs
|
|
114
|
|
115 (defvar site-start-file (purecopy "site-start")
|
|
116 "File containing site-wide run-time initializations.
|
|
117 This file is loaded at run-time before `~/.emacs'. It contains inits
|
|
118 that need to be in place for the entire site, but which, due to their
|
|
119 higher incidence of change, don't make sense to load into XEmacs'
|
|
120 dumped image. Thus, the run-time load order is: 1. file described in
|
|
121 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
|
|
122
|
|
123 Don't use the `site-start.el' file for things some users may not like.
|
|
124 Put them in `default.el' instead, so that users can more easily
|
|
125 override them. Users can prevent loading `default.el' with the `-q'
|
|
126 option or by setting `inhibit-default-init' in their own init files,
|
|
127 but inhibiting `site-start.el' requires `--no-site-file', which
|
|
128 is less convenient.")
|
|
129
|
70
|
130 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
|
|
131 ;; "Regexp that specifies when to enable the ISO 8859-1 character set.
|
|
132 ;;We do that if this regexp matches the locale name
|
|
133 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
|
0
|
134
|
|
135 (defvar mail-host-address nil
|
|
136 "*Name of this machine, for purposes of naming users.")
|
|
137
|
|
138 (defvar user-mail-address nil
|
|
139 "*Full mailing address of this user.
|
|
140 This is initialized based on `mail-host-address',
|
|
141 after your init file is read, in case it sets `mail-host-address'.")
|
|
142
|
|
143 (defvar auto-save-list-file-prefix "~/.saves-"
|
|
144 "Prefix for generating auto-save-list-file-name.
|
|
145 Emacs's pid and the system name will be appended to
|
|
146 this prefix to create a unique file name.")
|
|
147
|
|
148 (defvar init-file-debug nil)
|
|
149
|
|
150 (defvar init-file-had-error nil)
|
|
151
|
|
152 (defvar init-file-loaded nil
|
|
153 "True after the user's init file has been loaded (or suppressed with -q).
|
|
154 This will be true when `after-init-hook' is run and at all times
|
|
155 after, and will not be true at any time before.")
|
|
156
|
|
157 (defvar initial-frame-unmapped-p nil)
|
|
158
|
|
159
|
70
|
160
|
|
161 (defvar command-switch-alist
|
|
162 (purecopy
|
|
163 '(("-help" . command-line-do-help)
|
|
164 ("-flags" . command-line-do-help)
|
|
165 ("-h" . command-line-do-help)
|
|
166 ("-?" . command-line-do-help)
|
|
167 ("-version". command-line-do-version)
|
|
168 ("-V" . command-line-do-version)
|
|
169 ("-funcall". command-line-do-funcall)
|
|
170 ("-f" . command-line-do-funcall)
|
|
171 ("-e" . command-line-do-funcall-1)
|
|
172 ("-eval" . command-line-do-eval)
|
|
173 ("-load" . command-line-do-load)
|
|
174 ("-l" . command-line-do-load)
|
|
175 ("-insert" . command-line-do-insert)
|
|
176 ("-i" . command-line-do-insert)
|
|
177 ("-kill" . command-line-do-kill)
|
|
178 ;; Options like +35 are handled specially.
|
|
179 ;; Window-system, site, or package-specific code might add to this.
|
|
180 ;; X11 handles its options by letting Xt remove args from this list.
|
|
181 ))
|
|
182 "Alist of command-line switches.
|
|
183 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
|
|
184 HANDLER-FUNCTION receives switch name as sole arg;
|
|
185 remaining command-line args are in the variable `command-line-args-left'.")
|
|
186
|
0
|
187 ;;; default switches
|
|
188 ;;; Note: these doc strings are semi-magical.
|
|
189
|
70
|
190 (defun command-line-do-help (arg)
|
|
191 "Print the XEmacs usage message and exit."
|
|
192 (let ((standard-output 'external-debugging-output))
|
|
193 (princ (concat "\n" (emacs-version) "\n\n"))
|
|
194 (princ
|
|
195 (if (featurep 'x)
|
155
|
196 (concat (emacs-name)
|
|
197 " accepts all standard X Toolkit command line options.\n"
|
70
|
198 "In addition, the")
|
|
199 "The"))
|
|
200 (princ " following options are accepted:
|
|
201
|
|
202 -t <device> Use TTY <device> instead of the terminal for input
|
|
203 and output. This implies the -nw option.
|
|
204 -nw Inhibit the use of any window-system-specific
|
|
205 display code: use the current tty.
|
|
206 -batch Execute noninteractively (messages go to stderr).
|
|
207 -debug-init Enter the debugger if an error in the init file occurs.
|
|
208 -unmapped Do not map the initial frame.
|
|
209 -no-site-file Do not load the site-specific init file (site-start.el).
|
|
210 -no-init-file Do not load the user-specific init file (~/.emacs).
|
|
211 -q Same as -no-init-file.
|
|
212 -user <user> Load user's init file instead of your own.
|
|
213 -u <user> Same as -user.\n")
|
|
214 (let ((l command-switch-alist)
|
|
215 (insert (lambda (&rest x)
|
|
216 (princ " ")
|
|
217 (let ((len 2))
|
|
218 (while x
|
|
219 (princ (car x))
|
|
220 (incf len (length (car x)))
|
|
221 (setq x (cdr x)))
|
|
222 (when (>= len 24)
|
|
223 (terpri) (setq len 0))
|
|
224 (while (< len 24)
|
|
225 (princ " ")
|
|
226 (incf len))))))
|
|
227 (while l
|
|
228 (let ((name (car (car l)))
|
|
229 (fn (cdr (car l)))
|
|
230 doc arg cons)
|
|
231 (cond
|
|
232 ((and (symbolp fn) (get fn 'undocumented)) nil)
|
|
233 (t
|
|
234 (setq doc (documentation fn))
|
|
235 (if (member doc '(nil "")) (setq doc "(undocumented)"))
|
|
236 (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
|
|
237 ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
|
|
238 (setq arg (substring doc (match-beginning 1) (match-end 1))
|
|
239 doc (substring doc 0 (match-beginning 0))))
|
|
240 ((string-match "\n+\\'" doc)
|
|
241 (setq doc (substring doc 0 (match-beginning 0)))))
|
|
242 (if (and (setq cons (rassq fn command-switch-alist))
|
|
243 (not (eq cons (car l))))
|
|
244 (setq doc (format "Same as %s." (car cons))))
|
|
245 (if arg
|
|
246 (funcall insert name " " arg)
|
|
247 (funcall insert name))
|
|
248 (princ doc)
|
|
249 (terpri))))
|
|
250 (setq l (cdr l))))
|
155
|
251 (princ (concat "\
|
70
|
252 +N <file> Start displaying <file> at line N.
|
|
253
|
|
254 Anything else is considered a file name, and is placed into a buffer for
|
|
255 editing.
|
|
256
|
155
|
257 " (emacs-name) " has an online tutorial and manuals. Type ^Ht (Control-h t) after
|
70
|
258 starting XEmacs to run the tutorial. Type ^Hi to enter the manual browser.
|
|
259 Type ^H^H^H (Control-h Control-h Control-h) to get more help options.\n")
|
|
260
|
155
|
261 (kill-emacs 0))))
|
70
|
262
|
0
|
263 (defun command-line-do-funcall (arg)
|
|
264 "Invoke the named lisp function with no arguments.
|
|
265 <function>"
|
70
|
266 (funcall (intern (pop command-line-args-left))))
|
0
|
267 (fset 'command-line-do-funcall-1 'command-line-do-funcall)
|
|
268 (put 'command-line-do-funcall-1 'undocumented t)
|
|
269
|
|
270 (defun command-line-do-eval (arg)
|
|
271 "Evaluate the lisp form. Quote it carefully.
|
|
272 <form>"
|
70
|
273 (eval (read (pop command-line-args-left))))
|
0
|
274
|
|
275 (defun command-line-do-load (arg)
|
|
276 "Load the named file of Lisp code into XEmacs.
|
|
277 <file>"
|
70
|
278 (let ((file (pop command-line-args-left)))
|
0
|
279 ;; Take file from default dir if it exists there;
|
|
280 ;; otherwise let `load' search for it.
|
|
281 (if (file-exists-p (expand-file-name file))
|
|
282 (setq file (expand-file-name file)))
|
70
|
283 (load file nil t)))
|
0
|
284
|
|
285 (defun command-line-do-insert (arg)
|
|
286 "Insert file into the current buffer.
|
|
287 <file>"
|
70
|
288 (insert-file-contents (pop command-line-args-left)))
|
0
|
289
|
|
290 (defun command-line-do-kill (arg)
|
|
291 "Exit XEmacs."
|
|
292 (kill-emacs t))
|
|
293
|
|
294 (defun command-line-do-version (arg)
|
|
295 "Print version info and exit."
|
70
|
296 (princ (concat (emacs-version) "\n"))
|
0
|
297 (kill-emacs 0))
|
|
298
|
|
299
|
|
300 ;;; Processing the command line and loading various init files
|
|
301
|
|
302 (defun early-error-handler (&rest debugger-args)
|
|
303 "You should probably not be using this."
|
|
304 ;; Used as the debugger during XEmacs initialization; if an error occurs,
|
|
305 ;; print some diagnostics, and kill XEmacs.
|
|
306
|
|
307 ;; output the contents of the warning buffer, since it won't be seen
|
|
308 ;; otherwise.
|
|
309 ;; #### kludge! The call to Feval forces the pending warnings to
|
|
310 ;; get output. There definitely needs to be a better way.
|
|
311 (let ((buffer (eval (get-buffer-create "*Warnings*"))))
|
|
312 (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
|
|
313 'external-debugging-output))
|
|
314
|
|
315 (let ((string "Initialization error")
|
|
316 (error (nth 1 debugger-args))
|
|
317 (debug-on-error nil)
|
|
318 (stream 'external-debugging-output))
|
|
319 (if (null error)
|
|
320 (princ string stream)
|
|
321 (princ (concat "\n" string ": ") stream)
|
|
322 (condition-case ()
|
|
323 (display-error error stream)
|
|
324 (error (princ "<<< error printing error message >>>" stream)))
|
|
325 (princ "\n" stream)
|
|
326 (if (memq (car-safe error) '(void-function void-variable))
|
|
327 (princ "
|
|
328 This probably means that XEmacs is picking up an old version of
|
|
329 the lisp library, or that some .elc files are not up-to-date.\n"
|
|
330 stream)))
|
70
|
331 (when (not suppress-early-error-handler-backtrace)
|
|
332 (let ((print-length 1000)
|
|
333 (print-level 1000)
|
|
334 (print-escape-newlines t)
|
|
335 (print-readably nil))
|
|
336 (when (getenv "EMACSLOADPATH")
|
|
337 (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
|
|
338 stream))
|
|
339 (princ (format "\nexec-directory is %S" exec-directory) stream)
|
|
340 (princ (format "\ndata-directory is %S" data-directory) stream)
|
|
341 (princ (format "\ndoc-directory is %S" doc-directory) stream)
|
|
342 (princ (format "\nload-path is %S" load-path) stream)
|
|
343 (princ "\n\n" stream)))
|
|
344 (when (not suppress-early-error-handler-backtrace)
|
|
345 (backtrace stream t)))
|
0
|
346 (kill-emacs -1))
|
|
347
|
|
348 (defun normal-top-level ()
|
|
349 (if command-line-processed
|
|
350 (message "Back to top level.")
|
|
351 (setq command-line-processed t)
|
|
352 ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
|
70
|
353 (unless (eq system-type 'vax-vms)
|
|
354 (let ((value (getenv "HOME")))
|
|
355 (if (and value
|
|
356 (< (length value) (length default-directory))
|
|
357 (equal (file-attributes default-directory)
|
|
358 (file-attributes value)))
|
|
359 (setq default-directory (file-name-as-directory value)))))
|
0
|
360 (setq default-directory (abbreviate-file-name default-directory))
|
|
361 (initialize-xemacs-paths)
|
|
362 (unwind-protect
|
|
363 (command-line)
|
|
364 ;; Do this again, in case .emacs defined more abbreviations.
|
|
365 (setq default-directory (abbreviate-file-name default-directory))
|
|
366 ;; Specify the file for recording all the auto save files of
|
|
367 ;; this session. This is used by recover-session.
|
|
368 (setq auto-save-list-file-name
|
|
369 (expand-file-name
|
|
370 (format "%s%d-%s"
|
|
371 auto-save-list-file-prefix
|
|
372 (emacs-pid)
|
|
373 (system-name))))
|
|
374 (run-hooks 'emacs-startup-hook)
|
|
375 (and term-setup-hook
|
|
376 (run-hooks 'term-setup-hook))
|
|
377 (setq term-setup-hook nil)
|
70
|
378 ;; ;; Modify the initial frame based on what .emacs puts into
|
|
379 ;; ;; ...-frame-alist.
|
0
|
380 (frame-notice-user-settings)
|
70
|
381 ;; ;;####FSFmacs junk
|
|
382 ;; ;; Now we know the user's default font, so add it to the menu.
|
|
383 ;; (if (fboundp 'font-menu-add-default)
|
|
384 ;; (font-menu-add-default))
|
|
385 (when window-setup-hook
|
|
386 (run-hooks 'window-setup-hook))
|
0
|
387 (setq window-setup-hook nil))
|
70
|
388 ;;####FSFmacs junk
|
|
389 ;; (or menubar-bindings-done
|
|
390 ;; (precompute-menubar-bindings))
|
0
|
391 ))
|
|
392
|
|
393 ;;####FSFmacs junk
|
|
394 ;;; Precompute the keyboard equivalents in the menu bar items.
|
70
|
395 ;;(defun precompute-menubar-bindings ()
|
|
396 ;; (if (eq window-system 'x)
|
|
397 ;; (let ((submap (lookup-key global-map [menu-bar])))
|
|
398 ;; (while submap
|
|
399 ;; (and (consp (car submap))
|
|
400 ;; (symbolp (car (car submap)))
|
|
401 ;; (stringp (car-safe (cdr (car submap))))
|
|
402 ;; (keymapp (cdr (cdr (car submap))))
|
|
403 ;; (x-popup-menu nil (cdr (cdr (car submap)))))
|
|
404 ;; (setq submap (cdr submap))))))
|
0
|
405
|
70
|
406 (defun command-line-early (args)
|
0
|
407 ;; This processes those switches which need to be processed before
|
|
408 ;; starting up the window system.
|
|
409
|
|
410 (setq command-line-default-directory default-directory)
|
|
411
|
|
412 ;; See if we should import version-control from the environment variable.
|
|
413 (let ((vc (getenv "VERSION_CONTROL")))
|
|
414 (cond ((eq vc nil)) ;don't do anything if not set
|
|
415 ((or (string= vc "t")
|
|
416 (string= vc "numbered"))
|
|
417 (setq version-control t))
|
|
418 ((or (string= vc "nil")
|
|
419 (string= vc "existing"))
|
|
420 (setq version-control nil))
|
|
421 ((or (string= vc "never")
|
|
422 (string= vc "simple"))
|
|
423 (setq version-control 'never))))
|
|
424
|
70
|
425 ;;####FSFmacs
|
|
426 ;; (if (let ((ctype
|
|
427 ;; ;; Use the first of these three envvars that has a nonempty value.
|
|
428 ;; (or (let ((string (getenv "LC_ALL")))
|
|
429 ;; (and (not (equal string "")) string))
|
|
430 ;; (let ((string (getenv "LC_CTYPE")))
|
|
431 ;; (and (not (equal string "")) string))
|
|
432 ;; (let ((string (getenv "LANG")))
|
|
433 ;; (and (not (equal string "")) string)))))
|
|
434 ;; (and ctype
|
|
435 ;; (string-match iso-8859-1-locale-regexp ctype)))
|
|
436 ;; (progn
|
|
437 ;; (standard-display-european t)
|
|
438 ;; (require 'iso-syntax)))
|
0
|
439
|
70
|
440 ;; Figure out which user's init file to load,
|
|
441 ;; either from the environment or from the options.
|
|
442 (setq init-file-user (if (noninteractive) nil (user-login-name)))
|
|
443 ;; If user has not done su, use current $HOME to find .emacs.
|
|
444 (and init-file-user (string= init-file-user (user-real-login-name))
|
|
445 (setq init-file-user ""))
|
0
|
446
|
70
|
447 ;; Allow (at least) these arguments anywhere in the command line
|
|
448 (let ((new-args nil)
|
|
449 (arg nil))
|
|
450 (while args
|
|
451 (setq arg (pop args))
|
|
452 (cond
|
|
453 ((or (string= arg "-q")
|
|
454 (string= arg "-no-init-file"))
|
|
455 (setq init-file-user nil))
|
|
456 ((string= arg "-no-site-file")
|
|
457 (setq site-start-file nil))
|
|
458 ((or (string= arg "-u")
|
|
459 (string= arg "-user"))
|
|
460 (setq init-file-user (pop args)))
|
|
461 ((string= arg "-debug-init")
|
|
462 (setq init-file-debug t))
|
|
463 ((string= arg "-unmapped")
|
|
464 (setq initial-frame-unmapped-p t))
|
|
465 ((or (string= arg "--") (string= arg "-"))
|
|
466 (while args
|
|
467 (push (pop args) new-args)))
|
|
468 (t (push arg new-args))))
|
|
469
|
|
470 (nreverse new-args)))
|
0
|
471
|
|
472 (defun command-line ()
|
|
473 (let ((command-line-args-left (cdr command-line-args)))
|
|
474
|
|
475 (let ((debugger 'early-error-handler)
|
|
476 (debug-on-error t))
|
|
477 (set-default-load-path)
|
|
478
|
|
479 ;; Process magic command-line switches like -q and -u. Do this
|
|
480 ;; before creating the first frame because some of these switches
|
|
481 ;; may affect that. I think it's ok to do this before establishing
|
|
482 ;; the X connection, and maybe someday things like -nw can be
|
|
483 ;; handled here instead of down in C.
|
70
|
484 (setq command-line-args-left (command-line-early command-line-args-left))
|
0
|
485
|
|
486 ;; Setup the toolbar icon directory
|
70
|
487 (when (featurep 'toolbar)
|
|
488 (init-toolbar-location))
|
0
|
489
|
70
|
490 ;; Initialize the built-in glyphs and default specifier lists
|
|
491 (when (not noninteractive)
|
|
492 (init-glyphs))
|
0
|
493
|
|
494 ;; Run the window system's init function. tty is considered to be
|
|
495 ;; a type of window system for this purpose. This creates the
|
|
496 ;; initial (non stdio) device.
|
70
|
497 (when (and initial-window-system (not noninteractive))
|
|
498 (funcall (intern (concat "init-"
|
|
499 (symbol-name initial-window-system)
|
|
500 "-win"))))
|
0
|
501
|
|
502 ;; When not in batch mode, this creates the first visible frame,
|
|
503 ;; and deletes the stdio device.
|
|
504 (frame-initialize))
|
|
505
|
|
506 ;;
|
|
507 ;; We have normality, I repeat, we have normality. Anything you still
|
|
508 ;; can't cope with is therefore your own problem. (And we don't need
|
|
509 ;; to kill XEmacs for it.)
|
|
510 ;;
|
|
511
|
|
512 ;;; Load init files.
|
|
513 (load-init-file)
|
|
514
|
|
515 ;; If *scratch* exists and init file didn't change its mode, initialize it.
|
70
|
516 (when (get-buffer "*scratch*")
|
|
517 (save-excursion
|
|
518 (set-buffer "*scratch*")
|
|
519 (when (eq major-mode 'fundamental-mode)
|
|
520 (funcall initial-major-mode))))
|
0
|
521
|
|
522 ;; Load library for our terminal type.
|
|
523 ;; User init file can set term-file-prefix to nil to prevent this.
|
|
524 ;; Note that for any TTY's opened subsequently, the TTY init
|
|
525 ;; code will run this.
|
70
|
526 (when (and (eq 'tty (console-type))
|
|
527 (not (noninteractive)))
|
|
528 (load-terminal-library))
|
0
|
529
|
|
530 ;; Process the remaining args.
|
|
531 (command-line-1)
|
|
532
|
|
533 ;; it was turned on by default so that the warnings don't get displayed
|
|
534 ;; until after the splash screen.
|
|
535 (setq inhibit-warning-display nil)
|
|
536 ;; If -batch, terminate after processing the command options.
|
70
|
537 (when (noninteractive) (kill-emacs t))))
|
0
|
538
|
|
539 (defun load-terminal-library ()
|
70
|
540 (when term-file-prefix
|
|
541 (let ((term (getenv "TERM"))
|
|
542 hyphend)
|
|
543 (while (and term
|
|
544 (not (load (concat term-file-prefix term) t t)))
|
|
545 ;; Strip off last hyphen and what follows, then try again
|
|
546 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
|
|
547 (setq term (substring term 0 hyphend))
|
|
548 (setq term nil))))))
|
0
|
549
|
171
|
550 (defconst emacs-user-extension-dir "/.xemacs/"
|
|
551 "Directory where user initialization and user-installed packages may go.")
|
163
|
552
|
0
|
553 (defun load-user-init-file (init-file-user)
|
163
|
554 "This function actually reads the init files.
|
|
555 First try .xemacs, then try .emacs, but only load one of the two."
|
70
|
556 (when init-file-user
|
|
557 (setq user-init-file
|
|
558 (cond
|
|
559 ((eq system-type 'ms-dos)
|
171
|
560 (concat "~" init-file-user emacs-user-extension-dir "init.el"))
|
70
|
561 (t
|
171
|
562 (concat "~" init-file-user emacs-user-extension-dir "init.el"))))
|
163
|
563 (unless (file-exists-p (expand-file-name user-init-file))
|
|
564 (setq user-init-file
|
|
565 (cond
|
|
566 ((eq system-type 'ms-dos)
|
|
567 (concat "~" init-file-user "/_emacs"))
|
|
568 (t
|
|
569 (concat "~" init-file-user "/.emacs")))))
|
70
|
570 (load user-init-file t t t)
|
171
|
571 (when (string= custom-file (concat "~"
|
|
572 init-file-user
|
|
573 emacs-user-extension-dir
|
|
574 "options.el"))
|
|
575 (load (concat "~"
|
|
576 init-file-user
|
|
577 emacs-user-extension-dir
|
|
578 "options.el") t t))
|
70
|
579 (unless inhibit-default-init
|
|
580 (let ((inhibit-startup-message nil))
|
|
581 ;; Users are supposed to be told their rights.
|
|
582 ;; (Plus how to get help and how to undo.)
|
|
583 ;; Don't you dare turn this off for anyone except yourself.
|
|
584 (load "default" t t)))))
|
0
|
585
|
|
586 ;;; Load user's init file and default ones.
|
|
587 (defun load-init-file ()
|
|
588 (run-hooks 'before-init-hook)
|
|
589
|
|
590 ;; Run the site-start library if it exists. The point of this file is
|
|
591 ;; that it is run before .emacs. There is no point in doing this after
|
|
592 ;; .emacs; that is useless.
|
70
|
593 (when site-start-file
|
|
594 (load site-start-file t t))
|
0
|
595
|
|
596 ;; Sites should not disable this. Only individuals should disable
|
|
597 ;; the startup message.
|
|
598 (setq inhibit-startup-message nil)
|
|
599
|
|
600 (let (debug-on-error-from-init-file
|
|
601 debug-on-error-should-be-set
|
|
602 (debug-on-error-initial
|
|
603 (if (eq init-file-debug t) 'startup init-file-debug)))
|
|
604 (let ((debug-on-error debug-on-error-initial))
|
|
605 (if init-file-debug
|
|
606 ;; Do this without a condition-case if the user wants to debug.
|
|
607 (load-user-init-file init-file-user)
|
|
608 (condition-case error
|
|
609 (progn
|
|
610 (load-user-init-file init-file-user)
|
|
611 (setq init-file-had-error nil))
|
|
612 (error
|
|
613 (message "Error in init file: ")
|
|
614 (display-error error nil)
|
|
615 (setq init-file-had-error t))))
|
|
616 ;; If we can tell that the init file altered debug-on-error,
|
|
617 ;; arrange to preserve the value that it set up.
|
|
618 (or (eq debug-on-error debug-on-error-initial)
|
|
619 (setq debug-on-error-should-be-set t
|
|
620 debug-on-error-from-init-file debug-on-error)))
|
70
|
621 (when debug-on-error-should-be-set
|
|
622 (setq debug-on-error debug-on-error-from-init-file)))
|
0
|
623
|
|
624 (setq init-file-loaded t)
|
|
625
|
|
626 ;; Do this here in case the init file sets mail-host-address.
|
114
|
627 ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
|
|
628 ;; (or user-mail-address
|
|
629 (when noninteractive
|
|
630 (setq user-mail-address (concat (user-login-name) "@"
|
|
631 (or mail-host-address
|
|
632 (system-name)))))
|
0
|
633
|
|
634 (run-hooks 'after-init-hook)
|
|
635 nil)
|
|
636
|
|
637 (defun load-options-file (filename)
|
|
638 "Load the file of saved options (from the Options menu) called FILENAME.
|
|
639 Currently this does nothing but call `load', but it might be redefined
|
|
640 in the future to support automatically converting older options files to
|
|
641 a new format, when variables have changed, etc."
|
|
642 (load filename))
|
|
643
|
|
644 (defun command-line-1 ()
|
|
645 (if (null command-line-args-left)
|
70
|
646 (unless (or inhibit-startup-message
|
|
647 noninteractive
|
0
|
648 ;; Don't clobber a non-scratch buffer if init file
|
|
649 ;; has selected it.
|
70
|
650 (not (string= (buffer-name) "*scratch*"))
|
|
651 (input-pending-p))
|
0
|
652
|
70
|
653 ;; If there are no switches to process, run the term-setup-hook
|
|
654 ;; before displaying the copyright notice; there may be some need
|
|
655 ;; to do it before doing any output. If we're not going to
|
|
656 ;; display a copyright notice (because other options are present)
|
|
657 ;; then this is run after those options are processed.
|
|
658 (run-hooks 'term-setup-hook)
|
|
659 ;; Don't let the hook be run twice.
|
|
660 (setq term-setup-hook nil)
|
0
|
661
|
70
|
662 (let ((timeout nil))
|
|
663 (unwind-protect
|
|
664 ;; Guts of with-timeout
|
|
665 (catch 'timeout
|
|
666 (setq timeout (add-timeout startup-message-timeout
|
|
667 (lambda (ignore)
|
|
668 (condition-case nil
|
|
669 (throw 'timeout t)
|
|
670 (error nil)))
|
|
671 nil))
|
|
672 (startup-splash-frame)
|
|
673 (or nil;; (pos-visible-in-window-p (point-min))
|
|
674 (goto-char (point-min)))
|
|
675 (sit-for 0)
|
|
676 (setq unread-command-event (next-command-event)))
|
|
677 (when timeout (disable-timeout timeout))
|
|
678 (save-excursion
|
|
679 ;; In case the XEmacs server has already selected
|
|
680 ;; another buffer, erase the one our message is in.
|
|
681 (set-buffer (get-buffer "*scratch*"))
|
|
682 (erase-buffer)
|
|
683 (set-buffer-modified-p nil)))))
|
|
684
|
|
685 ;; Command-line-options exist
|
0
|
686 (let ((dir command-line-default-directory)
|
|
687 (file-count 0)
|
70
|
688 (line nil)
|
|
689 (end-of-options nil)
|
|
690 first-file-buffer file-p arg tem)
|
0
|
691 (while command-line-args-left
|
70
|
692 (setq arg (pop command-line-args-left))
|
|
693 (cond
|
|
694 (end-of-options
|
|
695 (setq file-p t))
|
|
696 ((setq tem (when (eq (aref arg 0) ?-)
|
|
697 (or (assoc arg command-switch-alist)
|
|
698 (assoc (substring arg 1)
|
|
699 command-switch-alist))))
|
|
700 (funcall (cdr tem) arg))
|
|
701 ((string-match "\\`\\+[0-9]+\\'" arg)
|
|
702 (setq line (string-to-int arg)))
|
|
703 ;; "- file" means don't treat "file" as a switch
|
|
704 ;; ("+0 file" has the same effect; "-" added
|
|
705 ;; for unixoidiality).
|
|
706 ;; This is worthless; the `unixoid' way is "./file". -jwz
|
|
707 ((or (string= arg "-") (string= arg "--"))
|
|
708 (setq end-of-options t))
|
|
709 (t
|
|
710 (setq file-p t)))
|
|
711
|
|
712 (when file-p
|
|
713 (setq file-p nil)
|
|
714 (incf file-count)
|
|
715 (setq arg (expand-file-name arg dir))
|
|
716 (cond
|
|
717 ((= file-count 1) (setq first-file-buffer
|
|
718 (progn (find-file arg) (current-buffer))))
|
|
719 (noninteractive (find-file arg))
|
|
720 (t (find-file-other-window arg)))
|
|
721 (when line
|
|
722 (goto-line line)
|
|
723 (setq line nil))))
|
0
|
724 ;; If 3 or more files visited, and not all visible,
|
|
725 ;; show user what they all are.
|
70
|
726 (when (and (not noninteractive)
|
|
727 (> file-count 2)
|
|
728 (not (get-buffer-window first-file-buffer)))
|
|
729 (other-window 1)
|
|
730 (buffer-menu nil)))))
|
0
|
731
|
|
732 (defvar startup-presentation-hack-keymap
|
|
733 (let ((map (make-sparse-keymap)))
|
|
734 (set-keymap-name map 'startup-presentation-hack-keymap)
|
|
735 (define-key map '[button1] 'startup-presentation-hack)
|
|
736 (define-key map '[button2] 'startup-presentation-hack)
|
|
737 map)
|
|
738 "Putting yesterday in the future tomorrow.")
|
|
739
|
|
740 (defun startup-presentation-hack ()
|
|
741 (interactive)
|
|
742 (let ((e last-command-event))
|
|
743 (and (button-press-event-p e)
|
|
744 (setq e (extent-at (event-point e)
|
|
745 (event-buffer e)
|
|
746 'startup-presentation-hack))
|
|
747 (setq e (extent-property e 'startup-presentation-hack))
|
|
748 (if (consp e)
|
|
749 (apply (car e) (cdr e))
|
70
|
750 (while (keymapp (indirect-function e))
|
|
751 (let ((map e)
|
|
752 (overriding-local-map (indirect-function e)))
|
|
753 (setq e (read-key-sequence
|
|
754 (let ((p (keymap-prompt map t)))
|
|
755 (cond ((symbolp map)
|
|
756 (if p
|
|
757 (format "%s %s " map p)
|
|
758 (format "%s " map)))
|
|
759 (p)
|
|
760 (t
|
|
761 (prin1-to-string map))))))
|
|
762 (if (and (button-release-event-p (elt e 0))
|
|
763 (null (key-binding e)))
|
|
764 (setq e map) ; try again
|
|
765 (setq e (key-binding e)))))
|
|
766 (call-interactively e)))))
|
0
|
767
|
|
768 (defun startup-presentation-hack-help (e)
|
|
769 (setq e (extent-property e 'startup-presentation-hack))
|
|
770 (if (consp e)
|
|
771 (format "Evaluate %S" e)
|
70
|
772 (symbol-name e)))
|
0
|
773
|
|
774 (defun splash-frame-present-hack (e v)
|
70
|
775 ;; (set-extent-property e 'mouse-face 'highlight)
|
|
776 ;; (set-extent-property e 'keymap
|
|
777 ;; startup-presentation-hack-keymap)
|
|
778 ;; (set-extent-property e 'startup-presentation-hack v)
|
|
779 ;; (set-extent-property e 'help-echo
|
|
780 ;; 'startup-presentation-hack-help))
|
0
|
781 )
|
|
782
|
108
|
783 (defun splash-hack-version-string ()
|
|
784 (save-excursion
|
|
785 (save-restriction
|
|
786 (goto-char (point-min))
|
|
787 (re-search-forward "^XEmacs" nil t)
|
|
788 (narrow-to-region (point-at-bol) (point-at-eol))
|
|
789 (goto-char (point-min))
|
|
790 (when (re-search-forward " \\[Lucid\\]" nil t)
|
|
791 (delete-region (match-beginning 0) (match-end 0)))
|
116
|
792 (when (re-search-forward "[^(][^)]*-[^)]*-" nil t)
|
108
|
793 (delete-region (1+ (match-beginning 0)) (match-end 0))
|
|
794 (insert "("))
|
|
795 (goto-char (point-max))
|
|
796 (search-backward " " nil t)
|
|
797 (when (search-forward "." nil t)
|
|
798 (delete-region (1- (point)) (point-max))))))
|
|
799
|
0
|
800 (defun splash-frame-present (l)
|
|
801 (cond ((stringp l)
|
108
|
802 (insert l)
|
|
803 (splash-hack-version-string))
|
0
|
804 ((eq (car-safe l) 'face)
|
|
805 ;; (face name string)
|
|
806 (let ((p (point)))
|
|
807 (splash-frame-present (elt l 2))
|
|
808 (if (fboundp 'set-extent-face)
|
|
809 (set-extent-face (make-extent p (point))
|
|
810 (elt l 1)))))
|
|
811 ((eq (car-safe l) 'key)
|
|
812 (let* ((c (elt l 1))
|
|
813 (p (point))
|
|
814 (k (where-is-internal c nil t)))
|
|
815 (insert (if k (key-description k)
|
70
|
816 (format "M-x %s" c)))
|
0
|
817 (if (fboundp 'set-extent-face)
|
|
818 (let ((e (make-extent p (point))))
|
|
819 (set-extent-face e 'bold)
|
|
820 (splash-frame-present-hack e c)))))
|
|
821 ((eq (car-safe l) 'funcall)
|
|
822 ;; (funcall (fun . args) string)
|
|
823 (let ((p (point)))
|
|
824 (splash-frame-present (elt l 2))
|
|
825 (if (fboundp 'set-extent-face)
|
|
826 (splash-frame-present-hack (make-extent p (point))
|
70
|
827 (elt l 1)))))
|
0
|
828 ((consp l)
|
|
829 (mapcar 'splash-frame-present l))
|
|
830 (t
|
|
831 (error "WTF!?"))))
|
|
832
|
|
833 (defun startup-center-spaces (glyph)
|
|
834 ;; Return the number of spaces to insert in order to center
|
|
835 ;; the given glyph (may be a string or a pixmap).
|
|
836 ;; Assume spaces are as wide as avg-pixwidth.
|
|
837 ;; Won't be quite right for proportional fonts, but it's the best we can do.
|
|
838 ;; Maybe the new redisplay will export something a glyph-width function.
|
|
839 ;;; #### Yes, there is a glyph-width function but it isn't quite what
|
|
840 ;;; #### this was expecting. Or is it?
|
|
841 ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
|
|
842 ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
|
|
843
|
|
844 ;; This function is used in about.el too.
|
|
845 (let* ((avg-pixwidth (round (/ (frame-pixel-width) (frame-width))))
|
|
846 (fill-area-width (* avg-pixwidth (- fill-column left-margin)))
|
|
847 (glyph-pixwidth (cond ((stringp glyph)
|
|
848 (* avg-pixwidth (length glyph)))
|
|
849 ;; #### the pixmap option should be removed
|
|
850 ;;((pixmapp glyph)
|
|
851 ;; (pixmap-width glyph))
|
|
852 ((glyphp glyph)
|
|
853 (glyph-width glyph))
|
|
854 (t
|
|
855 (error "startup-center-spaces: bad arg")))))
|
|
856 (+ left-margin
|
|
857 (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
|
|
858
|
2
|
859 (defun startup-splash-frame-body ()
|
|
860 `("\n" ,(emacs-version) "\n"
|
108
|
861 ,@(if (string-match "beta" emacs-version)
|
|
862 `( (face (bold blue) ( "This is an Experimental version of XEmacs. "
|
|
863 " Type " (key describe-beta)
|
|
864 " to see what this means.\n")))
|
|
865 `( "\n"))
|
2
|
866 (face bold-italic "\
|
108
|
867 Copyright (C) 1985-1997 Free Software Foundation, Inc.
|
0
|
868 Copyright (C) 1990-1994 Lucid, Inc.
|
108
|
869 Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
|
0
|
870 Copyright (C) 1994-1996 Board of Trustees, University of Illinois
|
2
|
871 Copyright (C) 1995-1996 Ben Wing\n\n")
|
|
872
|
|
873 ,@(if (featurep 'sparcworks)
|
|
874 `( "\
|
|
875 Sun provides support for the WorkShop/XEmacs integration package only.
|
|
876 All other XEmacs packages are provided to you \"AS IS\".
|
|
877 For full details, type " (key describe-no-warranty)
|
|
878 " to refer to the GPL Version 2, dated June 1991.\n\n"
|
70
|
879 ,@(let ((lang (or (getenv "LC_ALL") (getenv "LC_MESSAGES") (getenv "LANG"))))
|
2
|
880 (if (and
|
|
881 (not (featurep 'mule)) ; Already got mule?
|
|
882 (not (eq 'tty (console-type))) ; No Mule support on tty's yet
|
|
883 lang ; Non-English locale?
|
70
|
884 (not (string= lang "C"))
|
2
|
885 (not (string-match "^en" lang))
|
|
886 (locate-file "xemacs-mule" exec-path)) ; Comes with Sun WorkShop
|
|
887 '( "\
|
|
888 This version of XEmacs has been built with support for Latin-1 languages only.
|
|
889 To handle other languages you need to run a Multi-lingual (`Mule') version of
|
|
890 XEmacs, by either running the command `xemacs-mule', or by using the X resource
|
|
891 `ESERVE*defaultXEmacsPath: xemacs-mule' when starting XEmacs from Sun WorkShop.\n\n"))))
|
0
|
892
|
2
|
893 '("XEmacs comes with ABSOLUTELY NO WARRANTY; type "
|
|
894 (key describe-no-warranty) " for full details.\n"))
|
|
895
|
|
896 "You may give out copies of XEmacs; type "
|
|
897 (key describe-copying) " to see the conditions.\n"
|
|
898 "Type " (key describe-distribution)
|
|
899 " for information on getting the latest version.\n\n"
|
|
900
|
|
901 "Type " (key help-command) " or use the " (face bold "Help") " menu to get help.\n"
|
|
902 "Type " (key advertised-undo) " to undo changes (`C-' means use the Control key).\n"
|
|
903 "To get out of XEmacs, type " (key save-buffers-kill-emacs) ".\n"
|
|
904 "Type " (key help-with-tutorial) " for a tutorial on using XEmacs.\n"
|
|
905 "Type " (key info) " to enter Info, "
|
110
|
906 "which you can use to read online documentation.\n"
|
2
|
907 (face (bold red) ( "\
|
|
908 For tips and answers to frequently asked questions, see the XEmacs FAQ.
|
|
909 \(It's on the Help menu, or type " (key xemacs-local-faq) " [a capital F!].\)"))))
|
|
910
|
|
911 (defun startup-splash-frame ()
|
|
912 (let ((p (point))
|
|
913 (cramped-p (eq 'tty (console-type))))
|
|
914 (unless cramped-p (insert "\n"))
|
|
915 (indent-to (startup-center-spaces xemacs-logo))
|
|
916 (set-extent-begin-glyph (make-extent (point) (point)) xemacs-logo)
|
|
917 (insert (if cramped-p "\n" "\n\n"))
|
|
918 (splash-frame-present-hack (make-extent p (point)) 'about-xemacs))
|
|
919
|
70
|
920 (let ((after-change-functions nil)) ; no font-lock, thank you
|
2
|
921 (dolist (l (startup-splash-frame-body))
|
|
922 (splash-frame-present l)))
|
|
923 (set-buffer-modified-p nil))
|
|
924
|
70
|
925 ;; (let ((present-file
|
|
926 ;; #'(lambda (f)
|
|
927 ;; (splash-frame-present
|
|
928 ;; (list 'funcall
|
|
929 ;; (list 'find-file-other-window
|
|
930 ;; (expand-file-name f data-directory))
|
|
931 ;; f)))))
|
|
932 ;; (insert "For customization examples, see the files ")
|
|
933 ;; (funcall present-file "sample.emacs")
|
|
934 ;; (insert " and ")
|
|
935 ;; (funcall present-file "sample.Xdefaults")
|
|
936 ;; (insert (format "\nin the directory %s." data-directory)))
|
2
|
937
|
0
|
938
|
|
939 ;;;; Computing the default load-path, etc.
|
|
940 ;;;
|
|
941 ;;; This stuff is a complete mess and isn't nearly as general as it
|
|
942 ;;; thinks it is. It should be rethunk. In particular, too much logic
|
|
943 ;;; is duplicated between the code that looks around for the various
|
|
944 ;;; directories, and the code which suggests where to create the various
|
|
945 ;;; directories once it decides they are missing.
|
|
946
|
|
947 ;;; The source directory has this layout:
|
|
948 ;;;
|
|
949 ;;; BUILD_ROOT/src/xemacs* argv[0]
|
|
950 ;;; BUILD_ROOT/xemacs* argv[0], possibly
|
|
951 ;;; BUILD_ROOT/lisp/
|
|
952 ;;; BUILD_ROOT/etc/ data-directory
|
|
953 ;;; BUILD_ROOT/info/
|
|
954 ;;; BUILD_ROOT/lib-src/ exec-directory, doc-directory
|
|
955 ;;; BUILD_ROOT/lock/
|
|
956 ;;;
|
|
957 ;;; The default tree created by "make install" has this layout:
|
|
958 ;;;
|
|
959 ;;; PREFIX/bin/xemacs* argv[0]
|
|
960 ;;; PREFIX/lib/xemacs-VERSION/lisp/
|
|
961 ;;; PREFIX/lib/xemacs-VERSION/etc/ data-directory
|
|
962 ;;; PREFIX/lib/xemacs-VERSION/info/
|
|
963 ;;; PREFIX/lib/xemacs-VERSION/CONFIGURATION/ exec-directory, doc-directory
|
|
964 ;;; PREFIX/lib/xemacs/lock/
|
|
965 ;;; PREFIX/lib/xemacs/site-lisp/
|
|
966 ;;;
|
|
967 ;;; The binary packages we ship have that layout, except that argv[0] has
|
|
968 ;;; been moved one level deeper under the bin directory:
|
|
969 ;;;
|
|
970 ;;; PREFIX/bin/CONFIGURATION/xemacs*
|
|
971 ;;;
|
|
972 ;;; The following code has to deal with at least the above three situations,
|
|
973 ;;; and it should be possible for it to deal with more. Though perhaps that
|
|
974 ;;; does cover it all? The trick is, when something is missing, realizing
|
|
975 ;;; which of those three layouts is mostly in place, so that we can suggest
|
|
976 ;;; the right directories in the error message.
|
|
977
|
|
978
|
|
979 ;; extremely low-tech debugging, since this happens so early in startup.
|
70
|
980 ;;(or (fboundp 'orig-file-directory-p)
|
|
981 ;; (fset 'orig-file-directory-p (symbol-function 'file-directory-p)))
|
|
982 ;;(defun file-directory-p (path)
|
|
983 ;; (send-string-to-terminal (format "PROBING %S" path))
|
|
984 ;; (let ((v (orig-file-directory-p path)))
|
|
985 ;; (send-string-to-terminal (format " -> %S\n" v))
|
|
986 ;; v))
|
0
|
987
|
|
988 (defun startup-make-version-dir ()
|
|
989 (let ((version (and (string-match "\\`[^0-9]*\\([0-9]+\\.[0-9]+\\)"
|
|
990 emacs-version)
|
|
991 (substring emacs-version
|
|
992 (match-beginning 1) (match-end 1)))))
|
|
993 (if (string-match "(beta *\\([0-9]+\\))" emacs-version)
|
|
994 (setq version (concat version "-b"
|
|
995 (substring emacs-version (match-beginning 1)
|
|
996 (match-end 1)))))
|
|
997 (if (string-match "(alpha *\\([0-9]+\\))" emacs-version)
|
|
998 (setq version (concat version "-a"
|
|
999 (substring emacs-version (match-beginning 1)
|
|
1000 (match-end 1)))))
|
|
1001 (concat "lib/xemacs-" version)))
|
|
1002
|
|
1003 (defun find-emacs-root-internal-1 (path lisp-p)
|
|
1004 (let ((dir (file-name-directory path)))
|
|
1005 (or
|
|
1006 ;;
|
|
1007 ;; If this directory is a plausible root of the XEmacs tree, return it.
|
|
1008 ;;
|
|
1009 (and (or (not lisp-p)
|
|
1010 (file-directory-p (expand-file-name "lisp/prim" dir)))
|
|
1011 (or (file-directory-p (expand-file-name "lib-src" dir))
|
|
1012 (file-directory-p (expand-file-name system-configuration dir)))
|
|
1013 dir)
|
|
1014 ;;
|
|
1015 ;; If the parent of this directory is a plausible root, use it.
|
|
1016 ;; (But don't do so recursively!)
|
|
1017 ;;
|
|
1018 (and (or (not lisp-p)
|
|
1019 (file-directory-p (expand-file-name "../lisp/prim" dir)))
|
|
1020 (or (file-directory-p (expand-file-name
|
|
1021 (format "../%s" system-configuration)
|
|
1022 dir))
|
|
1023 (file-directory-p (expand-file-name "../lib-src" dir)))
|
|
1024 (expand-file-name "../" dir))
|
|
1025
|
|
1026 ;;
|
|
1027 ;; (--run-in-place) Same thing, but from one directory level deeper.
|
|
1028 ;;
|
|
1029 (and (or (not lisp-p)
|
|
1030 (file-directory-p (expand-file-name "../../lisp/prim" dir)))
|
|
1031 (or (file-directory-p (expand-file-name
|
|
1032 (format "../%s" system-configuration)
|
|
1033 dir))
|
|
1034 (file-directory-p
|
|
1035 (expand-file-name
|
|
1036 (format "../../lib-src/%s" system-configuration) dir)))
|
|
1037 (expand-file-name "../.." dir))
|
|
1038
|
|
1039 ;; If ../lib/xemacs-<version> exists check it.
|
|
1040 ;; This is of the form "xemacs-19.10/" or "xemacs-19.10-b7/".
|
|
1041 ;;
|
|
1042 (let ((ver-dir (concat "../" (startup-make-version-dir))))
|
|
1043 (and (or (not lisp-p)
|
|
1044 (file-directory-p (expand-file-name
|
|
1045 (format "%s/lisp/prim" ver-dir)
|
|
1046 dir)))
|
|
1047 (or (file-directory-p (expand-file-name
|
|
1048 (format "%s/%s" ver-dir
|
|
1049 system-configuration)
|
|
1050 dir))
|
|
1051 (file-directory-p (expand-file-name
|
|
1052 (format "%s/lib-src" ver-dir)
|
|
1053 dir)))
|
|
1054 (expand-file-name (file-name-as-directory ver-dir) dir)))
|
|
1055 ;;
|
|
1056 ;; Same thing, but one higher: ../../lib/xemacs-<version>.
|
|
1057 ;;
|
|
1058 (let ((ver-dir (concat "../../" (startup-make-version-dir))))
|
|
1059 (and (or (not lisp-p)
|
|
1060 (file-directory-p (expand-file-name
|
|
1061 (format "%s/lisp/prim" ver-dir)
|
|
1062 dir)))
|
|
1063 (or (file-directory-p (expand-file-name
|
|
1064 (format "%s/%s" ver-dir
|
|
1065 system-configuration)
|
|
1066 dir))
|
|
1067 (file-directory-p (expand-file-name
|
|
1068 (format "%s/lib-src" ver-dir)
|
|
1069 dir)))
|
|
1070 (expand-file-name (file-name-as-directory ver-dir) dir)))
|
|
1071 ;;
|
|
1072 ;; If that doesn't work, and the XEmacs executable is a symlink, then
|
|
1073 ;; chase the link and try again there.
|
|
1074 ;;
|
|
1075 (and (setq path (file-symlink-p path))
|
|
1076 (find-emacs-root-internal-1 (expand-file-name path dir) lisp-p))
|
|
1077 ;;
|
|
1078 ;; Otherwise, this directory just doesn't cut it.
|
|
1079 ;; Some bozos think they can use the 18.59 lisp directory with 19.*.
|
|
1080 ;; This is because they're not using their brains. But it might be
|
|
1081 ;; nice to notice that that is happening and point them in the
|
|
1082 ;; general direction of a clue.
|
|
1083 ;;
|
|
1084 nil)))
|
|
1085
|
|
1086 (defun find-emacs-root-internal (path)
|
70
|
1087 ;; (send-string-to-terminal (format "FINDING ROOT FOR %S\n" path))
|
0
|
1088 ;; first look for lisp/prim and lib-src; then just look for lib-src.
|
|
1089 ;; XEmacs can run (kind of) if the lisp directory is omitted, which
|
|
1090 ;; some people might want to do for space reasons.
|
|
1091 (or (find-emacs-root-internal-1 path t)
|
|
1092 (find-emacs-root-internal-1 path nil)
|
|
1093 ;; If we don't succeed we are going to crash and burn for sure.
|
|
1094 ;; Try some paths relative to prefix-directory if it isn't nil.
|
|
1095 ;; This is definitely necessary in cases such as when we're used
|
|
1096 ;; as a login shell since we can't determine the invocation
|
|
1097 ;; directory in that case.
|
|
1098 (find-emacs-root-internal-1
|
|
1099 (format "%s/bin/%s" prefix-directory invocation-name) t)
|
|
1100 (find-emacs-root-internal-1
|
|
1101 (format "%s/bin/%s" prefix-directory invocation-name) nil)
|
|
1102 (find-emacs-root-internal-1
|
|
1103 (format "%s/lib/%s" prefix-directory invocation-name) t)
|
|
1104 (find-emacs-root-internal-1
|
|
1105 (format "%s/lib/%s" prefix-directory invocation-name) nil)
|
|
1106 ))
|
|
1107
|
|
1108 (defun set-default-load-path ()
|
|
1109 ;; XEmacs -- Steven Baur says invocation directory is nil if you
|
|
1110 ;; try to use XEmacs as a login shell.
|
|
1111 (or invocation-directory (setq invocation-directory default-directory))
|
|
1112 (setq invocation-directory
|
|
1113 ;; don't let /tmp_mnt/... get into the load-path or exec-path.
|
|
1114 (abbreviate-file-name invocation-directory))
|
|
1115
|
|
1116 ;; #### FSFmacs recognizes environment vars EMACSLOCKDIR, etc.
|
|
1117 (let* ((root (find-emacs-root-internal (concat invocation-directory
|
|
1118 invocation-name)))
|
|
1119 (lisp (and root
|
|
1120 (let ((f (expand-file-name "lisp" root)))
|
|
1121 (and (file-directory-p f) f))))
|
70
|
1122 (site-lisp
|
|
1123 (and root
|
|
1124 (or
|
|
1125 (let ((f (expand-file-name "xemacs/site-lisp" root)))
|
|
1126 (and (file-directory-p f) f))
|
|
1127 (let ((f (expand-file-name "../xemacs/site-lisp" root)))
|
|
1128 (and (file-directory-p f) f))
|
|
1129 ;; the next two are for --run-in-place
|
|
1130 (let ((f (expand-file-name "site-lisp" root)))
|
|
1131 (and (file-directory-p f) f))
|
|
1132 (let ((f (expand-file-name "lisp/site-lisp" root)))
|
|
1133 (and (file-directory-p f) f))
|
|
1134 )))
|
|
1135 (lib-src
|
|
1136 (and root
|
|
1137 (or
|
|
1138 (let ((f (expand-file-name
|
|
1139 (concat "lib-src/" system-configuration)
|
|
1140 root)))
|
|
1141 (and (file-directory-p f) f))
|
|
1142 (let ((f (expand-file-name "lib-src" root)))
|
|
1143 (and (file-directory-p f) f))
|
|
1144 (let ((f (expand-file-name system-configuration root)))
|
|
1145 (and (file-directory-p f) f)))))
|
|
1146 (etc
|
|
1147 (and root
|
|
1148 (let ((f (expand-file-name "etc" root)))
|
|
1149 (and (file-directory-p f) f))))
|
|
1150 (info
|
|
1151 (and root
|
|
1152 (let ((f (expand-file-name "info" root)))
|
|
1153 (and (file-directory-p f) (file-name-as-directory f)))))
|
|
1154 (lock
|
|
1155 (and root
|
|
1156 (boundp 'lock-directory)
|
|
1157 (if (and lock-directory (file-directory-p lock-directory))
|
|
1158 (file-name-as-directory lock-directory)
|
|
1159 (or
|
|
1160 (let ((f (expand-file-name "xemacs/lock" root)))
|
|
1161 (and (file-directory-p f)
|
|
1162 (file-name-as-directory f)))
|
|
1163 (let ((f (expand-file-name "../xemacs/lock" root)))
|
|
1164 (and (file-directory-p f)
|
|
1165 (file-name-as-directory f)))
|
|
1166 (let ((f (expand-file-name "lock" root)))
|
|
1167 (and (file-directory-p f)
|
|
1168 (file-name-as-directory f)))
|
|
1169 ;; if none of them exist, make the "guess" be
|
|
1170 ;; the one that set-default-load-path-warning
|
|
1171 ;; will suggest.
|
|
1172 (file-name-as-directory
|
|
1173 (expand-file-name "../xemacs/lock" root))
|
|
1174 )))))
|
72
|
1175
|
|
1176 ;; 1996/12/6 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
1177 ;; define `default-load-path' for file-detect.el
|
|
1178 (setq default-load-path load-path)
|
|
1179
|
0
|
1180 ;; add site-lisp dir to load-path
|
70
|
1181 (when site-lisp
|
|
1182 ;; If the site-lisp dir isn't on the load-path, add it to the end.
|
|
1183 (or (member site-lisp load-path)
|
|
1184 (setq load-path (append load-path (list site-lisp))))
|
|
1185 ;; Also add any direct subdirectories of the site-lisp directory
|
|
1186 ;; to the load-path. But don't add dirs whose names begin
|
|
1187 ;; with dot or hyphen.
|
|
1188 (let ((files (directory-files site-lisp nil "^[^-.]" nil 'dirs-only))
|
|
1189 file)
|
|
1190 (while files
|
|
1191 (setq file (car files))
|
|
1192 (if (and (not (member file '("RCS" "CVS" "SCCS")))
|
|
1193 (setq file (expand-file-name file site-lisp))
|
|
1194 (not (member file load-path)))
|
|
1195 (setq load-path
|
|
1196 (nconc load-path
|
|
1197 (list (file-name-as-directory file)))))
|
|
1198 (setq files (cdr files)))))
|
|
1199
|
0
|
1200 ;; add lisp dir to load-path
|
70
|
1201 (when lisp
|
|
1202 ;; If the lisp dir isn't on the load-path, add it to the end.
|
|
1203 (or (member lisp load-path)
|
|
1204 (setq load-path (append load-path (list lisp))))
|
|
1205 ;; Also add any direct subdirectories of the lisp directory
|
|
1206 ;; to the load-path. But don't add dirs whose names begin
|
|
1207 ;; with dot or hyphen.
|
|
1208 (let ((files (directory-files lisp nil "^[^-.]" nil 'dirs-only))
|
|
1209 file)
|
|
1210 (while files
|
|
1211 (setq file (car files))
|
|
1212 (when (and (not (member file '("RCS" "CVS" "SCCS")))
|
|
1213 (setq file (expand-file-name file lisp))
|
|
1214 (not (member file load-path)))
|
|
1215 (setq load-path
|
|
1216 (nconc load-path
|
|
1217 (list (file-name-as-directory file)))))
|
|
1218 (setq files (cdr files)))))
|
32
|
1219
|
72
|
1220 ;; 1996/12/6 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
1221 ;; define `default-load-path' for file-detect.el
|
|
1222 (setq default-load-path
|
|
1223 (append default-load-path
|
|
1224 (if site-lisp
|
|
1225 (list site-lisp))
|
|
1226 (if lisp
|
|
1227 (list lisp)
|
|
1228 )
|
|
1229 ))
|
|
1230
|
110
|
1231 ;; 1997/03/06 by Jeff Miller <jmiller@bayserve.net>
|
|
1232 ;; initialize 'site-directory'. This is the site-lisp dir used by
|
|
1233 ;; XEmacs
|
|
1234 (if site-lisp
|
|
1235 (setq site-directory (file-name-as-directory site-lisp))
|
|
1236 )
|
0
|
1237 ;; If running from the build directory, always prefer the exec-directory
|
70
|
1238 ;; that is here over to the one that came from paths.h.
|
|
1239 (when (or (and (null exec-directory) lib-src)
|
|
1240 (and (string= lib-src (expand-file-name "lib-src" root))
|
|
1241 (not (string= exec-directory lib-src))))
|
|
1242 (setq exec-directory (file-name-as-directory lib-src)))
|
|
1243 (when (or (and (null doc-directory) lib-src)
|
|
1244 (and (string= lib-src (expand-file-name "lib-src" root))
|
|
1245 (not (string= doc-directory lib-src))))
|
|
1246 (setq doc-directory (file-name-as-directory lib-src)))
|
0
|
1247
|
70
|
1248 (when exec-directory
|
|
1249 (or (member exec-directory exec-path)
|
|
1250 (setq exec-path (append exec-path (list exec-directory)))))
|
|
1251 (when (or (and (null data-directory) etc)
|
|
1252 (and (string= etc (expand-file-name "etc" root))
|
|
1253 (not (string= data-directory etc))))
|
|
1254 (setq data-directory (file-name-as-directory etc)))
|
0
|
1255
|
|
1256
|
|
1257
|
|
1258 ;; If `configure' specified an info dir, use it.
|
|
1259 (or (boundp 'Info-default-directory-list)
|
|
1260 (setq Info-default-directory-list nil))
|
|
1261 (cond (configure-info-directory
|
|
1262 (setq configure-info-directory (file-name-as-directory
|
|
1263 configure-info-directory))
|
|
1264 (or (member configure-info-directory Info-default-directory-list)
|
|
1265 (setq Info-default-directory-list
|
|
1266 (append Info-default-directory-list
|
|
1267 (list configure-info-directory))))))
|
|
1268 ;; If we've guessed the info dir, use that (too).
|
70
|
1269 (when (and info (not (member info Info-default-directory-list)))
|
|
1270 (setq Info-default-directory-list
|
|
1271 (append Info-default-directory-list (list info))))
|
0
|
1272
|
|
1273 ;; Default the lock dir to being a sibling of the data-directory.
|
|
1274 ;; If superlock isn't set, or is set to a file in a nonexistent
|
|
1275 ;; directory, derive it from the lock dir.
|
70
|
1276 (when (boundp 'lock-directory)
|
|
1277 (setq lock-directory lock)
|
|
1278 (cond ((null lock-directory)
|
|
1279 (setq superlock-file nil))
|
|
1280 ((or (null superlock-file)
|
|
1281 (not (file-directory-p
|
|
1282 (file-name-directory superlock-file))))
|
|
1283 (setq superlock-file
|
|
1284 (expand-file-name "!!!SuperLock!!!"
|
|
1285 lock-directory)))))
|
0
|
1286
|
|
1287 (set-default-load-path-warning)))
|
|
1288
|
|
1289
|
|
1290 (defun set-default-load-path-warning ()
|
|
1291 (let ((lock (if (boundp 'lock-directory) lock-directory 't))
|
|
1292 warnings message guess)
|
70
|
1293 (when (and (stringp lock) (not (file-directory-p lock)))
|
|
1294 (setq lock nil))
|
0
|
1295 (cond
|
|
1296 ((not (and exec-directory data-directory doc-directory load-path lock))
|
|
1297 (save-excursion
|
|
1298 (set-buffer (get-buffer-create " *warning-tmp*"))
|
|
1299 (erase-buffer)
|
|
1300 (buffer-disable-undo (current-buffer))
|
70
|
1301 (when (null lock) (push "lock-directory" warnings))
|
|
1302 (when (null exec-directory) (push "exec-directory" warnings))
|
|
1303 (when (null data-directory) (push "data-directory" warnings))
|
|
1304 (when (null doc-directory) (push "doc-directory" warnings))
|
|
1305 (when (null load-path) (push "load-path" warnings))
|
0
|
1306 (cond ((cdr (cdr warnings))
|
|
1307 (setq message (apply 'format "%s, %s, and %s" warnings)))
|
|
1308 ((cdr warnings)
|
|
1309 (setq message (apply 'format "%s and %s" warnings)))
|
|
1310 (t (setq message (format "variable %s" (car warnings)))))
|
|
1311 (insert "couldn't find an obvious default for " message
|
|
1312 ", and there were no defaults specified in paths.h when "
|
|
1313 "XEmacs was built. Perhaps some directories don't exist, "
|
|
1314 "or the XEmacs executable, " (concat invocation-directory
|
|
1315 invocation-name)
|
|
1316 " is in a strange place?")
|
|
1317 (setq guess (or exec-directory
|
|
1318 data-directory
|
|
1319 doc-directory
|
|
1320 (car load-path)
|
|
1321 (and (string-match "/[^/]+\\'" invocation-directory)
|
|
1322 (substring invocation-directory 0
|
|
1323 (match-beginning 0)))))
|
70
|
1324 (when (and guess
|
|
1325 (or
|
|
1326 ;; parent of a terminal bin/<configuration> pair (hack hack).
|
|
1327 (string-match (concat "/bin/"
|
|
1328 (regexp-quote system-configuration)
|
|
1329 "/?\\'")
|
|
1330 guess)
|
|
1331 ;; parent of terminal src, lib-src, etc, or lisp dir.
|
|
1332 (string-match
|
|
1333 "/\\(bin\\|src\\|lib-src\\|etc\\|lisp\\)[^/]*/?\\'"
|
|
1334 guess)))
|
|
1335 (setq guess (substring guess 0 (match-beginning 0))))
|
0
|
1336
|
|
1337 ;; If neither the exec nor lisp dirs are around, then "guess" that
|
|
1338 ;; the new configure-style lib dir should be used. Otherwise, if
|
|
1339 ;; only one of them appears to be missing, or it's just lock,
|
|
1340 ;; then guess it to be a sibling of whatever already exists.
|
70
|
1341 (when (and (null exec-directory) (null load-path))
|
|
1342 (setq guess (expand-file-name (startup-make-version-dir) guess)))
|
0
|
1343
|
70
|
1344 (when (or (null exec-directory) (null load-path))
|
|
1345 (insert
|
|
1346 "\n\nWithout both exec-directory and load-path, XEmacs will "
|
|
1347 "be very broken. "))
|
|
1348 (when (and (null exec-directory) guess)
|
|
1349 (insert
|
|
1350 "Consider making a symbolic link from "
|
|
1351 (expand-file-name system-configuration guess)
|
|
1352 " to wherever the appropriate XEmacs exec-directory "
|
|
1353 "directory is"))
|
|
1354 (when (and (null data-directory) guess)
|
|
1355 (insert
|
|
1356 (if exec-directory
|
|
1357 "\n\nConsider making a symbolic link " ", and ")
|
|
1358 "from "
|
|
1359 (expand-file-name "etc" (if load-path
|
|
1360 (file-name-directory
|
|
1361 (directory-file-name
|
|
1362 (car load-path)))
|
|
1363 guess))
|
|
1364 " to wherever the appropriate XEmacs data-directory is"))
|
|
1365 (when (and (null load-path) guess)
|
|
1366 (insert
|
|
1367 (if (and exec-directory data-directory)
|
|
1368 "Consider making a symbolic link "
|
|
1369 ", and ")
|
|
1370 "from "
|
|
1371 (expand-file-name "lisp" guess)
|
|
1372 " to wherever the appropriate XEmacs lisp library is"))
|
0
|
1373 (insert ".")
|
|
1374
|
70
|
1375 (when (null lock)
|
|
1376 (insert
|
|
1377 "\n\nWithout lock-directory set, file locking won't work. ")
|
|
1378 (when guess
|
|
1379 (insert
|
|
1380 "Consider creating "
|
|
1381 (expand-file-name "../xemacs/lock"
|
|
1382 (or (find-emacs-root-internal
|
|
1383 (concat invocation-directory
|
|
1384 invocation-name))
|
|
1385 guess))
|
|
1386 " as a directory or symbolic link for use as the lock "
|
|
1387 "directory. (This directory must be globally writable.)"
|
|
1388 )))
|
0
|
1389
|
70
|
1390 (when (fboundp 'fill-region)
|
|
1391 ;; Might not be bound in the cold load environment...
|
|
1392 (let ((fill-column 76))
|
|
1393 (fill-region (point-min) (point-max))))
|
0
|
1394 (goto-char (point-min))
|
|
1395 (princ "\nWARNING:\n" 'external-debugging-output)
|
|
1396 (princ (buffer-string) 'external-debugging-output)
|
|
1397 (erase-buffer)
|
|
1398 t)))))
|
|
1399
|
|
1400 ;;; startup.el ends here
|