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