Major bugfixes and slight enhancements.
[bpt/emacs.git] / lisp / startup.el
CommitLineData
c88ab9ce
ER
1;;; startup.el --- process Emacs shell arguments
2
84691156 3;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
347d0813 4;; Free Software Foundation, Inc.
eea8d4ef 5
630cc463 6;; Maintainer: FSF
d7b4d18f 7;; Keywords: internal
630cc463 8
a726e0d1
JB
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
4746118a 13;; the Free Software Foundation; either version 2, or (at your option)
a726e0d1
JB
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267
EN
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
a726e0d1 25
630cc463 26;;; Commentary:
a726e0d1 27
ab30fc8a
RS
28;; This file parses the command line and gets Emacs running. Options on
29;; the command line are handled in precedence order. The order is the
30;; one in the list below; first described means first handled. Options
31;; within each category (delimited by a bar) are handled in the order
32;; encountered on the command line.
33
34;; -------------------------
35;; -version Print Emacs version to stderr, then exit
36;; --version successfully right away.
37;; This option is handled by emacs.c
38;; -------------------------
39;; -help Print a short usage description and exit
40;; --help successfully right away.
41;; This option is handled by emacs.c
42;; -------------------------
43;; -nl Do not use shared memory (for systems that
44;; -no-shared-memory support this) for the dumped Emacs data.
45;; This option is handled by emacs.c
46;;
47;; -map For VMS.
48;; --map-data This option is handled by emacs.c
49;; -------------------------
50;; -t FILE Use FILE as the name of the terminal.
51;; --terminal FILE Using this implies "-nw" also.
52;; This option is handled by emacs.c
53;; -------------------------
64b0dbdb 54;; -d DISPNAME Use DISPNAME as the name of the X
ab30fc8a
RS
55;; -display DISPNAME display for the initial frame.
56;; --display DISPNAME This option is handled by emacs.c
57;; -------------------------
58;; -nw Do not use a windows system (but use the
568bd708 59;; --no-window-system terminal instead.)
ab30fc8a
RS
60;; This option is handled by emacs.c
61;; -------------------------
62;; -batch Execute noninteractively (messages go to stdout,
63;; --batch variable noninteractive set to t)
64;; This option is handled by emacs.c
65;; -------------------------
66;; -q Do not load user's init file and do not load
67;; -no-init-file "default.el". Regardless of this switch,
6f9340dd 68;; --no-init-file "site-start" is still loaded.
ab30fc8a 69;; -------------------------
6f9340dd 70;; -no-site-file Do not load "site-start.el". (This is the ONLY
ab30fc8a
RS
71;; --no-site-file way to prevent loading that file.)
72;; -------------------------
f6a9d2d8
CW
73;; -no-splash Don't display a splash screen on startup.
74;; --no-splash
1b207153 75;; -------------------------
ab30fc8a
RS
76;; -u USER Load USER's init file instead of the init
77;; -user USER file belonging to the user starting Emacs.
78;; --user USER
79;; -------------------------
80;; -debug-init Don't catch errors in init files; let the
81;; --debug-init debugger run.
82;; -------------------------
83;; -i ICONTYPE Set type of icon using when Emacs is
64b0dbdb 84;; -itype ICONTYPE iconified under X.
ab30fc8a
RS
85;; --icon-type ICONTYPE This option is passed on to term/x-win.el
86;;
64b0dbdb 87;; -iconic Start Emacs iconified.
ab30fc8a
RS
88;; --iconic This option is passed on to term/x-win.el
89;; -------------------------
64b0dbdb 90;; Various X options for colors/fonts/geometry/title etc.
f5627e93 91;; These options are passed on to term/x-win.el which see.
ab30fc8a
RS
92;; -------------------------
93;; FILE Visit FILE.
dc2cd811
GM
94;; -visit FILE
95;; --visit FILE
96;; -file FILE
97;; --file FILE
ab30fc8a
RS
98;;
99;; -L DIRNAME Add DIRNAME to load-path
100;; -directory DIRNAME
101;; --directory DIRNAME
102;;
103;; -l FILE Load and execute the Emacs lisp code
104;; -load FILE in FILE.
105;; --load FILE
106;;
107;; -f FUNC Execute Emacs lisp function FUNC with
108;; -funcall FUNC no arguments. The "-e" form is outdated
109;; --funcall FUNC and should not be used. (It's a typo
110;; -e FUNC promoted to a feature.)
111;;
955093c9
EN
112;; -eval FORM Execute Emacs lisp form FORM.
113;; --eval FORM
dc2cd811
GM
114;; -execute EXPR
115;; --execute EXPR
e6b75e30 116;;
ab30fc8a
RS
117;; -insert FILE Insert the contents of FILE into buffer.
118;; --insert FILE
119;; -------------------------
120;; -kill Kill (exit) Emacs right away.
121;; --kill
122;; -------------------------
a726e0d1 123
630cc463
ER
124;;; Code:
125
a726e0d1
JB
126(setq top-level '(normal-top-level))
127
42a3e6fa 128(defvar command-line-processed nil
2879a13b 129 "Non-nil once command line has been processed.")
a726e0d1 130
42a3e6fa
RS
131(defgroup initialization nil
132 "Emacs start-up procedure"
133 :group 'internal)
134
135(defcustom inhibit-startup-message nil
1d7da582 136 "*Non-nil inhibits the initial startup message.
a726e0d1 137This is for use in your personal init file, once you are familiar
42a3e6fa
RS
138with the contents of the startup message."
139 :type 'boolean
140 :group 'initialization)
a726e0d1 141
1b207153
CW
142(defvaralias 'inhibit-splash-screen 'inhibit-startup-message)
143
42a3e6fa 144(defcustom inhibit-startup-echo-area-message nil
1d7da582 145 "*Non-nil inhibits the initial startup echo area message.
42a3e6fa
RS
146Setting this variable takes effect
147only if you do it with the customization buffer
94487c4e 148or if your `.emacs' file contains a line of this form:
54a003f7 149 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
e5575c06
RS
150If your `.emacs' file is byte-compiled, use the following form instead:
151 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
1d7da582 152Thus, someone else using a copy of your `.emacs' file will see
42a3e6fa
RS
153the startup message unless he personally acts to inhibit it."
154 :type '(choice (const :tag "Don't inhibit")
155 (string :tag "Enter your user name, to inhibit"))
156 :group 'initialization)
1d7da582 157
42a3e6fa
RS
158(defcustom inhibit-default-init nil
159 "*Non-nil inhibits loading the `default' library."
160 :type 'boolean
161 :group 'initialization)
a726e0d1 162
802a980a
GM
163(defcustom inhibit-startup-buffer-menu nil
164 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
165 :type 'boolean
166 :group 'initialization)
167
d7fa5aa2 168(defvar command-switch-alist nil
a726e0d1
JB
169 "Alist of command-line switches.
170Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
171HANDLER-FUNCTION receives switch name as sole arg;
172remaining command-line args are in the variable `command-line-args-left'.")
173
860befc8
RS
174(defvar command-line-args-left nil
175 "List of command-line args not yet processed.")
176
a726e0d1
JB
177(defvar command-line-functions nil ;; lrs 7/31/89
178 "List of functions to process unrecognized command-line arguments.
179Each function should access the dynamically bound variables
b4484ea8 180`argi' (the current argument) and `command-line-args-left' (the remaining
a726e0d1 181arguments). The function should return non-nil only if it recognizes and
b4484ea8
RS
182processes `argi'. If it does so, it may consume successive arguments by
183altering `command-line-args-left' to remove them.")
a726e0d1 184
09a1077c
RS
185(defvar command-line-default-directory nil
186 "Default directory to use for command line arguments.
187This is normally copied from `default-directory' when Emacs starts.")
188
b3afdeb8
RS
189;;; This is here, rather than in x-win.el, so that we can ignore these
190;;; options when we are not using X.
46cfd295 191(defconst command-line-x-option-alist
b3afdeb8
RS
192 '(("-bw" 1 x-handle-numeric-switch border-width)
193 ("-d" 1 x-handle-display)
194 ("-display" 1 x-handle-display)
5676ab57 195 ("-name" 1 x-handle-name-switch)
2c3fef40
RS
196 ("-title" 1 x-handle-switch title)
197 ("-T" 1 x-handle-switch title)
b3afdeb8
RS
198 ("-r" 0 x-handle-switch reverse t)
199 ("-rv" 0 x-handle-switch reverse t)
200 ("-reverse" 0 x-handle-switch reverse t)
201 ("-reverse-video" 0 x-handle-switch reverse t)
202 ("-fn" 1 x-handle-switch font)
203 ("-font" 1 x-handle-switch font)
188b6a5e
EZ
204 ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
205 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
206 ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
b3afdeb8 207 ("-ib" 1 x-handle-numeric-switch internal-border-width)
1f7f78f1 208 ("-g" 1 x-handle-geometry)
9ff6bda1 209 ("-lsp" 1 x-handle-numeric-switch line-spacing)
1f7f78f1 210 ("-geometry" 1 x-handle-geometry)
b3afdeb8
RS
211 ("-fg" 1 x-handle-switch foreground-color)
212 ("-foreground" 1 x-handle-switch foreground-color)
213 ("-bg" 1 x-handle-switch background-color)
214 ("-background" 1 x-handle-switch background-color)
215 ("-ms" 1 x-handle-switch mouse-color)
216 ("-itype" 0 x-handle-switch icon-type t)
217 ("-i" 0 x-handle-switch icon-type t)
218 ("-iconic" 0 x-handle-iconic)
219 ("-xrm" 1 x-handle-xrm-switch)
220 ("-cr" 1 x-handle-switch cursor-color)
221 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
222 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
223 ("-bd" 1 x-handle-switch)
224 ("--border-width" 1 x-handle-numeric-switch border-width)
225 ("--display" 1 x-handle-display)
5676ab57 226 ("--name" 1 x-handle-name-switch)
7775acb8 227 ("--title" 1 x-handle-switch title)
b3afdeb8
RS
228 ("--reverse-video" 0 x-handle-switch reverse t)
229 ("--font" 1 x-handle-switch font)
188b6a5e
EZ
230 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
231 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
232 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
b3afdeb8 233 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
1f7f78f1 234 ("--geometry" 1 x-handle-geometry)
b3afdeb8
RS
235 ("--foreground-color" 1 x-handle-switch foreground-color)
236 ("--background-color" 1 x-handle-switch background-color)
237 ("--mouse-color" 1 x-handle-switch mouse-color)
238 ("--icon-type" 0 x-handle-switch icon-type t)
239 ("--iconic" 0 x-handle-iconic)
240 ("--xrm" 1 x-handle-xrm-switch)
241 ("--cursor-color" 1 x-handle-switch cursor-color)
242 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
9ff6bda1 243 ("--line-spacing" 1 x-handle-numeric-switch line-spacing)
7f944e8e 244 ("--border-color" 1 x-handle-switch border-color)
ca57f55d 245 ("--smid" 1 x-handle-smid))
b3afdeb8
RS
246 "Alist of X Windows options.
247Each element has the form
248 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
249where NAME is the option name string, NUMARGS is the number of arguments
250that the option accepts, HANDLER is a function to call to handle the option.
251FRAME-PARAM (optional) is the frame parameter this option specifies,
252and VALUE is the value which is given to that frame parameter
253\(most options use the argument for this, so VALUE is not present).")
254
e3bd99f5 255(defvar before-init-hook nil
db3f571a 256 "Normal hook run after handling urgent options but before loading init files.")
3fc958a4 257
e3bd99f5 258(defvar after-init-hook nil
db3f571a
KH
259 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
260There is no `condition-case' around the running of these functions;
261therefore, if you set `debug-on-error' non-nil in `.emacs',
262an error in one of these functions will invoke the debugger.")
263
264(defvar emacs-startup-hook nil
265 "Normal hook run after loading init files and handling the command line.")
e3bd99f5 266
a726e0d1 267(defvar term-setup-hook nil
db3f571a
KH
268 "Normal hook run after loading terminal-specific Lisp code.
269It also follows `emacs-startup-hook'. This hook exists for users to set,
a726e0d1
JB
270so as to override the definitions made by the terminal-specific file.
271Emacs never sets this variable itself.")
272
deebb0e9
RS
273(defvar inhibit-startup-hooks nil
274 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
275This is because we already did so.")
276
a726e0d1 277(defvar keyboard-type nil
b4484ea8
RS
278 "The brand of keyboard you are using.
279This variable is used to define
a726e0d1 280the proper function and keypad keys for use under X. It is used in a
94487c4e 281fashion analogous to the environment variable TERM.")
a726e0d1
JB
282
283(defvar window-setup-hook nil
b4484ea8
RS
284 "Normal hook run to initialize window system display.
285Emacs runs this hook after processing the command line arguments and loading
286the user's init file.")
a726e0d1 287
42a3e6fa
RS
288(defcustom initial-major-mode 'lisp-interaction-mode
289 "Major mode command symbol to use for the initial *scratch* buffer."
ce2f921e 290 :type 'function
42a3e6fa 291 :group 'initialization)
a726e0d1 292
42a3e6fa 293(defcustom init-file-user nil
a726e0d1 294 "Identity of user whose `.emacs' file is or was read.
d7fa5aa2
RS
295The value is nil if `-q' or `--no-init-file' was specified,
296meaning do not load any init file.
297
298Otherwise, the value may be the null string, meaning use the init file
299for the user that originally logged in, or it may be a
300string containing a user's name meaning use that person's init file.
a726e0d1 301
2bdfaa42
KH
302In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
303evaluates to the name of the directory where the `.emacs' file was
13fce4e6
RS
304looked for.
305
306Setting `init-file-user' does not prevent Emacs from loading
42a3e6fa
RS
307`site-start.el'. The only way to do that is to use `--no-site-file'."
308 :type '(choice (const :tag "none" nil) string)
309 :group 'initialization)
a726e0d1 310
42a3e6fa 311(defcustom site-run-file "site-start"
b7444d31
RS
312 "File containing site-wide run-time initializations.
313This file is loaded at run-time before `~/.emacs'. It contains inits
314that need to be in place for the entire site, but which, due to their
315higher incidence of change, don't make sense to load into emacs'
316dumped image. Thus, the run-time load order is: 1. file described in
13fce4e6
RS
317this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
318
319Don't use the `site-start.el' file for things some users may not like.
320Put them in `default.el' instead, so that users can more easily
321override them. Users can prevent loading `default.el' with the `-q'
322option or by setting `inhibit-default-init' in their own init files,
323but inhibiting `site-start.el' requires `--no-site-file', which
42a3e6fa 324is less convenient."
93812130 325 :type '(choice (const :tag "none" nil) string)
42a3e6fa 326 :group 'initialization)
b7444d31 327
42a3e6fa
RS
328(defcustom mail-host-address nil
329 "*Name of this machine, for purposes of naming users."
330 :type '(choice (const nil) string)
331 :group 'mail)
c13fbb62 332
680ebfa6
RS
333(defcustom user-mail-address (if command-line-processed
334 (concat (user-login-name) "@"
335 (or mail-host-address
336 (system-name)))
337 ;; Empty string means "not set yet".
338 "")
452e9090
RS
339 "*Full mailing address of this user.
340This is initialized based on `mail-host-address',
42a3e6fa
RS
341after your init file is read, in case it sets `mail-host-address'."
342 :type 'string
343 :group 'mail)
c10d1f06 344
42a3e6fa 345(defcustom auto-save-list-file-prefix
73f13e5a
GM
346 (cond ((eq system-type 'ms-dos)
347 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
4b33deaa 348 "~/_emacs.d/auto-save.list/_s")
73f13e5a
GM
349 (t
350 "~/.emacs.d/auto-save-list/.saves-"))
cdee38c3
KH
351 "Prefix for generating `auto-save-list-file-name'.
352This is used after reading your `.emacs' file to initialize
353`auto-save-list-file-name', by appending Emacs's pid and the system name,
354if you have not already set `auto-save-list-file-name' yourself.
73f13e5a 355Directories in the prefix will be created if necessary.
cdee38c3 356Set this to nil if you want to prevent `auto-save-list-file-name'
42a3e6fa 357from being initialized."
3671f444
KH
358 :type '(choice (const :tag "Don't record a session's auto save list" nil)
359 string)
42a3e6fa 360 :group 'auto-save)
2e05d063 361
a726e0d1
JB
362(defvar init-file-debug nil)
363
52320897
RS
364(defvar init-file-had-error nil)
365
95eada65
RS
366(defvar normal-top-level-add-subdirs-inode-list nil)
367
b693e375
RS
368(defvar pure-space-overflow nil
369 "Non-nil if building Emacs overflowed pure space.")
370
859e15c1 371(defun normal-top-level-add-subdirs-to-load-path ()
0412d833
RS
372 "Add all subdirectories of current directory to `load-path'.
373More precisely, this uses only the subdirectories whose names
f734a13e
DL
374start with letters or digits; it excludes any subdirectory named `RCS'
375or `CVS', and any subdirectory that contains a file named `.nosearch'."
f1180544 376 (let (dirs
95eada65 377 attrs
859e15c1
KH
378 (pending (list default-directory)))
379 ;; This loop does a breadth-first tree walk on DIR's subtree,
380 ;; putting each subdir into DIRS as its contents are examined.
381 (while pending
4e0a3971 382 (push (pop pending) dirs)
722a451d
EZ
383 (let* ((this-dir (car dirs))
384 (contents (directory-files this-dir))
385 (default-directory this-dir)
386 (canonicalized (and (eq system-type 'windows-nt)
387 (untranslated-canonical-name this-dir))))
388 ;; The Windows version doesn't report meaningful inode
389 ;; numbers, so use the canonicalized absolute file name of the
390 ;; directory instead.
391 (setq attrs (or canonicalized
392 (nthcdr 10 (file-attributes this-dir))))
95eada65 393 (unless (member attrs normal-top-level-add-subdirs-inode-list)
4e0a3971
SM
394 (push attrs normal-top-level-add-subdirs-inode-list)
395 (dolist (file contents)
c4a40544 396 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
4e0a3971
SM
397 (unless (member file '("." ".." "RCS" "CVS" "rcs" "cvs"))
398 (when (and (string-match "\\`[[:alnum:]]" file)
9d1fb179
RS
399 ;; Avoid doing a `stat' when it isn't necessary
400 ;; because that can cause trouble when an NFS server
401 ;; is down.
4e0a3971
SM
402 (not (string-match "\\.elc?\\'" file))
403 (file-directory-p file))
404 (let ((expanded (expand-file-name file)))
95eada65
RS
405 (unless (file-exists-p (expand-file-name ".nosearch"
406 expanded))
4e0a3971 407 (setq pending (nconc pending (list expanded)))))))))))
bb15e81a 408 (normal-top-level-add-to-load-path (cdr (nreverse dirs)))))
859e15c1 409
537b6e4e
RS
410;; This function is called from a subdirs.el file.
411;; It assumes that default-directory is the directory
412;; in which the subdirs.el file exists,
413;; and it adds to load-path the subdirs of that directory
414;; as specified in DIRS. Normally the elements of DIRS are relative.
e87a7309 415(defun normal-top-level-add-to-load-path (dirs)
cd1c10f6
RS
416 (let ((tail load-path)
417 (thisdir (directory-file-name default-directory)))
418 (while (and tail
138e541f
GM
419 ;;Don't go all the way to the nil terminator.
420 (cdr tail)
cd1c10f6
RS
421 (not (equal thisdir (car tail)))
422 (not (and (memq system-type '(ms-dos windows-nt))
423 (equal (downcase thisdir) (downcase (car tail))))))
424 (setq tail (cdr tail)))
138e541f
GM
425 ;;Splice the new section in.
426 (when tail
427 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
e87a7309 428
a726e0d1
JB
429(defun normal-top-level ()
430 (if command-line-processed
431 (message "Back to top level.")
432 (setq command-line-processed t)
8d4c2221
RS
433 ;; Give *Messages* the same default-directory as *scratch*,
434 ;; just to keep things predictable.
435 (let ((dir default-directory))
436 (save-excursion
437 (set-buffer (get-buffer "*Messages*"))
438 (setq default-directory dir)))
9715399e
MR
439 ;; `user-full-name' is now known; reset its standard-value here.
440 (put 'user-full-name 'standard-value
441 (list (default-value 'user-full-name)))
80d71556
KH
442 ;; For root, preserve owner and group when editing files.
443 (if (equal (user-uid) 0)
444 (setq backup-by-copying-when-mismatch t))
e87a7309
RS
445 ;; Look in each dir in load-path for a subdirs.el file.
446 ;; If we find one, load it, which will add the appropriate subdirs
447 ;; of that dir into load-path,
357438eb
KH
448 ;; Look for a leim-list.el file too. Loading it will register
449 ;; available input methods.
e87a7309
RS
450 (let ((tail load-path)
451 new)
452 (while tail
4e0a3971 453 (push (car tail) new)
bbfc7591
GM
454 (condition-case nil
455 (let ((default-directory (car tail)))
456 (load (expand-file-name "subdirs.el" (car tail)) t t t)))
357438eb
KH
457 (condition-case nil
458 (let ((default-directory (car tail)))
459 (load (expand-file-name "leim-list.el" (car tail)) t t t)))
e87a7309 460 (setq tail (cdr tail))))
ffd56f97 461 (if (not (eq system-type 'vax-vms))
a4b33896
JB
462 (progn
463 ;; If the PWD environment variable isn't accurate, delete it.
464 (let ((pwd (getenv "PWD")))
465 (and (stringp pwd)
466 ;; Use FOO/., so that if FOO is a symlink, file-attributes
467 ;; describes the directory linked to, not FOO itself.
468 (or (equal (file-attributes
469 (concat (file-name-as-directory pwd) "."))
470 (file-attributes
471 (concat (file-name-as-directory default-directory)
472 ".")))
473 (setq process-environment
474 (delete (concat "PWD=" pwd)
475 process-environment)))))))
492878e4 476 (setq default-directory (abbreviate-file-name default-directory))
6f2c86fa
KH
477 (let ((menubar-bindings-done nil))
478 (unwind-protect
479 (command-line)
480 ;; Do this again, in case .emacs defined more abbreviations.
481 (setq default-directory (abbreviate-file-name default-directory))
b3c7c12c
RS
482 ;; Specify the file for recording all the auto save files of this session.
483 ;; This is used by recover-session.
cdee38c3
KH
484 (or auto-save-list-file-name
485 (and auto-save-list-file-prefix
486 (setq auto-save-list-file-name
1f7f78f1
RS
487 ;; Under MS-DOS our PID is almost always reused between
488 ;; Emacs invocations. We need something more unique.
4b33deaa
EZ
489 (cond ((eq system-type 'ms-dos)
490 ;; We are going to access the auto-save
491 ;; directory, so make sure it exists.
492 (make-directory
493 (file-name-directory auto-save-list-file-prefix)
494 t)
f1180544 495 (concat
4b33deaa
EZ
496 (make-temp-name
497 (expand-file-name
498 auto-save-list-file-prefix))
499 "~"))
500 (t
501 (expand-file-name
502 (format "%s%d-%s~"
503 auto-save-list-file-prefix
504 (emacs-pid)
505 (system-name))))))))
deebb0e9
RS
506 (unless inhibit-startup-hooks
507 (run-hooks 'emacs-startup-hook)
508 (and term-setup-hook
509 (run-hooks 'term-setup-hook)))
6a1e7d67
GM
510
511 ;; Don't do this if we failed to create the initial frame,
512 ;; for instance due to a dense colormap.
538ef02a
GM
513 (when (or frame-initial-frame
514 ;; If frame-initial-frame has no meaning, do this anyway.
515 (not (and window-system
516 (not noninteractive)
517 (not (eq window-system 'pc)))))
6a1e7d67
GM
518 ;; Modify the initial frame based on what .emacs puts into
519 ;; ...-frame-alist.
520 (if (fboundp 'frame-notice-user-settings)
521 (frame-notice-user-settings))
522 (if (fboundp 'frame-set-background-mode)
523 ;; Set the faces for the initial background mode even if
524 ;; frame-notice-user-settings didn't (such as on a tty).
525 ;; frame-set-background-mode is idempotent, so it won't
526 ;; cause any harm if it's already been done.
527 (let ((frame-background-mode frame-background-mode)
528 (frame (selected-frame))
529 term)
530 (when (and (null window-system)
531 ;; Don't override a possibly customized value.
532 (null frame-background-mode)
533 ;; Don't override user specifications.
534 (null (frame-parameter frame 'reverse))
535 (let ((bg (frame-parameter frame 'background-color)))
536 (or (null bg)
537 (member bg '(unspecified "unspecified-bg")))))
538 (setq term (getenv "TERM"))
818cd248
EZ
539 ;; Some files in lisp/term do a better job with the
540 ;; background mode, but we leave this here anyway, in
541 ;; case they remove those files.
6a1e7d67
GM
542 (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
543 term)
544 (setq frame-background-mode 'light)))
545 (frame-set-background-mode (selected-frame)))))
13ab33c4 546
6f2c86fa
KH
547 ;; Now we know the user's default font, so add it to the menu.
548 (if (fboundp 'font-menu-add-default)
549 (font-menu-add-default))
550 (and window-setup-hook
551 (run-hooks 'window-setup-hook))
552 (or menubar-bindings-done
66c24e1e
EZ
553 (if (display-popup-menus-p)
554 (precompute-menubar-bindings)))))))
6f2c86fa
KH
555
556;; Precompute the keyboard equivalents in the menu bar items.
557(defun precompute-menubar-bindings ()
365636dc
RS
558 (let ((submap (lookup-key global-map [menu-bar])))
559 (while submap
560 (and (consp (car submap))
561 (symbolp (car (car submap)))
562 (stringp (car-safe (cdr (car submap))))
563 (keymapp (cdr (cdr (car submap))))
a18042d7
RS
564 (progn
565 (x-popup-menu nil (cdr (cdr (car submap))))
566 (if purify-flag
567 (garbage-collect))))
365636dc 568 (setq submap (cdr submap))))
5b61c6a7 569 (setq define-key-rebound-commands t))
a726e0d1 570
c381f482
EZ
571;; Command-line options supported by tty's:
572(defconst tty-long-option-alist
8957d2bf
EZ
573 '(("--name" . "-name")
574 ("--title" . "-T")
575 ("--reverse-video" . "-reverse")
c381f482 576 ("--foreground-color" . "-fg")
8957d2bf
EZ
577 ("--background-color" . "-bg")
578 ("--color" . "-color")))
c381f482 579
b66b6aeb
GM
580(defconst tool-bar-images-pixel-height 24
581 "Height in pixels of images in the tool bar.")
582
3a55d3d0
JR
583(defvar tool-bar-originally-present nil
584 "Non-nil if tool-bars are present before user and site init files are read.")
585
bca8c7be 586;; Handle the X-like command-line arguments "-fg", "-bg", "-name", etc.
c381f482 587(defun tty-handle-args (args)
bca8c7be 588 (let (rest)
c381f482
EZ
589 (message "%s" args)
590 (while (and args
591 (not (equal (car args) "--")))
bca8c7be
MS
592 (let* ((argi (pop args))
593 (orig-argi argi)
594 argval completion)
c381f482
EZ
595 ;; Check for long options with attached arguments
596 ;; and separate out the attached option argument into argval.
bca8c7be
MS
597 (when (string-match "^\\(--[^=]*\\)=" argi)
598 (setq argval (substring argi (match-end 0))
599 argi (match-string 1 argi)))
600 (when (string-match "^--" argi)
601 (setq completion (try-completion argi tty-long-option-alist))
c381f482
EZ
602 (if (eq completion t)
603 ;; Exact match for long option.
bca8c7be 604 (setq argi (cdr (assoc argi tty-long-option-alist)))
c381f482
EZ
605 (if (stringp completion)
606 (let ((elt (assoc completion tty-long-option-alist)))
607 ;; Check for abbreviated long option.
608 (or elt
bca8c7be
MS
609 (error "Option `%s' is ambiguous" argi))
610 (setq argi (cdr elt)))
c381f482 611 ;; Check for a short option.
bca8c7be
MS
612 (setq argval nil
613 argi orig-argi))))
614 (cond ((member argi '("-fg" "-foreground"))
615 (push (cons 'foreground-color (or argval (pop args)))
616 default-frame-alist))
617 ((member argi '("-bg" "-background"))
618 (push (cons 'background-color (or argval (pop args)))
619 default-frame-alist))
620 ((member argi '("-T" "-name"))
621 (unless argval (setq argval (pop args)))
622 (push (cons 'title
623 (if (stringp argval)
624 argval
625 (let ((case-fold-search t)
626 i)
627 (setq argval (invocation-name))
628
629 ;; Change any . or * characters in name to
630 ;; hyphens, so as to emulate behavior on X.
631 (while
632 (setq i (string-match "[.*]" argval))
633 (aset argval i ?-))
634 argval)))
635 default-frame-alist))
636 ((member argi '("-r" "-rv" "-reverse"))
637 (push '(reverse . t)
638 default-frame-alist))
639 ((equal argi "-color")
640 (unless argval (setq argval 8)) ; default --color means 8 ANSI colors
641 (push (cons 'tty-color-mode
642 (cond
643 ((numberp argval) argval)
644 ((string-match "-?[0-9]+" argval)
645 (string-to-number argval))
646 (t (intern argval))))
647 default-frame-alist))
648 (t
649 (push argi rest)))))
650 (nreverse rest)))
c381f482 651
a726e0d1 652(defun command-line ()
09a1077c
RS
653 (setq command-line-default-directory default-directory)
654
849eedba
RS
655 ;; Choose a reasonable location for temporary files.
656 (setq temporary-file-directory
657 (file-name-as-directory
658 (cond ((memq system-type '(ms-dos windows-nt))
659 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
660 ((memq system-type '(vax-vms axp-vms))
661 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
662 (t
663 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))))
607f86f5
EZ
664 (setq small-temporary-file-directory
665 (if (eq system-type 'ms-dos)
f5568df0 666 (getenv "TMPDIR")))
d88c92eb
EZ
667 (setq auto-save-file-name-transforms
668 (list (list "\\`/[^/]*:\\(.+/\\)*\\(.*\\)"
669 ;; Don't put "\\2" inside expand-file-name, since
670 ;; it will be transformed to "/2" on DOS/Windows.
5ecad17d 671 (concat temporary-file-directory "\\2") t)))
849eedba 672
74f2ab06 673 ;; See if we should import version-control from the environment variable.
a726e0d1
JB
674 (let ((vc (getenv "VERSION_CONTROL")))
675 (cond ((eq vc nil)) ;don't do anything if not set
bca8c7be 676 ((member vc '("t" "numbered"))
a726e0d1 677 (setq version-control t))
bca8c7be 678 ((member vc '("nil" "existing"))
a726e0d1 679 (setq version-control nil))
bca8c7be 680 ((member vc '("never" "simple"))
a726e0d1
JB
681 (setq version-control 'never))))
682
79058860
JB
683 ;;! This has been commented out; I currently find the behavior when
684 ;;! split-window-keep-point is nil disturbing, but if I can get used
685 ;;! to it, then it would be better to eliminate the option.
686 ;;! ;; Choose a good default value for split-window-keep-point.
687 ;;! (setq split-window-keep-point (> baud-rate 2400))
f35fe3c6 688
d4308a4d
EZ
689 ;; Set the default strings to display in mode line for
690 ;; end-of-line formats that aren't native to this platform.
691 (cond
692 ((memq system-type '(ms-dos windows-nt emx))
bca8c7be
MS
693 (setq eol-mnemonic-unix "(Unix)"
694 eol-mnemonic-mac "(Mac)"))
bde61f8b
EZ
695 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
696 ;; abbreviated strings `/' and `:' set in coding.c for them.
697 ((eq system-type 'macos)
698 (setq eol-mnemonic-dos "(DOS)"))
bca8c7be
MS
699 (t ; this is for Unix/GNU/Linux systems
700 (setq eol-mnemonic-dos "(DOS)"
701 eol-mnemonic-mac "(Mac)")))
d4308a4d 702
a726e0d1 703 ;; Read window system's init file if using a window system.
1ed14cfd
RS
704 (condition-case error
705 (if (and window-system (not noninteractive))
706 (load (concat term-file-prefix
707 (symbol-name window-system)
708 "-win")
709 ;; Every window system should have a startup file;
710 ;; barf if we can't find it.
711 nil t))
712 ;; If we can't read it, print the error message and exit.
713 (error
2677ad61
RS
714 (princ
715 (if (eq (car error) 'error)
716 (apply 'concat (cdr error))
717 (if (memq 'file-error (get (car error) 'error-conditions))
718 (format "%s: %s"
bca8c7be
MS
719 (nth 1 error)
720 (mapconcat (lambda (obj) (prin1-to-string obj t))
721 (cdr (cdr error)) ", "))
2677ad61 722 (format "%s: %s"
bca8c7be
MS
723 (get (car error) 'error-message)
724 (mapconcat (lambda (obj) (prin1-to-string obj t))
725 (cdr error) ", "))))
2677ad61 726 'external-debugging-output)
27f5188c 727 (terpri 'external-debugging-output)
2677ad61 728 (setq window-system nil)
1ed14cfd 729 (kill-emacs)))
a726e0d1 730
c381f482 731 ;; Windowed displays do this inside their *-win.el.
bca8c7be 732 (unless (or (display-graphic-p) noninteractive)
c381f482
EZ
733 (setq command-line-args (tty-handle-args command-line-args)))
734
640a9cdd
JR
735 (set-locale-environment nil)
736
c16eb7b0
RS
737 ;; Convert the arguments to Emacs internal representation.
738 (let ((args (cdr command-line-args)))
739 (while args
740 (setcar args
741 (decode-coding-string (car args) locale-coding-system t))
bca8c7be 742 (pop args)))
c16eb7b0 743
03e3c30a
JB
744 (let ((done nil)
745 (args (cdr command-line-args)))
746
a726e0d1
JB
747 ;; Figure out which user's init file to load,
748 ;; either from the environment or from the options.
749 (setq init-file-user (if noninteractive nil (user-login-name)))
750 ;; If user has not done su, use current $HOME to find .emacs.
bca8c7be
MS
751 (and init-file-user
752 (equal init-file-user (user-real-login-name))
a726e0d1 753 (setq init-file-user ""))
03e3c30a
JB
754
755 ;; Process the command-line args, and delete the arguments
756 ;; processed. This is consistent with the way main in emacs.c
757 ;; does things.
a726e0d1 758 (while (and (not done) args)
bca8c7be
MS
759 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
760 ("--debug-init") ("--iconic") ("--icon-type")))
761 (argi (pop args))
762 (orig-argi argi)
763 argval)
452e9090 764 ;; Handle --OPTION=VALUE format.
bca8c7be 765 (when (string-match "^\\(--[^=]*\\)=" argi)
1b207153 766 (setq argval (substring argi (match-end 0))
bca8c7be 767 argi (match-string 1 argi)))
1b207153
CW
768 (unless (equal argi "--")
769 (let ((completion (try-completion argi longopts)))
770 (if (eq completion t)
771 (setq argi (substring argi 1))
772 (if (stringp completion)
773 (let ((elt (assoc completion longopts)))
774 (or elt
775 (error "Option `%s' is ambiguous" argi))
776 (setq argi (substring (car elt) 1)))
bca8c7be
MS
777 (setq argval nil
778 argi orig-argi)))))
a726e0d1 779 (cond
4e0a3971
SM
780 ((member argi '("-q" "-no-init-file"))
781 (setq init-file-user nil))
782 ((member argi '("-u" "-user"))
bca8c7be 783 (setq init-file-user (or argval (pop args))
4e0a3971 784 argval nil))
bca8c7be 785 ((equal argi "-no-site-file")
4e0a3971 786 (setq site-run-file nil))
bca8c7be 787 ((equal argi "-debug-init")
4e0a3971 788 (setq init-file-debug t))
bca8c7be 789 ((equal argi "-iconic")
4e0a3971 790 (push '(visibility . icon) initial-frame-alist))
bca8c7be 791 ((member argi '("-icon-type" "-i" "-itype"))
4e0a3971
SM
792 (push '(icon-type . t) default-frame-alist))
793 ;; Push the popped arg back on the list of arguments.
bca8c7be
MS
794 (t
795 (push argi args)
796 (setq done t)))
096b7031
KH
797 ;; Was argval set but not used?
798 (and argval
799 (error "Option `%s' doesn't allow an argument" argi))))
800
03e3c30a 801 ;; Re-attach the program name to the front of the arg list.
bca8c7be
MS
802 (and command-line-args
803 (setcdr command-line-args args)))
a726e0d1 804
c722566c 805 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
14f16b9c
GM
806 (when (fboundp 'frame-initialize)
807 (frame-initialize))
808
1fe0333f 809 ;; If frame was created with a menu bar, set menu-bar-mode on.
bca8c7be
MS
810 (unless (or noninteractive
811 (and (memq window-system '(x w32))
812 (<= (frame-parameter nil 'menu-bar-lines) 0)))
8ab9589d 813 (menu-bar-mode 1))
c722566c 814
7d1eb6a4 815 ;; If frame was created with a tool bar, switch tool-bar-mode on.
bca8c7be
MS
816 (unless (or noninteractive
817 (not (display-graphic-p))
818 (<= (frame-parameter nil 'tool-bar-lines) 0))
b66b6aeb 819 (tool-bar-mode 1))
7d1eb6a4 820
6753393b 821 ;; Can't do this init in defcustom because window-system isn't set.
bca8c7be
MS
822 (unless (or noninteractive
823 (eq system-type 'ms-dos)
824 (not (memq window-system '(x w32))))
6753393b
GM
825 (setq-default blink-cursor t)
826 (blink-cursor-mode 1))
827
3ecd8ad0
GM
828 (unless noninteractive
829 ;; DOS/Windows systems have a PC-type keyboard which has both
830 ;; <delete> and <backspace> keys.
831 (when (or (memq system-type '(ms-dos windows-nt))
832 (and (memq window-system '(x))
833 (fboundp 'x-backspace-delete-keys-p)
7360b8aa
GM
834 (x-backspace-delete-keys-p))
835 ;; If the terminal Emacs is running on has erase char
836 ;; set to ^H, use the Backspace key for deleting
837 ;; backward and, and the Delete key for deleting forward.
838 (and (null window-system)
839 (eq tty-erase-char 8)))
d8e17bc6
EZ
840 (setq-default normal-erase-is-backspace t)
841 (normal-erase-is-backspace-mode 1)))
14f076a8 842
bca8c7be
MS
843 (unless (or noninteractive
844 (not (display-graphic-p))
845 (not (fboundp 'x-show-tip)))
3b73087e
GM
846 (setq-default tooltip-mode t)
847 (tooltip-mode 1))
848
1592c1ef
EZ
849 ;; Register default TTY colors for the case the terminal hasn't a
850 ;; terminal init file.
bca8c7be
MS
851 (unless (memq window-system '(x w32))
852 ;; We do this regardles of whether the terminal supports colors
853 ;; or not, since they can switch that support on or off in
854 ;; mid-session by setting the tty-color-mode frame parameter.
855 (tty-register-default-colors))
1592c1ef 856
3a55d3d0
JR
857 ;; Record whether the tool-bar is present before the user and site
858 ;; init files are processed. frame-notice-user-settings uses this
859 ;; to determine if the tool-bar has been disabled by the init files,
860 ;; and the frame needs to be resized.
861 (when (fboundp 'frame-notice-user-settings)
862 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
863 (assq 'tool-bar-lines default-frame-alist))))
864 (setq tool-bar-originally-present
bca8c7be
MS
865 (and tool-bar-lines
866 (cdr tool-bar-lines)
867 (not (eq 0 (cdr tool-bar-lines)))))))
3a55d3d0 868
752ef254
GM
869 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
870 (old-font-list-limit font-list-limit)
871 (old-face-ignored-fonts face-ignored-fonts))
872
873 (run-hooks 'before-init-hook)
874
875 ;; Run the site-start library if it exists. The point of this file is
876 ;; that it is run before .emacs. There is no point in doing this after
877 ;; .emacs; that is useless.
f1180544 878 (if site-run-file
752ef254
GM
879 (load site-run-file t t))
880
881 ;; Sites should not disable this. Only individuals should disable
882 ;; the startup message.
883 (setq inhibit-startup-message nil)
884
885 ;; Load that user's init file, or the default one, or none.
886 (let (debug-on-error-from-init-file
887 debug-on-error-should-be-set
888 (debug-on-error-initial
889 (if (eq init-file-debug t) 'startup init-file-debug))
890 (orig-enable-multibyte default-enable-multibyte-characters))
891 (let ((debug-on-error debug-on-error-initial)
892 ;; This function actually reads the init files.
893 (inner
894 (function
895 (lambda ()
896 (if init-file-user
897 (let ((user-init-file-1
4e0a3971 898 (cond
752ef254
GM
899 ((eq system-type 'ms-dos)
900 (concat "~" init-file-user "/_emacs"))
901 ((eq system-type 'windows-nt)
902 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
903 "~/.emacs"
904 "~/_emacs"))
f1180544 905 ((eq system-type 'vax-vms)
752ef254 906 "sys$login:.emacs")
4e0a3971 907 (t
752ef254
GM
908 (concat "~" init-file-user "/.emacs")))))
909 ;; This tells `load' to store the file name found
910 ;; into user-init-file.
911 (setq user-init-file t)
912 (load user-init-file-1 t t)
f1180544 913
a04d5983
RS
914 (when (eq user-init-file t)
915 ;; If we did not find ~/.emacs, try
916 ;; ~/.emacs.d/.emacs.
917 (let ((otherfile
918 (expand-file-name
919 (file-name-nondirectory user-init-file-1)
920 (file-name-as-directory
921 (expand-file-name
922 ".emacs.d"
923 (file-name-directory user-init-file-1))))))
924 (load otherfile t t)
925
926 ;; If we did not find the user's init file,
927 ;; set user-init-file conclusively.
928 ;; Don't let it be set from default.el.
929 (when (eq user-init-file t)
930 (setq user-init-file user-init-file-1))))
f1180544 931
752ef254
GM
932 ;; If we loaded a compiled file, set
933 ;; `user-init-file' to the source version if that
934 ;; exists.
935 (when (and user-init-file
936 (equal (file-name-extension user-init-file)
937 "elc"))
938 (let* ((source (file-name-sans-extension user-init-file))
939 (alt (concat source ".el")))
940 (setq source (cond ((file-exists-p alt) alt)
941 ((file-exists-p source) source)
942 (t nil)))
943 (when source
944 (when (file-newer-than-file-p source user-init-file)
945 (message "Warning: %s is newer than %s"
946 source user-init-file)
947 (sit-for 1))
948 (setq user-init-file source))))
f1180544 949
bca8c7be
MS
950 (when (stringp custom-file)
951 (unless (assoc custom-file load-history)
952 ;; If the .emacs file has set `custom-file' but hasn't
953 ;; loaded the file yet, let's load it.
954 (load custom-file t t)))
955
956 (unless inhibit-default-init
957 (let ((inhibit-startup-message nil))
958 ;; Users are supposed to be told their rights.
959 ;; (Plus how to get help and how to undo.)
960 ;; Don't you dare turn this off for anyone
961 ;; except yourself.
962 (load "default" t t)))))))))
752ef254
GM
963 (if init-file-debug
964 ;; Do this without a condition-case if the user wants to debug.
965 (funcall inner)
966 (condition-case error
967 (progn
968 (funcall inner)
969 (setq init-file-had-error nil))
970 (error
971 (let ((message-log-max nil))
972 (save-excursion
973 (set-buffer (get-buffer-create "*Messages*"))
974 (insert "\n\n"
975 (format "An error has occurred while loading `%s':\n\n"
976 user-init-file)
977 (format "%s%s%s"
978 (get (car error) 'error-message)
979 (if (cdr error) ": " "")
f5b6cffd 980 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
752ef254 981 "\n\n"
f5b6cffd
KS
982 "To ensure normal operation, you should investigate and remove the\n"
983 "cause of the error in your initialization file. Start Emacs with\n"
984 "the `--debug-init' option to view a complete error backtrace.\n\n"))
752ef254
GM
985 (message "Error in init file: %s%s%s"
986 (get (car error) 'error-message)
987 (if (cdr error) ": " "")
988 (mapconcat 'prin1-to-string (cdr error) ", "))
f5b6cffd
KS
989 (let ((pop-up-windows nil))
990 (pop-to-buffer "*Messages*"))
752ef254 991 (setq init-file-had-error t)))))
ac3186fd
RS
992
993 ;; If the user has a file of abbrevs, read it.
994 (if (file-exists-p abbrev-file-name)
995 (quietly-read-abbrev-file abbrev-file-name))
996
70b199c3
RS
997 ;; If the abbrevs came entirely from the init file or the
998 ;; abbrevs file, they do not need saving.
999 (setq abbrevs-changed nil)
1000
752ef254
GM
1001 ;; If we can tell that the init file altered debug-on-error,
1002 ;; arrange to preserve the value that it set up.
1003 (or (eq debug-on-error debug-on-error-initial)
1004 (setq debug-on-error-should-be-set t
1005 debug-on-error-from-init-file debug-on-error)))
1006 (if debug-on-error-should-be-set
1007 (setq debug-on-error debug-on-error-from-init-file))
1008 (unless (or default-enable-multibyte-characters
1009 (eq orig-enable-multibyte default-enable-multibyte-characters))
1010 ;; Init file changed to unibyte. Reset existing multibyte
1011 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1012 ;; Arguably this should only be done if they're free of
1013 ;; multibyte characters.
1014 (mapcar (lambda (buffer)
1015 (with-current-buffer buffer
1016 (if enable-multibyte-characters
1017 (set-buffer-multibyte nil))))
1018 (buffer-list))
1019 ;; Also re-set the language environment in case it was
1020 ;; originally done before unibyte was set and is sensitive to
1021 ;; unibyte (display table, terminal coding system &c).
1022 (set-language-environment current-language-environment)))
f1180544 1023
752ef254 1024 ;; Do this here in case the init file sets mail-host-address.
5b88a2c5 1025 (if (equal user-mail-address "")
752ef254
GM
1026 (setq user-mail-address (concat (user-login-name) "@"
1027 (or mail-host-address
1028 (system-name)))))
1029
1030 ;; If parameter have been changed in the init file which influence
1031 ;; face realization, clear the face cache so that new faces will
1032 ;; be realized.
1033 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1034 (eq font-list-limit old-font-list-limit)
1035 (eq face-ignored-fonts old-face-ignored-fonts))
1036 (clear-face-cache)))
f1180544 1037
e3bd99f5
RM
1038 (run-hooks 'after-init-hook)
1039
a726e0d1
JB
1040 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1041 (if (get-buffer "*scratch*")
694210c4 1042 (with-current-buffer "*scratch*"
a726e0d1
JB
1043 (if (eq major-mode 'fundamental-mode)
1044 (funcall initial-major-mode))))
f1180544 1045
a726e0d1
JB
1046 ;; Load library for our terminal type.
1047 ;; User init file can set term-file-prefix to nil to prevent this.
bca8c7be
MS
1048 (unless (or noninteractive
1049 window-system
1050 (null term-file-prefix))
1051 (let ((term (getenv "TERM"))
1052 hyphend)
1053 (while (and term
1054 (not (load (concat term-file-prefix term) t t)))
1055 ;; Strip off last hyphen and what follows, then try again
1056 (setq term
1057 (if (setq hyphend (string-match "[-_][^-_]+$" term))
1058 (substring term 0 hyphend)
1059 nil)))))
a726e0d1 1060
5777a167
RS
1061 ;; Update the out-of-memory error message based on user's key bindings
1062 ;; for save-some-buffers.
1063 (setq memory-signal-data
1064 (list 'error
1065 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1066
03e3c30a 1067 ;; Process the remaining args.
a726e0d1
JB
1068 (command-line-1 (cdr command-line-args))
1069
1070 ;; If -batch, terminate after processing the command options.
ca57f55d
JD
1071 (if noninteractive (kill-emacs t))
1072
1073 ;; Run emacs-session-restore (session management) if started by
1074 ;; the session manager and we have a session manager connection.
bca8c7be
MS
1075 (if (and (boundp 'x-session-previous-id)
1076 (stringp x-session-previous-id))
70646cf0 1077 (emacs-session-restore x-session-previous-id)))
a726e0d1 1078
46cfd295 1079(defcustom initial-scratch-message (purecopy "\
3b79c219
GM
1080;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1081;; If you want to create a file, visit that file with C-x C-f,
1082;; then enter the text in that file's own buffer.
9fe3219e 1083
46cfd295 1084")
9fe3219e
RS
1085 "Initial message displayed in *scratch* buffer at startup.
1086If this is nil, no message will be displayed."
fa071a47
RS
1087 :type '(choice (text :tag "Message")
1088 (const :tag "none" nil))
1089 :group 'initialization)
9fe3219e 1090
ce9ded5d
GM
1091\f
1092;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1093;;; Fancy splash screen
1094;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1095
1096(defvar fancy-splash-text
26ff68aa 1097 '((:face variable-pitch
926aa0ee 1098 "You can do basic editing with the menu bar and scroll bar \
926aa0ee 1099using the mouse.\n\n"
26ff68aa 1100 :face (variable-pitch :weight bold)
ce9ded5d 1101 "Important Help menu items:\n"
26ff68aa 1102 :face variable-pitch "\
d7618b60 1103Emacs Tutorial\tLearn-by-doing tutorial for using Emacs efficiently
1fc02b3c 1104Emacs FAQ\tFrequently asked questions and answers
5777a167 1105Read the Emacs Manual\tView the Emacs manual using Info
1fc02b3c 1106\(Non)Warranty\tGNU Emacs comes with "
26ff68aa 1107 :face (variable-pitch :slant oblique)
ce9ded5d 1108 "ABSOLUTELY NO WARRANTY\n"
26ff68aa 1109 :face variable-pitch
d3c5bad2 1110 "\
d7618b60 1111Copying Conditions\tConditions for redistributing and changing Emacs
682b60ae 1112More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
d7618b60
GM
1113 (:face variable-pitch
1114 "You can do basic editing with the menu bar and scroll bar \
1115using the mouse.\n\n"
1116 :face (variable-pitch :weight bold)
1117 "Useful File menu items:\n"
1118 :face variable-pitch "\
1119Exit Emacs\t(Or type Control-x followed by Control-c)
1120Recover Session\tRecover files you were editing before a crash
1121
1122
1123
3f334882 1124
d7618b60
GM
1125"
1126 ))
ce9ded5d
GM
1127 "A list of texts to show in the middle part of splash screens.
1128Each element in the list should be a list of strings or pairs
1129`:face FACE', like `fancy-splash-insert' accepts them.")
1130
1131
fb275c02 1132(defgroup fancy-splash-screen ()
a01bb1db 1133 "Fancy splash screen when Emacs starts."
fb275c02 1134 :version "21.1"
a01bb1db
GM
1135 :group 'initialization)
1136
1137
e9da51a1 1138(defcustom fancy-splash-delay 10
49939379 1139 "*Delay in seconds between splash screens."
a01bb1db 1140 :group 'fancy-splash-screen
ce9ded5d
GM
1141 :type 'integer)
1142
1143
e9da51a1
GM
1144(defcustom fancy-splash-max-time 60
1145 "*Show splash screens for at most this number of seconds.
1146Values less than 60 seconds are ignored."
1147 :group 'fancy-splash-screen
1148 :type 'integer)
1149
1150
8ad8561b
GM
1151(defcustom fancy-splash-image nil
1152 "*The image to show in the splash screens, or nil for defaults."
a01bb1db 1153 :group 'fancy-splash-screen
8ad8561b
GM
1154 :type '(choice (const :tag "Default" nil)
1155 (file :tag "File")))
ce9ded5d
GM
1156
1157
f645586f
GM
1158;; These are temporary storage areas for the splash screen display.
1159
1160(defvar fancy-current-text nil)
1161(defvar fancy-splash-help-echo nil)
e9da51a1 1162(defvar fancy-splash-stop-time nil)
eae91b60 1163(defvar fancy-splash-outer-buffer nil)
f645586f 1164
ce9ded5d
GM
1165(defun fancy-splash-insert (&rest args)
1166 "Insert text into the current buffer, with faces.
1167Arguments from ARGS should be either strings or pairs `:face FACE',
1168where FACE is a valid face specification, as it can be used with
1169`put-text-properties'."
1170 (let ((current-face nil))
1171 (while args
1172 (if (eq (car args) :face)
1173 (setq args (cdr args) current-face (car args))
f645586f
GM
1174 (insert (propertize (car args)
1175 'face current-face
1176 'help-echo fancy-splash-help-echo)))
ce9ded5d
GM
1177 (setq args (cdr args)))))
1178
1179
1180(defun fancy-splash-head ()
1181 "Insert the head part of the splash screen into the current buffer."
51e8cfdd
GM
1182 (let* ((image-file (cond ((stringp fancy-splash-image)
1183 fancy-splash-image)
1184 ((and (display-color-p)
1185 (image-type-available-p 'xpm))
1186 (if (and (fboundp 'x-display-planes)
1187 (= (funcall 'x-display-planes) 8))
1188 "splash8.xpm"
1189 "splash.xpm"))
1190 (t "splash.pbm")))
1191 (img (create-image image-file))
ce9ded5d
GM
1192 (image-width (and img (car (image-size img))))
1193 (window-width (window-width (selected-window))))
1194 (when img
1195 (when (> window-width image-width)
f645586f 1196 ;; Center the image in the window.
ce9ded5d
GM
1197 (let ((pos (/ (- window-width image-width) 2)))
1198 (insert (propertize " " 'display `(space :align-to ,pos))))
f645586f 1199
e7f3afa9
MB
1200 ;; Change the color of the XPM version of the splash image
1201 ;; so that it is visible with a dark frame background.
1202 (when (and (memq 'xpm img)
1203 (eq (frame-parameter nil 'background-mode) 'dark))
1204 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1205
f645586f
GM
1206 ;; Insert the image with a help-echo and a keymap.
1207 (let ((map (make-sparse-keymap))
a622451f 1208 (help-echo "mouse-2: browse http://www.gnu.org/"))
f645586f
GM
1209 (define-key map [mouse-2]
1210 (lambda ()
1211 (interactive)
a622451f 1212 (browse-url "http://www.gnu.org/")
f645586f
GM
1213 (throw 'exit nil)))
1214 (define-key map [down-mouse-2] 'ignore)
1215 (define-key map [up-mouse-2] 'ignore)
1216 (insert-image img (propertize "xxx" 'help-echo help-echo
1217 'keymap map)))
ce9ded5d 1218 (insert "\n"))))
9d5cf87c
RS
1219 (fancy-splash-insert
1220 :face '(variable-pitch :foreground "red")
1221 (if (eq system-type 'gnu/linux)
1222 "GNU Emacs is one component of the GNU/Linux operating system."
b831c087 1223 "GNU Emacs is one component of the GNU operating system."))
eae91b60
RS
1224 (insert "\n")
1225 (unless (equal (buffer-name fancy-splash-outer-buffer) "*scratch*")
1226 (fancy-splash-insert :face 'variable-pitch
1227 (substitute-command-keys
1228 "Type \\[recenter] to begin editing your file.\n"))))
ce9ded5d
GM
1229
1230
1231(defun fancy-splash-tail ()
1232 "Insert the tail part of the splash screen into the current buffer."
95fadcca
GM
1233 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1234 "cyan" "darkblue")))
1235 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1236 "\nThis is "
1237 (emacs-version)
1238 "\n"
1239 :face '(variable-pitch :height 0.5)
84691156 1240 "Copyright (C) 2002 Free Software Foundation, Inc.")
ed638cc9
RS
1241 (and auto-save-list-file-prefix
1242 ;; Don't signal an error if the
1243 ;; directory for auto-save-list files
1244 ;; does not yet exist.
1245 (file-directory-p (file-name-directory
1246 auto-save-list-file-prefix))
1247 (directory-files
1248 (file-name-directory auto-save-list-file-prefix)
1249 nil
1250 (concat "\\`"
1251 (regexp-quote (file-name-nondirectory
1252 auto-save-list-file-prefix)))
1253 t)
1254 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1255 "\n\nIf an Emacs session crashed recently, "
1256 "type M-x recover-session RET\nto recover"
1257 " the files you were editing."))))
ce9ded5d 1258
f645586f
GM
1259(defun fancy-splash-screens-1 (buffer)
1260 "Timer function displaying a splash screen."
e9da51a1
GM
1261 (when (> (float-time) fancy-splash-stop-time)
1262 (throw 'stop-splashing nil))
f645586f
GM
1263 (unless fancy-current-text
1264 (setq fancy-current-text fancy-splash-text))
1265 (let ((text (car fancy-current-text)))
1266 (set-buffer buffer)
1267 (erase-buffer)
b693e375
RS
1268 (if pure-space-overflow
1269 (insert "Warning Warning Pure space overflow Warning Warning\n"))
f645586f
GM
1270 (fancy-splash-head)
1271 (apply #'fancy-splash-insert text)
1272 (fancy-splash-tail)
1273 (unless (current-message)
1274 (message fancy-splash-help-echo))
1275 (set-buffer-modified-p nil)
dbeb499b 1276 (goto-char (point-min))
f645586f
GM
1277 (force-mode-line-update)
1278 (setq fancy-current-text (cdr fancy-current-text))))
1279
1280
1281(defun fancy-splash-default-action ()
732950b1
JB
1282 "Stop displaying the splash screen buffer.
1283This is an internal function used to turn off the splash screen after
1284the user caused an input event by hitting a key or clicking with the
1285mouse."
f645586f
GM
1286 (interactive)
1287 (push last-command-event unread-command-events)
1288 (throw 'exit nil))
1289
1290
ce9ded5d 1291(defun fancy-splash-screens ()
f645586f 1292 "Display fancy splash screens when Emacs starts."
5b61c6a7 1293 (setq fancy-splash-help-echo (startup-echo-area-message))
848c7757 1294 (let ((old-hourglass display-hourglass)
eae91b60
RS
1295 (fancy-splash-outer-buffer (current-buffer))
1296 splash-buffer
ff4ec1f7 1297 (old-minor-mode-map-alist minor-mode-map-alist)
6b20fb8e 1298 (frame (fancy-splash-frame))
5b61c6a7 1299 timer)
6b20fb8e
RS
1300 (save-selected-window
1301 (select-frame frame)
1302 (switch-to-buffer "GNU Emacs")
1303 (setq tab-width 20)
1304 (setq splash-buffer (current-buffer))
1305 (catch 'stop-splashing
1306 (unwind-protect
1307 (let ((map (make-sparse-keymap)))
1308 (use-local-map map)
1309 (define-key map [switch-frame] 'ignore)
1310 (define-key map [t] 'fancy-splash-default-action)
1311 (define-key map [mouse-movement] 'ignore)
1312 (define-key map [mode-line t] 'ignore)
1313 (setq cursor-type nil
1314 display-hourglass nil
1315 minor-mode-map-alist nil
1316 buffer-undo-list t
f1180544 1317 mode-line-format (propertize "---- %b %-"
6b20fb8e
RS
1318 'face '(:weight bold))
1319 fancy-splash-stop-time (+ (float-time)
1320 (max 60 fancy-splash-max-time))
1321 timer (run-with-timer 0 fancy-splash-delay
1322 #'fancy-splash-screens-1
1323 splash-buffer))
1324 (recursive-edit))
e9da51a1 1325 (cancel-timer timer)
ff4ec1f7
GM
1326 (setq display-hourglass old-hourglass
1327 minor-mode-map-alist old-minor-mode-map-alist)
6b20fb8e
RS
1328 (kill-buffer splash-buffer))))))
1329
1330(defun fancy-splash-frame ()
1331 "Return the frame to use for the fancy splash screen.
1332Returning non-nil does not mean we should necessarily
1333use the fancy splash screen, but if we do use it,
1334we put it on this frame."
1335 (let (chosen-frame)
3a321ddb 1336 (dolist (frame (append (frame-list) (list (selected-frame))))
6b20fb8e
RS
1337 (if (and (frame-visible-p frame)
1338 (not (window-minibuffer-p (frame-selected-window frame))))
1339 (setq chosen-frame frame)))
1340 chosen-frame))
f645586f 1341
285991dc
GM
1342(defun use-fancy-splash-screens-p ()
1343 "Return t if fancy splash screens should be used."
9df076f2
GM
1344 (when (and (display-graphic-p)
1345 (or (and (display-color-p)
285991dc 1346 (image-type-available-p 'xpm))
9df076f2 1347 (image-type-available-p 'pbm)))
16d2fae9
JPW
1348 (let ((frame (fancy-splash-frame)))
1349 (when frame
1350 (let* ((img (create-image (or fancy-splash-image
1351 (if (and (display-color-p)
1352 (image-type-available-p 'xpm))
1353 "splash.xpm" "splash.pbm"))))
1354 (image-height (and img (cdr (image-size img))))
1355 (window-height (1- (window-height (frame-selected-window frame)))))
1356 (> window-height (+ image-height 19)))))))
285991dc
GM
1357
1358
c61453ea
PJ
1359(defun normal-splash-screen ()
1360 "Display splash screen when Emacs starts."
82e736c1
JPW
1361 (let ((prev-buffer (current-buffer)))
1362 (unwind-protect
1363 (with-current-buffer (get-buffer-create "GNU Emacs")
1364 (let ((tab-width 8)
f1180544 1365 (mode-line-format (propertize "---- %b %-"
82e736c1
JPW
1366 'face '(:weight bold))))
1367
b693e375
RS
1368 (if pure-space-overflow
1369 (insert "Warning Warning Pure space overflow Warning Warning\n"))
1370
82e736c1
JPW
1371 ;; The convention for this piece of code is that
1372 ;; each piece of output starts with one or two newlines
1373 ;; and does not end with any newlines.
1374 (insert "Welcome to GNU Emacs")
9d5cf87c
RS
1375 (insert
1376 (if (eq system-type 'gnu/linux)
1377 ", one component of the GNU/Linux operating system.\n"
1378 ", a part of the GNU operating system.\n"))
82e736c1
JPW
1379
1380 (unless (equal (buffer-name prev-buffer) "*scratch*")
1381 (insert (substitute-command-keys
1382 "\nType \\[recenter] to begin editing your file.\n")))
1383
1384 (if (display-mouse-p)
1385 ;; The user can use the mouse to activate menus
1386 ;; so give help in terms of menu items.
1387 (progn
1388 (insert "\
c61453ea
PJ
1389You can do basic editing with the menu bar and scroll bar using the mouse.
1390
1391Useful File menu items:
1392Exit Emacs (or type Control-x followed by Control-c)
1393Recover Session recover files you were editing before a crash
1394
1395Important Help menu items:
1396Emacs Tutorial Learn-by-doing tutorial for using Emacs efficiently.
1397Emacs FAQ Frequently asked questions and answers
5777a167 1398Read the Emacs Manual View the Emacs manual using Info
c61453ea
PJ
1399\(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1400Copying Conditions Conditions for redistributing and changing Emacs.
1401Getting New Versions How to obtain the latest version of Emacs.
682b60ae 1402More Manuals / Ordering Manuals How to order printed manuals from the FSF.
c61453ea 1403")
82e736c1
JPW
1404 (insert "\n\n" (emacs-version)
1405 "
84691156 1406Copyright (C) 2002 Free Software Foundation, Inc."))
c61453ea 1407
82e736c1
JPW
1408 ;; No mouse menus, so give help using kbd commands.
1409
1410 ;; If keys have their default meanings,
1411 ;; use precomputed string to save lots of time.
1412 (if (and (eq (key-binding "\C-h") 'help-command)
1413 (eq (key-binding "\C-xu") 'advertised-undo)
1414 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1415 (eq (key-binding "\C-ht") 'help-with-tutorial)
1416 (eq (key-binding "\C-hi") 'info)
1417 (eq (key-binding "\C-hr") 'info-emacs-manual)
1418 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1419 (insert "
c61453ea 1420Get help C-h (Hold down CTRL and press h)
5777a167
RS
1421Emacs manual C-h r
1422Emacs tutorial C-h t Undo changes C-x u
1423Buy manuals C-h C-m Exit Emacs C-x C-c
1424Browse manuals C-h i")
1425
82e736c1
JPW
1426 (insert (substitute-command-keys
1427 (format "\n
c61453ea 1428Get help %s
5777a167 1429Emacs manual \\[info-emacs-manual]
82e736c1
JPW
1430Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1431Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-emacs]
5777a167 1432Browse manuals \\[info]"
82e736c1
JPW
1433 (let ((where (where-is-internal
1434 'help-command nil t)))
1435 (if where
1436 (key-description where)
1437 "M-x help"))))))
1438
1439 ;; Say how to use the menu bar with the keyboard.
1440 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1441 (eq (key-binding [f10]) 'tmm-menubar))
1442 (insert "
c61453ea 1443Activate menubar F10 or ESC ` or M-`")
82e736c1 1444 (insert (substitute-command-keys "
c61453ea
PJ
1445Activate menubar \\[tmm-menubar]")))
1446
82e736c1
JPW
1447 ;; Many users seem to have problems with these.
1448 (insert "
c61453ea
PJ
1449\(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1450If you have no Meta key, you may instead type ESC followed by the character.)")
1451
82e736c1
JPW
1452 (insert "\n\n" (emacs-version)
1453 "
84691156 1454Copyright (C) 2002 Free Software Foundation, Inc.")
c61453ea 1455
82e736c1
JPW
1456 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1457 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1458 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
f1180544 1459 (insert
82e736c1 1460 "\n
c61453ea
PJ
1461GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1462Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1463of Emacs and modify it; type C-h C-c to see the conditions.
1464Type C-h C-d for information on getting the latest version.")
82e736c1
JPW
1465 (insert (substitute-command-keys
1466 "\n
c61453ea
PJ
1467GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1468Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1469of Emacs and modify it; type \\[describe-copying] to see the conditions.
1470Type \\[describe-distribution] for information on getting the latest version."))))
1471
82e736c1
JPW
1472 ;; The rest of the startup screen is the same on all
1473 ;; kinds of terminals.
1474
1475 ;; Give information on recovering, if there was a crash.
1476 (and auto-save-list-file-prefix
1477 ;; Don't signal an error if the
1478 ;; directory for auto-save-list files
1479 ;; does not yet exist.
1480 (file-directory-p (file-name-directory
1481 auto-save-list-file-prefix))
1482 (directory-files
1483 (file-name-directory auto-save-list-file-prefix)
1484 nil
1485 (concat "\\`"
1486 (regexp-quote (file-name-nondirectory
1487 auto-save-list-file-prefix)))
1488 t)
1489 (insert "\n\nIf an Emacs session crashed recently, "
1490 "type M-x recover-session RET\nto recover"
1491 " the files you were editing."))
1492
1493 ;; Display the input that we set up in the buffer.
1494 (set-buffer-modified-p nil)
1495 (goto-char (point-min))
1496 (save-window-excursion
1497 (switch-to-buffer (current-buffer))
1498 (sit-for 120))))
1499 ;; Unwind ... ensure splash buffer is killed
1500 (kill-buffer "GNU Emacs"))))
1501
c61453ea 1502
f645586f
GM
1503(defun startup-echo-area-message ()
1504 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1505 "For information about the GNU Project and its goals, type C-h C-p."
1506 (substitute-command-keys
1507 "For information about the GNU Project and its goals, type \
1508\\[describe-project].")))
ce9ded5d
GM
1509
1510
49939379 1511(defun display-startup-echo-area-message ()
15fa6db0
GM
1512 (let ((resize-mini-windows t))
1513 (message (startup-echo-area-message))))
f645586f 1514
49939379 1515
c61453ea
PJ
1516(defun display-splash-screen ()
1517 "Display splash screen according to display.
1518Fancy splash screens are used on graphic displays,
1519normal otherwise."
1520 (interactive)
9df076f2 1521 (if (use-fancy-splash-screens-p)
c61453ea
PJ
1522 (fancy-splash-screens)
1523 (normal-splash-screen)))
1524
1525
a726e0d1 1526(defun command-line-1 (command-line-args-left)
52320897 1527 (or noninteractive (input-pending-p) init-file-had-error
ed638cc9
RS
1528 ;; t if the init file says to inhibit the echo area startup message.
1529 (and inhibit-startup-echo-area-message
1530 user-init-file
1531 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1532 (equal inhibit-startup-echo-area-message
bca8c7be 1533 (if (equal init-file-user "")
ed638cc9
RS
1534 (user-login-name)
1535 init-file-user)))
1536 ;; Wasn't set with custom; see if .emacs has a setq.
1537 (let ((buffer (get-buffer-create " *temp*")))
1538 (prog1
1539 (condition-case nil
1540 (save-excursion
1541 (set-buffer buffer)
1542 (insert-file-contents user-init-file)
1543 (re-search-forward
1544 (concat
1545 "([ \t\n]*setq[ \t\n]+"
1546 "inhibit-startup-echo-area-message[ \t\n]+"
1547 (regexp-quote
1548 (prin1-to-string
bca8c7be 1549 (if (equal init-file-user "")
ed638cc9
RS
1550 (user-login-name)
1551 init-file-user)))
1552 "[ \t\n]*)")
1553 nil t))
1554 (error nil))
1555 (kill-buffer buffer)))))
9f8b5809
GM
1556 ;; Stop any "Loading image..." message hiding echo-area-message.
1557 (use-fancy-splash-screens-p)
ed638cc9
RS
1558 (display-startup-echo-area-message))
1559
1560 ;; Delay 2 seconds after an init file error message
1561 ;; was displayed, so user can read it.
bca8c7be
MS
1562 (when init-file-had-error
1563 (sit-for 2))
1564
1565 (when command-line-args-left
1566 ;; We have command args; process them.
1567 (let ((dir command-line-default-directory)
1568 (file-count 0)
1569 first-file-buffer
1570 tem
1571 ;; The directories listed in --directory/-L options will *appear*
1572 ;; at the front of `load-path' in the order they appear on the
1573 ;; command-line. We cannot do this by *placing* them at the front
1574 ;; in the order they appear, so we need this variable to hold them,
1575 ;; temporarily.
1576 extra-load-path
1577 just-files ;; t if this follows the magic -- option.
1578 ;; This includes our standard options' long versions
1579 ;; and long versions of what's on command-switch-alist.
1580 (longopts
1581 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1582 ("--directory") ("--eval") ("--execute") ("--no-splash")
1583 ("--find-file") ("--visit") ("--file"))
1584 (mapcar (lambda (elt)
1585 (list (concat "-" (car elt))))
1586 command-switch-alist)))
1587 (line 0)
1588 (column 0))
1589
1590 ;; Add the long X options to longopts.
1591 (dolist (tem command-line-x-option-alist)
1592 (if (string-match "^--" (car tem))
1593 (push (list (car tem)) longopts)))
1594
1595 ;; Loop, processing options.
1596 (while command-line-args-left
1597 (let* ((argi (car command-line-args-left))
1598 (orig-argi argi)
1599 argval completion)
1600 (setq command-line-args-left (cdr command-line-args-left))
1601
1602 ;; Do preliminary decoding of the option.
1603 (if just-files
1604 ;; After --, don't look for options; treat all args as files.
1605 (setq argi "")
1606 ;; Convert long options to ordinary options
1607 ;; and separate out an attached option argument into argval.
1608 (when (string-match "^\\(--[^=]*\\)=" argi)
1609 (setq argval (substring argi (match-end 0))
1610 argi (match-string 1 argi)))
1611 (if (equal argi "--")
1612 (setq completion nil)
1613 (setq completion (try-completion argi longopts)))
1614 (if (eq completion t)
1615 (setq argi (substring argi 1))
1616 (if (stringp completion)
1617 (let ((elt (assoc completion longopts)))
1618 (or elt
1619 (error "Option `%s' is ambiguous" argi))
1620 (setq argi (substring (car elt) 1)))
1621 (setq argval nil
1622 argi orig-argi))))
1623
1624 ;; Execute the option.
1625 (cond ((setq tem (assoc argi command-switch-alist))
1626 (if argval
1627 (let ((command-line-args-left
1628 (cons argval command-line-args-left)))
1629 (funcall (cdr tem) argi))
1630 (funcall (cdr tem) argi)))
1631
1632 ((equal argi "-no-splash")
1633 (setq inhibit-startup-message t))
1634
1635 ((member argi '("-f" ; what the manual claims
1636 "-funcall"
1637 "-e")) ; what the source used to say
1638 (setq tem (intern (or argval (pop command-line-args-left))))
f39864ec 1639 (if (commandp tem)
bca8c7be
MS
1640 (command-execute tem)
1641 (funcall tem)))
1642
1643 ((member argi '("-eval" "-execute"))
1644 (eval (read (or argval (pop command-line-args-left)))))
1645 ;; Set the default directory as specified in -L.
1646
1647 ((member argi '("-L" "-directory"))
1648 (setq tem (or argval (pop command-line-args-left)))
1649 ;; We will reverse `extra-load-path' and prepend it to
1650 ;; `load-path' after all the arguments have been processed.
1651 (push
1652 (expand-file-name (command-line-normalize-file-name tem))
1653 extra-load-path))
1654
1655 ((member argi '("-l" "-load"))
1656 (let* ((file (command-line-normalize-file-name
1657 (or argval (pop command-line-args-left))))
1658 ;; Take file from default dir if it exists there;
1659 ;; otherwise let `load' search for it.
1660 (file-ex (expand-file-name file)))
1661 (when (file-exists-p file-ex)
1662 (setq file file-ex))
1663 (load file nil t)))
1664
1665 ((equal argi "-insert")
1666 (setq tem (or argval (pop command-line-args-left)))
1667 (or (stringp tem)
1668 (error "File name omitted from `-insert' option"))
1669 (insert-file-contents (command-line-normalize-file-name tem)))
1670
1671 ((equal argi "-kill")
1672 (kill-emacs t))
1673
1674 ((string-match "^\\+[0-9]+\\'" argi)
1675 (setq line (string-to-int argi)))
1676
1677 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1678 (setq line (string-to-int (match-string 1 argi))
1679 column (string-to-int (match-string 2 argi))))
1680
1681 ((setq tem (assoc argi command-line-x-option-alist))
1682 ;; Ignore X-windows options and their args if not using X.
1683 (setq command-line-args-left
1684 (nthcdr (nth 1 tem) command-line-args-left)))
1685
1686 ((member argi '("-find-file" "-file" "-visit"))
1687 ;; An explicit option to specify visiting a file.
1688 (setq tem (or argval (pop command-line-args-left)))
1689 (unless (stringp tem)
1690 (error "File name omitted from `%s' option" argi))
1691 (setq file-count (1+ file-count))
1692 (let ((file (expand-file-name
1693 (command-line-normalize-file-name tem) dir)))
1694 (if (= file-count 1)
1695 (setq first-file-buffer (find-file file))
1696 (find-file-other-window file)))
1697 (or (zerop line)
1698 (goto-line line))
1699 (setq line 0)
1700 (unless (< column 1)
1701 (move-to-column (1- column)))
1702 (setq column 0))
1703
1704 ((equal argi "--")
1705 (setq just-files t))
1706 (t
1707 ;; We have almost exhausted our options. See if the
1708 ;; user has made any other command-line options available
1709 (let ((hooks command-line-functions) ;; lrs 7/31/89
1710 (did-hook nil))
1711 (while (and hooks
1712 (not (setq did-hook (funcall (car hooks)))))
1713 (setq hooks (cdr hooks)))
1714 (if (not did-hook)
1715 ;; Presume that the argument is a file name.
1716 (progn
1717 (if (string-match "\\`-" argi)
1718 (error "Unknown option `%s'" argi))
1719 (setq file-count (1+ file-count))
1720 (let ((file
1721 (expand-file-name
1722 (command-line-normalize-file-name orig-argi)
1723 dir)))
1724 (if (= file-count 1)
1725 (setq first-file-buffer (find-file file))
1726 (find-file-other-window file)))
1727 (or (zerop line)
1728 (goto-line line))
1729 (setq line 0)
1730 (unless (< column 1)
1731 (move-to-column (1- column)))
1732 (setq column 0))))))))
1733
1734 ;; See --directory/-L option above.
1735 (when extra-load-path
1736 (setq load-path (append (nreverse extra-load-path) load-path)))
1737
1738 ;; If 3 or more files visited, and not all visible,
1739 ;; show user what they all are. But leave the last one current.
1740 (and (> file-count 2)
1741 (not noninteractive)
1742 (not inhibit-startup-buffer-menu)
1743 (or (get-buffer-window first-file-buffer)
1744 (list-buffers)))))
eae91b60
RS
1745
1746 ;; Maybe display a startup screen.
1747 (when (and (not inhibit-startup-message) (not noninteractive)
1748 ;; Don't display startup screen if init file
1749 ;; has started some sort of server.
1750 (not (and (fboundp 'process-list)
1751 (process-list))))
1752 ;; Display a startup screen, after some preparations.
1753
1754 ;; If there are no switches to process, we might as well
1755 ;; run this hook now, and there may be some need to do it
1756 ;; before doing any output.
deebb0e9 1757 (run-hooks 'emacs-startup-hook)
eae91b60
RS
1758 (and term-setup-hook
1759 (run-hooks 'term-setup-hook))
deebb0e9 1760 (setq inhibit-startup-hooks t)
eae91b60
RS
1761
1762 ;; It's important to notice the user settings before we
1763 ;; display the startup message; otherwise, the settings
1764 ;; won't take effect until the user gives the first
1765 ;; keystroke, and that's distracting.
1766 (when (fboundp 'frame-notice-user-settings)
1767 (frame-notice-user-settings))
1768
1769 ;; If there are no switches to process, we might as well
1770 ;; run this hook now, and there may be some need to do it
1771 ;; before doing any output.
1772 (when window-setup-hook
1773 (run-hooks 'window-setup-hook)
1774 ;; Don't let the hook be run twice.
1775 (setq window-setup-hook nil))
1776
1777 ;; Do this now to avoid an annoying delay if the user
1778 ;; clicks the menu bar during the sit-for.
1779 (when (display-popup-menus-p)
1780 (precompute-menubar-bindings))
d759a2f5
RS
1781 (with-no-warnings
1782 (setq menubar-bindings-done t))
ed638cc9 1783
eae91b60
RS
1784 ;; If *scratch* is selected and it is empty, insert an
1785 ;; initial message saying not to create a file there.
1786 (when (and initial-scratch-message
bca8c7be 1787 (equal (buffer-name) "*scratch*")
ed638cc9 1788 (= 0 (buffer-size)))
eae91b60
RS
1789 (insert initial-scratch-message)
1790 (set-buffer-modified-p nil))
ed638cc9 1791
eae91b60
RS
1792 ;; If user typed input during all that work,
1793 ;; abort the startup screen. Otherwise, display it now.
c61453ea
PJ
1794 (unless (input-pending-p)
1795 (display-splash-screen))))
c88ab9ce 1796
49939379 1797
47c7adae
RS
1798(defun command-line-normalize-file-name (file)
1799 "Collapse multiple slashes to one, to handle non-Emacs file names."
6b9e794f
RS
1800 (save-match-data
1801 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1802 ;; That is significant on some systems.
1803 ;; However, /// at the beginning is supposed to mean just /, not //.
1804 (if (string-match "^///+" file)
1805 (setq file (replace-match "/" t t file)))
1806 (while (string-match "//+" file 1)
1807 (setq file (replace-match "/" t t file)))
1808 file))
47c7adae 1809
ab5796a9 1810;;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
c88ab9ce 1811;;; startup.el ends here