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