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