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