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 (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 (custom-reevaluate-setting 'focus-follows-mouse)
788
789 (normal-erase-is-backspace-setup-frame)
790
791 ;; Register default TTY colors for the case the terminal hasn't a
792 ;; terminal init file. We do this regardles of whether the terminal
793 ;; supports colors or not and regardless the current display type,
794 ;; since users can connect to color-capable terminals and also
795 ;; switch color support on or off in mid-session by setting the
796 ;; tty-color-mode frame parameter.
797 (tty-register-default-colors)
798
799 ;; Record whether the tool-bar is present before the user and site
800 ;; init files are processed. frame-notice-user-settings uses this
801 ;; to determine if the tool-bar has been disabled by the init files,
802 ;; and the frame needs to be resized.
803 (when (fboundp 'frame-notice-user-settings)
804 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
805 (assq 'tool-bar-lines default-frame-alist))))
806 (setq tool-bar-originally-present
807 (and tool-bar-lines
808 (cdr tool-bar-lines)
809 (not (eq 0 (cdr tool-bar-lines)))))))
810
811 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
812 (old-font-list-limit font-list-limit)
813 (old-face-ignored-fonts face-ignored-fonts))
814
815 ;; Run the site-start library if it exists. The point of this file is
816 ;; that it is run before .emacs. There is no point in doing this after
817 ;; .emacs; that is useless.
818 (if site-run-file
819 (load site-run-file t t))
820
821 ;; Sites should not disable this. Only individuals should disable
822 ;; the startup message.
823 (setq inhibit-startup-message nil)
824
825 ;; Warn for invalid user name.
826 (when init-file-user
827 (if (string-match "[~/:\n]" init-file-user)
828 (display-warning 'initialization
829 (format "Invalid user name %s"
830 init-file-user)
831 :error)
832 (if (file-directory-p (expand-file-name
833 ;; We don't support ~USER on MS-Windows except
834 ;; for the current user, and always load .emacs
835 ;; from the current user's home directory (see
836 ;; below). So always check "~", even if invoked
837 ;; with "-u USER", or if $USER or $LOGNAME are
838 ;; set to something different.
839 (if (eq system-type 'windows-nt)
840 "~"
841 (concat "~" init-file-user))))
842 nil
843 (display-warning 'initialization
844 (format "User %s has no home directory"
845 init-file-user)
846 :error))))
847
848 ;; Load that user's init file, or the default one, or none.
849 (let (debug-on-error-from-init-file
850 debug-on-error-should-be-set
851 (debug-on-error-initial
852 (if (eq init-file-debug t) 'startup init-file-debug))
853 (orig-enable-multibyte default-enable-multibyte-characters))
854 (let ((debug-on-error debug-on-error-initial)
855 ;; This function actually reads the init files.
856 (inner
857 (function
858 (lambda ()
859 (if init-file-user
860 (let ((user-init-file-1
861 (cond
862 ((eq system-type 'ms-dos)
863 (concat "~" init-file-user "/_emacs"))
864 ((eq system-type 'windows-nt)
865 ;; Prefer .emacs on Windows.
866 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
867 "~/.emacs"
868 ;; Also support _emacs for compatibility.
869 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
870 "~/_emacs"
871 ;; But default to .emacs if _emacs does not exist.
872 "~/.emacs")))
873 ((eq system-type 'vax-vms)
874 "sys$login:.emacs")
875 (t
876 (concat "~" init-file-user "/.emacs")))))
877 ;; This tells `load' to store the file name found
878 ;; into user-init-file.
879 (setq user-init-file t)
880 (load user-init-file-1 t t)
881
882 (when (eq user-init-file t)
883 ;; If we did not find ~/.emacs, try
884 ;; ~/.emacs.d/init.el.
885 (let ((otherfile
886 (expand-file-name
887 "init"
888 (file-name-as-directory
889 (concat "~" init-file-user "/.emacs.d")))))
890 (load otherfile t t)
891
892 ;; If we did not find the user's init file,
893 ;; set user-init-file conclusively.
894 ;; Don't let it be set from default.el.
895 (when (eq user-init-file t)
896 (setq user-init-file user-init-file-1))))
897
898 ;; If we loaded a compiled file, set
899 ;; `user-init-file' to the source version if that
900 ;; exists.
901 (when (and user-init-file
902 (equal (file-name-extension user-init-file)
903 "elc"))
904 (let* ((source (file-name-sans-extension user-init-file))
905 (alt (concat source ".el")))
906 (setq source (cond ((file-exists-p alt) alt)
907 ((file-exists-p source) source)
908 (t nil)))
909 (when source
910 (when (file-newer-than-file-p source user-init-file)
911 (message "Warning: %s is newer than %s"
912 source user-init-file)
913 (sit-for 1))
914 (setq user-init-file source))))
915
916 (unless inhibit-default-init
917 (let ((inhibit-startup-message nil))
918 ;; Users are supposed to be told their rights.
919 ;; (Plus how to get help and how to undo.)
920 ;; Don't you dare turn this off for anyone
921 ;; except yourself.
922 (load "default" t t)))))))))
923 (if init-file-debug
924 ;; Do this without a condition-case if the user wants to debug.
925 (funcall inner)
926 (condition-case error
927 (progn
928 (funcall inner)
929 (setq init-file-had-error nil))
930 (error
931 (let ((message-log-max nil))
932 (save-excursion
933 (set-buffer (get-buffer-create "*Messages*"))
934 (insert "\n\n"
935 (format "An error has occurred while loading `%s':\n\n"
936 user-init-file)
937 (format "%s%s%s"
938 (get (car error) 'error-message)
939 (if (cdr error) ": " "")
940 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
941 "\n\n"
942 "To ensure normal operation, you should investigate and remove the\n"
943 "cause of the error in your initialization file. Start Emacs with\n"
944 "the `--debug-init' option to view a complete error backtrace.\n\n"))
945 (message "Error in init file: %s%s%s"
946 (get (car error) 'error-message)
947 (if (cdr error) ": " "")
948 (mapconcat 'prin1-to-string (cdr error) ", "))
949 (let ((pop-up-windows nil))
950 (pop-to-buffer "*Messages*"))
951 (setq init-file-had-error t)))))
952
953 (if (and deactivate-mark transient-mark-mode)
954 (with-current-buffer (window-buffer)
955 (deactivate-mark)))
956
957 ;; If the user has a file of abbrevs, read it.
958 (if (file-exists-p abbrev-file-name)
959 (quietly-read-abbrev-file abbrev-file-name))
960
961 ;; If the abbrevs came entirely from the init file or the
962 ;; abbrevs file, they do not need saving.
963 (setq abbrevs-changed nil)
964
965 ;; If we can tell that the init file altered debug-on-error,
966 ;; arrange to preserve the value that it set up.
967 (or (eq debug-on-error debug-on-error-initial)
968 (setq debug-on-error-should-be-set t
969 debug-on-error-from-init-file debug-on-error)))
970 (if debug-on-error-should-be-set
971 (setq debug-on-error debug-on-error-from-init-file))
972 (unless (or default-enable-multibyte-characters
973 (eq orig-enable-multibyte default-enable-multibyte-characters))
974 ;; Init file changed to unibyte. Reset existing multibyte
975 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
976 ;; Arguably this should only be done if they're free of
977 ;; multibyte characters.
978 (mapcar (lambda (buffer)
979 (with-current-buffer buffer
980 (if enable-multibyte-characters
981 (set-buffer-multibyte nil))))
982 (buffer-list))
983 ;; Also re-set the language environment in case it was
984 ;; originally done before unibyte was set and is sensitive to
985 ;; unibyte (display table, terminal coding system &c).
986 (set-language-environment current-language-environment)))
987
988 ;; Do this here in case the init file sets mail-host-address.
989 (if (equal user-mail-address "")
990 (setq user-mail-address (or (getenv "EMAIL")
991 (concat (user-login-name) "@"
992 (or mail-host-address
993 (system-name))))))
994
995 ;; Originally face attributes were specified via
996 ;; `font-lock-face-attributes'. Users then changed the default
997 ;; face attributes by setting that variable. However, we try and
998 ;; be back-compatible and respect its value if set except for
999 ;; faces where M-x customize has been used to save changes for the
1000 ;; face.
1001 (when (boundp 'font-lock-face-attributes)
1002 (let ((face-attributes font-lock-face-attributes))
1003 (while face-attributes
1004 (let* ((face-attribute (pop face-attributes))
1005 (face (car face-attribute)))
1006 ;; Rustle up a `defface' SPEC from a
1007 ;; `font-lock-face-attributes' entry.
1008 (unless (get face 'saved-face)
1009 (let ((foreground (nth 1 face-attribute))
1010 (background (nth 2 face-attribute))
1011 (bold-p (nth 3 face-attribute))
1012 (italic-p (nth 4 face-attribute))
1013 (underline-p (nth 5 face-attribute))
1014 face-spec)
1015 (when foreground
1016 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1017 (when background
1018 (setq face-spec (cons ':background (cons background face-spec))))
1019 (when bold-p
1020 (setq face-spec (append '(:weight bold) face-spec)))
1021 (when italic-p
1022 (setq face-spec (append '(:slant italic) face-spec)))
1023 (when underline-p
1024 (setq face-spec (append '(:underline t) face-spec)))
1025 (face-spec-set face (list (list t face-spec)) nil)))))))
1026
1027 ;; If parameter have been changed in the init file which influence
1028 ;; face realization, clear the face cache so that new faces will
1029 ;; be realized.
1030 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1031 (eq font-list-limit old-font-list-limit)
1032 (eq face-ignored-fonts old-face-ignored-fonts))
1033 (clear-face-cache)))
1034
1035 (run-hooks 'after-init-hook)
1036
1037 ;; Decode all default-directory.
1038 (if (and default-enable-multibyte-characters locale-coding-system)
1039 (save-excursion
1040 (dolist (elt (buffer-list))
1041 (set-buffer elt)
1042 (if default-directory
1043 (setq default-directory
1044 (decode-coding-string default-directory
1045 locale-coding-system t))))
1046 (setq command-line-default-directory
1047 (decode-coding-string command-line-default-directory
1048 locale-coding-system t))))
1049
1050 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1051 (if (get-buffer "*scratch*")
1052 (with-current-buffer "*scratch*"
1053 (if (eq major-mode 'fundamental-mode)
1054 (funcall initial-major-mode))))
1055
1056 ;; Load library for our terminal type.
1057 ;; User init file can set term-file-prefix to nil to prevent this.
1058 (unless (or noninteractive
1059 initial-window-system)
1060 (tty-run-terminal-initialization (selected-frame)))
1061
1062 ;; Update the out-of-memory error message based on user's key bindings
1063 ;; for save-some-buffers.
1064 (setq memory-signal-data
1065 (list 'error
1066 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1067
1068 ;; Process the remaining args.
1069 (command-line-1 (cdr command-line-args))
1070
1071 ;; If -batch, terminate after processing the command options.
1072 (if noninteractive (kill-emacs t))
1073
1074 ;; Run emacs-session-restore (session management) if started by
1075 ;; the session manager and we have a session manager connection.
1076 (if (and (boundp 'x-session-previous-id)
1077 (stringp x-session-previous-id))
1078 (with-no-warnings
1079 (emacs-session-restore x-session-previous-id))))
1080
1081 (defcustom initial-scratch-message (purecopy "\
1082 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1083 ;; If you want to create a file, visit that file with C-x C-f,
1084 ;; then enter the text in that file's own buffer.
1085
1086 ")
1087 "Initial message displayed in *scratch* buffer at startup.
1088 If this is nil, no message will be displayed.
1089 If `inhibit-splash-screen' is non-nil, then no message is displayed,
1090 regardless of the value of this variable."
1091 :type '(choice (text :tag "Message")
1092 (const :tag "none" nil))
1093 :group 'initialization)
1094
1095 \f
1096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1097 ;;; Fancy splash screen
1098 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1099
1100 (defvar fancy-splash-text
1101 '((:face (variable-pitch :weight bold)
1102 "Important Help menu items:\n"
1103 :face variable-pitch
1104 (lambda ()
1105 (let* ((en "TUTORIAL")
1106 (tut (or (get-language-info current-language-environment
1107 'tutorial)
1108 en))
1109 (title (with-temp-buffer
1110 (insert-file-contents
1111 (expand-file-name tut data-directory)
1112 nil 0 256)
1113 (search-forward ".")
1114 (buffer-substring (point-min) (1- (point))))))
1115 ;; If there is a specific tutorial for the current language
1116 ;; environment and it is not English, append its title.
1117 (concat
1118 "Emacs Tutorial\tLearn how to use Emacs efficiently"
1119 (if (string= en tut)
1120 ""
1121 (concat " (" title ")"))
1122 "\n")))
1123 :face variable-pitch "\
1124 Emacs FAQ\tFrequently asked questions and answers
1125 View Emacs Manual\tView the Emacs manual using Info
1126 Absence of Warranty\tGNU Emacs comes with "
1127 :face (variable-pitch :slant oblique)
1128 "ABSOLUTELY NO WARRANTY\n"
1129 :face variable-pitch
1130 "\
1131 Copying Conditions\tConditions for redistributing and changing Emacs
1132 Getting New Versions\tHow to obtain the latest version of Emacs
1133 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1134 (:face (variable-pitch :weight bold)
1135 "Useful File menu items:\n"
1136 :face variable-pitch "\
1137 Exit Emacs\t\t(Or type Control-x followed by Control-c)
1138 Recover Crashed Session\tRecover files you were editing before a crash
1139
1140
1141
1142
1143
1144 "
1145 ))
1146 "A list of texts to show in the middle part of splash screens.
1147 Each element in the list should be a list of strings or pairs
1148 `:face FACE', like `fancy-splash-insert' accepts them.")
1149
1150
1151 (defgroup fancy-splash-screen ()
1152 "Fancy splash screen when Emacs starts."
1153 :version "21.1"
1154 :group 'initialization)
1155
1156
1157 (defcustom fancy-splash-delay 7
1158 "*Delay in seconds between splash screens."
1159 :group 'fancy-splash-screen
1160 :type 'integer)
1161
1162
1163 (defcustom fancy-splash-max-time 30
1164 "*Show splash screens for at most this number of seconds.
1165 Values less than twice `fancy-splash-delay' are ignored."
1166 :group 'fancy-splash-screen
1167 :type 'integer)
1168
1169
1170 (defcustom fancy-splash-image nil
1171 "*The image to show in the splash screens, or nil for defaults."
1172 :group 'fancy-splash-screen
1173 :type '(choice (const :tag "Default" nil)
1174 (file :tag "File")))
1175
1176
1177 ;; These are temporary storage areas for the splash screen display.
1178
1179 (defvar fancy-current-text nil)
1180 (defvar fancy-splash-help-echo nil)
1181 (defvar fancy-splash-stop-time nil)
1182 (defvar fancy-splash-outer-buffer nil)
1183
1184 (defun fancy-splash-insert (&rest args)
1185 "Insert text into the current buffer, with faces.
1186 Arguments from ARGS should be either strings, functions called
1187 with no args that return a string, or pairs `:face FACE',
1188 where FACE is a valid face specification, as it can be used with
1189 `put-text-property'."
1190 (let ((current-face nil))
1191 (while args
1192 (if (eq (car args) :face)
1193 (setq args (cdr args) current-face (car args))
1194 (insert (propertize (let ((it (car args)))
1195 (if (functionp it)
1196 (funcall it)
1197 it))
1198 'face current-face
1199 'help-echo fancy-splash-help-echo)))
1200 (setq args (cdr args)))))
1201
1202
1203 (defun fancy-splash-head ()
1204 "Insert the head part of the splash screen into the current buffer."
1205 (let* ((image-file (cond ((stringp fancy-splash-image)
1206 fancy-splash-image)
1207 ((and (display-color-p)
1208 (image-type-available-p 'xpm))
1209 (if (and (fboundp 'x-display-planes)
1210 (= (funcall 'x-display-planes) 8))
1211 "splash8.xpm"
1212 "splash.xpm"))
1213 (t "splash.pbm")))
1214 (img (create-image image-file))
1215 (image-width (and img (car (image-size img))))
1216 (window-width (window-width (selected-window))))
1217 (when img
1218 (when (> window-width image-width)
1219 ;; Center the image in the window.
1220 (insert (propertize " " 'display
1221 `(space :align-to (+ center (-0.5 . ,img)))))
1222
1223 ;; Change the color of the XPM version of the splash image
1224 ;; so that it is visible with a dark frame background.
1225 (when (and (memq 'xpm img)
1226 (eq (frame-parameter nil 'background-mode) 'dark))
1227 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1228
1229 ;; Insert the image with a help-echo and a keymap.
1230 (let ((map (make-sparse-keymap))
1231 (help-echo "mouse-2: browse http://www.gnu.org/"))
1232 (define-key map [mouse-2]
1233 (lambda ()
1234 (interactive)
1235 (browse-url "http://www.gnu.org/")
1236 (throw 'exit nil)))
1237 (define-key map [down-mouse-2] 'ignore)
1238 (define-key map [up-mouse-2] 'ignore)
1239 (insert-image img (propertize "xxx" 'help-echo help-echo
1240 'keymap map)))
1241 (insert "\n"))))
1242 (fancy-splash-insert
1243 :face '(variable-pitch :foreground "red")
1244 (if (eq system-type 'gnu/linux)
1245 "GNU Emacs is one component of the GNU/Linux operating system."
1246 "GNU Emacs is one component of the GNU operating system."))
1247 (insert "\n")
1248 (fancy-splash-insert
1249 :face 'variable-pitch
1250 "You can do basic editing with the menu bar and scroll bar \
1251 using the mouse.\n\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 Meta-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 (if hide-on-input
1344 (let ((old-hourglass display-hourglass)
1345 (fancy-splash-outer-buffer (current-buffer))
1346 splash-buffer
1347 (old-minor-mode-map-alist minor-mode-map-alist)
1348 (old-emulation-mode-map-alists emulation-mode-map-alists)
1349 (frame (fancy-splash-frame))
1350 timer)
1351 (save-selected-window
1352 (select-frame frame)
1353 (switch-to-buffer "GNU Emacs")
1354 (setq splash-buffer (current-buffer))
1355 (catch 'stop-splashing
1356 (unwind-protect
1357 (let* ((map (make-sparse-keymap))
1358 (cursor-type nil)
1359 (overriding-local-map map)
1360 ;; Catch if our frame is deleted; the delete-frame
1361 ;; event is unreliable and is handled by
1362 ;; `special-event-map' anyway.
1363 (delete-frame-functions (cons 'fancy-splash-delete-frame
1364 delete-frame-functions)))
1365 (define-key map [t] 'fancy-splash-default-action)
1366 (define-key map [mouse-movement] 'ignore)
1367 (define-key map [mode-line t] 'ignore)
1368 (define-key map [select-window] 'ignore)
1369 (setq display-hourglass nil
1370 minor-mode-map-alist nil
1371 emulation-mode-map-alists nil
1372 buffer-undo-list t
1373 mode-line-format (propertize "---- %b %-"
1374 'face 'mode-line-buffer-id)
1375 fancy-splash-stop-time (+ (float-time)
1376 fancy-splash-max-time)
1377 timer (run-with-timer 0 fancy-splash-delay
1378 #'fancy-splash-screens-1
1379 splash-buffer))
1380 (message "%s" (startup-echo-area-message))
1381 (recursive-edit))
1382 (cancel-timer timer)
1383 (setq display-hourglass old-hourglass
1384 minor-mode-map-alist old-minor-mode-map-alist
1385 emulation-mode-map-alists old-emulation-mode-map-alists)
1386 (kill-buffer splash-buffer)
1387 (when (frame-live-p frame)
1388 (select-frame frame)
1389 (switch-to-buffer fancy-splash-outer-buffer))))))
1390 ;; If hide-on-input is nil, don't hide the buffer on input.
1391 (if (or (window-minibuffer-p)
1392 (window-dedicated-p (selected-window)))
1393 (pop-to-buffer (current-buffer))
1394 (switch-to-buffer "*About GNU Emacs*"))
1395 (setq buffer-read-only nil)
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 (insert "\n"))
1406 (skip-chars-backward "\n")
1407 (delete-region (point) (point-max))
1408 (insert "\n")
1409 (fancy-splash-tail)
1410 (set-buffer-modified-p nil)
1411 (setq buffer-read-only t)
1412 (if (and view-read-only (not view-mode))
1413 (view-mode-enter nil 'kill-buffer))
1414 (goto-char (point-min)))))
1415
1416
1417 (defun fancy-splash-frame ()
1418 "Return the frame to use for the fancy splash screen.
1419 Returning non-nil does not mean we should necessarily
1420 use the fancy splash screen, but if we do use it,
1421 we put it on this frame."
1422 (let (chosen-frame)
1423 (dolist (frame (append (frame-list) (list (selected-frame))))
1424 (if (and (frame-visible-p frame)
1425 (not (window-minibuffer-p (frame-selected-window frame))))
1426 (setq chosen-frame frame)))
1427 chosen-frame))
1428
1429 (defun use-fancy-splash-screens-p ()
1430 "Return t if fancy splash screens should be used."
1431 (when (and (display-graphic-p)
1432 (or (and (display-color-p)
1433 (image-type-available-p 'xpm))
1434 (image-type-available-p 'pbm)))
1435 (let ((frame (fancy-splash-frame)))
1436 (when frame
1437 (let* ((img (create-image (or fancy-splash-image
1438 (if (and (display-color-p)
1439 (image-type-available-p 'xpm))
1440 "splash.xpm" "splash.pbm"))))
1441 (image-height (and img (cdr (image-size img))))
1442 (window-height (1- (window-height (frame-selected-window frame)))))
1443 (> window-height (+ image-height 19)))))))
1444
1445
1446 (defun normal-splash-screen (&optional hide-on-input)
1447 "Display splash screen when Emacs starts."
1448 (let ((prev-buffer (current-buffer)))
1449 (unwind-protect
1450 (with-current-buffer (get-buffer-create "GNU Emacs")
1451 (setq buffer-read-only nil)
1452 (erase-buffer)
1453 (set (make-local-variable 'tab-width) 8)
1454 (if hide-on-input
1455 (set (make-local-variable 'mode-line-format)
1456 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1457
1458 (if pure-space-overflow
1459 (insert "\
1460 Warning Warning!!! Pure space overflow !!!Warning Warning
1461 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1462
1463 ;; The convention for this piece of code is that
1464 ;; each piece of output starts with one or two newlines
1465 ;; and does not end with any newlines.
1466 (insert "Welcome to GNU Emacs")
1467 (insert
1468 (if (eq system-type 'gnu/linux)
1469 ", one component of the GNU/Linux operating system.\n"
1470 ", a part of the GNU operating system.\n"))
1471
1472 (if hide-on-input
1473 (insert (substitute-command-keys
1474 (concat
1475 "\nType \\[recenter] to begin editing"
1476 (if (equal (buffer-name prev-buffer) "*scratch*")
1477 ".\n"
1478 " your file.\n")))))
1479
1480 (if (display-mouse-p)
1481 ;; The user can use the mouse to activate menus
1482 ;; so give help in terms of menu items.
1483 (progn
1484 (insert "\
1485 You can do basic editing with the menu bar and scroll bar using the mouse.
1486
1487 Useful File menu items:
1488 Exit Emacs (or type Control-x followed by Control-c)
1489 Recover Crashed Session Recover files you were editing before a crash
1490
1491 Important Help menu items:
1492 Emacs Tutorial Learn how to use Emacs efficiently
1493 Emacs FAQ Frequently asked questions and answers
1494 Read the Emacs Manual View the Emacs manual using Info
1495 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1496 Copying Conditions Conditions for redistributing and changing Emacs
1497 Getting New Versions How to obtain the latest version of Emacs
1498 More Manuals / Ordering Manuals How to order printed manuals from the FSF
1499 ")
1500 (insert "\n\n" (emacs-version)
1501 "
1502 Copyright (C) 2006 Free Software Foundation, Inc."))
1503
1504 ;; No mouse menus, so give help using kbd commands.
1505
1506 ;; If keys have their default meanings,
1507 ;; use precomputed string to save lots of time.
1508 (if (and (eq (key-binding "\C-h") 'help-command)
1509 (eq (key-binding "\C-xu") 'advertised-undo)
1510 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
1511 (eq (key-binding "\C-ht") 'help-with-tutorial)
1512 (eq (key-binding "\C-hi") 'info)
1513 (eq (key-binding "\C-hr") 'info-emacs-manual)
1514 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1515 (insert "
1516 Get help C-h (Hold down CTRL and press h)
1517 Emacs manual C-h r
1518 Emacs tutorial C-h t Undo changes C-x u
1519 Buy manuals C-h C-m Exit Emacs C-x C-c
1520 Browse manuals C-h i")
1521
1522 (insert (substitute-command-keys
1523 (format "\n
1524 Get help %s
1525 Emacs manual \\[info-emacs-manual]
1526 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1527 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-terminal]
1528 Browse manuals \\[info]"
1529 (let ((where (where-is-internal
1530 'help-command nil t)))
1531 (if where
1532 (key-description where)
1533 "M-x help"))))))
1534
1535 ;; Say how to use the menu bar with the keyboard.
1536 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1537 (eq (key-binding [f10]) 'tmm-menubar))
1538 (insert "
1539 Activate menubar F10 or ESC ` or M-`")
1540 (insert (substitute-command-keys "
1541 Activate menubar \\[tmm-menubar]")))
1542
1543 ;; Many users seem to have problems with these.
1544 (insert "
1545 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1546 If you have no Meta key, you may instead type ESC followed by the character.)")
1547
1548 (insert "\n\n" (emacs-version)
1549 "
1550 Copyright (C) 2006 Free Software Foundation, Inc.")
1551
1552 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1553 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1554 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1555 (insert
1556 "\n
1557 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1558 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1559 of Emacs and modify it; type C-h C-c to see the conditions.
1560 Type C-h C-d for information on getting the latest version.")
1561 (insert (substitute-command-keys
1562 "\n
1563 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1564 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1565 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1566 Type \\[describe-distribution] for information on getting the latest version."))))
1567
1568 ;; The rest of the startup screen is the same on all
1569 ;; kinds of terminals.
1570
1571 ;; Give information on recovering, if there was a crash.
1572 (and auto-save-list-file-prefix
1573 ;; Don't signal an error if the
1574 ;; directory for auto-save-list files
1575 ;; does not yet exist.
1576 (file-directory-p (file-name-directory
1577 auto-save-list-file-prefix))
1578 (directory-files
1579 (file-name-directory auto-save-list-file-prefix)
1580 nil
1581 (concat "\\`"
1582 (regexp-quote (file-name-nondirectory
1583 auto-save-list-file-prefix)))
1584 t)
1585 (insert "\n\nIf an Emacs session crashed recently, "
1586 "type Meta-x recover-session RET\nto recover"
1587 " the files you were editing."))
1588
1589 ;; Display the input that we set up in the buffer.
1590 (set-buffer-modified-p nil)
1591 (setq buffer-read-only t)
1592 (if (and view-read-only (not view-mode))
1593 (view-mode-enter nil 'kill-buffer))
1594 (goto-char (point-min))
1595 (if hide-on-input
1596 (if (or (window-minibuffer-p)
1597 (window-dedicated-p (selected-window)))
1598 ;; If hide-on-input is nil, creating a new frame will
1599 ;; generate enough events that the subsequent `sit-for'
1600 ;; will immediately return anyway.
1601 nil ;; (pop-to-buffer (current-buffer))
1602 (save-window-excursion
1603 (switch-to-buffer (current-buffer))
1604 (sit-for 120))
1605 (condition-case nil
1606 (switch-to-buffer (current-buffer))))))
1607 ;; Unwind ... ensure splash buffer is killed
1608 (if hide-on-input
1609 (kill-buffer "GNU Emacs")
1610 (switch-to-buffer "GNU Emacs")
1611 (rename-buffer "*About GNU Emacs*" t)))))
1612
1613
1614 (defun startup-echo-area-message ()
1615 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1616 "For information about the GNU Project and its goals, type C-h C-p."
1617 (substitute-command-keys
1618 "For information about the GNU Project and its goals, type \
1619 \\[describe-project].")))
1620
1621
1622 (defun display-startup-echo-area-message ()
1623 (let ((resize-mini-windows t))
1624 (or noninteractive ;(input-pending-p) init-file-had-error
1625 ;; t if the init file says to inhibit the echo area startup message.
1626 (and inhibit-startup-echo-area-message
1627 user-init-file
1628 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1629 (equal inhibit-startup-echo-area-message
1630 (if (equal init-file-user "")
1631 (user-login-name)
1632 init-file-user)))
1633 ;; Wasn't set with custom; see if .emacs has a setq.
1634 (let ((buffer (get-buffer-create " *temp*")))
1635 (prog1
1636 (condition-case nil
1637 (save-excursion
1638 (set-buffer buffer)
1639 (insert-file-contents user-init-file)
1640 (re-search-forward
1641 (concat
1642 "([ \t\n]*setq[ \t\n]+"
1643 "inhibit-startup-echo-area-message[ \t\n]+"
1644 (regexp-quote
1645 (prin1-to-string
1646 (if (equal init-file-user "")
1647 (user-login-name)
1648 init-file-user)))
1649 "[ \t\n]*)")
1650 nil t))
1651 (error nil))
1652 (kill-buffer buffer)))))
1653 ;; display-splash-screen at the end of command-line-1 calls
1654 ;; use-fancy-splash-screens-p. This can cause image.el to be
1655 ;; loaded, putting "Loading image... done" in the echo area.
1656 ;; This hides startup-echo-area-message. So
1657 ;; use-fancy-splash-screens-p is called here simply to get the
1658 ;; loading of image.el (if needed) out of the way before
1659 ;; display-startup-echo-area-message runs.
1660 (progn
1661 (use-fancy-splash-screens-p)
1662 (message "%s" (startup-echo-area-message))))))
1663
1664
1665 (defun display-splash-screen (&optional hide-on-input)
1666 "Display splash screen according to display.
1667 Fancy splash screens are used on graphic displays,
1668 normal otherwise.
1669 With a prefix argument, any user input hides the splash screen."
1670 (interactive "P")
1671 ;; Prevent recursive calls from server-process-filter.
1672 (if (not (get-buffer "GNU Emacs"))
1673 (if (use-fancy-splash-screens-p)
1674 (fancy-splash-screens hide-on-input)
1675 (normal-splash-screen hide-on-input))))
1676
1677 (defun command-line-1 (command-line-args-left)
1678 (display-startup-echo-area-message)
1679
1680 ;; Delay 2 seconds after an init file error message
1681 ;; was displayed, so user can read it.
1682 (when init-file-had-error
1683 (sit-for 2))
1684
1685 (when (and pure-space-overflow
1686 (not noninteractive))
1687 (display-warning
1688 'initialization
1689 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1690 :warning))
1691
1692 (when command-line-args-left
1693 ;; We have command args; process them.
1694 (let ((dir command-line-default-directory)
1695 (file-count 0)
1696 first-file-buffer
1697 tem
1698 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1699 ;; if foo is intended to be found in DIR.
1700 ;;
1701 ;; ;; The directories listed in --directory/-L options will *appear*
1702 ;; ;; at the front of `load-path' in the order they appear on the
1703 ;; ;; command-line. We cannot do this by *placing* them at the front
1704 ;; ;; in the order they appear, so we need this variable to hold them,
1705 ;; ;; temporarily.
1706 ;; extra-load-path
1707 ;;
1708 ;; To DTRT we keep track of the splice point and modify `load-path'
1709 ;; straight away upon any --directory/-L option.
1710 splice
1711 just-files ;; t if this follows the magic -- option.
1712 ;; This includes our standard options' long versions
1713 ;; and long versions of what's on command-switch-alist.
1714 (longopts
1715 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1716 ("--directory") ("--eval") ("--execute") ("--no-splash")
1717 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1718 (mapcar (lambda (elt)
1719 (list (concat "-" (car elt))))
1720 command-switch-alist)))
1721 (line 0)
1722 (column 0))
1723
1724 ;; Add the long X options to longopts.
1725 (dolist (tem command-line-x-option-alist)
1726 (if (string-match "^--" (car tem))
1727 (push (list (car tem)) longopts)))
1728
1729 ;; Loop, processing options.
1730 (while command-line-args-left
1731 (let* ((argi (car command-line-args-left))
1732 (orig-argi argi)
1733 argval completion)
1734 (setq command-line-args-left (cdr command-line-args-left))
1735
1736 ;; Do preliminary decoding of the option.
1737 (if just-files
1738 ;; After --, don't look for options; treat all args as files.
1739 (setq argi "")
1740 ;; Convert long options to ordinary options
1741 ;; and separate out an attached option argument into argval.
1742 (when (string-match "^\\(--[^=]*\\)=" argi)
1743 (setq argval (substring argi (match-end 0))
1744 argi (match-string 1 argi)))
1745 (if (equal argi "--")
1746 (setq completion nil)
1747 (setq completion (try-completion argi longopts)))
1748 (if (eq completion t)
1749 (setq argi (substring argi 1))
1750 (if (stringp completion)
1751 (let ((elt (assoc completion longopts)))
1752 (or elt
1753 (error "Option `%s' is ambiguous" argi))
1754 (setq argi (substring (car elt) 1)))
1755 (setq argval nil
1756 argi orig-argi))))
1757
1758 ;; Execute the option.
1759 (cond ((setq tem (assoc argi command-switch-alist))
1760 (if argval
1761 (let ((command-line-args-left
1762 (cons argval command-line-args-left)))
1763 (funcall (cdr tem) argi))
1764 (funcall (cdr tem) argi)))
1765
1766 ((equal argi "-no-splash")
1767 (setq inhibit-startup-message t))
1768
1769 ((member argi '("-f" ; what the manual claims
1770 "-funcall"
1771 "-e")) ; what the source used to say
1772 (setq tem (intern (or argval (pop command-line-args-left))))
1773 (if (commandp tem)
1774 (command-execute tem)
1775 (funcall tem)))
1776
1777 ((member argi '("-eval" "-execute"))
1778 (eval (read (or argval (pop command-line-args-left)))))
1779
1780 ((member argi '("-L" "-directory"))
1781 (setq tem (expand-file-name
1782 (command-line-normalize-file-name
1783 (or argval (pop command-line-args-left)))))
1784 (cond (splice (setcdr splice (cons tem (cdr splice)))
1785 (setq splice (cdr splice)))
1786 (t (setq load-path (cons tem load-path)
1787 splice load-path))))
1788
1789 ((member argi '("-l" "-load"))
1790 (let* ((file (command-line-normalize-file-name
1791 (or argval (pop command-line-args-left))))
1792 ;; Take file from default dir if it exists there;
1793 ;; otherwise let `load' search for it.
1794 (file-ex (expand-file-name file)))
1795 (when (file-exists-p file-ex)
1796 (setq file file-ex))
1797 (load file nil t)))
1798
1799 ;; This is used to handle -script. It's not clear
1800 ;; we need to document it.
1801 ((member argi '("-scriptload"))
1802 (let* ((file (command-line-normalize-file-name
1803 (or argval (pop command-line-args-left))))
1804 ;; Take file from default dir.
1805 (file-ex (expand-file-name file)))
1806 (load file-ex nil t t)))
1807
1808 ((equal argi "-insert")
1809 (setq tem (or argval (pop command-line-args-left)))
1810 (or (stringp tem)
1811 (error "File name omitted from `-insert' option"))
1812 (insert-file-contents (command-line-normalize-file-name tem)))
1813
1814 ((equal argi "-kill")
1815 (kill-emacs t))
1816
1817 ;; This is for when they use --no-desktop with -q, or
1818 ;; don't load Desktop in their .emacs. If desktop.el
1819 ;; _is_ loaded, it will handle this switch, and we
1820 ;; won't see it by the time we get here.
1821 ((equal argi "-no-desktop")
1822 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
1823
1824 ((string-match "^\\+[0-9]+\\'" argi)
1825 (setq line (string-to-number argi)))
1826
1827 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1828 (setq line (string-to-number (match-string 1 argi))
1829 column (string-to-number (match-string 2 argi))))
1830
1831 ((setq tem (assoc argi command-line-x-option-alist))
1832 ;; Ignore X-windows options and their args if not using X.
1833 (setq command-line-args-left
1834 (nthcdr (nth 1 tem) command-line-args-left)))
1835
1836 ((member argi '("-find-file" "-file" "-visit"))
1837 ;; An explicit option to specify visiting a file.
1838 (setq tem (or argval (pop command-line-args-left)))
1839 (unless (stringp tem)
1840 (error "File name omitted from `%s' option" argi))
1841 (setq file-count (1+ file-count))
1842 (let ((file (expand-file-name
1843 (command-line-normalize-file-name tem) dir)))
1844 (if (= file-count 1)
1845 (setq first-file-buffer (find-file file))
1846 (find-file-other-window file)))
1847 (or (zerop line)
1848 (goto-line line))
1849 (setq line 0)
1850 (unless (< column 1)
1851 (move-to-column (1- column)))
1852 (setq column 0))
1853
1854 ((equal argi "--")
1855 (setq just-files t))
1856 (t
1857 ;; We have almost exhausted our options. See if the
1858 ;; user has made any other command-line options available
1859 (let ((hooks command-line-functions) ;; lrs 7/31/89
1860 (did-hook nil))
1861 (while (and hooks
1862 (not (setq did-hook (funcall (car hooks)))))
1863 (setq hooks (cdr hooks)))
1864 (if (not did-hook)
1865 ;; Presume that the argument is a file name.
1866 (progn
1867 (if (string-match "\\`-" argi)
1868 (error "Unknown option `%s'" argi))
1869 (setq file-count (1+ file-count))
1870 (let ((file
1871 (expand-file-name
1872 (command-line-normalize-file-name orig-argi)
1873 dir)))
1874 (if (= file-count 1)
1875 (setq first-file-buffer (find-file file))
1876 (find-file-other-window file)))
1877 (or (zerop line)
1878 (goto-line line))
1879 (setq line 0)
1880 (unless (< column 1)
1881 (move-to-column (1- column)))
1882 (setq column 0))))))))
1883
1884 ;; If 3 or more files visited, and not all visible,
1885 ;; show user what they all are. But leave the last one current.
1886 (and (> file-count 2)
1887 (not noninteractive)
1888 (not inhibit-startup-buffer-menu)
1889 (or (get-buffer-window first-file-buffer)
1890 (list-buffers)))))
1891
1892 ;; Maybe display a startup screen.
1893 (unless (or inhibit-startup-message
1894 noninteractive
1895 emacs-quick-startup)
1896 ;; Display a startup screen, after some preparations.
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 (run-hooks 'emacs-startup-hook)
1902 (and term-setup-hook
1903 (run-hooks 'term-setup-hook))
1904 (setq inhibit-startup-hooks t)
1905
1906 ;; It's important to notice the user settings before we
1907 ;; display the startup message; otherwise, the settings
1908 ;; won't take effect until the user gives the first
1909 ;; keystroke, and that's distracting.
1910 (when (fboundp 'frame-notice-user-settings)
1911 (frame-notice-user-settings))
1912
1913 ;; If there are no switches to process, we might as well
1914 ;; run this hook now, and there may be some need to do it
1915 ;; before doing any output.
1916 (when window-setup-hook
1917 (run-hooks 'window-setup-hook)
1918 ;; Don't let the hook be run twice.
1919 (setq window-setup-hook nil))
1920
1921 ;; Do this now to avoid an annoying delay if the user
1922 ;; clicks the menu bar during the sit-for.
1923 (when (display-popup-menus-p)
1924 (precompute-menubar-bindings))
1925 (with-no-warnings
1926 (setq menubar-bindings-done t))
1927
1928 ;; If *scratch* is selected and it is empty, insert an
1929 ;; initial message saying not to create a file there.
1930 (when (and initial-scratch-message
1931 (equal (buffer-name) "*scratch*")
1932 (= 0 (buffer-size)))
1933 (insert initial-scratch-message)
1934 (set-buffer-modified-p nil))
1935
1936 ;; If user typed input during all that work,
1937 ;; abort the startup screen. Otherwise, display it now.
1938 (unless (input-pending-p)
1939 (display-splash-screen t))))
1940
1941
1942 (defun command-line-normalize-file-name (file)
1943 "Collapse multiple slashes to one, to handle non-Emacs file names."
1944 (save-match-data
1945 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1946 ;; That is significant on some systems.
1947 ;; However, /// at the beginning is supposed to mean just /, not //.
1948 (if (string-match "^///+" file)
1949 (setq file (replace-match "/" t t file)))
1950 (while (string-match "//+" file 1)
1951 (setq file (replace-match "/" t t file)))
1952 file))
1953
1954 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
1955 ;;; startup.el ends here