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