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