]> code.delx.au - gnu-emacs/blob - lisp/startup.el
Merge from emacs--rel--22
[gnu-emacs] / 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
804 ;; Register default TTY colors for the case the terminal hasn't a
805 ;; terminal init file.
806 (unless (memq window-system '(x w32 mac))
807 ;; We do this regardles of whether the terminal supports colors
808 ;; or not, since they can switch that support on or off in
809 ;; mid-session by setting the tty-color-mode frame parameter.
810 (tty-register-default-colors))
811
812 ;; Record whether the tool-bar is present before the user and site
813 ;; init files are processed. frame-notice-user-settings uses this
814 ;; to determine if the tool-bar has been disabled by the init files,
815 ;; and the frame needs to be resized.
816 (when (fboundp 'frame-notice-user-settings)
817 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
818 (assq 'tool-bar-lines default-frame-alist))))
819 (setq tool-bar-originally-present
820 (and tool-bar-lines
821 (cdr tool-bar-lines)
822 (not (eq 0 (cdr tool-bar-lines)))))))
823
824 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
825 (old-font-list-limit font-list-limit)
826 (old-face-ignored-fonts face-ignored-fonts))
827
828 ;; Run the site-start library if it exists. The point of this file is
829 ;; that it is run before .emacs. There is no point in doing this after
830 ;; .emacs; that is useless.
831 (if site-run-file
832 (load site-run-file t t))
833
834 ;; Sites should not disable this. Only individuals should disable
835 ;; the startup message.
836 (setq inhibit-startup-message nil)
837
838 ;; Warn for invalid user name.
839 (when init-file-user
840 (if (string-match "[~/:\n]" init-file-user)
841 (display-warning 'initialization
842 (format "Invalid user name %s"
843 init-file-user)
844 :error)
845 (if (file-directory-p (expand-file-name
846 ;; We don't support ~USER on MS-Windows except
847 ;; for the current user, and always load .emacs
848 ;; from the current user's home directory (see
849 ;; below). So always check "~", even if invoked
850 ;; with "-u USER", or if $USER or $LOGNAME are
851 ;; set to something different.
852 (if (eq system-type 'windows-nt)
853 "~"
854 (concat "~" init-file-user))))
855 nil
856 (display-warning 'initialization
857 (format "User %s has no home directory"
858 init-file-user)
859 :error))))
860
861 ;; Load that user's init file, or the default one, or none.
862 (let (debug-on-error-from-init-file
863 debug-on-error-should-be-set
864 (debug-on-error-initial
865 (if (eq init-file-debug t) 'startup init-file-debug))
866 (orig-enable-multibyte default-enable-multibyte-characters))
867 (let ((debug-on-error debug-on-error-initial)
868 ;; This function actually reads the init files.
869 (inner
870 (function
871 (lambda ()
872 (if init-file-user
873 (let ((user-init-file-1
874 (cond
875 ((eq system-type 'ms-dos)
876 (concat "~" init-file-user "/_emacs"))
877 ((eq system-type 'windows-nt)
878 ;; Prefer .emacs on Windows.
879 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
880 "~/.emacs"
881 ;; Also support _emacs for compatibility.
882 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
883 "~/_emacs"
884 ;; But default to .emacs if _emacs does not exist.
885 "~/.emacs")))
886 ((eq system-type 'vax-vms)
887 "sys$login:.emacs")
888 (t
889 (concat "~" init-file-user "/.emacs")))))
890 ;; This tells `load' to store the file name found
891 ;; into user-init-file.
892 (setq user-init-file t)
893 (load user-init-file-1 t t)
894
895 (when (eq user-init-file t)
896 ;; If we did not find ~/.emacs, try
897 ;; ~/.emacs.d/init.el.
898 (let ((otherfile
899 (expand-file-name
900 "init"
901 (file-name-as-directory
902 (concat "~" init-file-user "/.emacs.d")))))
903 (load otherfile t t)
904
905 ;; If we did not find the user's init file,
906 ;; set user-init-file conclusively.
907 ;; Don't let it be set from default.el.
908 (when (eq user-init-file t)
909 (setq user-init-file user-init-file-1))))
910
911 ;; If we loaded a compiled file, set
912 ;; `user-init-file' to the source version if that
913 ;; exists.
914 (when (and user-init-file
915 (equal (file-name-extension user-init-file)
916 "elc"))
917 (let* ((source (file-name-sans-extension user-init-file))
918 (alt (concat source ".el")))
919 (setq source (cond ((file-exists-p alt) alt)
920 ((file-exists-p source) source)
921 (t nil)))
922 (when source
923 (when (file-newer-than-file-p source user-init-file)
924 (message "Warning: %s is newer than %s"
925 source user-init-file)
926 (sit-for 1))
927 (setq user-init-file source))))
928
929 (unless inhibit-default-init
930 (let ((inhibit-startup-message nil))
931 ;; Users are supposed to be told their rights.
932 ;; (Plus how to get help and how to undo.)
933 ;; Don't you dare turn this off for anyone
934 ;; except yourself.
935 (load "default" t t)))))))))
936 (if init-file-debug
937 ;; Do this without a condition-case if the user wants to debug.
938 (funcall inner)
939 (condition-case error
940 (progn
941 (funcall inner)
942 (setq init-file-had-error nil))
943 (error
944 (let ((message-log-max nil))
945 (save-excursion
946 (set-buffer (get-buffer-create "*Messages*"))
947 (insert "\n\n"
948 (format "An error has occurred while loading `%s':\n\n"
949 user-init-file)
950 (format "%s%s%s"
951 (get (car error) 'error-message)
952 (if (cdr error) ": " "")
953 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
954 "\n\n"
955 "To ensure normal operation, you should investigate and remove the\n"
956 "cause of the error in your initialization file. Start Emacs with\n"
957 "the `--debug-init' option to view a complete error backtrace.\n\n"))
958 (message "Error in init file: %s%s%s"
959 (get (car error) 'error-message)
960 (if (cdr error) ": " "")
961 (mapconcat 'prin1-to-string (cdr error) ", "))
962 (let ((pop-up-windows nil))
963 (pop-to-buffer "*Messages*"))
964 (setq init-file-had-error t)))))
965
966 (if (and deactivate-mark transient-mark-mode)
967 (with-current-buffer (window-buffer)
968 (deactivate-mark)))
969
970 ;; If the user has a file of abbrevs, read it.
971 ;; FIXME: after the 22.0 release this should be changed so
972 ;; that it does not read the abbrev file when -batch is used
973 ;; on the command line.
974 (when (and (file-exists-p abbrev-file-name)
975 (file-readable-p abbrev-file-name))
976 (quietly-read-abbrev-file abbrev-file-name))
977
978 ;; If the abbrevs came entirely from the init file or the
979 ;; abbrevs file, they do not need saving.
980 (setq abbrevs-changed nil)
981
982 ;; If we can tell that the init file altered debug-on-error,
983 ;; arrange to preserve the value that it set up.
984 (or (eq debug-on-error debug-on-error-initial)
985 (setq debug-on-error-should-be-set t
986 debug-on-error-from-init-file debug-on-error)))
987 (if debug-on-error-should-be-set
988 (setq debug-on-error debug-on-error-from-init-file))
989 (unless (or default-enable-multibyte-characters
990 (eq orig-enable-multibyte default-enable-multibyte-characters))
991 ;; Init file changed to unibyte. Reset existing multibyte
992 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
993 ;; Arguably this should only be done if they're free of
994 ;; multibyte characters.
995 (mapcar (lambda (buffer)
996 (with-current-buffer buffer
997 (if enable-multibyte-characters
998 (set-buffer-multibyte nil))))
999 (buffer-list))
1000 ;; Also re-set the language environment in case it was
1001 ;; originally done before unibyte was set and is sensitive to
1002 ;; unibyte (display table, terminal coding system &c).
1003 (set-language-environment current-language-environment)))
1004
1005 ;; Do this here in case the init file sets mail-host-address.
1006 (if (equal user-mail-address "")
1007 (setq user-mail-address (or (getenv "EMAIL")
1008 (concat (user-login-name) "@"
1009 (or mail-host-address
1010 (system-name))))))
1011
1012 ;; Originally face attributes were specified via
1013 ;; `font-lock-face-attributes'. Users then changed the default
1014 ;; face attributes by setting that variable. However, we try and
1015 ;; be back-compatible and respect its value if set except for
1016 ;; faces where M-x customize has been used to save changes for the
1017 ;; face.
1018 (when (boundp 'font-lock-face-attributes)
1019 (let ((face-attributes font-lock-face-attributes))
1020 (while face-attributes
1021 (let* ((face-attribute (pop face-attributes))
1022 (face (car face-attribute)))
1023 ;; Rustle up a `defface' SPEC from a
1024 ;; `font-lock-face-attributes' entry.
1025 (unless (get face 'saved-face)
1026 (let ((foreground (nth 1 face-attribute))
1027 (background (nth 2 face-attribute))
1028 (bold-p (nth 3 face-attribute))
1029 (italic-p (nth 4 face-attribute))
1030 (underline-p (nth 5 face-attribute))
1031 face-spec)
1032 (when foreground
1033 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1034 (when background
1035 (setq face-spec (cons ':background (cons background face-spec))))
1036 (when bold-p
1037 (setq face-spec (append '(:weight bold) face-spec)))
1038 (when italic-p
1039 (setq face-spec (append '(:slant italic) face-spec)))
1040 (when underline-p
1041 (setq face-spec (append '(:underline t) face-spec)))
1042 (face-spec-set face (list (list t face-spec)) nil)))))))
1043
1044 ;; If parameter have been changed in the init file which influence
1045 ;; face realization, clear the face cache so that new faces will
1046 ;; be realized.
1047 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1048 (eq font-list-limit old-font-list-limit)
1049 (eq face-ignored-fonts old-face-ignored-fonts))
1050 (clear-face-cache)))
1051
1052 (run-hooks 'after-init-hook)
1053
1054 ;; Decode all default-directory.
1055 (if (and default-enable-multibyte-characters locale-coding-system)
1056 (save-excursion
1057 (dolist (elt (buffer-list))
1058 (set-buffer elt)
1059 (if default-directory
1060 (setq default-directory
1061 (decode-coding-string default-directory
1062 locale-coding-system t))))
1063 (setq command-line-default-directory
1064 (decode-coding-string command-line-default-directory
1065 locale-coding-system t))))
1066
1067 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1068 (if (get-buffer "*scratch*")
1069 (with-current-buffer "*scratch*"
1070 (if (eq major-mode 'fundamental-mode)
1071 (funcall initial-major-mode))))
1072
1073 ;; Load library for our terminal type.
1074 ;; User init file can set term-file-prefix to nil to prevent this.
1075 (unless (or noninteractive
1076 window-system
1077 (null term-file-prefix))
1078 (let* ((TERM (getenv "TERM"))
1079 (term TERM)
1080 hyphend)
1081 (while (and term
1082 (not (load (concat term-file-prefix term) t t)))
1083 ;; Strip off last hyphen and what follows, then try again
1084 (setq term
1085 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
1086 (substring term 0 hyphend)
1087 nil)))
1088 (setq term TERM)
1089 ;; The terminal file has been loaded, now call the terminal specific
1090 ;; initialization function.
1091 (while term
1092 (let ((term-init-func (intern-soft (concat "terminal-init-" term))))
1093 (if (not (fboundp term-init-func))
1094 ;; Strip off last hyphen and what follows, then try again
1095 (setq term
1096 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
1097 (substring term 0 hyphend)
1098 nil))
1099 (setq term nil)
1100 (funcall term-init-func))))))
1101
1102 ;; Update the out-of-memory error message based on user's key bindings
1103 ;; for save-some-buffers.
1104 (setq memory-signal-data
1105 (list 'error
1106 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1107
1108 ;; Process the remaining args.
1109 (command-line-1 (cdr command-line-args))
1110
1111 ;; If -batch, terminate after processing the command options.
1112 (if noninteractive (kill-emacs t))
1113
1114 ;; Run emacs-session-restore (session management) if started by
1115 ;; the session manager and we have a session manager connection.
1116 (if (and (boundp 'x-session-previous-id)
1117 (stringp x-session-previous-id))
1118 (with-no-warnings
1119 (emacs-session-restore x-session-previous-id))))
1120
1121 (defcustom initial-scratch-message (purecopy "\
1122 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1123 ;; If you want to create a file, visit that file with C-x C-f,
1124 ;; then enter the text in that file's own buffer.
1125
1126 ")
1127 "Initial message displayed in *scratch* buffer at startup.
1128 If this is nil, no message will be displayed.
1129 If `inhibit-splash-screen' is non-nil, then no message is displayed,
1130 regardless of the value of this variable."
1131 :type '(choice (text :tag "Message")
1132 (const :tag "none" nil))
1133 :group 'initialization)
1134
1135 \f
1136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1137 ;;; Fancy splash screen
1138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1139
1140 (defvar fancy-splash-text
1141 '((:face (variable-pitch :weight bold)
1142 "Important Help menu items:\n"
1143 :face variable-pitch
1144 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1145 "\tLearn how to use Emacs efficiently"
1146 (lambda ()
1147 (let* ((en "TUTORIAL")
1148 (tut (or (get-language-info current-language-environment
1149 'tutorial)
1150 en))
1151 (title (with-temp-buffer
1152 (insert-file-contents
1153 (expand-file-name tut data-directory)
1154 nil 0 256)
1155 (search-forward ".")
1156 (buffer-substring (point-min) (1- (point))))))
1157 ;; If there is a specific tutorial for the current language
1158 ;; environment and it is not English, append its title.
1159 (if (string= en tut)
1160 ""
1161 (concat " (" title ")"))))
1162 "\n"
1163 :face variable-pitch
1164 :link ("Emacs FAQ" (lambda (button) (view-emacs-FAQ)))
1165 "\tFrequently asked questions and answers\n"
1166 :link ("View Emacs Manual" (lambda (button) (info-emacs-manual)))
1167 "\tView the Emacs manual using Info\n"
1168 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1169 "\tGNU Emacs comes with "
1170 :face (variable-pitch :slant oblique)
1171 "ABSOLUTELY NO WARRANTY\n"
1172 :face variable-pitch
1173 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1174 "\tConditions for redistributing and changing Emacs\n"
1175 :link ("Getting New Versions" (lambda (button) (describe-distribution)))
1176 "\tHow to obtain the latest version of Emacs\n"
1177 :link ("More Manuals / Ordering Manuals" (lambda (button) (view-order-manuals)))
1178 " Buying printed manuals from the FSF\n")
1179 (:face (variable-pitch :weight bold)
1180 "Useful tasks:\n"
1181 :face variable-pitch
1182 :link ("Visit New File"
1183 (lambda (button) (call-interactively 'find-file)))
1184 "\tSpecify a new file's name, to edit the file\n"
1185 :link ("Open Home Directory"
1186 (lambda (button) (dired "~")))
1187 "\tOpen your home directory, to operate on its files\n"
1188 :link ("Open *scratch* buffer"
1189 (lambda (button) (switch-to-buffer (get-buffer-create "*scratch*"))))
1190 "\tOpen buffer for notes you don't want to save\n"
1191 :link ("Customize Startup"
1192 (lambda (button) (customize-group 'initialization)))
1193 "\tChange initialization settings including this screen\n"
1194
1195 "\nEmacs Guided Tour\tSee "
1196 :link ("http://www.gnu.org/software/emacs/tour/"
1197 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/")))
1198
1199 ))
1200 "A list of texts to show in the middle part of splash screens.
1201 Each element in the list should be a list of strings or pairs
1202 `:face FACE', like `fancy-splash-insert' accepts them.")
1203
1204
1205 (defgroup fancy-splash-screen ()
1206 "Fancy splash screen when Emacs starts."
1207 :version "21.1"
1208 :group 'initialization)
1209
1210
1211 (defcustom fancy-splash-delay 7
1212 "*Delay in seconds between splash screens."
1213 :group 'fancy-splash-screen
1214 :type 'integer)
1215
1216
1217 (defcustom fancy-splash-max-time 30
1218 "*Show splash screens for at most this number of seconds.
1219 Values less than twice `fancy-splash-delay' are ignored."
1220 :group 'fancy-splash-screen
1221 :type 'integer)
1222
1223
1224 (defcustom fancy-splash-image nil
1225 "*The image to show in the splash screens, or nil for defaults."
1226 :group 'fancy-splash-screen
1227 :type '(choice (const :tag "Default" nil)
1228 (file :tag "File")))
1229
1230
1231 (defvar splash-screen-keymap
1232 (let ((map (make-sparse-keymap)))
1233 (suppress-keymap map)
1234 (set-keymap-parent map button-buffer-map)
1235 (define-key map "\C-?" 'scroll-down)
1236 (define-key map " " 'scroll-up)
1237 (define-key map "q" 'exit-splash-screen)
1238 map)
1239 "Keymap for splash screen buffer.")
1240
1241 ;; These are temporary storage areas for the splash screen display.
1242
1243 (defvar fancy-current-text nil)
1244 (defvar fancy-splash-help-echo nil)
1245 (defvar fancy-splash-stop-time nil)
1246 (defvar fancy-splash-outer-buffer nil)
1247
1248 (defun fancy-splash-insert (&rest args)
1249 "Insert text into the current buffer, with faces.
1250 Arguments from ARGS should be either strings, functions called
1251 with no args that return a string, or pairs `:face FACE',
1252 where FACE is a valid face specification, as it can be used with
1253 `put-text-property'."
1254 (let ((current-face nil))
1255 (while args
1256 (cond ((eq (car args) :face)
1257 (setq args (cdr args) current-face (car args)))
1258 ((eq (car args) :link)
1259 (setq args (cdr args))
1260 (let ((spec (car args)))
1261 (insert-button (car spec)
1262 'face (list 'link current-face)
1263 'action (cadr spec)
1264 'follow-link t)))
1265 (t (insert (propertize (let ((it (car args)))
1266 (if (functionp it)
1267 (funcall it)
1268 it))
1269 'face current-face
1270 'help-echo fancy-splash-help-echo))))
1271 (setq args (cdr args)))))
1272
1273
1274 (defun fancy-splash-head ()
1275 "Insert the head part of the splash screen into the current buffer."
1276 (let* ((image-file (cond ((stringp fancy-splash-image)
1277 fancy-splash-image)
1278 ((and (display-color-p)
1279 (image-type-available-p 'xpm))
1280 (if (and (fboundp 'x-display-planes)
1281 (= (funcall 'x-display-planes) 8))
1282 "splash8.xpm"
1283 "splash.xpm"))
1284 (t "splash.pbm")))
1285 (img (create-image image-file))
1286 (image-width (and img (car (image-size img))))
1287 (window-width (window-width (selected-window))))
1288 (when img
1289 (when (> window-width image-width)
1290 ;; Center the image in the window.
1291 (insert (propertize " " 'display
1292 `(space :align-to (+ center (-0.5 . ,img)))))
1293
1294 ;; Change the color of the XPM version of the splash image
1295 ;; so that it is visible with a dark frame background.
1296 (when (and (memq 'xpm img)
1297 (eq (frame-parameter nil 'background-mode) 'dark))
1298 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1299
1300 ;; Insert the image with a help-echo and a link.
1301 (make-button (prog1 (point) (insert-image img)) (point)
1302 'face 'default
1303 'help-echo "mouse-2: browse http://www.gnu.org/"
1304 'action (lambda (button) (browse-url "http://www.gnu.org/"))
1305 'follow-link t)
1306 (insert "\n"))))
1307 (fancy-splash-insert
1308 :face '(variable-pitch :foreground "red")
1309 (if (eq system-type 'gnu/linux)
1310 "GNU Emacs is one component of the GNU/Linux operating system."
1311 "GNU Emacs is one component of the GNU operating system."))
1312 (insert "\n")
1313 (fancy-splash-insert
1314 :face 'variable-pitch
1315 "You can do basic editing with the menu bar and scroll bar \
1316 using the mouse.\n"
1317 :face 'variable-pitch
1318 "To quit a partially entered command, type "
1319 :face 'default
1320 "Control-g"
1321 :face 'variable-pitch
1322 "."
1323 "\n\n")
1324 (when fancy-splash-outer-buffer
1325 (fancy-splash-insert
1326 :face 'variable-pitch
1327 "Type "
1328 :face 'default
1329 "`q'"
1330 :face 'variable-pitch
1331 " to exit from this screen.\n")))
1332
1333 (defun fancy-splash-tail ()
1334 "Insert the tail part of the splash screen into the current buffer."
1335 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1336 "cyan" "darkblue")))
1337 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1338 "\nThis is "
1339 (emacs-version)
1340 "\n"
1341 :face '(variable-pitch :height 0.5)
1342 emacs-copyright)
1343 (and auto-save-list-file-prefix
1344 ;; Don't signal an error if the
1345 ;; directory for auto-save-list files
1346 ;; does not yet exist.
1347 (file-directory-p (file-name-directory
1348 auto-save-list-file-prefix))
1349 (directory-files
1350 (file-name-directory auto-save-list-file-prefix)
1351 nil
1352 (concat "\\`"
1353 (regexp-quote (file-name-nondirectory
1354 auto-save-list-file-prefix)))
1355 t)
1356 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1357 "\n\nIf an Emacs session crashed recently, "
1358 "type "
1359 :face '(fixed-pitch :foreground "red")
1360 "Meta-x recover-session RET"
1361 :face '(variable-pitch :foreground "red")
1362 "\nto recover"
1363 " the files you were editing.\n"))))
1364
1365 (defun fancy-splash-screens-1 (buffer)
1366 "Timer function displaying a splash screen."
1367 (when (> (float-time) fancy-splash-stop-time)
1368 (throw 'stop-splashing nil))
1369 (unless fancy-current-text
1370 (setq fancy-current-text fancy-splash-text))
1371 (let ((text (car fancy-current-text))
1372 (inhibit-read-only t))
1373 (set-buffer buffer)
1374 (erase-buffer)
1375 (if pure-space-overflow
1376 (insert "\
1377 Warning Warning!!! Pure space overflow !!!Warning Warning
1378 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1379 (fancy-splash-head)
1380 (apply #'fancy-splash-insert text)
1381 (fancy-splash-tail)
1382 (unless (current-message)
1383 (message fancy-splash-help-echo))
1384 (set-buffer-modified-p nil)
1385 (goto-char (point-min))
1386 (force-mode-line-update)
1387 (setq fancy-current-text (cdr fancy-current-text))))
1388
1389 (defun exit-splash-screen ()
1390 "Stop displaying the splash screen buffer."
1391 (interactive)
1392 (if fancy-splash-outer-buffer
1393 (throw 'exit nil)
1394 (quit-window t)))
1395
1396 (defun fancy-splash-screens (&optional static)
1397 "Display fancy splash screens when Emacs starts."
1398 (if (not static)
1399 (let ((old-hourglass display-hourglass)
1400 (fancy-splash-outer-buffer (current-buffer))
1401 splash-buffer
1402 (frame (fancy-splash-frame))
1403 timer)
1404 (save-selected-window
1405 (select-frame frame)
1406 (switch-to-buffer "*About GNU Emacs*")
1407 (make-local-variable 'cursor-type)
1408 (setq splash-buffer (current-buffer))
1409 (catch 'stop-splashing
1410 (unwind-protect
1411 (let ((cursor-type nil))
1412 (setq display-hourglass nil
1413 buffer-undo-list t
1414 mode-line-format (propertize "---- %b %-"
1415 'face 'mode-line-buffer-id)
1416 fancy-splash-stop-time (+ (float-time)
1417 fancy-splash-max-time)
1418 timer (run-with-timer 0 fancy-splash-delay
1419 #'fancy-splash-screens-1
1420 splash-buffer))
1421 (use-local-map splash-screen-keymap)
1422 (setq tab-width 22)
1423 (message "%s" (startup-echo-area-message))
1424 (setq buffer-read-only t)
1425 (recursive-edit))
1426 (cancel-timer timer)
1427 (setq display-hourglass old-hourglass)
1428 (kill-buffer splash-buffer)))))
1429 ;; If static is non-nil, don't show fancy splash screen.
1430 (if (or (window-minibuffer-p)
1431 (window-dedicated-p (selected-window)))
1432 (pop-to-buffer (current-buffer))
1433 (switch-to-buffer "*GNU Emacs*"))
1434 (setq buffer-read-only nil)
1435 (erase-buffer)
1436 (if pure-space-overflow
1437 (insert "\
1438 Warning Warning!!! Pure space overflow !!!Warning Warning
1439 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1440 (let (fancy-splash-outer-buffer)
1441 (fancy-splash-head)
1442 (dolist (text fancy-splash-text)
1443 (apply #'fancy-splash-insert text)
1444 (insert "\n"))
1445 (skip-chars-backward "\n")
1446 (delete-region (point) (point-max))
1447 (insert "\n")
1448 (fancy-splash-tail)
1449 (use-local-map splash-screen-keymap)
1450 (setq tab-width 22)
1451 (set-buffer-modified-p nil)
1452 (setq buffer-read-only t)
1453 (if (and view-read-only (not view-mode))
1454 (view-mode-enter nil 'kill-buffer))
1455 (goto-char (point-min)))))
1456
1457 (defun fancy-splash-frame ()
1458 "Return the frame to use for the fancy splash screen.
1459 Returning non-nil does not mean we should necessarily
1460 use the fancy splash screen, but if we do use it,
1461 we put it on this frame."
1462 (let (chosen-frame)
1463 (dolist (frame (append (frame-list) (list (selected-frame))))
1464 (if (and (frame-visible-p frame)
1465 (not (window-minibuffer-p (frame-selected-window frame))))
1466 (setq chosen-frame frame)))
1467 chosen-frame))
1468
1469 (defun use-fancy-splash-screens-p ()
1470 "Return t if fancy splash screens should be used."
1471 (when (and (display-graphic-p)
1472 (or (and (display-color-p)
1473 (image-type-available-p 'xpm))
1474 (image-type-available-p 'pbm)))
1475 (let ((frame (fancy-splash-frame)))
1476 (when frame
1477 (let* ((img (create-image (or fancy-splash-image
1478 (if (and (display-color-p)
1479 (image-type-available-p 'xpm))
1480 "splash.xpm" "splash.pbm"))))
1481 (image-height (and img (cdr (image-size img nil frame))))
1482 ;; We test frame-height so that, if the frame is split
1483 ;; by displaying a warning, that doesn't cause the normal
1484 ;; splash screen to be used.
1485 (frame-height (1- (frame-height frame))))
1486 (> frame-height (+ image-height 19)))))))
1487
1488
1489 (defun normal-splash-screen (&optional static)
1490 "Display splash screen when Emacs starts."
1491 (let ((prev-buffer (current-buffer)))
1492 (unwind-protect
1493 (with-current-buffer (get-buffer-create "*About GNU Emacs*")
1494 (setq buffer-read-only nil)
1495 (erase-buffer)
1496 (set (make-local-variable 'tab-width) 8)
1497 (if (not static)
1498 (set (make-local-variable 'mode-line-format)
1499 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1500
1501 (if pure-space-overflow
1502 (insert "\
1503 Warning Warning!!! Pure space overflow !!!Warning Warning
1504 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1505
1506 ;; The convention for this piece of code is that
1507 ;; each piece of output starts with one or two newlines
1508 ;; and does not end with any newlines.
1509 (insert "Welcome to GNU Emacs")
1510 (insert
1511 (if (eq system-type 'gnu/linux)
1512 ", one component of the GNU/Linux operating system.\n"
1513 ", a part of the GNU operating system.\n"))
1514
1515 (if (not static)
1516 (insert (substitute-command-keys
1517 (concat
1518 "\nType \\[recenter] to quit from this screen.\n"))))
1519
1520 (if (display-mouse-p)
1521 ;; The user can use the mouse to activate menus
1522 ;; so give help in terms of menu items.
1523 (progn
1524 (insert "\
1525 You can do basic editing with the menu bar and scroll bar using the mouse.
1526 To quit a partially entered command, type Control-g.\n")
1527
1528 (insert "\nImportant Help menu items:\n")
1529 (insert-button "Emacs Tutorial"
1530 'action (lambda (button) (help-with-tutorial))
1531 'follow-link t)
1532 (insert "\t\tLearn how to use Emacs efficiently\n")
1533 (insert-button "Emacs FAQ"
1534 'action (lambda (button) (view-emacs-FAQ))
1535 'follow-link t)
1536 (insert "\t\tFrequently asked questions and answers\n")
1537 (insert-button "Read the Emacs Manual"
1538 'action (lambda (button) (info-emacs-manual))
1539 'follow-link t)
1540 (insert "\tView the Emacs manual using Info\n")
1541 (insert-button "\(Non)Warranty"
1542 'action (lambda (button) (describe-no-warranty))
1543 'follow-link t)
1544 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1545 (insert-button "Copying Conditions"
1546 'action (lambda (button) (describe-copying))
1547 'follow-link t)
1548 (insert "\tConditions for redistributing and changing Emacs\n")
1549 (insert-button "Getting New Versions"
1550 'action (lambda (button) (describe-distribution))
1551 'follow-link t)
1552 (insert "\tHow to obtain the latest version of Emacs\n")
1553 (insert-button "More Manuals / Ordering Manuals"
1554 'action (lambda (button) (view-order-manuals))
1555 'follow-link t)
1556 (insert " How to order printed manuals from the FSF\n")
1557
1558 (insert "\nUseful tasks:\n")
1559 (insert-button "Visit New File"
1560 'action (lambda (button) (call-interactively 'find-file))
1561 'follow-link t)
1562 (insert "\t\tSpecify a new file's name, to edit the file\n")
1563 (insert-button "Open Home Directory"
1564 'action (lambda (button) (dired "~"))
1565 'follow-link t)
1566 (insert "\tOpen your home directory, to operate on its files\n")
1567 (insert-button "Open *scratch* buffer"
1568 'action (lambda (button) (switch-to-buffer
1569 (get-buffer-create "*scratch*")))
1570 'follow-link t)
1571 (insert "\tOpen buffer for notes you don't want to save\n")
1572 (insert-button "Customize Startup"
1573 'action (lambda (button) (customize-group 'initialization))
1574 'follow-link t)
1575 (insert "\tChange initialization settings including this screen\n")
1576
1577 (insert "\n" (emacs-version)
1578 "\n" emacs-copyright))
1579
1580 ;; No mouse menus, so give help using kbd commands.
1581
1582 ;; If keys have their default meanings,
1583 ;; use precomputed string to save lots of time.
1584 (if (and (eq (key-binding "\C-h") 'help-command)
1585 (eq (key-binding "\C-xu") 'advertised-undo)
1586 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1587 (eq (key-binding "\C-ht") 'help-with-tutorial)
1588 (eq (key-binding "\C-hi") 'info)
1589 (eq (key-binding "\C-hr") 'info-emacs-manual)
1590 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1591 (progn
1592 (insert "
1593 Get help C-h (Hold down CTRL and press h)
1594 ")
1595 (insert-button "Emacs manual"
1596 'action (lambda (button) (info-emacs-manual))
1597 'follow-link t)
1598 (insert " C-h r\t")
1599 (insert-button "Browse manuals"
1600 'action (lambda (button) (Info-directory))
1601 'follow-link t)
1602 (insert "\t C-h i
1603 ")
1604 (insert-button "Emacs tutorial"
1605 'action (lambda (button) (help-with-tutorial))
1606 'follow-link t)
1607 (insert " C-h t\tUndo changes\t C-x u
1608 ")
1609 (insert-button "Buy manuals"
1610 'action (lambda (button) (view-order-manuals))
1611 'follow-link t)
1612 (insert "\t C-h C-m\tExit Emacs\t C-x C-c"))
1613
1614 (insert (format "
1615 Get help %s
1616 "
1617 (let ((where (where-is-internal
1618 'help-command nil t)))
1619 (if where
1620 (key-description where)
1621 "M-x help"))))
1622 (insert-button "Emacs manual"
1623 'action (lambda (button) (info-emacs-manual))
1624 'follow-link t)
1625 (insert (substitute-command-keys" \\[info-emacs-manual]\t"))
1626 (insert-button "Browse manuals"
1627 'action (lambda (button) (Info-directory))
1628 'follow-link t)
1629 (insert (substitute-command-keys "\t \\[info]
1630 "))
1631 (insert-button "Emacs tutorial"
1632 'action (lambda (button) (help-with-tutorial))
1633 'follow-link t)
1634 (insert (substitute-command-keys
1635 " \\[help-with-tutorial]\tUndo changes\t \\[advertised-undo]
1636 "))
1637 (insert-button "Buy manuals"
1638 'action (lambda (button) (view-order-manuals))
1639 'follow-link t)
1640 (insert (substitute-command-keys
1641 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-emacs]")))
1642
1643 ;; Say how to use the menu bar with the keyboard.
1644 (insert "\n")
1645 (insert-button "Activate menubar"
1646 'action (lambda (button) (tmm-menubar))
1647 'follow-link t)
1648 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1649 (eq (key-binding [f10]) 'tmm-menubar))
1650 (insert " F10 or ESC ` or M-`")
1651 (insert (substitute-command-keys " \\[tmm-menubar]")))
1652
1653 ;; Many users seem to have problems with these.
1654 (insert "
1655 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1656 If you have no Meta key, you may instead type ESC followed by the character.)")
1657
1658 ;; Insert links to useful tasks
1659 (insert "\nUseful tasks:\n")
1660
1661 (insert-button "Visit New File"
1662 'action (lambda (button) (call-interactively 'find-file))
1663 'follow-link t)
1664 (insert "\t\t\t")
1665 (insert-button "Open Home Directory"
1666 'action (lambda (button) (dired "~"))
1667 'follow-link t)
1668 (insert "\n")
1669
1670 (insert-button "Customize Startup"
1671 'action (lambda (button) (customize-group 'initialization))
1672 'follow-link t)
1673 (insert "\t\t")
1674 (insert-button "Open *scratch* buffer"
1675 'action (lambda (button) (switch-to-buffer
1676 (get-buffer-create "*scratch*")))
1677 'follow-link t)
1678 (insert "\n")
1679
1680 (insert "\n" (emacs-version)
1681 "\n" emacs-copyright)
1682
1683 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1684 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1685 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1686 (progn
1687 (insert
1688 "\n
1689 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1690 (insert-button "full details"
1691 'action (lambda (button) (describe-no-warranty))
1692 'follow-link t)
1693 (insert ".
1694 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1695 of Emacs and modify it; type C-h C-c to see ")
1696 (insert-button "the conditions"
1697 'action (lambda (button) (describe-copying))
1698 'follow-link t)
1699 (insert ".
1700 Type C-h C-d for information on ")
1701 (insert-button "getting the latest version"
1702 'action (lambda (button) (describe-distribution))
1703 'follow-link t)
1704 (insert "."))
1705 (insert (substitute-command-keys
1706 "\n
1707 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1708 (insert-button "full details"
1709 'action (lambda (button) (describe-no-warranty))
1710 'follow-link t)
1711 (insert (substitute-command-keys ".
1712 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1713 of Emacs and modify it; type \\[describe-copying] to see "))
1714 (insert-button "the conditions"
1715 'action (lambda (button) (describe-copying))
1716 'follow-link t)
1717 (insert (substitute-command-keys".
1718 Type \\[describe-distribution] for information on "))
1719 (insert-button "getting the latest version"
1720 'action (lambda (button) (describe-distribution))
1721 'follow-link t)
1722 (insert ".")))
1723
1724 ;; The rest of the startup screen is the same on all
1725 ;; kinds of terminals.
1726
1727 ;; Give information on recovering, if there was a crash.
1728 (and auto-save-list-file-prefix
1729 ;; Don't signal an error if the
1730 ;; directory for auto-save-list files
1731 ;; does not yet exist.
1732 (file-directory-p (file-name-directory
1733 auto-save-list-file-prefix))
1734 (directory-files
1735 (file-name-directory auto-save-list-file-prefix)
1736 nil
1737 (concat "\\`"
1738 (regexp-quote (file-name-nondirectory
1739 auto-save-list-file-prefix)))
1740 t)
1741 (insert "\n\nIf an Emacs session crashed recently, "
1742 "type Meta-x recover-session RET\nto recover"
1743 " the files you were editing.\n"))
1744
1745 (use-local-map splash-screen-keymap)
1746
1747 ;; Display the input that we set up in the buffer.
1748 (set-buffer-modified-p nil)
1749 (setq buffer-read-only t)
1750 (if (and view-read-only (not view-mode))
1751 (view-mode-enter nil 'kill-buffer))
1752 (goto-char (point-min))
1753 (if (not static)
1754 (if (or (window-minibuffer-p)
1755 (window-dedicated-p (selected-window)))
1756 ;; If static is nil, creating a new frame will
1757 ;; generate enough events that the subsequent `sit-for'
1758 ;; will immediately return anyway.
1759 nil ;; (pop-to-buffer (current-buffer))
1760 (save-window-excursion
1761 (switch-to-buffer (current-buffer))
1762 (sit-for 120)))
1763 (condition-case nil
1764 (switch-to-buffer (current-buffer))
1765 ;; In case the window is dedicated or something.
1766 (error (pop-to-buffer (current-buffer))))))
1767 ;; Unwind ... ensure splash buffer is killed
1768 (if (not static)
1769 (kill-buffer "*About GNU Emacs*")
1770 (switch-to-buffer "*About GNU Emacs*")
1771 (rename-buffer "*GNU Emacs*" t)))))
1772
1773
1774 (defun startup-echo-area-message ()
1775 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1776 "For information about the GNU system and GNU/Linux, type C-h C-p."
1777 (substitute-command-keys
1778 "For information about the GNU system and GNU/Linux, type \
1779 \\[describe-project].")))
1780
1781
1782 (defun display-startup-echo-area-message ()
1783 (let ((resize-mini-windows t))
1784 (message "%s" (startup-echo-area-message))))
1785
1786
1787 (defun display-splash-screen (&optional static)
1788 "Display splash screen according to display.
1789 Fancy splash screens are used on graphic displays,
1790 normal otherwise.
1791 With a prefix argument, any user input hides the splash screen."
1792 (interactive "P")
1793 (if (use-fancy-splash-screens-p)
1794 (fancy-splash-screens static)
1795 (normal-splash-screen static)))
1796
1797 (defalias 'about-emacs 'display-splash-screen)
1798
1799 (defun command-line-1 (command-line-args-left)
1800 (or noninteractive (input-pending-p) init-file-had-error
1801 ;; t if the init file says to inhibit the echo area startup message.
1802 (and inhibit-startup-echo-area-message
1803 user-init-file
1804 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1805 (equal inhibit-startup-echo-area-message
1806 (if (equal init-file-user "")
1807 (user-login-name)
1808 init-file-user)))
1809 ;; Wasn't set with custom; see if .emacs has a setq.
1810 (let ((buffer (get-buffer-create " *temp*")))
1811 (prog1
1812 (condition-case nil
1813 (save-excursion
1814 (set-buffer buffer)
1815 (insert-file-contents user-init-file)
1816 (re-search-forward
1817 (concat
1818 "([ \t\n]*setq[ \t\n]+"
1819 "inhibit-startup-echo-area-message[ \t\n]+"
1820 (regexp-quote
1821 (prin1-to-string
1822 (if (equal init-file-user "")
1823 (user-login-name)
1824 init-file-user)))
1825 "[ \t\n]*)")
1826 nil t))
1827 (error nil))
1828 (kill-buffer buffer)))))
1829 ;; display-splash-screen at the end of command-line-1 calls
1830 ;; use-fancy-splash-screens-p. This can cause image.el to be
1831 ;; loaded, putting "Loading image... done" in the echo area.
1832 ;; This hides startup-echo-area-message. So
1833 ;; use-fancy-splash-screens-p is called here simply to get the
1834 ;; loading of image.el (if needed) out of the way before
1835 ;; display-startup-echo-area-message runs.
1836 (progn
1837 (use-fancy-splash-screens-p)
1838 (display-startup-echo-area-message)))
1839
1840 ;; Delay 2 seconds after an init file error message
1841 ;; was displayed, so user can read it.
1842 (when init-file-had-error
1843 (sit-for 2))
1844
1845 (when (and pure-space-overflow
1846 (not noninteractive))
1847 (display-warning
1848 'initialization
1849 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1850 :warning))
1851
1852 (when command-line-args-left
1853 ;; We have command args; process them.
1854 (let ((dir command-line-default-directory)
1855 (file-count 0)
1856 first-file-buffer
1857 tem
1858 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1859 ;; if foo is intended to be found in DIR.
1860 ;;
1861 ;; ;; The directories listed in --directory/-L options will *appear*
1862 ;; ;; at the front of `load-path' in the order they appear on the
1863 ;; ;; command-line. We cannot do this by *placing* them at the front
1864 ;; ;; in the order they appear, so we need this variable to hold them,
1865 ;; ;; temporarily.
1866 ;; extra-load-path
1867 ;;
1868 ;; To DTRT we keep track of the splice point and modify `load-path'
1869 ;; straight away upon any --directory/-L option.
1870 splice
1871 just-files ;; t if this follows the magic -- option.
1872 ;; This includes our standard options' long versions
1873 ;; and long versions of what's on command-switch-alist.
1874 (longopts
1875 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1876 ("--directory") ("--eval") ("--execute") ("--no-splash")
1877 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1878 (mapcar (lambda (elt)
1879 (list (concat "-" (car elt))))
1880 command-switch-alist)))
1881 (line 0)
1882 (column 0))
1883
1884 ;; Add the long X options to longopts.
1885 (dolist (tem command-line-x-option-alist)
1886 (if (string-match "^--" (car tem))
1887 (push (list (car tem)) longopts)))
1888
1889 ;; Loop, processing options.
1890 (while command-line-args-left
1891 (let* ((argi (car command-line-args-left))
1892 (orig-argi argi)
1893 argval completion)
1894 (setq command-line-args-left (cdr command-line-args-left))
1895
1896 ;; Do preliminary decoding of the option.
1897 (if just-files
1898 ;; After --, don't look for options; treat all args as files.
1899 (setq argi "")
1900 ;; Convert long options to ordinary options
1901 ;; and separate out an attached option argument into argval.
1902 (when (string-match "^\\(--[^=]*\\)=" argi)
1903 (setq argval (substring argi (match-end 0))
1904 argi (match-string 1 argi)))
1905 (if (equal argi "--")
1906 (setq completion nil)
1907 (setq completion (try-completion argi longopts)))
1908 (if (eq completion t)
1909 (setq argi (substring argi 1))
1910 (if (stringp completion)
1911 (let ((elt (assoc completion longopts)))
1912 (or elt
1913 (error "Option `%s' is ambiguous" argi))
1914 (setq argi (substring (car elt) 1)))
1915 (setq argval nil
1916 argi orig-argi))))
1917
1918 ;; Execute the option.
1919 (cond ((setq tem (assoc argi command-switch-alist))
1920 (if argval
1921 (let ((command-line-args-left
1922 (cons argval command-line-args-left)))
1923 (funcall (cdr tem) argi))
1924 (funcall (cdr tem) argi)))
1925
1926 ((equal argi "-no-splash")
1927 (setq inhibit-startup-message t))
1928
1929 ((member argi '("-f" ; what the manual claims
1930 "-funcall"
1931 "-e")) ; what the source used to say
1932 (setq tem (intern (or argval (pop command-line-args-left))))
1933 (if (commandp tem)
1934 (command-execute tem)
1935 (funcall tem)))
1936
1937 ((member argi '("-eval" "-execute"))
1938 (eval (read (or argval (pop command-line-args-left)))))
1939
1940 ((member argi '("-L" "-directory"))
1941 (setq tem (expand-file-name
1942 (command-line-normalize-file-name
1943 (or argval (pop command-line-args-left)))))
1944 (cond (splice (setcdr splice (cons tem (cdr splice)))
1945 (setq splice (cdr splice)))
1946 (t (setq load-path (cons tem load-path)
1947 splice load-path))))
1948
1949 ((member argi '("-l" "-load"))
1950 (let* ((file (command-line-normalize-file-name
1951 (or argval (pop command-line-args-left))))
1952 ;; Take file from default dir if it exists there;
1953 ;; otherwise let `load' search for it.
1954 (file-ex (expand-file-name file)))
1955 (when (file-exists-p file-ex)
1956 (setq file file-ex))
1957 (load file nil t)))
1958
1959 ;; This is used to handle -script. It's not clear
1960 ;; we need to document it.
1961 ((member argi '("-scriptload"))
1962 (let* ((file (command-line-normalize-file-name
1963 (or argval (pop command-line-args-left))))
1964 ;; Take file from default dir.
1965 (file-ex (expand-file-name file)))
1966 (load file-ex nil t t)))
1967
1968 ((equal argi "-insert")
1969 (setq tem (or argval (pop command-line-args-left)))
1970 (or (stringp tem)
1971 (error "File name omitted from `-insert' option"))
1972 (insert-file-contents (command-line-normalize-file-name tem)))
1973
1974 ((equal argi "-kill")
1975 (kill-emacs t))
1976
1977 ;; This is for when they use --no-desktop with -q, or
1978 ;; don't load Desktop in their .emacs. If desktop.el
1979 ;; _is_ loaded, it will handle this switch, and we
1980 ;; won't see it by the time we get here.
1981 ((equal argi "-no-desktop")
1982 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
1983
1984 ((string-match "^\\+[0-9]+\\'" argi)
1985 (setq line (string-to-number argi)))
1986
1987 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1988 (setq line (string-to-number (match-string 1 argi))
1989 column (string-to-number (match-string 2 argi))))
1990
1991 ((setq tem (assoc argi command-line-x-option-alist))
1992 ;; Ignore X-windows options and their args if not using X.
1993 (setq command-line-args-left
1994 (nthcdr (nth 1 tem) command-line-args-left)))
1995
1996 ((member argi '("-find-file" "-file" "-visit"))
1997 ;; An explicit option to specify visiting a file.
1998 (setq tem (or argval (pop command-line-args-left)))
1999 (unless (stringp tem)
2000 (error "File name omitted from `%s' option" argi))
2001 (setq file-count (1+ file-count))
2002 (let ((file (expand-file-name
2003 (command-line-normalize-file-name tem) dir)))
2004 (if (= file-count 1)
2005 (setq first-file-buffer (find-file file))
2006 (find-file-other-window file)))
2007 (or (zerop line)
2008 (goto-line line))
2009 (setq line 0)
2010 (unless (< column 1)
2011 (move-to-column (1- column)))
2012 (setq column 0))
2013
2014 ((equal argi "--")
2015 (setq just-files t))
2016 (t
2017 ;; We have almost exhausted our options. See if the
2018 ;; user has made any other command-line options available
2019 (let ((hooks command-line-functions) ;; lrs 7/31/89
2020 (did-hook nil))
2021 (while (and hooks
2022 (not (setq did-hook (funcall (car hooks)))))
2023 (setq hooks (cdr hooks)))
2024 (if (not did-hook)
2025 ;; Presume that the argument is a file name.
2026 (progn
2027 (if (string-match "\\`-" argi)
2028 (error "Unknown option `%s'" argi))
2029 (setq file-count (1+ file-count))
2030 (let ((file
2031 (expand-file-name
2032 (command-line-normalize-file-name orig-argi)
2033 dir)))
2034 (if (= file-count 1)
2035 (setq first-file-buffer (find-file file))
2036 (find-file-other-window file)))
2037 (or (zerop line)
2038 (goto-line line))
2039 (setq line 0)
2040 (unless (< column 1)
2041 (move-to-column (1- column)))
2042 (setq column 0))))))
2043 ;; In unusual circumstances, the execution of Lisp code due
2044 ;; to command-line options can cause the last visible frame
2045 ;; to be deleted. In this case, kill emacs to avoid an
2046 ;; abort later.
2047 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))
2048
2049 ;; If 3 or more files visited, and not all visible,
2050 ;; show user what they all are. But leave the last one current.
2051 (and (> file-count 2)
2052 (not noninteractive)
2053 (not inhibit-startup-buffer-menu)
2054 (or (get-buffer-window first-file-buffer)
2055 (list-buffers)))))
2056
2057 (when initial-buffer-choice
2058 (cond ((eq initial-buffer-choice t)
2059 (switch-to-buffer (get-buffer-create "*scratch*")))
2060 ((stringp initial-buffer-choice)
2061 (find-file initial-buffer-choice))))
2062
2063 ;; Maybe display a startup screen.
2064 (unless (or inhibit-startup-message
2065 initial-buffer-choice
2066 noninteractive
2067 emacs-quick-startup)
2068 ;; Display a startup screen, after some preparations.
2069
2070 ;; If there are no switches to process, we might as well
2071 ;; run this hook now, and there may be some need to do it
2072 ;; before doing any output.
2073 (run-hooks 'emacs-startup-hook)
2074 (and term-setup-hook
2075 (run-hooks 'term-setup-hook))
2076 (setq inhibit-startup-hooks t)
2077
2078 ;; It's important to notice the user settings before we
2079 ;; display the startup message; otherwise, the settings
2080 ;; won't take effect until the user gives the first
2081 ;; keystroke, and that's distracting.
2082 (when (fboundp 'frame-notice-user-settings)
2083 (frame-notice-user-settings))
2084
2085 ;; If there are no switches to process, we might as well
2086 ;; run this hook now, and there may be some need to do it
2087 ;; before doing any output.
2088 (when window-setup-hook
2089 (run-hooks 'window-setup-hook)
2090 ;; Don't let the hook be run twice.
2091 (setq window-setup-hook nil))
2092
2093 ;; Do this now to avoid an annoying delay if the user
2094 ;; clicks the menu bar during the sit-for.
2095 (when (display-popup-menus-p)
2096 (precompute-menubar-bindings))
2097 (with-no-warnings
2098 (setq menubar-bindings-done t))
2099
2100 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2101 (and initial-scratch-message
2102 (get-buffer "*scratch*")
2103 (with-current-buffer "*scratch*"
2104 (when (zerop (buffer-size))
2105 (insert initial-scratch-message)
2106 (set-buffer-modified-p nil))))
2107
2108 ;; If user typed input during all that work,
2109 ;; abort the startup screen. Otherwise, display it now.
2110 (unless (input-pending-p)
2111 (display-splash-screen t))))
2112
2113
2114 (defun command-line-normalize-file-name (file)
2115 "Collapse multiple slashes to one, to handle non-Emacs file names."
2116 (save-match-data
2117 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2118 ;; That is significant on some systems.
2119 ;; However, /// at the beginning is supposed to mean just /, not //.
2120 (if (string-match "^///+" file)
2121 (setq file (replace-match "/" t t file)))
2122 (while (string-match "//+" file 1)
2123 (setq file (replace-match "/" t t file)))
2124 file))
2125
2126 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
2127 ;;; startup.el ends here