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