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