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