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