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