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