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