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