(normal-top-level, command-line-1):
[bpt/emacs.git] / lisp / startup.el
... / ...
CommitLineData
1;;; startup.el --- process Emacs shell arguments
2
3;; Copyright (C) 1985, 1986, 1992, 1994 Free Software Foundation, Inc.
4
5;; Maintainer: FSF
6;; Keywords: internal
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to
22;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24;;; Commentary:
25
26;; This file parses the command line and gets Emacs running. Options on
27;; the command line are handled in precedence order. The order is the
28;; one in the list below; first described means first handled. Options
29;; within each category (delimited by a bar) are handled in the order
30;; encountered on the command line.
31
32;; -------------------------
33;; -version Print Emacs version to stderr, then exit
34;; --version successfully right away.
35;; This option is handled by emacs.c
36;; -------------------------
37;; -help Print a short usage description and exit
38;; --help successfully right away.
39;; This option is handled by emacs.c
40;; -------------------------
41;; -nl Do not use shared memory (for systems that
42;; -no-shared-memory support this) for the dumped Emacs data.
43;; This option is handled by emacs.c
44;;
45;; -map For VMS.
46;; --map-data This option is handled by emacs.c
47;; -------------------------
48;; -t FILE Use FILE as the name of the terminal.
49;; --terminal FILE Using this implies "-nw" also.
50;; This option is handled by emacs.c
51;; -------------------------
52;; -d DISPNAME Use DISPNAME as the name of the X-windows
53;; -display DISPNAME display for the initial frame.
54;; --display DISPNAME This option is handled by emacs.c
55;; -------------------------
56;; -nw Do not use a windows system (but use the
57;; --no-windows terminal instead.)
58;; This option is handled by emacs.c
59;; -------------------------
60;; -batch Execute noninteractively (messages go to stdout,
61;; --batch variable noninteractive set to t)
62;; This option is handled by emacs.c
63;; -------------------------
64;; -q Do not load user's init file and do not load
65;; -no-init-file "default.el". Regardless of this switch,
66;; --no-init-file "site-init.el" is still loaded.
67;; -------------------------
68;; -no-site-file Do not load "site-init.el". (This is the ONLY
69;; --no-site-file way to prevent loading that file.)
70;; -------------------------
71;; -u USER Load USER's init file instead of the init
72;; -user USER file belonging to the user starting Emacs.
73;; --user USER
74;; -------------------------
75;; -debug-init Don't catch errors in init files; let the
76;; --debug-init debugger run.
77;; -------------------------
78;; -i ICONTYPE Set type of icon using when Emacs is
79;; -itype ICONTYPE iconified under X-windows.
80;; --icon-type ICONTYPE This option is passed on to term/x-win.el
81;;
82;; -iconic Start Emacs iconified under X-windows.
83;; --iconic This option is passed on to term/x-win.el
84;; -------------------------
85;; Various X-windows options for colors/fonts/geometry/title etc.
86;; These options are passed on to term/x-win.el which see. Certain
87;; of these are also found in term/pc-win.el
88;; -------------------------
89;; FILE Visit FILE.
90;;
91;; -L DIRNAME Add DIRNAME to load-path
92;; -directory DIRNAME
93;; --directory DIRNAME
94;;
95;; -l FILE Load and execute the Emacs lisp code
96;; -load FILE in FILE.
97;; --load FILE
98;;
99;; -f FUNC Execute Emacs lisp function FUNC with
100;; -funcall FUNC no arguments. The "-e" form is outdated
101;; --funcall FUNC and should not be used. (It's a typo
102;; -e FUNC promoted to a feature.)
103;;
104;; -insert FILE Insert the contents of FILE into buffer.
105;; --insert FILE
106;; -------------------------
107;; -kill Kill (exit) Emacs right away.
108;; --kill
109;; -------------------------
110
111;;; Code:
112
113(setq top-level '(normal-top-level))
114
115(defvar command-line-processed nil "t once command line has been processed")
116
117(defconst inhibit-startup-message nil
118 "*Non-nil inhibits the initial startup message.
119This is for use in your personal init file, once you are familiar
120with the contents of the startup message.")
121
122(defconst inhibit-startup-echo-area-message nil
123 "*Non-nil inhibits the initial startup echo area message.
124Inhibition takes effect only if your `.emacs' file contains
125a line of this form:
126 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
127If your `.emacs' file is byte-compiled, use the following form instead:
128 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
129Thus, someone else using a copy of your `.emacs' file will see
130the startup message unless he personally acts to inhibit it.")
131
132(defconst inhibit-default-init nil
133 "*Non-nil inhibits loading the `default' library.")
134
135(defconst command-switch-alist nil
136 "Alist of command-line switches.
137Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
138HANDLER-FUNCTION receives switch name as sole arg;
139remaining command-line args are in the variable `command-line-args-left'.")
140
141(defvar command-line-args-left nil
142 "List of command-line args not yet processed.")
143
144(defvar command-line-functions nil ;; lrs 7/31/89
145 "List of functions to process unrecognized command-line arguments.
146Each function should access the dynamically bound variables
147`argi' (the current argument) and `command-line-args-left' (the remaining
148arguments). The function should return non-nil only if it recognizes and
149processes `argi'. If it does so, it may consume successive arguments by
150altering `command-line-args-left' to remove them.")
151
152(defvar command-line-default-directory nil
153 "Default directory to use for command line arguments.
154This is normally copied from `default-directory' when Emacs starts.")
155
156(defvar before-init-hook nil
157 "Functions to call after handling urgent options but before init files.
158The frame system uses this to open frames to display messages while
159Emacs loads the user's initialization file.")
160
161(defvar after-init-hook nil
162 "Functions to call after loading the init file (`~/.emacs').
163The call is not protected by a condition-case, so you can set `debug-on-error'
164in `.emacs', and put all the actual code on `after-init-hook'.")
165
166(defvar term-setup-hook nil
167 "Functions to be called after loading terminal-specific Lisp code.
168See `run-hooks'. This variable exists for users to set,
169so as to override the definitions made by the terminal-specific file.
170Emacs never sets this variable itself.")
171
172(defvar keyboard-type nil
173 "The brand of keyboard you are using.
174This variable is used to define
175the proper function and keypad keys for use under X. It is used in a
176fashion analogous to the environment value TERM.")
177
178(defvar window-setup-hook nil
179 "Normal hook run to initialize window system display.
180Emacs runs this hook after processing the command line arguments and loading
181the user's init file.")
182
183(defconst initial-major-mode 'lisp-interaction-mode
184 "Major mode command symbol to use for the initial *scratch* buffer.")
185
186(defvar init-file-user nil
187 "Identity of user whose `.emacs' file is or was read.
188The value is nil if no init file is being used; otherwise, it may be either
189the null string, meaning that the init file was taken from the user that
190originally logged in, or it may be a string containing a user's name.
191
192In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
193evaluates to the name of the directory where the `.emacs' file was
194looked for.
195
196Setting `init-file-user' does not prevent Emacs from loading
197`site-start.el'. The only way to do that is to use `--no-site-file'.")
198
199(defvar site-run-file "site-start"
200 "File containing site-wide run-time initializations.
201This file is loaded at run-time before `~/.emacs'. It contains inits
202that need to be in place for the entire site, but which, due to their
203higher incidence of change, don't make sense to load into emacs'
204dumped image. Thus, the run-time load order is: 1. file described in
205this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
206
207Don't use the `site-start.el' file for things some users may not like.
208Put them in `default.el' instead, so that users can more easily
209override them. Users can prevent loading `default.el' with the `-q'
210option or by setting `inhibit-default-init' in their own init files,
211but inhibiting `site-start.el' requires `--no-site-file', which
212is less convenient.")
213
214(defconst iso-8859-1-locale-regexp "8859[-_]?1"
215 "Regexp that specifies when to enable the ISO 8859-1 character set.
216We do that if this regexp matches the locale name
217specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
218
219(defvar mail-host-address nil
220 "*Name of this machine, for purposes of naming users.")
221
222(defvar user-mail-address nil
223 "*Full mailing address of this user.")
224
225(defvar init-file-debug nil)
226
227(defvar init-file-had-error nil)
228
229;; This function is called from the subdirs.el file.
230(defun normal-top-level-add-to-load-path (dirs)
231 (let ((tail (member default-directory load-path)))
232 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail)))))
233
234(defun normal-top-level ()
235 (if command-line-processed
236 (message "Back to top level.")
237 (setq command-line-processed t)
238 ;; Give *Messages* the same default-directory as *scratch*,
239 ;; just to keep things predictable.
240 (let ((dir default-directory))
241 (save-excursion
242 (set-buffer (get-buffer "*Messages*"))
243 (setq default-directory dir)))
244 ;; Look in each dir in load-path for a subdirs.el file.
245 ;; If we find one, load it, which will add the appropriate subdirs
246 ;; of that dir into load-path,
247 (let ((tail load-path)
248 new)
249 (while tail
250 (setq new (cons (car tail) new))
251 (let ((default-directory (car tail)))
252 (load (expand-file-name "subdirs.el" (car tail)) t t t))
253 (setq tail (cdr tail))))
254 (if (not (eq system-type 'vax-vms))
255 (progn
256 ;; If the PWD environment variable isn't accurate, delete it.
257 (let ((pwd (getenv "PWD")))
258 (and (stringp pwd)
259 ;; Use FOO/., so that if FOO is a symlink, file-attributes
260 ;; describes the directory linked to, not FOO itself.
261 (or (equal (file-attributes
262 (concat (file-name-as-directory pwd) "."))
263 (file-attributes
264 (concat (file-name-as-directory default-directory)
265 ".")))
266 (setq process-environment
267 (delete (concat "PWD=" pwd)
268 process-environment)))))))
269 (setq default-directory (abbreviate-file-name default-directory))
270 (setq user-mail-address (concat (user-login-name) "@"
271 (or mail-host-address
272 (system-name))))
273 ;; Specify the file for recording all the auto save files of this session.
274 ;; This is used by multiple-recover.
275 (setq auto-save-list-file-name
276 (expand-file-name
277 (format "~/.saves-%d-%s"
278 (emacs-pid)
279 (or mail-host-address (system-name)))))
280 (let ((menubar-bindings-done nil))
281 (unwind-protect
282 (command-line)
283 ;; Do this again, in case .emacs defined more abbreviations.
284 (setq default-directory (abbreviate-file-name default-directory))
285 (run-hooks 'emacs-startup-hook)
286 (and term-setup-hook
287 (run-hooks 'term-setup-hook))
288 ;; Modify the initial frame based on what .emacs puts into
289 ;; ...-frame-alist.
290 (if (fboundp 'frame-notice-user-settings)
291 (frame-notice-user-settings))
292 ;; Now we know the user's default font, so add it to the menu.
293 (if (fboundp 'font-menu-add-default)
294 (font-menu-add-default))
295 (and window-setup-hook
296 (run-hooks 'window-setup-hook))
297 (or menubar-bindings-done
298 (if (eq window-system 'x)
299 (precompute-menubar-bindings)))))))
300
301;; Precompute the keyboard equivalents in the menu bar items.
302(defun precompute-menubar-bindings ()
303 (let ((submap (lookup-key global-map [menu-bar])))
304 (while submap
305 (and (consp (car submap))
306 (symbolp (car (car submap)))
307 (stringp (car-safe (cdr (car submap))))
308 (keymapp (cdr (cdr (car submap))))
309 (x-popup-menu nil (cdr (cdr (car submap)))))
310 (setq submap (cdr submap))))
311 (setq define-key-rebound-commands t))
312
313(defun command-line ()
314 (setq command-line-default-directory default-directory)
315
316 ;; See if we should import version-control from the environment variable.
317 (let ((vc (getenv "VERSION_CONTROL")))
318 (cond ((eq vc nil)) ;don't do anything if not set
319 ((or (string= vc "t")
320 (string= vc "numbered"))
321 (setq version-control t))
322 ((or (string= vc "nil")
323 (string= vc "existing"))
324 (setq version-control nil))
325 ((or (string= vc "never")
326 (string= vc "simple"))
327 (setq version-control 'never))))
328
329 (if (let ((ctype
330 ;; Use the first of these three envvars that has a nonempty value.
331 (or (let ((string (getenv "LC_ALL")))
332 (and (not (equal string "")) string))
333 (let ((string (getenv "LC_CTYPE")))
334 (and (not (equal string "")) string))
335 (let ((string (getenv "LANG")))
336 (and (not (equal string "")) string)))))
337 (and ctype
338 (string-match iso-8859-1-locale-regexp ctype)))
339 (progn
340 (require 'disp-table)
341 (standard-display-european t)
342 (require 'iso-syntax)))
343
344 ;;! This has been commented out; I currently find the behavior when
345 ;;! split-window-keep-point is nil disturbing, but if I can get used
346 ;;! to it, then it would be better to eliminate the option.
347 ;;! ;; Choose a good default value for split-window-keep-point.
348 ;;! (setq split-window-keep-point (> baud-rate 2400))
349
350 ;; Read window system's init file if using a window system.
351 (condition-case error
352 (if (and window-system (not noninteractive))
353 (load (concat term-file-prefix
354 (symbol-name window-system)
355 "-win")
356 ;; Every window system should have a startup file;
357 ;; barf if we can't find it.
358 nil t))
359 ;; If we can't read it, print the error message and exit.
360 (error
361 (princ
362 (if (eq (car error) 'error)
363 (apply 'concat (cdr error))
364 (if (memq 'file-error (get (car error) 'error-conditions))
365 (format "%s: %s"
366 (nth 1 error)
367 (mapconcat '(lambda (obj) (prin1-to-string obj t))
368 (cdr (cdr error)) ", "))
369 (format "%s: %s"
370 (get (car error) 'error-message)
371 (mapconcat '(lambda (obj) (prin1-to-string obj t))
372 (cdr error) ", "))))
373 'external-debugging-output)
374 (setq window-system nil)
375 (kill-emacs)))
376
377 (let ((done nil)
378 (args (cdr command-line-args)))
379
380 ;; Figure out which user's init file to load,
381 ;; either from the environment or from the options.
382 (setq init-file-user (if noninteractive nil (user-login-name)))
383 ;; If user has not done su, use current $HOME to find .emacs.
384 (and init-file-user (string= init-file-user (user-real-login-name))
385 (setq init-file-user ""))
386
387 ;; Process the command-line args, and delete the arguments
388 ;; processed. This is consistent with the way main in emacs.c
389 ;; does things.
390 (while (and (not done) args)
391 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
392 ("--debug-init") ("--iconic") ("--icon-type")))
393 (argi (car args))
394 (argval nil))
395 (if (string-match "=" argi)
396 (setq argval (substring argi (match-end 0))
397 argi (substring argi 0 (match-beginning 0))))
398 (let ((completion (try-completion argi longopts)))
399 (if (eq completion t)
400 (setq argi (substring argi 1))
401 (if (stringp completion)
402 (let ((elt (assoc completion longopts)))
403 (or elt
404 (error "Option `%s' is ambiguous" argi))
405 (setq argi (substring (car elt) 1)))
406 (setq argval nil))))
407 (cond
408 ((or (string-equal argi "-q")
409 (string-equal argi "-no-init-file"))
410 (setq init-file-user nil
411 args (cdr args)))
412 ((or (string-equal argi "-u")
413 (string-equal argi "-user"))
414 (or argval
415 (setq argval (car args)
416 args (cdr args)))
417 (setq init-file-user argval
418 argval nil
419 args (cdr args)))
420 ((string-equal argi "-no-site-file")
421 (setq site-run-file nil
422 args (cdr args)))
423 ((string-equal argi "-debug-init")
424 (setq init-file-debug t
425 args (cdr args)))
426 ((string-equal argi "-iconic")
427 (setq initial-frame-alist
428 (cons '(visibility . icon) initial-frame-alist))
429 (setq args (cdr args)))
430 ((or (string-equal argi "-icon-type")
431 (string-equal argi "-i")
432 (string-equal argi "-itype"))
433 (setq default-frame-alist
434 (cons '(icon-type . t) default-frame-alist))
435 (setq args (cdr args)))
436 (t (setq done t)))
437 ;; Was argval set but not used?
438 (and argval
439 (error "Option `%s' doesn't allow an argument" argi))))
440
441 ;; Re-attach the program name to the front of the arg list.
442 (and command-line-args (setcdr command-line-args args)))
443
444 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
445 (if (fboundp 'face-initialize)
446 (face-initialize))
447 (if (fboundp 'frame-initialize)
448 (frame-initialize))
449 ;; If frame was created with a menu bar, set menu-bar-mode on.
450 (if (and (eq window-system 'x)
451 (> (cdr (assq 'menu-bar-lines (frame-parameters))) 0))
452 (menu-bar-mode t))
453
454 (run-hooks 'before-init-hook)
455
456 ;; Run the site-start library if it exists. The point of this file is
457 ;; that it is run before .emacs. There is no point in doing this after
458 ;; .emacs; that is useless.
459 (if site-run-file
460 (load site-run-file t t))
461
462 ;; Sites should not disable this. Only individuals should disable
463 ;; the startup message.
464 (setq inhibit-startup-message nil)
465
466 ;; Load that user's init file, or the default one, or none.
467 (let (debug-on-error-from-init-file
468 debug-on-error-should-be-set
469 (debug-on-error-initial
470 (if (eq init-file-debug t) 'startup init-file-debug)))
471 (let ((debug-on-error debug-on-error-initial)
472 ;; This function actually reads the init files.
473 (inner
474 (function
475 (lambda ()
476 (if init-file-user
477 (progn
478 (setq user-init-file
479 (cond
480 ((eq system-type 'ms-dos)
481 (concat "~" init-file-user "/_emacs"))
482 ((eq system-type 'windows-nt)
483 "~/_emacs")
484 ((eq system-type 'vax-vms)
485 "sys$login:.emacs")
486 (t
487 (concat "~" init-file-user "/.emacs"))))
488 (load user-init-file t t t)
489 (or inhibit-default-init
490 (let ((inhibit-startup-message nil))
491 ;; Users are supposed to be told their rights.
492 ;; (Plus how to get help and how to undo.)
493 ;; Don't you dare turn this off for anyone
494 ;; except yourself.
495 (load "default" t t)))))))))
496 (if init-file-debug
497 ;; Do this without a condition-case if the user wants to debug.
498 (funcall inner)
499 (condition-case error
500 (progn
501 (funcall inner)
502 (setq init-file-had-error nil))
503 (error (message "Error in init file: %s%s%s"
504 (get (car error) 'error-message)
505 (if (cdr error) ": " "")
506 (mapconcat 'prin1-to-string (cdr error) ", "))
507 (setq init-file-had-error t))))
508 ;; If we can tell that the init file altered debug-on-error,
509 ;; arrange to preserve the value that it set up.
510 (or (eq debug-on-error debug-on-error-initial)
511 (setq debug-on-error-should-be-set t
512 debug-on-error-from-init-file debug-on-error)))
513 (if debug-on-error-should-be-set
514 (setq debug-on-error debug-on-error-from-init-file)))
515
516 (run-hooks 'after-init-hook)
517
518 ;; If *scratch* exists and init file didn't change its mode, initialize it.
519 (if (get-buffer "*scratch*")
520 (save-excursion
521 (set-buffer "*scratch*")
522 (if (eq major-mode 'fundamental-mode)
523 (funcall initial-major-mode))))
524 ;; Load library for our terminal type.
525 ;; User init file can set term-file-prefix to nil to prevent this.
526 (and term-file-prefix (not noninteractive) (not window-system)
527 (let ((term (getenv "TERM"))
528 hyphend)
529 (while (and term
530 (not (load (concat term-file-prefix term) t t)))
531 ;; Strip off last hyphen and what follows, then try again
532 (if (setq hyphend (string-match "[-_][^-_]+$" term))
533 (setq term (substring term 0 hyphend))
534 (setq term nil)))))
535
536 ;; Process the remaining args.
537 (command-line-1 (cdr command-line-args))
538
539 ;; If -batch, terminate after processing the command options.
540 (if noninteractive (kill-emacs t)))
541
542(defun command-line-1 (command-line-args-left)
543 (or noninteractive (input-pending-p) init-file-had-error
544 (and inhibit-startup-echo-area-message
545 (let ((buffer (get-buffer-create " *temp*")))
546 (prog1
547 (condition-case nil
548 (save-excursion
549 (set-buffer buffer)
550 (insert-file-contents user-init-file)
551 (re-search-forward
552 (concat
553 "([ \t\n]*setq[ \t\n]+"
554 "inhibit-startup-echo-area-message[ \t\n]+"
555 (regexp-quote
556 (prin1-to-string
557 (if (string= init-file-user "")
558 (user-login-name)
559 init-file-user)))
560 "[ \t\n]*)")
561 nil t))
562 (error nil))
563 (kill-buffer buffer))))
564 (message (if (eq (key-binding "\C-h\C-p") 'describe-project)
565 "For information about the GNU Project and its goals, type C-h C-p."
566 (substitute-command-keys
567 "For information about the GNU Project and its goals, type \\[describe-project]."))))
568 (if (null command-line-args-left)
569 (cond ((and (not inhibit-startup-message) (not noninteractive)
570 ;; Don't clobber a non-scratch buffer if init file
571 ;; has selected it.
572 (string= (buffer-name) "*scratch*")
573 (not (input-pending-p)))
574 ;; If there are no switches to process, we might as well
575 ;; run this hook now, and there may be some need to do it
576 ;; before doing any output.
577 (and term-setup-hook
578 (run-hooks 'term-setup-hook))
579 ;; Don't let the hook be run twice.
580 (setq term-setup-hook nil)
581
582 ;; It's important to notice the user settings before we
583 ;; display the startup message; otherwise, the settings
584 ;; won't take effect until the user gives the first
585 ;; keystroke, and that's distracting.
586 (if (fboundp 'frame-notice-user-settings)
587 (frame-notice-user-settings))
588
589 (and window-setup-hook
590 (run-hooks 'window-setup-hook))
591 (setq window-setup-hook nil)
592 ;; Do this now to avoid an annoying delay if the user
593 ;; clicks the menu bar during the sit-for.
594 (if (eq window-system 'x)
595 (precompute-menubar-bindings))
596 (setq menubar-bindings-done t)
597 (unwind-protect
598 (progn
599 (insert (emacs-version)
600 "
601Copyright (C) 1994 Free Software Foundation, Inc.\n\n")
602 ;; If keys have their default meanings,
603 ;; use precomputed string to save lots of time.
604 (if (and (eq (key-binding "\C-h") 'help-command)
605 (eq (key-binding "\C-xu") 'advertised-undo)
606 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
607 (eq (key-binding "\C-ht") 'help-with-tutorial)
608 (eq (key-binding "\C-hi") 'info))
609 (insert
610 "Type C-h for help; C-x u to undo changes. (`C-' means use CTRL key.)
611To kill the Emacs job, type C-x C-c.
612Type C-h t for a tutorial on using Emacs.
613Type C-h i to enter Info, which you can use to read GNU documentation.")
614 (insert (substitute-command-keys
615 (format "Type %s for help; \\[advertised-undo] to undo changes. (`C-' means use CTRL key.)
616To kill the Emacs job, type \\[save-buffers-kill-emacs].
617Type \\[help-with-tutorial] for a tutorial on using Emacs.
618Type \\[info] to enter Info, which you can use to read GNU documentation."
619 (let ((where (where-is-internal
620 'help-command nil t)))
621 (if where
622 (key-description where)
623 "M-x help"))))))
624
625 ;; Windows and MSDOS (currently) do not count as
626 ;; window systems, but do have mouse support.
627 (if (or (memq system-type '(msdos windowsnt))
628 window-system)
629 (insert "
630C-mouse-3 (third mouse button, with Control) gets a mode-specific menu."))
631 (insert "\n")
632 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
633 (eq (key-binding "\C-h\C-d") 'describe-distribution)
634 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
635 (insert
636 "
637GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
638You may give out copies of Emacs; type C-h C-c to see the conditions.
639Type C-h C-d for information on getting the latest version.")
640 (insert (substitute-command-keys
641 "
642GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
643You may give out copies of Emacs; type \\[describe-copying] to see the conditions.
644Type \\[describe-distribution] for information on getting the latest version.")))
645 (set-buffer-modified-p nil)
646 (sit-for 120))
647 (save-excursion
648 ;; In case the Emacs server has already selected
649 ;; another buffer, erase the one our message is in.
650 (set-buffer (get-buffer "*scratch*"))
651 (erase-buffer)
652 (set-buffer-modified-p nil)))))
653 ;; Delay 2 seconds after the init file error message
654 ;; was displayed, so user can read it.
655 (if init-file-had-error
656 (sit-for 2))
657 (let ((dir command-line-default-directory)
658 (file-count 0)
659 first-file-buffer
660 (line 0))
661 (while command-line-args-left
662 (let* ((argi (car command-line-args-left))
663 (orig-argi argi)
664 ;; This includes our standard options' long versions
665 ;; and long versions of what's on command-switch-alist.
666 (longopts
667 (append '(("--funcall") ("--load") ("--insert") ("--kill")
668 ("--directory"))
669 (mapcar '(lambda (elt)
670 (list (concat "-" (car elt))))
671 command-switch-alist)))
672 tem argval completion
673 ;; List of directories specified in -L/--directory,
674 ;; in reverse of the order specified.
675 extra-load-path
676 (initial-load-path load-path))
677 (setq command-line-args-left (cdr command-line-args-left))
678
679 ;; Convert long options to ordinary options
680 ;; and separate out an attached option argument into argval.
681 (if (string-match "^--[^=]*=" argi)
682 (setq argval (substring argi (match-end 0))
683 argi (substring argi 0 (1- (match-end 0)))))
684 (setq completion (try-completion argi longopts))
685 (if (eq completion t)
686 (setq argi (substring argi 1))
687 (if (stringp completion)
688 (let ((elt (assoc completion longopts)))
689 (or elt
690 (error "Option `%s' is ambiguous" argi))
691 (setq argi (substring (car elt) 1)))
692 (setq argval nil argi orig-argi)))
693
694 ;; Execute the option.
695 (cond ((setq tem (assoc argi command-switch-alist))
696 (if argval
697 (let ((command-line-args-left
698 (cons argval command-line-args-left)))
699 (funcall (cdr tem) argi))
700 (funcall (cdr tem) argi)))
701 ((or (string-equal argi "-f") ;what the manual claims
702 (string-equal argi "-funcall")
703 (string-equal argi "-e")) ; what the source used to say
704 (if argval
705 (setq tem (intern argval))
706 (setq tem (intern (car command-line-args-left)))
707 (setq command-line-args-left (cdr command-line-args-left)))
708 (if (arrayp (symbol-function tem))
709 (command-execute tem)
710 (funcall tem)))
711 ;; Set the default directory as specified in -L.
712 ((or (string-equal argi "-L")
713 (string-equal argi "-directory"))
714 (if argval
715 (setq tem argval)
716 (setq tem (car command-line-args-left)
717 command-line-args-left (cdr command-line-args-left)))
718 (setq extra-load-path
719 (cons (expand-file-name tem) extra-load-path))
720 (setq load-path (append (nreverse extra-load-path)
721 initial-load-path)))
722 ((or (string-equal argi "-l")
723 (string-equal argi "-load"))
724 (if argval
725 (setq tem argval)
726 (setq tem (car command-line-args-left)
727 command-line-args-left (cdr command-line-args-left)))
728 (let ((file tem))
729 ;; Take file from default dir if it exists there;
730 ;; otherwise let `load' search for it.
731 (if (file-exists-p (expand-file-name file))
732 (setq file (expand-file-name file)))
733 (load file nil t)))
734 ((string-equal argi "-insert")
735 (or (stringp (car command-line-args-left))
736 (error "File name omitted from `-insert' option"))
737 (if argval
738 (setq tem argval)
739 (setq tem (car command-line-args-left)
740 command-line-args-left (cdr command-line-args-left)))
741 (insert-file-contents tem))
742 ((string-equal argi "-kill")
743 (kill-emacs t))
744 ((string-match "^\\+[0-9]+\\'" argi)
745 (setq line (string-to-int argi)))
746 (t
747 ;; We have almost exhausted our options. See if the
748 ;; user has made any other command-line options available
749 (let ((hooks command-line-functions);; lrs 7/31/89
750 (did-hook nil))
751 (while (and hooks
752 (not (setq did-hook (funcall (car hooks)))))
753 (setq hooks (cdr hooks)))
754 (if (not did-hook)
755 ;; Ok, presume that the argument is a file name
756 (progn
757 (setq file-count (1+ file-count))
758 (cond ((= file-count 1)
759 (setq first-file-buffer
760 (find-file (expand-file-name argi dir))))
761 (t
762 (find-file-other-window (expand-file-name argi dir))))
763 (or (zerop line)
764 (goto-line line))
765 (setq line 0))))))))
766 ;; If 3 or more files visited, and not all visible,
767 ;; show user what they all are.
768 (if (> file-count 2)
769 (or (get-buffer-window first-file-buffer)
770 (progn (other-window 1)
771 (buffer-menu)))))))
772
773;;; startup.el ends here