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 ;; -u USER Load USER's init file instead of the init
74 ;; -user USER file belonging to the user starting Emacs.
76 ;; -------------------------
77 ;; -debug-init Don't catch errors in init files; let the
78 ;; --debug-init debugger run.
79 ;; -------------------------
80 ;; -i ICONTYPE Set type of icon using when Emacs is
81 ;; -itype ICONTYPE iconified under X.
82 ;; --icon-type ICONTYPE This option is passed on to term/x-win.el
84 ;; -iconic Start Emacs iconified.
85 ;; --iconic This option is passed on to term/x-win.el
86 ;; -------------------------
87 ;; Various X options for colors/fonts/geometry/title etc.
88 ;; These options are passed on to term/x-win.el which see.
89 ;; -------------------------
96 ;; -L DIRNAME Add DIRNAME to load-path
98 ;; --directory DIRNAME
100 ;; -l FILE Load and execute the Emacs lisp code
101 ;; -load FILE in FILE.
104 ;; -f FUNC Execute Emacs lisp function FUNC with
105 ;; -funcall FUNC no arguments. The "-e" form is outdated
106 ;; --funcall FUNC and should not be used. (It's a typo
107 ;; -e FUNC promoted to a feature.)
109 ;; -eval FORM Execute Emacs lisp form FORM.
114 ;; -insert FILE Insert the contents of FILE into buffer.
116 ;; -------------------------
117 ;; -kill Kill (exit) Emacs right away.
119 ;; -------------------------
123 (setq top-level
'(normal-top-level))
125 (defvar command-line-processed nil
126 "Non-nil once command line has been processed.")
128 (defgroup initialization nil
129 "Emacs start-up procedure"
132 (defcustom inhibit-startup-message nil
133 "*Non-nil inhibits the initial startup message.
134 This is for use in your personal init file, once you are familiar
135 with the contents of the startup message."
137 :group
'initialization
)
139 (defcustom inhibit-startup-echo-area-message nil
140 "*Non-nil inhibits the initial startup echo area message.
141 Setting this variable takes effect
142 only if you do it with the customization buffer
143 or if your `.emacs' file contains a line of this form:
144 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
145 If your `.emacs' file is byte-compiled, use the following form instead:
146 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
147 Thus, someone else using a copy of your `.emacs' file will see
148 the startup message unless he personally acts to inhibit it."
149 :type
'(choice (const :tag
"Don't inhibit")
150 (string :tag
"Enter your user name, to inhibit"))
151 :group
'initialization
)
153 (defcustom inhibit-default-init nil
154 "*Non-nil inhibits loading the `default' library."
156 :group
'initialization
)
158 (defcustom inhibit-startup-buffer-menu nil
159 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
161 :group
'initialization
)
163 (defvar command-switch-alist nil
164 "Alist of command-line switches.
165 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
166 HANDLER-FUNCTION receives switch name as sole arg;
167 remaining command-line args are in the variable `command-line-args-left'.")
169 (defvar command-line-args-left nil
170 "List of command-line args not yet processed.")
172 (defvar command-line-functions nil
;; lrs 7/31/89
173 "List of functions to process unrecognized command-line arguments.
174 Each function should access the dynamically bound variables
175 `argi' (the current argument) and `command-line-args-left' (the remaining
176 arguments). The function should return non-nil only if it recognizes and
177 processes `argi'. If it does so, it may consume successive arguments by
178 altering `command-line-args-left' to remove them.")
180 (defvar command-line-default-directory nil
181 "Default directory to use for command line arguments.
182 This is normally copied from `default-directory' when Emacs starts.")
184 ;;; This is here, rather than in x-win.el, so that we can ignore these
185 ;;; options when we are not using X.
186 (defconst command-line-x-option-alist
187 '(("-bw" 1 x-handle-numeric-switch border-width
)
188 ("-d" 1 x-handle-display
)
189 ("-display" 1 x-handle-display
)
190 ("-name" 1 x-handle-name-switch
)
191 ("-title" 1 x-handle-switch title
)
192 ("-T" 1 x-handle-switch title
)
193 ("-r" 0 x-handle-switch reverse t
)
194 ("-rv" 0 x-handle-switch reverse t
)
195 ("-reverse" 0 x-handle-switch reverse t
)
196 ("-reverse-video" 0 x-handle-switch reverse t
)
197 ("-fn" 1 x-handle-switch font
)
198 ("-font" 1 x-handle-switch font
)
199 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
200 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
201 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
202 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
203 ("-g" 1 x-handle-geometry
)
204 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
205 ("-geometry" 1 x-handle-geometry
)
206 ("-fg" 1 x-handle-switch foreground-color
)
207 ("-foreground" 1 x-handle-switch foreground-color
)
208 ("-bg" 1 x-handle-switch background-color
)
209 ("-background" 1 x-handle-switch background-color
)
210 ("-ms" 1 x-handle-switch mouse-color
)
211 ("-itype" 0 x-handle-switch icon-type t
)
212 ("-i" 0 x-handle-switch icon-type t
)
213 ("-iconic" 0 x-handle-iconic
)
214 ("-xrm" 1 x-handle-xrm-switch
)
215 ("-cr" 1 x-handle-switch cursor-color
)
216 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
217 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
218 ("-bd" 1 x-handle-switch
)
219 ("--border-width" 1 x-handle-numeric-switch border-width
)
220 ("--display" 1 x-handle-display
)
221 ("--name" 1 x-handle-name-switch
)
222 ("--title" 1 x-handle-switch title
)
223 ("--reverse-video" 0 x-handle-switch reverse t
)
224 ("--font" 1 x-handle-switch font
)
225 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
226 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
227 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
228 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
229 ("--geometry" 1 x-handle-geometry
)
230 ("--foreground-color" 1 x-handle-switch foreground-color
)
231 ("--background-color" 1 x-handle-switch background-color
)
232 ("--mouse-color" 1 x-handle-switch mouse-color
)
233 ("--icon-type" 0 x-handle-switch icon-type t
)
234 ("--iconic" 0 x-handle-iconic
)
235 ("--xrm" 1 x-handle-xrm-switch
)
236 ("--cursor-color" 1 x-handle-switch cursor-color
)
237 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
238 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
239 ("--border-color" 1 x-handle-switch border-width
)
240 ("--smid" 1 x-handle-smid
))
241 "Alist of X Windows options.
242 Each element has the form
243 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
244 where NAME is the option name string, NUMARGS is the number of arguments
245 that the option accepts, HANDLER is a function to call to handle the option.
246 FRAME-PARAM (optional) is the frame parameter this option specifies,
247 and VALUE is the value which is given to that frame parameter
248 \(most options use the argument for this, so VALUE is not present).")
250 (defvar before-init-hook nil
251 "Normal hook run after handling urgent options but before loading init files.")
253 (defvar after-init-hook nil
254 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
255 There is no `condition-case' around the running of these functions;
256 therefore, if you set `debug-on-error' non-nil in `.emacs',
257 an error in one of these functions will invoke the debugger.")
259 (defvar emacs-startup-hook nil
260 "Normal hook run after loading init files and handling the command line.")
262 (defvar term-setup-hook nil
263 "Normal hook run after loading terminal-specific Lisp code.
264 It also follows `emacs-startup-hook'. This hook exists for users to set,
265 so as to override the definitions made by the terminal-specific file.
266 Emacs never sets this variable itself.")
268 (defvar keyboard-type nil
269 "The brand of keyboard you are using.
270 This variable is used to define
271 the proper function and keypad keys for use under X. It is used in a
272 fashion analogous to the environment variable TERM.")
274 (defvar window-setup-hook nil
275 "Normal hook run to initialize window system display.
276 Emacs runs this hook after processing the command line arguments and loading
277 the user's init file.")
279 (defcustom initial-major-mode
'lisp-interaction-mode
280 "Major mode command symbol to use for the initial *scratch* buffer."
282 :group
'initialization
)
284 (defcustom init-file-user nil
285 "Identity of user whose `.emacs' file is or was read.
286 The value is nil if `-q' or `--no-init-file' was specified,
287 meaning do not load any init file.
289 Otherwise, the value may be the null string, meaning use the init file
290 for the user that originally logged in, or it may be a
291 string containing a user's name meaning use that person's init file.
293 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
294 evaluates to the name of the directory where the `.emacs' file was
297 Setting `init-file-user' does not prevent Emacs from loading
298 `site-start.el'. The only way to do that is to use `--no-site-file'."
299 :type
'(choice (const :tag
"none" nil
) string
)
300 :group
'initialization
)
302 (defcustom site-run-file
"site-start"
303 "File containing site-wide run-time initializations.
304 This file is loaded at run-time before `~/.emacs'. It contains inits
305 that need to be in place for the entire site, but which, due to their
306 higher incidence of change, don't make sense to load into emacs'
307 dumped image. Thus, the run-time load order is: 1. file described in
308 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
310 Don't use the `site-start.el' file for things some users may not like.
311 Put them in `default.el' instead, so that users can more easily
312 override them. Users can prevent loading `default.el' with the `-q'
313 option or by setting `inhibit-default-init' in their own init files,
314 but inhibiting `site-start.el' requires `--no-site-file', which
316 :type
'(choice (const :tag
"none" nil
) string
)
317 :group
'initialization
)
319 (defcustom mail-host-address nil
320 "*Name of this machine, for purposes of naming users."
321 :type
'(choice (const nil
) string
)
324 (defcustom user-mail-address nil
325 "*Full mailing address of this user.
326 This is initialized based on `mail-host-address',
327 after your init file is read, in case it sets `mail-host-address'."
331 (defcustom auto-save-list-file-prefix
332 (cond ((eq system-type
'ms-dos
)
333 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
334 "~/_emacs.d/auto-save.list/_s")
336 "~/.emacs.d/auto-save-list/.saves-"))
337 "Prefix for generating `auto-save-list-file-name'.
338 This is used after reading your `.emacs' file to initialize
339 `auto-save-list-file-name', by appending Emacs's pid and the system name,
340 if you have not already set `auto-save-list-file-name' yourself.
341 Directories in the prefix will be created if necessary.
342 Set this to nil if you want to prevent `auto-save-list-file-name'
343 from being initialized."
344 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
348 (defvar init-file-debug nil
)
350 (defvar init-file-had-error nil
)
352 (defvar normal-top-level-add-subdirs-inode-list nil
)
354 (defun normal-top-level-add-subdirs-to-load-path ()
355 "Add all subdirectories of current directory to `load-path'.
356 More precisely, this uses only the subdirectories whose names
357 start with letters or digits; it excludes any subdirectory named `RCS'
358 or `CVS', and any subdirectory that contains a file named `.nosearch'."
361 (pending (list default-directory
)))
362 ;; This loop does a breadth-first tree walk on DIR's subtree,
363 ;; putting each subdir into DIRS as its contents are examined.
365 (push (pop pending
) dirs
)
366 (let* ((this-dir (car dirs
))
367 (contents (directory-files this-dir
))
368 (default-directory this-dir
)
369 (canonicalized (and (eq system-type
'windows-nt
)
370 (untranslated-canonical-name this-dir
))))
371 ;; The Windows version doesn't report meaningful inode
372 ;; numbers, so use the canonicalized absolute file name of the
373 ;; directory instead.
374 (setq attrs
(or canonicalized
375 (nthcdr 10 (file-attributes this-dir
))))
376 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
377 (push attrs normal-top-level-add-subdirs-inode-list
)
378 (dolist (file contents
)
379 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
380 (unless (member file
'("." ".." "RCS" "CVS" "rcs" "cvs"))
381 (when (and (string-match "\\`[[:alnum:]]" file
)
382 ;; Avoid doing a `stat' when it isn't necessary
383 ;; because that can cause trouble when an NFS server
385 (not (string-match "\\.elc?\\'" file
))
386 (file-directory-p file
))
387 (let ((expanded (expand-file-name file
)))
388 (unless (file-exists-p (expand-file-name ".nosearch"
390 (setq pending
(nconc pending
(list expanded
)))))))))))
391 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
393 ;; This function is called from a subdirs.el file.
394 ;; It assumes that default-directory is the directory
395 ;; in which the subdirs.el file exists,
396 ;; and it adds to load-path the subdirs of that directory
397 ;; as specified in DIRS. Normally the elements of DIRS are relative.
398 (defun normal-top-level-add-to-load-path (dirs)
399 (let ((tail load-path
)
400 (thisdir (directory-file-name default-directory
)))
402 ;;Don't go all the way to the nil terminator.
404 (not (equal thisdir
(car tail
)))
405 (not (and (memq system-type
'(ms-dos windows-nt
))
406 (equal (downcase thisdir
) (downcase (car tail
))))))
407 (setq tail
(cdr tail
)))
408 ;;Splice the new section in.
410 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
412 (defun normal-top-level ()
413 (if command-line-processed
414 (message "Back to top level.")
415 (setq command-line-processed t
)
416 ;; Give *Messages* the same default-directory as *scratch*,
417 ;; just to keep things predictable.
418 (let ((dir default-directory
))
420 (set-buffer (get-buffer "*Messages*"))
421 (setq default-directory dir
)))
422 ;; For root, preserve owner and group when editing files.
423 (if (equal (user-uid) 0)
424 (setq backup-by-copying-when-mismatch t
))
425 ;; Look in each dir in load-path for a subdirs.el file.
426 ;; If we find one, load it, which will add the appropriate subdirs
427 ;; of that dir into load-path,
428 ;; Look for a leim-list.el file too. Loading it will register
429 ;; available input methods.
430 (let ((tail load-path
)
433 (push (car tail
) new
)
435 (let ((default-directory (car tail
)))
436 (load (expand-file-name "subdirs.el" (car tail
)) t t t
)))
438 (let ((default-directory (car tail
)))
439 (load (expand-file-name "leim-list.el" (car tail
)) t t t
)))
440 (setq tail
(cdr tail
))))
441 (if (not (eq system-type
'vax-vms
))
443 ;; If the PWD environment variable isn't accurate, delete it.
444 (let ((pwd (getenv "PWD")))
446 ;; Use FOO/., so that if FOO is a symlink, file-attributes
447 ;; describes the directory linked to, not FOO itself.
448 (or (equal (file-attributes
449 (concat (file-name-as-directory pwd
) "."))
451 (concat (file-name-as-directory default-directory
)
453 (setq process-environment
454 (delete (concat "PWD=" pwd
)
455 process-environment
)))))))
456 (setq default-directory
(abbreviate-file-name default-directory
))
457 (let ((menubar-bindings-done nil
))
460 ;; Do this again, in case .emacs defined more abbreviations.
461 (setq default-directory
(abbreviate-file-name default-directory
))
462 ;; Specify the file for recording all the auto save files of this session.
463 ;; This is used by recover-session.
464 (or auto-save-list-file-name
465 (and auto-save-list-file-prefix
466 (setq auto-save-list-file-name
467 ;; Under MS-DOS our PID is almost always reused between
468 ;; Emacs invocations. We need something more unique.
469 (cond ((eq system-type
'ms-dos
)
470 ;; We are going to access the auto-save
471 ;; directory, so make sure it exists.
473 (file-name-directory auto-save-list-file-prefix
)
478 auto-save-list-file-prefix
))
483 auto-save-list-file-prefix
486 (run-hooks 'emacs-startup-hook
)
488 (run-hooks 'term-setup-hook
))
490 ;; Don't do this if we failed to create the initial frame,
491 ;; for instance due to a dense colormap.
492 (when (or frame-initial-frame
493 ;; If frame-initial-frame has no meaning, do this anyway.
494 (not (and window-system
496 (not (eq window-system
'pc
)))))
497 ;; Modify the initial frame based on what .emacs puts into
499 (if (fboundp 'frame-notice-user-settings
)
500 (frame-notice-user-settings))
501 (if (fboundp 'frame-set-background-mode
)
502 ;; Set the faces for the initial background mode even if
503 ;; frame-notice-user-settings didn't (such as on a tty).
504 ;; frame-set-background-mode is idempotent, so it won't
505 ;; cause any harm if it's already been done.
506 (let ((frame-background-mode frame-background-mode
)
507 (frame (selected-frame))
509 (when (and (null window-system
)
510 ;; Don't override a possibly customized value.
511 (null frame-background-mode
)
512 ;; Don't override user specifications.
513 (null (frame-parameter frame
'reverse
))
514 (let ((bg (frame-parameter frame
'background-color
)))
516 (member bg
'(unspecified "unspecified-bg")))))
517 (setq term
(getenv "TERM"))
518 ;; Some files in lisp/term do a better job with the
519 ;; background mode, but we leave this here anyway, in
520 ;; case they remove those files.
521 (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
523 (setq frame-background-mode
'light
)))
524 (frame-set-background-mode (selected-frame)))))
526 ;; Now we know the user's default font, so add it to the menu.
527 (if (fboundp 'font-menu-add-default
)
528 (font-menu-add-default))
529 (and window-setup-hook
530 (run-hooks 'window-setup-hook
))
531 (or menubar-bindings-done
532 (if (display-popup-menus-p)
533 (precompute-menubar-bindings)))))))
535 ;; Precompute the keyboard equivalents in the menu bar items.
536 (defun precompute-menubar-bindings ()
537 (let ((submap (lookup-key global-map
[menu-bar
])))
539 (and (consp (car submap
))
540 (symbolp (car (car submap
)))
541 (stringp (car-safe (cdr (car submap
))))
542 (keymapp (cdr (cdr (car submap
))))
544 (x-popup-menu nil
(cdr (cdr (car submap
))))
547 (setq submap
(cdr submap
))))
548 (setq define-key-rebound-commands t
))
550 ;; Command-line options supported by tty's:
551 (defconst tty-long-option-alist
552 '(("--name" .
"-name")
554 ("--reverse-video" .
"-reverse")
555 ("--foreground-color" .
"-fg")
556 ("--background-color" .
"-bg")
557 ("--color" .
"-color")))
559 (defconst tool-bar-images-pixel-height
24
560 "Height in pixels of images in the tool bar.")
562 (defvar tool-bar-originally-present nil
563 "Non-nil if tool-bars are present before user and site init files are read.")
565 ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc.
566 (defun tty-handle-args (args)
570 (not (equal (car args
) "--")))
571 (let* ((this (car args
))
574 (setq args
(cdr args
))
575 ;; Check for long options with attached arguments
576 ;; and separate out the attached option argument into argval.
577 (if (string-match "^--[^=]*=" this
)
578 (setq argval
(substring this
(match-end 0))
579 this
(substring this
0 (1- (match-end 0)))))
580 (when (string-match "^--" this
)
581 (setq completion
(try-completion this tty-long-option-alist
))
582 (if (eq completion t
)
583 ;; Exact match for long option.
584 (setq this
(cdr (assoc this tty-long-option-alist
)))
585 (if (stringp completion
)
586 (let ((elt (assoc completion tty-long-option-alist
)))
587 ;; Check for abbreviated long option.
589 (error "Option `%s' is ambiguous" this
))
590 (setq this
(cdr elt
)))
591 ;; Check for a short option.
592 (setq argval nil this orig-this
))))
593 (cond ((or (string= this
"-fg") (string= this
"-foreground"))
594 (or argval
(setq argval
(car args
) args
(cdr args
)))
595 (setq default-frame-alist
596 (cons (cons 'foreground-color argval
)
597 default-frame-alist
)))
598 ((or (string= this
"-bg") (string= this
"-background"))
599 (or argval
(setq argval
(car args
) args
(cdr args
)))
600 (setq default-frame-alist
601 (cons (cons 'background-color argval
)
602 default-frame-alist
)))
603 ((or (string= this
"-T") (string= this
"-name"))
604 (or argval
(setq argval
(car args
) args
(cdr args
)))
605 (setq default-frame-alist
610 (let ((case-fold-search t
)
612 (setq argval
(invocation-name))
614 ;; Change any . or * characters in name to
615 ;; hyphens, so as to emulate behavior on X.
617 (setq i
(string-match "[.*]" argval
))
620 default-frame-alist
)))
621 ((or (string= this
"-r")
623 (string= this
"-reverse"))
624 (setq default-frame-alist
626 default-frame-alist
)))
627 ((string= this
"-color")
629 (setq argval
8)) ; default --color means 8 ANSI colors
630 (setq default-frame-alist
631 (cons (cons 'tty-color-mode
633 ((numberp argval
) argval
)
634 ((string-match "-?[0-9]+" argval
)
635 (string-to-number argval
))
636 (t (intern argval
))))
637 default-frame-alist
)))
638 (t (setq rest
(cons this rest
))))))
641 (defun command-line ()
642 (setq command-line-default-directory default-directory
)
644 ;; Choose a reasonable location for temporary files.
645 (setq temporary-file-directory
646 (file-name-as-directory
647 (cond ((memq system-type
'(ms-dos windows-nt
))
648 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
649 ((memq system-type
'(vax-vms axp-vms
))
650 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
652 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))))
653 (setq small-temporary-file-directory
654 (if (eq system-type
'ms-dos
)
656 (setq auto-save-file-name-transforms
657 (list (list "\\`/[^/]*:\\(.+/\\)*\\(.*\\)"
658 ;; Don't put "\\2" inside expand-file-name, since
659 ;; it will be transformed to "/2" on DOS/Windows.
660 (concat temporary-file-directory
"\\2"))))
662 ;; See if we should import version-control from the environment variable.
663 (let ((vc (getenv "VERSION_CONTROL")))
664 (cond ((eq vc nil
)) ;don't do anything if not set
665 ((or (string= vc
"t")
666 (string= vc
"numbered"))
667 (setq version-control t
))
668 ((or (string= vc
"nil")
669 (string= vc
"existing"))
670 (setq version-control nil
))
671 ((or (string= vc
"never")
672 (string= vc
"simple"))
673 (setq version-control
'never
))))
675 ;;! This has been commented out; I currently find the behavior when
676 ;;! split-window-keep-point is nil disturbing, but if I can get used
677 ;;! to it, then it would be better to eliminate the option.
678 ;;! ;; Choose a good default value for split-window-keep-point.
679 ;;! (setq split-window-keep-point (> baud-rate 2400))
681 ;; Set the default strings to display in mode line for
682 ;; end-of-line formats that aren't native to this platform.
684 ((memq system-type
'(ms-dos windows-nt emx
))
685 (setq eol-mnemonic-unix
"(Unix)")
686 (setq eol-mnemonic-mac
"(Mac)"))
687 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
688 ;; abbreviated strings `/' and `:' set in coding.c for them.
689 ((eq system-type
'macos
)
690 (setq eol-mnemonic-dos
"(DOS)"))
691 (t ; this is for Unix/GNU/Linux systems
692 (setq eol-mnemonic-dos
"(DOS)")
693 (setq eol-mnemonic-mac
"(Mac)")))
695 ;; Read window system's init file if using a window system.
696 (condition-case error
697 (if (and window-system
(not noninteractive
))
698 (load (concat term-file-prefix
699 (symbol-name window-system
)
701 ;; Every window system should have a startup file;
702 ;; barf if we can't find it.
704 ;; If we can't read it, print the error message and exit.
707 (if (eq (car error
) 'error
)
708 (apply 'concat
(cdr error
))
709 (if (memq 'file-error
(get (car error
) 'error-conditions
))
712 (mapconcat (lambda (obj) (prin1-to-string obj t
))
713 (cdr (cdr error
)) ", "))
715 (get (car error
) 'error-message
)
716 (mapconcat (lambda (obj) (prin1-to-string obj t
))
718 'external-debugging-output
)
719 (terpri 'external-debugging-output
)
720 (setq window-system nil
)
723 ;; Windowed displays do this inside their *-win.el.
724 (when (and (not (display-graphic-p))
725 (not noninteractive
))
726 (setq command-line-args
(tty-handle-args command-line-args
)))
728 (set-locale-environment nil
)
730 ;; Convert the arguments to Emacs internal representation.
731 (let ((args (cdr command-line-args
)))
734 (decode-coding-string (car args
) locale-coding-system t
))
735 (setq args
(cdr args
))))
738 (args (cdr command-line-args
)))
740 ;; Figure out which user's init file to load,
741 ;; either from the environment or from the options.
742 (setq init-file-user
(if noninteractive nil
(user-login-name)))
743 ;; If user has not done su, use current $HOME to find .emacs.
744 (and init-file-user
(string= init-file-user
(user-real-login-name))
745 (setq init-file-user
""))
747 ;; Process the command-line args, and delete the arguments
748 ;; processed. This is consistent with the way main in emacs.c
750 (while (and (not done
) args
)
751 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
752 ("--debug-init") ("--iconic") ("--icon-type")))
755 ;; Handle --OPTION=VALUE format.
756 (if (and (string-match "\\`--" argi
)
757 (string-match "=" argi
))
758 (setq argval
(substring argi
(match-end 0))
759 argi
(substring argi
0 (match-beginning 0))))
760 (or (equal argi
"--")
761 (let ((completion (try-completion argi longopts
)))
762 (if (eq completion t
)
763 (setq argi
(substring argi
1))
764 (if (stringp completion
)
765 (let ((elt (assoc completion longopts
)))
767 (error "Option `%s' is ambiguous" argi
))
768 (setq argi
(substring (car elt
) 1)))
769 (setq argval nil
)))))
771 ((member argi
'("-q" "-no-init-file"))
772 (setq init-file-user nil
))
773 ((member argi
'("-u" "-user"))
775 (setq argval
(pop args
)))
776 (setq init-file-user argval
778 ((string-equal argi
"-no-site-file")
779 (setq site-run-file nil
))
780 ((string-equal argi
"-debug-init")
781 (setq init-file-debug t
))
782 ((string-equal argi
"-iconic")
783 (push '(visibility . icon
) initial-frame-alist
))
784 ((or (string-equal argi
"-icon-type")
785 (string-equal argi
"-i")
786 (string-equal argi
"-itype"))
787 (push '(icon-type . t
) default-frame-alist
))
788 ;; Push the popped arg back on the list of arguments.
789 (t (push argi args
) (setq done t
)))
790 ;; Was argval set but not used?
792 (error "Option `%s' doesn't allow an argument" argi
))))
794 ;; Re-attach the program name to the front of the arg list.
795 (and command-line-args
(setcdr command-line-args args
)))
797 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
798 (when (fboundp 'frame-initialize
)
801 ;; If frame was created with a menu bar, set menu-bar-mode on.
802 (if (and (not noninteractive
)
803 (or (not (memq window-system
'(x w32
)))
804 (> (frame-parameter nil
'menu-bar-lines
) 0)))
807 ;; If frame was created with a tool bar, switch tool-bar-mode on.
808 (when (and (not noninteractive
)
810 (> (frame-parameter nil
'tool-bar-lines
) 0))
813 ;; Can't do this init in defcustom because window-system isn't set.
814 (when (and (not noninteractive
)
815 (not (eq system-type
'ms-dos
))
816 (memq window-system
'(x w32
)))
817 (setq-default blink-cursor t
)
818 (blink-cursor-mode 1))
820 (unless noninteractive
821 ;; DOS/Windows systems have a PC-type keyboard which has both
822 ;; <delete> and <backspace> keys.
823 (when (or (memq system-type
'(ms-dos windows-nt
))
824 (and (memq window-system
'(x))
825 (fboundp 'x-backspace-delete-keys-p
)
826 (x-backspace-delete-keys-p))
827 ;; If the terminal Emacs is running on has erase char
828 ;; set to ^H, use the Backspace key for deleting
829 ;; backward and, and the Delete key for deleting forward.
830 (and (null window-system
)
831 (eq tty-erase-char
8)))
832 (setq-default normal-erase-is-backspace t
)
833 (normal-erase-is-backspace-mode 1)))
835 (when (and (not noninteractive
)
837 (fboundp 'x-show-tip
))
838 (setq-default tooltip-mode t
)
841 ;; Register default TTY colors for the case the terminal hasn't a
842 ;; terminal init file.
843 (or (memq window-system
'(x w32
))
844 ;; We do this regardles of whether the terminal supports colors
845 ;; or not, since they can switch that support on or off in
846 ;; mid-session by setting the tty-color-mode frame parameter.
847 (tty-register-default-colors))
849 ;; Record whether the tool-bar is present before the user and site
850 ;; init files are processed. frame-notice-user-settings uses this
851 ;; to determine if the tool-bar has been disabled by the init files,
852 ;; and the frame needs to be resized.
853 (when (fboundp 'frame-notice-user-settings
)
854 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
855 (assq 'tool-bar-lines default-frame-alist
))))
856 (setq tool-bar-originally-present
857 (not (or (null tool-bar-lines
)
858 (null (cdr tool-bar-lines
))
859 (eq 0 (cdr tool-bar-lines
)))))))
861 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
862 (old-font-list-limit font-list-limit
)
863 (old-face-ignored-fonts face-ignored-fonts
))
865 (run-hooks 'before-init-hook
)
867 ;; Run the site-start library if it exists. The point of this file is
868 ;; that it is run before .emacs. There is no point in doing this after
869 ;; .emacs; that is useless.
871 (load site-run-file t t
))
873 ;; Sites should not disable this. Only individuals should disable
874 ;; the startup message.
875 (setq inhibit-startup-message nil
)
877 ;; Load that user's init file, or the default one, or none.
878 (let (debug-on-error-from-init-file
879 debug-on-error-should-be-set
880 (debug-on-error-initial
881 (if (eq init-file-debug t
) 'startup init-file-debug
))
882 (orig-enable-multibyte default-enable-multibyte-characters
))
883 (let ((debug-on-error debug-on-error-initial
)
884 ;; This function actually reads the init files.
889 (let ((user-init-file-1
891 ((eq system-type
'ms-dos
)
892 (concat "~" init-file-user
"/_emacs"))
893 ((eq system-type
'windows-nt
)
894 (if (directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
897 ((eq system-type
'vax-vms
)
900 (concat "~" init-file-user
"/.emacs")))))
901 ;; This tells `load' to store the file name found
902 ;; into user-init-file.
903 (setq user-init-file t
)
904 (load user-init-file-1 t t
)
906 ;; If we did not find the user's init file,
907 ;; set user-init-file conclusively to nil;
908 ;; don't let it be set from default.el.
909 (if (eq user-init-file t
)
910 (setq user-init-file user-init-file-1
))
912 ;; If we loaded a compiled file, set
913 ;; `user-init-file' to the source version if that
915 (when (and user-init-file
916 (equal (file-name-extension user-init-file
)
918 (let* ((source (file-name-sans-extension user-init-file
))
919 (alt (concat source
".el")))
920 (setq source
(cond ((file-exists-p alt
) alt
)
921 ((file-exists-p source
) source
)
924 (when (file-newer-than-file-p source user-init-file
)
925 (message "Warning: %s is newer than %s"
926 source user-init-file
)
928 (setq user-init-file source
))))
930 (or inhibit-default-init
931 (let ((inhibit-startup-message nil
))
932 ;; Users are supposed to be told their rights.
933 ;; (Plus how to get help and how to undo.)
934 ;; Don't you dare turn this off for anyone
936 (load "default" t t
)))))))))
938 ;; Do this without a condition-case if the user wants to debug.
940 (condition-case error
943 (setq init-file-had-error nil
))
945 (let ((message-log-max nil
))
947 (set-buffer (get-buffer-create "*Messages*"))
949 (format "An error has occurred while loading `%s':\n\n"
952 (get (car error
) 'error-message
)
953 (if (cdr error
) ": " "")
954 (mapconcat 'prin1-to-string
(cdr error
) ", "))
956 "To ensure normal operation, you should investigate the cause\n"
957 "of the error in your initialization file and remove it. Start\n"
958 "Emacs with the `--debug-init' option to view a complete error\n"
960 (message "Error in init file: %s%s%s"
961 (get (car error
) 'error-message
)
962 (if (cdr error
) ": " "")
963 (mapconcat 'prin1-to-string
(cdr error
) ", "))
964 (pop-to-buffer "*Messages*")
965 (setq init-file-had-error t
)))))
967 ;; If the user has a file of abbrevs, read it.
968 (if (file-exists-p abbrev-file-name
)
969 (quietly-read-abbrev-file abbrev-file-name
))
971 ;; If the abbrevs came entirely from the init file or the
972 ;; abbrevs file, they do not need saving.
973 (setq abbrevs-changed nil
)
975 ;; If we can tell that the init file altered debug-on-error,
976 ;; arrange to preserve the value that it set up.
977 (or (eq debug-on-error debug-on-error-initial
)
978 (setq debug-on-error-should-be-set t
979 debug-on-error-from-init-file debug-on-error
)))
980 (if debug-on-error-should-be-set
981 (setq debug-on-error debug-on-error-from-init-file
))
982 (unless (or default-enable-multibyte-characters
983 (eq orig-enable-multibyte default-enable-multibyte-characters
))
984 ;; Init file changed to unibyte. Reset existing multibyte
985 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
986 ;; Arguably this should only be done if they're free of
987 ;; multibyte characters.
988 (mapcar (lambda (buffer)
989 (with-current-buffer buffer
990 (if enable-multibyte-characters
991 (set-buffer-multibyte nil
))))
993 ;; Also re-set the language environment in case it was
994 ;; originally done before unibyte was set and is sensitive to
995 ;; unibyte (display table, terminal coding system &c).
996 (set-language-environment current-language-environment
)))
998 ;; Do this here in case the init file sets mail-host-address.
999 (or user-mail-address
1000 (setq user-mail-address
(concat (user-login-name) "@"
1001 (or mail-host-address
1004 ;; If parameter have been changed in the init file which influence
1005 ;; face realization, clear the face cache so that new faces will
1007 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1008 (eq font-list-limit old-font-list-limit
)
1009 (eq face-ignored-fonts old-face-ignored-fonts
))
1010 (clear-face-cache)))
1012 (run-hooks 'after-init-hook
)
1014 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1015 (if (get-buffer "*scratch*")
1017 (set-buffer "*scratch*")
1018 (if (eq major-mode
'fundamental-mode
)
1019 (funcall initial-major-mode
))))
1021 ;; Load library for our terminal type.
1022 ;; User init file can set term-file-prefix to nil to prevent this.
1023 (and term-file-prefix
(not noninteractive
) (not window-system
)
1024 (let ((term (getenv "TERM"))
1027 (not (load (concat term-file-prefix term
) t t
)))
1028 ;; Strip off last hyphen and what follows, then try again
1029 (if (setq hyphend
(string-match "[-_][^-_]+$" term
))
1030 (setq term
(substring term
0 hyphend
))
1033 ;; Process the remaining args.
1034 (command-line-1 (cdr command-line-args
))
1036 ;; If -batch, terminate after processing the command options.
1037 (if noninteractive
(kill-emacs t
))
1039 ;; Run emacs-session-restore (session management) if started by
1040 ;; the session manager and we have a session manager connection.
1041 (if (and (boundp 'x-session-previous-id
) (stringp x-session-previous-id
))
1042 (emacs-session-restore x-session-previous-id
)))
1044 (defcustom initial-scratch-message
(purecopy "\
1045 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1046 ;; If you want to create a file, visit that file with C-x C-f,
1047 ;; then enter the text in that file's own buffer.
1050 "Initial message displayed in *scratch* buffer at startup.
1051 If this is nil, no message will be displayed."
1052 :type
'(choice (text :tag
"Message")
1053 (const :tag
"none" nil
))
1054 :group
'initialization
)
1057 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1058 ;;; Fancy splash screen
1059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1061 (defvar fancy-splash-text
1062 '((:face variable-pitch
1063 "You can do basic editing with the menu bar and scroll bar \
1064 using the mouse.\n\n"
1065 :face
(variable-pitch :weight bold
)
1066 "Important Help menu items:\n"
1067 :face variable-pitch
"\
1068 Emacs Tutorial\tLearn-by-doing tutorial for using Emacs efficiently
1069 Emacs FAQ\tFrequently asked questions and answers
1070 \(Non)Warranty\tGNU Emacs comes with "
1071 :face
(variable-pitch :slant oblique
)
1072 "ABSOLUTELY NO WARRANTY\n"
1073 :face variable-pitch
1075 Copying Conditions\tConditions for redistributing and changing Emacs
1076 Ordering Manuals\tHow to order Emacs manuals from the Free Software Foundation\n")
1077 (:face variable-pitch
1078 "You can do basic editing with the menu bar and scroll bar \
1079 using the mouse.\n\n"
1080 :face
(variable-pitch :weight bold
)
1081 "Useful File menu items:\n"
1082 :face variable-pitch
"\
1083 Exit Emacs\t(Or type Control-x followed by Control-c)
1084 Recover Session\tRecover files you were editing before a crash
1090 "A list of texts to show in the middle part of splash screens.
1091 Each element in the list should be a list of strings or pairs
1092 `:face FACE', like `fancy-splash-insert' accepts them.")
1095 (defgroup fancy-splash-screen
()
1096 "Fancy splash screen when Emacs starts."
1098 :group
'initialization
)
1101 (defcustom fancy-splash-delay
10
1102 "*Delay in seconds between splash screens."
1103 :group
'fancy-splash-screen
1107 (defcustom fancy-splash-max-time
60
1108 "*Show splash screens for at most this number of seconds.
1109 Values less than 60 seconds are ignored."
1110 :group
'fancy-splash-screen
1114 (defcustom fancy-splash-image nil
1115 "*The image to show in the splash screens, or nil for defaults."
1116 :group
'fancy-splash-screen
1117 :type
'(choice (const :tag
"Default" nil
)
1118 (file :tag
"File")))
1121 ;; These are temporary storage areas for the splash screen display.
1123 (defvar fancy-current-text nil
)
1124 (defvar fancy-splash-help-echo nil
)
1125 (defvar fancy-splash-stop-time nil
)
1126 (defvar fancy-splash-outer-buffer nil
)
1128 (defun fancy-splash-insert (&rest args
)
1129 "Insert text into the current buffer, with faces.
1130 Arguments from ARGS should be either strings or pairs `:face FACE',
1131 where FACE is a valid face specification, as it can be used with
1132 `put-text-properties'."
1133 (let ((current-face nil
))
1135 (if (eq (car args
) :face
)
1136 (setq args
(cdr args
) current-face
(car args
))
1137 (insert (propertize (car args
)
1139 'help-echo fancy-splash-help-echo
)))
1140 (setq args
(cdr args
)))))
1143 (defun fancy-splash-head ()
1144 "Insert the head part of the splash screen into the current buffer."
1145 (let* ((image-file (cond ((stringp fancy-splash-image
)
1147 ((and (display-color-p)
1148 (image-type-available-p 'xpm
))
1149 (if (and (fboundp 'x-display-planes
)
1150 (= (funcall 'x-display-planes
) 8))
1154 (img (create-image image-file
))
1155 (image-width (and img
(car (image-size img
))))
1156 (window-width (window-width (selected-window))))
1158 (when (> window-width image-width
)
1159 ;; Center the image in the window.
1160 (let ((pos (/ (- window-width image-width
) 2)))
1161 (insert (propertize " " 'display
`(space :align-to
,pos
))))
1163 ;; Change the color of the XPM version of the splash image
1164 ;; so that it is visible with a dark frame background.
1165 (when (and (memq 'xpm img
)
1166 (eq (frame-parameter nil
'background-mode
) 'dark
))
1167 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1169 ;; Insert the image with a help-echo and a keymap.
1170 (let ((map (make-sparse-keymap))
1171 (help-echo "mouse-2: browse http://www.gnu.org/"))
1172 (define-key map
[mouse-2
]
1175 (browse-url "http://www.gnu.org/")
1177 (define-key map
[down-mouse-2
] 'ignore
)
1178 (define-key map
[up-mouse-2
] 'ignore
)
1179 (insert-image img
(propertize "xxx" 'help-echo help-echo
1182 (if (eq system-type
'gnu
/linux
)
1183 (fancy-splash-insert
1184 :face
'(variable-pitch :foreground
"red")
1185 "GNU Emacs is one component of a Linux-based GNU system.")
1186 (fancy-splash-insert
1187 :face
'(variable-pitch :foreground
"red")
1188 "GNU Emacs is one component of the GNU operating system."))
1190 (unless (equal (buffer-name fancy-splash-outer-buffer
) "*scratch*")
1191 (fancy-splash-insert :face
'variable-pitch
1192 (substitute-command-keys
1193 "Type \\[recenter] to begin editing your file.\n"))))
1196 (defun fancy-splash-tail ()
1197 "Insert the tail part of the splash screen into the current buffer."
1198 (let ((fg (if (eq (frame-parameter nil
'background-mode
) 'dark
)
1199 "cyan" "darkblue")))
1200 (fancy-splash-insert :face
`(variable-pitch :foreground
,fg
)
1204 :face
'(variable-pitch :height
0.5)
1205 "Copyright (C) 2002 Free Software Foundation, Inc.")
1206 (and auto-save-list-file-prefix
1207 ;; Don't signal an error if the
1208 ;; directory for auto-save-list files
1209 ;; does not yet exist.
1210 (file-directory-p (file-name-directory
1211 auto-save-list-file-prefix
))
1213 (file-name-directory auto-save-list-file-prefix
)
1216 (regexp-quote (file-name-nondirectory
1217 auto-save-list-file-prefix
)))
1219 (fancy-splash-insert :face
'(variable-pitch :foreground
"red")
1220 "\n\nIf an Emacs session crashed recently, "
1221 "type M-x recover-session RET\nto recover"
1222 " the files you were editing."))))
1224 (defun fancy-splash-screens-1 (buffer)
1225 "Timer function displaying a splash screen."
1226 (when (> (float-time) fancy-splash-stop-time
)
1227 (throw 'stop-splashing nil
))
1228 (unless fancy-current-text
1229 (setq fancy-current-text fancy-splash-text
))
1230 (let ((text (car fancy-current-text
)))
1234 (apply #'fancy-splash-insert text
)
1236 (unless (current-message)
1237 (message fancy-splash-help-echo
))
1238 (set-buffer-modified-p nil
)
1239 (goto-char (point-min))
1240 (force-mode-line-update)
1241 (setq fancy-current-text
(cdr fancy-current-text
))))
1244 (defun fancy-splash-default-action ()
1245 "Default action for events in the splash screen buffer."
1247 (push last-command-event unread-command-events
)
1251 (defun fancy-splash-screens ()
1252 "Display fancy splash screens when Emacs starts."
1253 (setq fancy-splash-help-echo
(startup-echo-area-message))
1254 (let ((old-hourglass display-hourglass
)
1255 (fancy-splash-outer-buffer (current-buffer))
1257 (old-minor-mode-map-alist minor-mode-map-alist
)
1259 (switch-to-buffer "GNU Emacs")
1261 (setq splash-buffer
(current-buffer))
1262 (catch 'stop-splashing
1264 (let ((map (make-sparse-keymap)))
1266 (define-key map
[t] 'fancy-splash-default-action)
1267 (define-key map [mouse-movement] 'ignore)
1268 (define-key map [mode-line t] 'ignore)
1269 (setq cursor-type nil
1270 display-hourglass nil
1271 minor-mode-map-alist nil
1273 mode-line-format (propertize "---- %b %-"
1274 'face '(:weight bold))
1275 fancy-splash-stop-time (+ (float-time)
1276 (max 60 fancy-splash-max-time))
1277 timer (run-with-timer 0 fancy-splash-delay
1278 #'fancy-splash-screens-1
1281 (cancel-timer timer)
1282 (setq display-hourglass old-hourglass
1283 minor-mode-map-alist old-minor-mode-map-alist)
1284 (kill-buffer splash-buffer)))))
1287 (defun use-fancy-splash-screens-p ()
1288 "Return t if fancy splash screens should be used."
1289 (when (or (and (display-color-p)
1290 (image-type-available-p 'xpm))
1291 (image-type-available-p 'pbm))
1292 (let* ((img (create-image (or fancy-splash-image
1293 (if (and (display-color-p)
1294 (image-type-available-p 'xpm))
1295 "splash.xpm" "splash.pbm"))))
1296 (image-height (and img (cdr (image-size img))))
1297 (window-height (1- (window-height (selected-window)))))
1298 (> window-height (+ image-height 19)))))
1301 (defun normal-splash-screen ()
1302 "Display splash screen when Emacs starts."
1303 (with-current-buffer (get-buffer-create "GNU Emacs")
1305 (mode-line-format (propertize "---- %b %-"
1306 'face '(:weight bold))))
1308 ;; The convention for this piece of code is that
1309 ;; each piece of output starts with one or two newlines
1310 ;; and does not end with any newlines.
1311 (insert "Welcome to GNU Emacs")
1312 (if (eq system-type 'gnu/linux)
1313 (insert ", one component of a Linux-based GNU system."))
1316 (unless (equal (buffer-name (current-buffer)) "*scratch*")
1317 (insert (substitute-command-keys
1318 "\nType \\[recenter] to begin editing your file.\n")))
1320 (if (display-mouse-p)
1321 ;; The user can use the mouse to activate menus
1322 ;; so give help in terms of menu items.
1325 You can do basic editing with the menu bar and scroll bar using the mouse.
1327 Useful File menu items:
1328 Exit Emacs (or type Control-x followed by Control-c)
1329 Recover Session recover files you were editing before a crash
1331 Important Help menu items:
1332 Emacs Tutorial Learn-by-doing tutorial for using Emacs efficiently.
1333 Emacs FAQ Frequently asked questions and answers
1334 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1335 Copying Conditions Conditions for redistributing and changing Emacs.
1336 Getting New Versions How to obtain the latest version of Emacs.
1337 Ordering Manuals How to order manuals from the FSF.
1339 (insert "\n\n" (emacs-version)
1341 Copyright (C) 2002 Free Software Foundation, Inc."))
1343 ;; No mouse menus, so give help using kbd commands.
1345 ;; If keys have their default meanings,
1346 ;; use precomputed string to save lots of time.
1347 (if (and (eq (key-binding "\C-h") 'help-command)
1348 (eq (key-binding "\C-xu") 'advertised-undo)
1349 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1350 (eq (key-binding "\C-ht") 'help-with-tutorial)
1351 (eq (key-binding "\C-hi") 'info)
1352 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1354 Get help C-h (Hold down CTRL and press h)
1355 Undo changes C-x u Exit Emacs C-x C-c
1356 Get a tutorial C-h t Use Info to read docs C-h i
1357 Ordering manuals C-h RET")
1358 (insert (substitute-command-keys
1361 Undo changes \\[advertised-undo]
1362 Exit Emacs \\[save-buffers-kill-emacs]
1363 Get a tutorial \\[help-with-tutorial]
1364 Use Info to read docs \\[info]
1365 Ordering manuals \\[view-order-manuals]"
1366 (let ((where (where-is-internal
1367 'help-command nil t)))
1369 (key-description where)
1372 ;; Say how to use the menu bar with the keyboard.
1373 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1374 (eq (key-binding [f10]) 'tmm-menubar))
1376 Activate menubar F10 or ESC ` or M-`")
1377 (insert (substitute-command-keys "
1378 Activate menubar \\[tmm-menubar]")))
1380 ;; Many users seem to have problems with these.
1382 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1383 If you have no Meta key, you may instead type ESC followed by the character.)")
1385 (insert "\n\n" (emacs-version)
1387 Copyright (C) 2002 Free Software Foundation, Inc.")
1389 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1390 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1391 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1394 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1395 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1396 of Emacs and modify it; type C-h C-c to see the conditions.
1397 Type C-h C-d for information on getting the latest version.")
1398 (insert (substitute-command-keys
1400 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1401 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1402 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1403 Type \\[describe-distribution] for information on getting the latest version."))))
1405 ;; The rest of the startup screen is the same on all
1406 ;; kinds of terminals.
1408 ;; Give information on recovering, if there was a crash.
1409 (and auto-save-list-file-prefix
1410 ;; Don't signal an error if the
1411 ;; directory for auto-save-list files
1412 ;; does not yet exist.
1413 (file-directory-p (file-name-directory
1414 auto-save-list-file-prefix))
1416 (file-name-directory auto-save-list-file-prefix)
1419 (regexp-quote (file-name-nondirectory
1420 auto-save-list-file-prefix)))
1422 (insert "\n\nIf an Emacs session crashed recently, "
1423 "type M-x recover-session RET\nto recover"
1424 " the files you were editing."))
1426 ;; Display the input that we set up in the buffer.
1427 (set-buffer-modified-p nil)
1428 (goto-char (point-min))
1429 (save-window-excursion
1430 (switch-to-buffer (current-buffer))
1432 (kill-buffer "GNU Emacs"))
1434 (defun startup-echo-area-message ()
1435 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1436 "For information about the GNU Project and its goals, type C-h C-p."
1437 (substitute-command-keys
1438 "For information about the GNU Project and its goals, type \
1439 \\[describe-project].")))
1442 (defun display-startup-echo-area-message ()
1443 (let ((resize-mini-windows t))
1444 (message (startup-echo-area-message))))
1447 (defun display-splash-screen ()
1448 "Display splash screen according to display.
1449 Fancy splash screens are used on graphic displays,
1452 (if (and (display-graphic-p)
1453 (use-fancy-splash-screens-p))
1454 (fancy-splash-screens)
1455 (normal-splash-screen)))
1458 (defun command-line-1 (command-line-args-left)
1459 (or noninteractive (input-pending-p) init-file-had-error
1460 ;; t if the init file says to inhibit the echo area startup message.
1461 (and inhibit-startup-echo-area-message
1463 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1464 (equal inhibit-startup-echo-area-message
1465 (if (string= init-file-user "")
1468 ;; Wasn't set with custom; see if .emacs has a setq.
1469 (let ((buffer (get-buffer-create " *temp*")))
1474 (insert-file-contents user-init-file)
1477 "([ \t\n]*setq[ \t\n]+"
1478 "inhibit-startup-echo-area-message[ \t\n]+"
1481 (if (string= init-file-user "")
1487 (kill-buffer buffer)))))
1488 (display-startup-echo-area-message))
1490 ;; Delay 2 seconds after an init file error message
1491 ;; was displayed, so user can read it.
1492 (if init-file-had-error
1495 (if command-line-args-left
1496 ;; We have command args; process them.
1497 (let ((dir command-line-default-directory)
1501 just-files ;; t if this follows the magic -- option.
1502 ;; This includes our standard options' long versions
1503 ;; and long versions of what's on command-switch-alist.
1505 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1506 ("--directory") ("--eval") ("--execute")
1507 ("--find-file") ("--visit") ("--file"))
1508 (mapcar (lambda (elt)
1509 (list (concat "-" (car elt))))
1510 command-switch-alist)))
1514 ;; Add the long X options to longopts.
1515 (dolist (tem command-line-x-option-alist)
1516 (if (string-match "^--" (car tem))
1517 (push (list (car tem)) longopts)))
1519 ;; Loop, processing options.
1520 (while (and command-line-args-left)
1521 (let* ((argi (car command-line-args-left))
1524 ;; List of directories specified in -L/--directory,
1525 ;; in reverse of the order specified.
1527 (initial-load-path load-path))
1528 (setq command-line-args-left (cdr command-line-args-left))
1530 ;; Do preliminary decoding of the option.
1532 ;; After --, don't look for options; treat all args as files.
1534 ;; Convert long options to ordinary options
1535 ;; and separate out an attached option argument into argval.
1536 (if (string-match "^--[^=]*=" argi)
1537 (setq argval (substring argi (match-end 0))
1538 argi (substring argi 0 (1- (match-end 0)))))
1539 (if (equal argi "--")
1540 (setq completion nil)
1541 (setq completion (try-completion argi longopts)))
1542 (if (eq completion t)
1543 (setq argi (substring argi 1))
1544 (if (stringp completion)
1545 (let ((elt (assoc completion longopts)))
1547 (error "Option `%s' is ambiguous" argi))
1548 (setq argi (substring (car elt) 1)))
1549 (setq argval nil argi orig-argi))))
1551 ;; Execute the option.
1552 (cond ((setq tem (assoc argi command-switch-alist))
1554 (let ((command-line-args-left
1555 (cons argval command-line-args-left)))
1556 (funcall (cdr tem) argi))
1557 (funcall (cdr tem) argi)))
1559 ((member argi '("-f" ;what the manual claims
1561 "-e")) ; what the source used to say
1563 (setq tem (intern argval))
1564 (setq tem (intern (car command-line-args-left)))
1565 (setq command-line-args-left (cdr command-line-args-left)))
1566 (if (arrayp (symbol-function tem))
1567 (command-execute tem)
1570 ((member argi '("-eval" "-execute"))
1573 (setq tem (car command-line-args-left))
1574 (setq command-line-args-left (cdr command-line-args-left)))
1576 ;; Set the default directory as specified in -L.
1578 ((member argi '("-L" "-directory"))
1581 (setq tem (car command-line-args-left)
1582 command-line-args-left (cdr command-line-args-left)))
1583 (setq tem (command-line-normalize-file-name tem))
1584 (setq extra-load-path
1585 (cons (expand-file-name tem) extra-load-path))
1586 (setq load-path (append (nreverse extra-load-path)
1587 initial-load-path)))
1589 ((member argi '("-l" "-load"))
1592 (setq tem (car command-line-args-left)
1593 command-line-args-left (cdr command-line-args-left)))
1594 (let ((file (command-line-normalize-file-name tem)))
1595 ;; Take file from default dir if it exists there;
1596 ;; otherwise let `load' search for it.
1597 (if (file-exists-p (expand-file-name file))
1598 (setq file (expand-file-name file)))
1601 ((string-equal argi "-insert")
1604 (setq tem (car command-line-args-left)
1605 command-line-args-left (cdr command-line-args-left)))
1607 (error "File name omitted from `-insert' option"))
1608 (insert-file-contents (command-line-normalize-file-name tem)))
1610 ((string-equal argi "-kill")
1613 ((string-match "^\\+[0-9]+\\'" argi)
1614 (setq line (string-to-int argi)))
1616 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1617 (setq line (string-to-int (match-string 1 argi))
1618 column (string-to-int (match-string 2 argi))))
1620 ((setq tem (assoc argi command-line-x-option-alist))
1621 ;; Ignore X-windows options and their args if not using X.
1622 (setq command-line-args-left
1623 (nthcdr (nth 1 tem) command-line-args-left)))
1625 ((member argi '("-find-file" "-file" "-visit"))
1626 ;; An explicit option to specify visiting a file.
1629 (setq tem (car command-line-args-left)
1630 command-line-args-left (cdr command-line-args-left)))
1631 (unless (stringp tem)
1632 (error "File name omitted from `%s' option" argi))
1633 (setq file-count (1+ file-count))
1634 (let ((file (expand-file-name
1635 (command-line-normalize-file-name tem) dir)))
1636 (if (= file-count 1)
1637 (setq first-file-buffer (find-file file))
1638 (find-file-other-window file)))
1642 (unless (< column 1)
1643 (move-to-column (1- column)))
1647 (setq just-files t))
1649 ;; We have almost exhausted our options. See if the
1650 ;; user has made any other command-line options available
1651 (let ((hooks command-line-functions) ;; lrs 7/31/89
1654 (not (setq did-hook (funcall (car hooks)))))
1655 (setq hooks (cdr hooks)))
1657 ;; Ok, presume that the argument is a file name
1659 (if (string-match "\\`-" argi)
1660 (error "Unknown option `%s'" argi))
1661 (setq file-count (1+ file-count))
1664 (command-line-normalize-file-name orig-argi)
1666 (if (= file-count 1)
1667 (setq first-file-buffer (find-file file))
1668 (find-file-other-window file)))
1672 (unless (< column 1)
1673 (move-to-column (1- column)))
1674 (setq column 0))))))))
1675 ;; If 3 or more files visited, and not all visible,
1676 ;; show user what they all are. But leave the last one current.
1677 (and (> file-count 2)
1678 (not noninteractive)
1679 (not inhibit-startup-buffer-menu)
1680 (or (get-buffer-window first-file-buffer)
1683 ;; Maybe display a startup screen.
1684 (when (and (not inhibit-startup-message) (not noninteractive)
1685 ;; Don't display startup screen if init file
1686 ;; has started some sort of server.
1687 (not (and (fboundp 'process-list)
1689 ;; Display a startup screen, after some preparations.
1691 ;; If there are no switches to process, we might as well
1692 ;; run this hook now, and there may be some need to do it
1693 ;; before doing any output.
1694 (and term-setup-hook
1695 (run-hooks 'term-setup-hook))
1696 ;; Don't let the hook be run twice.
1697 (setq term-setup-hook nil)
1699 ;; It's important to notice the user settings before we
1700 ;; display the startup message; otherwise, the settings
1701 ;; won't take effect until the user gives the first
1702 ;; keystroke, and that's distracting.
1703 (when (fboundp 'frame-notice-user-settings)
1704 (frame-notice-user-settings))
1706 ;; If there are no switches to process, we might as well
1707 ;; run this hook now, and there may be some need to do it
1708 ;; before doing any output.
1709 (when window-setup-hook
1710 (run-hooks 'window-setup-hook)
1711 ;; Don't let the hook be run twice.
1712 (setq window-setup-hook nil))
1714 ;; Do this now to avoid an annoying delay if the user
1715 ;; clicks the menu bar during the sit-for.
1716 (when (display-popup-menus-p)
1717 (precompute-menubar-bindings))
1718 (setq menubar-bindings-done t)
1720 ;; If *scratch* is selected and it is empty, insert an
1721 ;; initial message saying not to create a file there.
1722 (when (and initial-scratch-message
1723 (string= (buffer-name) "*scratch*")
1724 (= 0 (buffer-size)))
1725 (insert initial-scratch-message)
1726 (set-buffer-modified-p nil))
1728 ;; If user typed input during all that work,
1729 ;; abort the startup screen. Otherwise, display it now.
1730 (unless (input-pending-p)
1731 (display-splash-screen))))
1734 (defun command-line-normalize-file-name (file)
1735 "Collapse multiple slashes to one, to handle non-Emacs file names."
1737 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1738 ;; That is significant on some systems.
1739 ;; However, /// at the beginning is supposed to mean just /, not //.
1740 (if (string-match "^///+" file)
1741 (setq file (replace-match "/" t t file)))
1742 (while (string-match "//+" file 1)
1743 (setq file (replace-match "/" t t file)))
1746 ;;; startup.el ends here