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