* erc-stamp.el (erc-echo-timestamp):
[bpt/emacs.git] / lisp / startup.el
CommitLineData
c88ab9ce
ER
1;;; startup.el --- process Emacs shell arguments
2
a3194d03 3;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
d7a0267c 4;; 2001, 2002, 2003, 2004, 2005, 2006, 2007 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
b4aa6026 13;; the Free Software Foundation; either version 3, 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 22;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
a726e0d1 25
630cc463 26;;; Commentary:
a726e0d1 27
32e51983
EZ
28;; This file parses the command line and gets Emacs running. Options
29;; on the command line are handled in precedence order. For priorities
30;; see the structure standard_args in the emacs.c file.
a726e0d1 31
630cc463
ER
32;;; Code:
33
a726e0d1
JB
34(setq top-level '(normal-top-level))
35
42a3e6fa 36(defvar command-line-processed nil
2879a13b 37 "Non-nil once command line has been processed.")
a726e0d1 38
42a3e6fa 39(defgroup initialization nil
ca3685a3 40 "Emacs start-up procedure."
26cdce23
JL
41 :group 'environment)
42
43(defcustom initial-buffer-choice nil
44 "Buffer to show after starting Emacs.
490a1ad6 45If the value is nil and `inhibit-startup-screen' is nil, show the
26cdce23
JL
46startup screen. If the value is string, visit the specified file or
47directory using `find-file'. If t, open the `*scratch*' buffer."
48 :type '(choice
490a1ad6 49 (const :tag "Startup screen" nil)
26cdce23
JL
50 (directory :tag "Directory" :value "~/")
51 (file :tag "File" :value "~/file.txt")
52 (const :tag "Lisp scratch buffer" t))
53 :version "23.1"
54 :group 'initialization)
42a3e6fa 55
490a1ad6 56(defcustom inhibit-startup-screen nil
249d9683 57 "Non-nil inhibits the startup screen.
ab863ac2 58It also inhibits display of the initial message in the `*scratch*' buffer.
249d9683 59
531b591d
AM
60This is for use in your personal init file (but NOT site-start.el), once
61you are familiar with the contents of the startup screen."
42a3e6fa
RS
62 :type 'boolean
63 :group 'initialization)
a726e0d1 64
490a1ad6
JL
65(defvaralias 'inhibit-splash-screen 'inhibit-startup-screen)
66(defvaralias 'inhibit-startup-message 'inhibit-startup-screen)
1b207153 67
22a58255
CY
68(defvar startup-screen-inhibit-startup-screen nil)
69
42a3e6fa 70(defcustom inhibit-startup-echo-area-message nil
1d7da582 71 "*Non-nil inhibits the initial startup echo area message.
42a3e6fa
RS
72Setting this variable takes effect
73only if you do it with the customization buffer
94487c4e 74or if your `.emacs' file contains a line of this form:
54a003f7 75 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
e5575c06
RS
76If your `.emacs' file is byte-compiled, use the following form instead:
77 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
1d7da582 78Thus, someone else using a copy of your `.emacs' file will see
42a3e6fa
RS
79the startup message unless he personally acts to inhibit it."
80 :type '(choice (const :tag "Don't inhibit")
81 (string :tag "Enter your user name, to inhibit"))
82 :group 'initialization)
1d7da582 83
42a3e6fa
RS
84(defcustom inhibit-default-init nil
85 "*Non-nil inhibits loading the `default' library."
86 :type 'boolean
87 :group 'initialization)
a726e0d1 88
802a980a
GM
89(defcustom inhibit-startup-buffer-menu nil
90 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
91 :type 'boolean
92 :group 'initialization)
93
d7fa5aa2 94(defvar command-switch-alist nil
a726e0d1
JB
95 "Alist of command-line switches.
96Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
5bb54c61
RS
97HANDLER-FUNCTION receives the switch string as its sole argument;
98the remaining command-line args are in the variable `command-line-args-left'.")
a726e0d1 99
860befc8
RS
100(defvar command-line-args-left nil
101 "List of command-line args not yet processed.")
102
aa5310e4
DK
103(defvaralias 'argv 'command-line-args-left
104 "List of command-line args not yet processed.
105This is a convenience alias, so that one can write \(pop argv\)
106inside of --eval command line arguments in order to access
107following arguments.")
108
a726e0d1
JB
109(defvar command-line-functions nil ;; lrs 7/31/89
110 "List of functions to process unrecognized command-line arguments.
111Each function should access the dynamically bound variables
b4484ea8 112`argi' (the current argument) and `command-line-args-left' (the remaining
a726e0d1 113arguments). The function should return non-nil only if it recognizes and
b4484ea8
RS
114processes `argi'. If it does so, it may consume successive arguments by
115altering `command-line-args-left' to remove them.")
a726e0d1 116
09a1077c
RS
117(defvar command-line-default-directory nil
118 "Default directory to use for command line arguments.
119This is normally copied from `default-directory' when Emacs starts.")
120
b3afdeb8
RS
121;;; This is here, rather than in x-win.el, so that we can ignore these
122;;; options when we are not using X.
46cfd295 123(defconst command-line-x-option-alist
b3afdeb8
RS
124 '(("-bw" 1 x-handle-numeric-switch border-width)
125 ("-d" 1 x-handle-display)
126 ("-display" 1 x-handle-display)
5676ab57 127 ("-name" 1 x-handle-name-switch)
2c3fef40
RS
128 ("-title" 1 x-handle-switch title)
129 ("-T" 1 x-handle-switch title)
b3afdeb8
RS
130 ("-r" 0 x-handle-switch reverse t)
131 ("-rv" 0 x-handle-switch reverse t)
132 ("-reverse" 0 x-handle-switch reverse t)
133 ("-reverse-video" 0 x-handle-switch reverse t)
134 ("-fn" 1 x-handle-switch font)
135 ("-font" 1 x-handle-switch font)
188b6a5e
EZ
136 ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
137 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
138 ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
b3afdeb8 139 ("-ib" 1 x-handle-numeric-switch internal-border-width)
1f7f78f1 140 ("-g" 1 x-handle-geometry)
9ff6bda1 141 ("-lsp" 1 x-handle-numeric-switch line-spacing)
1f7f78f1 142 ("-geometry" 1 x-handle-geometry)
b3afdeb8
RS
143 ("-fg" 1 x-handle-switch foreground-color)
144 ("-foreground" 1 x-handle-switch foreground-color)
145 ("-bg" 1 x-handle-switch background-color)
146 ("-background" 1 x-handle-switch background-color)
147 ("-ms" 1 x-handle-switch mouse-color)
c755acf3 148 ("-nbi" 0 x-handle-switch icon-type nil)
b3afdeb8
RS
149 ("-iconic" 0 x-handle-iconic)
150 ("-xrm" 1 x-handle-xrm-switch)
151 ("-cr" 1 x-handle-switch cursor-color)
152 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
153 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
154 ("-bd" 1 x-handle-switch)
155 ("--border-width" 1 x-handle-numeric-switch border-width)
156 ("--display" 1 x-handle-display)
5676ab57 157 ("--name" 1 x-handle-name-switch)
7775acb8 158 ("--title" 1 x-handle-switch title)
b3afdeb8
RS
159 ("--reverse-video" 0 x-handle-switch reverse t)
160 ("--font" 1 x-handle-switch font)
188b6a5e
EZ
161 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
162 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
163 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
b3afdeb8 164 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
1f7f78f1 165 ("--geometry" 1 x-handle-geometry)
b3afdeb8
RS
166 ("--foreground-color" 1 x-handle-switch foreground-color)
167 ("--background-color" 1 x-handle-switch background-color)
168 ("--mouse-color" 1 x-handle-switch mouse-color)
bb1f0f78 169 ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon)
b3afdeb8
RS
170 ("--iconic" 0 x-handle-iconic)
171 ("--xrm" 1 x-handle-xrm-switch)
172 ("--cursor-color" 1 x-handle-switch cursor-color)
173 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
9ff6bda1 174 ("--line-spacing" 1 x-handle-numeric-switch line-spacing)
7f944e8e 175 ("--border-color" 1 x-handle-switch border-color)
ca57f55d 176 ("--smid" 1 x-handle-smid))
b3afdeb8
RS
177 "Alist of X Windows options.
178Each element has the form
179 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
180where NAME is the option name string, NUMARGS is the number of arguments
181that the option accepts, HANDLER is a function to call to handle the option.
182FRAME-PARAM (optional) is the frame parameter this option specifies,
183and VALUE is the value which is given to that frame parameter
184\(most options use the argument for this, so VALUE is not present).")
185
e3bd99f5 186(defvar before-init-hook nil
db3f571a 187 "Normal hook run after handling urgent options but before loading init files.")
3fc958a4 188
e3bd99f5 189(defvar after-init-hook nil
db3f571a
KH
190 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
191There is no `condition-case' around the running of these functions;
192therefore, if you set `debug-on-error' non-nil in `.emacs',
193an error in one of these functions will invoke the debugger.")
194
195(defvar emacs-startup-hook nil
196 "Normal hook run after loading init files and handling the command line.")
e3bd99f5 197
a726e0d1 198(defvar term-setup-hook nil
db3f571a
KH
199 "Normal hook run after loading terminal-specific Lisp code.
200It also follows `emacs-startup-hook'. This hook exists for users to set,
a726e0d1
JB
201so as to override the definitions made by the terminal-specific file.
202Emacs never sets this variable itself.")
203
deebb0e9
RS
204(defvar inhibit-startup-hooks nil
205 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
206This is because we already did so.")
207
a726e0d1 208(defvar keyboard-type nil
b4484ea8 209 "The brand of keyboard you are using.
9ab281f0
JB
210This variable is used to define the proper function and keypad
211keys for use under X. It is used in a fashion analogous to the
212environment variable TERM.")
a726e0d1
JB
213
214(defvar window-setup-hook nil
b4484ea8
RS
215 "Normal hook run to initialize window system display.
216Emacs runs this hook after processing the command line arguments and loading
217the user's init file.")
a726e0d1 218
42a3e6fa 219(defcustom initial-major-mode 'lisp-interaction-mode
ab863ac2 220 "Major mode command symbol to use for the initial `*scratch*' buffer."
ce2f921e 221 :type 'function
42a3e6fa 222 :group 'initialization)
a726e0d1 223
ecbff273 224(defvar init-file-user nil
a726e0d1 225 "Identity of user whose `.emacs' file is or was read.
d7fa5aa2
RS
226The value is nil if `-q' or `--no-init-file' was specified,
227meaning do not load any init file.
228
d3a81eee
EZ
229Otherwise, the value may be an empty string, meaning
230use the init file for the user who originally logged in,
231or it may be a string containing a user's name meaning
232use that person's init file.
a726e0d1 233
2bdfaa42
KH
234In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
235evaluates to the name of the directory where the `.emacs' file was
13fce4e6
RS
236looked for.
237
238Setting `init-file-user' does not prevent Emacs from loading
ecbff273 239`site-start.el'. The only way to do that is to use `--no-site-file'.")
a726e0d1 240
42a3e6fa 241(defcustom site-run-file "site-start"
b7444d31
RS
242 "File containing site-wide run-time initializations.
243This file is loaded at run-time before `~/.emacs'. It contains inits
244that need to be in place for the entire site, but which, due to their
fcaf7de9 245higher incidence of change, don't make sense to load into Emacs's
b7444d31 246dumped image. Thus, the run-time load order is: 1. file described in
13fce4e6
RS
247this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
248
249Don't use the `site-start.el' file for things some users may not like.
250Put them in `default.el' instead, so that users can more easily
251override them. Users can prevent loading `default.el' with the `-q'
252option or by setting `inhibit-default-init' in their own init files,
253but inhibiting `site-start.el' requires `--no-site-file', which
842a1eac
RS
254is less convenient.
255
256This variable is defined for customization so as to make
257it visible in the relevant context. However, actually customizing it
258is not allowed, since it would not work anyway. The only way to set
9ab281f0 259this variable usefully is to set it while building and dumping Emacs."
93812130 260 :type '(choice (const :tag "none" nil) string)
842a1eac
RS
261 :group 'initialization
262 :initialize 'custom-initialize-default
263 :set '(lambda (variable value)
264 (error "Customizing `site-run-file' does not work")))
b7444d31 265
42a3e6fa
RS
266(defcustom mail-host-address nil
267 "*Name of this machine, for purposes of naming users."
268 :type '(choice (const nil) string)
269 :group 'mail)
c13fbb62 270
680ebfa6 271(defcustom user-mail-address (if command-line-processed
cee0c996
EZ
272 (or (getenv "EMAIL")
273 (concat (user-login-name) "@"
274 (or mail-host-address
275 (system-name))))
680ebfa6
RS
276 ;; Empty string means "not set yet".
277 "")
452e9090 278 "*Full mailing address of this user.
cee0c996
EZ
279This is initialized with environment variable `EMAIL' or, as a
280fallback, using `mail-host-address'. This is done after your
281init file is read, in case it sets `mail-host-address'."
42a3e6fa
RS
282 :type 'string
283 :group 'mail)
c10d1f06 284
42a3e6fa 285(defcustom auto-save-list-file-prefix
73f13e5a
GM
286 (cond ((eq system-type 'ms-dos)
287 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
34b68a62 288 (concat user-emacs-directory "auto-save.list/_s"))
73f13e5a 289 (t
34b68a62 290 (concat user-emacs-directory "auto-save-list/.saves-")))
cdee38c3
KH
291 "Prefix for generating `auto-save-list-file-name'.
292This is used after reading your `.emacs' file to initialize
293`auto-save-list-file-name', by appending Emacs's pid and the system name,
294if you have not already set `auto-save-list-file-name' yourself.
73f13e5a 295Directories in the prefix will be created if necessary.
cdee38c3 296Set this to nil if you want to prevent `auto-save-list-file-name'
42a3e6fa 297from being initialized."
3671f444
KH
298 :type '(choice (const :tag "Don't record a session's auto save list" nil)
299 string)
42a3e6fa 300 :group 'auto-save)
2e05d063 301
e2c60824
KS
302(defvar emacs-quick-startup nil)
303
dc58296d
RS
304(defvar emacs-basic-display nil)
305
a726e0d1
JB
306(defvar init-file-debug nil)
307
5b309ebf
RS
308(defvar init-file-had-error nil
309 "Non-nil if there was an error loading the user's init file.")
52320897 310
95eada65
RS
311(defvar normal-top-level-add-subdirs-inode-list nil)
312
178b4542
JL
313(defvar no-blinking-cursor nil)
314
0a480f3d
RS
315(defvar default-frame-background-mode)
316
b693e375
RS
317(defvar pure-space-overflow nil
318 "Non-nil if building Emacs overflowed pure space.")
319
22a58255
CY
320(defvar pure-space-overflow-message "\
321Warning Warning!!! Pure space overflow !!!Warning Warning
322\(See the node Pure Storage in the Lisp manual for details.)\n")
323
5f5ba825 324(defvar tutorial-directory nil
f51a80af
GM
325 "Directory containing the Emacs TUTORIAL files.")
326
5f5ba825
GM
327;; Get correct value in a dumped, installed Emacs.
328(eval-at-startup
329 (setq tutorial-directory (file-name-as-directory
330 (expand-file-name "tutorials" data-directory))))
331
859e15c1 332(defun normal-top-level-add-subdirs-to-load-path ()
0412d833
RS
333 "Add all subdirectories of current directory to `load-path'.
334More precisely, this uses only the subdirectories whose names
f734a13e
DL
335start with letters or digits; it excludes any subdirectory named `RCS'
336or `CVS', and any subdirectory that contains a file named `.nosearch'."
f1180544 337 (let (dirs
95eada65 338 attrs
859e15c1
KH
339 (pending (list default-directory)))
340 ;; This loop does a breadth-first tree walk on DIR's subtree,
341 ;; putting each subdir into DIRS as its contents are examined.
342 (while pending
4e0a3971 343 (push (pop pending) dirs)
722a451d
EZ
344 (let* ((this-dir (car dirs))
345 (contents (directory-files this-dir))
346 (default-directory this-dir)
fcaf7de9
SM
347 (canonicalized (if (fboundp 'untranslated-canonical-name)
348 (untranslated-canonical-name this-dir))))
722a451d
EZ
349 ;; The Windows version doesn't report meaningful inode
350 ;; numbers, so use the canonicalized absolute file name of the
351 ;; directory instead.
352 (setq attrs (or canonicalized
353 (nthcdr 10 (file-attributes this-dir))))
95eada65 354 (unless (member attrs normal-top-level-add-subdirs-inode-list)
4e0a3971
SM
355 (push attrs normal-top-level-add-subdirs-inode-list)
356 (dolist (file contents)
c4a40544 357 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
4e0a3971
SM
358 (unless (member file '("." ".." "RCS" "CVS" "rcs" "cvs"))
359 (when (and (string-match "\\`[[:alnum:]]" file)
9d1fb179
RS
360 ;; Avoid doing a `stat' when it isn't necessary
361 ;; because that can cause trouble when an NFS server
362 ;; is down.
4e0a3971
SM
363 (not (string-match "\\.elc?\\'" file))
364 (file-directory-p file))
365 (let ((expanded (expand-file-name file)))
95eada65
RS
366 (unless (file-exists-p (expand-file-name ".nosearch"
367 expanded))
4e0a3971 368 (setq pending (nconc pending (list expanded)))))))))))
bb15e81a 369 (normal-top-level-add-to-load-path (cdr (nreverse dirs)))))
859e15c1 370
537b6e4e
RS
371;; This function is called from a subdirs.el file.
372;; It assumes that default-directory is the directory
373;; in which the subdirs.el file exists,
374;; and it adds to load-path the subdirs of that directory
375;; as specified in DIRS. Normally the elements of DIRS are relative.
e87a7309 376(defun normal-top-level-add-to-load-path (dirs)
cd1c10f6
RS
377 (let ((tail load-path)
378 (thisdir (directory-file-name default-directory)))
379 (while (and tail
138e541f
GM
380 ;;Don't go all the way to the nil terminator.
381 (cdr tail)
cd1c10f6
RS
382 (not (equal thisdir (car tail)))
383 (not (and (memq system-type '(ms-dos windows-nt))
384 (equal (downcase thisdir) (downcase (car tail))))))
385 (setq tail (cdr tail)))
138e541f
GM
386 ;;Splice the new section in.
387 (when tail
388 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
e87a7309 389
a726e0d1
JB
390(defun normal-top-level ()
391 (if command-line-processed
392 (message "Back to top level.")
393 (setq command-line-processed t)
8d4c2221
RS
394 ;; Give *Messages* the same default-directory as *scratch*,
395 ;; just to keep things predictable.
396 (let ((dir default-directory))
fcaf7de9 397 (with-current-buffer "*Messages*"
8d4c2221 398 (setq default-directory dir)))
9715399e
MR
399 ;; `user-full-name' is now known; reset its standard-value here.
400 (put 'user-full-name 'standard-value
401 (list (default-value 'user-full-name)))
80d71556
KH
402 ;; For root, preserve owner and group when editing files.
403 (if (equal (user-uid) 0)
404 (setq backup-by-copying-when-mismatch t))
e87a7309
RS
405 ;; Look in each dir in load-path for a subdirs.el file.
406 ;; If we find one, load it, which will add the appropriate subdirs
407 ;; of that dir into load-path,
357438eb
KH
408 ;; Look for a leim-list.el file too. Loading it will register
409 ;; available input methods.
b6666b5f
SM
410 (let ((tail load-path) dir)
411 (while tail
412 (setq dir (car tail))
413 (let ((default-directory dir))
414 (load (expand-file-name "subdirs.el") t t t))
415 (let ((default-directory dir))
416 (load (expand-file-name "leim-list.el") t t t))
417 ;; We don't use a dolist loop and we put this "setq-cdr" command at
418 ;; the end, because the subdirs.el files may add elements to the end
419 ;; of load-path and we want to take it into account.
420 (setq tail (cdr tail))))
fcaf7de9
SM
421 (unless (eq system-type 'vax-vms)
422 ;; If the PWD environment variable isn't accurate, delete it.
423 (let ((pwd (getenv "PWD")))
424 (and (stringp pwd)
425 ;; Use FOO/., so that if FOO is a symlink, file-attributes
426 ;; describes the directory linked to, not FOO itself.
427 (or (equal (file-attributes
428 (concat (file-name-as-directory pwd) "."))
429 (file-attributes
430 (concat (file-name-as-directory default-directory)
431 ".")))
432 (setq process-environment
433 (delete (concat "PWD=" pwd)
434 process-environment))))))
492878e4 435 (setq default-directory (abbreviate-file-name default-directory))
6f2c86fa
KH
436 (let ((menubar-bindings-done nil))
437 (unwind-protect
438 (command-line)
439 ;; Do this again, in case .emacs defined more abbreviations.
440 (setq default-directory (abbreviate-file-name default-directory))
b3c7c12c
RS
441 ;; Specify the file for recording all the auto save files of this session.
442 ;; This is used by recover-session.
cdee38c3
KH
443 (or auto-save-list-file-name
444 (and auto-save-list-file-prefix
445 (setq auto-save-list-file-name
1f7f78f1
RS
446 ;; Under MS-DOS our PID is almost always reused between
447 ;; Emacs invocations. We need something more unique.
4b33deaa
EZ
448 (cond ((eq system-type 'ms-dos)
449 ;; We are going to access the auto-save
450 ;; directory, so make sure it exists.
451 (make-directory
452 (file-name-directory auto-save-list-file-prefix)
453 t)
f1180544 454 (concat
4b33deaa
EZ
455 (make-temp-name
456 (expand-file-name
457 auto-save-list-file-prefix))
458 "~"))
459 (t
460 (expand-file-name
461 (format "%s%d-%s~"
462 auto-save-list-file-prefix
463 (emacs-pid)
464 (system-name))))))))
deebb0e9
RS
465 (unless inhibit-startup-hooks
466 (run-hooks 'emacs-startup-hook)
467 (and term-setup-hook
468 (run-hooks 'term-setup-hook)))
6a1e7d67
GM
469
470 ;; Don't do this if we failed to create the initial frame,
471 ;; for instance due to a dense colormap.
538ef02a
GM
472 (when (or frame-initial-frame
473 ;; If frame-initial-frame has no meaning, do this anyway.
2246281f 474 (not (and initial-window-system
538ef02a 475 (not noninteractive)
2246281f 476 (not (eq initial-window-system 'pc)))))
6a1e7d67
GM
477 ;; Modify the initial frame based on what .emacs puts into
478 ;; ...-frame-alist.
479 (if (fboundp 'frame-notice-user-settings)
480 (frame-notice-user-settings))
2666355c
KL
481 ;; Set the faces for the initial background mode even if
482 ;; frame-notice-user-settings didn't (such as on a tty).
483 ;; frame-set-background-mode is idempotent, so it won't
484 ;; cause any harm if it's already been done.
6a1e7d67 485 (if (fboundp 'frame-set-background-mode)
2666355c 486 (frame-set-background-mode (selected-frame))))
13ab33c4 487
6f2c86fa
KH
488 ;; Now we know the user's default font, so add it to the menu.
489 (if (fboundp 'font-menu-add-default)
490 (font-menu-add-default))
491 (and window-setup-hook
492 (run-hooks 'window-setup-hook))
493 (or menubar-bindings-done
66c24e1e 494 (if (display-popup-menus-p)
fdb88463
SM
495 (precompute-menubar-bindings)))))
496 ;; Subprocesses of Emacs do not have direct access to the terminal, so
497 ;; unless told otherwise they should only assume a dumb terminal.
498 ;; We are careful to do it late (after term-setup-hook), although the
499 ;; new multi-tty code does not use $TERM any more there anyway.
4bbfda32
SM
500 (setenv "TERM" "dumb")
501 ;; Remove DISPLAY from the process-environment as well. This allows
502 ;; `callproc.c' to give it a useful adaptive default which is either
503 ;; the value of the `display' frame-parameter or the DISPLAY value
504 ;; from initial-environment.
505 (let ((display (frame-parameter nil 'display)))
506 ;; Be careful which DISPLAY to remove from process-environment: follow
507 ;; the logic of `callproc.c'.
508 (if (stringp display) (setq display (concat "DISPLAY=" display))
509 (dolist (varval initial-environment)
510 (if (string-match "\\`DISPLAY=" varval)
511 (setq display varval))))
512 (when display
4bbfda32 513 (delete display process-environment)))))
6f2c86fa
KH
514
515;; Precompute the keyboard equivalents in the menu bar items.
516(defun precompute-menubar-bindings ()
365636dc
RS
517 (let ((submap (lookup-key global-map [menu-bar])))
518 (while submap
519 (and (consp (car submap))
520 (symbolp (car (car submap)))
521 (stringp (car-safe (cdr (car submap))))
522 (keymapp (cdr (cdr (car submap))))
a18042d7
RS
523 (progn
524 (x-popup-menu nil (cdr (cdr (car submap))))
525 (if purify-flag
526 (garbage-collect))))
365636dc 527 (setq submap (cdr submap))))
5b61c6a7 528 (setq define-key-rebound-commands t))
a726e0d1 529
c381f482
EZ
530;; Command-line options supported by tty's:
531(defconst tty-long-option-alist
8957d2bf
EZ
532 '(("--name" . "-name")
533 ("--title" . "-T")
534 ("--reverse-video" . "-reverse")
c381f482 535 ("--foreground-color" . "-fg")
8957d2bf
EZ
536 ("--background-color" . "-bg")
537 ("--color" . "-color")))
c381f482 538
b66b6aeb
GM
539(defconst tool-bar-images-pixel-height 24
540 "Height in pixels of images in the tool bar.")
541
3a55d3d0
JR
542(defvar tool-bar-originally-present nil
543 "Non-nil if tool-bars are present before user and site init files are read.")
544
e9cda827
KL
545(defvar handle-args-function-alist '((nil . tty-handle-args))
546 "Functions for processing window-system dependent command-line arguments.
547Window system startup files should add their own function to this
548alist, which should parse the command line arguments. Those
549pertaining to the window system should be processed and removed
550from the returned command line.")
551
552(defvar window-system-initialization-alist '((nil . ignore))
553 "Alist of window-system initialization functions.
554Window-system startup files should add their own initialization
555function to this list. The function should take no arguments,
556and initialize the window system environment to prepare for
2bb819d5 557opening the first frame (e.g. open a connection to an X server).")
e9cda827 558
bca8c7be 559;; Handle the X-like command-line arguments "-fg", "-bg", "-name", etc.
c381f482 560(defun tty-handle-args (args)
bca8c7be 561 (let (rest)
ae8bf5ab 562 (message "%S" args)
c381f482
EZ
563 (while (and args
564 (not (equal (car args) "--")))
bca8c7be
MS
565 (let* ((argi (pop args))
566 (orig-argi argi)
567 argval completion)
c381f482
EZ
568 ;; Check for long options with attached arguments
569 ;; and separate out the attached option argument into argval.
bca8c7be
MS
570 (when (string-match "^\\(--[^=]*\\)=" argi)
571 (setq argval (substring argi (match-end 0))
572 argi (match-string 1 argi)))
573 (when (string-match "^--" argi)
574 (setq completion (try-completion argi tty-long-option-alist))
c381f482
EZ
575 (if (eq completion t)
576 ;; Exact match for long option.
bca8c7be 577 (setq argi (cdr (assoc argi tty-long-option-alist)))
c381f482
EZ
578 (if (stringp completion)
579 (let ((elt (assoc completion tty-long-option-alist)))
580 ;; Check for abbreviated long option.
581 (or elt
bca8c7be
MS
582 (error "Option `%s' is ambiguous" argi))
583 (setq argi (cdr elt)))
c381f482 584 ;; Check for a short option.
bca8c7be
MS
585 (setq argval nil
586 argi orig-argi))))
587 (cond ((member argi '("-fg" "-foreground"))
588 (push (cons 'foreground-color (or argval (pop args)))
589 default-frame-alist))
590 ((member argi '("-bg" "-background"))
591 (push (cons 'background-color (or argval (pop args)))
592 default-frame-alist))
593 ((member argi '("-T" "-name"))
594 (unless argval (setq argval (pop args)))
595 (push (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 ((member argi '("-r" "-rv" "-reverse"))
610 (push '(reverse . t)
611 default-frame-alist))
612 ((equal argi "-color")
613 (unless argval (setq argval 8)) ; default --color means 8 ANSI colors
614 (push (cons 'tty-color-mode
615 (cond
616 ((numberp argval) argval)
617 ((string-match "-?[0-9]+" argval)
618 (string-to-number argval))
619 (t (intern argval))))
620 default-frame-alist))
621 (t
622 (push argi rest)))))
623 (nreverse rest)))
c381f482 624
a726e0d1 625(defun command-line ()
09a1077c
RS
626 (setq command-line-default-directory default-directory)
627
849eedba 628 ;; Choose a reasonable location for temporary files.
a3194d03 629 (custom-reevaluate-setting 'temporary-file-directory)
51db08eb 630 (custom-reevaluate-setting 'small-temporary-file-directory)
a3194d03 631 (custom-reevaluate-setting 'auto-save-file-name-transforms)
849eedba 632
74f2ab06 633 ;; See if we should import version-control from the environment variable.
a726e0d1
JB
634 (let ((vc (getenv "VERSION_CONTROL")))
635 (cond ((eq vc nil)) ;don't do anything if not set
bca8c7be 636 ((member vc '("t" "numbered"))
a726e0d1 637 (setq version-control t))
bca8c7be 638 ((member vc '("nil" "existing"))
a726e0d1 639 (setq version-control nil))
bca8c7be 640 ((member vc '("never" "simple"))
a726e0d1
JB
641 (setq version-control 'never))))
642
79058860
JB
643 ;;! This has been commented out; I currently find the behavior when
644 ;;! split-window-keep-point is nil disturbing, but if I can get used
645 ;;! to it, then it would be better to eliminate the option.
646 ;;! ;; Choose a good default value for split-window-keep-point.
647 ;;! (setq split-window-keep-point (> baud-rate 2400))
f35fe3c6 648
d4308a4d
EZ
649 ;; Set the default strings to display in mode line for
650 ;; end-of-line formats that aren't native to this platform.
651 (cond
652 ((memq system-type '(ms-dos windows-nt emx))
bca8c7be
MS
653 (setq eol-mnemonic-unix "(Unix)"
654 eol-mnemonic-mac "(Mac)"))
bde61f8b
EZ
655 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
656 ;; abbreviated strings `/' and `:' set in coding.c for them.
657 ((eq system-type 'macos)
658 (setq eol-mnemonic-dos "(DOS)"))
bca8c7be
MS
659 (t ; this is for Unix/GNU/Linux systems
660 (setq eol-mnemonic-dos "(DOS)"
661 eol-mnemonic-mac "(Mac)")))
d4308a4d 662
2666355c 663 ;; Make sure window system's init file was loaded in loadup.el if using a window system.
1ed14cfd 664 (condition-case error
e9cda827
KL
665 (unless noninteractive
666 (if (and initial-window-system
667 (not (featurep
2666355c 668 (intern (concat (symbol-name initial-window-system) "-win")))))
e9cda827
KL
669 (error "Unsupported window system `%s'" initial-window-system))
670 ;; Process window-system specific command line parameters.
671 (setq command-line-args
672 (funcall (or (cdr (assq initial-window-system handle-args-function-alist))
673 (error "Unsupported window system `%s'" initial-window-system))
674 command-line-args))
675 ;; Initialize the window system. (Open connection, etc.)
676 (funcall (or (cdr (assq initial-window-system window-system-initialization-alist))
677 (error "Unsupported window system `%s'" initial-window-system))))
678 ;; If there was an error, print the error message and exit.
1ed14cfd 679 (error
2677ad61
RS
680 (princ
681 (if (eq (car error) 'error)
682 (apply 'concat (cdr error))
683 (if (memq 'file-error (get (car error) 'error-conditions))
684 (format "%s: %s"
bca8c7be
MS
685 (nth 1 error)
686 (mapconcat (lambda (obj) (prin1-to-string obj t))
687 (cdr (cdr error)) ", "))
2677ad61 688 (format "%s: %s"
bca8c7be
MS
689 (get (car error) 'error-message)
690 (mapconcat (lambda (obj) (prin1-to-string obj t))
691 (cdr error) ", "))))
2677ad61 692 'external-debugging-output)
27f5188c 693 (terpri 'external-debugging-output)
2246281f 694 (setq initial-window-system nil)
1ed14cfd 695 (kill-emacs)))
a726e0d1 696
640a9cdd
JR
697 (set-locale-environment nil)
698
735895f1
EZ
699 ;; Convert preloaded file names in load-history to absolute.
700 (let ((simple-file-name
3b61abfe
EZ
701 ;; Look for simple.el or simple.elc and use their directory
702 ;; as the place where all Lisp files live.
735895f1
EZ
703 (locate-file "simple" load-path (get-load-suffixes)))
704 lisp-dir)
705 ;; Don't abort if simple.el cannot be found, but print a warning.
706 (if (null simple-file-name)
707 (progn
708 (princ "Warning: Could not find simple.el nor simple.elc"
709 'external-debugging-output)
710 (terpri 'external-debugging-output))
711 (setq lisp-dir (file-truename (file-name-directory simple-file-name)))
712 (setq load-history
713 (mapcar (lambda (elt)
714 (if (and (stringp (car elt))
715 (not (file-name-absolute-p (car elt))))
716 (cons (concat lisp-dir
717 (car elt))
718 (cdr elt))
719 elt))
720 load-history))))
4b816985 721
c16eb7b0
RS
722 ;; Convert the arguments to Emacs internal representation.
723 (let ((args (cdr command-line-args)))
724 (while args
725 (setcar args
726 (decode-coding-string (car args) locale-coding-system t))
bca8c7be 727 (pop args)))
c16eb7b0 728
03e3c30a
JB
729 (let ((done nil)
730 (args (cdr command-line-args)))
731
a726e0d1
JB
732 ;; Figure out which user's init file to load,
733 ;; either from the environment or from the options.
734 (setq init-file-user (if noninteractive nil (user-login-name)))
735 ;; If user has not done su, use current $HOME to find .emacs.
bca8c7be
MS
736 (and init-file-user
737 (equal init-file-user (user-real-login-name))
a726e0d1 738 (setq init-file-user ""))
03e3c30a
JB
739
740 ;; Process the command-line args, and delete the arguments
741 ;; processed. This is consistent with the way main in emacs.c
742 ;; does things.
a726e0d1 743 (while (and (not done) args)
9ab281f0
JB
744 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
745 ("--user") ("--iconic") ("--icon-type") ("--quick")
746 ("--no-blinking-cursor") ("--basic-display")))
bca8c7be
MS
747 (argi (pop args))
748 (orig-argi argi)
749 argval)
452e9090 750 ;; Handle --OPTION=VALUE format.
bca8c7be 751 (when (string-match "^\\(--[^=]*\\)=" argi)
1b207153 752 (setq argval (substring argi (match-end 0))
bca8c7be 753 argi (match-string 1 argi)))
1b207153
CW
754 (unless (equal argi "--")
755 (let ((completion (try-completion argi longopts)))
756 (if (eq completion t)
757 (setq argi (substring argi 1))
758 (if (stringp completion)
759 (let ((elt (assoc completion longopts)))
760 (or elt
761 (error "Option `%s' is ambiguous" argi))
762 (setq argi (substring (car elt) 1)))
bca8c7be
MS
763 (setq argval nil
764 argi orig-argi)))))
a726e0d1 765 (cond
dc58296d 766 ((member argi '("-Q" "-quick"))
e2c60824
KS
767 (setq init-file-user nil
768 site-run-file nil
dc58296d
RS
769 emacs-quick-startup t))
770 ((member argi '("-D" "-basic-display"))
771 (setq no-blinking-cursor t
772 emacs-basic-display t)
e2c60824 773 (push '(vertical-scroll-bars . nil) initial-frame-alist))
4e0a3971
SM
774 ((member argi '("-q" "-no-init-file"))
775 (setq init-file-user nil))
776 ((member argi '("-u" "-user"))
bca8c7be 777 (setq init-file-user (or argval (pop args))
4e0a3971 778 argval nil))
bca8c7be 779 ((equal argi "-no-site-file")
4e0a3971 780 (setq site-run-file nil))
bca8c7be 781 ((equal argi "-debug-init")
4e0a3971 782 (setq init-file-debug t))
bca8c7be 783 ((equal argi "-iconic")
4e0a3971 784 (push '(visibility . icon) initial-frame-alist))
bca8c7be 785 ((member argi '("-icon-type" "-i" "-itype"))
4e0a3971 786 (push '(icon-type . t) default-frame-alist))
178b4542
JL
787 ((member argi '("-nbc" "-no-blinking-cursor"))
788 (setq no-blinking-cursor t))
4e0a3971 789 ;; Push the popped arg back on the list of arguments.
bca8c7be
MS
790 (t
791 (push argi args)
792 (setq done t)))
096b7031
KH
793 ;; Was argval set but not used?
794 (and argval
795 (error "Option `%s' doesn't allow an argument" argi))))
796
03e3c30a 797 ;; Re-attach the program name to the front of the arg list.
bca8c7be
MS
798 (and command-line-args
799 (setcdr command-line-args args)))
a726e0d1 800
ce98f555
RS
801 (run-hooks 'before-init-hook)
802
ed0fb1f1 803 ;; Under X Window, this creates the X frame and deletes the terminal frame.
14f16b9c
GM
804 (when (fboundp 'frame-initialize)
805 (frame-initialize))
806
ed0fb1f1 807 ;; Turn off blinking cursor if so specified in X resources. This is here
b08cb5a6 808 ;; only because all other settings of no-blinking-cursor are here.
ed0fb1f1
JD
809 (unless (or noninteractive
810 emacs-basic-display
811 (and (memq window-system '(x w32 mac))
812 (not (member (x-get-resource "cursorBlink" "CursorBlink")
813 '("off" "false")))))
814 (setq no-blinking-cursor t))
815
1fe0333f 816 ;; If frame was created with a menu bar, set menu-bar-mode on.
bca8c7be 817 (unless (or noninteractive
dc58296d 818 emacs-basic-display
2246281f 819 (and (memq initial-window-system '(x w32))
bca8c7be 820 (<= (frame-parameter nil 'menu-bar-lines) 0)))
8ab9589d 821 (menu-bar-mode 1))
c722566c 822
7d1eb6a4 823 ;; If frame was created with a tool bar, switch tool-bar-mode on.
bca8c7be 824 (unless (or noninteractive
dc58296d 825 emacs-basic-display
bca8c7be
MS
826 (not (display-graphic-p))
827 (<= (frame-parameter nil 'tool-bar-lines) 0))
b66b6aeb 828 (tool-bar-mode 1))
7d1eb6a4 829
3413f928 830 ;; Can't do this init in defcustom because the relevant variables
a3194d03
SM
831 ;; are not set.
832 (custom-reevaluate-setting 'blink-cursor-mode)
dc86f0a9 833 (custom-reevaluate-setting 'tooltip-mode)
c442c26d 834 (custom-reevaluate-setting 'global-font-lock-mode)
97a7dbee
YM
835 (custom-reevaluate-setting 'mouse-wheel-down-event)
836 (custom-reevaluate-setting 'mouse-wheel-up-event)
db441dba 837 (custom-reevaluate-setting 'file-name-shadow-mode)
a496452f 838 (custom-reevaluate-setting 'send-mail-function)
1e2d7573 839 (custom-reevaluate-setting 'focus-follows-mouse)
3b73087e 840
30a2fded
KL
841 (normal-erase-is-backspace-setup-frame)
842
1592c1ef 843 ;; Register default TTY colors for the case the terminal hasn't a
79c3172f
KL
844 ;; terminal init file. We do this regardles of whether the terminal
845 ;; supports colors or not and regardless the current display type,
846 ;; since users can connect to color-capable terminals and also
847 ;; switch color support on or off in mid-session by setting the
848 ;; tty-color-mode frame parameter.
d448e982 849 (tty-register-default-colors)
1592c1ef 850
3a55d3d0
JR
851 ;; Record whether the tool-bar is present before the user and site
852 ;; init files are processed. frame-notice-user-settings uses this
853 ;; to determine if the tool-bar has been disabled by the init files,
854 ;; and the frame needs to be resized.
855 (when (fboundp 'frame-notice-user-settings)
856 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
857 (assq 'tool-bar-lines default-frame-alist))))
858 (setq tool-bar-originally-present
bca8c7be
MS
859 (and tool-bar-lines
860 (cdr tool-bar-lines)
861 (not (eq 0 (cdr tool-bar-lines)))))))
3a55d3d0 862
752ef254
GM
863 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
864 (old-font-list-limit font-list-limit)
865 (old-face-ignored-fonts face-ignored-fonts))
866
752ef254
GM
867 ;; Run the site-start library if it exists. The point of this file is
868 ;; that it is run before .emacs. There is no point in doing this after
869 ;; .emacs; that is useless.
5f144784
GM
870 ;; Note that user-init-file is nil at this point. Code that might
871 ;; be loaded from site-run-file and wants to test if -q was given
872 ;; should check init-file-user instead, since that is already set.
873 ;; See cus-edit.el for an example.
f1180544 874 (if site-run-file
752ef254
GM
875 (load site-run-file t t))
876
877 ;; Sites should not disable this. Only individuals should disable
1cff9ad1
JL
878 ;; the startup screen.
879 (setq inhibit-startup-screen nil)
752ef254 880
f963ea40 881 ;; Warn for invalid user name.
ce98f555
RS
882 (when init-file-user
883 (if (string-match "[~/:\n]" init-file-user)
884 (display-warning 'initialization
885 (format "Invalid user name %s"
886 init-file-user)
887 :error)
1df1e49e
EZ
888 (if (file-directory-p (expand-file-name
889 ;; We don't support ~USER on MS-Windows except
890 ;; for the current user, and always load .emacs
891 ;; from the current user's home directory (see
892 ;; below). So always check "~", even if invoked
893 ;; with "-u USER", or if $USER or $LOGNAME are
894 ;; set to something different.
895 (if (eq system-type 'windows-nt)
896 "~"
897 (concat "~" init-file-user))))
ce98f555
RS
898 nil
899 (display-warning 'initialization
900 (format "User %s has no home directory"
901 init-file-user)
902 :error))))
f963ea40 903
752ef254
GM
904 ;; Load that user's init file, or the default one, or none.
905 (let (debug-on-error-from-init-file
906 debug-on-error-should-be-set
907 (debug-on-error-initial
908 (if (eq init-file-debug t) 'startup init-file-debug))
909 (orig-enable-multibyte default-enable-multibyte-characters))
910 (let ((debug-on-error debug-on-error-initial)
911 ;; This function actually reads the init files.
912 (inner
913 (function
914 (lambda ()
915 (if init-file-user
916 (let ((user-init-file-1
4e0a3971 917 (cond
752ef254
GM
918 ((eq system-type 'ms-dos)
919 (concat "~" init-file-user "/_emacs"))
920 ((eq system-type 'windows-nt)
fe7ecaf2 921 ;; Prefer .emacs on Windows.
752ef254
GM
922 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
923 "~/.emacs"
fe7ecaf2
JR
924 ;; Also support _emacs for compatibility.
925 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
926 "~/_emacs"
927 ;; But default to .emacs if _emacs does not exist.
928 "~/.emacs")))
f1180544 929 ((eq system-type 'vax-vms)
752ef254 930 "sys$login:.emacs")
4e0a3971 931 (t
752ef254
GM
932 (concat "~" init-file-user "/.emacs")))))
933 ;; This tells `load' to store the file name found
934 ;; into user-init-file.
935 (setq user-init-file t)
936 (load user-init-file-1 t t)
f1180544 937
a04d5983
RS
938 (when (eq user-init-file t)
939 ;; If we did not find ~/.emacs, try
c3ab3701 940 ;; ~/.emacs.d/init.el.
a04d5983
RS
941 (let ((otherfile
942 (expand-file-name
c3ab3701 943 "init"
a04d5983 944 (file-name-as-directory
c3ab3701 945 (concat "~" init-file-user "/.emacs.d")))))
a04d5983
RS
946 (load otherfile t t)
947
948 ;; If we did not find the user's init file,
949 ;; set user-init-file conclusively.
950 ;; Don't let it be set from default.el.
951 (when (eq user-init-file t)
952 (setq user-init-file user-init-file-1))))
f1180544 953
752ef254
GM
954 ;; If we loaded a compiled file, set
955 ;; `user-init-file' to the source version if that
956 ;; exists.
957 (when (and user-init-file
958 (equal (file-name-extension user-init-file)
959 "elc"))
960 (let* ((source (file-name-sans-extension user-init-file))
961 (alt (concat source ".el")))
962 (setq source (cond ((file-exists-p alt) alt)
963 ((file-exists-p source) source)
964 (t nil)))
965 (when source
966 (when (file-newer-than-file-p source user-init-file)
967 (message "Warning: %s is newer than %s"
968 source user-init-file)
969 (sit-for 1))
970 (setq user-init-file source))))
f1180544 971
bca8c7be 972 (unless inhibit-default-init
1cff9ad1 973 (let ((inhibit-startup-screen nil))
bca8c7be
MS
974 ;; Users are supposed to be told their rights.
975 ;; (Plus how to get help and how to undo.)
976 ;; Don't you dare turn this off for anyone
977 ;; except yourself.
978 (load "default" t t)))))))))
752ef254
GM
979 (if init-file-debug
980 ;; Do this without a condition-case if the user wants to debug.
981 (funcall inner)
982 (condition-case error
983 (progn
984 (funcall inner)
985 (setq init-file-had-error nil))
986 (error
987 (let ((message-log-max nil))
988 (save-excursion
989 (set-buffer (get-buffer-create "*Messages*"))
990 (insert "\n\n"
991 (format "An error has occurred while loading `%s':\n\n"
992 user-init-file)
993 (format "%s%s%s"
994 (get (car error) 'error-message)
995 (if (cdr error) ": " "")
f5b6cffd 996 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
752ef254 997 "\n\n"
f5b6cffd
KS
998 "To ensure normal operation, you should investigate and remove the\n"
999 "cause of the error in your initialization file. Start Emacs with\n"
1000 "the `--debug-init' option to view a complete error backtrace.\n\n"))
752ef254
GM
1001 (message "Error in init file: %s%s%s"
1002 (get (car error) 'error-message)
1003 (if (cdr error) ": " "")
1004 (mapconcat 'prin1-to-string (cdr error) ", "))
f5b6cffd
KS
1005 (let ((pop-up-windows nil))
1006 (pop-to-buffer "*Messages*"))
752ef254 1007 (setq init-file-had-error t)))))
ac3186fd 1008
9c8b2150
RS
1009 (if (and deactivate-mark transient-mark-mode)
1010 (with-current-buffer (window-buffer)
1011 (deactivate-mark)))
1012
d5bd2558
GM
1013 ;; If the user has a file of abbrevs, read it (unless -batch).
1014 (when (and (not noninteractive)
1015 (file-exists-p abbrev-file-name)
2863a9be 1016 (file-readable-p abbrev-file-name))
ac3186fd
RS
1017 (quietly-read-abbrev-file abbrev-file-name))
1018
70b199c3
RS
1019 ;; If the abbrevs came entirely from the init file or the
1020 ;; abbrevs file, they do not need saving.
1021 (setq abbrevs-changed nil)
1022
752ef254
GM
1023 ;; If we can tell that the init file altered debug-on-error,
1024 ;; arrange to preserve the value that it set up.
1025 (or (eq debug-on-error debug-on-error-initial)
1026 (setq debug-on-error-should-be-set t
1027 debug-on-error-from-init-file debug-on-error)))
1028 (if debug-on-error-should-be-set
1029 (setq debug-on-error debug-on-error-from-init-file))
1030 (unless (or default-enable-multibyte-characters
1031 (eq orig-enable-multibyte default-enable-multibyte-characters))
1032 ;; Init file changed to unibyte. Reset existing multibyte
1033 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1034 ;; Arguably this should only be done if they're free of
1035 ;; multibyte characters.
e18c18e8
JB
1036 (mapc (lambda (buffer)
1037 (with-current-buffer buffer
1038 (if enable-multibyte-characters
1039 (set-buffer-multibyte nil))))
1040 (buffer-list))
752ef254
GM
1041 ;; Also re-set the language environment in case it was
1042 ;; originally done before unibyte was set and is sensitive to
1043 ;; unibyte (display table, terminal coding system &c).
1044 (set-language-environment current-language-environment)))
f1180544 1045
752ef254 1046 ;; Do this here in case the init file sets mail-host-address.
5b88a2c5 1047 (if (equal user-mail-address "")
cee0c996
EZ
1048 (setq user-mail-address (or (getenv "EMAIL")
1049 (concat (user-login-name) "@"
1050 (or mail-host-address
1051 (system-name))))))
752ef254 1052
d60b49ac
DN
1053 ;; Originally face attributes were specified via
1054 ;; `font-lock-face-attributes'. Users then changed the default
1055 ;; face attributes by setting that variable. However, we try and
1056 ;; be back-compatible and respect its value if set except for
1057 ;; faces where M-x customize has been used to save changes for the
1058 ;; face.
1059 (when (boundp 'font-lock-face-attributes)
1060 (let ((face-attributes font-lock-face-attributes))
1061 (while face-attributes
1062 (let* ((face-attribute (pop face-attributes))
1063 (face (car face-attribute)))
1064 ;; Rustle up a `defface' SPEC from a
1065 ;; `font-lock-face-attributes' entry.
1066 (unless (get face 'saved-face)
1067 (let ((foreground (nth 1 face-attribute))
1068 (background (nth 2 face-attribute))
1069 (bold-p (nth 3 face-attribute))
1070 (italic-p (nth 4 face-attribute))
1071 (underline-p (nth 5 face-attribute))
1072 face-spec)
1073 (when foreground
1074 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1075 (when background
1076 (setq face-spec (cons ':background (cons background face-spec))))
1077 (when bold-p
1078 (setq face-spec (append '(:weight bold) face-spec)))
1079 (when italic-p
1080 (setq face-spec (append '(:slant italic) face-spec)))
1081 (when underline-p
1082 (setq face-spec (append '(:underline t) face-spec)))
1083 (face-spec-set face (list (list t face-spec)) nil)))))))
1084
752ef254
GM
1085 ;; If parameter have been changed in the init file which influence
1086 ;; face realization, clear the face cache so that new faces will
1087 ;; be realized.
1088 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1089 (eq font-list-limit old-font-list-limit)
1090 (eq face-ignored-fonts old-face-ignored-fonts))
1091 (clear-face-cache)))
f1180544 1092
e3bd99f5
RM
1093 (run-hooks 'after-init-hook)
1094
1fc67c11 1095 ;; Decode all default-directory.
cea927ed
KH
1096 (if (and default-enable-multibyte-characters locale-coding-system)
1097 (save-excursion
1098 (dolist (elt (buffer-list))
1099 (set-buffer elt)
1100 (if default-directory
1101 (setq default-directory
1102 (decode-coding-string default-directory
1103 locale-coding-system t))))
1104 (setq command-line-default-directory
1105 (decode-coding-string command-line-default-directory
1106 locale-coding-system t))))
1107
a726e0d1
JB
1108 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1109 (if (get-buffer "*scratch*")
694210c4 1110 (with-current-buffer "*scratch*"
a726e0d1 1111 (if (eq major-mode 'fundamental-mode)
26cdce23 1112 (funcall initial-major-mode))))
f1180544 1113
a726e0d1
JB
1114 ;; Load library for our terminal type.
1115 ;; User init file can set term-file-prefix to nil to prevent this.
bca8c7be 1116 (unless (or noninteractive
cd85984a
KL
1117 initial-window-system)
1118 (tty-run-terminal-initialization (selected-frame)))
a726e0d1 1119
5777a167
RS
1120 ;; Update the out-of-memory error message based on user's key bindings
1121 ;; for save-some-buffers.
1122 (setq memory-signal-data
1123 (list 'error
1124 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1125
03e3c30a 1126 ;; Process the remaining args.
a726e0d1
JB
1127 (command-line-1 (cdr command-line-args))
1128
1129 ;; If -batch, terminate after processing the command options.
ca57f55d
JD
1130 (if noninteractive (kill-emacs t))
1131
1132 ;; Run emacs-session-restore (session management) if started by
1133 ;; the session manager and we have a session manager connection.
bca8c7be
MS
1134 (if (and (boundp 'x-session-previous-id)
1135 (stringp x-session-previous-id))
a99df87d
RS
1136 (with-no-warnings
1137 (emacs-session-restore x-session-previous-id))))
a726e0d1 1138
46cfd295 1139(defcustom initial-scratch-message (purecopy "\
3b79c219
GM
1140;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1141;; If you want to create a file, visit that file with C-x C-f,
1142;; then enter the text in that file's own buffer.
9fe3219e 1143
46cfd295 1144")
9fe3219e 1145 "Initial message displayed in *scratch* buffer at startup.
249d9683 1146If this is nil, no message will be displayed.
490a1ad6 1147If `inhibit-startup-screen' is non-nil, then no message is displayed,
249d9683 1148regardless of the value of this variable."
fa071a47
RS
1149 :type '(choice (text :tag "Message")
1150 (const :tag "none" nil))
1151 :group 'initialization)
9fe3219e 1152
ce9ded5d
GM
1153\f
1154;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1155;;; Fancy splash screen
1156;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1157
fad930b6 1158(defvar fancy-startup-text
34acda03 1159 '((:face (variable-pitch :foreground "red")
22a58255 1160 "Welcome to "
6e0cfad3
JL
1161 :link ("GNU Emacs"
1162 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1163 "Browse http://www.gnu.org/software/emacs/")
22a58255
CY
1164 ", one component of the "
1165 :link
1166 (lambda ()
1167 (if (eq system-type 'gnu/linux)
6e0cfad3
JL
1168 '("GNU/Linux"
1169 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1170 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1171 '("GNU" (lambda (button) (describe-project))
1172 "Display info on the GNU project")))
22a58255 1173 " operating system.\n"
34acda03
GM
1174 :face variable-pitch "To quit a partially entered command, type "
1175 :face default "Control-g"
1176 :face variable-pitch ".\n\n"
fad930b6 1177 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
22a58255 1178 "\tLearn basic keystroke commands"
fad930b6
RS
1179 (lambda ()
1180 (let* ((en "TUTORIAL")
1181 (tut (or (get-language-info current-language-environment
1182 'tutorial)
1183 en))
1184 (title (with-temp-buffer
1185 (insert-file-contents
1186 (expand-file-name tut tutorial-directory)
1187 nil 0 256)
1188 (search-forward ".")
1189 (buffer-substring (point-min) (1- (point))))))
1190 ;; If there is a specific tutorial for the current language
1191 ;; environment and it is not English, append its title.
1192 (if (string= en tut)
1193 ""
1194 (concat " (" title ")"))))
1195 "\n"
1196 :face variable-pitch
fad930b6 1197 :link ("Emacs Guided Tour"
6e0cfad3
JL
1198 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1199 "Browse http://www.gnu.org/software/emacs/tour/")
fad930b6 1200 "\tOverview of Emacs features\n"
490a1ad6
JL
1201 :link ("View Emacs Manual" (lambda (button) (info-emacs-manual)))
1202 "\tView the Emacs manual using Info\n"
fad930b6
RS
1203 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1204 "\tGNU Emacs comes with "
1205 :face (variable-pitch :slant oblique)
1206 "ABSOLUTELY NO WARRANTY\n"
1207 :face variable-pitch
1208 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1209 "\tConditions for redistributing and changing Emacs\n"
22a58255
CY
1210 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1211 "\tPurchasing printed copies of manuals\n"
fad930b6 1212 "\n"))
ce9ded5d
GM
1213 "A list of texts to show in the middle part of splash screens.
1214Each element in the list should be a list of strings or pairs
1215`:face FACE', like `fancy-splash-insert' accepts them.")
1216
1d865f15 1217(defvar fancy-about-text
34acda03 1218 '((:face (variable-pitch :foreground "red")
22a58255 1219 "This is "
6e0cfad3
JL
1220 :link ("GNU Emacs"
1221 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1222 "Browse http://www.gnu.org/software/emacs/")
22a58255
CY
1223 ", one component of the "
1224 :link
1225 (lambda ()
1226 (if (eq system-type 'gnu/linux)
6e0cfad3
JL
1227 '("GNU/Linux"
1228 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1229 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1230 '("GNU" (lambda (button) (describe-project))
1231 "Display info on the GNU project.")))
22a58255 1232 " operating system.\n"
34acda03 1233 :face (lambda ()
22a58255
CY
1234 (list 'variable-pitch :foreground
1235 (if (eq (frame-parameter nil 'background-mode) 'dark)
1236 "cyan" "darkblue")))
1237 "\n"
1238 (lambda () (emacs-version))
1239 "\n"
34acda03 1240 :face (variable-pitch :height 0.5)
22a58255
CY
1241 (lambda () emacs-copyright)
1242 "\n\n"
1243 :face variable-pitch
490a1ad6
JL
1244 :link ("Authors"
1245 (lambda (button)
1246 (view-file (expand-file-name "AUTHORS" data-directory))
1247 (goto-char (point-min))))
1248 "\tMany people have contributed code included in GNU Emacs\n"
1249 :link ("Contributing"
1250 (lambda (button)
1251 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1252 (goto-char (point-min))))
1253 "\tHow to contribute improvements to Emacs\n"
1254 "\n"
fad930b6
RS
1255 :link ("GNU and Freedom" (lambda (button) (describe-project)))
1256 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1257 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1258 "\tGNU Emacs comes with "
1259 :face (variable-pitch :slant oblique)
1260 "ABSOLUTELY NO WARRANTY\n"
1261 :face variable-pitch
1262 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1263 "\tConditions for redistributing and changing Emacs\n"
1264 :link ("Getting New Versions" (lambda (button) (describe-distribution)))
1265 "\tHow to obtain the latest version of Emacs\n"
1cff9ad1
JL
1266 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1267 "\tBuying printed manuals from the FSF\n"
fad930b6
RS
1268 "\n"
1269 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1270 "\tLearn basic Emacs keystroke commands"
1271 (lambda ()
1272 (let* ((en "TUTORIAL")
1273 (tut (or (get-language-info current-language-environment
1274 'tutorial)
1275 en))
1276 (title (with-temp-buffer
1277 (insert-file-contents
1278 (expand-file-name tut tutorial-directory)
1279 nil 0 256)
1280 (search-forward ".")
1281 (buffer-substring (point-min) (1- (point))))))
1282 ;; If there is a specific tutorial for the current language
1283 ;; environment and it is not English, append its title.
1284 (if (string= en tut)
1285 ""
1286 (concat " (" title ")"))))
1287 "\n"
1288 :link ("Emacs Guided Tour"
6e0cfad3
JL
1289 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1290 "Browse http://www.gnu.org/software/emacs/tour/")
fad930b6
RS
1291 "\tSee an overview of the many facilities of GNU Emacs"
1292 ))
1d865f15
JL
1293 "A list of texts to show in the middle part of the About screen.
1294Each element in the list should be a list of strings or pairs
1295`:face FACE', like `fancy-splash-insert' accepts them.")
1296
ce9ded5d 1297
fb275c02 1298(defgroup fancy-splash-screen ()
a01bb1db 1299 "Fancy splash screen when Emacs starts."
fb275c02 1300 :version "21.1"
a01bb1db
GM
1301 :group 'initialization)
1302
8ad8561b
GM
1303(defcustom fancy-splash-image nil
1304 "*The image to show in the splash screens, or nil for defaults."
a01bb1db 1305 :group 'fancy-splash-screen
8ad8561b
GM
1306 :type '(choice (const :tag "Default" nil)
1307 (file :tag "File")))
ce9ded5d
GM
1308
1309
aeb6faec 1310(defvar splash-screen-keymap
26cdce23
JL
1311 (let ((map (make-sparse-keymap)))
1312 (suppress-keymap map)
1313 (set-keymap-parent map button-buffer-map)
aeb6faec
JL
1314 (define-key map "\C-?" 'scroll-down)
1315 (define-key map " " 'scroll-up)
1316 (define-key map "q" 'exit-splash-screen)
26cdce23
JL
1317 map)
1318 "Keymap for splash screen buffer.")
1319
f645586f
GM
1320;; These are temporary storage areas for the splash screen display.
1321
f645586f 1322(defvar fancy-splash-help-echo nil)
f645586f 1323
ce9ded5d
GM
1324(defun fancy-splash-insert (&rest args)
1325 "Insert text into the current buffer, with faces.
22a58255
CY
1326Arguments from ARGS should be either strings; functions called
1327with no args that return a string; pairs `:face FACE', where FACE
1328is a face specification usable with `put-text-property'; or pairs
1329`:link LINK' where LINK is a list of arguments to pass to
6e0cfad3
JL
1330`insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1331specifies the button's label, `action' property and help-echo string.
1332FACE and LINK can also be functions, which are evaluated to obtain
1333a face or button specification."
ce9ded5d
GM
1334 (let ((current-face nil))
1335 (while args
26cdce23 1336 (cond ((eq (car args) :face)
22a58255
CY
1337 (setq args (cdr args) current-face (car args))
1338 (if (functionp current-face)
1339 (setq current-face (funcall current-face))))
26cdce23
JL
1340 ((eq (car args) :link)
1341 (setq args (cdr args))
1342 (let ((spec (car args)))
22a58255
CY
1343 (if (functionp spec)
1344 (setq spec (funcall spec)))
26cdce23
JL
1345 (insert-button (car spec)
1346 'face (list 'link current-face)
1347 'action (cadr spec)
6e0cfad3
JL
1348 'help-echo (concat "mouse-2, RET: "
1349 (or (nth 2 spec)
1350 "Follow this link"))
26cdce23
JL
1351 'follow-link t)))
1352 (t (insert (propertize (let ((it (car args)))
1353 (if (functionp it)
1354 (funcall it)
1355 it))
1356 'face current-face
1357 'help-echo fancy-splash-help-echo))))
ce9ded5d
GM
1358 (setq args (cdr args)))))
1359
1360
22a58255 1361(defun fancy-splash-head ()
ce9ded5d 1362 "Insert the head part of the splash screen into the current buffer."
51e8cfdd
GM
1363 (let* ((image-file (cond ((stringp fancy-splash-image)
1364 fancy-splash-image)
1365 ((and (display-color-p)
1366 (image-type-available-p 'xpm))
f51a80af
GM
1367 (if (and (fboundp 'x-display-planes)
1368 (= (funcall 'x-display-planes) 8))
1369 "splash8.xpm"
1370 "splash.xpm"))
1371 (t "splash.pbm")))
51e8cfdd 1372 (img (create-image image-file))
ce9ded5d
GM
1373 (image-width (and img (car (image-size img))))
1374 (window-width (window-width (selected-window))))
1375 (when img
1376 (when (> window-width image-width)
f645586f 1377 ;; Center the image in the window.
e2c60824
KS
1378 (insert (propertize " " 'display
1379 `(space :align-to (+ center (-0.5 . ,img)))))
f645586f 1380
e7f3afa9
MB
1381 ;; Change the color of the XPM version of the splash image
1382 ;; so that it is visible with a dark frame background.
1383 (when (and (memq 'xpm img)
1384 (eq (frame-parameter nil 'background-mode) 'dark))
1385 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1386
aeb6faec
JL
1387 ;; Insert the image with a help-echo and a link.
1388 (make-button (prog1 (point) (insert-image img)) (point)
1389 'face 'default
6e0cfad3 1390 'help-echo "mouse-2, RET: Browse http://www.gnu.org/"
aeb6faec
JL
1391 'action (lambda (button) (browse-url "http://www.gnu.org/"))
1392 'follow-link t)
22a58255
CY
1393 (insert "\n\n")))))
1394
1cff9ad1 1395(defun fancy-startup-tail (&optional concise)
ce9ded5d 1396 "Insert the tail part of the splash screen into the current buffer."
95fadcca
GM
1397 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1398 "cyan" "darkblue")))
1cff9ad1
JL
1399 (unless concise
1400 (fancy-splash-insert
1401 :face 'variable-pitch
1402 "\nTo start... "
1403 :link '("Open a File"
6e0cfad3
JL
1404 (lambda (button) (call-interactively 'find-file))
1405 "Specify a new file's name, to edit the file")
1cff9ad1
JL
1406 " "
1407 :link '("Open Home Directory"
6e0cfad3
JL
1408 (lambda (button) (dired "~"))
1409 "Open your home directory, to operate on its files")
1cff9ad1
JL
1410 " "
1411 :link '("Customize Startup"
6e0cfad3
JL
1412 (lambda (button) (customize-group 'initialization))
1413 "Change initialization settings including this screen")
1cff9ad1 1414 "\n"))
22a58255
CY
1415 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1416 "\nThis is "
1417 (emacs-version)
1418 "\n"
1419 :face '(variable-pitch :height 0.5)
1420 emacs-copyright
1421 "\n")
1422 (and auto-save-list-file-prefix
ed638cc9
RS
1423 ;; Don't signal an error if the
1424 ;; directory for auto-save-list files
1425 ;; does not yet exist.
1426 (file-directory-p (file-name-directory
1427 auto-save-list-file-prefix))
1428 (directory-files
1429 (file-name-directory auto-save-list-file-prefix)
1430 nil
1431 (concat "\\`"
1432 (regexp-quote (file-name-nondirectory
1433 auto-save-list-file-prefix)))
1434 t)
1435 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1d865f15 1436 "\nIf an Emacs session crashed recently, "
5b309ebf
RS
1437 "type "
1438 :face '(fixed-pitch :foreground "red")
1439 "Meta-x recover-session RET"
1440 :face '(variable-pitch :foreground "red")
1441 "\nto recover"
22a58255
CY
1442 " the files you were editing."))
1443
1cff9ad1
JL
1444 (when concise
1445 (fancy-splash-insert
3d9d55e6 1446 :face 'variable-pitch "\n"
09723615
JL
1447 :link '("Dismiss this startup screen"
1448 (lambda (button)
1449 (when startup-screen-inhibit-startup-screen
1450 (customize-set-variable 'inhibit-startup-screen t)
1451 (customize-mark-to-save 'inhibit-startup-screen)
1452 (custom-save-all))
1453 (let ((w (get-buffer-window "*GNU Emacs*")))
1454 (and w (not (one-window-p)) (delete-window w)))
1455 (kill-buffer "*GNU Emacs*")))
1cff9ad1
JL
1456 " ")
1457 (when (or user-init-file custom-file)
1458 (let ((checked (create-image "\300\300\141\143\067\076\034\030"
22a58255 1459 'xbm t :width 8 :height 8 :background "grey75"
1cff9ad1
JL
1460 :foreground "black" :relief -2 :ascent 'center))
1461 (unchecked (create-image (make-string 8 0)
1462 'xbm t :width 8 :height 8 :background "grey75"
1463 :foreground "black" :relief -2 :ascent 'center)))
1464 (insert-button
1465 " " :on-glyph checked :off-glyph unchecked 'checked nil
1466 'display unchecked 'follow-link t
1467 'action (lambda (button)
1468 (if (overlay-get button 'checked)
1469 (progn (overlay-put button 'checked nil)
1470 (overlay-put button 'display (overlay-get button :off-glyph))
1471 (setq startup-screen-inhibit-startup-screen nil))
1472 (overlay-put button 'checked t)
1473 (overlay-put button 'display (overlay-get button :on-glyph))
1474 (setq startup-screen-inhibit-startup-screen t)))))
1475 (fancy-splash-insert :face '(variable-pitch :height 0.9)
09723615 1476 " Never show it again.")))))
ce9ded5d 1477
1fb072d1 1478(defun exit-splash-screen ()
875ad194 1479 "Stop displaying the splash screen buffer."
fa7e0e98 1480 (interactive)
1d865f15
JL
1481 (quit-window t))
1482
1cff9ad1 1483(defun fancy-startup-screen (&optional concise)
22a58255 1484 "Display fancy startup screen.
1cff9ad1
JL
1485If CONCISE is non-nil, display a concise version of the
1486splash screen in another window."
3d9d55e6 1487 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
09723615 1488 (with-current-buffer splash-buffer
3d9d55e6
CY
1489 (let ((inhibit-read-only t))
1490 (erase-buffer)
1491 (make-local-variable 'startup-screen-inhibit-startup-screen)
1492 (if pure-space-overflow
1493 (insert pure-space-overflow-message))
1494 (unless concise
1495 (fancy-splash-head))
1496 (dolist (text fancy-startup-text)
1497 (apply #'fancy-splash-insert text)
1498 (insert "\n"))
1499 (skip-chars-backward "\n")
1500 (delete-region (point) (point-max))
1501 (insert "\n")
1502 (fancy-startup-tail concise))
1503 (use-local-map splash-screen-keymap)
1504 (setq tab-width 22
1505 buffer-read-only t)
1506 (set-buffer-modified-p nil)
1507 (if (and view-read-only (not view-mode))
1508 (view-mode-enter nil 'kill-buffer))
09723615
JL
1509 (goto-char (point-min))
1510 (forward-line (if concise 2 4)))
3d9d55e6
CY
1511 (if concise
1512 (progn
1513 (display-buffer splash-buffer)
1514 ;; If the splash screen is in a split window, fit it.
1515 (let ((window (get-buffer-window splash-buffer t)))
1516 (or (null window)
1517 (eq window (selected-window))
1518 (eq window (next-window window))
1519 (fit-window-to-buffer window))))
1520 (switch-to-buffer splash-buffer))))
22a58255
CY
1521
1522(defun fancy-about-screen ()
1523 "Display fancy About screen."
1524 (let ((frame (fancy-splash-frame)))
1525 (save-selected-window
1526 (select-frame frame)
1527 (switch-to-buffer "*About GNU Emacs*")
1528 (setq buffer-undo-list t
1529 mode-line-format (propertize "---- %b %-"
1530 'face 'mode-line-buffer-id))
1531 (let ((inhibit-read-only t))
1532 (erase-buffer)
1533 (if pure-space-overflow
1534 (insert pure-space-overflow-message))
1535 (fancy-splash-head)
1536 (dolist (text fancy-about-text)
1537 (apply #'fancy-splash-insert text)
1538 (insert "\n"))
1539 (unless (current-message)
274f1353 1540 (message "%s" (or fancy-splash-help-echo "")))
22a58255
CY
1541 (set-buffer-modified-p nil)
1542 (goto-char (point-min))
1543 (force-mode-line-update))
1544 (use-local-map splash-screen-keymap)
1545 (setq tab-width 22)
1546 (message "%s" (startup-echo-area-message))
1547 (setq buffer-read-only t)
09723615
JL
1548 (goto-char (point-min))
1549 (forward-line 3))))
6b20fb8e
RS
1550
1551(defun fancy-splash-frame ()
1552 "Return the frame to use for the fancy splash screen.
1553Returning non-nil does not mean we should necessarily
1554use the fancy splash screen, but if we do use it,
1555we put it on this frame."
1556 (let (chosen-frame)
3a321ddb 1557 (dolist (frame (append (frame-list) (list (selected-frame))))
6b20fb8e
RS
1558 (if (and (frame-visible-p frame)
1559 (not (window-minibuffer-p (frame-selected-window frame))))
1560 (setq chosen-frame frame)))
1561 chosen-frame))
f645586f 1562
285991dc
GM
1563(defun use-fancy-splash-screens-p ()
1564 "Return t if fancy splash screens should be used."
9df076f2
GM
1565 (when (and (display-graphic-p)
1566 (or (and (display-color-p)
285991dc 1567 (image-type-available-p 'xpm))
9df076f2 1568 (image-type-available-p 'pbm)))
16d2fae9
JPW
1569 (let ((frame (fancy-splash-frame)))
1570 (when frame
1571 (let* ((img (create-image (or fancy-splash-image
1572 (if (and (display-color-p)
1573 (image-type-available-p 'xpm))
1574 "splash.xpm" "splash.pbm"))))
a68ccb40
RS
1575 (image-height (and img (cdr (image-size img nil frame))))
1576 ;; We test frame-height so that, if the frame is split
1577 ;; by displaying a warning, that doesn't cause the normal
1578 ;; splash screen to be used.
1579 (frame-height (1- (frame-height frame))))
1580 (> frame-height (+ image-height 19)))))))
285991dc
GM
1581
1582
1d865f15
JL
1583(defun normal-splash-screen (&optional startup)
1584 "Display non-graphic splash screen.
1585If optional argument STARTUP is non-nil, display the startup screen
1586after Emacs starts. If STARTUP is nil, display the About screen."
82e736c1 1587 (let ((prev-buffer (current-buffer)))
1d865f15
JL
1588 (with-current-buffer (get-buffer-create "*About GNU Emacs*")
1589 (setq buffer-read-only nil)
1590 (erase-buffer)
1591 (set (make-local-variable 'tab-width) 8)
1592 (if (not startup)
1593 (set (make-local-variable 'mode-line-format)
1594 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1595
1596 (if pure-space-overflow
22a58255 1597 (insert pure-space-overflow-message))
260a5020 1598
1d865f15
JL
1599 ;; The convention for this piece of code is that
1600 ;; each piece of output starts with one or two newlines
1601 ;; and does not end with any newlines.
22a58255 1602 (insert (if startup "Welcome to GNU Emacs" "This is GNU Emacs"))
1d865f15
JL
1603 (insert
1604 (if (eq system-type 'gnu/linux)
1605 ", one component of the GNU/Linux operating system.\n"
1606 ", a part of the GNU operating system.\n"))
1607
1608 (if startup
1609 (if (display-mouse-p)
1610 ;; The user can use the mouse to activate menus
1611 ;; so give help in terms of menu items.
fad930b6 1612 (normal-mouse-startup-screen)
c61453ea 1613
e349ae3b 1614 ;; No mouse menus, so give help using kbd commands.
fad930b6 1615 (normal-no-mouse-startup-screen))
e349ae3b 1616
fad930b6 1617 (normal-about-screen))
1d865f15
JL
1618
1619 ;; The rest of the startup screen is the same on all
1620 ;; kinds of terminals.
1621
1622 ;; Give information on recovering, if there was a crash.
1623 (and startup
1624 auto-save-list-file-prefix
1625 ;; Don't signal an error if the
1626 ;; directory for auto-save-list files
1627 ;; does not yet exist.
1628 (file-directory-p (file-name-directory
1629 auto-save-list-file-prefix))
1630 (directory-files
1631 (file-name-directory auto-save-list-file-prefix)
1632 nil
1633 (concat "\\`"
1634 (regexp-quote (file-name-nondirectory
1635 auto-save-list-file-prefix)))
1636 t)
1637 (insert "\n\nIf an Emacs session crashed recently, "
1638 "type Meta-x recover-session RET\nto recover"
1639 " the files you were editing.\n"))
26cdce23 1640
1d865f15 1641 (use-local-map splash-screen-keymap)
e349ae3b 1642
1d865f15
JL
1643 ;; Display the input that we set up in the buffer.
1644 (set-buffer-modified-p nil)
1645 (setq buffer-read-only t)
1646 (if (and view-read-only (not view-mode))
1647 (view-mode-enter nil 'kill-buffer))
1648 (switch-to-buffer "*About GNU Emacs*")
1649 (if startup (rename-buffer "*GNU Emacs*" t))
1650 (goto-char (point-min)))))
82e736c1 1651
fad930b6
RS
1652(defun normal-mouse-startup-screen ()
1653 ;; The user can use the mouse to activate menus
1654 ;; so give help in terms of menu items.
1655 (insert "\
09723615 1656To follow a link, click Mouse-1 on it, or move to it and type RET.
fad930b6
RS
1657To quit a partially entered command, type Control-g.\n")
1658
1659 (insert "\nImportant Help menu items:\n")
1660 (insert-button "Emacs Tutorial"
1661 'action (lambda (button) (help-with-tutorial))
1662 'follow-link t)
1663 (insert "\t\tLearn basic Emacs keystroke commands\n")
1664 (insert-button "Read the Emacs Manual"
1665 'action (lambda (button) (info-emacs-manual))
1666 'follow-link t)
1667 (insert "\tView the Emacs manual using Info\n")
1668 (insert-button "\(Non)Warranty"
1669 'action (lambda (button) (describe-no-warranty))
1670 'follow-link t)
1671 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1672 (insert-button "Copying Conditions"
1673 'action (lambda (button) (describe-copying))
1674 'follow-link t)
1675 (insert "\tConditions for redistributing and changing Emacs\n")
1676 (insert-button "More Manuals / Ordering Manuals"
1677 'action (lambda (button) (view-order-manuals))
1678 'follow-link t)
1679 (insert " How to order printed manuals from the FSF\n")
1680
1681 (insert "\nUseful tasks:\n")
1682 (insert-button "Visit New File"
1683 'action (lambda (button) (call-interactively 'find-file))
1684 'follow-link t)
1685 (insert "\t\tSpecify a new file's name, to edit the file\n")
1686 (insert-button "Open Home Directory"
1687 'action (lambda (button) (dired "~"))
1688 'follow-link t)
1689 (insert "\tOpen your home directory, to operate on its files\n")
1690 (insert-button "Customize Startup"
1691 'action (lambda (button) (customize-group 'initialization))
1692 'follow-link t)
1693 (insert "\tChange initialization settings including this screen\n")
1694
1695 (insert "\n" (emacs-version)
1696 "\n" emacs-copyright))
1697
1698;; No mouse menus, so give help using kbd commands.
1699(defun normal-no-mouse-startup-screen ()
1700
1701 ;; If keys have their default meanings,
1702 ;; use precomputed string to save lots of time.
1703 (if (and (eq (key-binding "\C-h") 'help-command)
1704 (eq (key-binding "\C-xu") 'advertised-undo)
1705 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
1706 (eq (key-binding "\C-ht") 'help-with-tutorial)
1707 (eq (key-binding "\C-hi") 'info)
1708 (eq (key-binding "\C-hr") 'info-emacs-manual)
1709 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1710 (progn
1711 (insert "
1712Get help\t C-h (Hold down CTRL and press h)
1713")
1714 (insert-button "Emacs manual"
1715 'action (lambda (button) (info-emacs-manual))
1716 'follow-link t)
1717 (insert " C-h r\t")
1718 (insert-button "Browse manuals"
1719 'action (lambda (button) (Info-directory))
1720 'follow-link t)
1721 (insert "\t C-h i
1722")
1723 (insert-button "Emacs tutorial"
1724 'action (lambda (button) (help-with-tutorial))
1725 'follow-link t)
1726 (insert " C-h t\tUndo changes\t C-x u
1727")
1728 (insert-button "Buy manuals"
1729 'action (lambda (button) (view-order-manuals))
1730 'follow-link t)
1731 (insert "\t C-h C-m\tExit Emacs\t C-x C-c"))
1732
1733 (insert (format "
1734Get help\t %s
1735"
1736 (let ((where (where-is-internal
1737 'help-command nil t)))
1738 (if where
1739 (key-description where)
1740 "M-x help"))))
1741 (insert-button "Emacs manual"
1742 'action (lambda (button) (info-emacs-manual))
1743 'follow-link t)
1744 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1745 (insert-button "Browse manuals"
1746 'action (lambda (button) (Info-directory))
1747 'follow-link t)
1748 (insert (substitute-command-keys "\t \\[info]
1749"))
1750 (insert-button "Emacs tutorial"
1751 'action (lambda (button) (help-with-tutorial))
1752 'follow-link t)
1753 (insert (substitute-command-keys
1754 "\t \\[help-with-tutorial]\tUndo changes\t \\[advertised-undo]
1755"))
1756 (insert-button "Buy manuals"
1757 'action (lambda (button) (view-order-manuals))
1758 'follow-link t)
1759 (insert (substitute-command-keys
1760 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1761
1762 ;; Say how to use the menu bar with the keyboard.
1763 (insert "\n")
1764 (insert-button "Activate menubar"
1765 'action (lambda (button) (tmm-menubar))
1766 'follow-link t)
1767 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1768 (eq (key-binding [f10]) 'tmm-menubar))
1769 (insert " F10 or ESC ` or M-`")
1770 (insert (substitute-command-keys " \\[tmm-menubar]")))
1771
1772 ;; Many users seem to have problems with these.
1773 (insert "
1774\(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1775If you have no Meta key, you may instead type ESC followed by the character.)")
1776
1777 ;; Insert links to useful tasks
1778 (insert "\nUseful tasks:\n")
1779
1780 (insert-button "Visit New File"
1781 'action (lambda (button) (call-interactively 'find-file))
1782 'follow-link t)
1783 (insert "\t\t\t")
1784 (insert-button "Open Home Directory"
1785 'action (lambda (button) (dired "~"))
1786 'follow-link t)
1787 (insert "\n")
1788
1789 (insert-button "Customize Startup"
1790 'action (lambda (button) (customize-group 'initialization))
1791 'follow-link t)
1792 (insert "\t\t")
1793 (insert-button "Open *scratch* buffer"
1794 'action (lambda (button) (switch-to-buffer
1795 (get-buffer-create "*scratch*")))
1796 'follow-link t)
1797 (insert "\n")
1798 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1799
1800 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1801 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1802 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1803 (progn
1804 (insert
490a1ad6 1805 "
fad930b6
RS
1806GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1807 (insert-button "full details"
1808 'action (lambda (button) (describe-no-warranty))
1809 'follow-link t)
1810 (insert ".
1811Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1812of Emacs and modify it; type C-h C-c to see ")
1813 (insert-button "the conditions"
1814 'action (lambda (button) (describe-copying))
1815 'follow-link t)
1816 (insert ".
1817Type C-h C-d for information on ")
1818 (insert-button "getting the latest version"
1819 'action (lambda (button) (describe-distribution))
1820 'follow-link t)
1821 (insert "."))
1822 (insert (substitute-command-keys
490a1ad6 1823 "
fad930b6
RS
1824GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1825 (insert-button "full details"
1826 'action (lambda (button) (describe-no-warranty))
1827 'follow-link t)
1828 (insert (substitute-command-keys ".
1829Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1830of Emacs and modify it; type \\[describe-copying] to see "))
1831 (insert-button "the conditions"
1832 'action (lambda (button) (describe-copying))
1833 'follow-link t)
1834 (insert (substitute-command-keys".
1835Type \\[describe-distribution] for information on "))
1836 (insert-button "getting the latest version"
1837 'action (lambda (button) (describe-distribution))
1838 'follow-link t)
1839 (insert ".")))
1840
1841(defun normal-about-screen ()
1842 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1843
1844 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1845
490a1ad6
JL
1846 (insert-button "Authors"
1847 'action
1848 (lambda (button)
1849 (view-file (expand-file-name "AUTHORS" data-directory))
1850 (goto-char (point-min)))
1851 'follow-link t)
1852 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1853
1854 (insert-button "Contributing"
1855 'action
1856 (lambda (button)
1857 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1858 (goto-char (point-min)))
1859 'follow-link t)
1860 (insert "\tHow to contribute improvements to Emacs\n\n")
1861
fad930b6
RS
1862 (insert-button "GNU and Freedom"
1863 'action (lambda (button) (describe-project))
1864 'follow-link t)
1865 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
1866
1867 (insert-button "Absence of Warranty"
1868 'action (lambda (button) (describe-no-warranty))
1869 'follow-link t)
1870 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1871
1872 (insert-button "Copying Conditions"
1873 'action (lambda (button) (describe-copying))
1874 'follow-link t)
1875 (insert "\tConditions for redistributing and changing Emacs\n")
1876
1877 (insert-button "Getting New Versions"
1878 'action (lambda (button) (describe-distribution))
1879 'follow-link t)
1880 (insert "\tHow to get the latest version of GNU Emacs\n")
1881
1882 (insert-button "More Manuals / Ordering Manuals"
1883 'action (lambda (button) (view-order-manuals))
1884 'follow-link t)
1885 (insert "\tBuying printed manuals from the FSF\n"))
c61453ea 1886
f645586f
GM
1887(defun startup-echo-area-message ()
1888 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1cff9ad1 1889 "For information about GNU Emacs and the GNU system, type C-h C-a."
f645586f 1890 (substitute-command-keys
1cff9ad1
JL
1891 "For information about GNU Emacs and the GNU system, type \
1892\\[about-emacs].")))
ce9ded5d
GM
1893
1894
49939379 1895(defun display-startup-echo-area-message ()
15fa6db0 1896 (let ((resize-mini-windows t))
f1be5774
KL
1897 (or noninteractive ;(input-pending-p) init-file-had-error
1898 ;; t if the init file says to inhibit the echo area startup message.
1899 (and inhibit-startup-echo-area-message
1900 user-init-file
1901 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1902 (equal inhibit-startup-echo-area-message
1903 (if (equal init-file-user "")
1904 (user-login-name)
1905 init-file-user)))
1906 ;; Wasn't set with custom; see if .emacs has a setq.
1907 (let ((buffer (get-buffer-create " *temp*")))
1908 (prog1
1909 (condition-case nil
1910 (save-excursion
1911 (set-buffer buffer)
1912 (insert-file-contents user-init-file)
1913 (re-search-forward
1914 (concat
1915 "([ \t\n]*setq[ \t\n]+"
1916 "inhibit-startup-echo-area-message[ \t\n]+"
1917 (regexp-quote
1918 (prin1-to-string
1919 (if (equal init-file-user "")
1920 (user-login-name)
1921 init-file-user)))
1922 "[ \t\n]*)")
1923 nil t))
1924 (error nil))
1925 (kill-buffer buffer)))))
1d865f15 1926 (message "%s" (startup-echo-area-message)))))
f645586f 1927
1cff9ad1 1928(defun display-startup-screen (&optional concise)
22a58255
CY
1929 "Display startup screen according to display.
1930A fancy display is used on graphic displays, normal otherwise.
49939379 1931
22a58255
CY
1932If CONCISE is non-nil, display a concise version of the startup
1933screen."
526039df 1934 ;; Prevent recursive calls from server-process-filter.
1cff9ad1 1935 (if (not (get-buffer "*GNU Emacs*"))
526039df 1936 (if (use-fancy-splash-screens-p)
22a58255
CY
1937 (fancy-startup-screen concise)
1938 (normal-splash-screen t))))
1939
1940(defun display-about-screen ()
1941 "Display the *About GNU Emacs* buffer.
1942A fancy display is used on graphic displays, normal otherwise."
1943 (interactive)
1cff9ad1
JL
1944 (if (use-fancy-splash-screens-p)
1945 (fancy-about-screen)
1946 (normal-splash-screen nil)))
875ad194 1947
22a58255 1948(defalias 'about-emacs 'display-about-screen)
1cff9ad1 1949(defalias 'display-splash-screen 'display-startup-screen)
c61453ea 1950
a726e0d1 1951(defun command-line-1 (command-line-args-left)
f1be5774 1952 (display-startup-echo-area-message)
ed638cc9
RS
1953
1954 ;; Delay 2 seconds after an init file error message
1955 ;; was displayed, so user can read it.
bca8c7be
MS
1956 (when init-file-had-error
1957 (sit-for 2))
1958
cb58ea33
RS
1959 (when (and pure-space-overflow
1960 (not noninteractive))
1961 (display-warning
1962 'initialization
2dca98f3 1963 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
cb58ea33
RS
1964 :warning))
1965
22a58255
CY
1966 (let ((file-count 0)
1967 first-file-buffer)
1968 (when command-line-args-left
1969 ;; We have command args; process them.
1970 (let ((dir command-line-default-directory)
1971 tem
1972 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1973 ;; if foo is intended to be found in DIR.
1974 ;;
1975 ;; ;; The directories listed in --directory/-L options will *appear*
1976 ;; ;; at the front of `load-path' in the order they appear on the
1977 ;; ;; command-line. We cannot do this by *placing* them at the front
1978 ;; ;; in the order they appear, so we need this variable to hold them,
1979 ;; ;; temporarily.
1980 ;; extra-load-path
1981 ;;
1982 ;; To DTRT we keep track of the splice point and modify `load-path'
1983 ;; straight away upon any --directory/-L option.
1984 splice
1985 just-files ;; t if this follows the magic -- option.
1986 ;; This includes our standard options' long versions
1987 ;; and long versions of what's on command-switch-alist.
1988 (longopts
1989 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1990 ("--directory") ("--eval") ("--execute") ("--no-splash")
1991 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1992 (mapcar (lambda (elt)
1993 (list (concat "-" (car elt))))
1994 command-switch-alist)))
1995 (line 0)
1996 (column 0))
1997
1998 ;; Add the long X options to longopts.
1999 (dolist (tem command-line-x-option-alist)
2000 (if (string-match "^--" (car tem))
2001 (push (list (car tem)) longopts)))
2002
2003 ;; Loop, processing options.
2004 (while command-line-args-left
2005 (let* ((argi (car command-line-args-left))
2006 (orig-argi argi)
2007 argval completion)
2008 (setq command-line-args-left (cdr command-line-args-left))
2009
2010 ;; Do preliminary decoding of the option.
2011 (if just-files
2012 ;; After --, don't look for options; treat all args as files.
2013 (setq argi "")
2014 ;; Convert long options to ordinary options
2015 ;; and separate out an attached option argument into argval.
2016 (when (string-match "^\\(--[^=]*\\)=" argi)
2017 (setq argval (substring argi (match-end 0))
2018 argi (match-string 1 argi)))
2019 (if (equal argi "--")
2020 (setq completion nil)
2021 (setq completion (try-completion argi longopts)))
2022 (if (eq completion t)
2023 (setq argi (substring argi 1))
2024 (if (stringp completion)
2025 (let ((elt (assoc completion longopts)))
2026 (or elt
2027 (error "Option `%s' is ambiguous" argi))
2028 (setq argi (substring (car elt) 1)))
2029 (setq argval nil
2030 argi orig-argi))))
2031
2032 ;; Execute the option.
2033 (cond ((setq tem (assoc argi command-switch-alist))
2034 (if argval
2035 (let ((command-line-args-left
2036 (cons argval command-line-args-left)))
2037 (funcall (cdr tem) argi))
2038 (funcall (cdr tem) argi)))
2039
2040 ((equal argi "-no-splash")
1cff9ad1 2041 (setq inhibit-startup-screen t))
22a58255
CY
2042
2043 ((member argi '("-f" ; what the manual claims
2044 "-funcall"
2045 "-e")) ; what the source used to say
1cff9ad1 2046 (setq inhibit-startup-screen t)
22a58255
CY
2047 (setq tem (intern (or argval (pop command-line-args-left))))
2048 (if (commandp tem)
2049 (command-execute tem)
2050 (funcall tem)))
2051
2052 ((member argi '("-eval" "-execute"))
1cff9ad1 2053 (setq inhibit-startup-screen t)
22a58255
CY
2054 (eval (read (or argval (pop command-line-args-left)))))
2055
2056 ((member argi '("-L" "-directory"))
2057 (setq tem (expand-file-name
2058 (command-line-normalize-file-name
2059 (or argval (pop command-line-args-left)))))
2060 (cond (splice (setcdr splice (cons tem (cdr splice)))
2061 (setq splice (cdr splice)))
2062 (t (setq load-path (cons tem load-path)
2063 splice load-path))))
2064
2065 ((member argi '("-l" "-load"))
2066 (let* ((file (command-line-normalize-file-name
2067 (or argval (pop command-line-args-left))))
2068 ;; Take file from default dir if it exists there;
2069 ;; otherwise let `load' search for it.
2070 (file-ex (expand-file-name file)))
2071 (when (file-exists-p file-ex)
2072 (setq file file-ex))
2073 (load file nil t)))
2074
2075 ;; This is used to handle -script. It's not clear
2076 ;; we need to document it.
2077 ((member argi '("-scriptload"))
2078 (let* ((file (command-line-normalize-file-name
2079 (or argval (pop command-line-args-left))))
2080 ;; Take file from default dir.
2081 (file-ex (expand-file-name file)))
2082 (load file-ex nil t t)))
2083
2084 ((equal argi "-insert")
1cff9ad1 2085 (setq inhibit-startup-screen t)
22a58255
CY
2086 (setq tem (or argval (pop command-line-args-left)))
2087 (or (stringp tem)
2088 (error "File name omitted from `-insert' option"))
2089 (insert-file-contents (command-line-normalize-file-name tem)))
2090
2091 ((equal argi "-kill")
2092 (kill-emacs t))
2093
2094 ;; This is for when they use --no-desktop with -q, or
2095 ;; don't load Desktop in their .emacs. If desktop.el
2096 ;; _is_ loaded, it will handle this switch, and we
2097 ;; won't see it by the time we get here.
2098 ((equal argi "-no-desktop")
2099 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2100
2101 ((string-match "^\\+[0-9]+\\'" argi)
2102 (setq line (string-to-number argi)))
2103
2104 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2105 (setq line (string-to-number (match-string 1 argi))
2106 column (string-to-number (match-string 2 argi))))
2107
2108 ((setq tem (assoc argi command-line-x-option-alist))
2109 ;; Ignore X-windows options and their args if not using X.
2110 (setq command-line-args-left
2111 (nthcdr (nth 1 tem) command-line-args-left)))
2112
2113 ((member argi '("-find-file" "-file" "-visit"))
1cff9ad1 2114 (setq inhibit-startup-screen t)
22a58255
CY
2115 ;; An explicit option to specify visiting a file.
2116 (setq tem (or argval (pop command-line-args-left)))
2117 (unless (stringp tem)
2118 (error "File name omitted from `%s' option" argi))
2119 (setq file-count (1+ file-count))
2120 (let ((file (expand-file-name
2121 (command-line-normalize-file-name tem) dir)))
2122 (if (= file-count 1)
2123 (setq first-file-buffer (find-file file))
2124 (find-file-other-window file)))
2125 (or (zerop line)
2126 (goto-line line))
2127 (setq line 0)
2128 (unless (< column 1)
2129 (move-to-column (1- column)))
2130 (setq column 0))
2131
2132 ((equal argi "--")
2133 (setq just-files t))
2134 (t
2135 ;; We have almost exhausted our options. See if the
2136 ;; user has made any other command-line options available
2137 (let ((hooks command-line-functions)
2138 (did-hook nil))
2139 (while (and hooks
2140 (not (setq did-hook (funcall (car hooks)))))
2141 (setq hooks (cdr hooks)))
2142 (if (not did-hook)
2143 ;; Presume that the argument is a file name.
2144 (progn
2145 (if (string-match "\\`-" argi)
2146 (error "Unknown option `%s'" argi))
1cff9ad1
JL
2147 (unless initial-window-system
2148 (setq inhibit-startup-screen t))
22a58255
CY
2149 (setq file-count (1+ file-count))
2150 (let ((file
2151 (expand-file-name
2152 (command-line-normalize-file-name orig-argi)
2153 dir)))
3d9d55e6
CY
2154 (cond ((= file-count 1)
2155 (setq first-file-buffer (find-file file)))
2156 (inhibit-startup-screen
2157 (find-file-other-window file))
2158 (t (find-file file))))
22a58255
CY
2159 (or (zerop line)
2160 (goto-line line))
2161 (setq line 0)
2162 (unless (< column 1)
2163 (move-to-column (1- column)))
2164 (setq column 0))))))
2165 ;; In unusual circumstances, the execution of Lisp code due
2166 ;; to command-line options can cause the last visible frame
2167 ;; to be deleted. In this case, kill emacs to avoid an
2168 ;; abort later.
2169 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2170
2171 (when initial-buffer-choice
2172 (cond ((eq initial-buffer-choice t)
2173 (switch-to-buffer (get-buffer-create "*scratch*")))
2174 ((stringp initial-buffer-choice)
2175 (find-file initial-buffer-choice))))
2176
1cff9ad1 2177 (if (or inhibit-startup-screen
22a58255
CY
2178 initial-buffer-choice
2179 noninteractive
2180 emacs-quick-startup)
2181
2182 ;; Not displaying a startup screen. If 3 or more files
2183 ;; visited, and not all visible, show user what they all are.
2184 (and (> file-count 2)
2185 (not noninteractive)
2186 (not inhibit-startup-buffer-menu)
2187 (or (get-buffer-window first-file-buffer)
2188 (list-buffers)))
2189
2190 ;; Display a startup screen, after some preparations.
2191
2192 ;; If there are no switches to process, we might as well
2193 ;; run this hook now, and there may be some need to do it
2194 ;; before doing any output.
2195 (run-hooks 'emacs-startup-hook)
2196 (and term-setup-hook
2197 (run-hooks 'term-setup-hook))
2198 (setq inhibit-startup-hooks t)
2199
2200 ;; It's important to notice the user settings before we
2201 ;; display the startup message; otherwise, the settings
2202 ;; won't take effect until the user gives the first
2203 ;; keystroke, and that's distracting.
2204 (when (fboundp 'frame-notice-user-settings)
2205 (frame-notice-user-settings))
2206
2207 ;; If there are no switches to process, we might as well
2208 ;; run this hook now, and there may be some need to do it
2209 ;; before doing any output.
2210 (when window-setup-hook
2211 (run-hooks 'window-setup-hook)
2212 ;; Don't let the hook be run twice.
2213 (setq window-setup-hook nil))
2214
04ef2618
CY
2215 ;; ;; Do this now to avoid an annoying delay if the user
2216 ;; ;; clicks the menu bar during the sit-for.
2217 ;; (when (display-popup-menus-p)
2218 ;; (precompute-menubar-bindings))
2219 ;; (with-no-warnings
2220 ;; (setq menubar-bindings-done t))
22a58255
CY
2221
2222 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2223 (and initial-scratch-message
2224 (get-buffer "*scratch*")
2225 (with-current-buffer "*scratch*"
2226 (when (zerop (buffer-size))
2227 (insert initial-scratch-message)
2228 (set-buffer-modified-p nil))))
2229
1cff9ad1
JL
2230 (if (> file-count 0)
2231 (display-startup-screen t)
2232 (display-startup-screen nil)))))
49939379 2233
47c7adae
RS
2234(defun command-line-normalize-file-name (file)
2235 "Collapse multiple slashes to one, to handle non-Emacs file names."
6b9e794f
RS
2236 (save-match-data
2237 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2238 ;; That is significant on some systems.
2239 ;; However, /// at the beginning is supposed to mean just /, not //.
2240 (if (string-match "^///+" file)
2241 (setq file (replace-match "/" t t file)))
2242 (while (string-match "//+" file 1)
2243 (setq file (replace-match "/" t t file)))
2244 file))
47c7adae 2245
a3194d03 2246;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
c88ab9ce 2247;;; startup.el ends here