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