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