(gnus-local-domain): Reformat the doc-string to refer to function
[bpt/emacs.git] / lisp / startup.el
1 ;;; startup.el --- process Emacs shell arguments
2
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 98, 99, 2000, 2001
4 ;; 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 2, 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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; This file parses the command line and gets Emacs running. Options on
29 ;; the command line are handled in precedence order. The order is the
30 ;; one in the list below; first described means first handled. Options
31 ;; within each category (delimited by a bar) are handled in the order
32 ;; encountered on the command line.
33
34 ;; -------------------------
35 ;; -version Print Emacs version to stderr, then exit
36 ;; --version successfully right away.
37 ;; This option is handled by emacs.c
38 ;; -------------------------
39 ;; -help Print a short usage description and exit
40 ;; --help successfully right away.
41 ;; This option is handled by emacs.c
42 ;; -------------------------
43 ;; -nl Do not use shared memory (for systems that
44 ;; -no-shared-memory support this) for the dumped Emacs data.
45 ;; This option is handled by emacs.c
46 ;;
47 ;; -map For VMS.
48 ;; --map-data This option is handled by emacs.c
49 ;; -------------------------
50 ;; -t FILE Use FILE as the name of the terminal.
51 ;; --terminal FILE Using this implies "-nw" also.
52 ;; This option is handled by emacs.c
53 ;; -------------------------
54 ;; -d DISPNAME Use DISPNAME as the name of the X
55 ;; -display DISPNAME display for the initial frame.
56 ;; --display DISPNAME This option is handled by emacs.c
57 ;; -------------------------
58 ;; -nw Do not use a windows system (but use the
59 ;; --no-window-system terminal instead.)
60 ;; This option is handled by emacs.c
61 ;; -------------------------
62 ;; -batch Execute noninteractively (messages go to stdout,
63 ;; --batch variable noninteractive set to t)
64 ;; This option is handled by emacs.c
65 ;; -------------------------
66 ;; -q Do not load user's init file and do not load
67 ;; -no-init-file "default.el". Regardless of this switch,
68 ;; --no-init-file "site-start" is still loaded.
69 ;; -------------------------
70 ;; -no-site-file Do not load "site-start.el". (This is the ONLY
71 ;; --no-site-file way to prevent loading that file.)
72 ;; -------------------------
73 ;; -u USER Load USER's init file instead of the init
74 ;; -user USER file belonging to the user starting Emacs.
75 ;; --user USER
76 ;; -------------------------
77 ;; -debug-init Don't catch errors in init files; let the
78 ;; --debug-init debugger run.
79 ;; -------------------------
80 ;; -i ICONTYPE Set type of icon using when Emacs is
81 ;; -itype ICONTYPE iconified under X.
82 ;; --icon-type ICONTYPE This option is passed on to term/x-win.el
83 ;;
84 ;; -iconic Start Emacs iconified.
85 ;; --iconic This option is passed on to term/x-win.el
86 ;; -------------------------
87 ;; Various X options for colors/fonts/geometry/title etc.
88 ;; These options are passed on to term/x-win.el which see.
89 ;; -------------------------
90 ;; FILE Visit FILE.
91 ;; -visit FILE
92 ;; --visit FILE
93 ;; -file FILE
94 ;; --file FILE
95 ;;
96 ;; -L DIRNAME Add DIRNAME to load-path
97 ;; -directory DIRNAME
98 ;; --directory DIRNAME
99 ;;
100 ;; -l FILE Load and execute the Emacs lisp code
101 ;; -load FILE in FILE.
102 ;; --load FILE
103 ;;
104 ;; -f FUNC Execute Emacs lisp function FUNC with
105 ;; -funcall FUNC no arguments. The "-e" form is outdated
106 ;; --funcall FUNC and should not be used. (It's a typo
107 ;; -e FUNC promoted to a feature.)
108 ;;
109 ;; -eval FORM Execute Emacs lisp form FORM.
110 ;; --eval FORM
111 ;; -execute EXPR
112 ;; --execute EXPR
113 ;;
114 ;; -insert FILE Insert the contents of FILE into buffer.
115 ;; --insert FILE
116 ;; -------------------------
117 ;; -kill Kill (exit) Emacs right away.
118 ;; --kill
119 ;; -------------------------
120
121 ;;; Code:
122
123 (setq top-level '(normal-top-level))
124
125 (defvar command-line-processed nil
126 "Non-nil once command line has been processed")
127
128 (defgroup initialization nil
129 "Emacs start-up procedure"
130 :group 'internal)
131
132 (defcustom inhibit-startup-message nil
133 "*Non-nil inhibits the initial startup message.
134 This is for use in your personal init file, once you are familiar
135 with the contents of the startup message."
136 :type 'boolean
137 :group 'initialization)
138
139 (defcustom inhibit-startup-echo-area-message nil
140 "*Non-nil inhibits the initial startup echo area message.
141 Setting this variable takes effect
142 only if you do it with the customization buffer
143 or if your `.emacs' file contains a line of this form:
144 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
145 If your `.emacs' file is byte-compiled, use the following form instead:
146 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
147 Thus, someone else using a copy of your `.emacs' file will see
148 the startup message unless he personally acts to inhibit it."
149 :type '(choice (const :tag "Don't inhibit")
150 (string :tag "Enter your user name, to inhibit"))
151 :group 'initialization)
152
153 (defcustom inhibit-default-init nil
154 "*Non-nil inhibits loading the `default' library."
155 :type 'boolean
156 :group 'initialization)
157
158 (defcustom inhibit-startup-buffer-menu nil
159 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
160 :type 'boolean
161 :group 'initialization)
162
163 (defvar command-switch-alist nil
164 "Alist of command-line switches.
165 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
166 HANDLER-FUNCTION receives switch name as sole arg;
167 remaining command-line args are in the variable `command-line-args-left'.")
168
169 (defvar command-line-args-left nil
170 "List of command-line args not yet processed.")
171
172 (defvar command-line-functions nil ;; lrs 7/31/89
173 "List of functions to process unrecognized command-line arguments.
174 Each function should access the dynamically bound variables
175 `argi' (the current argument) and `command-line-args-left' (the remaining
176 arguments). The function should return non-nil only if it recognizes and
177 processes `argi'. If it does so, it may consume successive arguments by
178 altering `command-line-args-left' to remove them.")
179
180 (defvar command-line-default-directory nil
181 "Default directory to use for command line arguments.
182 This is normally copied from `default-directory' when Emacs starts.")
183
184 ;;; This is here, rather than in x-win.el, so that we can ignore these
185 ;;; options when we are not using X.
186 (defconst command-line-x-option-alist
187 '(("-bw" 1 x-handle-numeric-switch border-width)
188 ("-d" 1 x-handle-display)
189 ("-display" 1 x-handle-display)
190 ("-name" 1 x-handle-name-switch)
191 ("-title" 1 x-handle-switch title)
192 ("-T" 1 x-handle-switch title)
193 ("-r" 0 x-handle-switch reverse t)
194 ("-rv" 0 x-handle-switch reverse t)
195 ("-reverse" 0 x-handle-switch reverse t)
196 ("-reverse-video" 0 x-handle-switch reverse t)
197 ("-fn" 1 x-handle-switch font)
198 ("-font" 1 x-handle-switch font)
199 ("-ib" 1 x-handle-numeric-switch internal-border-width)
200 ("-g" 1 x-handle-geometry)
201 ("-lsp" 1 x-handle-numeric-switch line-spacing)
202 ("-geometry" 1 x-handle-geometry)
203 ("-fg" 1 x-handle-switch foreground-color)
204 ("-foreground" 1 x-handle-switch foreground-color)
205 ("-bg" 1 x-handle-switch background-color)
206 ("-background" 1 x-handle-switch background-color)
207 ("-ms" 1 x-handle-switch mouse-color)
208 ("-itype" 0 x-handle-switch icon-type t)
209 ("-i" 0 x-handle-switch icon-type t)
210 ("-iconic" 0 x-handle-iconic)
211 ("-xrm" 1 x-handle-xrm-switch)
212 ("-cr" 1 x-handle-switch cursor-color)
213 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
214 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
215 ("-bd" 1 x-handle-switch)
216 ("--border-width" 1 x-handle-numeric-switch border-width)
217 ("--display" 1 x-handle-display)
218 ("--name" 1 x-handle-name-switch)
219 ("--title" 1 x-handle-switch title)
220 ("--reverse-video" 0 x-handle-switch reverse t)
221 ("--font" 1 x-handle-switch font)
222 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
223 ("--geometry" 1 x-handle-geometry)
224 ("--foreground-color" 1 x-handle-switch foreground-color)
225 ("--background-color" 1 x-handle-switch background-color)
226 ("--mouse-color" 1 x-handle-switch mouse-color)
227 ("--icon-type" 0 x-handle-switch icon-type t)
228 ("--iconic" 0 x-handle-iconic)
229 ("--xrm" 1 x-handle-xrm-switch)
230 ("--cursor-color" 1 x-handle-switch cursor-color)
231 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
232 ("--line-spacing" 1 x-handle-numeric-switch line-spacing)
233 ("--border-color" 1 x-handle-switch border-width))
234 "Alist of X Windows options.
235 Each element has the form
236 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
237 where NAME is the option name string, NUMARGS is the number of arguments
238 that the option accepts, HANDLER is a function to call to handle the option.
239 FRAME-PARAM (optional) is the frame parameter this option specifies,
240 and VALUE is the value which is given to that frame parameter
241 \(most options use the argument for this, so VALUE is not present).")
242
243 (defvar before-init-hook nil
244 "Normal hook run after handling urgent options but before loading init files.")
245
246 (defvar after-init-hook nil
247 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
248 There is no `condition-case' around the running of these functions;
249 therefore, if you set `debug-on-error' non-nil in `.emacs',
250 an error in one of these functions will invoke the debugger.")
251
252 (defvar emacs-startup-hook nil
253 "Normal hook run after loading init files and handling the command line.")
254
255 (defvar term-setup-hook nil
256 "Normal hook run after loading terminal-specific Lisp code.
257 It also follows `emacs-startup-hook'. This hook exists for users to set,
258 so as to override the definitions made by the terminal-specific file.
259 Emacs never sets this variable itself.")
260
261 (defvar keyboard-type nil
262 "The brand of keyboard you are using.
263 This variable is used to define
264 the proper function and keypad keys for use under X. It is used in a
265 fashion analogous to the environment variable TERM.")
266
267 (defvar window-setup-hook nil
268 "Normal hook run to initialize window system display.
269 Emacs runs this hook after processing the command line arguments and loading
270 the user's init file.")
271
272 (defcustom initial-major-mode 'lisp-interaction-mode
273 "Major mode command symbol to use for the initial *scratch* buffer."
274 :type 'function
275 :group 'initialization)
276
277 (defcustom init-file-user nil
278 "Identity of user whose `.emacs' file is or was read.
279 The value is nil if `-q' or `--no-init-file' was specified,
280 meaning do not load any init file.
281
282 Otherwise, the value may be the null string, meaning use the init file
283 for the user that originally logged in, or it may be a
284 string containing a user's name meaning use that person's init file.
285
286 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
287 evaluates to the name of the directory where the `.emacs' file was
288 looked for.
289
290 Setting `init-file-user' does not prevent Emacs from loading
291 `site-start.el'. The only way to do that is to use `--no-site-file'."
292 :type '(choice (const :tag "none" nil) string)
293 :group 'initialization)
294
295 (defcustom site-run-file "site-start"
296 "File containing site-wide run-time initializations.
297 This file is loaded at run-time before `~/.emacs'. It contains inits
298 that need to be in place for the entire site, but which, due to their
299 higher incidence of change, don't make sense to load into emacs'
300 dumped image. Thus, the run-time load order is: 1. file described in
301 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
302
303 Don't use the `site-start.el' file for things some users may not like.
304 Put them in `default.el' instead, so that users can more easily
305 override them. Users can prevent loading `default.el' with the `-q'
306 option or by setting `inhibit-default-init' in their own init files,
307 but inhibiting `site-start.el' requires `--no-site-file', which
308 is less convenient."
309 :type '(choice (const :tag "none" nil) string)
310 :group 'initialization)
311
312 (defcustom mail-host-address nil
313 "*Name of this machine, for purposes of naming users."
314 :type '(choice (const nil) string)
315 :group 'mail)
316
317 (defcustom user-mail-address nil
318 "*Full mailing address of this user.
319 This is initialized based on `mail-host-address',
320 after your init file is read, in case it sets `mail-host-address'."
321 :type 'string
322 :group 'mail)
323
324 (defcustom auto-save-list-file-prefix
325 (cond ((eq system-type 'ms-dos)
326 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
327 "~/_emacs.d/auto-save.list/_s")
328 (t
329 "~/.emacs.d/auto-save-list/.saves-"))
330 "Prefix for generating `auto-save-list-file-name'.
331 This is used after reading your `.emacs' file to initialize
332 `auto-save-list-file-name', by appending Emacs's pid and the system name,
333 if you have not already set `auto-save-list-file-name' yourself.
334 Directories in the prefix will be created if necessary.
335 Set this to nil if you want to prevent `auto-save-list-file-name'
336 from being initialized."
337 :type '(choice (const :tag "Don't record a session's auto save list" nil)
338 string)
339 :group 'auto-save)
340
341 (defvar init-file-debug nil)
342
343 (defvar init-file-had-error nil)
344
345 (defvar normal-top-level-add-subdirs-inode-list nil)
346
347 (defun normal-top-level-add-subdirs-to-load-path ()
348 "Add all subdirectories of current directory to `load-path'.
349 More precisely, this uses only the subdirectories whose names
350 start with letters or digits; it excludes any subdirectory named `RCS'
351 or `CVS', and any subdirectory that contains a file named `.nosearch'."
352 (let (dirs
353 attrs
354 (pending (list default-directory)))
355 ;; This loop does a breadth-first tree walk on DIR's subtree,
356 ;; putting each subdir into DIRS as its contents are examined.
357 (while pending
358 (setq dirs (cons (car pending) dirs))
359 (setq pending (cdr pending))
360 (let* ((this-dir (car dirs))
361 (contents (directory-files this-dir))
362 (default-directory this-dir)
363 (canonicalized (and (eq system-type 'windows-nt)
364 (untranslated-canonical-name this-dir))))
365 ;; The Windows version doesn't report meaningful inode
366 ;; numbers, so use the canonicalized absolute file name of the
367 ;; directory instead.
368 (setq attrs (or canonicalized
369 (nthcdr 10 (file-attributes this-dir))))
370 (unless (member attrs normal-top-level-add-subdirs-inode-list)
371 (setq normal-top-level-add-subdirs-inode-list
372 (cons attrs normal-top-level-add-subdirs-inode-list))
373 (while contents
374 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
375 (unless (member (car contents) '("." ".." "RCS" "CVS" "rcs" "cvs"))
376 (when (and (string-match "\\`[[:alnum:]]" (car contents))
377 ;; Avoid doing a `stat' when it isn't necessary
378 ;; because that can cause trouble when an NFS server
379 ;; is down.
380 (not (string-match "\\.elc?\\'" (car contents)))
381 (file-directory-p (car contents)))
382 (let ((expanded (expand-file-name (car contents))))
383 (unless (file-exists-p (expand-file-name ".nosearch"
384 expanded))
385 (setq pending (nconc pending (list expanded)))))))
386 (setq contents (cdr contents))))))
387 (normal-top-level-add-to-load-path (cdr (nreverse dirs)))))
388
389 ;; This function is called from a subdirs.el file.
390 ;; It assumes that default-directory is the directory
391 ;; in which the subdirs.el file exists,
392 ;; and it adds to load-path the subdirs of that directory
393 ;; as specified in DIRS. Normally the elements of DIRS are relative.
394 (defun normal-top-level-add-to-load-path (dirs)
395 (let ((tail load-path)
396 (thisdir (directory-file-name default-directory)))
397 (while (and tail
398 ;;Don't go all the way to the nil terminator.
399 (cdr tail)
400 (not (equal thisdir (car tail)))
401 (not (and (memq system-type '(ms-dos windows-nt))
402 (equal (downcase thisdir) (downcase (car tail))))))
403 (setq tail (cdr tail)))
404 ;;Splice the new section in.
405 (when tail
406 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
407
408 (defun normal-top-level ()
409 (if command-line-processed
410 (message "Back to top level.")
411 (setq command-line-processed t)
412 ;; Give *Messages* the same default-directory as *scratch*,
413 ;; just to keep things predictable.
414 (let ((dir default-directory))
415 (save-excursion
416 (set-buffer (get-buffer "*Messages*"))
417 (setq default-directory dir)))
418 ;; For root, preserve owner and group when editing files.
419 (if (equal (user-uid) 0)
420 (setq backup-by-copying-when-mismatch t))
421 ;; Look in each dir in load-path for a subdirs.el file.
422 ;; If we find one, load it, which will add the appropriate subdirs
423 ;; of that dir into load-path,
424 ;; Look for a leim-list.el file too. Loading it will register
425 ;; available input methods.
426 (let ((tail load-path)
427 new)
428 (while tail
429 (setq new (cons (car tail) new))
430 (condition-case nil
431 (let ((default-directory (car tail)))
432 (load (expand-file-name "subdirs.el" (car tail)) t t t)))
433 (condition-case nil
434 (let ((default-directory (car tail)))
435 (load (expand-file-name "leim-list.el" (car tail)) t t t)))
436 (setq tail (cdr tail))))
437 (if (not (eq system-type 'vax-vms))
438 (progn
439 ;; If the PWD environment variable isn't accurate, delete it.
440 (let ((pwd (getenv "PWD")))
441 (and (stringp pwd)
442 ;; Use FOO/., so that if FOO is a symlink, file-attributes
443 ;; describes the directory linked to, not FOO itself.
444 (or (equal (file-attributes
445 (concat (file-name-as-directory pwd) "."))
446 (file-attributes
447 (concat (file-name-as-directory default-directory)
448 ".")))
449 (setq process-environment
450 (delete (concat "PWD=" pwd)
451 process-environment)))))))
452 (setq default-directory (abbreviate-file-name default-directory))
453 (let ((menubar-bindings-done nil))
454 (unwind-protect
455 (command-line)
456 ;; Do this again, in case .emacs defined more abbreviations.
457 (setq default-directory (abbreviate-file-name default-directory))
458 ;; Specify the file for recording all the auto save files of this session.
459 ;; This is used by recover-session.
460 (or auto-save-list-file-name
461 (and auto-save-list-file-prefix
462 (setq auto-save-list-file-name
463 ;; Under MS-DOS our PID is almost always reused between
464 ;; Emacs invocations. We need something more unique.
465 (cond ((eq system-type 'ms-dos)
466 ;; We are going to access the auto-save
467 ;; directory, so make sure it exists.
468 (make-directory
469 (file-name-directory auto-save-list-file-prefix)
470 t)
471 (concat
472 (make-temp-name
473 (expand-file-name
474 auto-save-list-file-prefix))
475 "~"))
476 (t
477 (expand-file-name
478 (format "%s%d-%s~"
479 auto-save-list-file-prefix
480 (emacs-pid)
481 (system-name))))))))
482 (run-hooks 'emacs-startup-hook)
483 (and term-setup-hook
484 (run-hooks 'term-setup-hook))
485
486 ;; Don't do this if we failed to create the initial frame,
487 ;; for instance due to a dense colormap.
488 (when (or frame-initial-frame
489 ;; If frame-initial-frame has no meaning, do this anyway.
490 (not (and window-system
491 (not noninteractive)
492 (not (eq window-system 'pc)))))
493 ;; Modify the initial frame based on what .emacs puts into
494 ;; ...-frame-alist.
495 (if (fboundp 'frame-notice-user-settings)
496 (frame-notice-user-settings))
497 (if (fboundp 'frame-set-background-mode)
498 ;; Set the faces for the initial background mode even if
499 ;; frame-notice-user-settings didn't (such as on a tty).
500 ;; frame-set-background-mode is idempotent, so it won't
501 ;; cause any harm if it's already been done.
502 (let ((frame-background-mode frame-background-mode)
503 (frame (selected-frame))
504 term)
505 (when (and (null window-system)
506 ;; Don't override a possibly customized value.
507 (null frame-background-mode)
508 ;; Don't override user specifications.
509 (null (frame-parameter frame 'reverse))
510 (let ((bg (frame-parameter frame 'background-color)))
511 (or (null bg)
512 (member bg '(unspecified "unspecified-bg")))))
513 (setq term (getenv "TERM"))
514 (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
515 term)
516 (setq frame-background-mode 'light)))
517 (frame-set-background-mode (selected-frame)))))
518
519 ;; Now we know the user's default font, so add it to the menu.
520 (if (fboundp 'font-menu-add-default)
521 (font-menu-add-default))
522 (and window-setup-hook
523 (run-hooks 'window-setup-hook))
524 (or menubar-bindings-done
525 (if (display-popup-menus-p)
526 (precompute-menubar-bindings)))))))
527
528 ;; Precompute the keyboard equivalents in the menu bar items.
529 (defun precompute-menubar-bindings ()
530 (let ((submap (lookup-key global-map [menu-bar])))
531 (while submap
532 (and (consp (car submap))
533 (symbolp (car (car submap)))
534 (stringp (car-safe (cdr (car submap))))
535 (keymapp (cdr (cdr (car submap))))
536 (progn
537 (x-popup-menu nil (cdr (cdr (car submap))))
538 (if purify-flag
539 (garbage-collect))))
540 (setq submap (cdr submap))))
541 (setq define-key-rebound-commands t))
542
543 ;; Command-line options supported by tty's:
544 (defconst tty-long-option-alist
545 '(("--name" . "-name")
546 ("--title" . "-T")
547 ("--reverse-video" . "-reverse")
548 ("--foreground-color" . "-fg")
549 ("--background-color" . "-bg")))
550
551 (defconst tool-bar-images-pixel-height 24
552 "Height in pixels of images in the tool bar.")
553
554 (defvar tool-bar-originally-present nil
555 "Non-nil if tool-bars are present before user and site init files are read.")
556
557 ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc.
558 (defun tty-handle-args (args)
559 (let ((rest nil))
560 (message "%s" args)
561 (while (and args
562 (not (equal (car args) "--")))
563 (let* ((this (car args))
564 (orig-this this)
565 completion argval)
566 (setq args (cdr args))
567 ;; Check for long options with attached arguments
568 ;; and separate out the attached option argument into argval.
569 (if (string-match "^--[^=]*=" this)
570 (setq argval (substring this (match-end 0))
571 this (substring this 0 (1- (match-end 0)))))
572 (when (string-match "^--" this)
573 (setq completion (try-completion this tty-long-option-alist))
574 (if (eq completion t)
575 ;; Exact match for long option.
576 (setq this (cdr (assoc this tty-long-option-alist)))
577 (if (stringp completion)
578 (let ((elt (assoc completion tty-long-option-alist)))
579 ;; Check for abbreviated long option.
580 (or elt
581 (error "Option `%s' is ambiguous" this))
582 (setq this (cdr elt)))
583 ;; Check for a short option.
584 (setq argval nil this orig-this))))
585 (cond ((or (string= this "-fg") (string= this "-foreground"))
586 (or argval (setq argval (car args) args (cdr args)))
587 (setq default-frame-alist
588 (cons (cons 'foreground-color argval)
589 default-frame-alist)))
590 ((or (string= this "-bg") (string= this "-background"))
591 (or argval (setq argval (car args) args (cdr args)))
592 (setq default-frame-alist
593 (cons (cons 'background-color argval)
594 default-frame-alist)))
595 ((or (string= this "-T") (string= this "-name"))
596 (or argval (setq argval (car args) args (cdr args)))
597 (setq default-frame-alist
598 (cons
599 (cons 'title
600 (if (stringp argval)
601 argval
602 (let ((case-fold-search t)
603 i)
604 (setq argval (invocation-name))
605
606 ;; Change any . or * characters in name to
607 ;; hyphens, so as to emulate behavior on X.
608 (while
609 (setq i (string-match "[.*]" argval))
610 (aset argval i ?-))
611 argval)))
612 default-frame-alist)))
613 ((or (string= this "-r")
614 (string= this "-rv")
615 (string= this "-reverse"))
616 (setq default-frame-alist
617 (cons '(reverse . t)
618 default-frame-alist)))
619 (t (setq rest (cons this rest))))))
620 (nreverse rest)))
621
622 (defun command-line ()
623 (setq command-line-default-directory default-directory)
624
625 ;; Choose a reasonable location for temporary files.
626 (setq temporary-file-directory
627 (file-name-as-directory
628 (cond ((memq system-type '(ms-dos windows-nt))
629 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
630 ((memq system-type '(vax-vms axp-vms))
631 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
632 (t
633 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))))
634 (setq small-temporary-file-directory
635 (if (eq system-type 'ms-dos)
636 (getenv "TMPDIR")))
637
638 ;; See if we should import version-control from the environment variable.
639 (let ((vc (getenv "VERSION_CONTROL")))
640 (cond ((eq vc nil)) ;don't do anything if not set
641 ((or (string= vc "t")
642 (string= vc "numbered"))
643 (setq version-control t))
644 ((or (string= vc "nil")
645 (string= vc "existing"))
646 (setq version-control nil))
647 ((or (string= vc "never")
648 (string= vc "simple"))
649 (setq version-control 'never))))
650
651 ;;! This has been commented out; I currently find the behavior when
652 ;;! split-window-keep-point is nil disturbing, but if I can get used
653 ;;! to it, then it would be better to eliminate the option.
654 ;;! ;; Choose a good default value for split-window-keep-point.
655 ;;! (setq split-window-keep-point (> baud-rate 2400))
656
657 ;; Set the default strings to display in mode line for
658 ;; end-of-line formats that aren't native to this platform.
659 (cond
660 ((memq system-type '(ms-dos windows-nt emx))
661 (setq eol-mnemonic-unix "(Unix)")
662 (setq eol-mnemonic-mac "(Mac)"))
663 ;; Mac-specific settings should come here, once there's a
664 ;; system-type symbol specific to MacOS.
665 (t ; this is for Unix/GNU/Linux systems
666 (setq eol-mnemonic-dos "(DOS)")
667 (setq eol-mnemonic-mac "(Mac)")))
668
669 ;; Read window system's init file if using a window system.
670 (condition-case error
671 (if (and window-system (not noninteractive))
672 (load (concat term-file-prefix
673 (symbol-name window-system)
674 "-win")
675 ;; Every window system should have a startup file;
676 ;; barf if we can't find it.
677 nil t))
678 ;; If we can't read it, print the error message and exit.
679 (error
680 (princ
681 (if (eq (car error) 'error)
682 (apply 'concat (cdr error))
683 (if (memq 'file-error (get (car error) 'error-conditions))
684 (format "%s: %s"
685 (nth 1 error)
686 (mapconcat (lambda (obj) (prin1-to-string obj t))
687 (cdr (cdr error)) ", "))
688 (format "%s: %s"
689 (get (car error) 'error-message)
690 (mapconcat (lambda (obj) (prin1-to-string obj t))
691 (cdr error) ", "))))
692 'external-debugging-output)
693 (terpri 'external-debugging-output)
694 (setq window-system nil)
695 (kill-emacs)))
696
697 ;; Windowed displays do this inside their *-win.el.
698 (when (and (not (display-graphic-p))
699 (not noninteractive))
700 (setq command-line-args (tty-handle-args command-line-args)))
701
702 (set-locale-environment nil)
703
704 (let ((done nil)
705 (args (cdr command-line-args)))
706
707 ;; Figure out which user's init file to load,
708 ;; either from the environment or from the options.
709 (setq init-file-user (if noninteractive nil (user-login-name)))
710 ;; If user has not done su, use current $HOME to find .emacs.
711 (and init-file-user (string= init-file-user (user-real-login-name))
712 (setq init-file-user ""))
713
714 ;; Process the command-line args, and delete the arguments
715 ;; processed. This is consistent with the way main in emacs.c
716 ;; does things.
717 (while (and (not done) args)
718 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
719 ("--debug-init") ("--iconic") ("--icon-type")))
720 (argi (car args))
721 (argval nil))
722 ;; Handle --OPTION=VALUE format.
723 (if (and (string-match "\\`--" argi)
724 (string-match "=" argi))
725 (setq argval (substring argi (match-end 0))
726 argi (substring argi 0 (match-beginning 0))))
727 (or (equal argi "--")
728 (let ((completion (try-completion argi longopts)))
729 (if (eq completion t)
730 (setq argi (substring argi 1))
731 (if (stringp completion)
732 (let ((elt (assoc completion longopts)))
733 (or elt
734 (error "Option `%s' is ambiguous" argi))
735 (setq argi (substring (car elt) 1)))
736 (setq argval nil)))))
737 (cond
738 ((or (string-equal argi "-q")
739 (string-equal argi "-no-init-file"))
740 (setq init-file-user nil
741 args (cdr args)))
742 ((or (string-equal argi "-u")
743 (string-equal argi "-user"))
744 (or argval
745 (setq args (cdr args)
746 argval (car args)))
747 (setq init-file-user argval
748 argval nil
749 args (cdr args)))
750 ((string-equal argi "-no-site-file")
751 (setq site-run-file nil
752 args (cdr args)))
753 ((string-equal argi "-debug-init")
754 (setq init-file-debug t
755 args (cdr args)))
756 ((string-equal argi "-iconic")
757 (setq initial-frame-alist
758 (cons '(visibility . icon) initial-frame-alist))
759 (setq args (cdr args)))
760 ((or (string-equal argi "-icon-type")
761 (string-equal argi "-i")
762 (string-equal argi "-itype"))
763 (setq default-frame-alist
764 (cons '(icon-type . t) default-frame-alist))
765 (setq args (cdr args)))
766 (t (setq done t)))
767 ;; Was argval set but not used?
768 (and argval
769 (error "Option `%s' doesn't allow an argument" argi))))
770
771 ;; Re-attach the program name to the front of the arg list.
772 (and command-line-args (setcdr command-line-args args)))
773
774 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
775 (when (fboundp 'frame-initialize)
776 (frame-initialize))
777
778 ;; If frame was created with a menu bar, set menu-bar-mode on.
779 (if (and (not noninteractive)
780 (or (not (memq window-system '(x w32)))
781 (> (cdr (assq 'menu-bar-lines (frame-parameters))) 0)))
782 (menu-bar-mode t))
783
784 ;; If frame was created with a tool bar, switch tool-bar-mode on.
785 (when (and (not noninteractive)
786 (display-graphic-p)
787 (> (frame-parameter nil 'tool-bar-lines) 0))
788 (tool-bar-mode 1))
789
790 ;; Can't do this init in defcustom because window-system isn't set.
791 (when (and (not noninteractive)
792 (not (eq system-type 'ms-dos))
793 (memq window-system '(x w32)))
794 (setq-default blink-cursor t)
795 (blink-cursor-mode 1))
796
797 (unless noninteractive
798 ;; DOS/Windows systems have a PC-type keyboard which has both
799 ;; <delete> and <backspace> keys.
800 (when (or (memq system-type '(ms-dos windows-nt))
801 (and (memq window-system '(x))
802 (fboundp 'x-backspace-delete-keys-p)
803 (x-backspace-delete-keys-p))
804 ;; If the terminal Emacs is running on has erase char
805 ;; set to ^H, use the Backspace key for deleting
806 ;; backward and, and the Delete key for deleting forward.
807 (and (null window-system)
808 (eq tty-erase-char 8)))
809 (setq-default normal-erase-is-backspace t)
810 (normal-erase-is-backspace-mode 1)))
811
812 (when (and (not noninteractive)
813 (display-graphic-p)
814 (fboundp 'x-show-tip))
815 (setq-default tooltip-mode t)
816 (tooltip-mode 1))
817
818 ;; Register default TTY colors for the case the terminal hasn't a
819 ;; terminal init file.
820 (or (memq window-system '(x w32))
821 (not (tty-display-color-p))
822 (let* ((colors (cond ((eq window-system 'pc)
823 msdos-color-values)
824 ((eq system-type 'windows-nt)
825 w32-tty-standard-colors)
826 (t tty-standard-colors)))
827 (color (car colors)))
828 (while colors
829 (tty-color-define (car color) (cadr color) (cddr color))
830 (setq colors (cdr colors) color (car colors)))
831 ;; Modifying color mappings means realized faces don't
832 ;; use the right colors, so clear them.
833 (clear-face-cache)))
834
835 ;; Record whether the tool-bar is present before the user and site
836 ;; init files are processed. frame-notice-user-settings uses this
837 ;; to determine if the tool-bar has been disabled by the init files,
838 ;; and the frame needs to be resized.
839 (when (fboundp 'frame-notice-user-settings)
840 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
841 (assq 'tool-bar-lines default-frame-alist))))
842 (setq tool-bar-originally-present
843 (not (or (null tool-bar-lines)
844 (null (cdr tool-bar-lines))
845 (eq 0 (cdr tool-bar-lines)))))))
846
847 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
848 (old-font-list-limit font-list-limit)
849 (old-face-ignored-fonts face-ignored-fonts))
850
851 (run-hooks 'before-init-hook)
852
853 ;; Run the site-start library if it exists. The point of this file is
854 ;; that it is run before .emacs. There is no point in doing this after
855 ;; .emacs; that is useless.
856 (if site-run-file
857 (load site-run-file t t))
858
859 ;; Sites should not disable this. Only individuals should disable
860 ;; the startup message.
861 (setq inhibit-startup-message nil)
862
863 ;; Load that user's init file, or the default one, or none.
864 (let (debug-on-error-from-init-file
865 debug-on-error-should-be-set
866 (debug-on-error-initial
867 (if (eq init-file-debug t) 'startup init-file-debug))
868 (orig-enable-multibyte default-enable-multibyte-characters))
869 (let ((debug-on-error debug-on-error-initial)
870 ;; This function actually reads the init files.
871 (inner
872 (function
873 (lambda ()
874 (if init-file-user
875 (let ((user-init-file-1
876 (cond
877 ((eq system-type 'ms-dos)
878 (concat "~" init-file-user "/_emacs"))
879 ((eq system-type 'windows-nt)
880 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
881 "~/.emacs"
882 "~/_emacs"))
883 ((eq system-type 'vax-vms)
884 "sys$login:.emacs")
885 (t
886 (concat "~" init-file-user "/.emacs")))))
887 ;; This tells `load' to store the file name found
888 ;; into user-init-file.
889 (setq user-init-file t)
890 (load user-init-file-1 t t)
891
892 ;; If we did not find the user's init file,
893 ;; set user-init-file conclusively to nil;
894 ;; don't let it be set from default.el.
895 (if (eq user-init-file t)
896 (setq user-init-file nil))
897
898 ;; If we loaded a compiled file, set
899 ;; `user-init-file' to the source version if that
900 ;; exists.
901 (when (and user-init-file
902 (equal (file-name-extension user-init-file)
903 "elc"))
904 (let* ((source (file-name-sans-extension user-init-file))
905 (alt (concat source ".el")))
906 (setq source (cond ((file-exists-p alt) alt)
907 ((file-exists-p source) source)
908 (t nil)))
909 (when source
910 (when (file-newer-than-file-p source user-init-file)
911 (message "Warning: %s is newer than %s"
912 source user-init-file)
913 (sit-for 1))
914 (setq user-init-file source))))
915
916 (or inhibit-default-init
917 (let ((inhibit-startup-message nil))
918 ;; Users are supposed to be told their rights.
919 ;; (Plus how to get help and how to undo.)
920 ;; Don't you dare turn this off for anyone
921 ;; except yourself.
922 (load "default" t t)))))))))
923 (if init-file-debug
924 ;; Do this without a condition-case if the user wants to debug.
925 (funcall inner)
926 (condition-case error
927 (progn
928 (funcall inner)
929 (setq init-file-had-error nil))
930 (error
931 (let ((message-log-max nil))
932 (save-excursion
933 (set-buffer (get-buffer-create "*Messages*"))
934 (insert "\n\n"
935 (format "An error has occurred while loading `%s':\n\n"
936 user-init-file)
937 (format "%s%s%s"
938 (get (car error) 'error-message)
939 (if (cdr error) ": " "")
940 (mapconcat 'prin1-to-string (cdr error) ", "))
941 "\n\n"
942 "To ensure normal operation, you should investigate the cause\n"
943 "of the error in your initialization file and remove it. Start\n"
944 "Emacs with the `--debug-init' option to view a complete error\n"
945 "backtrace\n"))
946 (message "Error in init file: %s%s%s"
947 (get (car error) 'error-message)
948 (if (cdr error) ": " "")
949 (mapconcat 'prin1-to-string (cdr error) ", "))
950 (pop-to-buffer "*Messages*")
951 (setq init-file-had-error t)))))
952 ;; If we can tell that the init file altered debug-on-error,
953 ;; arrange to preserve the value that it set up.
954 (or (eq debug-on-error debug-on-error-initial)
955 (setq debug-on-error-should-be-set t
956 debug-on-error-from-init-file debug-on-error)))
957 (if debug-on-error-should-be-set
958 (setq debug-on-error debug-on-error-from-init-file))
959 (unless (or default-enable-multibyte-characters
960 (eq orig-enable-multibyte default-enable-multibyte-characters))
961 ;; Init file changed to unibyte. Reset existing multibyte
962 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
963 ;; Arguably this should only be done if they're free of
964 ;; multibyte characters.
965 (mapcar (lambda (buffer)
966 (with-current-buffer buffer
967 (if enable-multibyte-characters
968 (set-buffer-multibyte nil))))
969 (buffer-list))
970 ;; Also re-set the language environment in case it was
971 ;; originally done before unibyte was set and is sensitive to
972 ;; unibyte (display table, terminal coding system &c).
973 (set-language-environment current-language-environment)))
974
975 ;; Do this here in case the init file sets mail-host-address.
976 (or user-mail-address
977 (setq user-mail-address (concat (user-login-name) "@"
978 (or mail-host-address
979 (system-name)))))
980
981 ;; If parameter have been changed in the init file which influence
982 ;; face realization, clear the face cache so that new faces will
983 ;; be realized.
984 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
985 (eq font-list-limit old-font-list-limit)
986 (eq face-ignored-fonts old-face-ignored-fonts))
987 (clear-face-cache)))
988
989 (run-hooks 'after-init-hook)
990
991 ;; If *scratch* exists and init file didn't change its mode, initialize it.
992 (if (get-buffer "*scratch*")
993 (save-excursion
994 (set-buffer "*scratch*")
995 (if (eq major-mode 'fundamental-mode)
996 (funcall initial-major-mode))))
997
998 ;; Load library for our terminal type.
999 ;; User init file can set term-file-prefix to nil to prevent this.
1000 (and term-file-prefix (not noninteractive) (not window-system)
1001 (let ((term (getenv "TERM"))
1002 hyphend)
1003 (while (and term
1004 (not (load (concat term-file-prefix term) t t)))
1005 ;; Strip off last hyphen and what follows, then try again
1006 (if (setq hyphend (string-match "[-_][^-_]+$" term))
1007 (setq term (substring term 0 hyphend))
1008 (setq term nil)))))
1009
1010 ;; Process the remaining args.
1011 (command-line-1 (cdr command-line-args))
1012
1013 ;; If -batch, terminate after processing the command options.
1014 (if noninteractive (kill-emacs t)))
1015
1016 (defcustom initial-scratch-message (purecopy "\
1017 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1018 ;; If you want to create a file, visit that file with C-x C-f,
1019 ;; then enter the text in that file's own buffer.
1020
1021 ")
1022 "Initial message displayed in *scratch* buffer at startup.
1023 If this is nil, no message will be displayed."
1024 :type 'string)
1025
1026 \f
1027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1028 ;;; Fancy splash screen
1029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1030
1031 (defvar fancy-splash-text
1032 '((:face variable-pitch
1033 "You can do basic editing with the menu bar and scroll bar \
1034 using the mouse.\n\n"
1035 :face (variable-pitch :weight bold)
1036 "Important Help menu items:\n"
1037 :face variable-pitch "\
1038 Emacs Tutorial\tLearn-by-doing tutorial for using Emacs efficiently
1039 Emacs FAQ\tFrequently asked questions and answers
1040 \(Non)Warranty\tGNU Emacs comes with "
1041 :face (variable-pitch :slant oblique)
1042 "ABSOLUTELY NO WARRANTY\n"
1043 :face variable-pitch
1044 "\
1045 Copying Conditions\tConditions for redistributing and changing Emacs
1046 Ordering Manuals\tHow to order Emacs manuals from the Free Software Foundation\n")
1047 (:face variable-pitch
1048 "You can do basic editing with the menu bar and scroll bar \
1049 using the mouse.\n\n"
1050 :face (variable-pitch :weight bold)
1051 "Useful File menu items:\n"
1052 :face variable-pitch "\
1053 Exit Emacs\t(Or type Control-x followed by Control-c)
1054 Recover Session\tRecover files you were editing before a crash
1055
1056
1057
1058 "
1059 ))
1060 "A list of texts to show in the middle part of splash screens.
1061 Each element in the list should be a list of strings or pairs
1062 `:face FACE', like `fancy-splash-insert' accepts them.")
1063
1064
1065 (defgroup fancy-splash-screen ()
1066 "Fancy splash screen when Emacs starts."
1067 :version "21.1"
1068 :group 'initialization)
1069
1070
1071 (defcustom fancy-splash-delay 10
1072 "*Delay in seconds between splash screens."
1073 :group 'fancy-splash-screen
1074 :type 'integer)
1075
1076
1077 (defcustom fancy-splash-max-time 60
1078 "*Show splash screens for at most this number of seconds.
1079 Values less than 60 seconds are ignored."
1080 :group 'fancy-splash-screen
1081 :type 'integer)
1082
1083
1084 (defcustom fancy-splash-image nil
1085 "*The image to show in the splash screens, or nil for defaults."
1086 :group 'fancy-splash-screen
1087 :type '(choice (const :tag "Default" nil)
1088 (file :tag "File")))
1089
1090
1091 ;; These are temporary storage areas for the splash screen display.
1092
1093 (defvar fancy-current-text nil)
1094 (defvar fancy-splash-help-echo nil)
1095 (defvar fancy-splash-stop-time nil)
1096
1097
1098 (defun fancy-splash-insert (&rest args)
1099 "Insert text into the current buffer, with faces.
1100 Arguments from ARGS should be either strings or pairs `:face FACE',
1101 where FACE is a valid face specification, as it can be used with
1102 `put-text-properties'."
1103 (let ((current-face nil))
1104 (while args
1105 (if (eq (car args) :face)
1106 (setq args (cdr args) current-face (car args))
1107 (insert (propertize (car args)
1108 'face current-face
1109 'help-echo fancy-splash-help-echo)))
1110 (setq args (cdr args)))))
1111
1112
1113 (defun fancy-splash-head ()
1114 "Insert the head part of the splash screen into the current buffer."
1115 (let* ((image-file (cond ((stringp fancy-splash-image)
1116 fancy-splash-image)
1117 ((and (display-color-p)
1118 (image-type-available-p 'xpm))
1119 (if (and (fboundp 'x-display-planes)
1120 (= (funcall 'x-display-planes) 8))
1121 "splash8.xpm"
1122 "splash.xpm"))
1123 (t "splash.pbm")))
1124 (img (create-image image-file))
1125 (image-width (and img (car (image-size img))))
1126 (window-width (window-width (selected-window))))
1127 (when img
1128 (when (> window-width image-width)
1129 ;; Center the image in the window.
1130 (let ((pos (/ (- window-width image-width) 2)))
1131 (insert (propertize " " 'display `(space :align-to ,pos))))
1132
1133 ;; Change the color of the XPM version of the splash image
1134 ;; so that it is visible with a dark frame background.
1135 (when (and (memq 'xpm img)
1136 (eq (frame-parameter nil 'background-mode) 'dark))
1137 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1138
1139 ;; Insert the image with a help-echo and a keymap.
1140 (let ((map (make-sparse-keymap))
1141 (help-echo "mouse-2: browse http://www.gnu.org/"))
1142 (define-key map [mouse-2]
1143 (lambda ()
1144 (interactive)
1145 (browse-url "http://www.gnu.org/")
1146 (throw 'exit nil)))
1147 (define-key map [down-mouse-2] 'ignore)
1148 (define-key map [up-mouse-2] 'ignore)
1149 (insert-image img (propertize "xxx" 'help-echo help-echo
1150 'keymap map)))
1151 (insert "\n"))))
1152 (if (eq system-type 'gnu/linux)
1153 (fancy-splash-insert
1154 :face '(variable-pitch :foreground "red")
1155 "GNU Emacs is one component of a Linux-based GNU system.")
1156 (fancy-splash-insert
1157 :face '(variable-pitch :foreground "red")
1158 "GNU Emacs is one component of the GNU operating system."))
1159 (insert "\n"))
1160
1161
1162 (defun fancy-splash-tail ()
1163 "Insert the tail part of the splash screen into the current buffer."
1164 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1165 "cyan" "darkblue")))
1166 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1167 "\nThis is "
1168 (emacs-version)
1169 "\n"
1170 :face '(variable-pitch :height 0.5)
1171 "Copyright (C) 2001 Free Software Foundation, Inc.")
1172 (and auto-save-list-file-prefix
1173 ;; Don't signal an error if the
1174 ;; directory for auto-save-list files
1175 ;; does not yet exist.
1176 (file-directory-p (file-name-directory
1177 auto-save-list-file-prefix))
1178 (directory-files
1179 (file-name-directory auto-save-list-file-prefix)
1180 nil
1181 (concat "\\`"
1182 (regexp-quote (file-name-nondirectory
1183 auto-save-list-file-prefix)))
1184 t)
1185 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1186 "\n\nIf an Emacs session crashed recently, "
1187 "type M-x recover-session RET\nto recover"
1188 " the files you were editing."))))
1189
1190 (defun fancy-splash-screens-1 (buffer)
1191 "Timer function displaying a splash screen."
1192 (when (> (float-time) fancy-splash-stop-time)
1193 (throw 'stop-splashing nil))
1194 (unless fancy-current-text
1195 (setq fancy-current-text fancy-splash-text))
1196 (let ((text (car fancy-current-text)))
1197 (set-buffer buffer)
1198 (erase-buffer)
1199 (fancy-splash-head)
1200 (apply #'fancy-splash-insert text)
1201 (fancy-splash-tail)
1202 (unless (current-message)
1203 (message fancy-splash-help-echo))
1204 (set-buffer-modified-p nil)
1205 (goto-char (point-min))
1206 (force-mode-line-update)
1207 (setq fancy-current-text (cdr fancy-current-text))))
1208
1209
1210 (defun fancy-splash-default-action ()
1211 "Default action for events in the splash screen buffer."
1212 (interactive)
1213 (push last-command-event unread-command-events)
1214 (throw 'exit nil))
1215
1216
1217 (defun fancy-splash-screens ()
1218 "Display fancy splash screens when Emacs starts."
1219 (setq fancy-splash-help-echo (startup-echo-area-message))
1220 (switch-to-buffer "GNU Emacs")
1221 (setq tab-width 20)
1222 (let ((old-hourglass display-hourglass)
1223 (splash-buffer (current-buffer))
1224 (old-minor-mode-map-alist minor-mode-map-alist)
1225 timer)
1226 (catch 'stop-splashing
1227 (unwind-protect
1228 (let ((map (make-sparse-keymap)))
1229 (use-local-map map)
1230 (define-key map [t] 'fancy-splash-default-action)
1231 (define-key map [mouse-movement] 'ignore)
1232 (define-key map [mode-line t] 'ignore)
1233 (setq cursor-type nil
1234 display-hourglass nil
1235 minor-mode-map-alist nil
1236 buffer-undo-list t
1237 mode-line-format (propertize "---- %b %-"
1238 'face '(:weight bold))
1239 fancy-splash-stop-time (+ (float-time)
1240 (max 60 fancy-splash-max-time))
1241 timer (run-with-timer 0 fancy-splash-delay
1242 #'fancy-splash-screens-1
1243 splash-buffer))
1244 (recursive-edit))
1245 (cancel-timer timer)
1246 (setq display-hourglass old-hourglass
1247 minor-mode-map-alist old-minor-mode-map-alist)
1248 (kill-buffer splash-buffer)))))
1249
1250
1251 (defun use-fancy-splash-screens-p ()
1252 "Return t if fancy splash screens should be used."
1253 (when (or (and (display-color-p)
1254 (image-type-available-p 'xpm))
1255 (image-type-available-p 'pbm))
1256 (let* ((img (create-image (or fancy-splash-image
1257 (if (and (display-color-p)
1258 (image-type-available-p 'xpm))
1259 "splash.xpm" "splash.pbm"))))
1260 (image-height (and img (cdr (image-size img))))
1261 (window-height (1- (window-height (selected-window)))))
1262 (> window-height (+ image-height 15)))))
1263
1264
1265 (defun startup-echo-area-message ()
1266 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1267 "For information about the GNU Project and its goals, type C-h C-p."
1268 (substitute-command-keys
1269 "For information about the GNU Project and its goals, type \
1270 \\[describe-project].")))
1271
1272
1273 (defun display-startup-echo-area-message ()
1274 (let ((resize-mini-windows t))
1275 (message (startup-echo-area-message))))
1276
1277
1278 (defun command-line-1 (command-line-args-left)
1279 (or noninteractive (input-pending-p) init-file-had-error
1280 ;; t if the init file says to inhibit the echo area startup message.
1281 (and inhibit-startup-echo-area-message
1282 user-init-file
1283 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1284 (equal inhibit-startup-echo-area-message
1285 (if (string= init-file-user "")
1286 (user-login-name)
1287 init-file-user)))
1288 ;; Wasn't set with custom; see if .emacs has a setq.
1289 (let ((buffer (get-buffer-create " *temp*")))
1290 (prog1
1291 (condition-case nil
1292 (save-excursion
1293 (set-buffer buffer)
1294 (insert-file-contents user-init-file)
1295 (re-search-forward
1296 (concat
1297 "([ \t\n]*setq[ \t\n]+"
1298 "inhibit-startup-echo-area-message[ \t\n]+"
1299 (regexp-quote
1300 (prin1-to-string
1301 (if (string= init-file-user "")
1302 (user-login-name)
1303 init-file-user)))
1304 "[ \t\n]*)")
1305 nil t))
1306 (error nil))
1307 (kill-buffer buffer)))))
1308 (display-startup-echo-area-message))
1309
1310 ;; Delay 2 seconds after an init file error message
1311 ;; was displayed, so user can read it.
1312 (if init-file-had-error
1313 (sit-for 2))
1314
1315 (if command-line-args-left
1316 ;; We have command args; process them.
1317 (let ((dir command-line-default-directory)
1318 (file-count 0)
1319 first-file-buffer
1320 tem
1321 just-files ;; t if this follows the magic -- option.
1322 ;; This includes our standard options' long versions
1323 ;; and long versions of what's on command-switch-alist.
1324 (longopts
1325 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1326 ("--directory") ("--eval") ("--execute")
1327 ("--find-file") ("--visit") ("--file"))
1328 (mapcar (lambda (elt)
1329 (list (concat "-" (car elt))))
1330 command-switch-alist)))
1331 (line 0)
1332 (column 0))
1333
1334 ;; Add the long X options to longopts.
1335 (setq tem command-line-x-option-alist)
1336 (while tem
1337 (if (string-match "^--" (car (car tem)))
1338 (setq longopts (cons (list (car (car tem))) longopts)))
1339 (setq tem (cdr tem)))
1340
1341 ;; Loop, processing options.
1342 (while (and command-line-args-left)
1343 (let* ((argi (car command-line-args-left))
1344 (orig-argi argi)
1345 argval completion
1346 ;; List of directories specified in -L/--directory,
1347 ;; in reverse of the order specified.
1348 extra-load-path
1349 (initial-load-path load-path))
1350 (setq command-line-args-left (cdr command-line-args-left))
1351
1352 ;; Do preliminary decoding of the option.
1353 (if just-files
1354 ;; After --, don't look for options; treat all args as files.
1355 (setq argi "")
1356 ;; Convert long options to ordinary options
1357 ;; and separate out an attached option argument into argval.
1358 (if (string-match "^--[^=]*=" argi)
1359 (setq argval (substring argi (match-end 0))
1360 argi (substring argi 0 (1- (match-end 0)))))
1361 (if (equal argi "--")
1362 (setq completion nil)
1363 (setq completion (try-completion argi longopts)))
1364 (if (eq completion t)
1365 (setq argi (substring argi 1))
1366 (if (stringp completion)
1367 (let ((elt (assoc completion longopts)))
1368 (or elt
1369 (error "Option `%s' is ambiguous" argi))
1370 (setq argi (substring (car elt) 1)))
1371 (setq argval nil argi orig-argi))))
1372
1373 ;; Execute the option.
1374 (cond ((setq tem (assoc argi command-switch-alist))
1375 (if argval
1376 (let ((command-line-args-left
1377 (cons argval command-line-args-left)))
1378 (funcall (cdr tem) argi))
1379 (funcall (cdr tem) argi)))
1380
1381 ((or (string-equal argi "-f") ;what the manual claims
1382 (string-equal argi "-funcall")
1383 (string-equal argi "-e")) ; what the source used to say
1384 (if argval
1385 (setq tem (intern argval))
1386 (setq tem (intern (car command-line-args-left)))
1387 (setq command-line-args-left (cdr command-line-args-left)))
1388 (if (arrayp (symbol-function tem))
1389 (command-execute tem)
1390 (funcall tem)))
1391
1392 ((or (string-equal argi "-eval")
1393 (string-equal argi "-execute"))
1394 (if argval
1395 (setq tem argval)
1396 (setq tem (car command-line-args-left))
1397 (setq command-line-args-left (cdr command-line-args-left)))
1398 (eval (read tem)))
1399 ;; Set the default directory as specified in -L.
1400
1401 ((or (string-equal argi "-L")
1402 (string-equal argi "-directory"))
1403 (if argval
1404 (setq tem argval)
1405 (setq tem (car command-line-args-left)
1406 command-line-args-left (cdr command-line-args-left)))
1407 (setq tem (command-line-normalize-file-name tem))
1408 (setq extra-load-path
1409 (cons (expand-file-name tem) extra-load-path))
1410 (setq load-path (append (nreverse extra-load-path)
1411 initial-load-path)))
1412
1413 ((or (string-equal argi "-l")
1414 (string-equal argi "-load"))
1415 (if argval
1416 (setq tem argval)
1417 (setq tem (car command-line-args-left)
1418 command-line-args-left (cdr command-line-args-left)))
1419 (let ((file (command-line-normalize-file-name tem)))
1420 ;; Take file from default dir if it exists there;
1421 ;; otherwise let `load' search for it.
1422 (if (file-exists-p (expand-file-name file))
1423 (setq file (expand-file-name file)))
1424 (load file nil t)))
1425
1426 ((string-equal argi "-insert")
1427 (if argval
1428 (setq tem argval)
1429 (setq tem (car command-line-args-left)
1430 command-line-args-left (cdr command-line-args-left)))
1431 (or (stringp tem)
1432 (error "File name omitted from `-insert' option"))
1433 (insert-file-contents (command-line-normalize-file-name tem)))
1434
1435 ((string-equal argi "-kill")
1436 (kill-emacs t))
1437
1438 ((string-match "^\\+[0-9]+\\'" argi)
1439 (setq line (string-to-int argi)))
1440
1441 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1442 (setq line (string-to-int (match-string 1 argi))
1443 column (string-to-int (match-string 2 argi))))
1444
1445 ((setq tem (assoc argi command-line-x-option-alist))
1446 ;; Ignore X-windows options and their args if not using X.
1447 (setq command-line-args-left
1448 (nthcdr (nth 1 tem) command-line-args-left)))
1449
1450 ((or (string-equal argi "-find-file")
1451 (string-equal argi "-file")
1452 (string-equal argi "-visit"))
1453 ;; An explicit option to specify visiting a file.
1454 (if argval
1455 (setq tem argval)
1456 (setq tem (car command-line-args-left)
1457 command-line-args-left (cdr command-line-args-left)))
1458 (unless (stringp tem)
1459 (error "File name omitted from `%s' option" argi))
1460 (setq file-count (1+ file-count))
1461 (let ((file (expand-file-name
1462 (command-line-normalize-file-name tem) dir)))
1463 (if (= file-count 1)
1464 (setq first-file-buffer (find-file file))
1465 (find-file-other-window file)))
1466 (or (zerop line)
1467 (goto-line line))
1468 (setq line 0)
1469 (unless (< column 1)
1470 (move-to-column (1- column)))
1471 (setq column 0))
1472
1473 ((equal argi "--")
1474 (setq just-files t))
1475 (t
1476 ;; We have almost exhausted our options. See if the
1477 ;; user has made any other command-line options available
1478 (let ((hooks command-line-functions) ;; lrs 7/31/89
1479 (did-hook nil))
1480 (while (and hooks
1481 (not (setq did-hook (funcall (car hooks)))))
1482 (setq hooks (cdr hooks)))
1483 (if (not did-hook)
1484 ;; Ok, presume that the argument is a file name
1485 (progn
1486 (if (string-match "\\`-" argi)
1487 (error "Unknown option `%s'" argi))
1488 (setq file-count (1+ file-count))
1489 (let ((file
1490 (expand-file-name
1491 (command-line-normalize-file-name orig-argi)
1492 dir)))
1493 (if (= file-count 1)
1494 (setq first-file-buffer (find-file file))
1495 (find-file-other-window file)))
1496 (or (zerop line)
1497 (goto-line line))
1498 (setq line 0)
1499 (unless (< column 1)
1500 (move-to-column (1- column)))
1501 (setq column 0))))))))
1502 ;; If 3 or more files visited, and not all visible,
1503 ;; show user what they all are. But leave the last one current.
1504 (and (> file-count 2)
1505 (not noninteractive)
1506 (not inhibit-startup-buffer-menu)
1507 (or (get-buffer-window first-file-buffer)
1508 (list-buffers))))
1509
1510 ;; No command args: maybe display a startup screen.
1511 (when (and (not inhibit-startup-message) (not noninteractive)
1512 ;; Don't display startup screen if init file
1513 ;; has selected another buffer.
1514 (string= (buffer-name) "*scratch*")
1515 ;; Don't display startup screen if init file
1516 ;; has inserted some text in *scratch*.
1517 (= 0 (buffer-size)))
1518 ;; Display a startup screen, after some preparations.
1519
1520 ;; If there are no switches to process, we might as well
1521 ;; run this hook now, and there may be some need to do it
1522 ;; before doing any output.
1523 (and term-setup-hook
1524 (run-hooks 'term-setup-hook))
1525 ;; Don't let the hook be run twice.
1526 (setq term-setup-hook nil)
1527
1528 ;; It's important to notice the user settings before we
1529 ;; display the startup message; otherwise, the settings
1530 ;; won't take effect until the user gives the first
1531 ;; keystroke, and that's distracting.
1532 (when (fboundp 'frame-notice-user-settings)
1533 (frame-notice-user-settings))
1534
1535 ;; If there are no switches to process, we might as well
1536 ;; run this hook now, and there may be some need to do it
1537 ;; before doing any output.
1538 (when window-setup-hook
1539 (run-hooks 'window-setup-hook)
1540 ;; Don't let the hook be run twice.
1541 (setq window-setup-hook nil))
1542
1543 ;; Do this now to avoid an annoying delay if the user
1544 ;; clicks the menu bar during the sit-for.
1545 (when (display-popup-menus-p)
1546 (precompute-menubar-bindings))
1547 (setq menubar-bindings-done t)
1548
1549 (when initial-scratch-message
1550 (insert initial-scratch-message))
1551 (set-buffer-modified-p nil)
1552
1553 ;; If user typed input during all that work,
1554 ;; abort the startup screen. Otherwise, display it now.
1555 (when (not (input-pending-p))
1556 (with-temp-buffer
1557 (if (and (display-graphic-p)
1558 (use-fancy-splash-screens-p))
1559 (fancy-splash-screens)
1560 (let ((tab-width 8))
1561 ;; The convention for this piece of code is that
1562 ;; each piece of output starts with one or two newlines
1563 ;; and does not end with any newlines.
1564 (insert "Welcome to GNU Emacs")
1565 (if (eq system-type 'gnu/linux)
1566 (insert ", one component of a Linux-based GNU system."))
1567 (insert "\n")
1568
1569 (if (display-mouse-p)
1570 ;; The user can use the mouse to activate menus
1571 ;; so give help in terms of menu items.
1572 (progn
1573 (insert "\
1574 You can do basic editing with the menu bar and scroll bar using the mouse.
1575
1576 Useful File menu items:
1577 Exit Emacs (or type Control-x followed by Control-c)
1578 Recover Session recover files you were editing before a crash
1579
1580 Important Help menu items:
1581 Emacs Tutorial Learn-by-doing tutorial for using Emacs efficiently.
1582 Emacs FAQ Frequently asked questions and answers
1583 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1584 Copying Conditions Conditions for redistributing and changing Emacs.
1585 Getting New Versions How to obtain the latest version of Emacs.
1586 Ordering Manuals How to order manuals from the FSF.
1587 ")
1588 (insert "\n\n" (emacs-version)
1589 "
1590 Copyright (C) 2001 Free Software Foundation, Inc."))
1591
1592 ;; No mouse menus, so give help using kbd commands.
1593
1594 ;; If keys have their default meanings,
1595 ;; use precomputed string to save lots of time.
1596 (if (and (eq (key-binding "\C-h") 'help-command)
1597 (eq (key-binding "\C-xu") 'advertised-undo)
1598 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1599 (eq (key-binding "\C-ht") 'help-with-tutorial)
1600 (eq (key-binding "\C-hi") 'info)
1601 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1602 (insert "
1603 Get help C-h (Hold down CTRL and press h)
1604 Undo changes C-x u Exit Emacs C-x C-c
1605 Get a tutorial C-h t Use Info to read docs C-h i
1606 Ordering manuals C-h RET")
1607 (insert (substitute-command-keys
1608 (format "\n
1609 Get help %s
1610 Undo changes \\[advertised-undo]
1611 Exit Emacs \\[save-buffers-kill-emacs]
1612 Get a tutorial \\[help-with-tutorial]
1613 Use Info to read docs \\[info]
1614 Ordering manuals \\[view-order-manuals]"
1615 (let ((where (where-is-internal
1616 'help-command nil t)))
1617 (if where
1618 (key-description where)
1619 "M-x help"))))))
1620
1621 ;; Say how to use the menu bar with the keyboard.
1622 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1623 (eq (key-binding [f10]) 'tmm-menubar))
1624 (insert "
1625 Activate menubar F10 or ESC ` or M-`")
1626 (insert (substitute-command-keys "
1627 Activate menubar \\[tmm-menubar]")))
1628
1629 ;; Many users seem to have problems with these.
1630 (insert "
1631 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1632 If you have no Meta key, you may instead type ESC followed by the character.)")
1633
1634 (insert "\n\n" (emacs-version)
1635 "
1636 Copyright (C) 2001 Free Software Foundation, Inc.")
1637
1638 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1639 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1640 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1641 (insert
1642 "\n
1643 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1644 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1645 of Emacs and modify it; type C-h C-c to see the conditions.
1646 Type C-h C-d for information on getting the latest version.")
1647 (insert (substitute-command-keys
1648 "\n
1649 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1650 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1651 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1652 Type \\[describe-distribution] for information on getting the latest version."))))
1653
1654 ;; The rest of the startup screen is the same on all
1655 ;; kinds of terminals.
1656
1657 ;; Give information on recovering, if there was a crash.
1658 (and auto-save-list-file-prefix
1659 ;; Don't signal an error if the
1660 ;; directory for auto-save-list files
1661 ;; does not yet exist.
1662 (file-directory-p (file-name-directory
1663 auto-save-list-file-prefix))
1664 (directory-files
1665 (file-name-directory auto-save-list-file-prefix)
1666 nil
1667 (concat "\\`"
1668 (regexp-quote (file-name-nondirectory
1669 auto-save-list-file-prefix)))
1670 t)
1671 (insert "\n\nIf an Emacs session crashed recently, "
1672 "type M-x recover-session RET\nto recover"
1673 " the files you were editing."))
1674
1675 ;; Display the input that we set up in the buffer.
1676 (set-buffer-modified-p nil)
1677 (goto-char (point-min))
1678 (save-window-excursion
1679 (switch-to-buffer (current-buffer))
1680 (sit-for 120)))))))))
1681
1682
1683 (defun command-line-normalize-file-name (file)
1684 "Collapse multiple slashes to one, to handle non-Emacs file names."
1685 (save-match-data
1686 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1687 ;; That is significant on some systems.
1688 ;; However, /// at the beginning is supposed to mean just /, not //.
1689 (if (string-match "^///+" file)
1690 (setq file (replace-match "/" t t file)))
1691 (while (string-match "//+" file 1)
1692 (setq file (replace-match "/" t t file)))
1693 file))
1694
1695 ;;; startup.el ends here