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