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