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