Merge from emacs--devo--0
[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 (custom-reevaluate-setting 'global-auto-composition-mode)
783
784 ;; Register default TTY colors for the case the terminal hasn't a
785 ;; terminal init file.
786 (unless (memq window-system '(x w32 mac))
787 ;; We do this regardles of whether the terminal supports colors
788 ;; or not, since they can switch that support on or off in
789 ;; mid-session by setting the tty-color-mode frame parameter.
790 (tty-register-default-colors))
791
792 ;; Record whether the tool-bar is present before the user and site
793 ;; init files are processed. frame-notice-user-settings uses this
794 ;; to determine if the tool-bar has been disabled by the init files,
795 ;; and the frame needs to be resized.
796 (when (fboundp 'frame-notice-user-settings)
797 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
798 (assq 'tool-bar-lines default-frame-alist))))
799 (setq tool-bar-originally-present
800 (and tool-bar-lines
801 (cdr tool-bar-lines)
802 (not (eq 0 (cdr tool-bar-lines)))))))
803
804 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
805 (old-font-list-limit font-list-limit)
806 (old-face-ignored-fonts face-ignored-fonts))
807
808 ;; Run the site-start library if it exists. The point of this file is
809 ;; that it is run before .emacs. There is no point in doing this after
810 ;; .emacs; that is useless.
811 (if site-run-file
812 (load site-run-file t t))
813
814 ;; Sites should not disable this. Only individuals should disable
815 ;; the startup message.
816 (setq inhibit-startup-message nil)
817
818 ;; Warn for invalid user name.
819 (when init-file-user
820 (if (string-match "[~/:\n]" init-file-user)
821 (display-warning 'initialization
822 (format "Invalid user name %s"
823 init-file-user)
824 :error)
825 (if (file-directory-p (expand-file-name
826 ;; We don't support ~USER on MS-Windows except
827 ;; for the current user, and always load .emacs
828 ;; from the current user's home directory (see
829 ;; below). So always check "~", even if invoked
830 ;; with "-u USER", or if $USER or $LOGNAME are
831 ;; set to something different.
832 (if (eq system-type 'windows-nt)
833 "~"
834 (concat "~" init-file-user))))
835 nil
836 (display-warning 'initialization
837 (format "User %s has no home directory"
838 init-file-user)
839 :error))))
840
841 ;; Load that user's init file, or the default one, or none.
842 (let (debug-on-error-from-init-file
843 debug-on-error-should-be-set
844 (debug-on-error-initial
845 (if (eq init-file-debug t) 'startup init-file-debug))
846 (orig-enable-multibyte default-enable-multibyte-characters))
847 (let ((debug-on-error debug-on-error-initial)
848 ;; This function actually reads the init files.
849 (inner
850 (function
851 (lambda ()
852 (if init-file-user
853 (let ((user-init-file-1
854 (cond
855 ((eq system-type 'ms-dos)
856 (concat "~" init-file-user "/_emacs"))
857 ((eq system-type 'windows-nt)
858 ;; Prefer .emacs on Windows.
859 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
860 "~/.emacs"
861 ;; Also support _emacs for compatibility.
862 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
863 "~/_emacs"
864 ;; But default to .emacs if _emacs does not exist.
865 "~/.emacs")))
866 ((eq system-type 'vax-vms)
867 "sys$login:.emacs")
868 (t
869 (concat "~" init-file-user "/.emacs")))))
870 ;; This tells `load' to store the file name found
871 ;; into user-init-file.
872 (setq user-init-file t)
873 (load user-init-file-1 t t)
874
875 (when (eq user-init-file t)
876 ;; If we did not find ~/.emacs, try
877 ;; ~/.emacs.d/init.el.
878 (let ((otherfile
879 (expand-file-name
880 "init"
881 (file-name-as-directory
882 (concat "~" init-file-user "/.emacs.d")))))
883 (load otherfile t t)
884
885 ;; If we did not find the user's init file,
886 ;; set user-init-file conclusively.
887 ;; Don't let it be set from default.el.
888 (when (eq user-init-file t)
889 (setq user-init-file user-init-file-1))))
890
891 ;; If we loaded a compiled file, set
892 ;; `user-init-file' to the source version if that
893 ;; exists.
894 (when (and user-init-file
895 (equal (file-name-extension user-init-file)
896 "elc"))
897 (let* ((source (file-name-sans-extension user-init-file))
898 (alt (concat source ".el")))
899 (setq source (cond ((file-exists-p alt) alt)
900 ((file-exists-p source) source)
901 (t nil)))
902 (when source
903 (when (file-newer-than-file-p source user-init-file)
904 (message "Warning: %s is newer than %s"
905 source user-init-file)
906 (sit-for 1))
907 (setq user-init-file source))))
908
909 (unless inhibit-default-init
910 (let ((inhibit-startup-message nil))
911 ;; Users are supposed to be told their rights.
912 ;; (Plus how to get help and how to undo.)
913 ;; Don't you dare turn this off for anyone
914 ;; except yourself.
915 (load "default" t t)))))))))
916 (if init-file-debug
917 ;; Do this without a condition-case if the user wants to debug.
918 (funcall inner)
919 (condition-case error
920 (progn
921 (funcall inner)
922 (setq init-file-had-error nil))
923 (error
924 (let ((message-log-max nil))
925 (save-excursion
926 (set-buffer (get-buffer-create "*Messages*"))
927 (insert "\n\n"
928 (format "An error has occurred while loading `%s':\n\n"
929 user-init-file)
930 (format "%s%s%s"
931 (get (car error) 'error-message)
932 (if (cdr error) ": " "")
933 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
934 "\n\n"
935 "To ensure normal operation, you should investigate and remove the\n"
936 "cause of the error in your initialization file. Start Emacs with\n"
937 "the `--debug-init' option to view a complete error backtrace.\n\n"))
938 (message "Error in init file: %s%s%s"
939 (get (car error) 'error-message)
940 (if (cdr error) ": " "")
941 (mapconcat 'prin1-to-string (cdr error) ", "))
942 (let ((pop-up-windows nil))
943 (pop-to-buffer "*Messages*"))
944 (setq init-file-had-error t)))))
945
946 (if (and deactivate-mark transient-mark-mode)
947 (with-current-buffer (window-buffer)
948 (deactivate-mark)))
949
950 ;; If the user has a file of abbrevs, read it.
951 (if (file-exists-p abbrev-file-name)
952 (quietly-read-abbrev-file abbrev-file-name))
953
954 ;; If the abbrevs came entirely from the init file or the
955 ;; abbrevs file, they do not need saving.
956 (setq abbrevs-changed nil)
957
958 ;; If we can tell that the init file altered debug-on-error,
959 ;; arrange to preserve the value that it set up.
960 (or (eq debug-on-error debug-on-error-initial)
961 (setq debug-on-error-should-be-set t
962 debug-on-error-from-init-file debug-on-error)))
963 (if debug-on-error-should-be-set
964 (setq debug-on-error debug-on-error-from-init-file))
965 (unless (or default-enable-multibyte-characters
966 (eq orig-enable-multibyte default-enable-multibyte-characters))
967 ;; Init file changed to unibyte. Reset existing multibyte
968 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
969 ;; Arguably this should only be done if they're free of
970 ;; multibyte characters.
971 (mapcar (lambda (buffer)
972 (with-current-buffer buffer
973 (if enable-multibyte-characters
974 (set-buffer-multibyte nil))))
975 (buffer-list))
976 ;; Also re-set the language environment in case it was
977 ;; originally done before unibyte was set and is sensitive to
978 ;; unibyte (display table, terminal coding system &c).
979 (set-language-environment current-language-environment)))
980
981 ;; Do this here in case the init file sets mail-host-address.
982 (if (equal user-mail-address "")
983 (setq user-mail-address (or (getenv "EMAIL")
984 (concat (user-login-name) "@"
985 (or mail-host-address
986 (system-name))))))
987
988 ;; Originally face attributes were specified via
989 ;; `font-lock-face-attributes'. Users then changed the default
990 ;; face attributes by setting that variable. However, we try and
991 ;; be back-compatible and respect its value if set except for
992 ;; faces where M-x customize has been used to save changes for the
993 ;; face.
994 (when (boundp 'font-lock-face-attributes)
995 (let ((face-attributes font-lock-face-attributes))
996 (while face-attributes
997 (let* ((face-attribute (pop face-attributes))
998 (face (car face-attribute)))
999 ;; Rustle up a `defface' SPEC from a
1000 ;; `font-lock-face-attributes' entry.
1001 (unless (get face 'saved-face)
1002 (let ((foreground (nth 1 face-attribute))
1003 (background (nth 2 face-attribute))
1004 (bold-p (nth 3 face-attribute))
1005 (italic-p (nth 4 face-attribute))
1006 (underline-p (nth 5 face-attribute))
1007 face-spec)
1008 (when foreground
1009 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1010 (when background
1011 (setq face-spec (cons ':background (cons background face-spec))))
1012 (when bold-p
1013 (setq face-spec (append '(:weight bold) face-spec)))
1014 (when italic-p
1015 (setq face-spec (append '(:slant italic) face-spec)))
1016 (when underline-p
1017 (setq face-spec (append '(:underline t) face-spec)))
1018 (face-spec-set face (list (list t face-spec)) nil)))))))
1019
1020 ;; If parameter have been changed in the init file which influence
1021 ;; face realization, clear the face cache so that new faces will
1022 ;; be realized.
1023 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1024 (eq font-list-limit old-font-list-limit)
1025 (eq face-ignored-fonts old-face-ignored-fonts))
1026 (clear-face-cache)))
1027
1028 (run-hooks 'after-init-hook)
1029
1030 ;; Decode all default-directory.
1031 (if (and default-enable-multibyte-characters locale-coding-system)
1032 (save-excursion
1033 (dolist (elt (buffer-list))
1034 (set-buffer elt)
1035 (if default-directory
1036 (setq default-directory
1037 (decode-coding-string default-directory
1038 locale-coding-system t))))
1039 (setq command-line-default-directory
1040 (decode-coding-string command-line-default-directory
1041 locale-coding-system t))))
1042
1043 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1044 (if (get-buffer "*scratch*")
1045 (with-current-buffer "*scratch*"
1046 (if (eq major-mode 'fundamental-mode)
1047 (funcall initial-major-mode))))
1048
1049 ;; Load library for our terminal type.
1050 ;; User init file can set term-file-prefix to nil to prevent this.
1051 (unless (or noninteractive
1052 window-system
1053 (null term-file-prefix))
1054 (let* ((TERM (getenv "TERM"))
1055 (term TERM)
1056 hyphend)
1057 (while (and term
1058 (not (load (concat term-file-prefix term) t t)))
1059 ;; Strip off last hyphen and what follows, then try again
1060 (setq term
1061 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
1062 (substring term 0 hyphend)
1063 nil)))
1064 (setq term TERM)
1065 ;; The terminal file has been loaded, now call the terminal specific
1066 ;; initialization function.
1067 (while term
1068 (let ((term-init-func (intern-soft (concat "terminal-init-" term))))
1069 (if (not (fboundp term-init-func))
1070 ;; Strip off last hyphen and what follows, then try again
1071 (setq term
1072 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
1073 (substring term 0 hyphend)
1074 nil))
1075 (setq term nil)
1076 (funcall term-init-func))))))
1077
1078 ;; Update the out-of-memory error message based on user's key bindings
1079 ;; for save-some-buffers.
1080 (setq memory-signal-data
1081 (list 'error
1082 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1083
1084 ;; Process the remaining args.
1085 (command-line-1 (cdr command-line-args))
1086
1087 ;; If -batch, terminate after processing the command options.
1088 (if noninteractive (kill-emacs t))
1089
1090 ;; Run emacs-session-restore (session management) if started by
1091 ;; the session manager and we have a session manager connection.
1092 (if (and (boundp 'x-session-previous-id)
1093 (stringp x-session-previous-id))
1094 (with-no-warnings
1095 (emacs-session-restore x-session-previous-id))))
1096
1097 (defcustom initial-scratch-message (purecopy "\
1098 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1099 ;; If you want to create a file, visit that file with C-x C-f,
1100 ;; then enter the text in that file's own buffer.
1101
1102 ")
1103 "Initial message displayed in *scratch* buffer at startup.
1104 If this is nil, no message will be displayed.
1105 If `inhibit-splash-screen' is non-nil, then no message is displayed,
1106 regardless of the value of this variable."
1107 :type '(choice (text :tag "Message")
1108 (const :tag "none" nil))
1109 :group 'initialization)
1110
1111 \f
1112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1113 ;;; Fancy splash screen
1114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1115
1116 (defvar fancy-splash-text
1117 '((:face (variable-pitch :weight bold)
1118 "Important Help menu items:\n"
1119 :face variable-pitch
1120 (lambda ()
1121 (let* ((en "TUTORIAL")
1122 (tut (or (get-language-info current-language-environment
1123 'tutorial)
1124 en))
1125 (title (with-temp-buffer
1126 (insert-file-contents
1127 (expand-file-name tut data-directory)
1128 nil 0 256)
1129 (search-forward ".")
1130 (buffer-substring (point-min) (1- (point))))))
1131 ;; If there is a specific tutorial for the current language
1132 ;; environment and it is not English, append its title.
1133 (concat
1134 "Emacs Tutorial\tLearn how to use Emacs efficiently"
1135 (if (string= en tut)
1136 ""
1137 (concat " (" title ")"))
1138 "\n")))
1139 :face variable-pitch "\
1140 Emacs FAQ\tFrequently asked questions and answers
1141 View Emacs Manual\tView the Emacs manual using Info
1142 Absence of Warranty\tGNU Emacs comes with "
1143 :face (variable-pitch :slant oblique)
1144 "ABSOLUTELY NO WARRANTY\n"
1145 :face variable-pitch
1146 "\
1147 Copying Conditions\tConditions for redistributing and changing Emacs
1148 Getting New Versions\tHow to obtain the latest version of Emacs
1149 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1150 (:face (variable-pitch :weight bold)
1151 "Useful File menu items:\n"
1152 :face variable-pitch "\
1153 Exit Emacs\t\t(Or type Control-x followed by Control-c)
1154 Recover Crashed Session\tRecover files you were editing before a crash
1155
1156
1157
1158
1159
1160 "
1161 ))
1162 "A list of texts to show in the middle part of splash screens.
1163 Each element in the list should be a list of strings or pairs
1164 `:face FACE', like `fancy-splash-insert' accepts them.")
1165
1166
1167 (defgroup fancy-splash-screen ()
1168 "Fancy splash screen when Emacs starts."
1169 :version "21.1"
1170 :group 'initialization)
1171
1172
1173 (defcustom fancy-splash-delay 7
1174 "*Delay in seconds between splash screens."
1175 :group 'fancy-splash-screen
1176 :type 'integer)
1177
1178
1179 (defcustom fancy-splash-max-time 30
1180 "*Show splash screens for at most this number of seconds.
1181 Values less than twice `fancy-splash-delay' are ignored."
1182 :group 'fancy-splash-screen
1183 :type 'integer)
1184
1185
1186 (defcustom fancy-splash-image nil
1187 "*The image to show in the splash screens, or nil for defaults."
1188 :group 'fancy-splash-screen
1189 :type '(choice (const :tag "Default" nil)
1190 (file :tag "File")))
1191
1192
1193 ;; These are temporary storage areas for the splash screen display.
1194
1195 (defvar fancy-current-text nil)
1196 (defvar fancy-splash-help-echo nil)
1197 (defvar fancy-splash-stop-time nil)
1198 (defvar fancy-splash-outer-buffer nil)
1199
1200 (defun fancy-splash-insert (&rest args)
1201 "Insert text into the current buffer, with faces.
1202 Arguments from ARGS should be either strings, functions called
1203 with no args that return a string, or pairs `:face FACE',
1204 where FACE is a valid face specification, as it can be used with
1205 `put-text-property'."
1206 (let ((current-face nil))
1207 (while args
1208 (if (eq (car args) :face)
1209 (setq args (cdr args) current-face (car args))
1210 (insert (propertize (let ((it (car args)))
1211 (if (functionp it)
1212 (funcall it)
1213 it))
1214 'face current-face
1215 'help-echo fancy-splash-help-echo)))
1216 (setq args (cdr args)))))
1217
1218
1219 (defun fancy-splash-head ()
1220 "Insert the head part of the splash screen into the current buffer."
1221 (let* ((image-file (cond ((stringp fancy-splash-image)
1222 fancy-splash-image)
1223 ((and (display-color-p)
1224 (image-type-available-p 'xpm))
1225 (if (and (fboundp 'x-display-planes)
1226 (= (funcall 'x-display-planes) 8))
1227 "splash8.xpm"
1228 "splash.xpm"))
1229 (t "splash.pbm")))
1230 (img (create-image image-file))
1231 (image-width (and img (car (image-size img))))
1232 (window-width (window-width (selected-window))))
1233 (when img
1234 (when (> window-width image-width)
1235 ;; Center the image in the window.
1236 (insert (propertize " " 'display
1237 `(space :align-to (+ center (-0.5 . ,img)))))
1238
1239 ;; Change the color of the XPM version of the splash image
1240 ;; so that it is visible with a dark frame background.
1241 (when (and (memq 'xpm img)
1242 (eq (frame-parameter nil 'background-mode) 'dark))
1243 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1244
1245 ;; Insert the image with a help-echo and a keymap.
1246 (let ((map (make-sparse-keymap))
1247 (help-echo "mouse-2: browse http://www.gnu.org/"))
1248 (define-key map [mouse-2]
1249 (lambda ()
1250 (interactive)
1251 (browse-url "http://www.gnu.org/")
1252 (throw 'exit nil)))
1253 (define-key map [down-mouse-2] 'ignore)
1254 (define-key map [up-mouse-2] 'ignore)
1255 (insert-image img (propertize "xxx" 'help-echo help-echo
1256 'keymap map)))
1257 (insert "\n"))))
1258 (fancy-splash-insert
1259 :face '(variable-pitch :background "red")
1260 "\n!! This version is ALPHA status. It may lose your data!!\n\n")
1261 (fancy-splash-insert
1262 :face '(variable-pitch :foreground "red")
1263 (if (eq system-type 'gnu/linux)
1264 "GNU Emacs is one component of the GNU/Linux operating system."
1265 "GNU Emacs is one component of the GNU operating system."))
1266 (insert "\n")
1267 (fancy-splash-insert
1268 :face 'variable-pitch
1269 "You can do basic editing with the menu bar and scroll bar \
1270 using the mouse.\n\n")
1271 (if fancy-splash-outer-buffer
1272 (fancy-splash-insert
1273 :face 'variable-pitch
1274 (substitute-command-keys
1275 (concat
1276 "Type \\[recenter] to begin editing"
1277 (if (equal (buffer-name fancy-splash-outer-buffer)
1278 "*scratch*")
1279 ".\n"
1280 " your file.\n"))))))
1281
1282 (defun fancy-splash-tail ()
1283 "Insert the tail part of the splash screen into the current buffer."
1284 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1285 "cyan" "darkblue")))
1286 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1287 "\nThis is "
1288 (emacs-version)
1289 "\n"
1290 :face '(variable-pitch :height 0.5)
1291 "Copyright (C) 2006 Free Software Foundation, Inc.")
1292 (and auto-save-list-file-prefix
1293 ;; Don't signal an error if the
1294 ;; directory for auto-save-list files
1295 ;; does not yet exist.
1296 (file-directory-p (file-name-directory
1297 auto-save-list-file-prefix))
1298 (directory-files
1299 (file-name-directory auto-save-list-file-prefix)
1300 nil
1301 (concat "\\`"
1302 (regexp-quote (file-name-nondirectory
1303 auto-save-list-file-prefix)))
1304 t)
1305 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1306 "\n\nIf an Emacs session crashed recently, "
1307 "type Meta-x recover-session RET\nto recover"
1308 " the files you were editing."))))
1309
1310 (defun fancy-splash-screens-1 (buffer)
1311 "Timer function displaying a splash screen."
1312 (when (> (float-time) fancy-splash-stop-time)
1313 (throw 'stop-splashing nil))
1314 (unless fancy-current-text
1315 (setq fancy-current-text fancy-splash-text))
1316 (let ((text (car fancy-current-text)))
1317 (set-buffer buffer)
1318 (erase-buffer)
1319 (if pure-space-overflow
1320 (insert "\
1321 Warning Warning!!! Pure space overflow !!!Warning Warning
1322 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1323 (fancy-splash-head)
1324 (apply #'fancy-splash-insert text)
1325 (fancy-splash-tail)
1326 (unless (current-message)
1327 (message fancy-splash-help-echo))
1328 (set-buffer-modified-p nil)
1329 (goto-char (point-min))
1330 (force-mode-line-update)
1331 (setq fancy-current-text (cdr fancy-current-text))))
1332
1333
1334 (defun fancy-splash-default-action ()
1335 "Stop displaying the splash screen buffer.
1336 This is an internal function used to turn off the splash screen after
1337 the user caused an input event by hitting a key or clicking with the
1338 mouse."
1339 (interactive)
1340 (if (and (memq 'down (event-modifiers last-command-event))
1341 (eq (posn-window (event-start last-command-event))
1342 (selected-window)))
1343 ;; This is a mouse-down event in the spash screen window.
1344 ;; Ignore it and consume the corresponding mouse-up event.
1345 (read-event)
1346 (push last-command-event unread-command-events))
1347 (throw 'exit nil))
1348
1349
1350 (defun fancy-splash-screens (&optional hide-on-input)
1351 "Display fancy splash screens when Emacs starts."
1352 (if hide-on-input
1353 (let ((old-hourglass display-hourglass)
1354 (fancy-splash-outer-buffer (current-buffer))
1355 splash-buffer
1356 (old-minor-mode-map-alist minor-mode-map-alist)
1357 (old-emulation-mode-map-alists emulation-mode-map-alists)
1358 (frame (fancy-splash-frame))
1359 timer)
1360 (save-selected-window
1361 (select-frame frame)
1362 (switch-to-buffer "GNU Emacs")
1363 (setq splash-buffer (current-buffer))
1364 (catch 'stop-splashing
1365 (unwind-protect
1366 (let ((map (make-sparse-keymap))
1367 (cursor-type nil))
1368 (use-local-map map)
1369 (define-key map [switch-frame] 'ignore)
1370 (define-key map [t] 'fancy-splash-default-action)
1371 (define-key map [mouse-movement] 'ignore)
1372 (define-key map [mode-line t] 'ignore)
1373 (setq display-hourglass nil
1374 minor-mode-map-alist nil
1375 emulation-mode-map-alists nil
1376 buffer-undo-list t
1377 mode-line-format (propertize "---- %b %-"
1378 'face 'mode-line-buffer-id)
1379 fancy-splash-stop-time (+ (float-time)
1380 fancy-splash-max-time)
1381 timer (run-with-timer 0 fancy-splash-delay
1382 #'fancy-splash-screens-1
1383 splash-buffer))
1384 (message "%s" (startup-echo-area-message))
1385 (recursive-edit))
1386 (cancel-timer timer)
1387 (setq display-hourglass old-hourglass
1388 minor-mode-map-alist old-minor-mode-map-alist
1389 emulation-mode-map-alists old-emulation-mode-map-alists)
1390 (kill-buffer splash-buffer)))))
1391 ;; If hide-on-input is nil, don't hide the buffer on input.
1392 (if (or (window-minibuffer-p)
1393 (window-dedicated-p (selected-window)))
1394 (pop-to-buffer (current-buffer))
1395 (switch-to-buffer "GNU Emacs"))
1396 (setq buffer-read-only nil)
1397 (erase-buffer)
1398 (if pure-space-overflow
1399 (insert "\
1400 Warning Warning!!! Pure space overflow !!!Warning Warning
1401 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1402 (let (fancy-splash-outer-buffer)
1403 (fancy-splash-head)
1404 (dolist (text fancy-splash-text)
1405 (apply #'fancy-splash-insert text)
1406 (insert "\n"))
1407 (skip-chars-backward "\n")
1408 (delete-region (point) (point-max))
1409 (insert "\n")
1410 (fancy-splash-tail)
1411 (set-buffer-modified-p nil)
1412 (setq buffer-read-only t)
1413 (if (and view-read-only (not view-mode))
1414 (view-mode-enter nil 'kill-buffer))
1415 (goto-char (point-min)))))
1416
1417 (defun fancy-splash-frame ()
1418 "Return the frame to use for the fancy splash screen.
1419 Returning non-nil does not mean we should necessarily
1420 use the fancy splash screen, but if we do use it,
1421 we put it on this frame."
1422 (let (chosen-frame)
1423 (dolist (frame (append (frame-list) (list (selected-frame))))
1424 (if (and (frame-visible-p frame)
1425 (not (window-minibuffer-p (frame-selected-window frame))))
1426 (setq chosen-frame frame)))
1427 chosen-frame))
1428
1429 (defun use-fancy-splash-screens-p ()
1430 "Return t if fancy splash screens should be used."
1431 (when (and (display-graphic-p)
1432 (or (and (display-color-p)
1433 (image-type-available-p 'xpm))
1434 (image-type-available-p 'pbm)))
1435 (let ((frame (fancy-splash-frame)))
1436 (when frame
1437 (let* ((img (create-image (or fancy-splash-image
1438 (if (and (display-color-p)
1439 (image-type-available-p 'xpm))
1440 "splash.xpm" "splash.pbm"))))
1441 (image-height (and img (cdr (image-size img))))
1442 (window-height (1- (window-height (frame-selected-window frame)))))
1443 (> window-height (+ image-height 19)))))))
1444
1445
1446 (defun normal-splash-screen (&optional hide-on-input)
1447 "Display splash screen when Emacs starts."
1448 (let ((prev-buffer (current-buffer)))
1449 (unwind-protect
1450 (with-current-buffer (get-buffer-create "GNU Emacs")
1451 (setq buffer-read-only nil)
1452 (erase-buffer)
1453 (set (make-local-variable 'tab-width) 8)
1454 (if hide-on-input
1455 (set (make-local-variable 'mode-line-format)
1456 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1457
1458 (if pure-space-overflow
1459 (insert "\
1460 Warning Warning!!! Pure space overflow !!!Warning Warning
1461 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1462
1463 ;; The convention for this piece of code is that
1464 ;; each piece of output starts with one or two newlines
1465 ;; and does not end with any newlines.
1466 (insert "Welcome to GNU Emacs")
1467 (insert
1468 (if (eq system-type 'gnu/linux)
1469 ", one component of the GNU/Linux operating system.\n"
1470 ", a part of the GNU operating system.\n"))
1471
1472 (if hide-on-input
1473 (insert (substitute-command-keys
1474 (concat
1475 "\nType \\[recenter] to begin editing"
1476 (if (equal (buffer-name prev-buffer) "*scratch*")
1477 ".\n"
1478 " your file.\n")))))
1479
1480 (if (display-mouse-p)
1481 ;; The user can use the mouse to activate menus
1482 ;; so give help in terms of menu items.
1483 (progn
1484 (insert "\
1485 You can do basic editing with the menu bar and scroll bar using the mouse.
1486
1487 Useful File menu items:
1488 Exit Emacs (or type Control-x followed by Control-c)
1489 Recover Crashed Session Recover files you were editing before a crash
1490
1491 Important Help menu items:
1492 Emacs Tutorial Learn how to use Emacs efficiently
1493 Emacs FAQ Frequently asked questions and answers
1494 Read the Emacs Manual View the Emacs manual using Info
1495 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1496 Copying Conditions Conditions for redistributing and changing Emacs
1497 Getting New Versions How to obtain the latest version of Emacs
1498 More Manuals / Ordering Manuals How to order printed manuals from the FSF
1499 ")
1500 (insert "\n\n" (emacs-version)
1501 "
1502 Copyright (C) 2006 Free Software Foundation, Inc."))
1503
1504 ;; No mouse menus, so give help using kbd commands.
1505
1506 ;; If keys have their default meanings,
1507 ;; use precomputed string to save lots of time.
1508 (if (and (eq (key-binding "\C-h") 'help-command)
1509 (eq (key-binding "\C-xu") 'advertised-undo)
1510 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1511 (eq (key-binding "\C-ht") 'help-with-tutorial)
1512 (eq (key-binding "\C-hi") 'info)
1513 (eq (key-binding "\C-hr") 'info-emacs-manual)
1514 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1515 (insert "
1516 Get help C-h (Hold down CTRL and press h)
1517 Emacs manual C-h r
1518 Emacs tutorial C-h t Undo changes C-x u
1519 Buy manuals C-h C-m Exit Emacs C-x C-c
1520 Browse manuals C-h i")
1521
1522 (insert (substitute-command-keys
1523 (format "\n
1524 Get help %s
1525 Emacs manual \\[info-emacs-manual]
1526 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1527 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-emacs]
1528 Browse manuals \\[info]"
1529 (let ((where (where-is-internal
1530 'help-command nil t)))
1531 (if where
1532 (key-description where)
1533 "M-x help"))))))
1534
1535 ;; Say how to use the menu bar with the keyboard.
1536 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1537 (eq (key-binding [f10]) 'tmm-menubar))
1538 (insert "
1539 Activate menubar F10 or ESC ` or M-`")
1540 (insert (substitute-command-keys "
1541 Activate menubar \\[tmm-menubar]")))
1542
1543 ;; Many users seem to have problems with these.
1544 (insert "
1545 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1546 If you have no Meta key, you may instead type ESC followed by the character.)")
1547
1548 (insert "\n\n" (emacs-version)
1549 "
1550 Copyright (C) 2006 Free Software Foundation, Inc.")
1551
1552 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1553 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1554 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1555 (insert
1556 "\n
1557 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1558 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1559 of Emacs and modify it; type C-h C-c to see the conditions.
1560 Type C-h C-d for information on getting the latest version.")
1561 (insert (substitute-command-keys
1562 "\n
1563 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1564 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1565 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1566 Type \\[describe-distribution] for information on getting the latest version."))))
1567
1568 ;; The rest of the startup screen is the same on all
1569 ;; kinds of terminals.
1570
1571 ;; Give information on recovering, if there was a crash.
1572 (and auto-save-list-file-prefix
1573 ;; Don't signal an error if the
1574 ;; directory for auto-save-list files
1575 ;; does not yet exist.
1576 (file-directory-p (file-name-directory
1577 auto-save-list-file-prefix))
1578 (directory-files
1579 (file-name-directory auto-save-list-file-prefix)
1580 nil
1581 (concat "\\`"
1582 (regexp-quote (file-name-nondirectory
1583 auto-save-list-file-prefix)))
1584 t)
1585 (insert "\n\nIf an Emacs session crashed recently, "
1586 "type Meta-x recover-session RET\nto recover"
1587 " the files you were editing."))
1588
1589 ;; Display the input that we set up in the buffer.
1590 (set-buffer-modified-p nil)
1591 (setq buffer-read-only t)
1592 (if (and view-read-only (not view-mode))
1593 (view-mode-enter nil 'kill-buffer))
1594 (goto-char (point-min))
1595 (if hide-on-input
1596 (if (or (window-minibuffer-p)
1597 (window-dedicated-p (selected-window)))
1598 ;; If hide-on-input is nil, creating a new frame will
1599 ;; generate enough events that the subsequent `sit-for'
1600 ;; will immediately return anyway.
1601 nil ;; (pop-to-buffer (current-buffer))
1602 (save-window-excursion
1603 (switch-to-buffer (current-buffer))
1604 (sit-for 120)))
1605 (condition-case nil
1606 (switch-to-buffer (current-buffer))
1607 ;; In case the window is dedicated or something.
1608 (error (pop-to-buffer (current-buffer))))))
1609 ;; Unwind ... ensure splash buffer is killed
1610 (if hide-on-input
1611 (kill-buffer "GNU Emacs")))))
1612
1613
1614 (defun startup-echo-area-message ()
1615 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1616 "For information about the GNU Project and its goals, type C-h C-p."
1617 (substitute-command-keys
1618 "For information about the GNU Project and its goals, type \
1619 \\[describe-project].")))
1620
1621
1622 (defun display-startup-echo-area-message ()
1623 (let ((resize-mini-windows t))
1624 (message "%s" (startup-echo-area-message))))
1625
1626
1627 (defun display-splash-screen (&optional hide-on-input)
1628 "Display splash screen according to display.
1629 Fancy splash screens are used on graphic displays,
1630 normal otherwise."
1631 (interactive)
1632 (if (use-fancy-splash-screens-p)
1633 (fancy-splash-screens hide-on-input)
1634 (normal-splash-screen hide-on-input)))
1635
1636
1637 (defun command-line-1 (command-line-args-left)
1638 (or noninteractive (input-pending-p) init-file-had-error
1639 ;; t if the init file says to inhibit the echo area startup message.
1640 (and inhibit-startup-echo-area-message
1641 user-init-file
1642 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1643 (equal inhibit-startup-echo-area-message
1644 (if (equal init-file-user "")
1645 (user-login-name)
1646 init-file-user)))
1647 ;; Wasn't set with custom; see if .emacs has a setq.
1648 (let ((buffer (get-buffer-create " *temp*")))
1649 (prog1
1650 (condition-case nil
1651 (save-excursion
1652 (set-buffer buffer)
1653 (insert-file-contents user-init-file)
1654 (re-search-forward
1655 (concat
1656 "([ \t\n]*setq[ \t\n]+"
1657 "inhibit-startup-echo-area-message[ \t\n]+"
1658 (regexp-quote
1659 (prin1-to-string
1660 (if (equal init-file-user "")
1661 (user-login-name)
1662 init-file-user)))
1663 "[ \t\n]*)")
1664 nil t))
1665 (error nil))
1666 (kill-buffer buffer)))))
1667 ;; display-splash-screen at the end of command-line-1 calls
1668 ;; use-fancy-splash-screens-p. This can cause image.el to be
1669 ;; loaded, putting "Loading image... done" in the echo area.
1670 ;; This hides startup-echo-area-message. So
1671 ;; use-fancy-splash-screens-p is called here simply to get the
1672 ;; loading of image.el (if needed) out of the way before
1673 ;; display-startup-echo-area-message runs.
1674 (progn
1675 (use-fancy-splash-screens-p)
1676 (display-startup-echo-area-message)))
1677
1678 ;; Delay 2 seconds after an init file error message
1679 ;; was displayed, so user can read it.
1680 (when init-file-had-error
1681 (sit-for 2))
1682
1683 (when (and pure-space-overflow
1684 (not noninteractive))
1685 (display-warning
1686 'initialization
1687 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1688 :warning))
1689
1690 (when command-line-args-left
1691 ;; We have command args; process them.
1692 (let ((dir command-line-default-directory)
1693 (file-count 0)
1694 first-file-buffer
1695 tem
1696 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1697 ;; if foo is intended to be found in DIR.
1698 ;;
1699 ;; ;; The directories listed in --directory/-L options will *appear*
1700 ;; ;; at the front of `load-path' in the order they appear on the
1701 ;; ;; command-line. We cannot do this by *placing* them at the front
1702 ;; ;; in the order they appear, so we need this variable to hold them,
1703 ;; ;; temporarily.
1704 ;; extra-load-path
1705 ;;
1706 ;; To DTRT we keep track of the splice point and modify `load-path'
1707 ;; straight away upon any --directory/-L option.
1708 splice
1709 just-files ;; t if this follows the magic -- option.
1710 ;; This includes our standard options' long versions
1711 ;; and long versions of what's on command-switch-alist.
1712 (longopts
1713 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1714 ("--directory") ("--eval") ("--execute") ("--no-splash")
1715 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1716 (mapcar (lambda (elt)
1717 (list (concat "-" (car elt))))
1718 command-switch-alist)))
1719 (line 0)
1720 (column 0))
1721
1722 ;; Add the long X options to longopts.
1723 (dolist (tem command-line-x-option-alist)
1724 (if (string-match "^--" (car tem))
1725 (push (list (car tem)) longopts)))
1726
1727 ;; Loop, processing options.
1728 (while command-line-args-left
1729 (let* ((argi (car command-line-args-left))
1730 (orig-argi argi)
1731 argval completion)
1732 (setq command-line-args-left (cdr command-line-args-left))
1733
1734 ;; Do preliminary decoding of the option.
1735 (if just-files
1736 ;; After --, don't look for options; treat all args as files.
1737 (setq argi "")
1738 ;; Convert long options to ordinary options
1739 ;; and separate out an attached option argument into argval.
1740 (when (string-match "^\\(--[^=]*\\)=" argi)
1741 (setq argval (substring argi (match-end 0))
1742 argi (match-string 1 argi)))
1743 (if (equal argi "--")
1744 (setq completion nil)
1745 (setq completion (try-completion argi longopts)))
1746 (if (eq completion t)
1747 (setq argi (substring argi 1))
1748 (if (stringp completion)
1749 (let ((elt (assoc completion longopts)))
1750 (or elt
1751 (error "Option `%s' is ambiguous" argi))
1752 (setq argi (substring (car elt) 1)))
1753 (setq argval nil
1754 argi orig-argi))))
1755
1756 ;; Execute the option.
1757 (cond ((setq tem (assoc argi command-switch-alist))
1758 (if argval
1759 (let ((command-line-args-left
1760 (cons argval command-line-args-left)))
1761 (funcall (cdr tem) argi))
1762 (funcall (cdr tem) argi)))
1763
1764 ((equal argi "-no-splash")
1765 (setq inhibit-startup-message t))
1766
1767 ((member argi '("-f" ; what the manual claims
1768 "-funcall"
1769 "-e")) ; what the source used to say
1770 (setq tem (intern (or argval (pop command-line-args-left))))
1771 (if (commandp tem)
1772 (command-execute tem)
1773 (funcall tem)))
1774
1775 ((member argi '("-eval" "-execute"))
1776 (eval (read (or argval (pop command-line-args-left)))))
1777
1778 ((member argi '("-L" "-directory"))
1779 (setq tem (expand-file-name
1780 (command-line-normalize-file-name
1781 (or argval (pop command-line-args-left)))))
1782 (cond (splice (setcdr splice (cons tem (cdr splice)))
1783 (setq splice (cdr splice)))
1784 (t (setq load-path (cons tem load-path)
1785 splice load-path))))
1786
1787 ((member argi '("-l" "-load"))
1788 (let* ((file (command-line-normalize-file-name
1789 (or argval (pop command-line-args-left))))
1790 ;; Take file from default dir if it exists there;
1791 ;; otherwise let `load' search for it.
1792 (file-ex (expand-file-name file)))
1793 (when (file-exists-p file-ex)
1794 (setq file file-ex))
1795 (load file nil t)))
1796
1797 ;; This is used to handle -script. It's not clear
1798 ;; we need to document it.
1799 ((member argi '("-scriptload"))
1800 (let* ((file (command-line-normalize-file-name
1801 (or argval (pop command-line-args-left))))
1802 ;; Take file from default dir.
1803 (file-ex (expand-file-name file)))
1804 (load file-ex nil t t)))
1805
1806 ((equal argi "-insert")
1807 (setq tem (or argval (pop command-line-args-left)))
1808 (or (stringp tem)
1809 (error "File name omitted from `-insert' option"))
1810 (insert-file-contents (command-line-normalize-file-name tem)))
1811
1812 ((equal argi "-kill")
1813 (kill-emacs t))
1814
1815 ;; This is for when they use --no-desktop with -q, or
1816 ;; don't load Desktop in their .emacs. If desktop.el
1817 ;; _is_ loaded, it will handle this switch, and we
1818 ;; won't see it by the time we get here.
1819 ((equal argi "-no-desktop")
1820 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
1821
1822 ((string-match "^\\+[0-9]+\\'" argi)
1823 (setq line (string-to-number argi)))
1824
1825 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1826 (setq line (string-to-number (match-string 1 argi))
1827 column (string-to-number (match-string 2 argi))))
1828
1829 ((setq tem (assoc argi command-line-x-option-alist))
1830 ;; Ignore X-windows options and their args if not using X.
1831 (setq command-line-args-left
1832 (nthcdr (nth 1 tem) command-line-args-left)))
1833
1834 ((member argi '("-find-file" "-file" "-visit"))
1835 ;; An explicit option to specify visiting a file.
1836 (setq tem (or argval (pop command-line-args-left)))
1837 (unless (stringp tem)
1838 (error "File name omitted from `%s' option" argi))
1839 (setq file-count (1+ file-count))
1840 (let ((file (expand-file-name
1841 (command-line-normalize-file-name tem) dir)))
1842 (if (= file-count 1)
1843 (setq first-file-buffer (find-file file))
1844 (find-file-other-window file)))
1845 (or (zerop line)
1846 (goto-line line))
1847 (setq line 0)
1848 (unless (< column 1)
1849 (move-to-column (1- column)))
1850 (setq column 0))
1851
1852 ((equal argi "--")
1853 (setq just-files t))
1854 (t
1855 ;; We have almost exhausted our options. See if the
1856 ;; user has made any other command-line options available
1857 (let ((hooks command-line-functions) ;; lrs 7/31/89
1858 (did-hook nil))
1859 (while (and hooks
1860 (not (setq did-hook (funcall (car hooks)))))
1861 (setq hooks (cdr hooks)))
1862 (if (not did-hook)
1863 ;; Presume that the argument is a file name.
1864 (progn
1865 (if (string-match "\\`-" argi)
1866 (error "Unknown option `%s'" argi))
1867 (setq file-count (1+ file-count))
1868 (let ((file
1869 (expand-file-name
1870 (command-line-normalize-file-name orig-argi)
1871 dir)))
1872 (if (= file-count 1)
1873 (setq first-file-buffer (find-file file))
1874 (find-file-other-window file)))
1875 (or (zerop line)
1876 (goto-line line))
1877 (setq line 0)
1878 (unless (< column 1)
1879 (move-to-column (1- column)))
1880 (setq column 0))))))))
1881
1882 ;; If 3 or more files visited, and not all visible,
1883 ;; show user what they all are. But leave the last one current.
1884 (and (> file-count 2)
1885 (not noninteractive)
1886 (not inhibit-startup-buffer-menu)
1887 (or (get-buffer-window first-file-buffer)
1888 (list-buffers)))))
1889
1890 ;; Maybe display a startup screen.
1891 (unless (or inhibit-startup-message
1892 noninteractive
1893 emacs-quick-startup)
1894 ;; Display a startup screen, after some preparations.
1895
1896 ;; If there are no switches to process, we might as well
1897 ;; run this hook now, and there may be some need to do it
1898 ;; before doing any output.
1899 (run-hooks 'emacs-startup-hook)
1900 (and term-setup-hook
1901 (run-hooks 'term-setup-hook))
1902 (setq inhibit-startup-hooks t)
1903
1904 ;; It's important to notice the user settings before we
1905 ;; display the startup message; otherwise, the settings
1906 ;; won't take effect until the user gives the first
1907 ;; keystroke, and that's distracting.
1908 (when (fboundp 'frame-notice-user-settings)
1909 (frame-notice-user-settings))
1910
1911 ;; If there are no switches to process, we might as well
1912 ;; run this hook now, and there may be some need to do it
1913 ;; before doing any output.
1914 (when window-setup-hook
1915 (run-hooks 'window-setup-hook)
1916 ;; Don't let the hook be run twice.
1917 (setq window-setup-hook nil))
1918
1919 ;; Do this now to avoid an annoying delay if the user
1920 ;; clicks the menu bar during the sit-for.
1921 (when (display-popup-menus-p)
1922 (precompute-menubar-bindings))
1923 (with-no-warnings
1924 (setq menubar-bindings-done t))
1925
1926 ;; If *scratch* is selected and it is empty, insert an
1927 ;; initial message saying not to create a file there.
1928 (when (and initial-scratch-message
1929 (equal (buffer-name) "*scratch*")
1930 (= 0 (buffer-size)))
1931 (insert initial-scratch-message)
1932 (set-buffer-modified-p nil))
1933
1934 ;; If user typed input during all that work,
1935 ;; abort the startup screen. Otherwise, display it now.
1936 (unless (input-pending-p)
1937 (display-splash-screen t))))
1938
1939
1940 (defun command-line-normalize-file-name (file)
1941 "Collapse multiple slashes to one, to handle non-Emacs file names."
1942 (save-match-data
1943 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1944 ;; That is significant on some systems.
1945 ;; However, /// at the beginning is supposed to mean just /, not //.
1946 (if (string-match "^///+" file)
1947 (setq file (replace-match "/" t t file)))
1948 (while (string-match "//+" file 1)
1949 (setq file (replace-match "/" t t file)))
1950 file))
1951
1952 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
1953 ;;; startup.el ends here