]> code.delx.au - gnu-emacs/blob - lisp/startup.el
(Man-filter-list): Recognize "Rev" footers.
[gnu-emacs] / lisp / startup.el
1 ;;; startup.el --- process Emacs shell arguments
2
3 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Keywords: internal
7
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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
24 ;;; Commentary:
25
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-start" is still loaded.
67 ;; -------------------------
68 ;; -no-site-file Do not load "site-start.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 ;; -eval FORM Execute Emacs lisp form FORM.
105 ;; --eval FORM
106 ;;
107 ;; -insert FILE Insert the contents of FILE into buffer.
108 ;; --insert FILE
109 ;; -------------------------
110 ;; -kill Kill (exit) Emacs right away.
111 ;; --kill
112 ;; -------------------------
113
114 ;;; Code:
115
116 (setq top-level '(normal-top-level))
117
118 (defvar command-line-processed nil "t once command line has been processed")
119
120 (defconst inhibit-startup-message nil
121 "*Non-nil inhibits the initial startup message.
122 This is for use in your personal init file, once you are familiar
123 with the contents of the startup message.")
124
125 (defconst inhibit-startup-echo-area-message nil
126 "*Non-nil inhibits the initial startup echo area message.
127 Inhibition takes effect only if your `.emacs' file contains
128 a line of this form:
129 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
130 If your `.emacs' file is byte-compiled, use the following form instead:
131 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
132 Thus, someone else using a copy of your `.emacs' file will see
133 the startup message unless he personally acts to inhibit it.")
134
135 (defconst inhibit-default-init nil
136 "*Non-nil inhibits loading the `default' library.")
137
138 (defconst command-switch-alist nil
139 "Alist of command-line switches.
140 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
141 HANDLER-FUNCTION receives switch name as sole arg;
142 remaining command-line args are in the variable `command-line-args-left'.")
143
144 (defvar command-line-args-left nil
145 "List of command-line args not yet processed.")
146
147 (defvar command-line-functions nil ;; lrs 7/31/89
148 "List of functions to process unrecognized command-line arguments.
149 Each function should access the dynamically bound variables
150 `argi' (the current argument) and `command-line-args-left' (the remaining
151 arguments). The function should return non-nil only if it recognizes and
152 processes `argi'. If it does so, it may consume successive arguments by
153 altering `command-line-args-left' to remove them.")
154
155 (defvar command-line-default-directory nil
156 "Default directory to use for command line arguments.
157 This is normally copied from `default-directory' when Emacs starts.")
158
159 ;;; This is here, rather than in x-win.el, so that we can ignore these
160 ;;; options when we are not using X.
161 (defvar command-line-x-option-alist
162 '(("-bw" 1 x-handle-numeric-switch border-width)
163 ("-d" 1 x-handle-display)
164 ("-display" 1 x-handle-display)
165 ("-name" 1 x-handle-name-rn-switch)
166 ("-rn" 1 x-handle-name-rn-switch)
167 ("-T" 1 x-handle-switch name)
168 ("-r" 0 x-handle-switch reverse t)
169 ("-rv" 0 x-handle-switch reverse t)
170 ("-reverse" 0 x-handle-switch reverse t)
171 ("-reverse-video" 0 x-handle-switch reverse t)
172 ("-fn" 1 x-handle-switch font)
173 ("-font" 1 x-handle-switch font)
174 ("-ib" 1 x-handle-numeric-switch internal-border-width)
175 ("-g" 1 x-handle-geometry)
176 ("-geometry" 1 x-handle-geometry)
177 ("-fg" 1 x-handle-switch foreground-color)
178 ("-foreground" 1 x-handle-switch foreground-color)
179 ("-bg" 1 x-handle-switch background-color)
180 ("-background" 1 x-handle-switch background-color)
181 ("-ms" 1 x-handle-switch mouse-color)
182 ("-itype" 0 x-handle-switch icon-type t)
183 ("-i" 0 x-handle-switch icon-type t)
184 ("-iconic" 0 x-handle-iconic)
185 ("-xrm" 1 x-handle-xrm-switch)
186 ("-cr" 1 x-handle-switch cursor-color)
187 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
188 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
189 ("-bd" 1 x-handle-switch)
190 ("--border-width" 1 x-handle-numeric-switch border-width)
191 ("--display" 1 x-handle-display)
192 ("--name" 1 x-handle-name-rn-switch)
193 ("--title" 1 x-handle-name-rn-switch)
194 ("--reverse-video" 0 x-handle-switch reverse t)
195 ("--font" 1 x-handle-switch font)
196 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
197 ("--geometry" 1 x-handle-geometry)
198 ("--foreground-color" 1 x-handle-switch foreground-color)
199 ("--background-color" 1 x-handle-switch background-color)
200 ("--mouse-color" 1 x-handle-switch mouse-color)
201 ("--icon-type" 0 x-handle-switch icon-type t)
202 ("--iconic" 0 x-handle-iconic)
203 ("--xrm" 1 x-handle-xrm-switch)
204 ("--cursor-color" 1 x-handle-switch cursor-color)
205 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
206 ("--border-color" 1 x-handle-switch border-width))
207 "Alist of X Windows options.
208 Each element has the form
209 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
210 where NAME is the option name string, NUMARGS is the number of arguments
211 that the option accepts, HANDLER is a function to call to handle the option.
212 FRAME-PARAM (optional) is the frame parameter this option specifies,
213 and VALUE is the value which is given to that frame parameter
214 \(most options use the argument for this, so VALUE is not present).")
215
216 (defvar before-init-hook nil
217 "Functions to call after handling urgent options but before init files.
218 The frame system uses this to open frames to display messages while
219 Emacs loads the user's initialization file.")
220
221 (defvar after-init-hook nil
222 "Functions to call after loading the init file (`~/.emacs').
223 The call is not protected by a condition-case, so you can set `debug-on-error'
224 in `.emacs', and put all the actual code on `after-init-hook'.")
225
226 (defvar term-setup-hook nil
227 "Functions to be called after loading terminal-specific Lisp code.
228 See `run-hooks'. This variable exists for users to set,
229 so as to override the definitions made by the terminal-specific file.
230 Emacs never sets this variable itself.")
231
232 (defvar keyboard-type nil
233 "The brand of keyboard you are using.
234 This variable is used to define
235 the proper function and keypad keys for use under X. It is used in a
236 fashion analogous to the environment value TERM.")
237
238 (defvar window-setup-hook nil
239 "Normal hook run to initialize window system display.
240 Emacs runs this hook after processing the command line arguments and loading
241 the user's init file.")
242
243 (defconst initial-major-mode 'lisp-interaction-mode
244 "Major mode command symbol to use for the initial *scratch* buffer.")
245
246 (defvar init-file-user nil
247 "Identity of user whose `.emacs' file is or was read.
248 The value is nil if no init file is being used; otherwise, it may be either
249 the null string, meaning that the init file was taken from the user that
250 originally logged in, or it may be a string containing a user's name.
251
252 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
253 evaluates to the name of the directory where the `.emacs' file was
254 looked for.
255
256 Setting `init-file-user' does not prevent Emacs from loading
257 `site-start.el'. The only way to do that is to use `--no-site-file'.")
258
259 (defvar site-run-file "site-start"
260 "File containing site-wide run-time initializations.
261 This file is loaded at run-time before `~/.emacs'. It contains inits
262 that need to be in place for the entire site, but which, due to their
263 higher incidence of change, don't make sense to load into emacs'
264 dumped image. Thus, the run-time load order is: 1. file described in
265 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
266
267 Don't use the `site-start.el' file for things some users may not like.
268 Put them in `default.el' instead, so that users can more easily
269 override them. Users can prevent loading `default.el' with the `-q'
270 option or by setting `inhibit-default-init' in their own init files,
271 but inhibiting `site-start.el' requires `--no-site-file', which
272 is less convenient.")
273
274 (defconst iso-8859-1-locale-regexp "8859[-_]?1"
275 "Regexp that specifies when to enable the ISO 8859-1 character set.
276 We do that if this regexp matches the locale name
277 specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
278
279 (defvar mail-host-address nil
280 "*Name of this machine, for purposes of naming users.")
281
282 (defvar user-mail-address nil
283 "*Full mailing address of this user.
284 This is initialized based on `mail-host-address',
285 after your init file is read, in case it sets `mail-host-address'.")
286
287 (defvar auto-save-list-file-prefix
288 (if (eq system-type 'ms-dos)
289 "~/_s" ; MS-DOS cannot have initial dot, and allows only 8.3 names
290 "~/.saves-")
291 "Prefix for generating `auto-save-list-file-name'.
292 This is used after reading your `.emacs' file to initialize
293 `auto-save-list-file-name', by appending Emacs's pid and the system name,
294 if you have not already set `auto-save-list-file-name' yourself.
295 Set this to nil if you want to prevent `auto-save-list-file-name'
296 from being initialized.")
297
298 (defvar init-file-debug nil)
299
300 (defvar init-file-had-error nil)
301
302 ;; This function is called from the subdirs.el file.
303 (defun normal-top-level-add-to-load-path (dirs)
304 (let ((tail (member default-directory load-path)))
305 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail)))))
306
307 (defun normal-top-level ()
308 (if command-line-processed
309 (message "Back to top level.")
310 (setq command-line-processed t)
311 ;; Give *Messages* the same default-directory as *scratch*,
312 ;; just to keep things predictable.
313 (let ((dir default-directory))
314 (save-excursion
315 (set-buffer (get-buffer "*Messages*"))
316 (setq default-directory dir)))
317 ;; Look in each dir in load-path for a subdirs.el file.
318 ;; If we find one, load it, which will add the appropriate subdirs
319 ;; of that dir into load-path,
320 (let ((tail load-path)
321 new)
322 (while tail
323 (setq new (cons (car tail) new))
324 (let ((default-directory (car tail)))
325 (load (expand-file-name "subdirs.el" (car tail)) t t t))
326 (setq tail (cdr tail))))
327 (if (not (eq system-type 'vax-vms))
328 (progn
329 ;; If the PWD environment variable isn't accurate, delete it.
330 (let ((pwd (getenv "PWD")))
331 (and (stringp pwd)
332 ;; Use FOO/., so that if FOO is a symlink, file-attributes
333 ;; describes the directory linked to, not FOO itself.
334 (or (equal (file-attributes
335 (concat (file-name-as-directory pwd) "."))
336 (file-attributes
337 (concat (file-name-as-directory default-directory)
338 ".")))
339 (setq process-environment
340 (delete (concat "PWD=" pwd)
341 process-environment)))))))
342 (setq default-directory (abbreviate-file-name default-directory))
343 (let ((menubar-bindings-done nil))
344 (unwind-protect
345 (command-line)
346 ;; Do this again, in case .emacs defined more abbreviations.
347 (setq default-directory (abbreviate-file-name default-directory))
348 ;; Specify the file for recording all the auto save files of this session.
349 ;; This is used by recover-session.
350 (or auto-save-list-file-name
351 (and auto-save-list-file-prefix
352 (setq auto-save-list-file-name
353 ;; Under MS-DOS our PID is almost always reused between
354 ;; Emacs invocations. We need something more unique.
355 (if (eq system-type 'ms-dos)
356 (concat
357 (make-temp-name
358 (expand-file-name auto-save-list-file-prefix))
359 "~")
360
361 (expand-file-name (format "%s%d-%s~"
362 auto-save-list-file-prefix
363 (emacs-pid)
364 (system-name)))))))
365 (run-hooks 'emacs-startup-hook)
366 (and term-setup-hook
367 (run-hooks 'term-setup-hook))
368 ;; Modify the initial frame based on what .emacs puts into
369 ;; ...-frame-alist.
370 (if (fboundp 'frame-notice-user-settings)
371 (frame-notice-user-settings))
372 ;; Now we know the user's default font, so add it to the menu.
373 (if (fboundp 'font-menu-add-default)
374 (font-menu-add-default))
375 (and window-setup-hook
376 (run-hooks 'window-setup-hook))
377 (or menubar-bindings-done
378 (if (or (eq window-system 'x) (eq window-system 'win32))
379 (precompute-menubar-bindings)))))))
380
381 ;; Precompute the keyboard equivalents in the menu bar items.
382 (defun precompute-menubar-bindings ()
383 (let ((submap (lookup-key global-map [menu-bar])))
384 (while submap
385 (and (consp (car submap))
386 (symbolp (car (car submap)))
387 (stringp (car-safe (cdr (car submap))))
388 (keymapp (cdr (cdr (car submap))))
389 (progn
390 (x-popup-menu nil (cdr (cdr (car submap))))
391 (if purify-flag
392 (garbage-collect))))
393 (setq submap (cdr submap))))
394 (setq define-key-rebound-commands t))
395
396 (defun command-line ()
397 (setq command-line-default-directory default-directory)
398
399 ;; See if we should import version-control from the environment variable.
400 (let ((vc (getenv "VERSION_CONTROL")))
401 (cond ((eq vc nil)) ;don't do anything if not set
402 ((or (string= vc "t")
403 (string= vc "numbered"))
404 (setq version-control t))
405 ((or (string= vc "nil")
406 (string= vc "existing"))
407 (setq version-control nil))
408 ((or (string= vc "never")
409 (string= vc "simple"))
410 (setq version-control 'never))))
411
412 (if (let ((ctype
413 ;; Use the first of these three envvars that has a nonempty value.
414 (or (let ((string (getenv "LC_ALL")))
415 (and (not (equal string "")) string))
416 (let ((string (getenv "LC_CTYPE")))
417 (and (not (equal string "")) string))
418 (let ((string (getenv "LANG")))
419 (and (not (equal string "")) string)))))
420 (and ctype
421 (string-match iso-8859-1-locale-regexp ctype)))
422 (progn
423 (require 'disp-table)
424 (standard-display-european t)
425 (require 'iso-syntax)))
426
427 ;;! This has been commented out; I currently find the behavior when
428 ;;! split-window-keep-point is nil disturbing, but if I can get used
429 ;;! to it, then it would be better to eliminate the option.
430 ;;! ;; Choose a good default value for split-window-keep-point.
431 ;;! (setq split-window-keep-point (> baud-rate 2400))
432
433 ;; Read window system's init file if using a window system.
434 (condition-case error
435 (if (and window-system (not noninteractive))
436 (load (concat term-file-prefix
437 (symbol-name window-system)
438 "-win")
439 ;; Every window system should have a startup file;
440 ;; barf if we can't find it.
441 nil t))
442 ;; If we can't read it, print the error message and exit.
443 (error
444 (princ
445 (if (eq (car error) 'error)
446 (apply 'concat (cdr error))
447 (if (memq 'file-error (get (car error) 'error-conditions))
448 (format "%s: %s"
449 (nth 1 error)
450 (mapconcat '(lambda (obj) (prin1-to-string obj t))
451 (cdr (cdr error)) ", "))
452 (format "%s: %s"
453 (get (car error) 'error-message)
454 (mapconcat '(lambda (obj) (prin1-to-string obj t))
455 (cdr error) ", "))))
456 'external-debugging-output)
457 (setq window-system nil)
458 (kill-emacs)))
459
460 (let ((done nil)
461 (args (cdr command-line-args)))
462
463 ;; Figure out which user's init file to load,
464 ;; either from the environment or from the options.
465 (setq init-file-user (if noninteractive nil (user-login-name)))
466 ;; If user has not done su, use current $HOME to find .emacs.
467 (and init-file-user (string= init-file-user (user-real-login-name))
468 (setq init-file-user ""))
469
470 ;; Process the command-line args, and delete the arguments
471 ;; processed. This is consistent with the way main in emacs.c
472 ;; does things.
473 (while (and (not done) args)
474 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
475 ("--debug-init") ("--iconic") ("--icon-type")))
476 (argi (car args))
477 (argval nil))
478 ;; Handle --OPTION=VALUE format.
479 (if (and (string-match "\\`--" argi)
480 (string-match "=" argi))
481 (setq argval (substring argi (match-end 0))
482 argi (substring argi 0 (match-beginning 0))))
483 (let ((completion (try-completion argi longopts)))
484 (if (eq completion t)
485 (setq argi (substring argi 1))
486 (if (stringp completion)
487 (let ((elt (assoc completion longopts)))
488 (or elt
489 (error "Option `%s' is ambiguous" argi))
490 (setq argi (substring (car elt) 1)))
491 (setq argval nil))))
492 (cond
493 ((or (string-equal argi "-q")
494 (string-equal argi "-no-init-file"))
495 (setq init-file-user nil
496 args (cdr args)))
497 ((or (string-equal argi "-u")
498 (string-equal argi "-user"))
499 (or argval
500 (setq args (cdr args)
501 argval (car args)))
502 (setq init-file-user argval
503 argval nil
504 args (cdr args)))
505 ((string-equal argi "-no-site-file")
506 (setq site-run-file nil
507 args (cdr args)))
508 ((string-equal argi "-debug-init")
509 (setq init-file-debug t
510 args (cdr args)))
511 ((string-equal argi "-iconic")
512 (setq initial-frame-alist
513 (cons '(visibility . icon) initial-frame-alist))
514 (setq args (cdr args)))
515 ((or (string-equal argi "-icon-type")
516 (string-equal argi "-i")
517 (string-equal argi "-itype"))
518 (setq default-frame-alist
519 (cons '(icon-type . t) default-frame-alist))
520 (setq args (cdr args)))
521 (t (setq done t)))
522 ;; Was argval set but not used?
523 (and argval
524 (error "Option `%s' doesn't allow an argument" argi))))
525
526 ;; Re-attach the program name to the front of the arg list.
527 (and command-line-args (setcdr command-line-args args)))
528
529 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
530 (if (fboundp 'face-initialize)
531 (face-initialize))
532 (if (fboundp 'frame-initialize)
533 (frame-initialize))
534 ;; If frame was created with a menu bar, set menu-bar-mode on.
535 (if (or (not (or (eq window-system 'x) (eq window-system 'win32)))
536 (> (cdr (assq 'menu-bar-lines (frame-parameters))) 0))
537 (menu-bar-mode t))
538
539 (run-hooks 'before-init-hook)
540
541 ;; Run the site-start library if it exists. The point of this file is
542 ;; that it is run before .emacs. There is no point in doing this after
543 ;; .emacs; that is useless.
544 (if site-run-file
545 (load site-run-file t t))
546
547 ;; Sites should not disable this. Only individuals should disable
548 ;; the startup message.
549 (setq inhibit-startup-message nil)
550
551 ;; Load that user's init file, or the default one, or none.
552 (let (debug-on-error-from-init-file
553 debug-on-error-should-be-set
554 (debug-on-error-initial
555 (if (eq init-file-debug t) 'startup init-file-debug)))
556 (let ((debug-on-error debug-on-error-initial)
557 ;; This function actually reads the init files.
558 (inner
559 (function
560 (lambda ()
561 (if init-file-user
562 (progn
563 (setq user-init-file
564 (cond
565 ((eq system-type 'ms-dos)
566 (concat "~" init-file-user "/_emacs"))
567 ((eq system-type 'windows-nt)
568 "~/_emacs")
569 ((eq system-type 'vax-vms)
570 "sys$login:.emacs")
571 (t
572 (concat "~" init-file-user "/.emacs"))))
573 (load user-init-file t t t)
574 (or inhibit-default-init
575 (let ((inhibit-startup-message nil))
576 ;; Users are supposed to be told their rights.
577 ;; (Plus how to get help and how to undo.)
578 ;; Don't you dare turn this off for anyone
579 ;; except yourself.
580 (load "default" t t)))))))))
581 (if init-file-debug
582 ;; Do this without a condition-case if the user wants to debug.
583 (funcall inner)
584 (condition-case error
585 (progn
586 (funcall inner)
587 (setq init-file-had-error nil))
588 (error (message "Error in init file: %s%s%s"
589 (get (car error) 'error-message)
590 (if (cdr error) ": " "")
591 (mapconcat 'prin1-to-string (cdr error) ", "))
592 (setq init-file-had-error t))))
593 ;; If we can tell that the init file altered debug-on-error,
594 ;; arrange to preserve the value that it set up.
595 (or (eq debug-on-error debug-on-error-initial)
596 (setq debug-on-error-should-be-set t
597 debug-on-error-from-init-file debug-on-error)))
598 (if debug-on-error-should-be-set
599 (setq debug-on-error debug-on-error-from-init-file)))
600
601 ;; Do this here in case the init file sets mail-host-address.
602 (or user-mail-address
603 (setq user-mail-address (concat (user-login-name) "@"
604 (or mail-host-address
605 (system-name)))))
606
607 (run-hooks 'after-init-hook)
608
609 ;; If *scratch* exists and init file didn't change its mode, initialize it.
610 (if (get-buffer "*scratch*")
611 (save-excursion
612 (set-buffer "*scratch*")
613 (if (eq major-mode 'fundamental-mode)
614 (funcall initial-major-mode))))
615 ;; Load library for our terminal type.
616 ;; User init file can set term-file-prefix to nil to prevent this.
617 (and term-file-prefix (not noninteractive) (not window-system)
618 (let ((term (getenv "TERM"))
619 hyphend)
620 (while (and term
621 (not (load (concat term-file-prefix term) t t)))
622 ;; Strip off last hyphen and what follows, then try again
623 (if (setq hyphend (string-match "[-_][^-_]+$" term))
624 (setq term (substring term 0 hyphend))
625 (setq term nil)))))
626
627 ;; Process the remaining args.
628 (command-line-1 (cdr command-line-args))
629
630 ;; If -batch, terminate after processing the command options.
631 (if noninteractive (kill-emacs t)))
632
633 (defun command-line-1 (command-line-args-left)
634 (or noninteractive (input-pending-p) init-file-had-error
635 (and inhibit-startup-echo-area-message
636 (let ((buffer (get-buffer-create " *temp*")))
637 (prog1
638 (condition-case nil
639 (save-excursion
640 (set-buffer buffer)
641 (insert-file-contents user-init-file)
642 (re-search-forward
643 (concat
644 "([ \t\n]*setq[ \t\n]+"
645 "inhibit-startup-echo-area-message[ \t\n]+"
646 (regexp-quote
647 (prin1-to-string
648 (if (string= init-file-user "")
649 (user-login-name)
650 init-file-user)))
651 "[ \t\n]*)")
652 nil t))
653 (error nil))
654 (kill-buffer buffer))))
655 (message (if (eq (key-binding "\C-h\C-p") 'describe-project)
656 "For information about the GNU Project and its goals, type C-h C-p."
657 (substitute-command-keys
658 "For information about the GNU Project and its goals, type \\[describe-project]."))))
659 (if (null command-line-args-left)
660 (cond ((and (not inhibit-startup-message) (not noninteractive)
661 ;; Don't clobber a non-scratch buffer if init file
662 ;; has selected it.
663 (string= (buffer-name) "*scratch*")
664 (not (input-pending-p)))
665 ;; If there are no switches to process, we might as well
666 ;; run this hook now, and there may be some need to do it
667 ;; before doing any output.
668 (and term-setup-hook
669 (run-hooks 'term-setup-hook))
670 ;; Don't let the hook be run twice.
671 (setq term-setup-hook nil)
672
673 ;; It's important to notice the user settings before we
674 ;; display the startup message; otherwise, the settings
675 ;; won't take effect until the user gives the first
676 ;; keystroke, and that's distracting.
677 (if (fboundp 'frame-notice-user-settings)
678 (frame-notice-user-settings))
679
680 (and window-setup-hook
681 (run-hooks 'window-setup-hook))
682 (setq window-setup-hook nil)
683 ;; Do this now to avoid an annoying delay if the user
684 ;; clicks the menu bar during the sit-for.
685 (if (or (eq window-system 'x) (eq window-system 'win32))
686 (precompute-menubar-bindings))
687 (setq menubar-bindings-done t)
688 (unwind-protect
689 (progn
690 ;; The convention for this piece of code is that
691 ;; each piece of output starts with one or two newlines
692 ;; and does not end with any newlines.
693 (insert (emacs-version)
694 "
695 Copyright (C) 1995 Free Software Foundation, Inc.")
696 ;; If keys have their default meanings,
697 ;; use precomputed string to save lots of time.
698 (if (and (eq (key-binding "\C-h") 'help-command)
699 (eq (key-binding "\C-xu") 'advertised-undo)
700 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
701 (eq (key-binding "\C-ht") 'help-with-tutorial)
702 (eq (key-binding "\C-hi") 'info))
703 (insert "\n
704 Type C-h for help; C-x u to undo changes. (`C-' means use CTRL key.)
705 To kill the Emacs job, type C-x C-c.
706 Type C-h t for a tutorial on using Emacs.
707 Type C-h i to enter Info, which you can use to read GNU documentation.")
708 (insert (substitute-command-keys
709 (format "\n
710 Type %s for help; \\[advertised-undo] to undo changes. (`C-' means use CTRL key.)
711 To kill the Emacs job, type \\[save-buffers-kill-emacs].
712 Type \\[help-with-tutorial] for a tutorial on using Emacs.
713 Type \\[info] to enter Info, which you can use to read GNU documentation."
714 (let ((where (where-is-internal
715 'help-command nil t)))
716 (if where
717 (key-description where)
718 "M-x help"))))))
719 ;; Say how to use the menu bar
720 ;; if that is not with the mouse.
721 (if (not (assq 'display (frame-parameters)))
722 (if (eq (key-binding "\M-`") 'tmm-menubar)
723 (insert "\n\nType F10, ESC ` or Meta-` to use the menu bar.")
724 (insert (substitute-command-keys
725 "\n\nType \\[tmm-menubar] to use the menu bar."))))
726
727 ;; Windows and MSDOS (currently) do not count as
728 ;; window systems, but do have mouse support.
729 (if window-system
730 (insert "\n
731 C-mouse-3 (third mouse button, with Control) gets a mode-specific menu."))
732 (if (directory-files (file-name-directory auto-save-list-file-prefix)
733 nil
734 (concat "\\`"
735 (regexp-quote
736 (file-name-nondirectory
737 auto-save-list-file-prefix)))
738 t)
739 (insert "\n\nIf an Emacs session crashed recently,\n"
740 "type M-x recover-session RET to recover"
741 " the files you were editing."))
742
743 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
744 (eq (key-binding "\C-h\C-d") 'describe-distribution)
745 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
746 (insert
747 "\n
748 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
749 You may give out copies of Emacs; type C-h C-c to see the conditions.
750 Type C-h C-d for information on getting the latest version.")
751 (insert (substitute-command-keys
752 "\n
753 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
754 You may give out copies of Emacs; type \\[describe-copying] to see the conditions.
755 Type \\[describe-distribution] for information on getting the latest version.")))
756
757 (set-buffer-modified-p nil)
758 (sit-for 120))
759 (save-excursion
760 ;; In case the Emacs server has already selected
761 ;; another buffer, erase the one our message is in.
762 (set-buffer (get-buffer "*scratch*"))
763 (erase-buffer)
764 (set-buffer-modified-p nil)))))
765 ;; Delay 2 seconds after the init file error message
766 ;; was displayed, so user can read it.
767 (if init-file-had-error
768 (sit-for 2))
769 (let ((dir command-line-default-directory)
770 (file-count 0)
771 first-file-buffer
772 (line 0))
773 (while command-line-args-left
774 (let* ((argi (car command-line-args-left))
775 (orig-argi argi)
776 ;; This includes our standard options' long versions
777 ;; and long versions of what's on command-switch-alist.
778 (longopts
779 (append '(("--funcall") ("--load") ("--insert") ("--kill")
780 ("--directory") ("--eval"))
781 (mapcar '(lambda (elt)
782 (list (concat "-" (car elt))))
783 command-switch-alist)))
784 tem argval completion
785 ;; List of directories specified in -L/--directory,
786 ;; in reverse of the order specified.
787 extra-load-path
788 (initial-load-path load-path))
789 (setq command-line-args-left (cdr command-line-args-left))
790
791 ;; Add the long X options to longopts.
792 (setq tem command-line-x-option-alist)
793 (while tem
794 (if (string-match "^--" (car (car tem)))
795 (setq longopts (cons (list (car (car tem))) longopts)))
796 (setq tem (cdr tem)))
797
798 ;; Convert long options to ordinary options
799 ;; and separate out an attached option argument into argval.
800 (if (string-match "^--[^=]*=" argi)
801 (setq argval (substring argi (match-end 0))
802 argi (substring argi 0 (1- (match-end 0)))))
803 (setq completion (try-completion argi longopts))
804 (if (eq completion t)
805 (setq argi (substring argi 1))
806 (if (stringp completion)
807 (let ((elt (assoc completion longopts)))
808 (or elt
809 (error "Option `%s' is ambiguous" argi))
810 (setq argi (substring (car elt) 1)))
811 (setq argval nil argi orig-argi)))
812
813 ;; Execute the option.
814 (cond ((setq tem (assoc argi command-switch-alist))
815 (if argval
816 (let ((command-line-args-left
817 (cons argval command-line-args-left)))
818 (funcall (cdr tem) argi))
819 (funcall (cdr tem) argi)))
820 ((or (string-equal argi "-f") ;what the manual claims
821 (string-equal argi "-funcall")
822 (string-equal argi "-e")) ; what the source used to say
823 (if argval
824 (setq tem (intern argval))
825 (setq tem (intern (car command-line-args-left)))
826 (setq command-line-args-left (cdr command-line-args-left)))
827 (if (arrayp (symbol-function tem))
828 (command-execute tem)
829 (funcall tem)))
830 ((string-equal argi "-eval")
831 (if argval
832 (setq tem argval)
833 (setq tem (car command-line-args-left))
834 (setq command-line-args-left (cdr command-line-args-left)))
835 (eval (read tem)))
836 ;; Set the default directory as specified in -L.
837 ((or (string-equal argi "-L")
838 (string-equal argi "-directory"))
839 (if argval
840 (setq tem argval)
841 (setq tem (car command-line-args-left)
842 command-line-args-left (cdr command-line-args-left)))
843 (setq extra-load-path
844 (cons (expand-file-name tem) extra-load-path))
845 (setq load-path (append (nreverse extra-load-path)
846 initial-load-path)))
847 ((or (string-equal argi "-l")
848 (string-equal argi "-load"))
849 (if argval
850 (setq tem argval)
851 (setq tem (car command-line-args-left)
852 command-line-args-left (cdr command-line-args-left)))
853 (let ((file tem))
854 ;; Take file from default dir if it exists there;
855 ;; otherwise let `load' search for it.
856 (if (file-exists-p (expand-file-name file))
857 (setq file (expand-file-name file)))
858 (load file nil t)))
859 ((string-equal argi "-insert")
860 (if argval
861 (setq tem argval)
862 (setq tem (car command-line-args-left)
863 command-line-args-left (cdr command-line-args-left)))
864 (or (stringp tem)
865 (error "File name omitted from `-insert' option"))
866 (insert-file-contents tem))
867 ((string-equal argi "-kill")
868 (kill-emacs t))
869 ((string-match "^\\+[0-9]+\\'" argi)
870 (setq line (string-to-int argi)))
871 ((setq tem (assoc argi command-line-x-option-alist))
872 ;; Ignore X-windows options and their args if not using X.
873 (setq command-line-args-left
874 (nthcdr (nth 1 tem) command-line-args-left)))
875 (t
876 ;; We have almost exhausted our options. See if the
877 ;; user has made any other command-line options available
878 (let ((hooks command-line-functions);; lrs 7/31/89
879 (did-hook nil))
880 (while (and hooks
881 (not (setq did-hook (funcall (car hooks)))))
882 (setq hooks (cdr hooks)))
883 (if (not did-hook)
884 ;; Ok, presume that the argument is a file name
885 (progn
886 (if (string-match "\\`-" argi)
887 (error "Unknown option `%s'" argi))
888 (setq file-count (1+ file-count))
889 (cond ((= file-count 1)
890 (setq first-file-buffer
891 (find-file (expand-file-name argi dir))))
892 (t
893 (find-file-other-window (expand-file-name argi dir))))
894 (or (zerop line)
895 (goto-line line))
896 (setq line 0))))))))
897 ;; If 3 or more files visited, and not all visible,
898 ;; show user what they all are.
899 (if (> file-count 2)
900 (or (get-buffer-window first-file-buffer)
901 (progn (other-window 1)
902 (buffer-menu)))))))
903
904 ;;; startup.el ends here