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