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