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