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