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