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