1 ;;; startup.el --- process Emacs shell arguments
3 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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)
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.
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.
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.
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
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.
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
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 ;; -------------------------
91 ;; -L DIRNAME Add DIRNAME to load-path
93 ;; --directory DIRNAME
95 ;; -l FILE Load and execute the Emacs lisp code
96 ;; -load FILE in FILE.
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.)
104 ;; -insert FILE Insert the contents of FILE into buffer.
106 ;; -------------------------
107 ;; -kill Kill (exit) Emacs right away.
109 ;; -------------------------
113 (setq top-level
'(normal-top-level))
115 (defvar command-line-processed nil
"t once command line has been processed")
117 (defconst inhibit-startup-message nil
118 "*Non-nil inhibits the initial startup message.
119 This is for use in your personal init file, once you are familiar
120 with the contents of the startup message.")
122 (defconst inhibit-startup-echo-area-message nil
123 "*Non-nil inhibits the initial startup echo area message.
124 Inhibition takes effect only if your `.emacs' file contains
126 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
127 If your `.emacs' file is byte-compiled, use the following form instead:
128 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
129 Thus, someone else using a copy of your `.emacs' file will see
130 the startup message unless he personally acts to inhibit it.")
132 (defconst inhibit-default-init nil
133 "*Non-nil inhibits loading the `default' library.")
135 (defconst command-switch-alist nil
136 "Alist of command-line switches.
137 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
138 HANDLER-FUNCTION receives switch name as sole arg;
139 remaining command-line args are in the variable `command-line-args-left'.")
141 (defvar command-line-args-left nil
142 "List of command-line args not yet processed.")
144 (defvar command-line-functions nil
;; lrs 7/31/89
145 "List of functions to process unrecognized command-line arguments.
146 Each function should access the dynamically bound variables
147 `argi' (the current argument) and `command-line-args-left' (the remaining
148 arguments). The function should return non-nil only if it recognizes and
149 processes `argi'. If it does so, it may consume successive arguments by
150 altering `command-line-args-left' to remove them.")
152 (defvar command-line-default-directory nil
153 "Default directory to use for command line arguments.
154 This is normally copied from `default-directory' when Emacs starts.")
156 (defvar before-init-hook nil
157 "Functions to call after handling urgent options but before init files.
158 The frame system uses this to open frames to display messages while
159 Emacs loads the user's initialization file.")
161 (defvar after-init-hook nil
162 "Functions to call after loading the init file (`~/.emacs').
163 The call is not protected by a condition-case, so you can set `debug-on-error'
164 in `.emacs', and put all the actual code on `after-init-hook'.")
166 (defvar term-setup-hook nil
167 "Functions to be called after loading terminal-specific Lisp code.
168 See `run-hooks'. This variable exists for users to set,
169 so as to override the definitions made by the terminal-specific file.
170 Emacs never sets this variable itself.")
172 (defvar keyboard-type nil
173 "The brand of keyboard you are using.
174 This variable is used to define
175 the proper function and keypad keys for use under X. It is used in a
176 fashion analogous to the environment value TERM.")
178 (defvar window-setup-hook nil
179 "Normal hook run to initialize window system display.
180 Emacs runs this hook after processing the command line arguments and loading
181 the user's init file.")
183 (defconst initial-major-mode
'lisp-interaction-mode
184 "Major mode command symbol to use for the initial *scratch* buffer.")
186 (defvar init-file-user nil
187 "Identity of user whose `.emacs' file is or was read.
188 The value is nil if no init file is being used; otherwise, it may be either
189 the null string, meaning that the init file was taken from the user that
190 originally logged in, or it may be a string containing a user's name.
192 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
193 evaluates to the name of the directory where the `.emacs' file was
196 Setting `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'.")
199 (defvar site-run-file
"site-start"
200 "File containing site-wide run-time initializations.
201 This file is loaded at run-time before `~/.emacs'. It contains inits
202 that need to be in place for the entire site, but which, due to their
203 higher incidence of change, don't make sense to load into emacs'
204 dumped image. Thus, the run-time load order is: 1. file described in
205 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
207 Don't use the `site-start.el' file for things some users may not like.
208 Put them in `default.el' instead, so that users can more easily
209 override them. Users can prevent loading `default.el' with the `-q'
210 option or by setting `inhibit-default-init' in their own init files,
211 but inhibiting `site-start.el' requires `--no-site-file', which
212 is less convenient.")
214 (defconst iso-8859-1-locale-regexp
"8859[-_]?1"
215 "Regexp that specifies when to enable the ISO 8859-1 character set.
216 We do that if this regexp matches the locale name
217 specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
219 (defvar mail-host-address nil
220 "*Name of this machine, for purposes of naming users.")
222 (defvar user-mail-address nil
223 "*Full mailing address of this user.")
225 (defvar init-file-debug nil
)
227 (defvar init-file-had-error nil
)
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
)))))
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
))
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
)
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
))
256 ;; If the PWD environment variable isn't accurate, delete it.
257 (let ((pwd (getenv "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
) "."))
264 (concat (file-name-as-directory default-directory
)
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
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
277 (format "~/.saves-%d-%s"
280 (let ((menubar-bindings-done nil
))
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
)
287 (run-hooks 'term-setup-hook
))
288 ;; Modify the initial frame based on what .emacs puts into
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)))))))
301 ;; Precompute the keyboard equivalents in the menu bar items.
302 (defun precompute-menubar-bindings ()
303 (let ((submap (lookup-key global-map
[menu-bar
])))
305 (and (consp (car submap
))
306 (symbolp (car (car submap
)))
307 (stringp (car-safe (cdr (car submap
))))
308 (keymapp (cdr (cdr (car submap
))))
310 (x-popup-menu nil
(cdr (cdr (car submap
))))
313 (setq submap
(cdr submap
))))
314 (setq define-key-rebound-commands t
))
316 (defun command-line ()
317 (setq command-line-default-directory default-directory
)
319 ;; See if we should import version-control from the environment variable.
320 (let ((vc (getenv "VERSION_CONTROL")))
321 (cond ((eq vc nil
)) ;don't do anything if not set
322 ((or (string= vc
"t")
323 (string= vc
"numbered"))
324 (setq version-control t
))
325 ((or (string= vc
"nil")
326 (string= vc
"existing"))
327 (setq version-control nil
))
328 ((or (string= vc
"never")
329 (string= vc
"simple"))
330 (setq version-control
'never
))))
333 ;; Use the first of these three envvars that has a nonempty value.
334 (or (let ((string (getenv "LC_ALL")))
335 (and (not (equal string
"")) string
))
336 (let ((string (getenv "LC_CTYPE")))
337 (and (not (equal string
"")) string
))
338 (let ((string (getenv "LANG")))
339 (and (not (equal string
"")) string
)))))
341 (string-match iso-8859-1-locale-regexp ctype
)))
343 (require 'disp-table
)
344 (standard-display-european t
)
345 (require 'iso-syntax
)))
347 ;;! This has been commented out; I currently find the behavior when
348 ;;! split-window-keep-point is nil disturbing, but if I can get used
349 ;;! to it, then it would be better to eliminate the option.
350 ;;! ;; Choose a good default value for split-window-keep-point.
351 ;;! (setq split-window-keep-point (> baud-rate 2400))
353 ;; Read window system's init file if using a window system.
354 (condition-case error
355 (if (and window-system
(not noninteractive
))
356 (load (concat term-file-prefix
357 (symbol-name window-system
)
359 ;; Every window system should have a startup file;
360 ;; barf if we can't find it.
362 ;; If we can't read it, print the error message and exit.
365 (if (eq (car error
) 'error
)
366 (apply 'concat
(cdr error
))
367 (if (memq 'file-error
(get (car error
) 'error-conditions
))
370 (mapconcat '(lambda (obj) (prin1-to-string obj t
))
371 (cdr (cdr error
)) ", "))
373 (get (car error
) 'error-message
)
374 (mapconcat '(lambda (obj) (prin1-to-string obj t
))
376 'external-debugging-output
)
377 (setq window-system nil
)
381 (args (cdr command-line-args
)))
383 ;; Figure out which user's init file to load,
384 ;; either from the environment or from the options.
385 (setq init-file-user
(if noninteractive nil
(user-login-name)))
386 ;; If user has not done su, use current $HOME to find .emacs.
387 (and init-file-user
(string= init-file-user
(user-real-login-name))
388 (setq init-file-user
""))
390 ;; Process the command-line args, and delete the arguments
391 ;; processed. This is consistent with the way main in emacs.c
393 (while (and (not done
) args
)
394 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
395 ("--debug-init") ("--iconic") ("--icon-type")))
398 (if (string-match "=" argi
)
399 (setq argval
(substring argi
(match-end 0))
400 argi
(substring argi
0 (match-beginning 0))))
401 (let ((completion (try-completion argi longopts
)))
402 (if (eq completion t
)
403 (setq argi
(substring argi
1))
404 (if (stringp completion
)
405 (let ((elt (assoc completion longopts
)))
407 (error "Option `%s' is ambiguous" argi
))
408 (setq argi
(substring (car elt
) 1)))
411 ((or (string-equal argi
"-q")
412 (string-equal argi
"-no-init-file"))
413 (setq init-file-user nil
415 ((or (string-equal argi
"-u")
416 (string-equal argi
"-user"))
418 (setq args
(cdr args
)
420 (setq init-file-user argval
423 ((string-equal argi
"-no-site-file")
424 (setq site-run-file nil
426 ((string-equal argi
"-debug-init")
427 (setq init-file-debug t
429 ((string-equal argi
"-iconic")
430 (setq initial-frame-alist
431 (cons '(visibility . icon
) initial-frame-alist
))
432 (setq args
(cdr args
)))
433 ((or (string-equal argi
"-icon-type")
434 (string-equal argi
"-i")
435 (string-equal argi
"-itype"))
436 (setq default-frame-alist
437 (cons '(icon-type . t
) default-frame-alist
))
438 (setq args
(cdr args
)))
440 ;; Was argval set but not used?
442 (error "Option `%s' doesn't allow an argument" argi
))))
444 ;; Re-attach the program name to the front of the arg list.
445 (and command-line-args
(setcdr command-line-args args
)))
447 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
448 (if (fboundp 'face-initialize
)
450 (if (fboundp 'frame-initialize
)
452 ;; If frame was created with a menu bar, set menu-bar-mode on.
453 (if (and (eq window-system
'x
)
454 (> (cdr (assq 'menu-bar-lines
(frame-parameters))) 0))
457 (run-hooks 'before-init-hook
)
459 ;; Run the site-start library if it exists. The point of this file is
460 ;; that it is run before .emacs. There is no point in doing this after
461 ;; .emacs; that is useless.
463 (load site-run-file t t
))
465 ;; Sites should not disable this. Only individuals should disable
466 ;; the startup message.
467 (setq inhibit-startup-message nil
)
469 ;; Load that user's init file, or the default one, or none.
470 (let (debug-on-error-from-init-file
471 debug-on-error-should-be-set
472 (debug-on-error-initial
473 (if (eq init-file-debug t
) 'startup init-file-debug
)))
474 (let ((debug-on-error debug-on-error-initial
)
475 ;; This function actually reads the init files.
483 ((eq system-type
'ms-dos
)
484 (concat "~" init-file-user
"/_emacs"))
485 ((eq system-type
'windows-nt
)
487 ((eq system-type
'vax-vms
)
490 (concat "~" init-file-user
"/.emacs"))))
491 (load user-init-file t t t
)
492 (or inhibit-default-init
493 (let ((inhibit-startup-message nil
))
494 ;; Users are supposed to be told their rights.
495 ;; (Plus how to get help and how to undo.)
496 ;; Don't you dare turn this off for anyone
498 (load "default" t t
)))))))))
500 ;; Do this without a condition-case if the user wants to debug.
502 (condition-case error
505 (setq init-file-had-error nil
))
506 (error (message "Error in init file: %s%s%s"
507 (get (car error
) 'error-message
)
508 (if (cdr error
) ": " "")
509 (mapconcat 'prin1-to-string
(cdr error
) ", "))
510 (setq init-file-had-error t
))))
511 ;; If we can tell that the init file altered debug-on-error,
512 ;; arrange to preserve the value that it set up.
513 (or (eq debug-on-error debug-on-error-initial
)
514 (setq debug-on-error-should-be-set t
515 debug-on-error-from-init-file debug-on-error
)))
516 (if debug-on-error-should-be-set
517 (setq debug-on-error debug-on-error-from-init-file
)))
519 (run-hooks 'after-init-hook
)
521 ;; If *scratch* exists and init file didn't change its mode, initialize it.
522 (if (get-buffer "*scratch*")
524 (set-buffer "*scratch*")
525 (if (eq major-mode
'fundamental-mode
)
526 (funcall initial-major-mode
))))
527 ;; Load library for our terminal type.
528 ;; User init file can set term-file-prefix to nil to prevent this.
529 (and term-file-prefix
(not noninteractive
) (not window-system
)
530 (let ((term (getenv "TERM"))
533 (not (load (concat term-file-prefix term
) t t
)))
534 ;; Strip off last hyphen and what follows, then try again
535 (if (setq hyphend
(string-match "[-_][^-_]+$" term
))
536 (setq term
(substring term
0 hyphend
))
539 ;; Process the remaining args.
540 (command-line-1 (cdr command-line-args
))
542 ;; If -batch, terminate after processing the command options.
543 (if noninteractive
(kill-emacs t
)))
545 (defun command-line-1 (command-line-args-left)
546 (or noninteractive
(input-pending-p) init-file-had-error
547 (and inhibit-startup-echo-area-message
548 (let ((buffer (get-buffer-create " *temp*")))
553 (insert-file-contents user-init-file
)
556 "([ \t\n]*setq[ \t\n]+"
557 "inhibit-startup-echo-area-message[ \t\n]+"
560 (if (string= init-file-user
"")
566 (kill-buffer buffer
))))
567 (message (if (eq (key-binding "\C-h\C-p") 'describe-project
)
568 "For information about the GNU Project and its goals, type C-h C-p."
569 (substitute-command-keys
570 "For information about the GNU Project and its goals, type \\[describe-project]."))))
571 (if (null command-line-args-left
)
572 (cond ((and (not inhibit-startup-message
) (not noninteractive
)
573 ;; Don't clobber a non-scratch buffer if init file
575 (string= (buffer-name) "*scratch*")
576 (not (input-pending-p)))
577 ;; If there are no switches to process, we might as well
578 ;; run this hook now, and there may be some need to do it
579 ;; before doing any output.
581 (run-hooks 'term-setup-hook
))
582 ;; Don't let the hook be run twice.
583 (setq term-setup-hook nil
)
585 ;; It's important to notice the user settings before we
586 ;; display the startup message; otherwise, the settings
587 ;; won't take effect until the user gives the first
588 ;; keystroke, and that's distracting.
589 (if (fboundp 'frame-notice-user-settings
)
590 (frame-notice-user-settings))
592 (and window-setup-hook
593 (run-hooks 'window-setup-hook
))
594 (setq window-setup-hook nil
)
595 ;; Do this now to avoid an annoying delay if the user
596 ;; clicks the menu bar during the sit-for.
597 (if (eq window-system
'x
)
598 (precompute-menubar-bindings))
599 (setq menubar-bindings-done t
)
602 (insert (emacs-version)
604 Copyright (C) 1995 Free Software Foundation, Inc.\n\n")
605 ;; If keys have their default meanings,
606 ;; use precomputed string to save lots of time.
607 (if (and (eq (key-binding "\C-h") 'help-command
)
608 (eq (key-binding "\C-xu") 'advertised-undo
)
609 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs
)
610 (eq (key-binding "\C-ht") 'help-with-tutorial
)
611 (eq (key-binding "\C-hi") 'info
))
613 "Type C-h for help; C-x u to undo changes. (`C-' means use CTRL key.)
614 To kill the Emacs job, type C-x C-c.
615 Type C-h t for a tutorial on using Emacs.
616 Type C-h i to enter Info, which you can use to read GNU documentation.")
617 (insert (substitute-command-keys
618 (format "Type %s for help; \\[advertised-undo] to undo changes. (`C-' means use CTRL key.)
619 To kill the Emacs job, type \\[save-buffers-kill-emacs].
620 Type \\[help-with-tutorial] for a tutorial on using Emacs.
621 Type \\[info] to enter Info, which you can use to read GNU documentation."
622 (let ((where (where-is-internal
623 'help-command nil t
)))
625 (key-description where
)
628 ;; Windows and MSDOS (currently) do not count as
629 ;; window systems, but do have mouse support.
630 (if (or (memq system-type
'(msdos windowsnt
))
633 C-mouse-3 (third mouse button, with Control) gets a mode-specific menu."))
635 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying
)
636 (eq (key-binding "\C-h\C-d") 'describe-distribution
)
637 (eq (key-binding "\C-h\C-w") 'describe-no-warranty
))
640 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
641 You may give out copies of Emacs; type C-h C-c to see the conditions.
642 Type C-h C-d for information on getting the latest version.")
643 (insert (substitute-command-keys
645 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
646 You may give out copies of Emacs; type \\[describe-copying] to see the conditions.
647 Type \\[describe-distribution] for information on getting the latest version.")))
648 (set-buffer-modified-p nil
)
651 ;; In case the Emacs server has already selected
652 ;; another buffer, erase the one our message is in.
653 (set-buffer (get-buffer "*scratch*"))
655 (set-buffer-modified-p nil
)))))
656 ;; Delay 2 seconds after the init file error message
657 ;; was displayed, so user can read it.
658 (if init-file-had-error
660 (let ((dir command-line-default-directory
)
664 (while command-line-args-left
665 (let* ((argi (car command-line-args-left
))
667 ;; This includes our standard options' long versions
668 ;; and long versions of what's on command-switch-alist.
670 (append '(("--funcall") ("--load") ("--insert") ("--kill")
672 (mapcar '(lambda (elt)
673 (list (concat "-" (car elt
))))
674 command-switch-alist
)))
675 tem argval completion
676 ;; List of directories specified in -L/--directory,
677 ;; in reverse of the order specified.
679 (initial-load-path load-path
))
680 (setq command-line-args-left
(cdr command-line-args-left
))
682 ;; Convert long options to ordinary options
683 ;; and separate out an attached option argument into argval.
684 (if (string-match "^--[^=]*=" argi
)
685 (setq argval
(substring argi
(match-end 0))
686 argi
(substring argi
0 (1- (match-end 0)))))
687 (setq completion
(try-completion argi longopts
))
688 (if (eq completion t
)
689 (setq argi
(substring argi
1))
690 (if (stringp completion
)
691 (let ((elt (assoc completion longopts
)))
693 (error "Option `%s' is ambiguous" argi
))
694 (setq argi
(substring (car elt
) 1)))
695 (setq argval nil argi orig-argi
)))
697 ;; Execute the option.
698 (cond ((setq tem
(assoc argi command-switch-alist
))
700 (let ((command-line-args-left
701 (cons argval command-line-args-left
)))
702 (funcall (cdr tem
) argi
))
703 (funcall (cdr tem
) argi
)))
704 ((or (string-equal argi
"-f") ;what the manual claims
705 (string-equal argi
"-funcall")
706 (string-equal argi
"-e")) ; what the source used to say
708 (setq tem
(intern argval
))
709 (setq tem
(intern (car command-line-args-left
)))
710 (setq command-line-args-left
(cdr command-line-args-left
)))
711 (if (arrayp (symbol-function tem
))
712 (command-execute tem
)
714 ;; Set the default directory as specified in -L.
715 ((or (string-equal argi
"-L")
716 (string-equal argi
"-directory"))
719 (setq tem
(car command-line-args-left
)
720 command-line-args-left
(cdr command-line-args-left
)))
721 (setq extra-load-path
722 (cons (expand-file-name tem
) extra-load-path
))
723 (setq load-path
(append (nreverse extra-load-path
)
725 ((or (string-equal argi
"-l")
726 (string-equal argi
"-load"))
729 (setq tem
(car command-line-args-left
)
730 command-line-args-left
(cdr command-line-args-left
)))
732 ;; Take file from default dir if it exists there;
733 ;; otherwise let `load' search for it.
734 (if (file-exists-p (expand-file-name file
))
735 (setq file
(expand-file-name file
)))
737 ((string-equal argi
"-insert")
738 (or (stringp (car command-line-args-left
))
739 (error "File name omitted from `-insert' option"))
742 (setq tem
(car command-line-args-left
)
743 command-line-args-left
(cdr command-line-args-left
)))
744 (insert-file-contents tem
))
745 ((string-equal argi
"-kill")
747 ((string-match "^\\+[0-9]+\\'" argi
)
748 (setq line
(string-to-int argi
)))
750 ;; We have almost exhausted our options. See if the
751 ;; user has made any other command-line options available
752 (let ((hooks command-line-functions
);; lrs 7/31/89
755 (not (setq did-hook
(funcall (car hooks
)))))
756 (setq hooks
(cdr hooks
)))
758 ;; Ok, presume that the argument is a file name
760 (setq file-count
(1+ file-count
))
761 (cond ((= file-count
1)
762 (setq first-file-buffer
763 (find-file (expand-file-name argi dir
))))
765 (find-file-other-window (expand-file-name argi dir
))))
769 ;; If 3 or more files visited, and not all visible,
770 ;; show user what they all are.
772 (or (get-buffer-window first-file-buffer
)
773 (progn (other-window 1)
776 ;;; startup.el ends here