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