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 (defvar window-system initial-window-system
132 "Name of window system the selected frame is displaying through.
133 The value is a symbol--for instance, `x' for X windows.
134 The value is nil if the selected frame is on a text-only-terminal.")
136 (make-variable-frame-local 'window-system
)
138 (defgroup initialization nil
139 "Emacs start-up procedure"
142 (defcustom inhibit-startup-message nil
143 "*Non-nil inhibits the initial startup message.
144 This is for use in your personal init file, once you are familiar
145 with the contents of the startup message."
147 :group
'initialization
)
149 (defvaralias 'inhibit-splash-screen
'inhibit-startup-message
)
151 (defcustom inhibit-startup-echo-area-message nil
152 "*Non-nil inhibits the initial startup echo area message.
153 Setting this variable takes effect
154 only if you do it with the customization buffer
155 or if your `.emacs' file contains a line of this form:
156 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
157 If your `.emacs' file is byte-compiled, use the following form instead:
158 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
159 Thus, someone else using a copy of your `.emacs' file will see
160 the startup message unless he personally acts to inhibit it."
161 :type
'(choice (const :tag
"Don't inhibit")
162 (string :tag
"Enter your user name, to inhibit"))
163 :group
'initialization
)
165 (defcustom inhibit-default-init nil
166 "*Non-nil inhibits loading the `default' library."
168 :group
'initialization
)
170 (defcustom inhibit-startup-buffer-menu nil
171 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
173 :group
'initialization
)
175 (defvar command-switch-alist nil
176 "Alist of command-line switches.
177 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
178 HANDLER-FUNCTION receives switch name as sole arg;
179 remaining command-line args are in the variable `command-line-args-left'.")
181 (defvar command-line-args-left nil
182 "List of command-line args not yet processed.")
184 (defvar command-line-functions nil
;; lrs 7/31/89
185 "List of functions to process unrecognized command-line arguments.
186 Each function should access the dynamically bound variables
187 `argi' (the current argument) and `command-line-args-left' (the remaining
188 arguments). The function should return non-nil only if it recognizes and
189 processes `argi'. If it does so, it may consume successive arguments by
190 altering `command-line-args-left' to remove them.")
192 (defvar command-line-default-directory nil
193 "Default directory to use for command line arguments.
194 This is normally copied from `default-directory' when Emacs starts.")
196 ;;; This is here, rather than in x-win.el, so that we can ignore these
197 ;;; options when we are not using X.
198 (defconst command-line-x-option-alist
199 '(("-bw" 1 x-handle-numeric-switch border-width
)
200 ("-d" 1 x-handle-display
)
201 ("-display" 1 x-handle-display
)
202 ("-name" 1 x-handle-name-switch
)
203 ("-title" 1 x-handle-switch title
)
204 ("-T" 1 x-handle-switch title
)
205 ("-r" 0 x-handle-switch reverse t
)
206 ("-rv" 0 x-handle-switch reverse t
)
207 ("-reverse" 0 x-handle-switch reverse t
)
208 ("-reverse-video" 0 x-handle-switch reverse t
)
209 ("-fn" 1 x-handle-switch font
)
210 ("-font" 1 x-handle-switch font
)
211 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
212 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
213 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
214 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
215 ("-g" 1 x-handle-geometry
)
216 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
217 ("-geometry" 1 x-handle-geometry
)
218 ("-fg" 1 x-handle-switch foreground-color
)
219 ("-foreground" 1 x-handle-switch foreground-color
)
220 ("-bg" 1 x-handle-switch background-color
)
221 ("-background" 1 x-handle-switch background-color
)
222 ("-ms" 1 x-handle-switch mouse-color
)
223 ("-itype" 0 x-handle-switch icon-type t
)
224 ("-i" 0 x-handle-switch icon-type t
)
225 ("-iconic" 0 x-handle-iconic
)
226 ("-xrm" 1 x-handle-xrm-switch
)
227 ("-cr" 1 x-handle-switch cursor-color
)
228 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
229 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
230 ("-bd" 1 x-handle-switch
)
231 ("--border-width" 1 x-handle-numeric-switch border-width
)
232 ("--display" 1 x-handle-display
)
233 ("--name" 1 x-handle-name-switch
)
234 ("--title" 1 x-handle-switch title
)
235 ("--reverse-video" 0 x-handle-switch reverse t
)
236 ("--font" 1 x-handle-switch font
)
237 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
238 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
239 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
240 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
241 ("--geometry" 1 x-handle-geometry
)
242 ("--foreground-color" 1 x-handle-switch foreground-color
)
243 ("--background-color" 1 x-handle-switch background-color
)
244 ("--mouse-color" 1 x-handle-switch mouse-color
)
245 ("--icon-type" 0 x-handle-switch icon-type t
)
246 ("--iconic" 0 x-handle-iconic
)
247 ("--xrm" 1 x-handle-xrm-switch
)
248 ("--cursor-color" 1 x-handle-switch cursor-color
)
249 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
250 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
251 ("--border-color" 1 x-handle-switch border-color
)
252 ("--smid" 1 x-handle-smid
))
253 "Alist of X Windows options.
254 Each element has the form
255 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
256 where NAME is the option name string, NUMARGS is the number of arguments
257 that the option accepts, HANDLER is a function to call to handle the option.
258 FRAME-PARAM (optional) is the frame parameter this option specifies,
259 and VALUE is the value which is given to that frame parameter
260 \(most options use the argument for this, so VALUE is not present).")
262 (defvar before-init-hook nil
263 "Normal hook run after handling urgent options but before loading init files.")
265 (defvar after-init-hook nil
266 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
267 There is no `condition-case' around the running of these functions;
268 therefore, if you set `debug-on-error' non-nil in `.emacs',
269 an error in one of these functions will invoke the debugger.")
271 (defvar emacs-startup-hook nil
272 "Normal hook run after loading init files and handling the command line.")
274 (defvar term-setup-hook nil
275 "Normal hook run after loading terminal-specific Lisp code.
276 It also follows `emacs-startup-hook'. This hook exists for users to set,
277 so as to override the definitions made by the terminal-specific file.
278 Emacs never sets this variable itself.")
280 (defvar inhibit-startup-hooks nil
281 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
282 This is because we already did so.")
284 (defvar keyboard-type nil
285 "The brand of keyboard you are using.
286 This variable is used to define
287 the proper function and keypad keys for use under X. It is used in a
288 fashion analogous to the environment variable TERM.")
290 (defvar window-setup-hook nil
291 "Normal hook run to initialize window system display.
292 Emacs runs this hook after processing the command line arguments and loading
293 the user's init file.")
295 (defcustom initial-major-mode
'lisp-interaction-mode
296 "Major mode command symbol to use for the initial *scratch* buffer."
298 :group
'initialization
)
300 (defcustom init-file-user nil
301 "Identity of user whose `.emacs' file is or was read.
302 The value is nil if `-q' or `--no-init-file' was specified,
303 meaning do not load any init file.
305 Otherwise, the value may be the null string, meaning use the init file
306 for the user that originally logged in, or it may be a
307 string containing a user's name meaning use that person's init file.
309 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
310 evaluates to the name of the directory where the `.emacs' file was
313 Setting `init-file-user' does not prevent Emacs from loading
314 `site-start.el'. The only way to do that is to use `--no-site-file'."
315 :type
'(choice (const :tag
"none" nil
) string
)
316 :group
'initialization
)
318 (defcustom site-run-file
"site-start"
319 "File containing site-wide run-time initializations.
320 This file is loaded at run-time before `~/.emacs'. It contains inits
321 that need to be in place for the entire site, but which, due to their
322 higher incidence of change, don't make sense to load into emacs'
323 dumped image. Thus, the run-time load order is: 1. file described in
324 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
326 Don't use the `site-start.el' file for things some users may not like.
327 Put them in `default.el' instead, so that users can more easily
328 override them. Users can prevent loading `default.el' with the `-q'
329 option or by setting `inhibit-default-init' in their own init files,
330 but inhibiting `site-start.el' requires `--no-site-file', which
332 :type
'(choice (const :tag
"none" nil
) string
)
333 :group
'initialization
)
335 (defcustom mail-host-address nil
336 "*Name of this machine, for purposes of naming users."
337 :type
'(choice (const nil
) string
)
340 (defcustom user-mail-address
(if command-line-processed
341 (concat (user-login-name) "@"
342 (or mail-host-address
344 ;; Empty string means "not set yet".
346 "*Full mailing address of this user.
347 This is initialized based on `mail-host-address',
348 after your init file is read, in case it sets `mail-host-address'."
352 (defcustom auto-save-list-file-prefix
353 (cond ((eq system-type
'ms-dos
)
354 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
355 "~/_emacs.d/auto-save.list/_s")
357 "~/.emacs.d/auto-save-list/.saves-"))
358 "Prefix for generating `auto-save-list-file-name'.
359 This is used after reading your `.emacs' file to initialize
360 `auto-save-list-file-name', by appending Emacs's pid and the system name,
361 if you have not already set `auto-save-list-file-name' yourself.
362 Directories in the prefix will be created if necessary.
363 Set this to nil if you want to prevent `auto-save-list-file-name'
364 from being initialized."
365 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
369 (defvar init-file-debug nil
)
371 (defvar init-file-had-error nil
)
373 (defvar normal-top-level-add-subdirs-inode-list nil
)
375 (defvar pure-space-overflow nil
376 "Non-nil if building Emacs overflowed pure space.")
378 (defun normal-top-level-add-subdirs-to-load-path ()
379 "Add all subdirectories of current directory to `load-path'.
380 More precisely, this uses only the subdirectories whose names
381 start with letters or digits; it excludes any subdirectory named `RCS'
382 or `CVS', and any subdirectory that contains a file named `.nosearch'."
385 (pending (list default-directory
)))
386 ;; This loop does a breadth-first tree walk on DIR's subtree,
387 ;; putting each subdir into DIRS as its contents are examined.
389 (push (pop pending
) dirs
)
390 (let* ((this-dir (car dirs
))
391 (contents (directory-files this-dir
))
392 (default-directory this-dir
)
393 (canonicalized (and (eq system-type
'windows-nt
)
394 (untranslated-canonical-name this-dir
))))
395 ;; The Windows version doesn't report meaningful inode
396 ;; numbers, so use the canonicalized absolute file name of the
397 ;; directory instead.
398 (setq attrs
(or canonicalized
399 (nthcdr 10 (file-attributes this-dir
))))
400 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
401 (push attrs normal-top-level-add-subdirs-inode-list
)
402 (dolist (file contents
)
403 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
404 (unless (member file
'("." ".." "RCS" "CVS" "rcs" "cvs"))
405 (when (and (string-match "\\`[[:alnum:]]" file
)
406 ;; Avoid doing a `stat' when it isn't necessary
407 ;; because that can cause trouble when an NFS server
409 (not (string-match "\\.elc?\\'" file
))
410 (file-directory-p file
))
411 (let ((expanded (expand-file-name file
)))
412 (unless (file-exists-p (expand-file-name ".nosearch"
414 (setq pending
(nconc pending
(list expanded
)))))))))))
415 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
417 ;; This function is called from a subdirs.el file.
418 ;; It assumes that default-directory is the directory
419 ;; in which the subdirs.el file exists,
420 ;; and it adds to load-path the subdirs of that directory
421 ;; as specified in DIRS. Normally the elements of DIRS are relative.
422 (defun normal-top-level-add-to-load-path (dirs)
423 (let ((tail load-path
)
424 (thisdir (directory-file-name default-directory
)))
426 ;;Don't go all the way to the nil terminator.
428 (not (equal thisdir
(car tail
)))
429 (not (and (memq system-type
'(ms-dos windows-nt
))
430 (equal (downcase thisdir
) (downcase (car tail
))))))
431 (setq tail
(cdr tail
)))
432 ;;Splice the new section in.
434 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
436 (defun normal-top-level ()
437 (if command-line-processed
438 (message "Back to top level.")
439 (setq command-line-processed t
)
440 ;; Give *Messages* the same default-directory as *scratch*,
441 ;; just to keep things predictable.
442 (let ((dir default-directory
))
444 (set-buffer (get-buffer "*Messages*"))
445 (setq default-directory dir
)))
446 ;; `user-full-name' is now known; reset its standard-value here.
447 (put 'user-full-name
'standard-value
448 (list (default-value 'user-full-name
)))
449 ;; For root, preserve owner and group when editing files.
450 (if (equal (user-uid) 0)
451 (setq backup-by-copying-when-mismatch t
))
452 ;; Look in each dir in load-path for a subdirs.el file.
453 ;; If we find one, load it, which will add the appropriate subdirs
454 ;; of that dir into load-path,
455 ;; Look for a leim-list.el file too. Loading it will register
456 ;; available input methods.
457 (let ((tail load-path
)
460 (push (car tail
) new
)
462 (let ((default-directory (car tail
)))
463 (load (expand-file-name "subdirs.el" (car tail
)) t t t
)))
465 (let ((default-directory (car tail
)))
466 (load (expand-file-name "leim-list.el" (car tail
)) t t t
)))
467 (setq tail
(cdr tail
))))
468 (if (not (eq system-type
'vax-vms
))
470 ;; If the PWD environment variable isn't accurate, delete it.
471 (let ((pwd (getenv "PWD")))
473 ;; Use FOO/., so that if FOO is a symlink, file-attributes
474 ;; describes the directory linked to, not FOO itself.
475 (or (equal (file-attributes
476 (concat (file-name-as-directory pwd
) "."))
478 (concat (file-name-as-directory default-directory
)
480 (setq process-environment
481 (delete (concat "PWD=" pwd
)
482 process-environment
)))))))
483 (setq default-directory
(abbreviate-file-name default-directory
))
484 (let ((menubar-bindings-done nil
))
487 ;; Do this again, in case .emacs defined more abbreviations.
488 (setq default-directory
(abbreviate-file-name default-directory
))
489 ;; Specify the file for recording all the auto save files of this session.
490 ;; This is used by recover-session.
491 (or auto-save-list-file-name
492 (and auto-save-list-file-prefix
493 (setq auto-save-list-file-name
494 ;; Under MS-DOS our PID is almost always reused between
495 ;; Emacs invocations. We need something more unique.
496 (cond ((eq system-type
'ms-dos
)
497 ;; We are going to access the auto-save
498 ;; directory, so make sure it exists.
500 (file-name-directory auto-save-list-file-prefix
)
505 auto-save-list-file-prefix
))
510 auto-save-list-file-prefix
513 (unless inhibit-startup-hooks
514 (run-hooks 'emacs-startup-hook
)
516 (run-hooks 'term-setup-hook
)))
518 ;; Don't do this if we failed to create the initial frame,
519 ;; for instance due to a dense colormap.
520 (when (or frame-initial-frame
521 ;; If frame-initial-frame has no meaning, do this anyway.
522 (not (and initial-window-system
524 (not (eq initial-window-system
'pc
)))))
525 ;; Modify the initial frame based on what .emacs puts into
527 (if (fboundp 'frame-notice-user-settings
)
528 (frame-notice-user-settings))
529 (if (fboundp 'frame-set-background-mode
)
530 ;; Set the faces for the initial background mode even if
531 ;; frame-notice-user-settings didn't (such as on a tty).
532 ;; frame-set-background-mode is idempotent, so it won't
533 ;; cause any harm if it's already been done.
534 (let ((frame-background-mode frame-background-mode
)
535 (frame (selected-frame))
537 (when (and (null initial-window-system
)
538 ;; Don't override a possibly customized value.
539 (null frame-background-mode
)
540 ;; Don't override user specifications.
541 (null (frame-parameter frame
'reverse
))
542 (let ((bg (frame-parameter frame
'background-color
)))
544 (member bg
'(unspecified "unspecified-bg")))))
545 (setq term
(getenv "TERM"))
546 ;; Some files in lisp/term do a better job with the
547 ;; background mode, but we leave this here anyway, in
548 ;; case they remove those files.
549 (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
551 (setq frame-background-mode
'light
)))
552 (frame-set-background-mode (selected-frame)))))
554 ;; Now we know the user's default font, so add it to the menu.
555 (if (fboundp 'font-menu-add-default
)
556 (font-menu-add-default))
557 (and window-setup-hook
558 (run-hooks 'window-setup-hook
))
559 (or menubar-bindings-done
560 (if (display-popup-menus-p)
561 (precompute-menubar-bindings)))))))
563 ;; Precompute the keyboard equivalents in the menu bar items.
564 (defun precompute-menubar-bindings ()
565 (let ((submap (lookup-key global-map
[menu-bar
])))
567 (and (consp (car submap
))
568 (symbolp (car (car submap
)))
569 (stringp (car-safe (cdr (car submap
))))
570 (keymapp (cdr (cdr (car submap
))))
572 (x-popup-menu nil
(cdr (cdr (car submap
))))
575 (setq submap
(cdr submap
))))
576 (setq define-key-rebound-commands t
))
578 ;; Command-line options supported by tty's:
579 (defconst tty-long-option-alist
580 '(("--name" .
"-name")
582 ("--reverse-video" .
"-reverse")
583 ("--foreground-color" .
"-fg")
584 ("--background-color" .
"-bg")
585 ("--color" .
"-color")))
587 (defconst tool-bar-images-pixel-height
24
588 "Height in pixels of images in the tool bar.")
590 (defvar tool-bar-originally-present nil
591 "Non-nil if tool-bars are present before user and site init files are read.")
593 ;; Handle the X-like command-line arguments "-fg", "-bg", "-name", etc.
594 (defun tty-handle-args (args)
598 (not (equal (car args
) "--")))
599 (let* ((argi (pop args
))
602 ;; Check for long options with attached arguments
603 ;; and separate out the attached option argument into argval.
604 (when (string-match "^\\(--[^=]*\\)=" argi
)
605 (setq argval
(substring argi
(match-end 0))
606 argi
(match-string 1 argi
)))
607 (when (string-match "^--" argi
)
608 (setq completion
(try-completion argi tty-long-option-alist
))
609 (if (eq completion t
)
610 ;; Exact match for long option.
611 (setq argi
(cdr (assoc argi tty-long-option-alist
)))
612 (if (stringp completion
)
613 (let ((elt (assoc completion tty-long-option-alist
)))
614 ;; Check for abbreviated long option.
616 (error "Option `%s' is ambiguous" argi
))
617 (setq argi
(cdr elt
)))
618 ;; Check for a short option.
621 (cond ((member argi
'("-fg" "-foreground"))
622 (push (cons 'foreground-color
(or argval
(pop args
)))
623 default-frame-alist
))
624 ((member argi
'("-bg" "-background"))
625 (push (cons 'background-color
(or argval
(pop args
)))
626 default-frame-alist
))
627 ((member argi
'("-T" "-name"))
628 (unless argval
(setq argval
(pop args
)))
632 (let ((case-fold-search t
)
634 (setq argval
(invocation-name))
636 ;; Change any . or * characters in name to
637 ;; hyphens, so as to emulate behavior on X.
639 (setq i
(string-match "[.*]" argval
))
642 default-frame-alist
))
643 ((member argi
'("-r" "-rv" "-reverse"))
645 default-frame-alist
))
646 ((equal argi
"-color")
647 (unless argval
(setq argval
8)) ; default --color means 8 ANSI colors
648 (push (cons 'tty-color-mode
650 ((numberp argval
) argval
)
651 ((string-match "-?[0-9]+" argval
)
652 (string-to-number argval
))
653 (t (intern argval
))))
654 default-frame-alist
))
659 (defun command-line ()
660 (setq command-line-default-directory default-directory
)
662 ;; Choose a reasonable location for temporary files.
663 (setq temporary-file-directory
664 (file-name-as-directory
665 (cond ((memq system-type
'(ms-dos windows-nt
))
666 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
667 ((memq system-type
'(vax-vms axp-vms
))
668 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
670 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))))
671 (setq small-temporary-file-directory
672 (if (eq system-type
'ms-dos
)
674 (setq auto-save-file-name-transforms
675 (list (list "\\`/[^/]*:\\(.+/\\)*\\(.*\\)"
676 ;; Don't put "\\2" inside expand-file-name, since
677 ;; it will be transformed to "/2" on DOS/Windows.
678 (concat temporary-file-directory
"\\2") t
)))
680 ;; See if we should import version-control from the environment variable.
681 (let ((vc (getenv "VERSION_CONTROL")))
682 (cond ((eq vc nil
)) ;don't do anything if not set
683 ((member vc
'("t" "numbered"))
684 (setq version-control t
))
685 ((member vc
'("nil" "existing"))
686 (setq version-control nil
))
687 ((member vc
'("never" "simple"))
688 (setq version-control
'never
))))
690 ;;! This has been commented out; I currently find the behavior when
691 ;;! split-window-keep-point is nil disturbing, but if I can get used
692 ;;! to it, then it would be better to eliminate the option.
693 ;;! ;; Choose a good default value for split-window-keep-point.
694 ;;! (setq split-window-keep-point (> baud-rate 2400))
696 ;; Set the default strings to display in mode line for
697 ;; end-of-line formats that aren't native to this platform.
699 ((memq system-type
'(ms-dos windows-nt emx
))
700 (setq eol-mnemonic-unix
"(Unix)"
701 eol-mnemonic-mac
"(Mac)"))
702 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
703 ;; abbreviated strings `/' and `:' set in coding.c for them.
704 ((eq system-type
'macos
)
705 (setq eol-mnemonic-dos
"(DOS)"))
706 (t ; this is for Unix/GNU/Linux systems
707 (setq eol-mnemonic-dos
"(DOS)"
708 eol-mnemonic-mac
"(Mac)")))
710 ;; Read window system's init file if using a window system.
711 (condition-case error
712 (if (and initial-window-system
(not noninteractive
))
713 (load (concat term-file-prefix
714 (symbol-name initial-window-system
)
716 ;; Every window system should have a startup file;
717 ;; barf if we can't find it.
719 ;; If we can't read it, print the error message and exit.
722 (if (eq (car error
) 'error
)
723 (apply 'concat
(cdr error
))
724 (if (memq 'file-error
(get (car error
) 'error-conditions
))
727 (mapconcat (lambda (obj) (prin1-to-string obj t
))
728 (cdr (cdr error
)) ", "))
730 (get (car error
) 'error-message
)
731 (mapconcat (lambda (obj) (prin1-to-string obj t
))
733 'external-debugging-output
)
734 (terpri 'external-debugging-output
)
735 (setq initial-window-system nil
)
738 ;; Windowed displays do this inside their *-win.el.
739 (unless (or (display-graphic-p) noninteractive
)
740 (setq command-line-args
(tty-handle-args command-line-args
)))
742 (set-locale-environment nil
)
744 ;; Convert the arguments to Emacs internal representation.
745 (let ((args (cdr command-line-args
)))
748 (decode-coding-string (car args
) locale-coding-system t
))
752 (args (cdr command-line-args
)))
754 ;; Figure out which user's init file to load,
755 ;; either from the environment or from the options.
756 (setq init-file-user
(if noninteractive nil
(user-login-name)))
757 ;; If user has not done su, use current $HOME to find .emacs.
759 (equal init-file-user
(user-real-login-name))
760 (setq init-file-user
""))
762 ;; Process the command-line args, and delete the arguments
763 ;; processed. This is consistent with the way main in emacs.c
765 (while (and (not done
) args
)
766 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
767 ("--debug-init") ("--iconic") ("--icon-type")))
771 ;; Handle --OPTION=VALUE format.
772 (when (string-match "^\\(--[^=]*\\)=" argi
)
773 (setq argval
(substring argi
(match-end 0))
774 argi
(match-string 1 argi
)))
775 (unless (equal argi
"--")
776 (let ((completion (try-completion argi longopts
)))
777 (if (eq completion t
)
778 (setq argi
(substring argi
1))
779 (if (stringp completion
)
780 (let ((elt (assoc completion longopts
)))
782 (error "Option `%s' is ambiguous" argi
))
783 (setq argi
(substring (car elt
) 1)))
787 ((member argi
'("-q" "-no-init-file"))
788 (setq init-file-user nil
))
789 ((member argi
'("-u" "-user"))
790 (setq init-file-user
(or argval
(pop args
))
792 ((equal argi
"-no-site-file")
793 (setq site-run-file nil
))
794 ((equal argi
"-debug-init")
795 (setq init-file-debug t
))
796 ((equal argi
"-iconic")
797 (push '(visibility . icon
) initial-frame-alist
))
798 ((member argi
'("-icon-type" "-i" "-itype"))
799 (push '(icon-type . t
) default-frame-alist
))
800 ;; Push the popped arg back on the list of arguments.
804 ;; Was argval set but not used?
806 (error "Option `%s' doesn't allow an argument" argi
))))
808 ;; Re-attach the program name to the front of the arg list.
809 (and command-line-args
810 (setcdr command-line-args args
)))
812 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
813 (when (fboundp 'frame-initialize
)
816 ;; If frame was created with a menu bar, set menu-bar-mode on.
817 (unless (or noninteractive
818 (and (memq initial-window-system
'(x w32
))
819 (<= (frame-parameter nil
'menu-bar-lines
) 0)))
822 ;; If frame was created with a tool bar, switch tool-bar-mode on.
823 (unless (or noninteractive
824 (not (display-graphic-p))
825 (<= (frame-parameter nil
'tool-bar-lines
) 0))
828 ;; Can't do this init in defcustom because initial-window-system isn't set.
829 (unless (or noninteractive
830 (eq system-type
'ms-dos
)
831 (not (memq initial-window-system
'(x w32
))))
832 (setq-default blink-cursor t
)
833 (blink-cursor-mode 1))
835 (unless noninteractive
836 ;; DOS/Windows systems have a PC-type keyboard which has both
837 ;; <delete> and <backspace> keys.
838 (when (or (memq system-type
'(ms-dos windows-nt
))
839 (and (memq initial-window-system
'(x))
840 (fboundp 'x-backspace-delete-keys-p
)
841 (x-backspace-delete-keys-p))
842 ;; If the terminal Emacs is running on has erase char
843 ;; set to ^H, use the Backspace key for deleting
844 ;; backward and, and the Delete key for deleting forward.
845 (and (null initial-window-system
)
846 (eq tty-erase-char
8)))
847 (setq-default normal-erase-is-backspace t
)
848 (normal-erase-is-backspace-mode 1)))
850 (unless (or noninteractive
851 (not (display-graphic-p))
852 (not (fboundp 'x-show-tip
)))
853 (setq-default tooltip-mode t
)
856 ;; Register default TTY colors for the case the terminal hasn't a
857 ;; terminal init file.
858 (unless (memq initial-window-system
'(x w32
))
859 ;; We do this regardles of whether the terminal supports colors
860 ;; or not, since they can switch that support on or off in
861 ;; mid-session by setting the tty-color-mode frame parameter.
862 (tty-register-default-colors))
864 ;; Record whether the tool-bar is present before the user and site
865 ;; init files are processed. frame-notice-user-settings uses this
866 ;; to determine if the tool-bar has been disabled by the init files,
867 ;; and the frame needs to be resized.
868 (when (fboundp 'frame-notice-user-settings
)
869 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
870 (assq 'tool-bar-lines default-frame-alist
))))
871 (setq tool-bar-originally-present
874 (not (eq 0 (cdr tool-bar-lines
)))))))
876 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
877 (old-font-list-limit font-list-limit
)
878 (old-face-ignored-fonts face-ignored-fonts
))
880 (run-hooks 'before-init-hook
)
882 ;; Run the site-start library if it exists. The point of this file is
883 ;; that it is run before .emacs. There is no point in doing this after
884 ;; .emacs; that is useless.
886 (load site-run-file t t
))
888 ;; Sites should not disable this. Only individuals should disable
889 ;; the startup message.
890 (setq inhibit-startup-message nil
)
892 ;; Load that user's init file, or the default one, or none.
893 (let (debug-on-error-from-init-file
894 debug-on-error-should-be-set
895 (debug-on-error-initial
896 (if (eq init-file-debug t
) 'startup init-file-debug
))
897 (orig-enable-multibyte default-enable-multibyte-characters
))
898 (let ((debug-on-error debug-on-error-initial
)
899 ;; This function actually reads the init files.
904 (let ((user-init-file-1
906 ((eq system-type
'ms-dos
)
907 (concat "~" init-file-user
"/_emacs"))
908 ((eq system-type
'windows-nt
)
909 (if (directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
912 ((eq system-type
'vax-vms
)
915 (concat "~" init-file-user
"/.emacs")))))
916 ;; This tells `load' to store the file name found
917 ;; into user-init-file.
918 (setq user-init-file t
)
919 (load user-init-file-1 t t
)
921 (when (eq user-init-file t
)
922 ;; If we did not find ~/.emacs, try
923 ;; ~/.emacs.d/.emacs.
926 (file-name-nondirectory user-init-file-1
)
927 (file-name-as-directory
930 (file-name-directory user-init-file-1
))))))
933 ;; If we did not find the user's init file,
934 ;; set user-init-file conclusively.
935 ;; Don't let it be set from default.el.
936 (when (eq user-init-file t
)
937 (setq user-init-file user-init-file-1
))))
939 ;; If we loaded a compiled file, set
940 ;; `user-init-file' to the source version if that
942 (when (and user-init-file
943 (equal (file-name-extension user-init-file
)
945 (let* ((source (file-name-sans-extension user-init-file
))
946 (alt (concat source
".el")))
947 (setq source
(cond ((file-exists-p alt
) alt
)
948 ((file-exists-p source
) source
)
951 (when (file-newer-than-file-p source user-init-file
)
952 (message "Warning: %s is newer than %s"
953 source user-init-file
)
955 (setq user-init-file source
))))
957 (when (stringp custom-file
)
958 (unless (assoc custom-file load-history
)
959 ;; If the .emacs file has set `custom-file' but hasn't
960 ;; loaded the file yet, let's load it.
961 (load custom-file t t
)))
963 (unless inhibit-default-init
964 (let ((inhibit-startup-message nil
))
965 ;; Users are supposed to be told their rights.
966 ;; (Plus how to get help and how to undo.)
967 ;; Don't you dare turn this off for anyone
969 (load "default" t t
)))))))))
971 ;; Do this without a condition-case if the user wants to debug.
973 (condition-case error
976 (setq init-file-had-error nil
))
978 (let ((message-log-max nil
))
980 (set-buffer (get-buffer-create "*Messages*"))
982 (format "An error has occurred while loading `%s':\n\n"
985 (get (car error
) 'error-message
)
986 (if (cdr error
) ": " "")
987 (mapconcat (lambda (s) (prin1-to-string s t
)) (cdr error
) ", "))
989 "To ensure normal operation, you should investigate and remove the\n"
990 "cause of the error in your initialization file. Start Emacs with\n"
991 "the `--debug-init' option to view a complete error backtrace.\n\n"))
992 (message "Error in init file: %s%s%s"
993 (get (car error
) 'error-message
)
994 (if (cdr error
) ": " "")
995 (mapconcat 'prin1-to-string
(cdr error
) ", "))
996 (let ((pop-up-windows nil
))
997 (pop-to-buffer "*Messages*"))
998 (setq init-file-had-error t
)))))
1000 ;; If the user has a file of abbrevs, read it.
1001 (if (file-exists-p abbrev-file-name
)
1002 (quietly-read-abbrev-file abbrev-file-name
))
1004 ;; If the abbrevs came entirely from the init file or the
1005 ;; abbrevs file, they do not need saving.
1006 (setq abbrevs-changed nil
)
1008 ;; If we can tell that the init file altered debug-on-error,
1009 ;; arrange to preserve the value that it set up.
1010 (or (eq debug-on-error debug-on-error-initial
)
1011 (setq debug-on-error-should-be-set t
1012 debug-on-error-from-init-file debug-on-error
)))
1013 (if debug-on-error-should-be-set
1014 (setq debug-on-error debug-on-error-from-init-file
))
1015 (unless (or default-enable-multibyte-characters
1016 (eq orig-enable-multibyte default-enable-multibyte-characters
))
1017 ;; Init file changed to unibyte. Reset existing multibyte
1018 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1019 ;; Arguably this should only be done if they're free of
1020 ;; multibyte characters.
1021 (mapcar (lambda (buffer)
1022 (with-current-buffer buffer
1023 (if enable-multibyte-characters
1024 (set-buffer-multibyte nil
))))
1026 ;; Also re-set the language environment in case it was
1027 ;; originally done before unibyte was set and is sensitive to
1028 ;; unibyte (display table, terminal coding system &c).
1029 (set-language-environment current-language-environment
)))
1031 ;; Do this here in case the init file sets mail-host-address.
1032 (if (equal user-mail-address
"")
1033 (setq user-mail-address
(concat (user-login-name) "@"
1034 (or mail-host-address
1037 ;; If parameter have been changed in the init file which influence
1038 ;; face realization, clear the face cache so that new faces will
1040 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1041 (eq font-list-limit old-font-list-limit
)
1042 (eq face-ignored-fonts old-face-ignored-fonts
))
1043 (clear-face-cache)))
1045 (run-hooks 'after-init-hook
)
1047 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1048 (if (get-buffer "*scratch*")
1049 (with-current-buffer "*scratch*"
1050 (if (eq major-mode
'fundamental-mode
)
1051 (funcall initial-major-mode
))))
1053 ;; Load library for our terminal type.
1054 ;; User init file can set term-file-prefix to nil to prevent this.
1055 (unless (or noninteractive
1056 initial-window-system
1057 (null term-file-prefix
))
1058 (let ((term (getenv "TERM"))
1061 (not (load (concat term-file-prefix term
) t t
)))
1062 ;; Strip off last hyphen and what follows, then try again
1064 (if (setq hyphend
(string-match "[-_][^-_]+$" term
))
1065 (substring term
0 hyphend
)
1068 ;; Update the out-of-memory error message based on user's key bindings
1069 ;; for save-some-buffers.
1070 (setq memory-signal-data
1072 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1074 ;; Process the remaining args.
1075 (command-line-1 (cdr command-line-args
))
1077 ;; If -batch, terminate after processing the command options.
1078 (if noninteractive
(kill-emacs t
))
1080 ;; Run emacs-session-restore (session management) if started by
1081 ;; the session manager and we have a session manager connection.
1082 (if (and (boundp 'x-session-previous-id
)
1083 (stringp x-session-previous-id
))
1084 (emacs-session-restore x-session-previous-id
)))
1086 (defcustom initial-scratch-message
(purecopy "\
1087 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1088 ;; If you want to create a file, visit that file with C-x C-f,
1089 ;; then enter the text in that file's own buffer.
1092 "Initial message displayed in *scratch* buffer at startup.
1093 If this is nil, no message will be displayed."
1094 :type
'(choice (text :tag
"Message")
1095 (const :tag
"none" nil
))
1096 :group
'initialization
)
1099 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1100 ;;; Fancy splash screen
1101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1103 (defvar fancy-splash-text
1104 '((:face variable-pitch
1105 "You can do basic editing with the menu bar and scroll bar \
1106 using the mouse.\n\n"
1107 :face
(variable-pitch :weight bold
)
1108 "Important Help menu items:\n"
1109 :face variable-pitch
"\
1110 Emacs Tutorial\tLearn-by-doing tutorial for using Emacs efficiently
1111 Emacs FAQ\tFrequently asked questions and answers
1112 Read the Emacs Manual\tView the Emacs manual using Info
1113 \(Non)Warranty\tGNU Emacs comes with "
1114 :face
(variable-pitch :slant oblique
)
1115 "ABSOLUTELY NO WARRANTY\n"
1116 :face variable-pitch
1118 Copying Conditions\tConditions for redistributing and changing Emacs
1119 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1120 (:face variable-pitch
1121 "You can do basic editing with the menu bar and scroll bar \
1122 using the mouse.\n\n"
1123 :face
(variable-pitch :weight bold
)
1124 "Useful File menu items:\n"
1125 :face variable-pitch
"\
1126 Exit Emacs\t(Or type Control-x followed by Control-c)
1127 Recover Session\tRecover files you were editing before a crash
1134 "A list of texts to show in the middle part of splash screens.
1135 Each element in the list should be a list of strings or pairs
1136 `:face FACE', like `fancy-splash-insert' accepts them.")
1139 (defgroup fancy-splash-screen
()
1140 "Fancy splash screen when Emacs starts."
1142 :group
'initialization
)
1145 (defcustom fancy-splash-delay
10
1146 "*Delay in seconds between splash screens."
1147 :group
'fancy-splash-screen
1151 (defcustom fancy-splash-max-time
60
1152 "*Show splash screens for at most this number of seconds.
1153 Values less than 60 seconds are ignored."
1154 :group
'fancy-splash-screen
1158 (defcustom fancy-splash-image nil
1159 "*The image to show in the splash screens, or nil for defaults."
1160 :group
'fancy-splash-screen
1161 :type
'(choice (const :tag
"Default" nil
)
1162 (file :tag
"File")))
1165 ;; These are temporary storage areas for the splash screen display.
1167 (defvar fancy-current-text nil
)
1168 (defvar fancy-splash-help-echo nil
)
1169 (defvar fancy-splash-stop-time nil
)
1170 (defvar fancy-splash-outer-buffer nil
)
1172 (defun fancy-splash-insert (&rest args
)
1173 "Insert text into the current buffer, with faces.
1174 Arguments from ARGS should be either strings or pairs `:face FACE',
1175 where FACE is a valid face specification, as it can be used with
1176 `put-text-properties'."
1177 (let ((current-face nil
))
1179 (if (eq (car args
) :face
)
1180 (setq args
(cdr args
) current-face
(car args
))
1181 (insert (propertize (car args
)
1183 'help-echo fancy-splash-help-echo
)))
1184 (setq args
(cdr args
)))))
1187 (defun fancy-splash-head ()
1188 "Insert the head part of the splash screen into the current buffer."
1189 (let* ((image-file (cond ((stringp fancy-splash-image
)
1191 ((and (display-color-p)
1192 (image-type-available-p 'xpm
))
1193 (if (and (fboundp 'x-display-planes
)
1194 (= (funcall 'x-display-planes
) 8))
1198 (img (create-image image-file
))
1199 (image-width (and img
(car (image-size img
))))
1200 (window-width (window-width (selected-window))))
1202 (when (> window-width image-width
)
1203 ;; Center the image in the window.
1204 (let ((pos (/ (- window-width image-width
) 2)))
1205 (insert (propertize " " 'display
`(space :align-to
,pos
))))
1207 ;; Change the color of the XPM version of the splash image
1208 ;; so that it is visible with a dark frame background.
1209 (when (and (memq 'xpm img
)
1210 (eq (frame-parameter nil
'background-mode
) 'dark
))
1211 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1213 ;; Insert the image with a help-echo and a keymap.
1214 (let ((map (make-sparse-keymap))
1215 (help-echo "mouse-2: browse http://www.gnu.org/"))
1216 (define-key map
[mouse-2
]
1219 (browse-url "http://www.gnu.org/")
1221 (define-key map
[down-mouse-2
] 'ignore
)
1222 (define-key map
[up-mouse-2
] 'ignore
)
1223 (insert-image img
(propertize "xxx" 'help-echo help-echo
1226 (fancy-splash-insert
1227 :face
'(variable-pitch :foreground
"red")
1228 (if (eq system-type
'gnu
/linux
)
1229 "GNU Emacs is one component of the GNU/Linux operating system."
1230 "GNU Emacs is one component of the GNU operating system."))
1232 (unless (equal (buffer-name fancy-splash-outer-buffer
) "*scratch*")
1233 (fancy-splash-insert :face
'variable-pitch
1234 (substitute-command-keys
1235 "Type \\[recenter] to begin editing your file.\n"))))
1238 (defun fancy-splash-tail ()
1239 "Insert the tail part of the splash screen into the current buffer."
1240 (let ((fg (if (eq (frame-parameter nil
'background-mode
) 'dark
)
1241 "cyan" "darkblue")))
1242 (fancy-splash-insert :face
`(variable-pitch :foreground
,fg
)
1246 :face
'(variable-pitch :height
0.5)
1247 "Copyright (C) 2002 Free Software Foundation, Inc.")
1248 (and auto-save-list-file-prefix
1249 ;; Don't signal an error if the
1250 ;; directory for auto-save-list files
1251 ;; does not yet exist.
1252 (file-directory-p (file-name-directory
1253 auto-save-list-file-prefix
))
1255 (file-name-directory auto-save-list-file-prefix
)
1258 (regexp-quote (file-name-nondirectory
1259 auto-save-list-file-prefix
)))
1261 (fancy-splash-insert :face
'(variable-pitch :foreground
"red")
1262 "\n\nIf an Emacs session crashed recently, "
1263 "type M-x recover-session RET\nto recover"
1264 " the files you were editing."))))
1266 (defun fancy-splash-screens-1 (buffer)
1267 "Timer function displaying a splash screen."
1268 (when (> (float-time) fancy-splash-stop-time
)
1269 (throw 'stop-splashing nil
))
1270 (unless fancy-current-text
1271 (setq fancy-current-text fancy-splash-text
))
1272 (let ((text (car fancy-current-text
)))
1275 (if pure-space-overflow
1276 (insert "Warning Warning Pure space overflow Warning Warning\n"))
1278 (apply #'fancy-splash-insert text
)
1280 (unless (current-message)
1281 (message fancy-splash-help-echo
))
1282 (set-buffer-modified-p nil
)
1283 (goto-char (point-min))
1284 (force-mode-line-update)
1285 (setq fancy-current-text
(cdr fancy-current-text
))))
1288 (defun fancy-splash-default-action ()
1289 "Stop displaying the splash screen buffer.
1290 This is an internal function used to turn off the splash screen after
1291 the user caused an input event by hitting a key or clicking with the
1294 (push last-command-event unread-command-events
)
1298 (defun fancy-splash-screens ()
1299 "Display fancy splash screens when Emacs starts."
1300 (setq fancy-splash-help-echo
(startup-echo-area-message))
1301 (let ((old-hourglass display-hourglass
)
1302 (fancy-splash-outer-buffer (current-buffer))
1304 (old-minor-mode-map-alist minor-mode-map-alist
)
1305 (frame (fancy-splash-frame))
1307 (save-selected-window
1308 (select-frame frame
)
1309 (switch-to-buffer "GNU Emacs")
1311 (setq splash-buffer
(current-buffer))
1312 (catch 'stop-splashing
1314 (let ((map (make-sparse-keymap)))
1316 (define-key map
[switch-frame
] 'ignore
)
1317 (define-key map
[t] 'fancy-splash-default-action)
1318 (define-key map [mouse-movement] 'ignore)
1319 (define-key map [mode-line t] 'ignore)
1320 (setq cursor-type nil
1321 display-hourglass nil
1322 minor-mode-map-alist nil
1324 mode-line-format (propertize "---- %b %-"
1325 'face '(:weight bold))
1326 fancy-splash-stop-time (+ (float-time)
1327 (max 60 fancy-splash-max-time))
1328 timer (run-with-timer 0 fancy-splash-delay
1329 #'fancy-splash-screens-1
1332 (cancel-timer timer)
1333 (setq display-hourglass old-hourglass
1334 minor-mode-map-alist old-minor-mode-map-alist)
1335 (kill-buffer splash-buffer))))))
1337 (defun fancy-splash-frame ()
1338 "Return the frame to use for the fancy splash screen.
1339 Returning non-nil does not mean we should necessarily
1340 use the fancy splash screen, but if we do use it,
1341 we put it on this frame."
1343 (dolist (frame (append (frame-list) (list (selected-frame))))
1344 (if (and (frame-visible-p frame)
1345 (not (window-minibuffer-p (frame-selected-window frame))))
1346 (setq chosen-frame frame)))
1349 (defun use-fancy-splash-screens-p ()
1350 "Return t if fancy splash screens should be used."
1351 (when (and (display-graphic-p)
1352 (or (and (display-color-p)
1353 (image-type-available-p 'xpm))
1354 (image-type-available-p 'pbm)))
1355 (let ((frame (fancy-splash-frame)))
1357 (let* ((img (create-image (or fancy-splash-image
1358 (if (and (display-color-p)
1359 (image-type-available-p 'xpm))
1360 "splash.xpm" "splash.pbm"))))
1361 (image-height (and img (cdr (image-size img))))
1362 (window-height (1- (window-height (frame-selected-window frame)))))
1363 (> window-height (+ image-height 19)))))))
1366 (defun normal-splash-screen ()
1367 "Display splash screen when Emacs starts."
1368 (let ((prev-buffer (current-buffer)))
1370 (with-current-buffer (get-buffer-create "GNU Emacs")
1372 (mode-line-format (propertize "---- %b %-"
1373 'face '(:weight bold))))
1375 (if pure-space-overflow
1376 (insert "Warning Warning Pure space overflow Warning Warning\n"))
1378 ;; The convention for this piece of code is that
1379 ;; each piece of output starts with one or two newlines
1380 ;; and does not end with any newlines.
1381 (insert "Welcome to GNU Emacs")
1383 (if (eq system-type 'gnu/linux)
1384 ", one component of the GNU/Linux operating system.\n"
1385 ", a part of the GNU operating system.\n"))
1387 (unless (equal (buffer-name prev-buffer) "*scratch*")
1388 (insert (substitute-command-keys
1389 "\nType \\[recenter] to begin editing your file.\n")))
1391 (if (display-mouse-p)
1392 ;; The user can use the mouse to activate menus
1393 ;; so give help in terms of menu items.
1396 You can do basic editing with the menu bar and scroll bar using the mouse.
1398 Useful File menu items:
1399 Exit Emacs (or type Control-x followed by Control-c)
1400 Recover Session recover files you were editing before a crash
1402 Important Help menu items:
1403 Emacs Tutorial Learn-by-doing tutorial for using Emacs efficiently.
1404 Emacs FAQ Frequently asked questions and answers
1405 Read the Emacs Manual View the Emacs manual using Info
1406 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1407 Copying Conditions Conditions for redistributing and changing Emacs.
1408 Getting New Versions How to obtain the latest version of Emacs.
1409 More Manuals / Ordering Manuals How to order printed manuals from the FSF.
1411 (insert "\n\n" (emacs-version)
1413 Copyright (C) 2002 Free Software Foundation, Inc."))
1415 ;; No mouse menus, so give help using kbd commands.
1417 ;; If keys have their default meanings,
1418 ;; use precomputed string to save lots of time.
1419 (if (and (eq (key-binding "\C-h") 'help-command)
1420 (eq (key-binding "\C-xu") 'advertised-undo)
1421 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1422 (eq (key-binding "\C-ht") 'help-with-tutorial)
1423 (eq (key-binding "\C-hi") 'info)
1424 (eq (key-binding "\C-hr") 'info-emacs-manual)
1425 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1427 Get help C-h (Hold down CTRL and press h)
1429 Emacs tutorial C-h t Undo changes C-x u
1430 Buy manuals C-h C-m Exit Emacs C-x C-c
1431 Browse manuals C-h i")
1433 (insert (substitute-command-keys
1436 Emacs manual \\[info-emacs-manual]
1437 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1438 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-emacs]
1439 Browse manuals \\[info]"
1440 (let ((where (where-is-internal
1441 'help-command nil t)))
1443 (key-description where)
1446 ;; Say how to use the menu bar with the keyboard.
1447 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1448 (eq (key-binding [f10]) 'tmm-menubar))
1450 Activate menubar F10 or ESC ` or M-`")
1451 (insert (substitute-command-keys "
1452 Activate menubar \\[tmm-menubar]")))
1454 ;; Many users seem to have problems with these.
1456 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1457 If you have no Meta key, you may instead type ESC followed by the character.)")
1459 (insert "\n\n" (emacs-version)
1461 Copyright (C) 2002 Free Software Foundation, Inc.")
1463 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1464 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1465 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1468 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1469 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1470 of Emacs and modify it; type C-h C-c to see the conditions.
1471 Type C-h C-d for information on getting the latest version.")
1472 (insert (substitute-command-keys
1474 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1475 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1476 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1477 Type \\[describe-distribution] for information on getting the latest version."))))
1479 ;; The rest of the startup screen is the same on all
1480 ;; kinds of terminals.
1482 ;; Give information on recovering, if there was a crash.
1483 (and auto-save-list-file-prefix
1484 ;; Don't signal an error if the
1485 ;; directory for auto-save-list files
1486 ;; does not yet exist.
1487 (file-directory-p (file-name-directory
1488 auto-save-list-file-prefix))
1490 (file-name-directory auto-save-list-file-prefix)
1493 (regexp-quote (file-name-nondirectory
1494 auto-save-list-file-prefix)))
1496 (insert "\n\nIf an Emacs session crashed recently, "
1497 "type M-x recover-session RET\nto recover"
1498 " the files you were editing."))
1500 ;; Display the input that we set up in the buffer.
1501 (set-buffer-modified-p nil)
1502 (goto-char (point-min))
1503 (save-window-excursion
1504 (switch-to-buffer (current-buffer))
1506 ;; Unwind ... ensure splash buffer is killed
1507 (kill-buffer "GNU Emacs"))))
1510 (defun startup-echo-area-message ()
1511 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1512 "For information about the GNU Project and its goals, type C-h C-p."
1513 (substitute-command-keys
1514 "For information about the GNU Project and its goals, type \
1515 \\[describe-project].")))
1518 (defun display-startup-echo-area-message ()
1519 (let ((resize-mini-windows t))
1520 (message (startup-echo-area-message))))
1523 (defun display-splash-screen ()
1524 "Display splash screen according to display.
1525 Fancy splash screens are used on graphic displays,
1528 (if (use-fancy-splash-screens-p)
1529 (fancy-splash-screens)
1530 (normal-splash-screen)))
1533 (defun command-line-1 (command-line-args-left)
1534 (or noninteractive (input-pending-p) init-file-had-error
1535 ;; t if the init file says to inhibit the echo area startup message.
1536 (and inhibit-startup-echo-area-message
1538 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1539 (equal inhibit-startup-echo-area-message
1540 (if (equal init-file-user "")
1543 ;; Wasn't set with custom; see if .emacs has a setq.
1544 (let ((buffer (get-buffer-create " *temp*")))
1549 (insert-file-contents user-init-file)
1552 "([ \t\n]*setq[ \t\n]+"
1553 "inhibit-startup-echo-area-message[ \t\n]+"
1556 (if (equal init-file-user "")
1562 (kill-buffer buffer)))))
1563 ;; Stop any "Loading image..." message hiding echo-area-message.
1564 (use-fancy-splash-screens-p)
1565 (display-startup-echo-area-message))
1567 ;; Delay 2 seconds after an init file error message
1568 ;; was displayed, so user can read it.
1569 (when init-file-had-error
1572 (when command-line-args-left
1573 ;; We have command args; process them.
1574 (let ((dir command-line-default-directory)
1578 ;; The directories listed in --directory/-L options will *appear*
1579 ;; at the front of `load-path' in the order they appear on the
1580 ;; command-line. We cannot do this by *placing* them at the front
1581 ;; in the order they appear, so we need this variable to hold them,
1584 just-files ;; t if this follows the magic -- option.
1585 ;; This includes our standard options' long versions
1586 ;; and long versions of what's on command-switch-alist.
1588 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1589 ("--directory") ("--eval") ("--execute") ("--no-splash")
1590 ("--find-file") ("--visit") ("--file"))
1591 (mapcar (lambda (elt)
1592 (list (concat "-" (car elt))))
1593 command-switch-alist)))
1597 ;; Add the long X options to longopts.
1598 (dolist (tem command-line-x-option-alist)
1599 (if (string-match "^--" (car tem))
1600 (push (list (car tem)) longopts)))
1602 ;; Loop, processing options.
1603 (while command-line-args-left
1604 (let* ((argi (car command-line-args-left))
1607 (setq command-line-args-left (cdr command-line-args-left))
1609 ;; Do preliminary decoding of the option.
1611 ;; After --, don't look for options; treat all args as files.
1613 ;; Convert long options to ordinary options
1614 ;; and separate out an attached option argument into argval.
1615 (when (string-match "^\\(--[^=]*\\)=" argi)
1616 (setq argval (substring argi (match-end 0))
1617 argi (match-string 1 argi)))
1618 (if (equal argi "--")
1619 (setq completion nil)
1620 (setq completion (try-completion argi longopts)))
1621 (if (eq completion t)
1622 (setq argi (substring argi 1))
1623 (if (stringp completion)
1624 (let ((elt (assoc completion longopts)))
1626 (error "Option `%s' is ambiguous" argi))
1627 (setq argi (substring (car elt) 1)))
1631 ;; Execute the option.
1632 (cond ((setq tem (assoc argi command-switch-alist))
1634 (let ((command-line-args-left
1635 (cons argval command-line-args-left)))
1636 (funcall (cdr tem) argi))
1637 (funcall (cdr tem) argi)))
1639 ((equal argi "-no-splash")
1640 (setq inhibit-startup-message t))
1642 ((member argi '("-f" ; what the manual claims
1644 "-e")) ; what the source used to say
1645 (setq tem (intern (or argval (pop command-line-args-left))))
1647 (command-execute tem)
1650 ((member argi '("-eval" "-execute"))
1651 (eval (read (or argval (pop command-line-args-left)))))
1652 ;; Set the default directory as specified in -L.
1654 ((member argi '("-L" "-directory"))
1655 (setq tem (or argval (pop command-line-args-left)))
1656 ;; We will reverse `extra-load-path' and prepend it to
1657 ;; `load-path' after all the arguments have been processed.
1659 (expand-file-name (command-line-normalize-file-name tem))
1662 ((member argi '("-l" "-load"))
1663 (let* ((file (command-line-normalize-file-name
1664 (or argval (pop command-line-args-left))))
1665 ;; Take file from default dir if it exists there;
1666 ;; otherwise let `load' search for it.
1667 (file-ex (expand-file-name file)))
1668 (when (file-exists-p file-ex)
1669 (setq file file-ex))
1672 ((equal argi "-insert")
1673 (setq tem (or argval (pop command-line-args-left)))
1675 (error "File name omitted from `-insert' option"))
1676 (insert-file-contents (command-line-normalize-file-name tem)))
1678 ((equal argi "-kill")
1681 ((string-match "^\\+[0-9]+\\'" argi)
1682 (setq line (string-to-int argi)))
1684 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1685 (setq line (string-to-int (match-string 1 argi))
1686 column (string-to-int (match-string 2 argi))))
1688 ((setq tem (assoc argi command-line-x-option-alist))
1689 ;; Ignore X-windows options and their args if not using X.
1690 (setq command-line-args-left
1691 (nthcdr (nth 1 tem) command-line-args-left)))
1693 ((member argi '("-find-file" "-file" "-visit"))
1694 ;; An explicit option to specify visiting a file.
1695 (setq tem (or argval (pop command-line-args-left)))
1696 (unless (stringp tem)
1697 (error "File name omitted from `%s' option" argi))
1698 (setq file-count (1+ file-count))
1699 (let ((file (expand-file-name
1700 (command-line-normalize-file-name tem) dir)))
1701 (if (= file-count 1)
1702 (setq first-file-buffer (find-file file))
1703 (find-file-other-window file)))
1707 (unless (< column 1)
1708 (move-to-column (1- column)))
1712 (setq just-files t))
1714 ;; We have almost exhausted our options. See if the
1715 ;; user has made any other command-line options available
1716 (let ((hooks command-line-functions) ;; lrs 7/31/89
1719 (not (setq did-hook (funcall (car hooks)))))
1720 (setq hooks (cdr hooks)))
1722 ;; Presume that the argument is a file name.
1724 (if (string-match "\\`-" argi)
1725 (error "Unknown option `%s'" argi))
1726 (setq file-count (1+ file-count))
1729 (command-line-normalize-file-name orig-argi)
1731 (if (= file-count 1)
1732 (setq first-file-buffer (find-file file))
1733 (find-file-other-window file)))
1737 (unless (< column 1)
1738 (move-to-column (1- column)))
1739 (setq column 0))))))))
1741 ;; See --directory/-L option above.
1742 (when extra-load-path
1743 (setq load-path (append (nreverse extra-load-path) load-path)))
1745 ;; If 3 or more files visited, and not all visible,
1746 ;; show user what they all are. But leave the last one current.
1747 (and (> file-count 2)
1748 (not noninteractive)
1749 (not inhibit-startup-buffer-menu)
1750 (or (get-buffer-window first-file-buffer)
1753 ;; Maybe display a startup screen.
1754 (when (and (not inhibit-startup-message) (not noninteractive)
1755 ;; Don't display startup screen if init file
1756 ;; has started some sort of server.
1757 (not (and (fboundp 'process-list)
1759 ;; Display a startup screen, after some preparations.
1761 ;; If there are no switches to process, we might as well
1762 ;; run this hook now, and there may be some need to do it
1763 ;; before doing any output.
1764 (run-hooks 'emacs-startup-hook)
1765 (and term-setup-hook
1766 (run-hooks 'term-setup-hook))
1767 (setq inhibit-startup-hooks t)
1769 ;; It's important to notice the user settings before we
1770 ;; display the startup message; otherwise, the settings
1771 ;; won't take effect until the user gives the first
1772 ;; keystroke, and that's distracting.
1773 (when (fboundp 'frame-notice-user-settings)
1774 (frame-notice-user-settings))
1776 ;; If there are no switches to process, we might as well
1777 ;; run this hook now, and there may be some need to do it
1778 ;; before doing any output.
1779 (when window-setup-hook
1780 (run-hooks 'window-setup-hook)
1781 ;; Don't let the hook be run twice.
1782 (setq window-setup-hook nil))
1784 ;; Do this now to avoid an annoying delay if the user
1785 ;; clicks the menu bar during the sit-for.
1786 (when (display-popup-menus-p)
1787 (precompute-menubar-bindings))
1789 (setq menubar-bindings-done t))
1791 ;; If *scratch* is selected and it is empty, insert an
1792 ;; initial message saying not to create a file there.
1793 (when (and initial-scratch-message
1794 (equal (buffer-name) "*scratch*")
1795 (= 0 (buffer-size)))
1796 (insert initial-scratch-message)
1797 (set-buffer-modified-p nil))
1799 ;; If user typed input during all that work,
1800 ;; abort the startup screen. Otherwise, display it now.
1801 (unless (input-pending-p)
1802 (display-splash-screen))))
1805 (defun command-line-normalize-file-name (file)
1806 "Collapse multiple slashes to one, to handle non-Emacs file names."
1808 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1809 ;; That is significant on some systems.
1810 ;; However, /// at the beginning is supposed to mean just /, not //.
1811 (if (string-match "^///+" file)
1812 (setq file (replace-match "/" t t file)))
1813 (while (string-match "//+" file 1)
1814 (setq file (replace-match "/" t t file)))
1817 ;;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
1818 ;;; startup.el ends here