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