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