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