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