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