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