]> code.delx.au - gnu-emacs/blob - lisp/startup.el
(vip-custom-file-name): Use convert-standard-filename.
[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-switch geometry)
176 ("-geometry" 1 x-handle-switch 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-switch 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 "~/.saves-"
288 "Prefix for generating `auto-save-list-file-name'.
289 This is used after reading your `.emacs' file to initialize
290 `auto-save-list-file-name', by appending Emacs's pid and the system name,
291 if you have not already set `auto-save-list-file-name' yourself.
292 Set this to nil if you want to prevent `auto-save-list-file-name'
293 from being initialized.")
294
295 (defvar init-file-debug nil)
296
297 (defvar init-file-had-error nil)
298
299 ;; This function is called from the subdirs.el file.
300 (defun normal-top-level-add-to-load-path (dirs)
301 (let ((tail (member default-directory load-path)))
302 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail)))))
303
304 (defun normal-top-level ()
305 (if command-line-processed
306 (message "Back to top level.")
307 (setq command-line-processed t)
308 ;; Give *Messages* the same default-directory as *scratch*,
309 ;; just to keep things predictable.
310 (let ((dir default-directory))
311 (save-excursion
312 (set-buffer (get-buffer "*Messages*"))
313 (setq default-directory dir)))
314 ;; Look in each dir in load-path for a subdirs.el file.
315 ;; If we find one, load it, which will add the appropriate subdirs
316 ;; of that dir into load-path,
317 (let ((tail load-path)
318 new)
319 (while tail
320 (setq new (cons (car tail) new))
321 (let ((default-directory (car tail)))
322 (load (expand-file-name "subdirs.el" (car tail)) t t t))
323 (setq tail (cdr tail))))
324 (if (not (eq system-type 'vax-vms))
325 (progn
326 ;; If the PWD environment variable isn't accurate, delete it.
327 (let ((pwd (getenv "PWD")))
328 (and (stringp pwd)
329 ;; Use FOO/., so that if FOO is a symlink, file-attributes
330 ;; describes the directory linked to, not FOO itself.
331 (or (equal (file-attributes
332 (concat (file-name-as-directory pwd) "."))
333 (file-attributes
334 (concat (file-name-as-directory default-directory)
335 ".")))
336 (setq process-environment
337 (delete (concat "PWD=" pwd)
338 process-environment)))))))
339 (setq default-directory (abbreviate-file-name default-directory))
340 (let ((menubar-bindings-done nil))
341 (unwind-protect
342 (command-line)
343 ;; Do this again, in case .emacs defined more abbreviations.
344 (setq default-directory (abbreviate-file-name default-directory))
345 ;; Specify the file for recording all the auto save files of this session.
346 ;; This is used by recover-session.
347 (or auto-save-list-file-name
348 (and auto-save-list-file-prefix
349 (setq auto-save-list-file-name
350 (expand-file-name
351 (format "%s%d-%s"
352 auto-save-list-file-prefix
353 (emacs-pid)
354 (system-name))))))
355 (run-hooks 'emacs-startup-hook)
356 (and term-setup-hook
357 (run-hooks 'term-setup-hook))
358 ;; Modify the initial frame based on what .emacs puts into
359 ;; ...-frame-alist.
360 (if (fboundp 'frame-notice-user-settings)
361 (frame-notice-user-settings))
362 ;; Now we know the user's default font, so add it to the menu.
363 (if (fboundp 'font-menu-add-default)
364 (font-menu-add-default))
365 (and window-setup-hook
366 (run-hooks 'window-setup-hook))
367 (or menubar-bindings-done
368 (if (or (eq window-system 'x) (eq window-system 'win32))
369 (precompute-menubar-bindings)))))))
370
371 ;; Precompute the keyboard equivalents in the menu bar items.
372 (defun precompute-menubar-bindings ()
373 (let ((submap (lookup-key global-map [menu-bar])))
374 (while submap
375 (and (consp (car submap))
376 (symbolp (car (car submap)))
377 (stringp (car-safe (cdr (car submap))))
378 (keymapp (cdr (cdr (car submap))))
379 (progn
380 (x-popup-menu nil (cdr (cdr (car submap))))
381 (if purify-flag
382 (garbage-collect))))
383 (setq submap (cdr submap))))
384 (setq define-key-rebound-commands t))
385
386 (defun command-line ()
387 (setq command-line-default-directory default-directory)
388
389 ;; See if we should import version-control from the environment variable.
390 (let ((vc (getenv "VERSION_CONTROL")))
391 (cond ((eq vc nil)) ;don't do anything if not set
392 ((or (string= vc "t")
393 (string= vc "numbered"))
394 (setq version-control t))
395 ((or (string= vc "nil")
396 (string= vc "existing"))
397 (setq version-control nil))
398 ((or (string= vc "never")
399 (string= vc "simple"))
400 (setq version-control 'never))))
401
402 (if (let ((ctype
403 ;; Use the first of these three envvars that has a nonempty value.
404 (or (let ((string (getenv "LC_ALL")))
405 (and (not (equal string "")) string))
406 (let ((string (getenv "LC_CTYPE")))
407 (and (not (equal string "")) string))
408 (let ((string (getenv "LANG")))
409 (and (not (equal string "")) string)))))
410 (and ctype
411 (string-match iso-8859-1-locale-regexp ctype)))
412 (progn
413 (require 'disp-table)
414 (standard-display-european t)
415 (require 'iso-syntax)))
416
417 ;;! This has been commented out; I currently find the behavior when
418 ;;! split-window-keep-point is nil disturbing, but if I can get used
419 ;;! to it, then it would be better to eliminate the option.
420 ;;! ;; Choose a good default value for split-window-keep-point.
421 ;;! (setq split-window-keep-point (> baud-rate 2400))
422
423 ;; Read window system's init file if using a window system.
424 (condition-case error
425 (if (and window-system (not noninteractive))
426 (load (concat term-file-prefix
427 (symbol-name window-system)
428 "-win")
429 ;; Every window system should have a startup file;
430 ;; barf if we can't find it.
431 nil t))
432 ;; If we can't read it, print the error message and exit.
433 (error
434 (princ
435 (if (eq (car error) 'error)
436 (apply 'concat (cdr error))
437 (if (memq 'file-error (get (car error) 'error-conditions))
438 (format "%s: %s"
439 (nth 1 error)
440 (mapconcat '(lambda (obj) (prin1-to-string obj t))
441 (cdr (cdr error)) ", "))
442 (format "%s: %s"
443 (get (car error) 'error-message)
444 (mapconcat '(lambda (obj) (prin1-to-string obj t))
445 (cdr error) ", "))))
446 'external-debugging-output)
447 (setq window-system nil)
448 (kill-emacs)))
449
450 (let ((done nil)
451 (args (cdr command-line-args)))
452
453 ;; Figure out which user's init file to load,
454 ;; either from the environment or from the options.
455 (setq init-file-user (if noninteractive nil (user-login-name)))
456 ;; If user has not done su, use current $HOME to find .emacs.
457 (and init-file-user (string= init-file-user (user-real-login-name))
458 (setq init-file-user ""))
459
460 ;; Process the command-line args, and delete the arguments
461 ;; processed. This is consistent with the way main in emacs.c
462 ;; does things.
463 (while (and (not done) args)
464 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
465 ("--debug-init") ("--iconic") ("--icon-type")))
466 (argi (car args))
467 (argval nil))
468 ;; Handle --OPTION=VALUE format.
469 (if (and (string-match "\\`--" argi)
470 (string-match "=" argi))
471 (setq argval (substring argi (match-end 0))
472 argi (substring argi 0 (match-beginning 0))))
473 (let ((completion (try-completion argi longopts)))
474 (if (eq completion t)
475 (setq argi (substring argi 1))
476 (if (stringp completion)
477 (let ((elt (assoc completion longopts)))
478 (or elt
479 (error "Option `%s' is ambiguous" argi))
480 (setq argi (substring (car elt) 1)))
481 (setq argval nil))))
482 (cond
483 ((or (string-equal argi "-q")
484 (string-equal argi "-no-init-file"))
485 (setq init-file-user nil
486 args (cdr args)))
487 ((or (string-equal argi "-u")
488 (string-equal argi "-user"))
489 (or argval
490 (setq args (cdr args)
491 argval (car args)))
492 (setq init-file-user argval
493 argval nil
494 args (cdr args)))
495 ((string-equal argi "-no-site-file")
496 (setq site-run-file nil
497 args (cdr args)))
498 ((string-equal argi "-debug-init")
499 (setq init-file-debug t
500 args (cdr args)))
501 ((string-equal argi "-iconic")
502 (setq initial-frame-alist
503 (cons '(visibility . icon) initial-frame-alist))
504 (setq args (cdr args)))
505 ((or (string-equal argi "-icon-type")
506 (string-equal argi "-i")
507 (string-equal argi "-itype"))
508 (setq default-frame-alist
509 (cons '(icon-type . t) default-frame-alist))
510 (setq args (cdr args)))
511 (t (setq done t)))
512 ;; Was argval set but not used?
513 (and argval
514 (error "Option `%s' doesn't allow an argument" argi))))
515
516 ;; Re-attach the program name to the front of the arg list.
517 (and command-line-args (setcdr command-line-args args)))
518
519 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
520 (if (fboundp 'face-initialize)
521 (face-initialize))
522 (if (fboundp 'frame-initialize)
523 (frame-initialize))
524 ;; If frame was created with a menu bar, set menu-bar-mode on.
525 (if (or (not (or (eq window-system 'x) (eq window-system 'win32)))
526 (> (cdr (assq 'menu-bar-lines (frame-parameters))) 0))
527 (menu-bar-mode t))
528
529 (run-hooks 'before-init-hook)
530
531 ;; Run the site-start library if it exists. The point of this file is
532 ;; that it is run before .emacs. There is no point in doing this after
533 ;; .emacs; that is useless.
534 (if site-run-file
535 (load site-run-file t t))
536
537 ;; Sites should not disable this. Only individuals should disable
538 ;; the startup message.
539 (setq inhibit-startup-message nil)
540
541 ;; Load that user's init file, or the default one, or none.
542 (let (debug-on-error-from-init-file
543 debug-on-error-should-be-set
544 (debug-on-error-initial
545 (if (eq init-file-debug t) 'startup init-file-debug)))
546 (let ((debug-on-error debug-on-error-initial)
547 ;; This function actually reads the init files.
548 (inner
549 (function
550 (lambda ()
551 (if init-file-user
552 (progn
553 (setq user-init-file
554 (cond
555 ((eq system-type 'ms-dos)
556 (concat "~" init-file-user "/_emacs"))
557 ((eq system-type 'windows-nt)
558 "~/_emacs")
559 ((eq system-type 'vax-vms)
560 "sys$login:.emacs")
561 (t
562 (concat "~" init-file-user "/.emacs"))))
563 (load user-init-file t t t)
564 (or inhibit-default-init
565 (let ((inhibit-startup-message nil))
566 ;; Users are supposed to be told their rights.
567 ;; (Plus how to get help and how to undo.)
568 ;; Don't you dare turn this off for anyone
569 ;; except yourself.
570 (load "default" t t)))))))))
571 (if init-file-debug
572 ;; Do this without a condition-case if the user wants to debug.
573 (funcall inner)
574 (condition-case error
575 (progn
576 (funcall inner)
577 (setq init-file-had-error nil))
578 (error (message "Error in init file: %s%s%s"
579 (get (car error) 'error-message)
580 (if (cdr error) ": " "")
581 (mapconcat 'prin1-to-string (cdr error) ", "))
582 (setq init-file-had-error t))))
583 ;; If we can tell that the init file altered debug-on-error,
584 ;; arrange to preserve the value that it set up.
585 (or (eq debug-on-error debug-on-error-initial)
586 (setq debug-on-error-should-be-set t
587 debug-on-error-from-init-file debug-on-error)))
588 (if debug-on-error-should-be-set
589 (setq debug-on-error debug-on-error-from-init-file)))
590
591 ;; Do this here in case the init file sets mail-host-address.
592 (or user-mail-address
593 (setq user-mail-address (concat (user-login-name) "@"
594 (or mail-host-address
595 (system-name)))))
596
597 (run-hooks 'after-init-hook)
598
599 ;; If *scratch* exists and init file didn't change its mode, initialize it.
600 (if (get-buffer "*scratch*")
601 (save-excursion
602 (set-buffer "*scratch*")
603 (if (eq major-mode 'fundamental-mode)
604 (funcall initial-major-mode))))
605 ;; Load library for our terminal type.
606 ;; User init file can set term-file-prefix to nil to prevent this.
607 (and term-file-prefix (not noninteractive) (not window-system)
608 (let ((term (getenv "TERM"))
609 hyphend)
610 (while (and term
611 (not (load (concat term-file-prefix term) t t)))
612 ;; Strip off last hyphen and what follows, then try again
613 (if (setq hyphend (string-match "[-_][^-_]+$" term))
614 (setq term (substring term 0 hyphend))
615 (setq term nil)))))
616
617 ;; Process the remaining args.
618 (command-line-1 (cdr command-line-args))
619
620 ;; If -batch, terminate after processing the command options.
621 (if noninteractive (kill-emacs t)))
622
623 (defun command-line-1 (command-line-args-left)
624 (or noninteractive (input-pending-p) init-file-had-error
625 (and inhibit-startup-echo-area-message
626 (let ((buffer (get-buffer-create " *temp*")))
627 (prog1
628 (condition-case nil
629 (save-excursion
630 (set-buffer buffer)
631 (insert-file-contents user-init-file)
632 (re-search-forward
633 (concat
634 "([ \t\n]*setq[ \t\n]+"
635 "inhibit-startup-echo-area-message[ \t\n]+"
636 (regexp-quote
637 (prin1-to-string
638 (if (string= init-file-user "")
639 (user-login-name)
640 init-file-user)))
641 "[ \t\n]*)")
642 nil t))
643 (error nil))
644 (kill-buffer buffer))))
645 (message (if (eq (key-binding "\C-h\C-p") 'describe-project)
646 "For information about the GNU Project and its goals, type C-h C-p."
647 (substitute-command-keys
648 "For information about the GNU Project and its goals, type \\[describe-project]."))))
649 (if (null command-line-args-left)
650 (cond ((and (not inhibit-startup-message) (not noninteractive)
651 ;; Don't clobber a non-scratch buffer if init file
652 ;; has selected it.
653 (string= (buffer-name) "*scratch*")
654 (not (input-pending-p)))
655 ;; If there are no switches to process, we might as well
656 ;; run this hook now, and there may be some need to do it
657 ;; before doing any output.
658 (and term-setup-hook
659 (run-hooks 'term-setup-hook))
660 ;; Don't let the hook be run twice.
661 (setq term-setup-hook nil)
662
663 ;; It's important to notice the user settings before we
664 ;; display the startup message; otherwise, the settings
665 ;; won't take effect until the user gives the first
666 ;; keystroke, and that's distracting.
667 (if (fboundp 'frame-notice-user-settings)
668 (frame-notice-user-settings))
669
670 (and window-setup-hook
671 (run-hooks 'window-setup-hook))
672 (setq window-setup-hook nil)
673 ;; Do this now to avoid an annoying delay if the user
674 ;; clicks the menu bar during the sit-for.
675 (if (or (eq window-system 'x) (eq window-system 'win32))
676 (precompute-menubar-bindings))
677 (setq menubar-bindings-done t)
678 (unwind-protect
679 (progn
680 ;; The convention for this piece of code is that
681 ;; each piece of output starts with one or two newlines
682 ;; and does not end with any newlines.
683 (insert (emacs-version)
684 "
685 Copyright (C) 1995 Free Software Foundation, Inc.")
686 ;; If keys have their default meanings,
687 ;; use precomputed string to save lots of time.
688 (if (and (eq (key-binding "\C-h") 'help-command)
689 (eq (key-binding "\C-xu") 'advertised-undo)
690 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
691 (eq (key-binding "\C-ht") 'help-with-tutorial)
692 (eq (key-binding "\C-hi") 'info))
693 (insert "\n
694 Type C-h for help; C-x u to undo changes. (`C-' means use CTRL key.)
695 To kill the Emacs job, type C-x C-c.
696 Type C-h t for a tutorial on using Emacs.
697 Type C-h i to enter Info, which you can use to read GNU documentation.")
698 (insert (substitute-command-keys
699 (format "\n
700 Type %s for help; \\[advertised-undo] to undo changes. (`C-' means use CTRL key.)
701 To kill the Emacs job, type \\[save-buffers-kill-emacs].
702 Type \\[help-with-tutorial] for a tutorial on using Emacs.
703 Type \\[info] to enter Info, which you can use to read GNU documentation."
704 (let ((where (where-is-internal
705 'help-command nil t)))
706 (if where
707 (key-description where)
708 "M-x help"))))))
709 ;; Say how to use the menu bar
710 ;; if that is not with the mouse.
711 (if (not (assq 'display (frame-parameters)))
712 (if (eq (key-binding "\M-`") 'tmm-menubar)
713 (insert "\n\nType F10, ESC ` or Meta-` to use the menu bar.")
714 (insert (substitute-command-keys
715 "\n\nType \\[tmm-menubar] to use the menu bar."))))
716
717 ;; Windows and MSDOS (currently) do not count as
718 ;; window systems, but do have mouse support.
719 (if (or (memq system-type '(msdos windowsnt))
720 window-system)
721 (insert "\n
722 C-mouse-3 (third mouse button, with Control) gets a mode-specific menu."))
723 (if (directory-files (file-name-directory auto-save-list-file-prefix)
724 nil
725 (concat "\\`"
726 (regexp-quote
727 (file-name-nondirectory
728 auto-save-list-file-prefix)))
729 t)
730 (insert "\n\nIf an Emacs session crashed recently,\n"
731 "type M-x recover-session RET to recover"
732 " the files you were editing."))
733
734 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
735 (eq (key-binding "\C-h\C-d") 'describe-distribution)
736 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
737 (insert
738 "\n
739 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
740 You may give out copies of Emacs; type C-h C-c to see the conditions.
741 Type C-h C-d for information on getting the latest version.")
742 (insert (substitute-command-keys
743 "\n
744 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
745 You may give out copies of Emacs; type \\[describe-copying] to see the conditions.
746 Type \\[describe-distribution] for information on getting the latest version.")))
747
748 (set-buffer-modified-p nil)
749 (sit-for 120))
750 (save-excursion
751 ;; In case the Emacs server has already selected
752 ;; another buffer, erase the one our message is in.
753 (set-buffer (get-buffer "*scratch*"))
754 (erase-buffer)
755 (set-buffer-modified-p nil)))))
756 ;; Delay 2 seconds after the init file error message
757 ;; was displayed, so user can read it.
758 (if init-file-had-error
759 (sit-for 2))
760 (let ((dir command-line-default-directory)
761 (file-count 0)
762 first-file-buffer
763 (line 0))
764 (while command-line-args-left
765 (let* ((argi (car command-line-args-left))
766 (orig-argi argi)
767 ;; This includes our standard options' long versions
768 ;; and long versions of what's on command-switch-alist.
769 (longopts
770 (append '(("--funcall") ("--load") ("--insert") ("--kill")
771 ("--directory") ("--eval"))
772 (mapcar '(lambda (elt)
773 (list (concat "-" (car elt))))
774 command-switch-alist)))
775 tem argval completion
776 ;; List of directories specified in -L/--directory,
777 ;; in reverse of the order specified.
778 extra-load-path
779 (initial-load-path load-path))
780 (setq command-line-args-left (cdr command-line-args-left))
781
782 ;; Add the long X options to longopts.
783 (setq tem command-line-x-option-alist)
784 (while tem
785 (if (string-match "^--" (car (car tem)))
786 (setq longopts (cons (list (car (car tem))) longopts)))
787 (setq tem (cdr tem)))
788
789 ;; Convert long options to ordinary options
790 ;; and separate out an attached option argument into argval.
791 (if (string-match "^--[^=]*=" argi)
792 (setq argval (substring argi (match-end 0))
793 argi (substring argi 0 (1- (match-end 0)))))
794 (setq completion (try-completion argi longopts))
795 (if (eq completion t)
796 (setq argi (substring argi 1))
797 (if (stringp completion)
798 (let ((elt (assoc completion longopts)))
799 (or elt
800 (error "Option `%s' is ambiguous" argi))
801 (setq argi (substring (car elt) 1)))
802 (setq argval nil argi orig-argi)))
803
804 ;; Execute the option.
805 (cond ((setq tem (assoc argi command-switch-alist))
806 (if argval
807 (let ((command-line-args-left
808 (cons argval command-line-args-left)))
809 (funcall (cdr tem) argi))
810 (funcall (cdr tem) argi)))
811 ((or (string-equal argi "-f") ;what the manual claims
812 (string-equal argi "-funcall")
813 (string-equal argi "-e")) ; what the source used to say
814 (if argval
815 (setq tem (intern argval))
816 (setq tem (intern (car command-line-args-left)))
817 (setq command-line-args-left (cdr command-line-args-left)))
818 (if (arrayp (symbol-function tem))
819 (command-execute tem)
820 (funcall tem)))
821 ((string-equal argi "-eval")
822 (if argval
823 (setq tem argval)
824 (setq tem (car command-line-args-left))
825 (setq command-line-args-left (cdr command-line-args-left)))
826 (eval (read tem)))
827 ;; Set the default directory as specified in -L.
828 ((or (string-equal argi "-L")
829 (string-equal argi "-directory"))
830 (if argval
831 (setq tem argval)
832 (setq tem (car command-line-args-left)
833 command-line-args-left (cdr command-line-args-left)))
834 (setq extra-load-path
835 (cons (expand-file-name tem) extra-load-path))
836 (setq load-path (append (nreverse extra-load-path)
837 initial-load-path)))
838 ((or (string-equal argi "-l")
839 (string-equal argi "-load"))
840 (if argval
841 (setq tem argval)
842 (setq tem (car command-line-args-left)
843 command-line-args-left (cdr command-line-args-left)))
844 (let ((file tem))
845 ;; Take file from default dir if it exists there;
846 ;; otherwise let `load' search for it.
847 (if (file-exists-p (expand-file-name file))
848 (setq file (expand-file-name file)))
849 (load file nil t)))
850 ((string-equal argi "-insert")
851 (if argval
852 (setq tem argval)
853 (setq tem (car command-line-args-left)
854 command-line-args-left (cdr command-line-args-left)))
855 (or (stringp tem)
856 (error "File name omitted from `-insert' option"))
857 (insert-file-contents tem))
858 ((string-equal argi "-kill")
859 (kill-emacs t))
860 ((string-match "^\\+[0-9]+\\'" argi)
861 (setq line (string-to-int argi)))
862 ((setq tem (assoc argi command-line-x-option-alist))
863 ;; Ignore X-windows options and their args if not using X.
864 (setq command-line-args-left
865 (nthcdr (nth 1 tem) command-line-args-left)))
866 (t
867 ;; We have almost exhausted our options. See if the
868 ;; user has made any other command-line options available
869 (let ((hooks command-line-functions);; lrs 7/31/89
870 (did-hook nil))
871 (while (and hooks
872 (not (setq did-hook (funcall (car hooks)))))
873 (setq hooks (cdr hooks)))
874 (if (not did-hook)
875 ;; Ok, presume that the argument is a file name
876 (progn
877 (if (string-match "\\`-" argi)
878 (error "Unknown option `%s'" argi))
879 (setq file-count (1+ file-count))
880 (cond ((= file-count 1)
881 (setq first-file-buffer
882 (find-file (expand-file-name argi dir))))
883 (t
884 (find-file-other-window (expand-file-name argi dir))))
885 (or (zerop line)
886 (goto-line line))
887 (setq line 0))))))))
888 ;; If 3 or more files visited, and not all visible,
889 ;; show user what they all are.
890 (if (> file-count 2)
891 (or (get-buffer-window first-file-buffer)
892 (progn (other-window 1)
893 (buffer-menu)))))))
894
895 ;;; startup.el ends here