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