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