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