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