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