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