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