1 ;;; startup.el --- process Emacs shell arguments
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
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)
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.
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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This file parses the command line and gets Emacs running. Options on
29 ;; the command line are handled in precedence order. The order is the
30 ;; one in the list below; first described means first handled. Options
31 ;; within each category (delimited by a bar) are handled in the order
32 ;; encountered on the command line.
34 ;; -------------------------
35 ;; -version Print Emacs version to stderr, then exit
36 ;; --version successfully right away.
37 ;; This option is handled by emacs.c
38 ;; -------------------------
39 ;; -help Print a short usage description and exit
40 ;; --help successfully right away.
41 ;; This option is handled by emacs.c
42 ;; -------------------------
43 ;; -nl Do not use shared memory (for systems that
44 ;; -no-shared-memory support this) for the dumped Emacs data.
45 ;; This option is handled by emacs.c
48 ;; --map-data This option is handled by emacs.c
49 ;; -------------------------
50 ;; -t FILE Use FILE as the name of the terminal.
51 ;; --terminal FILE Using this implies "-nw" also.
52 ;; This option is handled by emacs.c
53 ;; -------------------------
54 ;; -d DISPNAME Use DISPNAME as the name of the X
55 ;; -display DISPNAME display for the initial frame.
56 ;; --display DISPNAME This option is handled by emacs.c
57 ;; -------------------------
58 ;; -nw Do not use a windows system (but use the
59 ;; --no-window-system terminal instead.)
60 ;; This option is handled by emacs.c
61 ;; -------------------------
62 ;; -batch Execute noninteractively (messages go to stdout,
63 ;; --batch variable noninteractive set to t)
64 ;; This option is handled by emacs.c
65 ;; -------------------------
66 ;; -q Do not load user's init file and do not load
67 ;; -no-init-file "default.el". Regardless of this switch,
68 ;; --no-init-file "site-start" is still loaded.
69 ;; -------------------------
70 ;; -no-site-file Do not load "site-start.el". (This is the ONLY
71 ;; --no-site-file way to prevent loading that file.)
72 ;; -------------------------
73 ;; -no-splash Don't display a splash screen on startup.
75 ;; -------------------------
76 ;; -u USER Load USER's init file instead of the init
77 ;; -user USER file belonging to the user starting Emacs.
79 ;; -------------------------
80 ;; -debug-init Don't catch errors in init files; let the
81 ;; --debug-init debugger run.
82 ;; -------------------------
83 ;; -i ICONTYPE Set type of icon using when Emacs is
84 ;; -itype ICONTYPE iconified under X.
85 ;; --icon-type ICONTYPE This option is passed on to term/x-win.el
87 ;; -iconic Start Emacs iconified.
88 ;; --iconic This option is passed on to term/x-win.el
89 ;; -------------------------
90 ;; Various X options for colors/fonts/geometry/title etc.
91 ;; These options are passed on to term/x-win.el which see.
92 ;; -------------------------
99 ;; -L DIRNAME Add DIRNAME to load-path
100 ;; -directory DIRNAME
101 ;; --directory DIRNAME
103 ;; -l FILE Load and execute the Emacs lisp code
104 ;; -load FILE in FILE.
107 ;; -f FUNC Execute Emacs lisp function FUNC with
108 ;; -funcall FUNC no arguments. The "-e" form is outdated
109 ;; --funcall FUNC and should not be used. (It's a typo
110 ;; -e FUNC promoted to a feature.)
112 ;; -eval FORM Execute Emacs lisp form FORM.
117 ;; -insert FILE Insert the contents of FILE into buffer.
119 ;; -------------------------
120 ;; -kill Kill (exit) Emacs right away.
122 ;; -------------------------
126 (setq top-level '(normal-top-level))
128 (defvar command-line-processed nil
129 "Non-nil once command line has been processed.")
131 (defgroup initialization nil
132 "Emacs start-up procedure"
135 (defcustom inhibit-startup-message nil
136 "*Non-nil inhibits the initial startup message.
137 This is for use in your personal init file, once you are familiar
138 with the contents of the startup message."
140 :group 'initialization)
142 (defvaralias 'inhibit-splash-screen 'inhibit-startup-message)
144 (defcustom inhibit-startup-echo-area-message nil
145 "*Non-nil inhibits the initial startup echo area message.
146 Setting this variable takes effect
147 only if you do it with the customization buffer
148 or if your `.emacs' file contains a line of this form:
149 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
150 If your `.emacs' file is byte-compiled, use the following form instead:
151 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
152 Thus, someone else using a copy of your `.emacs' file will see
153 the startup message unless he personally acts to inhibit it."
154 :type '(choice (const :tag "Don't inhibit")
155 (string :tag "Enter your user name, to inhibit"))
156 :group 'initialization)
158 (defcustom inhibit-default-init nil
159 "*Non-nil inhibits loading the `default' library."
161 :group 'initialization)
163 (defcustom inhibit-startup-buffer-menu nil
164 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
166 :group 'initialization)
168 (defvar command-switch-alist nil
169 "Alist of command-line switches.
170 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
171 HANDLER-FUNCTION receives switch name as sole arg;
172 remaining command-line args are in the variable `command-line-args-left'.")
174 (defvar command-line-args-left nil
175 "List of command-line args not yet processed.")
177 (defvar command-line-functions nil ;; lrs 7/31/89
178 "List of functions to process unrecognized command-line arguments.
179 Each function should access the dynamically bound variables
180 `argi' (the current argument) and `command-line-args-left' (the remaining
181 arguments). The function should return non-nil only if it recognizes and
182 processes `argi'. If it does so, it may consume successive arguments by
183 altering `command-line-args-left' to remove them.")
185 (defvar command-line-default-directory nil
186 "Default directory to use for command line arguments.
187 This is normally copied from `default-directory' when Emacs starts.")
189 ;;; This is here, rather than in x-win.el, so that we can ignore these
190 ;;; options when we are not using X.
191 (defconst command-line-x-option-alist
192 '(("-bw" 1 x-handle-numeric-switch border-width)
193 ("-d" 1 x-handle-display)
194 ("-display" 1 x-handle-display)
195 ("-name" 1 x-handle-name-switch)
196 ("-title" 1 x-handle-switch title)
197 ("-T" 1 x-handle-switch title)
198 ("-r" 0 x-handle-switch reverse t)
199 ("-rv" 0 x-handle-switch reverse t)
200 ("-reverse" 0 x-handle-switch reverse t)
201 ("-reverse-video" 0 x-handle-switch reverse t)
202 ("-fn" 1 x-handle-switch font)
203 ("-font" 1 x-handle-switch font)
204 ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
205 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
206 ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
207 ("-ib" 1 x-handle-numeric-switch internal-border-width)
208 ("-g" 1 x-handle-geometry)
209 ("-lsp" 1 x-handle-numeric-switch line-spacing)
210 ("-geometry" 1 x-handle-geometry)
211 ("-fg" 1 x-handle-switch foreground-color)
212 ("-foreground" 1 x-handle-switch foreground-color)
213 ("-bg" 1 x-handle-switch background-color)
214 ("-background" 1 x-handle-switch background-color)
215 ("-ms" 1 x-handle-switch mouse-color)
216 ("-itype" 0 x-handle-switch icon-type t)
217 ("-i" 0 x-handle-switch icon-type t)
218 ("-iconic" 0 x-handle-iconic)
219 ("-xrm" 1 x-handle-xrm-switch)
220 ("-cr" 1 x-handle-switch cursor-color)
221 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
222 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
223 ("-bd" 1 x-handle-switch)
224 ("--border-width" 1 x-handle-numeric-switch border-width)
225 ("--display" 1 x-handle-display)
226 ("--name" 1 x-handle-name-switch)
227 ("--title" 1 x-handle-switch title)
228 ("--reverse-video" 0 x-handle-switch reverse t)
229 ("--font" 1 x-handle-switch font)
230 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
231 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
232 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
233 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
234 ("--geometry" 1 x-handle-geometry)
235 ("--foreground-color" 1 x-handle-switch foreground-color)
236 ("--background-color" 1 x-handle-switch background-color)
237 ("--mouse-color" 1 x-handle-switch mouse-color)
238 ("--icon-type" 0 x-handle-switch icon-type t)
239 ("--iconic" 0 x-handle-iconic)
240 ("--xrm" 1 x-handle-xrm-switch)
241 ("--cursor-color" 1 x-handle-switch cursor-color)
242 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
243 ("--line-spacing" 1 x-handle-numeric-switch line-spacing)
244 ("--border-color" 1 x-handle-switch border-width)
245 ("--smid" 1 x-handle-smid))
246 "Alist of X Windows options.
247 Each element has the form
248 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
249 where NAME is the option name string, NUMARGS is the number of arguments
250 that the option accepts, HANDLER is a function to call to handle the option.
251 FRAME-PARAM (optional) is the frame parameter this option specifies,
252 and VALUE is the value which is given to that frame parameter
253 \(most options use the argument for this, so VALUE is not present).")
255 (defvar before-init-hook nil
256 "Normal hook run after handling urgent options but before loading init files.")
258 (defvar after-init-hook nil
259 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
260 There is no `condition-case' around the running of these functions;
261 therefore, if you set `debug-on-error' non-nil in `.emacs',
262 an error in one of these functions will invoke the debugger.")
264 (defvar emacs-startup-hook nil
265 "Normal hook run after loading init files and handling the command line.")
267 (defvar term-setup-hook nil
268 "Normal hook run after loading terminal-specific Lisp code.
269 It also follows `emacs-startup-hook'. This hook exists for users to set,
270 so as to override the definitions made by the terminal-specific file.
271 Emacs never sets this variable itself.")
273 (defvar keyboard-type nil
274 "The brand of keyboard you are using.
275 This variable is used to define
276 the proper function and keypad keys for use under X. It is used in a
277 fashion analogous to the environment variable TERM.")
279 (defvar window-setup-hook nil
280 "Normal hook run to initialize window system display.
281 Emacs runs this hook after processing the command line arguments and loading
282 the user's init file.")
284 (defcustom initial-major-mode 'lisp-interaction-mode
285 "Major mode command symbol to use for the initial *scratch* buffer."
287 :group 'initialization)
289 (defcustom init-file-user nil
290 "Identity of user whose `.emacs' file is or was read.
291 The value is nil if `-q' or `--no-init-file' was specified,
292 meaning do not load any init file.
294 Otherwise, the value may be the null string, meaning use the init file
295 for the user that originally logged in, or it may be a
296 string containing a user's name meaning use that person's init file.
298 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
299 evaluates to the name of the directory where the `.emacs' file was
302 Setting `init-file-user' does not prevent Emacs from loading
303 `site-start.el'. The only way to do that is to use `--no-site-file'."
304 :type '(choice (const :tag "none" nil) string)
305 :group 'initialization)
307 (defcustom site-run-file "site-start"
308 "File containing site-wide run-time initializations.
309 This file is loaded at run-time before `~/.emacs'. It contains inits
310 that need to be in place for the entire site, but which, due to their
311 higher incidence of change, don't make sense to load into emacs'
312 dumped image. Thus, the run-time load order is: 1. file described in
313 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
315 Don't use the `site-start.el' file for things some users may not like.
316 Put them in `default.el' instead, so that users can more easily
317 override them. Users can prevent loading `default.el' with the `-q'
318 option or by setting `inhibit-default-init' in their own init files,
319 but inhibiting `site-start.el' requires `--no-site-file', which
321 :type '(choice (const :tag "none" nil) string)
322 :group 'initialization)
324 (defcustom mail-host-address nil
325 "*Name of this machine, for purposes of naming users."
326 :type '(choice (const nil) string)
329 (defcustom user-mail-address (if command-line-processed
330 (concat (user-login-name) "@"
331 (or mail-host-address
333 ;; Empty string means "not set yet".
335 "*Full mailing address of this user.
336 This is initialized based on `mail-host-address',
337 after your init file is read, in case it sets `mail-host-address'."
341 (defcustom auto-save-list-file-prefix
342 (cond ((eq system-type 'ms-dos)
343 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
344 "~/_emacs.d/auto-save.list/_s")
346 "~/.emacs.d/auto-save-list/.saves-"))
347 "Prefix for generating `auto-save-list-file-name'.
348 This is used after reading your `.emacs' file to initialize
349 `auto-save-list-file-name', by appending Emacs's pid and the system name,
350 if you have not already set `auto-save-list-file-name' yourself.
351 Directories in the prefix will be created if necessary.
352 Set this to nil if you want to prevent `auto-save-list-file-name'
353 from being initialized."
354 :type '(choice (const :tag "Don't record a session's auto save list" nil)
358 (defvar init-file-debug nil)
360 (defvar init-file-had-error nil)
362 (defvar normal-top-level-add-subdirs-inode-list nil)
364 (defun normal-top-level-add-subdirs-to-load-path ()
365 "Add all subdirectories of current directory to `load-path'.
366 More precisely, this uses only the subdirectories whose names
367 start with letters or digits; it excludes any subdirectory named `RCS'
368 or `CVS', and any subdirectory that contains a file named `.nosearch'."
371 (pending (list default-directory)))
372 ;; This loop does a breadth-first tree walk on DIR's subtree,
373 ;; putting each subdir into DIRS as its contents are examined.
375 (push (pop pending) dirs)
376 (let* ((this-dir (car dirs))
377 (contents (directory-files this-dir))
378 (default-directory this-dir)
379 (canonicalized (and (eq system-type 'windows-nt)
380 (untranslated-canonical-name this-dir))))
381 ;; The Windows version doesn't report meaningful inode
382 ;; numbers, so use the canonicalized absolute file name of the
383 ;; directory instead.
384 (setq attrs (or canonicalized
385 (nthcdr 10 (file-attributes this-dir))))
386 (unless (member attrs normal-top-level-add-subdirs-inode-list)
387 (push attrs normal-top-level-add-subdirs-inode-list)
388 (dolist (file contents)
389 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
390 (unless (member file '("." ".." "RCS" "CVS" "rcs" "cvs"))
391 (when (and (string-match "\\`[[:alnum:]]" file)
392 ;; Avoid doing a `stat' when it isn't necessary
393 ;; because that can cause trouble when an NFS server
395 (not (string-match "\\.elc?\\'" file))
396 (file-directory-p file))
397 (let ((expanded (expand-file-name file)))
398 (unless (file-exists-p (expand-file-name ".nosearch"
400 (setq pending (nconc pending (list expanded)))))))))))
401 (normal-top-level-add-to-load-path (cdr (nreverse dirs)))))
403 ;; This function is called from a subdirs.el file.
404 ;; It assumes that default-directory is the directory
405 ;; in which the subdirs.el file exists,
406 ;; and it adds to load-path the subdirs of that directory
407 ;; as specified in DIRS. Normally the elements of DIRS are relative.
408 (defun normal-top-level-add-to-load-path (dirs)
409 (let ((tail load-path)
410 (thisdir (directory-file-name default-directory)))
412 ;;Don't go all the way to the nil terminator.
414 (not (equal thisdir (car tail)))
415 (not (and (memq system-type '(ms-dos windows-nt))
416 (equal (downcase thisdir) (downcase (car tail))))))
417 (setq tail (cdr tail)))
418 ;;Splice the new section in.
420 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
422 (defun normal-top-level ()
423 (if command-line-processed
424 (message "Back to top level.")
425 (setq command-line-processed t)
426 ;; Give *Messages* the same default-directory as *scratch*,
427 ;; just to keep things predictable.
428 (let ((dir default-directory))
430 (set-buffer (get-buffer "*Messages*"))
431 (setq default-directory dir)))
432 ;; For root, preserve owner and group when editing files.
433 (if (equal (user-uid) 0)
434 (setq backup-by-copying-when-mismatch t))
435 ;; Look in each dir in load-path for a subdirs.el file.
436 ;; If we find one, load it, which will add the appropriate subdirs
437 ;; of that dir into load-path,
438 ;; Look for a leim-list.el file too. Loading it will register
439 ;; available input methods.
440 (let ((tail load-path)
443 (push (car tail) new)
445 (let ((default-directory (car tail)))
446 (load (expand-file-name "subdirs.el" (car tail)) t t t)))
448 (let ((default-directory (car tail)))
449 (load (expand-file-name "leim-list.el" (car tail)) t t t)))
450 (setq tail (cdr tail))))
451 (if (not (eq system-type 'vax-vms))
453 ;; If the PWD environment variable isn't accurate, delete it.
454 (let ((pwd (getenv "PWD")))
456 ;; Use FOO/., so that if FOO is a symlink, file-attributes
457 ;; describes the directory linked to, not FOO itself.
458 (or (equal (file-attributes
459 (concat (file-name-as-directory pwd) "."))
461 (concat (file-name-as-directory default-directory)
463 (setq process-environment
464 (delete (concat "PWD=" pwd)
465 process-environment)))))))
466 (setq default-directory (abbreviate-file-name default-directory))
467 (let ((menubar-bindings-done nil))
470 ;; Do this again, in case .emacs defined more abbreviations.
471 (setq default-directory (abbreviate-file-name default-directory))
472 ;; Specify the file for recording all the auto save files of this session.
473 ;; This is used by recover-session.
474 (or auto-save-list-file-name
475 (and auto-save-list-file-prefix
476 (setq auto-save-list-file-name
477 ;; Under MS-DOS our PID is almost always reused between
478 ;; Emacs invocations. We need something more unique.
479 (cond ((eq system-type 'ms-dos)
480 ;; We are going to access the auto-save
481 ;; directory, so make sure it exists.
483 (file-name-directory auto-save-list-file-prefix)
488 auto-save-list-file-prefix))
493 auto-save-list-file-prefix
496 (run-hooks 'emacs-startup-hook)
498 (run-hooks 'term-setup-hook))
500 ;; Don't do this if we failed to create the initial frame,
501 ;; for instance due to a dense colormap.
502 (when (or frame-initial-frame
503 ;; If frame-initial-frame has no meaning, do this anyway.
504 (not (and window-system
506 (not (eq window-system 'pc)))))
507 ;; Modify the initial frame based on what .emacs puts into
509 (if (fboundp 'frame-notice-user-settings)
510 (frame-notice-user-settings))
511 (if (fboundp 'frame-set-background-mode)
512 ;; Set the faces for the initial background mode even if
513 ;; frame-notice-user-settings didn't (such as on a tty).
514 ;; frame-set-background-mode is idempotent, so it won't
515 ;; cause any harm if it's already been done.
516 (let ((frame-background-mode frame-background-mode)
517 (frame (selected-frame))
519 (when (and (null window-system)
520 ;; Don't override a possibly customized value.
521 (null frame-background-mode)
522 ;; Don't override user specifications.
523 (null (frame-parameter frame 'reverse))
524 (let ((bg (frame-parameter frame 'background-color)))
526 (member bg '(unspecified "unspecified-bg")))))
527 (setq term (getenv "TERM"))
528 ;; Some files in lisp/term do a better job with the
529 ;; background mode, but we leave this here anyway, in
530 ;; case they remove those files.
531 (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
533 (setq frame-background-mode 'light)))
534 (frame-set-background-mode (selected-frame)))))
536 ;; Now we know the user's default font, so add it to the menu.
537 (if (fboundp 'font-menu-add-default)
538 (font-menu-add-default))
539 (and window-setup-hook
540 (run-hooks 'window-setup-hook))
541 (or menubar-bindings-done
542 (if (display-popup-menus-p)
543 (precompute-menubar-bindings)))))))
545 ;; Precompute the keyboard equivalents in the menu bar items.
546 (defun precompute-menubar-bindings ()
547 (let ((submap (lookup-key global-map [menu-bar])))
549 (and (consp (car submap))
550 (symbolp (car (car submap)))
551 (stringp (car-safe (cdr (car submap))))
552 (keymapp (cdr (cdr (car submap))))
554 (x-popup-menu nil (cdr (cdr (car submap))))
557 (setq submap (cdr submap))))
558 (setq define-key-rebound-commands t))
560 ;; Command-line options supported by tty's:
561 (defconst tty-long-option-alist
562 '(("--name" . "-name")
564 ("--reverse-video" . "-reverse")
565 ("--foreground-color" . "-fg")
566 ("--background-color" . "-bg")
567 ("--color" . "-color")))
569 (defconst tool-bar-images-pixel-height 24
570 "Height in pixels of images in the tool bar.")
572 (defvar tool-bar-originally-present nil
573 "Non-nil if tool-bars are present before user and site init files are read.")
575 ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc.
576 (defun tty-handle-args (args)
580 (not (equal (car args) "--")))
581 (let* ((this (car args))
584 (setq args (cdr args))
585 ;; Check for long options with attached arguments
586 ;; and separate out the attached option argument into argval.
587 (if (string-match "^--[^=]*=" this)
588 (setq argval (substring this (match-end 0))
589 this (substring this 0 (1- (match-end 0)))))
590 (when (string-match "^--" this)
591 (setq completion (try-completion this tty-long-option-alist))
592 (if (eq completion t)
593 ;; Exact match for long option.
594 (setq this (cdr (assoc this tty-long-option-alist)))
595 (if (stringp completion)
596 (let ((elt (assoc completion tty-long-option-alist)))
597 ;; Check for abbreviated long option.
599 (error "Option `%s' is ambiguous" this))
600 (setq this (cdr elt)))
601 ;; Check for a short option.
602 (setq argval nil this orig-this))))
603 (cond ((or (string= this "-fg") (string= this "-foreground"))
604 (or argval (setq argval (car args) args (cdr args)))
605 (setq default-frame-alist
606 (cons (cons 'foreground-color argval)
607 default-frame-alist)))
608 ((or (string= this "-bg") (string= this "-background"))
609 (or argval (setq argval (car args) args (cdr args)))
610 (setq default-frame-alist
611 (cons (cons 'background-color argval)
612 default-frame-alist)))
613 ((or (string= this "-T") (string= this "-name"))
614 (or argval (setq argval (car args) args (cdr args)))
615 (setq default-frame-alist
620 (let ((case-fold-search t)
622 (setq argval (invocation-name))
624 ;; Change any . or * characters in name to
625 ;; hyphens, so as to emulate behavior on X.
627 (setq i (string-match "[.*]" argval))
630 default-frame-alist)))
631 ((or (string= this "-r")
633 (string= this "-reverse"))
634 (setq default-frame-alist
636 default-frame-alist)))
637 ((string= this "-color")
639 (setq argval 8)) ; default --color means 8 ANSI colors
640 (setq default-frame-alist
641 (cons (cons 'tty-color-mode
643 ((numberp argval) argval)
644 ((string-match "-?[0-9]+" argval)
645 (string-to-number argval))
646 (t (intern argval))))
647 default-frame-alist)))
648 (t (setq rest (cons this rest))))))
651 (defun command-line ()
652 (setq command-line-default-directory default-directory)
654 ;; Choose a reasonable location for temporary files.
655 (setq temporary-file-directory
656 (file-name-as-directory
657 (cond ((memq system-type '(ms-dos windows-nt))
658 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
659 ((memq system-type '(vax-vms axp-vms))
660 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
662 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))))
663 (setq small-temporary-file-directory
664 (if (eq system-type 'ms-dos)
666 (setq auto-save-file-name-transforms
667 (list (list "\\`/[^/]*:\\(.+/\\)*\\(.*\\)"
668 ;; Don't put "\\2" inside expand-file-name, since
669 ;; it will be transformed to "/2" on DOS/Windows.
670 (concat temporary-file-directory "\\2") t)))
672 ;; See if we should import version-control from the environment variable.
673 (let ((vc (getenv "VERSION_CONTROL")))
674 (cond ((eq vc nil)) ;don't do anything if not set
675 ((or (string= vc "t")
676 (string= vc "numbered"))
677 (setq version-control t))
678 ((or (string= vc "nil")
679 (string= vc "existing"))
680 (setq version-control nil))
681 ((or (string= vc "never")
682 (string= vc "simple"))
683 (setq version-control 'never))))
685 ;;! This has been commented out; I currently find the behavior when
686 ;;! split-window-keep-point is nil disturbing, but if I can get used
687 ;;! to it, then it would be better to eliminate the option.
688 ;;! ;; Choose a good default value for split-window-keep-point.
689 ;;! (setq split-window-keep-point (> baud-rate 2400))
691 ;; Set the default strings to display in mode line for
692 ;; end-of-line formats that aren't native to this platform.
694 ((memq system-type '(ms-dos windows-nt emx))
695 (setq eol-mnemonic-unix "(Unix)")
696 (setq eol-mnemonic-mac "(Mac)"))
697 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
698 ;; abbreviated strings `/' and `:' set in coding.c for them.
699 ((eq system-type 'macos)
700 (setq eol-mnemonic-dos "(DOS)"))
701 (t ; this is for Unix/GNU/Linux systems
702 (setq eol-mnemonic-dos "(DOS)")
703 (setq eol-mnemonic-mac "(Mac)")))
705 ;; Read window system's init file if using a window system.
706 (condition-case error
707 (if (and window-system (not noninteractive))
708 (load (concat term-file-prefix
709 (symbol-name window-system)
711 ;; Every window system should have a startup file;
712 ;; barf if we can't find it.
714 ;; If we can't read it, print the error message and exit.
717 (if (eq (car error) 'error)
718 (apply 'concat (cdr error))
719 (if (memq 'file-error (get (car error) 'error-conditions))
722 (mapconcat (lambda (obj) (prin1-to-string obj t))
723 (cdr (cdr error)) ", "))
725 (get (car error) 'error-message)
726 (mapconcat (lambda (obj) (prin1-to-string obj t))
728 'external-debugging-output)
729 (terpri 'external-debugging-output)
730 (setq window-system nil)
733 ;; Windowed displays do this inside their *-win.el.
734 (when (and (not (display-graphic-p))
735 (not noninteractive))
736 (setq command-line-args (tty-handle-args command-line-args)))
738 (set-locale-environment nil)
740 ;; Convert the arguments to Emacs internal representation.
741 (let ((args (cdr command-line-args)))
744 (decode-coding-string (car args) locale-coding-system t))
745 (setq args (cdr args))))
748 (args (cdr command-line-args)))
750 ;; Figure out which user's init file to load,
751 ;; either from the environment or from the options.
752 (setq init-file-user (if noninteractive nil (user-login-name)))
753 ;; If user has not done su, use current $HOME to find .emacs.
754 (and init-file-user (string= init-file-user (user-real-login-name))
755 (setq init-file-user ""))
757 ;; Process the command-line args, and delete the arguments
758 ;; processed. This is consistent with the way main in emacs.c
760 (while (and (not done) args)
761 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
762 ("--debug-init") ("--iconic") ("--icon-type")))
765 ;; Handle --OPTION=VALUE format.
766 (when (and (string-match "\\`--" argi)
767 (string-match "=" argi))
768 (setq argval (substring argi (match-end 0))
769 argi (substring argi 0 (match-beginning 0))))
770 (unless (equal argi "--")
771 (let ((completion (try-completion argi longopts)))
772 (if (eq completion t)
773 (setq argi (substring argi 1))
774 (if (stringp completion)
775 (let ((elt (assoc completion longopts)))
777 (error "Option `%s' is ambiguous" argi))
778 (setq argi (substring (car elt) 1)))
779 (setq argval nil)))))
781 ((member argi '("-q" "-no-init-file"))
782 (setq init-file-user nil))
783 ((member argi '("-u" "-user"))
785 (setq argval (pop args)))
786 (setq init-file-user argval
788 ((string-equal argi "-no-site-file")
789 (setq site-run-file nil))
790 ((string-equal argi "-debug-init")
791 (setq init-file-debug t))
792 ((string-equal argi "-iconic")
793 (push '(visibility . icon) initial-frame-alist))
794 ((or (string-equal argi "-icon-type")
795 (string-equal argi "-i")
796 (string-equal argi "-itype"))
797 (push '(icon-type . t) default-frame-alist))
798 ;; Push the popped arg back on the list of arguments.
799 (t (push argi args) (setq done t)))
800 ;; Was argval set but not used?
802 (error "Option `%s' doesn't allow an argument" argi))))
804 ;; Re-attach the program name to the front of the arg list.
805 (and command-line-args (setcdr command-line-args args)))
807 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
808 (when (fboundp 'frame-initialize)
811 ;; If frame was created with a menu bar, set menu-bar-mode on.
812 (if (and (not noninteractive)
813 (or (not (memq window-system '(x w32)))
814 (> (frame-parameter nil 'menu-bar-lines) 0)))
817 ;; If frame was created with a tool bar, switch tool-bar-mode on.
818 (when (and (not noninteractive)
820 (> (frame-parameter nil 'tool-bar-lines) 0))
823 ;; Can't do this init in defcustom because window-system isn't set.
824 (when (and (not noninteractive)
825 (not (eq system-type 'ms-dos))
826 (memq window-system '(x w32)))
827 (setq-default blink-cursor t)
828 (blink-cursor-mode 1))
830 (unless noninteractive
831 ;; DOS/Windows systems have a PC-type keyboard which has both
832 ;; <delete> and <backspace> keys.
833 (when (or (memq system-type '(ms-dos windows-nt))
834 (and (memq window-system '(x))
835 (fboundp 'x-backspace-delete-keys-p)
836 (x-backspace-delete-keys-p))
837 ;; If the terminal Emacs is running on has erase char
838 ;; set to ^H, use the Backspace key for deleting
839 ;; backward and, and the Delete key for deleting forward.
840 (and (null window-system)
841 (eq tty-erase-char 8)))
842 (setq-default normal-erase-is-backspace t)
843 (normal-erase-is-backspace-mode 1)))
845 (when (and (not noninteractive)
847 (fboundp 'x-show-tip))
848 (setq-default tooltip-mode t)
851 ;; Register default TTY colors for the case the terminal hasn't a
852 ;; terminal init file.
853 (or (memq window-system '(x w32))
854 ;; We do this regardles of whether the terminal supports colors
855 ;; or not, since they can switch that support on or off in
856 ;; mid-session by setting the tty-color-mode frame parameter.
857 (tty-register-default-colors))
859 ;; Record whether the tool-bar is present before the user and site
860 ;; init files are processed. frame-notice-user-settings uses this
861 ;; to determine if the tool-bar has been disabled by the init files,
862 ;; and the frame needs to be resized.
863 (when (fboundp 'frame-notice-user-settings)
864 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
865 (assq 'tool-bar-lines default-frame-alist))))
866 (setq tool-bar-originally-present
867 (not (or (null tool-bar-lines)
868 (null (cdr tool-bar-lines))
869 (eq 0 (cdr tool-bar-lines)))))))
871 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
872 (old-font-list-limit font-list-limit)
873 (old-face-ignored-fonts face-ignored-fonts))
875 (run-hooks 'before-init-hook)
877 ;; Run the site-start library if it exists. The point of this file is
878 ;; that it is run before .emacs. There is no point in doing this after
879 ;; .emacs; that is useless.
881 (load site-run-file t t))
883 ;; Sites should not disable this. Only individuals should disable
884 ;; the startup message.
885 (setq inhibit-startup-message nil)
887 ;; Load that user's init file, or the default one, or none.
888 (let (debug-on-error-from-init-file
889 debug-on-error-should-be-set
890 (debug-on-error-initial
891 (if (eq init-file-debug t) 'startup init-file-debug))
892 (orig-enable-multibyte default-enable-multibyte-characters))
893 (let ((debug-on-error debug-on-error-initial)
894 ;; This function actually reads the init files.
899 (let ((user-init-file-1
901 ((eq system-type 'ms-dos)
902 (concat "~" init-file-user "/_emacs"))
903 ((eq system-type 'windows-nt)
904 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
907 ((eq system-type 'vax-vms)
910 (concat "~" init-file-user "/.emacs")))))
911 ;; This tells `load' to store the file name found
912 ;; into user-init-file.
913 (setq user-init-file t)
914 (load user-init-file-1 t t)
916 ;; If we did not find the user's init file,
917 ;; set user-init-file conclusively to nil;
918 ;; don't let it be set from default.el.
919 (if (eq user-init-file t)
920 (setq user-init-file user-init-file-1))
922 ;; If we loaded a compiled file, set
923 ;; `user-init-file' to the source version if that
925 (when (and user-init-file
926 (equal (file-name-extension user-init-file)
928 (let* ((source (file-name-sans-extension user-init-file))
929 (alt (concat source ".el")))
930 (setq source (cond ((file-exists-p alt) alt)
931 ((file-exists-p source) source)
934 (when (file-newer-than-file-p source user-init-file)
935 (message "Warning: %s is newer than %s"
936 source user-init-file)
938 (setq user-init-file source))))
940 (when (and (stringp custom-file)
941 (not (assoc custom-file load-history)))
942 ;; If the .emacs file has set `custom-file' but hasn't
943 ;; loaded the file yet, let's load it.
944 (load custom-file t t))
946 (or inhibit-default-init
947 (let ((inhibit-startup-message nil))
948 ;; Users are supposed to be told their rights.
949 ;; (Plus how to get help and how to undo.)
950 ;; Don't you dare turn this off for anyone
952 (load "default" t t)))))))))
954 ;; Do this without a condition-case if the user wants to debug.
956 (condition-case error
959 (setq init-file-had-error nil))
961 (let ((message-log-max nil))
963 (set-buffer (get-buffer-create "*Messages*"))
965 (format "An error has occurred while loading `%s':\n\n"
968 (get (car error) 'error-message)
969 (if (cdr error) ": " "")
970 (mapconcat 'prin1-to-string (cdr error) ", "))
972 "To ensure normal operation, you should investigate the cause\n"
973 "of the error in your initialization file and remove it. Start\n"
974 "Emacs with the `--debug-init' option to view a complete error\n"
976 (message "Error in init file: %s%s%s"
977 (get (car error) 'error-message)
978 (if (cdr error) ": " "")
979 (mapconcat 'prin1-to-string (cdr error) ", "))
980 (pop-to-buffer "*Messages*")
981 (setq init-file-had-error t)))))
983 ;; If the user has a file of abbrevs, read it.
984 (if (file-exists-p abbrev-file-name)
985 (quietly-read-abbrev-file abbrev-file-name))
987 ;; If the abbrevs came entirely from the init file or the
988 ;; abbrevs file, they do not need saving.
989 (setq abbrevs-changed nil)
991 ;; If we can tell that the init file altered debug-on-error,
992 ;; arrange to preserve the value that it set up.
993 (or (eq debug-on-error debug-on-error-initial)
994 (setq debug-on-error-should-be-set t
995 debug-on-error-from-init-file debug-on-error)))
996 (if debug-on-error-should-be-set
997 (setq debug-on-error debug-on-error-from-init-file))
998 (unless (or default-enable-multibyte-characters
999 (eq orig-enable-multibyte default-enable-multibyte-characters))
1000 ;; Init file changed to unibyte. Reset existing multibyte
1001 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1002 ;; Arguably this should only be done if they're free of
1003 ;; multibyte characters.
1004 (mapcar (lambda (buffer)
1005 (with-current-buffer buffer
1006 (if enable-multibyte-characters
1007 (set-buffer-multibyte nil))))
1009 ;; Also re-set the language environment in case it was
1010 ;; originally done before unibyte was set and is sensitive to
1011 ;; unibyte (display table, terminal coding system &c).
1012 (set-language-environment current-language-environment)))
1014 ;; Do this here in case the init file sets mail-host-address.
1015 (or (equal user-mail-address "")
1016 (setq user-mail-address (concat (user-login-name) "@"
1017 (or mail-host-address
1020 ;; If parameter have been changed in the init file which influence
1021 ;; face realization, clear the face cache so that new faces will
1023 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1024 (eq font-list-limit old-font-list-limit)
1025 (eq face-ignored-fonts old-face-ignored-fonts))
1026 (clear-face-cache)))
1028 (run-hooks 'after-init-hook)
1030 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1031 (if (get-buffer "*scratch*")
1032 (with-current-buffer "*scratch*"
1033 (if (eq major-mode 'fundamental-mode)
1034 (funcall initial-major-mode))))
1036 ;; Load library for our terminal type.
1037 ;; User init file can set term-file-prefix to nil to prevent this.
1038 (and term-file-prefix (not noninteractive) (not window-system)
1039 (let ((term (getenv "TERM"))
1042 (not (load (concat term-file-prefix term) t t)))
1043 ;; Strip off last hyphen and what follows, then try again
1044 (if (setq hyphend (string-match "[-_][^-_]+$" term))
1045 (setq term (substring term 0 hyphend))
1048 ;; Update the out-of-memory error message based on user's key bindings
1049 ;; for save-some-buffers.
1050 (setq memory-signal-data
1052 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1054 ;; Process the remaining args.
1055 (command-line-1 (cdr command-line-args))
1057 ;; If -batch, terminate after processing the command options.
1058 (if noninteractive (kill-emacs t))
1060 ;; Run emacs-session-restore (session management) if started by
1061 ;; the session manager and we have a session manager connection.
1062 (if (and (boundp 'x-session-previous-id) (stringp x-session-previous-id))
1063 (emacs-session-restore x-session-previous-id)))
1065 (defcustom initial-scratch-message (purecopy "\
1066 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1067 ;; If you want to create a file, visit that file with C-x C-f,
1068 ;; then enter the text in that file's own buffer.
1071 "Initial message displayed in *scratch* buffer at startup.
1072 If this is nil, no message will be displayed."
1073 :type '(choice (text :tag "Message")
1074 (const :tag "none" nil))
1075 :group 'initialization)
1078 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1079 ;;; Fancy splash screen
1080 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1082 (defvar fancy-splash-text
1083 '((:face variable-pitch
1084 "You can do basic editing with the menu bar and scroll bar \
1085 using the mouse.\n\n"
1086 :face (variable-pitch :weight bold)
1087 "Important Help menu items:\n"
1088 :face variable-pitch "\
1089 Emacs Tutorial\tLearn-by-doing tutorial for using Emacs efficiently
1090 Emacs FAQ\tFrequently asked questions and answers
1091 Read the Emacs Manual\tView the Emacs manual using Info
1092 \(Non)Warranty\tGNU Emacs comes with "
1093 :face (variable-pitch :slant oblique)
1094 "ABSOLUTELY NO WARRANTY\n"
1095 :face variable-pitch
1097 Copying Conditions\tConditions for redistributing and changing Emacs
1098 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1099 (:face variable-pitch
1100 "You can do basic editing with the menu bar and scroll bar \
1101 using the mouse.\n\n"
1102 :face (variable-pitch :weight bold)
1103 "Useful File menu items:\n"
1104 :face variable-pitch "\
1105 Exit Emacs\t(Or type Control-x followed by Control-c)
1106 Recover Session\tRecover files you were editing before a crash
1113 "A list of texts to show in the middle part of splash screens.
1114 Each element in the list should be a list of strings or pairs
1115 `:face FACE', like `fancy-splash-insert' accepts them.")
1118 (defgroup fancy-splash-screen ()
1119 "Fancy splash screen when Emacs starts."
1121 :group 'initialization)
1124 (defcustom fancy-splash-delay 10
1125 "*Delay in seconds between splash screens."
1126 :group 'fancy-splash-screen
1130 (defcustom fancy-splash-max-time 60
1131 "*Show splash screens for at most this number of seconds.
1132 Values less than 60 seconds are ignored."
1133 :group 'fancy-splash-screen
1137 (defcustom fancy-splash-image nil
1138 "*The image to show in the splash screens, or nil for defaults."
1139 :group 'fancy-splash-screen
1140 :type '(choice (const :tag "Default" nil)
1141 (file :tag "File")))
1144 ;; These are temporary storage areas for the splash screen display.
1146 (defvar fancy-current-text nil)
1147 (defvar fancy-splash-help-echo nil)
1148 (defvar fancy-splash-stop-time nil)
1149 (defvar fancy-splash-outer-buffer nil)
1151 (defun fancy-splash-insert (&rest args)
1152 "Insert text into the current buffer, with faces.
1153 Arguments from ARGS should be either strings or pairs `:face FACE',
1154 where FACE is a valid face specification, as it can be used with
1155 `put-text-properties'."
1156 (let ((current-face nil))
1158 (if (eq (car args) :face)
1159 (setq args (cdr args) current-face (car args))
1160 (insert (propertize (car args)
1162 'help-echo fancy-splash-help-echo)))
1163 (setq args (cdr args)))))
1166 (defun fancy-splash-head ()
1167 "Insert the head part of the splash screen into the current buffer."
1168 (let* ((image-file (cond ((stringp fancy-splash-image)
1170 ((and (display-color-p)
1171 (image-type-available-p 'xpm))
1172 (if (and (fboundp 'x-display-planes)
1173 (= (funcall 'x-display-planes) 8))
1177 (img (create-image image-file))
1178 (image-width (and img (car (image-size img))))
1179 (window-width (window-width (selected-window))))
1181 (when (> window-width image-width)
1182 ;; Center the image in the window.
1183 (let ((pos (/ (- window-width image-width) 2)))
1184 (insert (propertize " " 'display `(space :align-to ,pos))))
1186 ;; Change the color of the XPM version of the splash image
1187 ;; so that it is visible with a dark frame background.
1188 (when (and (memq 'xpm img)
1189 (eq (frame-parameter nil 'background-mode) 'dark))
1190 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1192 ;; Insert the image with a help-echo and a keymap.
1193 (let ((map (make-sparse-keymap))
1194 (help-echo "mouse-2: browse http://www.gnu.org/"))
1195 (define-key map [mouse-2]
1198 (browse-url "http://www.gnu.org/")
1200 (define-key map [down-mouse-2] 'ignore)
1201 (define-key map [up-mouse-2] 'ignore)
1202 (insert-image img (propertize "xxx" 'help-echo help-echo
1205 (fancy-splash-insert
1206 :face '(variable-pitch :foreground "red")
1207 (if (eq system-type 'gnu/linux)
1208 "GNU Emacs is one component of the GNU/Linux operating system."
1209 "GNU Emacs is one component of the GNU operating system."))
1211 (unless (equal (buffer-name fancy-splash-outer-buffer) "*scratch*")
1212 (fancy-splash-insert :face 'variable-pitch
1213 (substitute-command-keys
1214 "Type \\[recenter] to begin editing your file.\n"))))
1217 (defun fancy-splash-tail ()
1218 "Insert the tail part of the splash screen into the current buffer."
1219 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1220 "cyan" "darkblue")))
1221 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1225 :face '(variable-pitch :height 0.5)
1226 "Copyright (C) 2002 Free Software Foundation, Inc.")
1227 (and auto-save-list-file-prefix
1228 ;; Don't signal an error if the
1229 ;; directory for auto-save-list files
1230 ;; does not yet exist.
1231 (file-directory-p (file-name-directory
1232 auto-save-list-file-prefix))
1234 (file-name-directory auto-save-list-file-prefix)
1237 (regexp-quote (file-name-nondirectory
1238 auto-save-list-file-prefix)))
1240 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1241 "\n\nIf an Emacs session crashed recently, "
1242 "type M-x recover-session RET\nto recover"
1243 " the files you were editing."))))
1245 (defun fancy-splash-screens-1 (buffer)
1246 "Timer function displaying a splash screen."
1247 (when (> (float-time) fancy-splash-stop-time)
1248 (throw 'stop-splashing nil))
1249 (unless fancy-current-text
1250 (setq fancy-current-text fancy-splash-text))
1251 (let ((text (car fancy-current-text)))
1255 (apply #'fancy-splash-insert text)
1257 (unless (current-message)
1258 (message fancy-splash-help-echo))
1259 (set-buffer-modified-p nil)
1260 (goto-char (point-min))
1261 (force-mode-line-update)
1262 (setq fancy-current-text (cdr fancy-current-text))))
1265 (defun fancy-splash-default-action ()
1266 "Default action for events in the splash screen buffer."
1268 (push last-command-event unread-command-events)
1272 (defun fancy-splash-screens ()
1273 "Display fancy splash screens when Emacs starts."
1274 (setq fancy-splash-help-echo (startup-echo-area-message))
1275 (let ((old-hourglass display-hourglass)
1276 (fancy-splash-outer-buffer (current-buffer))
1278 (old-minor-mode-map-alist minor-mode-map-alist)
1279 (frame (fancy-splash-frame))
1281 (save-selected-window
1282 (select-frame frame)
1283 (switch-to-buffer "GNU Emacs")
1285 (setq splash-buffer (current-buffer))
1286 (catch 'stop-splashing
1288 (let ((map (make-sparse-keymap)))
1290 (define-key map [switch-frame] 'ignore)
1291 (define-key map [t] 'fancy-splash-default-action)
1292 (define-key map [mouse-movement] 'ignore)
1293 (define-key map [mode-line t] 'ignore)
1294 (setq cursor-type nil
1295 display-hourglass nil
1296 minor-mode-map-alist nil
1298 mode-line-format (propertize "---- %b %-"
1299 'face '(:weight bold))
1300 fancy-splash-stop-time (+ (float-time)
1301 (max 60 fancy-splash-max-time))
1302 timer (run-with-timer 0 fancy-splash-delay
1303 #'fancy-splash-screens-1
1306 (cancel-timer timer)
1307 (setq display-hourglass old-hourglass
1308 minor-mode-map-alist old-minor-mode-map-alist)
1309 (kill-buffer splash-buffer))))))
1311 (defun fancy-splash-frame ()
1312 "Return the frame to use for the fancy splash screen.
1313 Returning non-nil does not mean we should necessarily
1314 use the fancy splash screen, but if we do use it,
1315 we put it on this frame."
1317 (dolist (frame (append (frame-list) (list (selected-frame))))
1318 (if (and (frame-visible-p frame)
1319 (not (window-minibuffer-p (frame-selected-window frame))))
1320 (setq chosen-frame frame)))
1323 (defun use-fancy-splash-screens-p ()
1324 "Return t if fancy splash screens should be used."
1325 (when (or (and (display-color-p)
1326 (image-type-available-p 'xpm))
1327 (image-type-available-p 'pbm))
1328 (let ((frame (fancy-splash-frame)))
1330 (let* ((img (create-image (or fancy-splash-image
1331 (if (and (display-color-p)
1332 (image-type-available-p 'xpm))
1333 "splash.xpm" "splash.pbm"))))
1334 (image-height (and img (cdr (image-size img))))
1335 (window-height (1- (window-height (frame-selected-window frame)))))
1336 (> window-height (+ image-height 19)))))))
1339 (defun normal-splash-screen ()
1340 "Display splash screen when Emacs starts."
1341 (let ((prev-buffer (current-buffer)))
1343 (with-current-buffer (get-buffer-create "GNU Emacs")
1345 (mode-line-format (propertize "---- %b %-"
1346 'face '(:weight bold))))
1348 ;; The convention for this piece of code is that
1349 ;; each piece of output starts with one or two newlines
1350 ;; and does not end with any newlines.
1351 (insert "Welcome to GNU Emacs")
1353 (if (eq system-type 'gnu/linux)
1354 ", one component of the GNU/Linux operating system.\n"
1355 ", a part of the GNU operating system.\n"))
1357 (unless (equal (buffer-name prev-buffer) "*scratch*")
1358 (insert (substitute-command-keys
1359 "\nType \\[recenter] to begin editing your file.\n")))
1361 (if (display-mouse-p)
1362 ;; The user can use the mouse to activate menus
1363 ;; so give help in terms of menu items.
1366 You can do basic editing with the menu bar and scroll bar using the mouse.
1368 Useful File menu items:
1369 Exit Emacs (or type Control-x followed by Control-c)
1370 Recover Session recover files you were editing before a crash
1372 Important Help menu items:
1373 Emacs Tutorial Learn-by-doing tutorial for using Emacs efficiently.
1374 Emacs FAQ Frequently asked questions and answers
1375 Read the Emacs Manual View the Emacs manual using Info
1376 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1377 Copying Conditions Conditions for redistributing and changing Emacs.
1378 Getting New Versions How to obtain the latest version of Emacs.
1379 More Manuals / Ordering Manuals How to order printed manuals from the FSF.
1381 (insert "\n\n" (emacs-version)
1383 Copyright (C) 2002 Free Software Foundation, Inc."))
1385 ;; No mouse menus, so give help using kbd commands.
1387 ;; If keys have their default meanings,
1388 ;; use precomputed string to save lots of time.
1389 (if (and (eq (key-binding "\C-h") 'help-command)
1390 (eq (key-binding "\C-xu") 'advertised-undo)
1391 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1392 (eq (key-binding "\C-ht") 'help-with-tutorial)
1393 (eq (key-binding "\C-hi") 'info)
1394 (eq (key-binding "\C-hr") 'info-emacs-manual)
1395 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1397 Get help C-h (Hold down CTRL and press h)
1399 Emacs tutorial C-h t Undo changes C-x u
1400 Buy manuals C-h C-m Exit Emacs C-x C-c
1401 Browse manuals C-h i")
1403 (insert (substitute-command-keys
1406 Emacs manual \\[info-emacs-manual]
1407 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1408 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-emacs]
1409 Browse manuals \\[info]"
1410 (let ((where (where-is-internal
1411 'help-command nil t)))
1413 (key-description where)
1416 ;; Say how to use the menu bar with the keyboard.
1417 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1418 (eq (key-binding [f10]) 'tmm-menubar))
1420 Activate menubar F10 or ESC ` or M-`")
1421 (insert (substitute-command-keys "
1422 Activate menubar \\[tmm-menubar]")))
1424 ;; Many users seem to have problems with these.
1426 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1427 If you have no Meta key, you may instead type ESC followed by the character.)")
1429 (insert "\n\n" (emacs-version)
1431 Copyright (C) 2002 Free Software Foundation, Inc.")
1433 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1434 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1435 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1438 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1439 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1440 of Emacs and modify it; type C-h C-c to see the conditions.
1441 Type C-h C-d for information on getting the latest version.")
1442 (insert (substitute-command-keys
1444 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1445 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1446 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1447 Type \\[describe-distribution] for information on getting the latest version."))))
1449 ;; The rest of the startup screen is the same on all
1450 ;; kinds of terminals.
1452 ;; Give information on recovering, if there was a crash.
1453 (and auto-save-list-file-prefix
1454 ;; Don't signal an error if the
1455 ;; directory for auto-save-list files
1456 ;; does not yet exist.
1457 (file-directory-p (file-name-directory
1458 auto-save-list-file-prefix))
1460 (file-name-directory auto-save-list-file-prefix)
1463 (regexp-quote (file-name-nondirectory
1464 auto-save-list-file-prefix)))
1466 (insert "\n\nIf an Emacs session crashed recently, "
1467 "type M-x recover-session RET\nto recover"
1468 " the files you were editing."))
1470 ;; Display the input that we set up in the buffer.
1471 (set-buffer-modified-p nil)
1472 (goto-char (point-min))
1473 (save-window-excursion
1474 (switch-to-buffer (current-buffer))
1476 ;; Unwind ... ensure splash buffer is killed
1477 (kill-buffer "GNU Emacs"))))
1480 (defun startup-echo-area-message ()
1481 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1482 "For information about the GNU Project and its goals, type C-h C-p."
1483 (substitute-command-keys
1484 "For information about the GNU Project and its goals, type \
1485 \\[describe-project].")))
1488 (defun display-startup-echo-area-message ()
1489 (let ((resize-mini-windows t))
1490 (message (startup-echo-area-message))))
1493 (defun display-splash-screen ()
1494 "Display splash screen according to display.
1495 Fancy splash screens are used on graphic displays,
1498 (if (and (display-graphic-p)
1499 (use-fancy-splash-screens-p))
1500 (fancy-splash-screens)
1501 (normal-splash-screen)))
1504 (defun command-line-1 (command-line-args-left)
1505 (or noninteractive (input-pending-p) init-file-had-error
1506 ;; t if the init file says to inhibit the echo area startup message.
1507 (and inhibit-startup-echo-area-message
1509 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1510 (equal inhibit-startup-echo-area-message
1511 (if (string= init-file-user "")
1514 ;; Wasn't set with custom; see if .emacs has a setq.
1515 (let ((buffer (get-buffer-create " *temp*")))
1520 (insert-file-contents user-init-file)
1523 "([ \t\n]*setq[ \t\n]+"
1524 "inhibit-startup-echo-area-message[ \t\n]+"
1527 (if (string= init-file-user "")
1533 (kill-buffer buffer)))))
1534 (display-startup-echo-area-message))
1536 ;; Delay 2 seconds after an init file error message
1537 ;; was displayed, so user can read it.
1538 (if init-file-had-error
1541 (if command-line-args-left
1542 ;; We have command args; process them.
1543 (let ((dir command-line-default-directory)
1547 just-files ;; t if this follows the magic -- option.
1548 ;; This includes our standard options' long versions
1549 ;; and long versions of what's on command-switch-alist.
1551 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1552 ("--directory") ("--eval") ("--execute") ("--no-splash")
1553 ("--find-file") ("--visit") ("--file"))
1554 (mapcar (lambda (elt)
1555 (list (concat "-" (car elt))))
1556 command-switch-alist)))
1560 ;; Add the long X options to longopts.
1561 (dolist (tem command-line-x-option-alist)
1562 (if (string-match "^--" (car tem))
1563 (push (list (car tem)) longopts)))
1565 ;; Loop, processing options.
1566 (while (and command-line-args-left)
1567 (let* ((argi (car command-line-args-left))
1570 ;; List of directories specified in -L/--directory,
1571 ;; in reverse of the order specified.
1573 (initial-load-path load-path))
1574 (setq command-line-args-left (cdr command-line-args-left))
1576 ;; Do preliminary decoding of the option.
1578 ;; After --, don't look for options; treat all args as files.
1580 ;; Convert long options to ordinary options
1581 ;; and separate out an attached option argument into argval.
1582 (if (string-match "^--[^=]*=" argi)
1583 (setq argval (substring argi (match-end 0))
1584 argi (substring argi 0 (1- (match-end 0)))))
1585 (if (equal argi "--")
1586 (setq completion nil)
1587 (setq completion (try-completion argi longopts)))
1588 (if (eq completion t)
1589 (setq argi (substring argi 1))
1590 (if (stringp completion)
1591 (let ((elt (assoc completion longopts)))
1593 (error "Option `%s' is ambiguous" argi))
1594 (setq argi (substring (car elt) 1)))
1595 (setq argval nil argi orig-argi))))
1597 ;; Execute the option.
1598 (cond ((setq tem (assoc argi command-switch-alist))
1600 (let ((command-line-args-left
1601 (cons argval command-line-args-left)))
1602 (funcall (cdr tem) argi))
1603 (funcall (cdr tem) argi)))
1605 ((string-equal argi "-no-splash")
1606 (setq inhibit-startup-message t))
1608 ((member argi '("-f" ;what the manual claims
1610 "-e")) ; what the source used to say
1612 (setq tem (intern argval))
1613 (setq tem (intern (car command-line-args-left)))
1614 (setq command-line-args-left (cdr command-line-args-left)))
1615 (if (arrayp (symbol-function tem))
1616 (command-execute tem)
1619 ((member argi '("-eval" "-execute"))
1622 (setq tem (car command-line-args-left))
1623 (setq command-line-args-left (cdr command-line-args-left)))
1625 ;; Set the default directory as specified in -L.
1627 ((member argi '("-L" "-directory"))
1630 (setq tem (car command-line-args-left)
1631 command-line-args-left (cdr command-line-args-left)))
1632 (setq tem (command-line-normalize-file-name tem))
1633 (setq extra-load-path
1634 (cons (expand-file-name tem) extra-load-path))
1635 (setq load-path (append (nreverse extra-load-path)
1636 initial-load-path)))
1638 ((member argi '("-l" "-load"))
1641 (setq tem (car command-line-args-left)
1642 command-line-args-left (cdr command-line-args-left)))
1643 (let ((file (command-line-normalize-file-name tem)))
1644 ;; Take file from default dir if it exists there;
1645 ;; otherwise let `load' search for it.
1646 (if (file-exists-p (expand-file-name file))
1647 (setq file (expand-file-name file)))
1650 ((string-equal argi "-insert")
1653 (setq tem (car command-line-args-left)
1654 command-line-args-left (cdr command-line-args-left)))
1656 (error "File name omitted from `-insert' option"))
1657 (insert-file-contents (command-line-normalize-file-name tem)))
1659 ((string-equal argi "-kill")
1662 ((string-match "^\\+[0-9]+\\'" argi)
1663 (setq line (string-to-int argi)))
1665 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1666 (setq line (string-to-int (match-string 1 argi))
1667 column (string-to-int (match-string 2 argi))))
1669 ((setq tem (assoc argi command-line-x-option-alist))
1670 ;; Ignore X-windows options and their args if not using X.
1671 (setq command-line-args-left
1672 (nthcdr (nth 1 tem) command-line-args-left)))
1674 ((member argi '("-find-file" "-file" "-visit"))
1675 ;; An explicit option to specify visiting a file.
1678 (setq tem (car command-line-args-left)
1679 command-line-args-left (cdr command-line-args-left)))
1680 (unless (stringp tem)
1681 (error "File name omitted from `%s' option" argi))
1682 (setq file-count (1+ file-count))
1683 (let ((file (expand-file-name
1684 (command-line-normalize-file-name tem) dir)))
1685 (if (= file-count 1)
1686 (setq first-file-buffer (find-file file))
1687 (find-file-other-window file)))
1691 (unless (< column 1)
1692 (move-to-column (1- column)))
1696 (setq just-files t))
1698 ;; We have almost exhausted our options. See if the
1699 ;; user has made any other command-line options available
1700 (let ((hooks command-line-functions) ;; lrs 7/31/89
1703 (not (setq did-hook (funcall (car hooks)))))
1704 (setq hooks (cdr hooks)))
1706 ;; Ok, presume that the argument is a file name
1708 (if (string-match "\\`-" argi)
1709 (error "Unknown option `%s'" argi))
1710 (setq file-count (1+ file-count))
1713 (command-line-normalize-file-name orig-argi)
1715 (if (= file-count 1)
1716 (setq first-file-buffer (find-file file))
1717 (find-file-other-window file)))
1721 (unless (< column 1)
1722 (move-to-column (1- column)))
1723 (setq column 0))))))))
1724 ;; If 3 or more files visited, and not all visible,
1725 ;; show user what they all are. But leave the last one current.
1726 (and (> file-count 2)
1727 (not noninteractive)
1728 (not inhibit-startup-buffer-menu)
1729 (or (get-buffer-window first-file-buffer)
1732 ;; Maybe display a startup screen.
1733 (when (and (not inhibit-startup-message) (not noninteractive)
1734 ;; Don't display startup screen if init file
1735 ;; has started some sort of server.
1736 (not (and (fboundp 'process-list)
1738 ;; Display a startup screen, after some preparations.
1740 ;; If there are no switches to process, we might as well
1741 ;; run this hook now, and there may be some need to do it
1742 ;; before doing any output.
1743 (and term-setup-hook
1744 (run-hooks 'term-setup-hook))
1745 ;; Don't let the hook be run twice.
1746 (setq term-setup-hook nil)
1748 ;; It's important to notice the user settings before we
1749 ;; display the startup message; otherwise, the settings
1750 ;; won't take effect until the user gives the first
1751 ;; keystroke, and that's distracting.
1752 (when (fboundp 'frame-notice-user-settings)
1753 (frame-notice-user-settings))
1755 ;; If there are no switches to process, we might as well
1756 ;; run this hook now, and there may be some need to do it
1757 ;; before doing any output.
1758 (when window-setup-hook
1759 (run-hooks 'window-setup-hook)
1760 ;; Don't let the hook be run twice.
1761 (setq window-setup-hook nil))
1763 ;; Do this now to avoid an annoying delay if the user
1764 ;; clicks the menu bar during the sit-for.
1765 (when (display-popup-menus-p)
1766 (precompute-menubar-bindings))
1767 (setq menubar-bindings-done t)
1769 ;; If *scratch* is selected and it is empty, insert an
1770 ;; initial message saying not to create a file there.
1771 (when (and initial-scratch-message
1772 (string= (buffer-name) "*scratch*")
1773 (= 0 (buffer-size)))
1774 (insert initial-scratch-message)
1775 (set-buffer-modified-p nil))
1777 ;; If user typed input during all that work,
1778 ;; abort the startup screen. Otherwise, display it now.
1779 (unless (input-pending-p)
1780 (display-splash-screen))))
1783 (defun command-line-normalize-file-name (file)
1784 "Collapse multiple slashes to one, to handle non-Emacs file names."
1786 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1787 ;; That is significant on some systems.
1788 ;; However, /// at the beginning is supposed to mean just /, not //.
1789 (if (string-match "^///+" file)
1790 (setq file (replace-match "/" t t file)))
1791 (while (string-match "//+" file 1)
1792 (setq file (replace-match "/" t t file)))
1795 ;;; startup.el ends here