Revert 2008-02-28 change that adds initial message
[emacs.git] / lisp / startup.el
blob4f66a1cf5013bf6ff2aff686b1e0b86e732a2371
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, 2008 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
1215 (list :foreground
1216 (if (eq (frame-parameter nil 'background-mode) 'dark)
1217 "cyan" "darkblue"))))
1218 "\n"
1219 (lambda () (emacs-version))
1220 "\n"
1221 :face (variable-pitch (:height 0.5))
1222 (lambda () emacs-copyright)
1223 "\n\n"
1224 :face variable-pitch
1225 :link ("GNU and Freedom" (lambda (button) (describe-project)))
1226 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1227 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1228 "\tGNU Emacs comes with "
1229 :face (variable-pitch (:slant oblique))
1230 "ABSOLUTELY NO WARRANTY\n"
1231 :face variable-pitch
1232 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1233 "\tConditions for redistributing and changing Emacs\n"
1234 :link ("Getting New Versions" (lambda (button) (describe-distribution)))
1235 "\tHow to obtain the latest version of Emacs\n"
1236 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1237 "\tBuying printed manuals from the FSF\n"
1238 "\n"
1239 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1240 "\tLearn basic Emacs keystroke commands"
1241 (lambda ()
1242 (let* ((en "TUTORIAL")
1243 (tut (or (get-language-info current-language-environment
1244 'tutorial)
1245 en))
1246 (title (with-temp-buffer
1247 (insert-file-contents
1248 (expand-file-name tut data-directory)
1249 nil 0 256)
1250 (search-forward ".")
1251 (buffer-substring (point-min) (1- (point))))))
1252 ;; If there is a specific tutorial for the current language
1253 ;; environment and it is not English, append its title.
1254 (if (string= en tut)
1256 (concat " (" title ")"))))
1257 "\n"
1258 :link ("Emacs Guided Tour"
1259 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1260 "Browse http://www.gnu.org/software/emacs/tour/")
1261 "\tSee an overview of the many facilities of GNU Emacs"
1263 "A list of texts to show in the middle part of the About screen.
1264 Each element in the list should be a list of strings or pairs
1265 `:face FACE', like `fancy-splash-insert' accepts them.")
1268 (defgroup fancy-splash-screen ()
1269 "Fancy splash screen when Emacs starts."
1270 :version "21.1"
1271 :group 'initialization)
1273 (defcustom fancy-splash-image nil
1274 "*The image to show in the splash screens, or nil for defaults."
1275 :group 'fancy-splash-screen
1276 :type '(choice (const :tag "Default" nil)
1277 (file :tag "File")))
1280 (defvar splash-screen-keymap
1281 (let ((map (make-sparse-keymap)))
1282 (suppress-keymap map)
1283 (set-keymap-parent map button-buffer-map)
1284 (define-key map "\C-?" 'scroll-down)
1285 (define-key map " " 'scroll-up)
1286 (define-key map "q" 'exit-splash-screen)
1287 map)
1288 "Keymap for splash screen buffer.")
1290 ;; These are temporary storage areas for the splash screen display.
1292 (defun fancy-splash-insert (&rest args)
1293 "Insert text into the current buffer, with faces.
1294 Arguments from ARGS should be either strings; functions called
1295 with no args that return a string; pairs `:face FACE', where FACE
1296 is a face specification usable with `put-text-property'; or pairs
1297 `:link LINK' where LINK is a list of arguments to pass to
1298 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1299 specifies the button's label, `action' property and help-echo string.
1300 FACE and LINK can also be functions, which are evaluated to obtain
1301 a face or button specification."
1302 (let ((current-face nil))
1303 (while args
1304 (cond ((eq (car args) :face)
1305 (setq args (cdr args) current-face (car args))
1306 (if (functionp current-face)
1307 (setq current-face (funcall current-face))))
1308 ((eq (car args) :link)
1309 (setq args (cdr args))
1310 (let ((spec (car args)))
1311 (if (functionp spec)
1312 (setq spec (funcall spec)))
1313 (insert-button (car spec)
1314 'face (list 'link current-face)
1315 'action (cadr spec)
1316 'help-echo (concat "mouse-2, RET: "
1317 (or (nth 2 spec)
1318 "Follow this link"))
1319 'follow-link t)))
1320 (t (insert (propertize (let ((it (car args)))
1321 (if (functionp it)
1322 (funcall it)
1323 it))
1324 'face current-face
1325 'help-echo (startup-echo-area-message)))))
1326 (setq args (cdr args)))))
1329 (defun fancy-splash-head ()
1330 "Insert the head part of the splash screen into the current buffer."
1331 (let* ((image-file (cond ((stringp fancy-splash-image)
1332 fancy-splash-image)
1333 ((and (display-color-p)
1334 (image-type-available-p 'xpm))
1335 (if (and (fboundp 'x-display-planes)
1336 (= (funcall 'x-display-planes) 8))
1337 "splash8.xpm"
1338 "splash.xpm"))
1339 (t "splash.pbm")))
1340 (img (create-image image-file))
1341 (image-width (and img (car (image-size img))))
1342 (window-width (window-width (selected-window))))
1343 (when img
1344 (when (> window-width image-width)
1345 ;; Center the image in the window.
1346 (insert (propertize " " 'display
1347 `(space :align-to (+ center (-0.5 . ,img)))))
1349 ;; Change the color of the XPM version of the splash image
1350 ;; so that it is visible with a dark frame background.
1351 (when (and (memq 'xpm img)
1352 (eq (frame-parameter nil 'background-mode) 'dark))
1353 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1355 ;; Insert the image with a help-echo and a link.
1356 (make-button (prog1 (point) (insert-image img)) (point)
1357 'face 'default
1358 'help-echo "mouse-2, RET: Browse http://www.gnu.org/"
1359 'action (lambda (button) (browse-url "http://www.gnu.org/"))
1360 'follow-link t)
1361 (insert "\n\n")))))
1363 (defun fancy-startup-tail (&optional concise)
1364 "Insert the tail part of the splash screen into the current buffer."
1365 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1366 "cyan" "darkblue")))
1367 (unless concise
1368 (fancy-splash-insert
1369 :face 'variable-pitch
1370 "\nTo start... "
1371 :link '("Open a File"
1372 (lambda (button) (call-interactively 'find-file))
1373 "Specify a new file's name, to edit the file")
1375 :link '("Open Home Directory"
1376 (lambda (button) (dired "~"))
1377 "Open your home directory, to operate on its files")
1379 :link '("Customize Startup"
1380 (lambda (button) (customize-group 'initialization))
1381 "Change initialization settings including this screen")
1382 "\n"))
1383 (fancy-splash-insert :face `(variable-pitch (:foreground ,fg))
1384 "\nThis is "
1385 (emacs-version)
1386 "\n"
1387 :face '(variable-pitch (:height 0.5))
1388 emacs-copyright
1389 "\n")
1390 (and auto-save-list-file-prefix
1391 ;; Don't signal an error if the
1392 ;; directory for auto-save-list files
1393 ;; does not yet exist.
1394 (file-directory-p (file-name-directory
1395 auto-save-list-file-prefix))
1396 (directory-files
1397 (file-name-directory auto-save-list-file-prefix)
1399 (concat "\\`"
1400 (regexp-quote (file-name-nondirectory
1401 auto-save-list-file-prefix)))
1403 (fancy-splash-insert :face '(variable-pitch (:foreground "red"))
1404 "\nIf an Emacs session crashed recently, "
1405 "type "
1406 :face '(fixed-pitch :foreground "red")
1407 "Meta-x recover-session RET"
1408 :face '(variable-pitch (:foreground "red"))
1409 "\nto recover"
1410 " the files you were editing."))
1412 (when concise
1413 (fancy-splash-insert
1414 :face 'variable-pitch "\n"
1415 :link '("Dismiss this startup screen"
1416 (lambda (button)
1417 (when startup-screen-inhibit-startup-screen
1418 (customize-set-variable 'inhibit-startup-screen t)
1419 (customize-mark-to-save 'inhibit-startup-screen)
1420 (custom-save-all))
1421 (let ((w (get-buffer-window "*GNU Emacs*")))
1422 (and w (not (one-window-p)) (delete-window w)))
1423 (kill-buffer "*GNU Emacs*")))
1424 " ")
1425 (when (or user-init-file custom-file)
1426 (let ((checked (create-image "\300\300\141\143\067\076\034\030"
1427 'xbm t :width 8 :height 8 :background "grey75"
1428 :foreground "black" :relief -2 :ascent 'center))
1429 (unchecked (create-image (make-string 8 0)
1430 'xbm t :width 8 :height 8 :background "grey75"
1431 :foreground "black" :relief -2 :ascent 'center)))
1432 (insert-button
1433 " " :on-glyph checked :off-glyph unchecked 'checked nil
1434 'display unchecked 'follow-link t
1435 'action (lambda (button)
1436 (if (overlay-get button 'checked)
1437 (progn (overlay-put button 'checked nil)
1438 (overlay-put button 'display (overlay-get button :off-glyph))
1439 (setq startup-screen-inhibit-startup-screen nil))
1440 (overlay-put button 'checked t)
1441 (overlay-put button 'display (overlay-get button :on-glyph))
1442 (setq startup-screen-inhibit-startup-screen t)))))
1443 (fancy-splash-insert :face '(variable-pitch (:height 0.9))
1444 " Never show it again.")))))
1446 (defun exit-splash-screen ()
1447 "Stop displaying the splash screen buffer."
1448 (interactive)
1449 (quit-window t))
1451 (defun fancy-startup-screen (&optional concise)
1452 "Display fancy startup screen.
1453 If CONCISE is non-nil, display a concise version of the
1454 splash screen in another window."
1455 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1456 (with-current-buffer splash-buffer
1457 (let ((inhibit-read-only t))
1458 (erase-buffer)
1459 (setq default-directory command-line-default-directory)
1460 (make-local-variable 'startup-screen-inhibit-startup-screen)
1461 (if pure-space-overflow
1462 (insert pure-space-overflow-message))
1463 (unless concise
1464 (fancy-splash-head))
1465 (dolist (text fancy-startup-text)
1466 (apply #'fancy-splash-insert text)
1467 (insert "\n"))
1468 (skip-chars-backward "\n")
1469 (delete-region (point) (point-max))
1470 (insert "\n")
1471 (fancy-startup-tail concise))
1472 (use-local-map splash-screen-keymap)
1473 (setq tab-width 22
1474 buffer-read-only t)
1475 (set-buffer-modified-p nil)
1476 (if (and view-read-only (not view-mode))
1477 (view-mode-enter nil 'kill-buffer))
1478 (goto-char (point-min))
1479 (forward-line (if concise 2 4)))
1480 (if concise
1481 (progn
1482 (display-buffer splash-buffer)
1483 ;; If the splash screen is in a split window, fit it.
1484 (let ((window (get-buffer-window splash-buffer t)))
1485 (or (null window)
1486 (eq window (selected-window))
1487 (eq window (next-window window))
1488 (fit-window-to-buffer window))))
1489 (switch-to-buffer splash-buffer))))
1491 (defun fancy-about-screen ()
1492 "Display fancy About screen."
1493 (let ((frame (fancy-splash-frame)))
1494 (save-selected-window
1495 (select-frame frame)
1496 (switch-to-buffer "*About GNU Emacs*")
1497 (setq buffer-undo-list t
1498 mode-line-format (propertize "---- %b %-"
1499 'face 'mode-line-buffer-id))
1500 (let ((inhibit-read-only t))
1501 (erase-buffer)
1502 (if pure-space-overflow
1503 (insert pure-space-overflow-message))
1504 (fancy-splash-head)
1505 (dolist (text fancy-about-text)
1506 (apply #'fancy-splash-insert text)
1507 (insert "\n"))
1508 (set-buffer-modified-p nil)
1509 (goto-char (point-min))
1510 (force-mode-line-update))
1511 (use-local-map splash-screen-keymap)
1512 (setq tab-width 22)
1513 (message "%s" (startup-echo-area-message))
1514 (setq buffer-read-only t)
1515 (goto-char (point-min))
1516 (forward-line 3))))
1518 (defun fancy-splash-frame ()
1519 "Return the frame to use for the fancy splash screen.
1520 Returning non-nil does not mean we should necessarily
1521 use the fancy splash screen, but if we do use it,
1522 we put it on this frame."
1523 (let (chosen-frame)
1524 (dolist (frame (append (frame-list) (list (selected-frame))))
1525 (if (and (frame-visible-p frame)
1526 (not (window-minibuffer-p (frame-selected-window frame))))
1527 (setq chosen-frame frame)))
1528 chosen-frame))
1530 (defun use-fancy-splash-screens-p ()
1531 "Return t if fancy splash screens should be used."
1532 (when (and (display-graphic-p)
1533 (or (and (display-color-p)
1534 (image-type-available-p 'xpm))
1535 (image-type-available-p 'pbm)))
1536 (let ((frame (fancy-splash-frame)))
1537 (when frame
1538 (let* ((img (create-image (or fancy-splash-image
1539 (if (and (display-color-p)
1540 (image-type-available-p 'xpm))
1541 "splash.xpm" "splash.pbm"))))
1542 (image-height (and img (cdr (image-size img nil frame))))
1543 ;; We test frame-height so that, if the frame is split
1544 ;; by displaying a warning, that doesn't cause the normal
1545 ;; splash screen to be used.
1546 (frame-height (1- (frame-height frame))))
1547 (> frame-height (+ image-height 19)))))))
1550 (defun normal-splash-screen (&optional startup concise)
1551 "Display non-graphic splash screen.
1552 If optional argument STARTUP is non-nil, display the startup screen
1553 after Emacs starts. If STARTUP is nil, display the About screen.
1554 If CONCISE is non-nil, display a concise version of the
1555 splash screen in another window."
1556 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1557 (with-current-buffer splash-buffer
1558 (setq buffer-read-only nil)
1559 (erase-buffer)
1560 (setq default-directory command-line-default-directory)
1561 (set (make-local-variable 'tab-width) 8)
1562 (if (not startup)
1563 (set (make-local-variable 'mode-line-format)
1564 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1566 (if pure-space-overflow
1567 (insert pure-space-overflow-message))
1569 ;; The convention for this piece of code is that
1570 ;; each piece of output starts with one or two newlines
1571 ;; and does not end with any newlines.
1572 (insert (if startup "Welcome to GNU Emacs" "This is GNU Emacs"))
1573 (insert
1574 (if (eq system-type 'gnu/linux)
1575 ", one component of the GNU/Linux operating system.\n"
1576 ", a part of the GNU operating system.\n"))
1578 (if startup
1579 (if (display-mouse-p)
1580 ;; The user can use the mouse to activate menus
1581 ;; so give help in terms of menu items.
1582 (normal-mouse-startup-screen)
1584 ;; No mouse menus, so give help using kbd commands.
1585 (normal-no-mouse-startup-screen))
1587 (normal-about-screen))
1589 ;; The rest of the startup screen is the same on all
1590 ;; kinds of terminals.
1592 ;; Give information on recovering, if there was a crash.
1593 (and startup
1594 auto-save-list-file-prefix
1595 ;; Don't signal an error if the
1596 ;; directory for auto-save-list files
1597 ;; does not yet exist.
1598 (file-directory-p (file-name-directory
1599 auto-save-list-file-prefix))
1600 (directory-files
1601 (file-name-directory auto-save-list-file-prefix)
1603 (concat "\\`"
1604 (regexp-quote (file-name-nondirectory
1605 auto-save-list-file-prefix)))
1607 (insert "\n\nIf an Emacs session crashed recently, "
1608 "type Meta-x recover-session RET\nto recover"
1609 " the files you were editing.\n"))
1611 (use-local-map splash-screen-keymap)
1613 ;; Display the input that we set up in the buffer.
1614 (set-buffer-modified-p nil)
1615 (setq buffer-read-only t)
1616 (if (and view-read-only (not view-mode))
1617 (view-mode-enter nil 'kill-buffer))
1618 (if startup (rename-buffer "*GNU Emacs*" t))
1619 (goto-char (point-min)))
1620 (if concise
1621 (display-buffer splash-buffer)
1622 (switch-to-buffer splash-buffer))))
1624 (defun normal-mouse-startup-screen ()
1625 ;; The user can use the mouse to activate menus
1626 ;; so give help in terms of menu items.
1627 (insert "\
1628 To follow a link, click Mouse-1 on it, or move to it and type RET.
1629 To quit a partially entered command, type Control-g.\n")
1631 (insert "\nImportant Help menu items:\n")
1632 (insert-button "Emacs Tutorial"
1633 'action (lambda (button) (help-with-tutorial))
1634 'follow-link t)
1635 (insert "\t\tLearn basic Emacs keystroke commands\n")
1636 (insert-button "Read the Emacs Manual"
1637 'action (lambda (button) (info-emacs-manual))
1638 'follow-link t)
1639 (insert "\tView the Emacs manual using Info\n")
1640 (insert-button "\(Non)Warranty"
1641 'action (lambda (button) (describe-no-warranty))
1642 'follow-link t)
1643 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1644 (insert-button "Copying Conditions"
1645 'action (lambda (button) (describe-copying))
1646 'follow-link t)
1647 (insert "\tConditions for redistributing and changing Emacs\n")
1648 (insert-button "More Manuals / Ordering Manuals"
1649 'action (lambda (button) (view-order-manuals))
1650 'follow-link t)
1651 (insert " How to order printed manuals from the FSF\n")
1653 (insert "\nUseful tasks:\n")
1654 (insert-button "Visit New File"
1655 'action (lambda (button) (call-interactively 'find-file))
1656 'follow-link t)
1657 (insert "\t\tSpecify a new file's name, to edit the file\n")
1658 (insert-button "Open Home Directory"
1659 'action (lambda (button) (dired "~"))
1660 'follow-link t)
1661 (insert "\tOpen your home directory, to operate on its files\n")
1662 (insert-button "Customize Startup"
1663 'action (lambda (button) (customize-group 'initialization))
1664 'follow-link t)
1665 (insert "\tChange initialization settings including this screen\n")
1667 (insert "\n" (emacs-version)
1668 "\n" emacs-copyright))
1670 ;; No mouse menus, so give help using kbd commands.
1671 (defun normal-no-mouse-startup-screen ()
1673 ;; If keys have their default meanings,
1674 ;; use precomputed string to save lots of time.
1675 (if (and (eq (key-binding "\C-h") 'help-command)
1676 (eq (key-binding "\C-xu") 'advertised-undo)
1677 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1678 (eq (key-binding "\C-ht") 'help-with-tutorial)
1679 (eq (key-binding "\C-hi") 'info)
1680 (eq (key-binding "\C-hr") 'info-emacs-manual)
1681 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1682 (progn
1683 (insert "
1684 Get help\t C-h (Hold down CTRL and press h)
1686 (insert-button "Emacs manual"
1687 'action (lambda (button) (info-emacs-manual))
1688 'follow-link t)
1689 (insert " C-h r\t")
1690 (insert-button "Browse manuals"
1691 'action (lambda (button) (Info-directory))
1692 'follow-link t)
1693 (insert "\t C-h i
1695 (insert-button "Emacs tutorial"
1696 'action (lambda (button) (help-with-tutorial))
1697 'follow-link t)
1698 (insert " C-h t\tUndo changes\t C-x u
1700 (insert-button "Buy manuals"
1701 'action (lambda (button) (view-order-manuals))
1702 'follow-link t)
1703 (insert "\t C-h C-m\tExit Emacs\t C-x C-c"))
1705 (insert (format "
1706 Get help\t %s
1708 (let ((where (where-is-internal
1709 'help-command nil t)))
1710 (if where
1711 (key-description where)
1712 "M-x help"))))
1713 (insert-button "Emacs manual"
1714 'action (lambda (button) (info-emacs-manual))
1715 'follow-link t)
1716 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1717 (insert-button "Browse manuals"
1718 'action (lambda (button) (Info-directory))
1719 'follow-link t)
1720 (insert (substitute-command-keys "\t \\[info]
1722 (insert-button "Emacs tutorial"
1723 'action (lambda (button) (help-with-tutorial))
1724 'follow-link t)
1725 (insert (substitute-command-keys
1726 "\t \\[help-with-tutorial]\tUndo changes\t \\[advertised-undo]
1728 (insert-button "Buy manuals"
1729 'action (lambda (button) (view-order-manuals))
1730 'follow-link t)
1731 (insert (substitute-command-keys
1732 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-emacs]")))
1734 ;; Say how to use the menu bar with the keyboard.
1735 (insert "\n")
1736 (insert-button "Activate menubar"
1737 'action (lambda (button) (tmm-menubar))
1738 'follow-link t)
1739 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1740 (eq (key-binding [f10]) 'tmm-menubar))
1741 (insert " F10 or ESC ` or M-`")
1742 (insert (substitute-command-keys " \\[tmm-menubar]")))
1744 ;; Many users seem to have problems with these.
1745 (insert "
1746 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1747 If you have no Meta key, you may instead type ESC followed by the character.)")
1749 ;; Insert links to useful tasks
1750 (insert "\nUseful tasks:\n")
1752 (insert-button "Visit New File"
1753 'action (lambda (button) (call-interactively 'find-file))
1754 'follow-link t)
1755 (insert "\t\t\t")
1756 (insert-button "Open Home Directory"
1757 'action (lambda (button) (dired "~"))
1758 'follow-link t)
1759 (insert "\n")
1761 (insert-button "Customize Startup"
1762 'action (lambda (button) (customize-group 'initialization))
1763 'follow-link t)
1764 (insert "\t\t")
1765 (insert-button "Open *scratch* buffer"
1766 'action (lambda (button) (switch-to-buffer
1767 (get-buffer-create "*scratch*")))
1768 'follow-link t)
1769 (insert "\n")
1770 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1772 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1773 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1774 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1775 (progn
1776 (insert
1778 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1779 (insert-button "full details"
1780 'action (lambda (button) (describe-no-warranty))
1781 'follow-link t)
1782 (insert ".
1783 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1784 of Emacs and modify it; type C-h C-c to see ")
1785 (insert-button "the conditions"
1786 'action (lambda (button) (describe-copying))
1787 'follow-link t)
1788 (insert ".
1789 Type C-h C-d for information on ")
1790 (insert-button "getting the latest version"
1791 'action (lambda (button) (describe-distribution))
1792 'follow-link t)
1793 (insert "."))
1794 (insert (substitute-command-keys
1796 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1797 (insert-button "full details"
1798 'action (lambda (button) (describe-no-warranty))
1799 'follow-link t)
1800 (insert (substitute-command-keys ".
1801 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1802 of Emacs and modify it; type \\[describe-copying] to see "))
1803 (insert-button "the conditions"
1804 'action (lambda (button) (describe-copying))
1805 'follow-link t)
1806 (insert (substitute-command-keys".
1807 Type \\[describe-distribution] for information on "))
1808 (insert-button "getting the latest version"
1809 'action (lambda (button) (describe-distribution))
1810 'follow-link t)
1811 (insert ".")))
1813 (defun normal-about-screen ()
1814 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1816 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1818 (insert-button "GNU and Freedom"
1819 'action (lambda (button) (describe-project))
1820 'follow-link t)
1821 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
1823 (insert-button "Absence of Warranty"
1824 'action (lambda (button) (describe-no-warranty))
1825 'follow-link t)
1826 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1828 (insert-button "Copying Conditions"
1829 'action (lambda (button) (describe-copying))
1830 'follow-link t)
1831 (insert "\tConditions for redistributing and changing Emacs\n")
1833 (insert-button "Getting New Versions"
1834 'action (lambda (button) (describe-distribution))
1835 'follow-link t)
1836 (insert "\tHow to get the latest version of GNU Emacs\n")
1838 (insert-button "More Manuals / Ordering Manuals"
1839 'action (lambda (button) (view-order-manuals))
1840 'follow-link t)
1841 (insert "\tBuying printed manuals from the FSF\n"))
1843 (defun startup-echo-area-message ()
1844 (if (eq (key-binding "\C-h\C-a") 'about-emacs)
1845 "For information about GNU Emacs and the GNU system, type C-h C-a."
1846 (substitute-command-keys
1847 "For information about GNU Emacs and the GNU system, type \
1848 \\[about-emacs].")))
1851 (defun display-startup-echo-area-message ()
1852 (let ((resize-mini-windows t))
1853 (or noninteractive ;(input-pending-p) init-file-had-error
1854 ;; t if the init file says to inhibit the echo area startup message.
1855 (and inhibit-startup-echo-area-message
1856 user-init-file
1857 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1858 (equal inhibit-startup-echo-area-message
1859 (if (equal init-file-user "")
1860 (user-login-name)
1861 init-file-user)))
1862 ;; Wasn't set with custom; see if .emacs has a setq.
1863 (let ((buffer (get-buffer-create " *temp*")))
1864 (prog1
1865 (condition-case nil
1866 (save-excursion
1867 (set-buffer buffer)
1868 (insert-file-contents user-init-file)
1869 (re-search-forward
1870 (concat
1871 "([ \t\n]*setq[ \t\n]+"
1872 "inhibit-startup-echo-area-message[ \t\n]+"
1873 (regexp-quote
1874 (prin1-to-string
1875 (if (equal init-file-user "")
1876 (user-login-name)
1877 init-file-user)))
1878 "[ \t\n]*)")
1879 nil t))
1880 (error nil))
1881 (kill-buffer buffer)))))
1882 (message "%s" (startup-echo-area-message)))))
1884 (defun display-startup-screen (&optional concise)
1885 "Display startup screen according to display.
1886 A fancy display is used on graphic displays, normal otherwise.
1888 If CONCISE is non-nil, display a concise version of the startup
1889 screen."
1890 ;; Prevent recursive calls from server-process-filter.
1891 (if (not (get-buffer "*GNU Emacs*"))
1892 (if (use-fancy-splash-screens-p)
1893 (fancy-startup-screen concise)
1894 (normal-splash-screen t concise))))
1896 (defun display-about-screen ()
1897 "Display the *About GNU Emacs* buffer.
1898 A fancy display is used on graphic displays, normal otherwise."
1899 (interactive)
1900 (if (use-fancy-splash-screens-p)
1901 (fancy-about-screen)
1902 (normal-splash-screen nil)))
1904 (defalias 'about-emacs 'display-about-screen)
1905 (defalias 'display-splash-screen 'display-startup-screen)
1907 (defun command-line-1 (command-line-args-left)
1908 (display-startup-echo-area-message)
1910 ;; Delay 2 seconds after an init file error message
1911 ;; was displayed, so user can read it.
1912 (when init-file-had-error
1913 (sit-for 2))
1915 (when (and pure-space-overflow
1916 (not noninteractive))
1917 (display-warning
1918 'initialization
1919 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1920 :warning))
1922 (let ((file-count 0)
1923 first-file-buffer)
1924 (when command-line-args-left
1925 ;; We have command args; process them.
1926 (let ((dir command-line-default-directory)
1928 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1929 ;; if foo is intended to be found in DIR.
1931 ;; ;; The directories listed in --directory/-L options will *appear*
1932 ;; ;; at the front of `load-path' in the order they appear on the
1933 ;; ;; command-line. We cannot do this by *placing* them at the front
1934 ;; ;; in the order they appear, so we need this variable to hold them,
1935 ;; ;; temporarily.
1936 ;; extra-load-path
1938 ;; To DTRT we keep track of the splice point and modify `load-path'
1939 ;; straight away upon any --directory/-L option.
1940 splice
1941 just-files ;; t if this follows the magic -- option.
1942 ;; This includes our standard options' long versions
1943 ;; and long versions of what's on command-switch-alist.
1944 (longopts
1945 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1946 ("--directory") ("--eval") ("--execute") ("--no-splash")
1947 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1948 (mapcar (lambda (elt)
1949 (list (concat "-" (car elt))))
1950 command-switch-alist)))
1951 (line 0)
1952 (column 0))
1954 ;; Add the long X options to longopts.
1955 (dolist (tem command-line-x-option-alist)
1956 (if (string-match "^--" (car tem))
1957 (push (list (car tem)) longopts)))
1959 ;; Loop, processing options.
1960 (while command-line-args-left
1961 (let* ((argi (car command-line-args-left))
1962 (orig-argi argi)
1963 argval completion)
1964 (setq command-line-args-left (cdr command-line-args-left))
1966 ;; Do preliminary decoding of the option.
1967 (if just-files
1968 ;; After --, don't look for options; treat all args as files.
1969 (setq argi "")
1970 ;; Convert long options to ordinary options
1971 ;; and separate out an attached option argument into argval.
1972 (when (string-match "^\\(--[^=]*\\)=" argi)
1973 (setq argval (substring argi (match-end 0))
1974 argi (match-string 1 argi)))
1975 (if (equal argi "--")
1976 (setq completion nil)
1977 (setq completion (try-completion argi longopts)))
1978 (if (eq completion t)
1979 (setq argi (substring argi 1))
1980 (if (stringp completion)
1981 (let ((elt (assoc completion longopts)))
1982 (or elt
1983 (error "Option `%s' is ambiguous" argi))
1984 (setq argi (substring (car elt) 1)))
1985 (setq argval nil
1986 argi orig-argi))))
1988 ;; Execute the option.
1989 (cond ((setq tem (assoc argi command-switch-alist))
1990 (if argval
1991 (let ((command-line-args-left
1992 (cons argval command-line-args-left)))
1993 (funcall (cdr tem) argi))
1994 (funcall (cdr tem) argi)))
1996 ((equal argi "-no-splash")
1997 (setq inhibit-startup-screen t))
1999 ((member argi '("-f" ; what the manual claims
2000 "-funcall"
2001 "-e")) ; what the source used to say
2002 (setq inhibit-startup-screen t)
2003 (setq tem (intern (or argval (pop command-line-args-left))))
2004 (if (commandp tem)
2005 (command-execute tem)
2006 (funcall tem)))
2008 ((member argi '("-eval" "-execute"))
2009 (setq inhibit-startup-screen t)
2010 (eval (read (or argval (pop command-line-args-left)))))
2012 ((member argi '("-L" "-directory"))
2013 (setq tem (expand-file-name
2014 (command-line-normalize-file-name
2015 (or argval (pop command-line-args-left)))))
2016 (cond (splice (setcdr splice (cons tem (cdr splice)))
2017 (setq splice (cdr splice)))
2018 (t (setq load-path (cons tem load-path)
2019 splice load-path))))
2021 ((member argi '("-l" "-load"))
2022 (let* ((file (command-line-normalize-file-name
2023 (or argval (pop command-line-args-left))))
2024 ;; Take file from default dir if it exists there;
2025 ;; otherwise let `load' search for it.
2026 (file-ex (expand-file-name file)))
2027 (when (file-exists-p file-ex)
2028 (setq file file-ex))
2029 (load file nil t)))
2031 ;; This is used to handle -script. It's not clear
2032 ;; we need to document it.
2033 ((member argi '("-scriptload"))
2034 (let* ((file (command-line-normalize-file-name
2035 (or argval (pop command-line-args-left))))
2036 ;; Take file from default dir.
2037 (file-ex (expand-file-name file)))
2038 (load file-ex nil t t)))
2040 ((equal argi "-insert")
2041 (setq inhibit-startup-screen t)
2042 (setq tem (or argval (pop command-line-args-left)))
2043 (or (stringp tem)
2044 (error "File name omitted from `-insert' option"))
2045 (insert-file-contents (command-line-normalize-file-name tem)))
2047 ((equal argi "-kill")
2048 (kill-emacs t))
2050 ;; This is for when they use --no-desktop with -q, or
2051 ;; don't load Desktop in their .emacs. If desktop.el
2052 ;; _is_ loaded, it will handle this switch, and we
2053 ;; won't see it by the time we get here.
2054 ((equal argi "-no-desktop")
2055 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2057 ((string-match "^\\+[0-9]+\\'" argi)
2058 (setq line (string-to-number argi)))
2060 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2061 (setq line (string-to-number (match-string 1 argi))
2062 column (string-to-number (match-string 2 argi))))
2064 ((setq tem (assoc argi command-line-x-option-alist))
2065 ;; Ignore X-windows options and their args if not using X.
2066 (setq command-line-args-left
2067 (nthcdr (nth 1 tem) command-line-args-left)))
2069 ((member argi '("-find-file" "-file" "-visit"))
2070 (setq inhibit-startup-screen t)
2071 ;; An explicit option to specify visiting a file.
2072 (setq tem (or argval (pop command-line-args-left)))
2073 (unless (stringp tem)
2074 (error "File name omitted from `%s' option" argi))
2075 (setq file-count (1+ file-count))
2076 (let ((file (expand-file-name
2077 (command-line-normalize-file-name tem) dir)))
2078 (if (= file-count 1)
2079 (setq first-file-buffer (find-file file))
2080 (find-file-other-window file)))
2081 (or (zerop line)
2082 (goto-line line))
2083 (setq line 0)
2084 (unless (< column 1)
2085 (move-to-column (1- column)))
2086 (setq column 0))
2088 ((equal argi "--")
2089 (setq just-files t))
2091 ;; We have almost exhausted our options. See if the
2092 ;; user has made any other command-line options available
2093 (let ((hooks command-line-functions)
2094 (did-hook nil))
2095 (while (and hooks
2096 (not (setq did-hook (funcall (car hooks)))))
2097 (setq hooks (cdr hooks)))
2098 (if (not did-hook)
2099 ;; Presume that the argument is a file name.
2100 (progn
2101 (if (string-match "\\`-" argi)
2102 (error "Unknown option `%s'" argi))
2103 (unless window-system
2104 (setq inhibit-startup-screen t))
2105 (setq file-count (1+ file-count))
2106 (let ((file
2107 (expand-file-name
2108 (command-line-normalize-file-name orig-argi)
2109 dir)))
2110 (cond ((= file-count 1)
2111 (setq first-file-buffer (find-file file)))
2112 (inhibit-startup-screen
2113 (find-file-other-window file))
2114 (t (find-file file))))
2115 (or (zerop line)
2116 (goto-line line))
2117 (setq line 0)
2118 (unless (< column 1)
2119 (move-to-column (1- column)))
2120 (setq column 0))))))
2121 ;; In unusual circumstances, the execution of Lisp code due
2122 ;; to command-line options can cause the last visible frame
2123 ;; to be deleted. In this case, kill emacs to avoid an
2124 ;; abort later.
2125 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2127 (if (or inhibit-startup-screen
2128 noninteractive
2129 emacs-quick-startup)
2131 ;; Not displaying a startup screen. If 3 or more files
2132 ;; visited, and not all visible, show user what they all are.
2133 (and (> file-count 2)
2134 (not noninteractive)
2135 (not inhibit-startup-buffer-menu)
2136 (or (get-buffer-window first-file-buffer)
2137 (list-buffers)))
2139 ;; Display a startup screen, after some preparations.
2141 ;; If there are no switches to process, we might as well
2142 ;; run this hook now, and there may be some need to do it
2143 ;; before doing any output.
2144 (run-hooks 'emacs-startup-hook)
2145 (and term-setup-hook
2146 (run-hooks 'term-setup-hook))
2147 (setq inhibit-startup-hooks t)
2149 ;; It's important to notice the user settings before we
2150 ;; display the startup message; otherwise, the settings
2151 ;; won't take effect until the user gives the first
2152 ;; keystroke, and that's distracting.
2153 (when (fboundp 'frame-notice-user-settings)
2154 (frame-notice-user-settings))
2156 ;; If there are no switches to process, we might as well
2157 ;; run this hook now, and there may be some need to do it
2158 ;; before doing any output.
2159 (when window-setup-hook
2160 (run-hooks 'window-setup-hook)
2161 ;; Don't let the hook be run twice.
2162 (setq window-setup-hook nil))
2164 ;; ;; Do this now to avoid an annoying delay if the user
2165 ;; ;; clicks the menu bar during the sit-for.
2166 ;; (when (display-popup-menus-p)
2167 ;; (precompute-menubar-bindings))
2168 ;; (with-no-warnings
2169 ;; (setq menubar-bindings-done t))
2171 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2172 (and initial-scratch-message
2173 (get-buffer "*scratch*")
2174 (with-current-buffer "*scratch*"
2175 (when (zerop (buffer-size))
2176 (insert initial-scratch-message)
2177 (set-buffer-modified-p nil))))
2179 (if (> file-count 0)
2180 (display-startup-screen t)
2181 (display-startup-screen nil)))))
2183 (defun command-line-normalize-file-name (file)
2184 "Collapse multiple slashes to one, to handle non-Emacs file names."
2185 (save-match-data
2186 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2187 ;; That is significant on some systems.
2188 ;; However, /// at the beginning is supposed to mean just /, not //.
2189 (if (string-match "^///+" file)
2190 (setq file (replace-match "/" t t file)))
2191 (while (string-match "//+" file 1)
2192 (setq file (replace-match "/" t t file)))
2193 file))
2195 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
2196 ;;; startup.el ends here