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