]> code.delx.au - gnu-emacs/blob - lisp/startup.el
(tetris): New defgroup.
[gnu-emacs] / 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 (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
518 term)
519 (setq frame-background-mode 'light)))
520 (frame-set-background-mode (selected-frame)))))
521
522 ;; Now we know the user's default font, so add it to the menu.
523 (if (fboundp 'font-menu-add-default)
524 (font-menu-add-default))
525 (and window-setup-hook
526 (run-hooks 'window-setup-hook))
527 (or menubar-bindings-done
528 (if (display-popup-menus-p)
529 (precompute-menubar-bindings)))))))
530
531 ;; Precompute the keyboard equivalents in the menu bar items.
532 (defun precompute-menubar-bindings ()
533 (let ((submap (lookup-key global-map [menu-bar])))
534 (while submap
535 (and (consp (car submap))
536 (symbolp (car (car submap)))
537 (stringp (car-safe (cdr (car submap))))
538 (keymapp (cdr (cdr (car submap))))
539 (progn
540 (x-popup-menu nil (cdr (cdr (car submap))))
541 (if purify-flag
542 (garbage-collect))))
543 (setq submap (cdr submap))))
544 (setq define-key-rebound-commands t))
545
546 ;; Command-line options supported by tty's:
547 (defconst tty-long-option-alist
548 '(("--name" . "-name")
549 ("--title" . "-T")
550 ("--reverse-video" . "-reverse")
551 ("--foreground-color" . "-fg")
552 ("--background-color" . "-bg")
553 ("--color" . "-color")))
554
555 (defconst tool-bar-images-pixel-height 24
556 "Height in pixels of images in the tool bar.")
557
558 (defvar tool-bar-originally-present nil
559 "Non-nil if tool-bars are present before user and site init files are read.")
560
561 ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc.
562 (defun tty-handle-args (args)
563 (let ((rest nil))
564 (message "%s" args)
565 (while (and args
566 (not (equal (car args) "--")))
567 (let* ((this (car args))
568 (orig-this this)
569 completion argval)
570 (setq args (cdr args))
571 ;; Check for long options with attached arguments
572 ;; and separate out the attached option argument into argval.
573 (if (string-match "^--[^=]*=" this)
574 (setq argval (substring this (match-end 0))
575 this (substring this 0 (1- (match-end 0)))))
576 (when (string-match "^--" this)
577 (setq completion (try-completion this tty-long-option-alist))
578 (if (eq completion t)
579 ;; Exact match for long option.
580 (setq this (cdr (assoc this tty-long-option-alist)))
581 (if (stringp completion)
582 (let ((elt (assoc completion tty-long-option-alist)))
583 ;; Check for abbreviated long option.
584 (or elt
585 (error "Option `%s' is ambiguous" this))
586 (setq this (cdr elt)))
587 ;; Check for a short option.
588 (setq argval nil this orig-this))))
589 (cond ((or (string= this "-fg") (string= this "-foreground"))
590 (or argval (setq argval (car args) args (cdr args)))
591 (setq default-frame-alist
592 (cons (cons 'foreground-color argval)
593 default-frame-alist)))
594 ((or (string= this "-bg") (string= this "-background"))
595 (or argval (setq argval (car args) args (cdr args)))
596 (setq default-frame-alist
597 (cons (cons 'background-color argval)
598 default-frame-alist)))
599 ((or (string= this "-T") (string= this "-name"))
600 (or argval (setq argval (car args) args (cdr args)))
601 (setq default-frame-alist
602 (cons
603 (cons 'title
604 (if (stringp argval)
605 argval
606 (let ((case-fold-search t)
607 i)
608 (setq argval (invocation-name))
609
610 ;; Change any . or * characters in name to
611 ;; hyphens, so as to emulate behavior on X.
612 (while
613 (setq i (string-match "[.*]" argval))
614 (aset argval i ?-))
615 argval)))
616 default-frame-alist)))
617 ((or (string= this "-r")
618 (string= this "-rv")
619 (string= this "-reverse"))
620 (setq default-frame-alist
621 (cons '(reverse . t)
622 default-frame-alist)))
623 ((string= this "-color")
624 (if (null argval)
625 (setq argval 8)) ; default --color means 8 ANSI colors
626 (setq default-frame-alist
627 (cons (cons 'tty-color-mode
628 (cond
629 ((numberp argval) argval)
630 ((string-match "-?[0-9]+" argval)
631 (string-to-number argval))
632 (t (intern argval))))
633 default-frame-alist)))
634 (t (setq rest (cons this rest))))))
635 (nreverse rest)))
636
637 (defun command-line ()
638 (setq command-line-default-directory default-directory)
639
640 ;; Choose a reasonable location for temporary files.
641 (setq temporary-file-directory
642 (file-name-as-directory
643 (cond ((memq system-type '(ms-dos windows-nt))
644 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
645 ((memq system-type '(vax-vms axp-vms))
646 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:"))
647 (t
648 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))))
649 (setq small-temporary-file-directory
650 (if (eq system-type 'ms-dos)
651 (getenv "TMPDIR")))
652
653 ;; See if we should import version-control from the environment variable.
654 (let ((vc (getenv "VERSION_CONTROL")))
655 (cond ((eq vc nil)) ;don't do anything if not set
656 ((or (string= vc "t")
657 (string= vc "numbered"))
658 (setq version-control t))
659 ((or (string= vc "nil")
660 (string= vc "existing"))
661 (setq version-control nil))
662 ((or (string= vc "never")
663 (string= vc "simple"))
664 (setq version-control 'never))))
665
666 ;;! This has been commented out; I currently find the behavior when
667 ;;! split-window-keep-point is nil disturbing, but if I can get used
668 ;;! to it, then it would be better to eliminate the option.
669 ;;! ;; Choose a good default value for split-window-keep-point.
670 ;;! (setq split-window-keep-point (> baud-rate 2400))
671
672 ;; Set the default strings to display in mode line for
673 ;; end-of-line formats that aren't native to this platform.
674 (cond
675 ((memq system-type '(ms-dos windows-nt emx))
676 (setq eol-mnemonic-unix "(Unix)")
677 (setq eol-mnemonic-mac "(Mac)"))
678 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
679 ;; abbreviated strings `/' and `:' set in coding.c for them.
680 ((eq system-type 'macos)
681 (setq eol-mnemonic-dos "(DOS)"))
682 (t ; this is for Unix/GNU/Linux systems
683 (setq eol-mnemonic-dos "(DOS)")
684 (setq eol-mnemonic-mac "(Mac)")))
685
686 ;; Read window system's init file if using a window system.
687 (condition-case error
688 (if (and window-system (not noninteractive))
689 (load (concat term-file-prefix
690 (symbol-name window-system)
691 "-win")
692 ;; Every window system should have a startup file;
693 ;; barf if we can't find it.
694 nil t))
695 ;; If we can't read it, print the error message and exit.
696 (error
697 (princ
698 (if (eq (car error) 'error)
699 (apply 'concat (cdr error))
700 (if (memq 'file-error (get (car error) 'error-conditions))
701 (format "%s: %s"
702 (nth 1 error)
703 (mapconcat (lambda (obj) (prin1-to-string obj t))
704 (cdr (cdr error)) ", "))
705 (format "%s: %s"
706 (get (car error) 'error-message)
707 (mapconcat (lambda (obj) (prin1-to-string obj t))
708 (cdr error) ", "))))
709 'external-debugging-output)
710 (terpri 'external-debugging-output)
711 (setq window-system nil)
712 (kill-emacs)))
713
714 ;; Windowed displays do this inside their *-win.el.
715 (when (and (not (display-graphic-p))
716 (not noninteractive))
717 (setq command-line-args (tty-handle-args command-line-args)))
718
719 (set-locale-environment nil)
720
721 ;; Convert the arguments to Emacs internal representation.
722 (let ((args (cdr command-line-args)))
723 (while args
724 (setcar args
725 (decode-coding-string (car args) locale-coding-system t))
726 (setq args (cdr args))))
727
728 (let ((done nil)
729 (args (cdr command-line-args)))
730
731 ;; Figure out which user's init file to load,
732 ;; either from the environment or from the options.
733 (setq init-file-user (if noninteractive nil (user-login-name)))
734 ;; If user has not done su, use current $HOME to find .emacs.
735 (and init-file-user (string= init-file-user (user-real-login-name))
736 (setq init-file-user ""))
737
738 ;; Process the command-line args, and delete the arguments
739 ;; processed. This is consistent with the way main in emacs.c
740 ;; does things.
741 (while (and (not done) args)
742 (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
743 ("--debug-init") ("--iconic") ("--icon-type")))
744 (argi (pop args))
745 (argval nil))
746 ;; Handle --OPTION=VALUE format.
747 (if (and (string-match "\\`--" argi)
748 (string-match "=" argi))
749 (setq argval (substring argi (match-end 0))
750 argi (substring argi 0 (match-beginning 0))))
751 (or (equal argi "--")
752 (let ((completion (try-completion argi longopts)))
753 (if (eq completion t)
754 (setq argi (substring argi 1))
755 (if (stringp completion)
756 (let ((elt (assoc completion longopts)))
757 (or elt
758 (error "Option `%s' is ambiguous" argi))
759 (setq argi (substring (car elt) 1)))
760 (setq argval nil)))))
761 (cond
762 ((member argi '("-q" "-no-init-file"))
763 (setq init-file-user nil))
764 ((member argi '("-u" "-user"))
765 (or argval
766 (setq argval (pop args)))
767 (setq init-file-user argval
768 argval nil))
769 ((string-equal argi "-no-site-file")
770 (setq site-run-file nil))
771 ((string-equal argi "-debug-init")
772 (setq init-file-debug t))
773 ((string-equal argi "-iconic")
774 (push '(visibility . icon) initial-frame-alist))
775 ((or (string-equal argi "-icon-type")
776 (string-equal argi "-i")
777 (string-equal argi "-itype"))
778 (push '(icon-type . t) default-frame-alist))
779 ;; Push the popped arg back on the list of arguments.
780 (t (push argi args) (setq done t)))
781 ;; Was argval set but not used?
782 (and argval
783 (error "Option `%s' doesn't allow an argument" argi))))
784
785 ;; Re-attach the program name to the front of the arg list.
786 (and command-line-args (setcdr command-line-args args)))
787
788 ;; Under X Windows, this creates the X frame and deletes the terminal frame.
789 (when (fboundp 'frame-initialize)
790 (frame-initialize))
791
792 ;; If frame was created with a menu bar, set menu-bar-mode on.
793 (if (and (not noninteractive)
794 (or (not (memq window-system '(x w32)))
795 (> (frame-parameter nil 'menu-bar-lines) 0)))
796 (menu-bar-mode t))
797
798 ;; If frame was created with a tool bar, switch tool-bar-mode on.
799 (when (and (not noninteractive)
800 (display-graphic-p)
801 (> (frame-parameter nil 'tool-bar-lines) 0))
802 (tool-bar-mode 1))
803
804 ;; Can't do this init in defcustom because window-system isn't set.
805 (when (and (not noninteractive)
806 (not (eq system-type 'ms-dos))
807 (memq window-system '(x w32)))
808 (setq-default blink-cursor t)
809 (blink-cursor-mode 1))
810
811 (unless noninteractive
812 ;; DOS/Windows systems have a PC-type keyboard which has both
813 ;; <delete> and <backspace> keys.
814 (when (or (memq system-type '(ms-dos windows-nt))
815 (and (memq window-system '(x))
816 (fboundp 'x-backspace-delete-keys-p)
817 (x-backspace-delete-keys-p))
818 ;; If the terminal Emacs is running on has erase char
819 ;; set to ^H, use the Backspace key for deleting
820 ;; backward and, and the Delete key for deleting forward.
821 (and (null window-system)
822 (eq tty-erase-char 8)))
823 (setq-default normal-erase-is-backspace t)
824 (normal-erase-is-backspace-mode 1)))
825
826 (when (and (not noninteractive)
827 (display-graphic-p)
828 (fboundp 'x-show-tip))
829 (setq-default tooltip-mode t)
830 (tooltip-mode 1))
831
832 ;; Register default TTY colors for the case the terminal hasn't a
833 ;; terminal init file.
834 (or (memq window-system '(x w32))
835 ;; We do this regardles of whether the terminal supports colors
836 ;; or not, since they can switch that support on or off in
837 ;; mid-session by setting the tty-color-mode frame parameter.
838 (let* ((colors (cond ((eq window-system 'pc)
839 msdos-color-values)
840 ((eq system-type 'windows-nt)
841 w32-tty-standard-colors)
842 (t tty-standard-colors)))
843 (color (car colors)))
844 (while colors
845 (tty-color-define (car color) (cadr color) (cddr color))
846 (setq colors (cdr colors) color (car colors)))
847 ;; Modifying color mappings means realized faces don't
848 ;; use the right colors, so clear them.
849 (clear-face-cache)))
850
851 ;; Record whether the tool-bar is present before the user and site
852 ;; init files are processed. frame-notice-user-settings uses this
853 ;; to determine if the tool-bar has been disabled by the init files,
854 ;; and the frame needs to be resized.
855 (when (fboundp 'frame-notice-user-settings)
856 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
857 (assq 'tool-bar-lines default-frame-alist))))
858 (setq tool-bar-originally-present
859 (not (or (null tool-bar-lines)
860 (null (cdr tool-bar-lines))
861 (eq 0 (cdr tool-bar-lines)))))))
862
863 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
864 (old-font-list-limit font-list-limit)
865 (old-face-ignored-fonts face-ignored-fonts))
866
867 (run-hooks 'before-init-hook)
868
869 ;; Run the site-start library if it exists. The point of this file is
870 ;; that it is run before .emacs. There is no point in doing this after
871 ;; .emacs; that is useless.
872 (if site-run-file
873 (load site-run-file t t))
874
875 ;; Sites should not disable this. Only individuals should disable
876 ;; the startup message.
877 (setq inhibit-startup-message nil)
878
879 ;; Load that user's init file, or the default one, or none.
880 (let (debug-on-error-from-init-file
881 debug-on-error-should-be-set
882 (debug-on-error-initial
883 (if (eq init-file-debug t) 'startup init-file-debug))
884 (orig-enable-multibyte default-enable-multibyte-characters))
885 (let ((debug-on-error debug-on-error-initial)
886 ;; This function actually reads the init files.
887 (inner
888 (function
889 (lambda ()
890 (if init-file-user
891 (let ((user-init-file-1
892 (cond
893 ((eq system-type 'ms-dos)
894 (concat "~" init-file-user "/_emacs"))
895 ((eq system-type 'windows-nt)
896 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
897 "~/.emacs"
898 "~/_emacs"))
899 ((eq system-type 'vax-vms)
900 "sys$login:.emacs")
901 (t
902 (concat "~" init-file-user "/.emacs")))))
903 ;; This tells `load' to store the file name found
904 ;; into user-init-file.
905 (setq user-init-file t)
906 (load user-init-file-1 t t)
907
908 ;; If we did not find the user's init file,
909 ;; set user-init-file conclusively to nil;
910 ;; don't let it be set from default.el.
911 (if (eq user-init-file t)
912 (setq user-init-file user-init-file-1))
913
914 ;; If we loaded a compiled file, set
915 ;; `user-init-file' to the source version if that
916 ;; exists.
917 (when (and user-init-file
918 (equal (file-name-extension user-init-file)
919 "elc"))
920 (let* ((source (file-name-sans-extension user-init-file))
921 (alt (concat source ".el")))
922 (setq source (cond ((file-exists-p alt) alt)
923 ((file-exists-p source) source)
924 (t nil)))
925 (when source
926 (when (file-newer-than-file-p source user-init-file)
927 (message "Warning: %s is newer than %s"
928 source user-init-file)
929 (sit-for 1))
930 (setq user-init-file source))))
931
932 (or inhibit-default-init
933 (let ((inhibit-startup-message nil))
934 ;; Users are supposed to be told their rights.
935 ;; (Plus how to get help and how to undo.)
936 ;; Don't you dare turn this off for anyone
937 ;; except yourself.
938 (load "default" t t)))))))))
939 (if init-file-debug
940 ;; Do this without a condition-case if the user wants to debug.
941 (funcall inner)
942 (condition-case error
943 (progn
944 (funcall inner)
945 (setq init-file-had-error nil))
946 (error
947 (let ((message-log-max nil))
948 (save-excursion
949 (set-buffer (get-buffer-create "*Messages*"))
950 (insert "\n\n"
951 (format "An error has occurred while loading `%s':\n\n"
952 user-init-file)
953 (format "%s%s%s"
954 (get (car error) 'error-message)
955 (if (cdr error) ": " "")
956 (mapconcat 'prin1-to-string (cdr error) ", "))
957 "\n\n"
958 "To ensure normal operation, you should investigate the cause\n"
959 "of the error in your initialization file and remove it. Start\n"
960 "Emacs with the `--debug-init' option to view a complete error\n"
961 "backtrace\n"))
962 (message "Error in init file: %s%s%s"
963 (get (car error) 'error-message)
964 (if (cdr error) ": " "")
965 (mapconcat 'prin1-to-string (cdr error) ", "))
966 (pop-to-buffer "*Messages*")
967 (setq init-file-had-error t)))))
968
969 ;; If the user has a file of abbrevs, read it.
970 (if (file-exists-p abbrev-file-name)
971 (quietly-read-abbrev-file abbrev-file-name))
972
973 ;; If the abbrevs came entirely from the init file or the
974 ;; abbrevs file, they do not need saving.
975 (setq abbrevs-changed nil)
976
977 ;; If we can tell that the init file altered debug-on-error,
978 ;; arrange to preserve the value that it set up.
979 (or (eq debug-on-error debug-on-error-initial)
980 (setq debug-on-error-should-be-set t
981 debug-on-error-from-init-file debug-on-error)))
982 (if debug-on-error-should-be-set
983 (setq debug-on-error debug-on-error-from-init-file))
984 (unless (or default-enable-multibyte-characters
985 (eq orig-enable-multibyte default-enable-multibyte-characters))
986 ;; Init file changed to unibyte. Reset existing multibyte
987 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
988 ;; Arguably this should only be done if they're free of
989 ;; multibyte characters.
990 (mapcar (lambda (buffer)
991 (with-current-buffer buffer
992 (if enable-multibyte-characters
993 (set-buffer-multibyte nil))))
994 (buffer-list))
995 ;; Also re-set the language environment in case it was
996 ;; originally done before unibyte was set and is sensitive to
997 ;; unibyte (display table, terminal coding system &c).
998 (set-language-environment current-language-environment)))
999
1000 ;; Do this here in case the init file sets mail-host-address.
1001 (or user-mail-address
1002 (setq user-mail-address (concat (user-login-name) "@"
1003 (or mail-host-address
1004 (system-name)))))
1005
1006 ;; If parameter have been changed in the init file which influence
1007 ;; face realization, clear the face cache so that new faces will
1008 ;; be realized.
1009 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1010 (eq font-list-limit old-font-list-limit)
1011 (eq face-ignored-fonts old-face-ignored-fonts))
1012 (clear-face-cache)))
1013
1014 (run-hooks 'after-init-hook)
1015
1016 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1017 (if (get-buffer "*scratch*")
1018 (save-excursion
1019 (set-buffer "*scratch*")
1020 (if (eq major-mode 'fundamental-mode)
1021 (funcall initial-major-mode))))
1022
1023 ;; Load library for our terminal type.
1024 ;; User init file can set term-file-prefix to nil to prevent this.
1025 (and term-file-prefix (not noninteractive) (not window-system)
1026 (let ((term (getenv "TERM"))
1027 hyphend)
1028 (while (and term
1029 (not (load (concat term-file-prefix term) t t)))
1030 ;; Strip off last hyphen and what follows, then try again
1031 (if (setq hyphend (string-match "[-_][^-_]+$" term))
1032 (setq term (substring term 0 hyphend))
1033 (setq term nil)))))
1034
1035 ;; Process the remaining args.
1036 (command-line-1 (cdr command-line-args))
1037
1038 ;; If -batch, terminate after processing the command options.
1039 (if noninteractive (kill-emacs t)))
1040
1041 (defcustom initial-scratch-message (purecopy "\
1042 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1043 ;; If you want to create a file, visit that file with C-x C-f,
1044 ;; then enter the text in that file's own buffer.
1045
1046 ")
1047 "Initial message displayed in *scratch* buffer at startup.
1048 If this is nil, no message will be displayed."
1049 :type '(choice (text :tag "Message")
1050 (const :tag "none" nil))
1051 :group 'initialization)
1052
1053 \f
1054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1055 ;;; Fancy splash screen
1056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1057
1058 (defvar fancy-splash-text
1059 '((:face variable-pitch
1060 "You can do basic editing with the menu bar and scroll bar \
1061 using the mouse.\n\n"
1062 :face (variable-pitch :weight bold)
1063 "Important Help menu items:\n"
1064 :face variable-pitch "\
1065 Emacs Tutorial\tLearn-by-doing tutorial for using Emacs efficiently
1066 Emacs FAQ\tFrequently asked questions and answers
1067 \(Non)Warranty\tGNU Emacs comes with "
1068 :face (variable-pitch :slant oblique)
1069 "ABSOLUTELY NO WARRANTY\n"
1070 :face variable-pitch
1071 "\
1072 Copying Conditions\tConditions for redistributing and changing Emacs
1073 Ordering Manuals\tHow to order Emacs manuals from the Free Software Foundation\n")
1074 (:face variable-pitch
1075 "You can do basic editing with the menu bar and scroll bar \
1076 using the mouse.\n\n"
1077 :face (variable-pitch :weight bold)
1078 "Useful File menu items:\n"
1079 :face variable-pitch "\
1080 Exit Emacs\t(Or type Control-x followed by Control-c)
1081 Recover Session\tRecover files you were editing before a crash
1082
1083
1084
1085 "
1086 ))
1087 "A list of texts to show in the middle part of splash screens.
1088 Each element in the list should be a list of strings or pairs
1089 `:face FACE', like `fancy-splash-insert' accepts them.")
1090
1091
1092 (defgroup fancy-splash-screen ()
1093 "Fancy splash screen when Emacs starts."
1094 :version "21.1"
1095 :group 'initialization)
1096
1097
1098 (defcustom fancy-splash-delay 10
1099 "*Delay in seconds between splash screens."
1100 :group 'fancy-splash-screen
1101 :type 'integer)
1102
1103
1104 (defcustom fancy-splash-max-time 60
1105 "*Show splash screens for at most this number of seconds.
1106 Values less than 60 seconds are ignored."
1107 :group 'fancy-splash-screen
1108 :type 'integer)
1109
1110
1111 (defcustom fancy-splash-image nil
1112 "*The image to show in the splash screens, or nil for defaults."
1113 :group 'fancy-splash-screen
1114 :type '(choice (const :tag "Default" nil)
1115 (file :tag "File")))
1116
1117
1118 ;; These are temporary storage areas for the splash screen display.
1119
1120 (defvar fancy-current-text nil)
1121 (defvar fancy-splash-help-echo nil)
1122 (defvar fancy-splash-stop-time nil)
1123 (defvar fancy-splash-outer-buffer nil)
1124
1125 (defun fancy-splash-insert (&rest args)
1126 "Insert text into the current buffer, with faces.
1127 Arguments from ARGS should be either strings or pairs `:face FACE',
1128 where FACE is a valid face specification, as it can be used with
1129 `put-text-properties'."
1130 (let ((current-face nil))
1131 (while args
1132 (if (eq (car args) :face)
1133 (setq args (cdr args) current-face (car args))
1134 (insert (propertize (car args)
1135 'face current-face
1136 'help-echo fancy-splash-help-echo)))
1137 (setq args (cdr args)))))
1138
1139
1140 (defun fancy-splash-head ()
1141 "Insert the head part of the splash screen into the current buffer."
1142 (let* ((image-file (cond ((stringp fancy-splash-image)
1143 fancy-splash-image)
1144 ((and (display-color-p)
1145 (image-type-available-p 'xpm))
1146 (if (and (fboundp 'x-display-planes)
1147 (= (funcall 'x-display-planes) 8))
1148 "splash8.xpm"
1149 "splash.xpm"))
1150 (t "splash.pbm")))
1151 (img (create-image image-file))
1152 (image-width (and img (car (image-size img))))
1153 (window-width (window-width (selected-window))))
1154 (when img
1155 (when (> window-width image-width)
1156 ;; Center the image in the window.
1157 (let ((pos (/ (- window-width image-width) 2)))
1158 (insert (propertize " " 'display `(space :align-to ,pos))))
1159
1160 ;; Change the color of the XPM version of the splash image
1161 ;; so that it is visible with a dark frame background.
1162 (when (and (memq 'xpm img)
1163 (eq (frame-parameter nil 'background-mode) 'dark))
1164 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1165
1166 ;; Insert the image with a help-echo and a keymap.
1167 (let ((map (make-sparse-keymap))
1168 (help-echo "mouse-2: browse http://www.gnu.org/"))
1169 (define-key map [mouse-2]
1170 (lambda ()
1171 (interactive)
1172 (browse-url "http://www.gnu.org/")
1173 (throw 'exit nil)))
1174 (define-key map [down-mouse-2] 'ignore)
1175 (define-key map [up-mouse-2] 'ignore)
1176 (insert-image img (propertize "xxx" 'help-echo help-echo
1177 'keymap map)))
1178 (insert "\n"))))
1179 (if (eq system-type 'gnu/linux)
1180 (fancy-splash-insert
1181 :face '(variable-pitch :foreground "red")
1182 "GNU Emacs is one component of a Linux-based GNU system.")
1183 (fancy-splash-insert
1184 :face '(variable-pitch :foreground "red")
1185 "GNU Emacs is one component of the GNU operating system."))
1186 (insert "\n")
1187 (unless (equal (buffer-name fancy-splash-outer-buffer) "*scratch*")
1188 (fancy-splash-insert :face 'variable-pitch
1189 (substitute-command-keys
1190 "Type \\[recenter] to begin editing your file.\n"))))
1191
1192
1193 (defun fancy-splash-tail ()
1194 "Insert the tail part of the splash screen into the current buffer."
1195 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1196 "cyan" "darkblue")))
1197 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1198 "\nThis is "
1199 (emacs-version)
1200 "\n"
1201 :face '(variable-pitch :height 0.5)
1202 "Copyright (C) 2001 Free Software Foundation, Inc.")
1203 (and auto-save-list-file-prefix
1204 ;; Don't signal an error if the
1205 ;; directory for auto-save-list files
1206 ;; does not yet exist.
1207 (file-directory-p (file-name-directory
1208 auto-save-list-file-prefix))
1209 (directory-files
1210 (file-name-directory auto-save-list-file-prefix)
1211 nil
1212 (concat "\\`"
1213 (regexp-quote (file-name-nondirectory
1214 auto-save-list-file-prefix)))
1215 t)
1216 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1217 "\n\nIf an Emacs session crashed recently, "
1218 "type M-x recover-session RET\nto recover"
1219 " the files you were editing."))))
1220
1221 (defun fancy-splash-screens-1 (buffer)
1222 "Timer function displaying a splash screen."
1223 (when (> (float-time) fancy-splash-stop-time)
1224 (throw 'stop-splashing nil))
1225 (unless fancy-current-text
1226 (setq fancy-current-text fancy-splash-text))
1227 (let ((text (car fancy-current-text)))
1228 (set-buffer buffer)
1229 (erase-buffer)
1230 (fancy-splash-head)
1231 (apply #'fancy-splash-insert text)
1232 (fancy-splash-tail)
1233 (unless (current-message)
1234 (message fancy-splash-help-echo))
1235 (set-buffer-modified-p nil)
1236 (goto-char (point-min))
1237 (force-mode-line-update)
1238 (setq fancy-current-text (cdr fancy-current-text))))
1239
1240
1241 (defun fancy-splash-default-action ()
1242 "Default action for events in the splash screen buffer."
1243 (interactive)
1244 (push last-command-event unread-command-events)
1245 (throw 'exit nil))
1246
1247
1248 (defun fancy-splash-screens ()
1249 "Display fancy splash screens when Emacs starts."
1250 (setq fancy-splash-help-echo (startup-echo-area-message))
1251 (let ((old-hourglass display-hourglass)
1252 (fancy-splash-outer-buffer (current-buffer))
1253 splash-buffer
1254 (old-minor-mode-map-alist minor-mode-map-alist)
1255 timer)
1256 (switch-to-buffer "GNU Emacs")
1257 (setq tab-width 20)
1258 (setq splash-buffer (current-buffer))
1259 (catch 'stop-splashing
1260 (unwind-protect
1261 (let ((map (make-sparse-keymap)))
1262 (use-local-map map)
1263 (define-key map [t] 'fancy-splash-default-action)
1264 (define-key map [mouse-movement] 'ignore)
1265 (define-key map [mode-line t] 'ignore)
1266 (setq cursor-type nil
1267 display-hourglass nil
1268 minor-mode-map-alist nil
1269 buffer-undo-list t
1270 mode-line-format (propertize "---- %b %-"
1271 'face '(:weight bold))
1272 fancy-splash-stop-time (+ (float-time)
1273 (max 60 fancy-splash-max-time))
1274 timer (run-with-timer 0 fancy-splash-delay
1275 #'fancy-splash-screens-1
1276 splash-buffer))
1277 (recursive-edit))
1278 (cancel-timer timer)
1279 (setq display-hourglass old-hourglass
1280 minor-mode-map-alist old-minor-mode-map-alist)
1281 (kill-buffer splash-buffer)))))
1282
1283
1284 (defun use-fancy-splash-screens-p ()
1285 "Return t if fancy splash screens should be used."
1286 (when (or (and (display-color-p)
1287 (image-type-available-p 'xpm))
1288 (image-type-available-p 'pbm))
1289 (let* ((img (create-image (or fancy-splash-image
1290 (if (and (display-color-p)
1291 (image-type-available-p 'xpm))
1292 "splash.xpm" "splash.pbm"))))
1293 (image-height (and img (cdr (image-size img))))
1294 (window-height (1- (window-height (selected-window)))))
1295 (> window-height (+ image-height 15)))))
1296
1297
1298 (defun startup-echo-area-message ()
1299 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1300 "For information about the GNU Project and its goals, type C-h C-p."
1301 (substitute-command-keys
1302 "For information about the GNU Project and its goals, type \
1303 \\[describe-project].")))
1304
1305
1306 (defun display-startup-echo-area-message ()
1307 (let ((resize-mini-windows t))
1308 (message (startup-echo-area-message))))
1309
1310
1311 (defun command-line-1 (command-line-args-left)
1312 (or noninteractive (input-pending-p) init-file-had-error
1313 ;; t if the init file says to inhibit the echo area startup message.
1314 (and inhibit-startup-echo-area-message
1315 user-init-file
1316 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1317 (equal inhibit-startup-echo-area-message
1318 (if (string= init-file-user "")
1319 (user-login-name)
1320 init-file-user)))
1321 ;; Wasn't set with custom; see if .emacs has a setq.
1322 (let ((buffer (get-buffer-create " *temp*")))
1323 (prog1
1324 (condition-case nil
1325 (save-excursion
1326 (set-buffer buffer)
1327 (insert-file-contents user-init-file)
1328 (re-search-forward
1329 (concat
1330 "([ \t\n]*setq[ \t\n]+"
1331 "inhibit-startup-echo-area-message[ \t\n]+"
1332 (regexp-quote
1333 (prin1-to-string
1334 (if (string= init-file-user "")
1335 (user-login-name)
1336 init-file-user)))
1337 "[ \t\n]*)")
1338 nil t))
1339 (error nil))
1340 (kill-buffer buffer)))))
1341 (display-startup-echo-area-message))
1342
1343 ;; Delay 2 seconds after an init file error message
1344 ;; was displayed, so user can read it.
1345 (if init-file-had-error
1346 (sit-for 2))
1347
1348 (if command-line-args-left
1349 ;; We have command args; process them.
1350 (let ((dir command-line-default-directory)
1351 (file-count 0)
1352 first-file-buffer
1353 tem
1354 just-files ;; t if this follows the magic -- option.
1355 ;; This includes our standard options' long versions
1356 ;; and long versions of what's on command-switch-alist.
1357 (longopts
1358 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1359 ("--directory") ("--eval") ("--execute")
1360 ("--find-file") ("--visit") ("--file"))
1361 (mapcar (lambda (elt)
1362 (list (concat "-" (car elt))))
1363 command-switch-alist)))
1364 (line 0)
1365 (column 0))
1366
1367 ;; Add the long X options to longopts.
1368 (dolist (tem command-line-x-option-alist)
1369 (if (string-match "^--" (car tem))
1370 (push (list (car tem)) longopts)))
1371
1372 ;; Loop, processing options.
1373 (while (and command-line-args-left)
1374 (let* ((argi (car command-line-args-left))
1375 (orig-argi argi)
1376 argval completion
1377 ;; List of directories specified in -L/--directory,
1378 ;; in reverse of the order specified.
1379 extra-load-path
1380 (initial-load-path load-path))
1381 (setq command-line-args-left (cdr command-line-args-left))
1382
1383 ;; Do preliminary decoding of the option.
1384 (if just-files
1385 ;; After --, don't look for options; treat all args as files.
1386 (setq argi "")
1387 ;; Convert long options to ordinary options
1388 ;; and separate out an attached option argument into argval.
1389 (if (string-match "^--[^=]*=" argi)
1390 (setq argval (substring argi (match-end 0))
1391 argi (substring argi 0 (1- (match-end 0)))))
1392 (if (equal argi "--")
1393 (setq completion nil)
1394 (setq completion (try-completion argi longopts)))
1395 (if (eq completion t)
1396 (setq argi (substring argi 1))
1397 (if (stringp completion)
1398 (let ((elt (assoc completion longopts)))
1399 (or elt
1400 (error "Option `%s' is ambiguous" argi))
1401 (setq argi (substring (car elt) 1)))
1402 (setq argval nil argi orig-argi))))
1403
1404 ;; Execute the option.
1405 (cond ((setq tem (assoc argi command-switch-alist))
1406 (if argval
1407 (let ((command-line-args-left
1408 (cons argval command-line-args-left)))
1409 (funcall (cdr tem) argi))
1410 (funcall (cdr tem) argi)))
1411
1412 ((member argi '("-f" ;what the manual claims
1413 "-funcall"
1414 "-e")) ; what the source used to say
1415 (if argval
1416 (setq tem (intern argval))
1417 (setq tem (intern (car command-line-args-left)))
1418 (setq command-line-args-left (cdr command-line-args-left)))
1419 (if (arrayp (symbol-function tem))
1420 (command-execute tem)
1421 (funcall tem)))
1422
1423 ((member argi '("-eval" "-execute"))
1424 (if argval
1425 (setq tem argval)
1426 (setq tem (car command-line-args-left))
1427 (setq command-line-args-left (cdr command-line-args-left)))
1428 (eval (read tem)))
1429 ;; Set the default directory as specified in -L.
1430
1431 ((member argi '("-L" "-directory"))
1432 (if argval
1433 (setq tem argval)
1434 (setq tem (car command-line-args-left)
1435 command-line-args-left (cdr command-line-args-left)))
1436 (setq tem (command-line-normalize-file-name tem))
1437 (setq extra-load-path
1438 (cons (expand-file-name tem) extra-load-path))
1439 (setq load-path (append (nreverse extra-load-path)
1440 initial-load-path)))
1441
1442 ((member argi '("-l" "-load"))
1443 (if argval
1444 (setq tem argval)
1445 (setq tem (car command-line-args-left)
1446 command-line-args-left (cdr command-line-args-left)))
1447 (let ((file (command-line-normalize-file-name tem)))
1448 ;; Take file from default dir if it exists there;
1449 ;; otherwise let `load' search for it.
1450 (if (file-exists-p (expand-file-name file))
1451 (setq file (expand-file-name file)))
1452 (load file nil t)))
1453
1454 ((string-equal argi "-insert")
1455 (if argval
1456 (setq tem argval)
1457 (setq tem (car command-line-args-left)
1458 command-line-args-left (cdr command-line-args-left)))
1459 (or (stringp tem)
1460 (error "File name omitted from `-insert' option"))
1461 (insert-file-contents (command-line-normalize-file-name tem)))
1462
1463 ((string-equal argi "-kill")
1464 (kill-emacs t))
1465
1466 ((string-match "^\\+[0-9]+\\'" argi)
1467 (setq line (string-to-int argi)))
1468
1469 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1470 (setq line (string-to-int (match-string 1 argi))
1471 column (string-to-int (match-string 2 argi))))
1472
1473 ((setq tem (assoc argi command-line-x-option-alist))
1474 ;; Ignore X-windows options and their args if not using X.
1475 (setq command-line-args-left
1476 (nthcdr (nth 1 tem) command-line-args-left)))
1477
1478 ((member argi '("-find-file" "-file" "-visit"))
1479 ;; An explicit option to specify visiting a file.
1480 (if argval
1481 (setq tem argval)
1482 (setq tem (car command-line-args-left)
1483 command-line-args-left (cdr command-line-args-left)))
1484 (unless (stringp tem)
1485 (error "File name omitted from `%s' option" argi))
1486 (setq file-count (1+ file-count))
1487 (let ((file (expand-file-name
1488 (command-line-normalize-file-name tem) dir)))
1489 (if (= file-count 1)
1490 (setq first-file-buffer (find-file file))
1491 (find-file-other-window file)))
1492 (or (zerop line)
1493 (goto-line line))
1494 (setq line 0)
1495 (unless (< column 1)
1496 (move-to-column (1- column)))
1497 (setq column 0))
1498
1499 ((equal argi "--")
1500 (setq just-files t))
1501 (t
1502 ;; We have almost exhausted our options. See if the
1503 ;; user has made any other command-line options available
1504 (let ((hooks command-line-functions) ;; lrs 7/31/89
1505 (did-hook nil))
1506 (while (and hooks
1507 (not (setq did-hook (funcall (car hooks)))))
1508 (setq hooks (cdr hooks)))
1509 (if (not did-hook)
1510 ;; Ok, presume that the argument is a file name
1511 (progn
1512 (if (string-match "\\`-" argi)
1513 (error "Unknown option `%s'" argi))
1514 (setq file-count (1+ file-count))
1515 (let ((file
1516 (expand-file-name
1517 (command-line-normalize-file-name orig-argi)
1518 dir)))
1519 (if (= file-count 1)
1520 (setq first-file-buffer (find-file file))
1521 (find-file-other-window file)))
1522 (or (zerop line)
1523 (goto-line line))
1524 (setq line 0)
1525 (unless (< column 1)
1526 (move-to-column (1- column)))
1527 (setq column 0))))))))
1528 ;; If 3 or more files visited, and not all visible,
1529 ;; show user what they all are. But leave the last one current.
1530 (and (> file-count 2)
1531 (not noninteractive)
1532 (not inhibit-startup-buffer-menu)
1533 (or (get-buffer-window first-file-buffer)
1534 (list-buffers)))))
1535
1536 ;; Maybe display a startup screen.
1537 (when (and (not inhibit-startup-message) (not noninteractive)
1538 ;; Don't display startup screen if init file
1539 ;; has started some sort of server.
1540 (not (and (fboundp 'process-list)
1541 (process-list))))
1542 ;; Display a startup screen, after some preparations.
1543
1544 ;; If there are no switches to process, we might as well
1545 ;; run this hook now, and there may be some need to do it
1546 ;; before doing any output.
1547 (and term-setup-hook
1548 (run-hooks 'term-setup-hook))
1549 ;; Don't let the hook be run twice.
1550 (setq term-setup-hook nil)
1551
1552 ;; It's important to notice the user settings before we
1553 ;; display the startup message; otherwise, the settings
1554 ;; won't take effect until the user gives the first
1555 ;; keystroke, and that's distracting.
1556 (when (fboundp 'frame-notice-user-settings)
1557 (frame-notice-user-settings))
1558
1559 ;; If there are no switches to process, we might as well
1560 ;; run this hook now, and there may be some need to do it
1561 ;; before doing any output.
1562 (when window-setup-hook
1563 (run-hooks 'window-setup-hook)
1564 ;; Don't let the hook be run twice.
1565 (setq window-setup-hook nil))
1566
1567 ;; Do this now to avoid an annoying delay if the user
1568 ;; clicks the menu bar during the sit-for.
1569 (when (display-popup-menus-p)
1570 (precompute-menubar-bindings))
1571 (setq menubar-bindings-done t)
1572
1573 ;; If *scratch* is selected and it is empty, insert an
1574 ;; initial message saying not to create a file there.
1575 (when (and initial-scratch-message
1576 (string= (buffer-name) "*scratch*")
1577 (= 0 (buffer-size)))
1578 (insert initial-scratch-message)
1579 (set-buffer-modified-p nil))
1580
1581 ;; If user typed input during all that work,
1582 ;; abort the startup screen. Otherwise, display it now.
1583 (let ((buffer (current-buffer)))
1584 (when (not (input-pending-p))
1585 (if (and (display-graphic-p)
1586 (use-fancy-splash-screens-p))
1587 (fancy-splash-screens)
1588 (with-current-buffer (get-buffer-create "GNU Emacs")
1589 (let ((tab-width 8)
1590 (mode-line-format (propertize "---- %b %-"
1591 'face '(:weight bold))))
1592
1593 ;; The convention for this piece of code is that
1594 ;; each piece of output starts with one or two newlines
1595 ;; and does not end with any newlines.
1596 (insert "Welcome to GNU Emacs")
1597 (if (eq system-type 'gnu/linux)
1598 (insert ", one component of a Linux-based GNU system."))
1599 (insert "\n")
1600
1601 (unless (equal (buffer-name buffer) "*scratch*")
1602 (insert (substitute-command-keys
1603 "\nType \\[recenter] to begin editing your file.\n")))
1604
1605 (if (display-mouse-p)
1606 ;; The user can use the mouse to activate menus
1607 ;; so give help in terms of menu items.
1608 (progn
1609 (insert "\
1610 You can do basic editing with the menu bar and scroll bar using the mouse.
1611
1612 Useful File menu items:
1613 Exit Emacs (or type Control-x followed by Control-c)
1614 Recover Session recover files you were editing before a crash
1615
1616 Important Help menu items:
1617 Emacs Tutorial Learn-by-doing tutorial for using Emacs efficiently.
1618 Emacs FAQ Frequently asked questions and answers
1619 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1620 Copying Conditions Conditions for redistributing and changing Emacs.
1621 Getting New Versions How to obtain the latest version of Emacs.
1622 Ordering Manuals How to order manuals from the FSF.
1623 ")
1624 (insert "\n\n" (emacs-version)
1625 "
1626 Copyright (C) 2001 Free Software Foundation, Inc."))
1627
1628 ;; No mouse menus, so give help using kbd commands.
1629
1630 ;; If keys have their default meanings,
1631 ;; use precomputed string to save lots of time.
1632 (if (and (eq (key-binding "\C-h") 'help-command)
1633 (eq (key-binding "\C-xu") 'advertised-undo)
1634 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1635 (eq (key-binding "\C-ht") 'help-with-tutorial)
1636 (eq (key-binding "\C-hi") 'info)
1637 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1638 (insert "
1639 Get help C-h (Hold down CTRL and press h)
1640 Undo changes C-x u Exit Emacs C-x C-c
1641 Get a tutorial C-h t Use Info to read docs C-h i
1642 Ordering manuals C-h RET")
1643 (insert (substitute-command-keys
1644 (format "\n
1645 Get help %s
1646 Undo changes \\[advertised-undo]
1647 Exit Emacs \\[save-buffers-kill-emacs]
1648 Get a tutorial \\[help-with-tutorial]
1649 Use Info to read docs \\[info]
1650 Ordering manuals \\[view-order-manuals]"
1651 (let ((where (where-is-internal
1652 'help-command nil t)))
1653 (if where
1654 (key-description where)
1655 "M-x help"))))))
1656
1657 ;; Say how to use the menu bar with the keyboard.
1658 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1659 (eq (key-binding [f10]) 'tmm-menubar))
1660 (insert "
1661 Activate menubar F10 or ESC ` or M-`")
1662 (insert (substitute-command-keys "
1663 Activate menubar \\[tmm-menubar]")))
1664
1665 ;; Many users seem to have problems with these.
1666 (insert "
1667 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1668 If you have no Meta key, you may instead type ESC followed by the character.)")
1669
1670 (insert "\n\n" (emacs-version)
1671 "
1672 Copyright (C) 2001 Free Software Foundation, Inc.")
1673
1674 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1675 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1676 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1677 (insert
1678 "\n
1679 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1680 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1681 of Emacs and modify it; type C-h C-c to see the conditions.
1682 Type C-h C-d for information on getting the latest version.")
1683 (insert (substitute-command-keys
1684 "\n
1685 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1686 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1687 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1688 Type \\[describe-distribution] for information on getting the latest version."))))
1689
1690 ;; The rest of the startup screen is the same on all
1691 ;; kinds of terminals.
1692
1693 ;; Give information on recovering, if there was a crash.
1694 (and auto-save-list-file-prefix
1695 ;; Don't signal an error if the
1696 ;; directory for auto-save-list files
1697 ;; does not yet exist.
1698 (file-directory-p (file-name-directory
1699 auto-save-list-file-prefix))
1700 (directory-files
1701 (file-name-directory auto-save-list-file-prefix)
1702 nil
1703 (concat "\\`"
1704 (regexp-quote (file-name-nondirectory
1705 auto-save-list-file-prefix)))
1706 t)
1707 (insert "\n\nIf an Emacs session crashed recently, "
1708 "type M-x recover-session RET\nto recover"
1709 " the files you were editing."))
1710
1711 ;; Display the input that we set up in the buffer.
1712 (set-buffer-modified-p nil)
1713 (goto-char (point-min))
1714 (save-window-excursion
1715 (switch-to-buffer (current-buffer))
1716 (sit-for 120))))
1717 (kill-buffer "GNU Emacs"))))))
1718
1719
1720 (defun command-line-normalize-file-name (file)
1721 "Collapse multiple slashes to one, to handle non-Emacs file names."
1722 (save-match-data
1723 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1724 ;; That is significant on some systems.
1725 ;; However, /// at the beginning is supposed to mean just /, not //.
1726 (if (string-match "^///+" file)
1727 (setq file (replace-match "/" t t file)))
1728 (while (string-match "//+" file 1)
1729 (setq file (replace-match "/" t t file)))
1730 file))
1731
1732 ;;; startup.el ends here