More changes for itcl.
[bpt/emacs.git] / lisp / startup.el
CommitLineData
c88ab9ce
ER
1;;; startup.el --- process Emacs shell arguments
2
1d7da582 3;; Copyright (C) 1985, 1986, 1992, 1994 Free Software Foundation, Inc.
eea8d4ef 4
630cc463 5;; Maintainer: FSF
d7b4d18f 6;; Keywords: internal
630cc463 7
a726e0d1
JB
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
4746118a 12;; the Free Software Foundation; either version 2, or (at your option)
a726e0d1
JB
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to
22;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
630cc463 24;;; Commentary:
a726e0d1 25
ab30fc8a
RS
26;; This file parses the command line and gets Emacs running. Options on
27;; the command line are handled in precedence order. The order is the
28;; one in the list below; first described means first handled. Options
29;; within each category (delimited by a bar) are handled in the order
30;; encountered on the command line.
31
32;; -------------------------
33;; -version Print Emacs version to stderr, then exit
34;; --version successfully right away.
35;; This option is handled by emacs.c
36;; -------------------------
37;; -help Print a short usage description and exit
38;; --help successfully right away.
39;; This option is handled by emacs.c
40;; -------------------------
41;; -nl Do not use shared memory (for systems that
42;; -no-shared-memory support this) for the dumped Emacs data.
43;; This option is handled by emacs.c
44;;
45;; -map For VMS.
46;; --map-data This option is handled by emacs.c
47;; -------------------------
48;; -t FILE Use FILE as the name of the terminal.
49;; --terminal FILE Using this implies "-nw" also.
50;; This option is handled by emacs.c
51;; -------------------------
52;; -d DISPNAME Use DISPNAME as the name of the X-windows
53;; -display DISPNAME display for the initial frame.
54;; --display DISPNAME This option is handled by emacs.c
55;; -------------------------
56;; -nw Do not use a windows system (but use the
57;; --no-windows terminal instead.)
58;; This option is handled by emacs.c
59;; -------------------------
60;; -batch Execute noninteractively (messages go to stdout,
61;; --batch variable noninteractive set to t)
62;; This option is handled by emacs.c
63;; -------------------------
64;; -q Do not load user's init file and do not load
65;; -no-init-file "default.el". Regardless of this switch,
66;; --no-init-file "site-init.el" is still loaded.
67;; -------------------------
68;; -no-site-file Do not load "site-init.el". (This is the ONLY
69;; --no-site-file way to prevent loading that file.)
70;; -------------------------
71;; -u USER Load USER's init file instead of the init
72;; -user USER file belonging to the user starting Emacs.
73;; --user USER
74;; -------------------------
75;; -debug-init Don't catch errors in init files; let the
76;; --debug-init debugger run.
77;; -------------------------
78;; -i ICONTYPE Set type of icon using when Emacs is
79;; -itype ICONTYPE iconified under X-windows.
80;; --icon-type ICONTYPE This option is passed on to term/x-win.el
81;;
82;; -iconic Start Emacs iconified under X-windows.
83;; --iconic This option is passed on to term/x-win.el
84;; -------------------------
85;; Various X-windows options for colors/fonts/geometry/title etc.
86;; These options are passed on to term/x-win.el which see. Certain
87;; of these are also found in term/pc-win.el
88;; -------------------------
89;; FILE Visit FILE.
90;;
91;; -L DIRNAME Add DIRNAME to load-path
92;; -directory DIRNAME
93;; --directory DIRNAME
94;;
95;; -l FILE Load and execute the Emacs lisp code
96;; -load FILE in FILE.
97;; --load FILE
98;;
99;; -f FUNC Execute Emacs lisp function FUNC with
100;; -funcall FUNC no arguments. The "-e" form is outdated
101;; --funcall FUNC and should not be used. (It's a typo
102;; -e FUNC promoted to a feature.)
103;;
104;; -insert FILE Insert the contents of FILE into buffer.
105;; --insert FILE
106;; -------------------------
107;; -kill Kill (exit) Emacs right away.
108;; --kill
109;; -------------------------
a726e0d1 110
630cc463
ER
111;;; Code:
112
a726e0d1
JB
113(setq top-level '(normal-top-level))
114
115(defvar command-line-processed nil "t once command line has been processed")
116
117(defconst inhibit-startup-message nil
1d7da582 118 "*Non-nil inhibits the initial startup message.
a726e0d1
JB
119This is for use in your personal init file, once you are familiar
120with the contents of the startup message.")
121
1d7da582
RS
122(defconst inhibit-startup-echo-area-message nil
123 "*Non-nil inhibits the initial startup echo area message.
124Inhibition takes effect only if your `.emacs' file contains
e5575c06 125a line of this form:
54a003f7 126 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
e5575c06
RS
127If your `.emacs' file is byte-compiled, use the following form instead:
128 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
1d7da582
RS
129Thus, someone else using a copy of your `.emacs' file will see
130the startup message unless he personally acts to inhibit it.")
131
a726e0d1
JB
132(defconst inhibit-default-init nil
133 "*Non-nil inhibits loading the `default' library.")
134
135(defconst command-switch-alist nil
136 "Alist of command-line switches.
137Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
138HANDLER-FUNCTION receives switch name as sole arg;
139remaining command-line args are in the variable `command-line-args-left'.")
140
860befc8
RS
141(defvar command-line-args-left nil
142 "List of command-line args not yet processed.")
143
a726e0d1
JB
144(defvar command-line-functions nil ;; lrs 7/31/89
145 "List of functions to process unrecognized command-line arguments.
146Each function should access the dynamically bound variables
b4484ea8 147`argi' (the current argument) and `command-line-args-left' (the remaining
a726e0d1 148arguments). The function should return non-nil only if it recognizes and
b4484ea8
RS
149processes `argi'. If it does so, it may consume successive arguments by
150altering `command-line-args-left' to remove them.")
a726e0d1 151
09a1077c
RS
152(defvar command-line-default-directory nil
153 "Default directory to use for command line arguments.
154This is normally copied from `default-directory' when Emacs starts.")
155
e3bd99f5 156(defvar before-init-hook nil
b4484ea8 157 "Functions to call after handling urgent options but before init files.
0cc89026 158The frame system uses this to open frames to display messages while
3fc958a4
JB
159Emacs loads the user's initialization file.")
160
e3bd99f5 161(defvar after-init-hook nil
a0965605 162 "Functions to call after loading the init file (`~/.emacs').
e3bd99f5 163The call is not protected by a condition-case, so you can set `debug-on-error'
a0965605 164in `.emacs', and put all the actual code on `after-init-hook'.")
e3bd99f5 165
a726e0d1 166(defvar term-setup-hook nil
b4484ea8 167 "Functions to be called after loading terminal-specific Lisp code.
e3bd99f5 168See `run-hooks'. This variable exists for users to set,
a726e0d1
JB
169so as to override the definitions made by the terminal-specific file.
170Emacs never sets this variable itself.")
171
172(defvar keyboard-type nil
b4484ea8
RS
173 "The brand of keyboard you are using.
174This variable is used to define
a726e0d1
JB
175the proper function and keypad keys for use under X. It is used in a
176fashion analogous to the environment value TERM.")
177
178(defvar window-setup-hook nil
b4484ea8
RS
179 "Normal hook run to initialize window system display.
180Emacs runs this hook after processing the command line arguments and loading
181the user's init file.")
a726e0d1
JB
182
183(defconst initial-major-mode 'lisp-interaction-mode
184 "Major mode command symbol to use for the initial *scratch* buffer.")
185
186(defvar init-file-user nil
187 "Identity of user whose `.emacs' file is or was read.
2bdfaa42
KH
188The value is nil if no init file is being used; otherwise, it may be either
189the null string, meaning that the init file was taken from the user that
190originally logged in, or it may be a string containing a user's name.
a726e0d1 191
2bdfaa42
KH
192In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
193evaluates to the name of the directory where the `.emacs' file was
13fce4e6
RS
194looked for.
195
196Setting `init-file-user' does not prevent Emacs from loading
197`site-start.el'. The only way to do that is to use `--no-site-file'.")
a726e0d1 198
b7444d31
RS
199(defvar site-run-file "site-start"
200 "File containing site-wide run-time initializations.
201This file is loaded at run-time before `~/.emacs'. It contains inits
202that need to be in place for the entire site, but which, due to their
203higher incidence of change, don't make sense to load into emacs'
204dumped image. Thus, the run-time load order is: 1. file described in
13fce4e6
RS
205this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
206
207Don't use the `site-start.el' file for things some users may not like.
208Put them in `default.el' instead, so that users can more easily
209override them. Users can prevent loading `default.el' with the `-q'
210option or by setting `inhibit-default-init' in their own init files,
211but inhibiting `site-start.el' requires `--no-site-file', which
212is less convenient.")
b7444d31 213
30dc01ea
RS
214(defconst iso-8859-1-locale-regexp "8859[-_]?1"
215 "Regexp that specifies when to enable the ISO 8859-1 character set.
216We do that if this regexp matches the locale name
217specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
218
c13fbb62
RS
219(defvar mail-host-address nil
220 "*Name of this machine, for purposes of naming users.")
221
c10d1f06 222(defvar user-mail-address nil
c13fbb62 223 "*Full mailing address of this user.")
c10d1f06 224
a726e0d1
JB
225(defvar init-file-debug nil)
226
52320897
RS
227(defvar init-file-had-error nil)
228
e87a7309
RS
229;; This function is called from the subdirs.el file.
230(defun normal-top-level-add-to-load-path (dirs)
231 (let ((tail (member default-directory load-path)))
232 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail)))))
233
a726e0d1
JB
234(defun normal-top-level ()
235 (if command-line-processed
236 (message "Back to top level.")
237 (setq command-line-processed t)
8d4c2221
RS
238 ;; Give *Messages* the same default-directory as *scratch*,
239 ;; just to keep things predictable.
240 (let ((dir default-directory))
241 (save-excursion
242 (set-buffer (get-buffer "*Messages*"))
243 (setq default-directory dir)))
e87a7309
RS
244 ;; Look in each dir in load-path for a subdirs.el file.
245 ;; If we find one, load it, which will add the appropriate subdirs
246 ;; of that dir into load-path,
247 (let ((tail load-path)
248 new)
249 (while tail
250 (setq new (cons (car tail) new))
251 (let ((default-directory (car tail)))
252 (load (expand-file-name "subdirs.el" (car tail)) t t t))
253 (setq tail (cdr tail))))
ffd56f97 254 (if (not (eq system-type 'vax-vms))
a4b33896
JB
255 (progn
256 ;; If the PWD environment variable isn't accurate, delete it.
257 (let ((pwd (getenv "PWD")))
258 (and (stringp pwd)
259 ;; Use FOO/., so that if FOO is a symlink, file-attributes
260 ;; describes the directory linked to, not FOO itself.
261 (or (equal (file-attributes
262 (concat (file-name-as-directory pwd) "."))
263 (file-attributes
264 (concat (file-name-as-directory default-directory)
265 ".")))
266 (setq process-environment
267 (delete (concat "PWD=" pwd)
268 process-environment)))))))
492878e4 269 (setq default-directory (abbreviate-file-name default-directory))
c13fbb62
RS
270 (setq user-mail-address (concat (user-login-name) "@"
271 (or mail-host-address
272 (system-name))))
0b9d4cf0
RS
273 ;; Specify the file for recording all the auto save files of this session.
274 ;; This is used by multiple-recover.
275 (setq auto-save-list-file-name
276 (expand-file-name
277 (format "~/.saves-%d-%s"
278 (emacs-pid)
279 (or mail-host-address (system-name)))))
6f2c86fa
KH
280 (let ((menubar-bindings-done nil))
281 (unwind-protect
282 (command-line)
283 ;; Do this again, in case .emacs defined more abbreviations.
284 (setq default-directory (abbreviate-file-name default-directory))
285 (run-hooks 'emacs-startup-hook)
286 (and term-setup-hook
287 (run-hooks 'term-setup-hook))
288 ;; Modify the initial frame based on what .emacs puts into
289 ;; ...-frame-alist.
290 (if (fboundp 'frame-notice-user-settings)
291 (frame-notice-user-settings))
292 ;; Now we know the user's default font, so add it to the menu.
293 (if (fboundp 'font-menu-add-default)
294 (font-menu-add-default))
295 (and window-setup-hook
296 (run-hooks 'window-setup-hook))
297 (or menubar-bindings-done
365636dc
RS
298 (if (eq window-system 'x)
299 (precompute-menubar-bindings)))))))
6f2c86fa
KH
300
301;; Precompute the keyboard equivalents in the menu bar items.
302(defun precompute-menubar-bindings ()
365636dc
RS
303 (let ((submap (lookup-key global-map [menu-bar])))
304 (while submap
305 (and (consp (car submap))
306 (symbolp (car (car submap)))
307 (stringp (car-safe (cdr (car submap))))
308 (keymapp (cdr (cdr (car submap))))
a18042d7
RS
309 (progn
310 (x-popup-menu nil (cdr (cdr (car submap))))
311 (if purify-flag
312 (garbage-collect))))
365636dc
RS
313 (setq submap (cdr submap))))
314 (setq define-key-rebound-commands t))
a726e0d1
JB
315
316(defun command-line ()
09a1077c
RS
317 (setq command-line-default-directory default-directory)
318
74f2ab06 319 ;; See if we should import version-control from the environment variable.
a726e0d1
JB
320 (let ((vc (getenv "VERSION_CONTROL")))
321 (cond ((eq vc nil)) ;don't do anything if not set
322 ((or (string= vc "t")
323 (string= vc "numbered"))
324 (setq version-control t))
325 ((or (string= vc "nil")
326 (string= vc "existing"))
327 (setq version-control nil))
328 ((or (string= vc "never")
329 (string= vc "simple"))
330 (setq version-control 'never))))
331
30dc01ea
RS
332 (if (let ((ctype
333 ;; Use the first of these three envvars that has a nonempty value.
334 (or (let ((string (getenv "LC_ALL")))
335 (and (not (equal string "")) string))
336 (let ((string (getenv "LC_CTYPE")))
337 (and (not (equal string "")) string))
338 (let ((string (getenv "LANG")))
339 (and (not (equal string "")) string)))))
340 (and ctype
341 (string-match iso-8859-1-locale-regexp ctype)))
e9d8e8c7 342 (progn
62bb5440 343 (require 'disp-table)
e9d8e8c7
RS
344 (standard-display-european t)
345 (require 'iso-syntax)))
346
79058860
JB
347 ;;! This has been commented out; I currently find the behavior when
348 ;;! split-window-keep-point is nil disturbing, but if I can get used
349 ;;! to it, then it would be better to eliminate the option.
350 ;;! ;; Choose a good default value for split-window-keep-point.
351 ;;! (setq split-window-keep-point (> baud-rate 2400))
f35fe3c6 352
a726e0d1 353 ;; Read window system's init file if using a window system.
1ed14cfd
RS
354 (condition-case error
355 (if (and window-system (not noninteractive))
356 (load (concat term-file-prefix
357 (symbol-name window-system)
358 "-win")
359 ;; Every window system should have a startup file;
360 ;; barf if we can't find it.
361 nil t))
362 ;; If we can't read it, print the error message and exit.
363 (error
2677ad61
RS
364 (princ
365 (if (eq (car error) 'error)
366 (apply 'concat (cdr error))
367 (if (memq 'file-error (get (car error) 'error-conditions))
368 (format "%s: %s"
369 (nth 1 error)
370 (mapconcat '(lambda (obj) (prin1-to-string obj t))
371 (cdr (cdr error)) ", "))
372 (format "%s: %s"
373 (get (car error) 'error-message)
374 (mapconcat '(lambda (obj) (prin1-to-string obj t))
375 (cdr error) ", "))))
376 'external-debugging-output)
377 (setq window-system nil)
1ed14cfd 378 (kill-emacs)))
a726e0d1 379
03e3c30a
JB
380 (let ((done nil)
381 (args (cdr command-line-args)))
382
a726e0d1
JB
383 ;; Figure out which user's init file to load,
384 ;; either from the environment or from the options.
385 (setq init-file-user (if noninteractive nil (user-login-name)))
386 ;; If user has not done su, use current $HOME to find .emacs.
387 (and init-file-user (string= init-file-user (user-real-login-name))
388 (setq init-file-user ""))
03e3c30a
JB
389
390 ;; Process the command-line args, and delete the arguments
391 ;; processed. This is consistent with the way main in emacs.c
392 ;; does things.
a726e0d1 393 (while (and (not done) args)
096b7031 394 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
a360cae9 395 ("--debug-init") ("--iconic") ("--icon-type")))
096b7031
KH
396 (argi (car args))
397 (argval nil))
398 (if (string-match "=" argi)
a981e7ff
KH
399 (setq argval (substring argi (match-end 0))
400 argi (substring argi 0 (match-beginning 0))))
096b7031
KH
401 (let ((completion (try-completion argi longopts)))
402 (if (eq completion t)
403 (setq argi (substring argi 1))
404 (if (stringp completion)
405 (let ((elt (assoc completion longopts)))
406 (or elt
407 (error "Option `%s' is ambiguous" argi))
3f53ddd0
RS
408 (setq argi (substring (car elt) 1)))
409 (setq argval nil))))
a726e0d1
JB
410 (cond
411 ((or (string-equal argi "-q")
412 (string-equal argi "-no-init-file"))
413 (setq init-file-user nil
414 args (cdr args)))
415 ((or (string-equal argi "-u")
416 (string-equal argi "-user"))
096b7031 417 (or argval
d3bea05f
RS
418 (setq args (cdr args)
419 argval (car args)))
096b7031
KH
420 (setq init-file-user argval
421 argval nil
a726e0d1 422 args (cdr args)))
b7444d31
RS
423 ((string-equal argi "-no-site-file")
424 (setq site-run-file nil
425 args (cdr args)))
a726e0d1
JB
426 ((string-equal argi "-debug-init")
427 (setq init-file-debug t
428 args (cdr args)))
a360cae9
RS
429 ((string-equal argi "-iconic")
430 (setq initial-frame-alist
431 (cons '(visibility . icon) initial-frame-alist))
432 (setq args (cdr args)))
433 ((or (string-equal argi "-icon-type")
434 (string-equal argi "-i")
435 (string-equal argi "-itype"))
436 (setq default-frame-alist
437 (cons '(icon-type . t) default-frame-alist))
438 (setq args (cdr args)))
096b7031
KH
439 (t (setq done t)))
440 ;; Was argval set but not used?
441 (and argval
442 (error "Option `%s' doesn't allow an argument" argi))))
443
03e3c30a 444 ;; Re-attach the program name to the front of the arg list.
4048e56d 445 (and command-line-args (setcdr command-line-args args)))
a726e0d1 446
c722566c 447 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
4e1b1e72
JB
448 (if (fboundp 'face-initialize)
449 (face-initialize))
853ccbd5
RS
450 (if (fboundp 'frame-initialize)
451 (frame-initialize))
1fe0333f
RS
452 ;; If frame was created with a menu bar, set menu-bar-mode on.
453 (if (and (eq window-system 'x)
454 (> (cdr (assq 'menu-bar-lines (frame-parameters))) 0))
455 (menu-bar-mode t))
c722566c 456
e3bd99f5 457 (run-hooks 'before-init-hook)
3fc958a4 458
09973c54
RM
459 ;; Run the site-start library if it exists. The point of this file is
460 ;; that it is run before .emacs. There is no point in doing this after
461 ;; .emacs; that is useless.
b7444d31
RS
462 (if site-run-file
463 (load site-run-file t t))
09973c54 464
8a988f45
RS
465 ;; Sites should not disable this. Only individuals should disable
466 ;; the startup message.
467 (setq inhibit-startup-message nil)
468
a726e0d1 469 ;; Load that user's init file, or the default one, or none.
3d1b78f0
RS
470 (let (debug-on-error-from-init-file
471 debug-on-error-should-be-set
472 (debug-on-error-initial
473 (if (eq init-file-debug t) 'startup init-file-debug)))
474 (let ((debug-on-error debug-on-error-initial)
475 ;; This function actually reads the init files.
476 (inner
477 (function
478 (lambda ()
479 (if init-file-user
a4c5c705
RS
480 (progn
481 (setq user-init-file
482 (cond
483 ((eq system-type 'ms-dos)
484 (concat "~" init-file-user "/_emacs"))
7d1aa45d
RS
485 ((eq system-type 'windows-nt)
486 "~/_emacs")
a4c5c705
RS
487 ((eq system-type 'vax-vms)
488 "sys$login:.emacs")
489 (t
490 (concat "~" init-file-user "/.emacs"))))
491 (load user-init-file t t t)
492 (or inhibit-default-init
493 (let ((inhibit-startup-message nil))
494 ;; Users are supposed to be told their rights.
495 ;; (Plus how to get help and how to undo.)
496 ;; Don't you dare turn this off for anyone
497 ;; except yourself.
498 (load "default" t t)))))))))
3d1b78f0
RS
499 (if init-file-debug
500 ;; Do this without a condition-case if the user wants to debug.
501 (funcall inner)
502 (condition-case error
503 (progn
504 (funcall inner)
505 (setq init-file-had-error nil))
506 (error (message "Error in init file: %s%s%s"
507 (get (car error) 'error-message)
ad2aeb8d 508 (if (cdr error) ": " "")
3d1b78f0
RS
509 (mapconcat 'prin1-to-string (cdr error) ", "))
510 (setq init-file-had-error t))))
ad2aeb8d 511 ;; If we can tell that the init file altered debug-on-error,
3d1b78f0
RS
512 ;; arrange to preserve the value that it set up.
513 (or (eq debug-on-error debug-on-error-initial)
514 (setq debug-on-error-should-be-set t
515 debug-on-error-from-init-file debug-on-error)))
516 (if debug-on-error-should-be-set
517 (setq debug-on-error debug-on-error-from-init-file)))
3fc958a4 518
e3bd99f5
RM
519 (run-hooks 'after-init-hook)
520
a726e0d1
JB
521 ;; If *scratch* exists and init file didn't change its mode, initialize it.
522 (if (get-buffer "*scratch*")
523 (save-excursion
524 (set-buffer "*scratch*")
525 (if (eq major-mode 'fundamental-mode)
526 (funcall initial-major-mode))))
527 ;; Load library for our terminal type.
528 ;; User init file can set term-file-prefix to nil to prevent this.
529 (and term-file-prefix (not noninteractive) (not window-system)
530 (let ((term (getenv "TERM"))
531 hyphend)
532 (while (and term
533 (not (load (concat term-file-prefix term) t t)))
534 ;; Strip off last hyphen and what follows, then try again
535 (if (setq hyphend (string-match "[-_][^-_]+$" term))
536 (setq term (substring term 0 hyphend))
537 (setq term nil)))))
538
03e3c30a 539 ;; Process the remaining args.
a726e0d1
JB
540 (command-line-1 (cdr command-line-args))
541
542 ;; If -batch, terminate after processing the command options.
543 (if noninteractive (kill-emacs t)))
544
545(defun command-line-1 (command-line-args-left)
52320897 546 (or noninteractive (input-pending-p) init-file-had-error
1d7da582
RS
547 (and inhibit-startup-echo-area-message
548 (let ((buffer (get-buffer-create " *temp*")))
549 (prog1
550 (condition-case nil
551 (save-excursion
552 (set-buffer buffer)
553 (insert-file-contents user-init-file)
554 (re-search-forward
555 (concat
d9a71a8f
RS
556 "([ \t\n]*setq[ \t\n]+"
557 "inhibit-startup-echo-area-message[ \t\n]+"
558 (regexp-quote
559 (prin1-to-string
560 (if (string= init-file-user "")
561 (user-login-name)
562 init-file-user)))
563 "[ \t\n]*)")
1d7da582
RS
564 nil t))
565 (error nil))
566 (kill-buffer buffer))))
567 (message (if (eq (key-binding "\C-h\C-p") 'describe-project)
568 "For information about the GNU Project and its goals, type C-h C-p."
569 (substitute-command-keys
570 "For information about the GNU Project and its goals, type \\[describe-project]."))))
a726e0d1
JB
571 (if (null command-line-args-left)
572 (cond ((and (not inhibit-startup-message) (not noninteractive)
573 ;; Don't clobber a non-scratch buffer if init file
574 ;; has selected it.
575 (string= (buffer-name) "*scratch*")
576 (not (input-pending-p)))
577 ;; If there are no switches to process, we might as well
578 ;; run this hook now, and there may be some need to do it
579 ;; before doing any output.
580 (and term-setup-hook
581 (run-hooks 'term-setup-hook))
582 ;; Don't let the hook be run twice.
583 (setq term-setup-hook nil)
4e1b1e72
JB
584
585 ;; It's important to notice the user settings before we
586 ;; display the startup message; otherwise, the settings
587 ;; won't take effect until the user gives the first
588 ;; keystroke, and that's distracting.
589 (if (fboundp 'frame-notice-user-settings)
590 (frame-notice-user-settings))
591
a726e0d1
JB
592 (and window-setup-hook
593 (run-hooks 'window-setup-hook))
594 (setq window-setup-hook nil)
fd11871a
RS
595 ;; Do this now to avoid an annoying delay if the user
596 ;; clicks the menu bar during the sit-for.
365636dc
RS
597 (if (eq window-system 'x)
598 (precompute-menubar-bindings))
fd11871a 599 (setq menubar-bindings-done t)
a726e0d1
JB
600 (unwind-protect
601 (progn
602 (insert (emacs-version)
603 "
1d7da582 604Copyright (C) 1994 Free Software Foundation, Inc.\n\n")
a726e0d1
JB
605 ;; If keys have their default meanings,
606 ;; use precomputed string to save lots of time.
607 (if (and (eq (key-binding "\C-h") 'help-command)
608 (eq (key-binding "\C-xu") 'advertised-undo)
609 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
e65a6404
RS
610 (eq (key-binding "\C-ht") 'help-with-tutorial)
611 (eq (key-binding "\C-hi") 'info))
a726e0d1
JB
612 (insert
613 "Type C-h for help; C-x u to undo changes. (`C-' means use CTRL key.)
614To kill the Emacs job, type C-x C-c.
615Type C-h t for a tutorial on using Emacs.
e65a6404
RS
616Type C-h i to enter Info, which you can use to read GNU documentation.")
617 (insert (substitute-command-keys
618 (format "Type %s for help; \\[advertised-undo] to undo changes. (`C-' means use CTRL key.)
619To kill the Emacs job, type \\[save-buffers-kill-emacs].
620Type \\[help-with-tutorial] for a tutorial on using Emacs.
621Type \\[info] to enter Info, which you can use to read GNU documentation."
622 (let ((where (where-is-internal
623 'help-command nil t)))
624 (if where
625 (key-description where)
626 "M-x help"))))))
627
628 ;; Windows and MSDOS (currently) do not count as
629 ;; window systems, but do have mouse support.
1ca92e26 630 (if (or (memq system-type '(msdos windowsnt))
e65a6404
RS
631 window-system)
632 (insert "
633C-mouse-3 (third mouse button, with Control) gets a mode-specific menu."))
634 (insert "\n")
635 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
636 (eq (key-binding "\C-h\C-d") 'describe-distribution)
637 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
638 (insert
639 "
a726e0d1
JB
640GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
641You may give out copies of Emacs; type C-h C-c to see the conditions.
642Type C-h C-d for information on getting the latest version.")
643 (insert (substitute-command-keys
e65a6404 644 "
a726e0d1
JB
645GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
646You may give out copies of Emacs; type \\[describe-copying] to see the conditions.
647Type \\[describe-distribution] for information on getting the latest version.")))
648 (set-buffer-modified-p nil)
649 (sit-for 120))
650 (save-excursion
651 ;; In case the Emacs server has already selected
652 ;; another buffer, erase the one our message is in.
653 (set-buffer (get-buffer "*scratch*"))
654 (erase-buffer)
655 (set-buffer-modified-p nil)))))
eca1cf26
RS
656 ;; Delay 2 seconds after the init file error message
657 ;; was displayed, so user can read it.
658 (if init-file-had-error
659 (sit-for 2))
09a1077c 660 (let ((dir command-line-default-directory)
a726e0d1
JB
661 (file-count 0)
662 first-file-buffer
663 (line 0))
664 (while command-line-args-left
3f53ddd0
RS
665 (let* ((argi (car command-line-args-left))
666 (orig-argi argi)
667 ;; This includes our standard options' long versions
668 ;; and long versions of what's on command-switch-alist.
669 (longopts
aba66e2a
RS
670 (append '(("--funcall") ("--load") ("--insert") ("--kill")
671 ("--directory"))
3f53ddd0
RS
672 (mapcar '(lambda (elt)
673 (list (concat "-" (car elt))))
674 command-switch-alist)))
aba66e2a
RS
675 tem argval completion
676 ;; List of directories specified in -L/--directory,
677 ;; in reverse of the order specified.
678 extra-load-path
679 (initial-load-path load-path))
a726e0d1 680 (setq command-line-args-left (cdr command-line-args-left))
3f53ddd0
RS
681
682 ;; Convert long options to ordinary options
683 ;; and separate out an attached option argument into argval.
684 (if (string-match "^--[^=]*=" argi)
685 (setq argval (substring argi (match-end 0))
686 argi (substring argi 0 (1- (match-end 0)))))
687 (setq completion (try-completion argi longopts))
688 (if (eq completion t)
689 (setq argi (substring argi 1))
690 (if (stringp completion)
691 (let ((elt (assoc completion longopts)))
692 (or elt
693 (error "Option `%s' is ambiguous" argi))
694 (setq argi (substring (car elt) 1)))
695 (setq argval nil argi orig-argi)))
696
697 ;; Execute the option.
a726e0d1 698 (cond ((setq tem (assoc argi command-switch-alist))
3f53ddd0
RS
699 (if argval
700 (let ((command-line-args-left
701 (cons argval command-line-args-left)))
702 (funcall (cdr tem) argi))
703 (funcall (cdr tem) argi)))
a726e0d1
JB
704 ((or (string-equal argi "-f") ;what the manual claims
705 (string-equal argi "-funcall")
706 (string-equal argi "-e")) ; what the source used to say
3f53ddd0
RS
707 (if argval
708 (setq tem (intern argval))
709 (setq tem (intern (car command-line-args-left)))
710 (setq command-line-args-left (cdr command-line-args-left)))
1908c565
RS
711 (if (arrayp (symbol-function tem))
712 (command-execute tem)
713 (funcall tem)))
aba66e2a
RS
714 ;; Set the default directory as specified in -L.
715 ((or (string-equal argi "-L")
716 (string-equal argi "-directory"))
717 (if argval
718 (setq tem argval)
719 (setq tem (car command-line-args-left)
720 command-line-args-left (cdr command-line-args-left)))
721 (setq extra-load-path
722 (cons (expand-file-name tem) extra-load-path))
723 (setq load-path (append (nreverse extra-load-path)
724 initial-load-path)))
a726e0d1
JB
725 ((or (string-equal argi "-l")
726 (string-equal argi "-load"))
3f53ddd0
RS
727 (if argval
728 (setq tem argval)
729 (setq tem (car command-line-args-left)
730 command-line-args-left (cdr command-line-args-left)))
731 (let ((file tem))
a726e0d1
JB
732 ;; Take file from default dir if it exists there;
733 ;; otherwise let `load' search for it.
734 (if (file-exists-p (expand-file-name file))
735 (setq file (expand-file-name file)))
3f53ddd0 736 (load file nil t)))
fbce8654 737 ((string-equal argi "-insert")
cf91c6c8 738 (or (stringp (car command-line-args-left))
3f53ddd0
RS
739 (error "File name omitted from `-insert' option"))
740 (if argval
741 (setq tem argval)
742 (setq tem (car command-line-args-left)
743 command-line-args-left (cdr command-line-args-left)))
744 (insert-file-contents tem))
a726e0d1
JB
745 ((string-equal argi "-kill")
746 (kill-emacs t))
747 ((string-match "^\\+[0-9]+\\'" argi)
748 (setq line (string-to-int argi)))
749 (t
750 ;; We have almost exhausted our options. See if the
751 ;; user has made any other command-line options available
752 (let ((hooks command-line-functions);; lrs 7/31/89
753 (did-hook nil))
754 (while (and hooks
755 (not (setq did-hook (funcall (car hooks)))))
756 (setq hooks (cdr hooks)))
757 (if (not did-hook)
758 ;; Ok, presume that the argument is a file name
759 (progn
760 (setq file-count (1+ file-count))
761 (cond ((= file-count 1)
762 (setq first-file-buffer
763 (find-file (expand-file-name argi dir))))
764 (t
765 (find-file-other-window (expand-file-name argi dir))))
766 (or (zerop line)
767 (goto-line line))
768 (setq line 0))))))))
769 ;; If 3 or more files visited, and not all visible,
770 ;; show user what they all are.
771 (if (> file-count 2)
772 (or (get-buffer-window first-file-buffer)
7e0795a4 773 (progn (other-window 1)
e8997612 774 (buffer-menu)))))))
c88ab9ce
ER
775
776;;; startup.el ends here