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