Switch to recommended form of GPLv3 permissions notice.
[emacs.git] / lisp / startup.el
blobeb8898551eb0867551ad2086d554d970460af9d2
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 of the License, or
15 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; This file parses the command line and gets Emacs running. Options
28 ;; on the command line are handled in precedence order. For priorities
29 ;; see the structure standard_args in the emacs.c file.
31 ;;; Code:
33 (setq top-level '(normal-top-level))
35 (defvar command-line-processed nil
36 "Non-nil once command line has been processed.")
38 (defgroup initialization nil
39 "Emacs start-up procedure."
40 :group 'environment)
42 (defcustom initial-buffer-choice nil
43 "Buffer to show after starting Emacs.
44 If the value is nil and `inhibit-startup-screen' is nil, show the
45 startup screen. If the value is string, visit the specified file or
46 directory using `find-file'. If t, open the `*scratch*' buffer."
47 :type '(choice
48 (const :tag "Startup screen" nil)
49 (directory :tag "Directory" :value "~/")
50 (file :tag "File" :value "~/file.txt")
51 (const :tag "Lisp scratch buffer" t))
52 :version "23.1"
53 :group 'initialization)
55 (defcustom inhibit-startup-screen nil
56 "Non-nil inhibits the startup screen.
58 This is for use in your personal init file (but NOT site-start.el), once
59 you are familiar with the contents of the startup screen."
60 :type 'boolean
61 :group 'initialization)
63 (defvaralias 'inhibit-splash-screen 'inhibit-startup-screen)
64 (defvaralias 'inhibit-startup-message 'inhibit-startup-screen)
66 (defvar startup-screen-inhibit-startup-screen nil)
68 (defcustom inhibit-startup-echo-area-message nil
69 "*Non-nil inhibits the initial startup echo area message.
70 Setting this variable takes effect
71 only if you do it with the customization buffer
72 or if your `.emacs' file contains a line of this form:
73 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
74 If your `.emacs' file is byte-compiled, use the following form instead:
75 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
76 Thus, someone else using a copy of your `.emacs' file will see
77 the startup message unless he personally acts to inhibit it."
78 :type '(choice (const :tag "Don't inhibit")
79 (string :tag "Enter your user name, to inhibit"))
80 :group 'initialization)
82 (defcustom inhibit-default-init nil
83 "*Non-nil inhibits loading the `default' library."
84 :type 'boolean
85 :group 'initialization)
87 (defcustom inhibit-startup-buffer-menu nil
88 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
89 :type 'boolean
90 :group 'initialization)
92 (defvar command-switch-alist nil
93 "Alist of command-line switches.
94 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
95 HANDLER-FUNCTION receives the switch string as its sole argument;
96 the remaining command-line args are in the variable `command-line-args-left'.")
98 (defvar command-line-args-left nil
99 "List of command-line args not yet processed.")
101 (defvaralias 'argv 'command-line-args-left
102 "List of command-line args not yet processed.
103 This is a convenience alias, so that one can write \(pop argv\)
104 inside of --eval command line arguments in order to access
105 following arguments.")
107 (defvar command-line-functions nil ;; lrs 7/31/89
108 "List of functions to process unrecognized command-line arguments.
109 Each function should access the dynamically bound variables
110 `argi' (the current argument) and `command-line-args-left' (the remaining
111 arguments). The function should return non-nil only if it recognizes and
112 processes `argi'. If it does so, it may consume successive arguments by
113 altering `command-line-args-left' to remove them.")
115 (defvar command-line-default-directory nil
116 "Default directory to use for command line arguments.
117 This is normally copied from `default-directory' when Emacs starts.")
119 ;;; This is here, rather than in x-win.el, so that we can ignore these
120 ;;; options when we are not using X.
121 (defconst command-line-x-option-alist
122 '(("-bw" 1 x-handle-numeric-switch border-width)
123 ("-d" 1 x-handle-display)
124 ("-display" 1 x-handle-display)
125 ("-name" 1 x-handle-name-switch)
126 ("-title" 1 x-handle-switch title)
127 ("-T" 1 x-handle-switch title)
128 ("-r" 0 x-handle-switch reverse t)
129 ("-rv" 0 x-handle-switch reverse t)
130 ("-reverse" 0 x-handle-switch reverse t)
131 ("-reverse-video" 0 x-handle-switch reverse t)
132 ("-fn" 1 x-handle-switch font)
133 ("-font" 1 x-handle-switch font)
134 ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
135 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
136 ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
137 ("-ib" 1 x-handle-numeric-switch internal-border-width)
138 ("-g" 1 x-handle-geometry)
139 ("-lsp" 1 x-handle-numeric-switch line-spacing)
140 ("-geometry" 1 x-handle-geometry)
141 ("-fg" 1 x-handle-switch foreground-color)
142 ("-foreground" 1 x-handle-switch foreground-color)
143 ("-bg" 1 x-handle-switch background-color)
144 ("-background" 1 x-handle-switch background-color)
145 ("-ms" 1 x-handle-switch mouse-color)
146 ("-nbi" 0 x-handle-switch icon-type nil)
147 ("-iconic" 0 x-handle-iconic)
148 ("-xrm" 1 x-handle-xrm-switch)
149 ("-cr" 1 x-handle-switch cursor-color)
150 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
151 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
152 ("-bd" 1 x-handle-switch)
153 ("--border-width" 1 x-handle-numeric-switch border-width)
154 ("--display" 1 x-handle-display)
155 ("--name" 1 x-handle-name-switch)
156 ("--title" 1 x-handle-switch title)
157 ("--reverse-video" 0 x-handle-switch reverse t)
158 ("--font" 1 x-handle-switch font)
159 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
160 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
161 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
162 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
163 ("--geometry" 1 x-handle-geometry)
164 ("--foreground-color" 1 x-handle-switch foreground-color)
165 ("--background-color" 1 x-handle-switch background-color)
166 ("--mouse-color" 1 x-handle-switch mouse-color)
167 ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon)
168 ("--iconic" 0 x-handle-iconic)
169 ("--xrm" 1 x-handle-xrm-switch)
170 ("--cursor-color" 1 x-handle-switch cursor-color)
171 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
172 ("--line-spacing" 1 x-handle-numeric-switch line-spacing)
173 ("--border-color" 1 x-handle-switch border-color)
174 ("--smid" 1 x-handle-smid)
175 ("--parent-id" 1 x-handle-parent-id))
176 "Alist of X Windows options.
177 Each element has the form
178 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
179 where NAME is the option name string, NUMARGS is the number of arguments
180 that the option accepts, HANDLER is a function to call to handle the option.
181 FRAME-PARAM (optional) is the frame parameter this option specifies,
182 and VALUE is the value which is given to that frame parameter
183 \(most options use the argument for this, so VALUE is not present).")
185 (defvar before-init-hook nil
186 "Normal hook run after handling urgent options but before loading init files.")
188 (defvar after-init-hook nil
189 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
190 There is no `condition-case' around the running of these functions;
191 therefore, if you set `debug-on-error' non-nil in `.emacs',
192 an error in one of these functions will invoke the debugger.")
194 (defvar before-init-time nil
195 "Value of `current-time' before Emacs begins initialization.")
197 (defvar after-init-time nil
198 "Value of `current-time' after loading the init files.")
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 before-init-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)
847 (custom-reevaluate-setting 'transient-mark-mode)
848 (custom-reevaluate-setting 'auto-encryption-mode)
850 (normal-erase-is-backspace-setup-frame)
852 ;; Register default TTY colors for the case the terminal hasn't a
853 ;; terminal init file. We do this regardles of whether the terminal
854 ;; supports colors or not and regardless the current display type,
855 ;; since users can connect to color-capable terminals and also
856 ;; switch color support on or off in mid-session by setting the
857 ;; tty-color-mode frame parameter.
858 (tty-register-default-colors)
860 ;; Record whether the tool-bar is present before the user and site
861 ;; init files are processed. frame-notice-user-settings uses this
862 ;; to determine if the tool-bar has been disabled by the init files,
863 ;; and the frame needs to be resized.
864 (when (fboundp 'frame-notice-user-settings)
865 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
866 (assq 'tool-bar-lines default-frame-alist))))
867 (setq tool-bar-originally-present
868 (and tool-bar-lines
869 (cdr tool-bar-lines)
870 (not (eq 0 (cdr tool-bar-lines)))))))
872 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
873 (old-font-list-limit font-list-limit)
874 (old-face-ignored-fonts face-ignored-fonts))
876 ;; Run the site-start library if it exists. The point of this file is
877 ;; that it is run before .emacs. There is no point in doing this after
878 ;; .emacs; that is useless.
879 ;; Note that user-init-file is nil at this point. Code that might
880 ;; be loaded from site-run-file and wants to test if -q was given
881 ;; should check init-file-user instead, since that is already set.
882 ;; See cus-edit.el for an example.
883 (if site-run-file
884 (load site-run-file t t))
886 ;; Sites should not disable this. Only individuals should disable
887 ;; the startup screen.
888 (setq inhibit-startup-screen nil)
890 ;; Warn for invalid user name.
891 (when init-file-user
892 (if (string-match "[~/:\n]" init-file-user)
893 (display-warning 'initialization
894 (format "Invalid user name %s"
895 init-file-user)
896 :error)
897 (if (file-directory-p (expand-file-name
898 ;; We don't support ~USER on MS-Windows except
899 ;; for the current user, and always load .emacs
900 ;; from the current user's home directory (see
901 ;; below). So always check "~", even if invoked
902 ;; with "-u USER", or if $USER or $LOGNAME are
903 ;; set to something different.
904 (if (eq system-type 'windows-nt)
906 (concat "~" init-file-user))))
908 (display-warning 'initialization
909 (format "User %s has no home directory"
910 init-file-user)
911 :error))))
913 ;; Load that user's init file, or the default one, or none.
914 (let (debug-on-error-from-init-file
915 debug-on-error-should-be-set
916 (debug-on-error-initial
917 (if (eq init-file-debug t) 'startup init-file-debug))
918 (orig-enable-multibyte default-enable-multibyte-characters))
919 (let ((debug-on-error debug-on-error-initial)
920 ;; This function actually reads the init files.
921 (inner
922 (function
923 (lambda ()
924 (if init-file-user
925 (let ((user-init-file-1
926 (cond
927 ((eq system-type 'ms-dos)
928 (concat "~" init-file-user "/_emacs"))
929 ((eq system-type 'windows-nt)
930 ;; Prefer .emacs on Windows.
931 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
932 "~/.emacs"
933 ;; Also support _emacs for compatibility.
934 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
935 "~/_emacs"
936 ;; But default to .emacs if _emacs does not exist.
937 "~/.emacs")))
938 ((eq system-type 'vax-vms)
939 "sys$login:.emacs")
941 (concat "~" init-file-user "/.emacs")))))
942 ;; This tells `load' to store the file name found
943 ;; into user-init-file.
944 (setq user-init-file t)
945 (load user-init-file-1 t t)
947 (when (eq user-init-file t)
948 ;; If we did not find ~/.emacs, try
949 ;; ~/.emacs.d/init.el.
950 (let ((otherfile
951 (expand-file-name
952 "init"
953 (file-name-as-directory
954 (concat "~" init-file-user "/.emacs.d")))))
955 (load otherfile t t)
957 ;; If we did not find the user's init file,
958 ;; set user-init-file conclusively.
959 ;; Don't let it be set from default.el.
960 (when (eq user-init-file t)
961 (setq user-init-file user-init-file-1))))
963 ;; If we loaded a compiled file, set
964 ;; `user-init-file' to the source version if that
965 ;; exists.
966 (when (and user-init-file
967 (equal (file-name-extension user-init-file)
968 "elc"))
969 (let* ((source (file-name-sans-extension user-init-file))
970 (alt (concat source ".el")))
971 (setq source (cond ((file-exists-p alt) alt)
972 ((file-exists-p source) source)
973 (t nil)))
974 (when source
975 (when (file-newer-than-file-p source user-init-file)
976 (message "Warning: %s is newer than %s"
977 source user-init-file)
978 (sit-for 1))
979 (setq user-init-file source))))
981 (unless inhibit-default-init
982 (let ((inhibit-startup-screen nil))
983 ;; Users are supposed to be told their rights.
984 ;; (Plus how to get help and how to undo.)
985 ;; Don't you dare turn this off for anyone
986 ;; except yourself.
987 (load "default" t t)))))))))
988 (if init-file-debug
989 ;; Do this without a condition-case if the user wants to debug.
990 (funcall inner)
991 (condition-case error
992 (progn
993 (funcall inner)
994 (setq init-file-had-error nil))
995 (error
996 (let ((message-log-max nil))
997 (save-excursion
998 (set-buffer (get-buffer-create "*Messages*"))
999 (insert "\n\n"
1000 (format "An error has occurred while loading `%s':\n\n"
1001 user-init-file)
1002 (format "%s%s%s"
1003 (get (car error) 'error-message)
1004 (if (cdr error) ": " "")
1005 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
1006 "\n\n"
1007 "To ensure normal operation, you should investigate and remove the\n"
1008 "cause of the error in your initialization file. Start Emacs with\n"
1009 "the `--debug-init' option to view a complete error backtrace.\n\n"))
1010 (message "Error in init file: %s%s%s"
1011 (get (car error) 'error-message)
1012 (if (cdr error) ": " "")
1013 (mapconcat 'prin1-to-string (cdr error) ", "))
1014 (let ((pop-up-windows nil))
1015 (pop-to-buffer "*Messages*"))
1016 (setq init-file-had-error t)))))
1018 (if (and deactivate-mark transient-mark-mode)
1019 (with-current-buffer (window-buffer)
1020 (deactivate-mark)))
1022 ;; If the user has a file of abbrevs, read it (unless -batch).
1023 (when (and (not noninteractive)
1024 (file-exists-p abbrev-file-name)
1025 (file-readable-p abbrev-file-name))
1026 (quietly-read-abbrev-file abbrev-file-name))
1028 ;; If the abbrevs came entirely from the init file or the
1029 ;; abbrevs file, they do not need saving.
1030 (setq abbrevs-changed nil)
1032 ;; If we can tell that the init file altered debug-on-error,
1033 ;; arrange to preserve the value that it set up.
1034 (or (eq debug-on-error debug-on-error-initial)
1035 (setq debug-on-error-should-be-set t
1036 debug-on-error-from-init-file debug-on-error)))
1037 (if debug-on-error-should-be-set
1038 (setq debug-on-error debug-on-error-from-init-file))
1039 (unless (or default-enable-multibyte-characters
1040 (eq orig-enable-multibyte default-enable-multibyte-characters))
1041 ;; Init file changed to unibyte. Reset existing multibyte
1042 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1043 ;; Arguably this should only be done if they're free of
1044 ;; multibyte characters.
1045 (mapc (lambda (buffer)
1046 (with-current-buffer buffer
1047 (if enable-multibyte-characters
1048 (set-buffer-multibyte nil))))
1049 (buffer-list))
1050 ;; Also re-set the language environment in case it was
1051 ;; originally done before unibyte was set and is sensitive to
1052 ;; unibyte (display table, terminal coding system &c).
1053 (set-language-environment current-language-environment)))
1055 ;; Do this here in case the init file sets mail-host-address.
1056 (if (equal user-mail-address "")
1057 (setq user-mail-address (or (getenv "EMAIL")
1058 (concat (user-login-name) "@"
1059 (or mail-host-address
1060 (system-name))))))
1062 ;; Originally face attributes were specified via
1063 ;; `font-lock-face-attributes'. Users then changed the default
1064 ;; face attributes by setting that variable. However, we try and
1065 ;; be back-compatible and respect its value if set except for
1066 ;; faces where M-x customize has been used to save changes for the
1067 ;; face.
1068 (when (boundp 'font-lock-face-attributes)
1069 (let ((face-attributes font-lock-face-attributes))
1070 (while face-attributes
1071 (let* ((face-attribute (pop face-attributes))
1072 (face (car face-attribute)))
1073 ;; Rustle up a `defface' SPEC from a
1074 ;; `font-lock-face-attributes' entry.
1075 (unless (get face 'saved-face)
1076 (let ((foreground (nth 1 face-attribute))
1077 (background (nth 2 face-attribute))
1078 (bold-p (nth 3 face-attribute))
1079 (italic-p (nth 4 face-attribute))
1080 (underline-p (nth 5 face-attribute))
1081 face-spec)
1082 (when foreground
1083 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1084 (when background
1085 (setq face-spec (cons ':background (cons background face-spec))))
1086 (when bold-p
1087 (setq face-spec (append '(:weight bold) face-spec)))
1088 (when italic-p
1089 (setq face-spec (append '(:slant italic) face-spec)))
1090 (when underline-p
1091 (setq face-spec (append '(:underline t) face-spec)))
1092 (face-spec-set face (list (list t face-spec)) nil)))))))
1094 ;; If parameter have been changed in the init file which influence
1095 ;; face realization, clear the face cache so that new faces will
1096 ;; be realized.
1097 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1098 (eq font-list-limit old-font-list-limit)
1099 (eq face-ignored-fonts old-face-ignored-fonts))
1100 (clear-face-cache)))
1102 (setq after-init-time (current-time))
1103 (run-hooks 'after-init-hook)
1105 ;; Decode all default-directory.
1106 (if (and default-enable-multibyte-characters locale-coding-system)
1107 (save-excursion
1108 (dolist (elt (buffer-list))
1109 (set-buffer elt)
1110 (if default-directory
1111 (setq default-directory
1112 (decode-coding-string default-directory
1113 locale-coding-system t))))
1114 (setq command-line-default-directory
1115 (decode-coding-string command-line-default-directory
1116 locale-coding-system t))))
1118 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1119 (if (get-buffer "*scratch*")
1120 (with-current-buffer "*scratch*"
1121 (if (eq major-mode 'fundamental-mode)
1122 (funcall initial-major-mode))))
1124 ;; Load library for our terminal type.
1125 ;; User init file can set term-file-prefix to nil to prevent this.
1126 (unless (or noninteractive
1127 initial-window-system)
1128 (tty-run-terminal-initialization (selected-frame)))
1130 ;; Update the out-of-memory error message based on user's key bindings
1131 ;; for save-some-buffers.
1132 (setq memory-signal-data
1133 (list 'error
1134 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1136 ;; Process the remaining args.
1137 (command-line-1 (cdr command-line-args))
1139 ;; If -batch, terminate after processing the command options.
1140 (if noninteractive (kill-emacs t))
1142 ;; Run emacs-session-restore (session management) if started by
1143 ;; the session manager and we have a session manager connection.
1144 (if (and (boundp 'x-session-previous-id)
1145 (stringp x-session-previous-id))
1146 (with-no-warnings
1147 (emacs-session-restore x-session-previous-id))))
1149 (defcustom initial-scratch-message (purecopy "\
1150 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1151 ;; If you want to create a file, visit that file with C-x C-f,
1152 ;; then enter the text in that file's own buffer.
1155 "Initial message displayed in *scratch* buffer at startup.
1156 If this is nil, no message will be displayed."
1157 :type '(choice (text :tag "Message")
1158 (const :tag "none" nil))
1159 :group 'initialization)
1162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1163 ;;; Fancy splash screen
1164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1166 (defvar fancy-startup-text
1167 '((:face (variable-pitch (:foreground "red"))
1168 "Welcome to "
1169 :link ("GNU Emacs"
1170 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1171 "Browse http://www.gnu.org/software/emacs/")
1172 ", one component of the "
1173 :link
1174 (lambda ()
1175 (if (eq system-type 'gnu/linux)
1176 '("GNU/Linux"
1177 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1178 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1179 '("GNU" (lambda (button) (describe-gnu-project))
1180 "Display info on the GNU project")))
1181 " operating system.\n"
1182 :face variable-pitch "To quit a partially entered command, type "
1183 :face default "Control-g"
1184 :face variable-pitch ".\n\n"
1185 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1186 "\tLearn basic keystroke commands"
1187 (lambda ()
1188 (let* ((en "TUTORIAL")
1189 (tut (or (get-language-info current-language-environment
1190 'tutorial)
1191 en))
1192 (title (with-temp-buffer
1193 (insert-file-contents
1194 (expand-file-name tut tutorial-directory)
1195 nil 0 256)
1196 (search-forward ".")
1197 (buffer-substring (point-min) (1- (point))))))
1198 ;; If there is a specific tutorial for the current language
1199 ;; environment and it is not English, append its title.
1200 (if (string= en tut)
1202 (concat " (" title ")"))))
1203 "\n"
1204 :face variable-pitch
1205 :link ("Emacs Guided Tour"
1206 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1207 "Browse http://www.gnu.org/software/emacs/tour/")
1208 "\tOverview of Emacs features\n"
1209 :link ("View Emacs Manual" (lambda (button) (info-emacs-manual)))
1210 "\tView the Emacs manual using Info\n"
1211 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1212 "\tGNU Emacs comes with "
1213 :face (variable-pitch (:slant oblique))
1214 "ABSOLUTELY NO WARRANTY\n"
1215 :face variable-pitch
1216 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1217 "\tConditions for redistributing and changing Emacs\n"
1218 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1219 "\tPurchasing printed copies of manuals\n"
1220 "\n"))
1221 "A list of texts to show in the middle part of splash screens.
1222 Each element in the list should be a list of strings or pairs
1223 `:face FACE', like `fancy-splash-insert' accepts them.")
1225 (defvar fancy-about-text
1226 '((:face (variable-pitch (:foreground "red"))
1227 "This is "
1228 :link ("GNU Emacs"
1229 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1230 "Browse http://www.gnu.org/software/emacs/")
1231 ", one component of the "
1232 :link
1233 (lambda ()
1234 (if (eq system-type 'gnu/linux)
1235 '("GNU/Linux"
1236 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1237 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1238 '("GNU" (lambda (button) (describe-gnu-project))
1239 "Display info on the GNU project.")))
1240 " operating system.\n"
1241 :face (lambda ()
1242 (list 'variable-pitch
1243 (list :foreground
1244 (if (eq (frame-parameter nil 'background-mode) 'dark)
1245 "cyan" "darkblue"))))
1246 "\n"
1247 (lambda () (emacs-version))
1248 "\n"
1249 :face (variable-pitch (:height 0.5))
1250 (lambda () emacs-copyright)
1251 "\n\n"
1252 :face variable-pitch
1253 :link ("Authors"
1254 (lambda (button)
1255 (view-file (expand-file-name "AUTHORS" data-directory))
1256 (goto-char (point-min))))
1257 "\tMany people have contributed code included in GNU Emacs\n"
1258 :link ("Contributing"
1259 (lambda (button)
1260 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1261 (goto-char (point-min))))
1262 "\tHow to contribute improvements to Emacs\n"
1263 "\n"
1264 :link ("GNU and Freedom" (lambda (button) (describe-gnu-project)))
1265 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1266 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1267 "\tGNU Emacs comes with "
1268 :face (variable-pitch (:slant oblique))
1269 "ABSOLUTELY NO WARRANTY\n"
1270 :face variable-pitch
1271 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1272 "\tConditions for redistributing and changing Emacs\n"
1273 :link ("Getting New Versions" (lambda (button) (describe-distribution)))
1274 "\tHow to obtain the latest version of Emacs\n"
1275 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1276 "\tBuying printed manuals from the FSF\n"
1277 "\n"
1278 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1279 "\tLearn basic Emacs keystroke commands"
1280 (lambda ()
1281 (let* ((en "TUTORIAL")
1282 (tut (or (get-language-info current-language-environment
1283 'tutorial)
1284 en))
1285 (title (with-temp-buffer
1286 (insert-file-contents
1287 (expand-file-name tut tutorial-directory)
1288 nil 0 256)
1289 (search-forward ".")
1290 (buffer-substring (point-min) (1- (point))))))
1291 ;; If there is a specific tutorial for the current language
1292 ;; environment and it is not English, append its title.
1293 (if (string= en tut)
1295 (concat " (" title ")"))))
1296 "\n"
1297 :link ("Emacs Guided Tour"
1298 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1299 "Browse http://www.gnu.org/software/emacs/tour/")
1300 "\tSee an overview of the many facilities of GNU Emacs"
1302 "A list of texts to show in the middle part of the About screen.
1303 Each element in the list should be a list of strings or pairs
1304 `:face FACE', like `fancy-splash-insert' accepts them.")
1307 (defgroup fancy-splash-screen ()
1308 "Fancy splash screen when Emacs starts."
1309 :version "21.1"
1310 :group 'initialization)
1312 (defcustom fancy-splash-image nil
1313 "*The image to show in the splash screens, or nil for defaults."
1314 :group 'fancy-splash-screen
1315 :type '(choice (const :tag "Default" nil)
1316 (file :tag "File")))
1319 (defvar splash-screen-keymap
1320 (let ((map (make-sparse-keymap)))
1321 (suppress-keymap map)
1322 (set-keymap-parent map button-buffer-map)
1323 (define-key map "\C-?" 'scroll-down)
1324 (define-key map " " 'scroll-up)
1325 (define-key map "q" 'exit-splash-screen)
1326 map)
1327 "Keymap for splash screen buffer.")
1329 ;; These are temporary storage areas for the splash screen display.
1331 (defun fancy-splash-insert (&rest args)
1332 "Insert text into the current buffer, with faces.
1333 Arguments from ARGS should be either strings; functions called
1334 with no args that return a string; pairs `:face FACE', where FACE
1335 is a face specification usable with `put-text-property'; or pairs
1336 `:link LINK' where LINK is a list of arguments to pass to
1337 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1338 specifies the button's label, `action' property and help-echo string.
1339 FACE and LINK can also be functions, which are evaluated to obtain
1340 a face or button specification."
1341 (let ((current-face nil))
1342 (while args
1343 (cond ((eq (car args) :face)
1344 (setq args (cdr args) current-face (car args))
1345 (if (functionp current-face)
1346 (setq current-face (funcall current-face))))
1347 ((eq (car args) :link)
1348 (setq args (cdr args))
1349 (let ((spec (car args)))
1350 (if (functionp spec)
1351 (setq spec (funcall spec)))
1352 (insert-button (car spec)
1353 'face (list 'link current-face)
1354 'action (cadr spec)
1355 'help-echo (concat "mouse-2, RET: "
1356 (or (nth 2 spec)
1357 "Follow this link"))
1358 'follow-link t)))
1359 (t (insert (propertize (let ((it (car args)))
1360 (if (functionp it)
1361 (funcall it)
1362 it))
1363 'face current-face
1364 'help-echo (startup-echo-area-message)))))
1365 (setq args (cdr args)))))
1368 (defun fancy-splash-head ()
1369 "Insert the head part of the splash screen into the current buffer."
1370 (let* ((image-file (cond ((stringp fancy-splash-image)
1371 fancy-splash-image)
1372 ((and (display-color-p)
1373 (image-type-available-p 'xpm))
1374 (if (and (fboundp 'x-display-planes)
1375 (= (funcall 'x-display-planes) 8))
1376 "splash8.xpm"
1377 "splash.xpm"))
1378 (t "splash.pbm")))
1379 (img (create-image image-file))
1380 (image-width (and img (car (image-size img))))
1381 (window-width (window-width (selected-window))))
1382 (when img
1383 (when (> window-width image-width)
1384 ;; Center the image in the window.
1385 (insert (propertize " " 'display
1386 `(space :align-to (+ center (-0.5 . ,img)))))
1388 ;; Change the color of the XPM version of the splash image
1389 ;; so that it is visible with a dark frame background.
1390 (when (and (memq 'xpm img)
1391 (eq (frame-parameter nil 'background-mode) 'dark))
1392 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1394 ;; Insert the image with a help-echo and a link.
1395 (make-button (prog1 (point) (insert-image img)) (point)
1396 'face 'default
1397 'help-echo "mouse-2, RET: Browse http://www.gnu.org/"
1398 'action (lambda (button) (browse-url "http://www.gnu.org/"))
1399 'follow-link t)
1400 (insert "\n\n")))))
1402 (defun fancy-startup-tail (&optional concise)
1403 "Insert the tail part of the splash screen into the current buffer."
1404 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1405 "cyan" "darkblue")))
1406 (unless concise
1407 (fancy-splash-insert
1408 :face 'variable-pitch
1409 "\nTo start... "
1410 :link '("Open a File"
1411 (lambda (button) (call-interactively 'find-file))
1412 "Specify a new file's name, to edit the file")
1414 :link '("Open Home Directory"
1415 (lambda (button) (dired "~"))
1416 "Open your home directory, to operate on its files")
1418 :link '("Customize Startup"
1419 (lambda (button) (customize-group 'initialization))
1420 "Change initialization settings including this screen")
1421 "\n"))
1422 (fancy-splash-insert :face `(variable-pitch (:foreground ,fg))
1423 "\nThis is "
1424 (emacs-version)
1425 "\n"
1426 :face '(variable-pitch (:height 0.5))
1427 emacs-copyright
1428 "\n")
1429 (and auto-save-list-file-prefix
1430 ;; Don't signal an error if the
1431 ;; directory for auto-save-list files
1432 ;; does not yet exist.
1433 (file-directory-p (file-name-directory
1434 auto-save-list-file-prefix))
1435 (directory-files
1436 (file-name-directory auto-save-list-file-prefix)
1438 (concat "\\`"
1439 (regexp-quote (file-name-nondirectory
1440 auto-save-list-file-prefix)))
1442 (fancy-splash-insert :face '(variable-pitch (:foreground "red"))
1443 "\nIf an Emacs session crashed recently, "
1444 "type "
1445 :face '(fixed-pitch :foreground "red")
1446 "Meta-x recover-session RET"
1447 :face '(variable-pitch (:foreground "red"))
1448 "\nto recover"
1449 " the files you were editing."))
1451 (when concise
1452 (fancy-splash-insert
1453 :face 'variable-pitch "\n"
1454 :link '("Dismiss this startup screen"
1455 (lambda (button)
1456 (when startup-screen-inhibit-startup-screen
1457 (customize-set-variable 'inhibit-startup-screen t)
1458 (customize-mark-to-save 'inhibit-startup-screen)
1459 (custom-save-all))
1460 (let ((w (get-buffer-window "*GNU Emacs*")))
1461 (and w (not (one-window-p)) (delete-window w)))
1462 (kill-buffer "*GNU Emacs*")))
1463 " ")
1464 (when (or user-init-file custom-file)
1465 (let ((checked (create-image "\300\300\141\143\067\076\034\030"
1466 'xbm t :width 8 :height 8 :background "grey75"
1467 :foreground "black" :relief -2 :ascent 'center))
1468 (unchecked (create-image (make-string 8 0)
1469 'xbm t :width 8 :height 8 :background "grey75"
1470 :foreground "black" :relief -2 :ascent 'center)))
1471 (insert-button
1472 " " :on-glyph checked :off-glyph unchecked 'checked nil
1473 'display unchecked 'follow-link t
1474 'action (lambda (button)
1475 (if (overlay-get button 'checked)
1476 (progn (overlay-put button 'checked nil)
1477 (overlay-put button 'display (overlay-get button :off-glyph))
1478 (setq startup-screen-inhibit-startup-screen nil))
1479 (overlay-put button 'checked t)
1480 (overlay-put button 'display (overlay-get button :on-glyph))
1481 (setq startup-screen-inhibit-startup-screen t)))))
1482 (fancy-splash-insert :face '(variable-pitch (:height 0.9))
1483 " Never show it again.")))))
1485 (defun exit-splash-screen ()
1486 "Stop displaying the splash screen buffer."
1487 (interactive)
1488 (quit-window t))
1490 (defun fancy-startup-screen (&optional concise)
1491 "Display fancy startup screen.
1492 If CONCISE is non-nil, display a concise version of the
1493 splash screen in another window."
1494 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1495 (with-current-buffer splash-buffer
1496 (let ((inhibit-read-only t))
1497 (erase-buffer)
1498 (setq default-directory command-line-default-directory)
1499 (make-local-variable 'startup-screen-inhibit-startup-screen)
1500 (if pure-space-overflow
1501 (insert pure-space-overflow-message))
1502 (unless concise
1503 (fancy-splash-head))
1504 (dolist (text fancy-startup-text)
1505 (apply #'fancy-splash-insert text)
1506 (insert "\n"))
1507 (skip-chars-backward "\n")
1508 (delete-region (point) (point-max))
1509 (insert "\n")
1510 (fancy-startup-tail concise))
1511 (use-local-map splash-screen-keymap)
1512 (setq tab-width 22
1513 buffer-read-only t)
1514 (set-buffer-modified-p nil)
1515 (if (and view-read-only (not view-mode))
1516 (view-mode-enter nil 'kill-buffer))
1517 (goto-char (point-min))
1518 (forward-line (if concise 2 4)))
1519 (if concise
1520 (progn
1521 (display-buffer splash-buffer)
1522 ;; If the splash screen is in a split window, fit it.
1523 (let ((window (get-buffer-window splash-buffer t)))
1524 (or (null window)
1525 (eq window (selected-window))
1526 (eq window (next-window window))
1527 (fit-window-to-buffer window))))
1528 (switch-to-buffer splash-buffer))))
1530 (defun fancy-about-screen ()
1531 "Display fancy About screen."
1532 (let ((frame (fancy-splash-frame)))
1533 (save-selected-window
1534 (select-frame frame)
1535 (switch-to-buffer "*About GNU Emacs*")
1536 (setq buffer-undo-list t
1537 mode-line-format (propertize "---- %b %-"
1538 'face 'mode-line-buffer-id))
1539 (let ((inhibit-read-only t))
1540 (erase-buffer)
1541 (if pure-space-overflow
1542 (insert pure-space-overflow-message))
1543 (fancy-splash-head)
1544 (dolist (text fancy-about-text)
1545 (apply #'fancy-splash-insert text)
1546 (insert "\n"))
1547 (set-buffer-modified-p nil)
1548 (goto-char (point-min))
1549 (force-mode-line-update))
1550 (use-local-map splash-screen-keymap)
1551 (setq tab-width 22)
1552 (message "%s" (startup-echo-area-message))
1553 (setq buffer-read-only t)
1554 (goto-char (point-min))
1555 (forward-line 3))))
1557 (defun fancy-splash-frame ()
1558 "Return the frame to use for the fancy splash screen.
1559 Returning non-nil does not mean we should necessarily
1560 use the fancy splash screen, but if we do use it,
1561 we put it on this frame."
1562 (let (chosen-frame)
1563 (dolist (frame (append (frame-list) (list (selected-frame))))
1564 (if (and (frame-visible-p frame)
1565 (not (window-minibuffer-p (frame-selected-window frame))))
1566 (setq chosen-frame frame)))
1567 chosen-frame))
1569 (defun use-fancy-splash-screens-p ()
1570 "Return t if fancy splash screens should be used."
1571 (when (and (display-graphic-p)
1572 (or (and (display-color-p)
1573 (image-type-available-p 'xpm))
1574 (image-type-available-p 'pbm)))
1575 (let ((frame (fancy-splash-frame)))
1576 (when frame
1577 (let* ((img (create-image (or fancy-splash-image
1578 (if (and (display-color-p)
1579 (image-type-available-p 'xpm))
1580 "splash.xpm" "splash.pbm"))))
1581 (image-height (and img (cdr (image-size img nil frame))))
1582 ;; We test frame-height so that, if the frame is split
1583 ;; by displaying a warning, that doesn't cause the normal
1584 ;; splash screen to be used.
1585 (frame-height (1- (frame-height frame))))
1586 (> frame-height (+ image-height 19)))))))
1589 (defun normal-splash-screen (&optional startup concise)
1590 "Display non-graphic splash screen.
1591 If optional argument STARTUP is non-nil, display the startup screen
1592 after Emacs starts. If STARTUP is nil, display the About screen.
1593 If CONCISE is non-nil, display a concise version of the
1594 splash screen in another window."
1595 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1596 (with-current-buffer splash-buffer
1597 (setq buffer-read-only nil)
1598 (erase-buffer)
1599 (setq default-directory command-line-default-directory)
1600 (set (make-local-variable 'tab-width) 8)
1601 (if (not startup)
1602 (set (make-local-variable 'mode-line-format)
1603 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1605 (if pure-space-overflow
1606 (insert pure-space-overflow-message))
1608 ;; The convention for this piece of code is that
1609 ;; each piece of output starts with one or two newlines
1610 ;; and does not end with any newlines.
1611 (insert (if startup "Welcome to GNU Emacs" "This is GNU Emacs"))
1612 (insert
1613 (if (eq system-type 'gnu/linux)
1614 ", one component of the GNU/Linux operating system.\n"
1615 ", a part of the GNU operating system.\n"))
1617 (if startup
1618 (if (display-mouse-p)
1619 ;; The user can use the mouse to activate menus
1620 ;; so give help in terms of menu items.
1621 (normal-mouse-startup-screen)
1623 ;; No mouse menus, so give help using kbd commands.
1624 (normal-no-mouse-startup-screen))
1626 (normal-about-screen))
1628 ;; The rest of the startup screen is the same on all
1629 ;; kinds of terminals.
1631 ;; Give information on recovering, if there was a crash.
1632 (and startup
1633 auto-save-list-file-prefix
1634 ;; Don't signal an error if the
1635 ;; directory for auto-save-list files
1636 ;; does not yet exist.
1637 (file-directory-p (file-name-directory
1638 auto-save-list-file-prefix))
1639 (directory-files
1640 (file-name-directory auto-save-list-file-prefix)
1642 (concat "\\`"
1643 (regexp-quote (file-name-nondirectory
1644 auto-save-list-file-prefix)))
1646 (insert "\n\nIf an Emacs session crashed recently, "
1647 "type Meta-x recover-session RET\nto recover"
1648 " the files you were editing.\n"))
1650 (use-local-map splash-screen-keymap)
1652 ;; Display the input that we set up in the buffer.
1653 (set-buffer-modified-p nil)
1654 (setq buffer-read-only t)
1655 (if (and view-read-only (not view-mode))
1656 (view-mode-enter nil 'kill-buffer))
1657 (if startup (rename-buffer "*GNU Emacs*" t))
1658 (goto-char (point-min)))
1659 (if concise
1660 (display-buffer splash-buffer)
1661 (switch-to-buffer splash-buffer))))
1663 (defun normal-mouse-startup-screen ()
1664 ;; The user can use the mouse to activate menus
1665 ;; so give help in terms of menu items.
1666 (insert "\
1667 To follow a link, click Mouse-1 on it, or move to it and type RET.
1668 To quit a partially entered command, type Control-g.\n")
1670 (insert "\nImportant Help menu items:\n")
1671 (insert-button "Emacs Tutorial"
1672 'action (lambda (button) (help-with-tutorial))
1673 'follow-link t)
1674 (insert "\t\tLearn basic Emacs keystroke commands\n")
1675 (insert-button "Read the Emacs Manual"
1676 'action (lambda (button) (info-emacs-manual))
1677 'follow-link t)
1678 (insert "\tView the Emacs manual using Info\n")
1679 (insert-button "\(Non)Warranty"
1680 'action (lambda (button) (describe-no-warranty))
1681 'follow-link t)
1682 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1683 (insert-button "Copying Conditions"
1684 'action (lambda (button) (describe-copying))
1685 'follow-link t)
1686 (insert "\tConditions for redistributing and changing Emacs\n")
1687 (insert-button "More Manuals / Ordering Manuals"
1688 'action (lambda (button) (view-order-manuals))
1689 'follow-link t)
1690 (insert " How to order printed manuals from the FSF\n")
1692 (insert "\nUseful tasks:\n")
1693 (insert-button "Visit New File"
1694 'action (lambda (button) (call-interactively 'find-file))
1695 'follow-link t)
1696 (insert "\t\tSpecify a new file's name, to edit the file\n")
1697 (insert-button "Open Home Directory"
1698 'action (lambda (button) (dired "~"))
1699 'follow-link t)
1700 (insert "\tOpen your home directory, to operate on its files\n")
1701 (insert-button "Customize Startup"
1702 'action (lambda (button) (customize-group 'initialization))
1703 'follow-link t)
1704 (insert "\tChange initialization settings including this screen\n")
1706 (insert "\n" (emacs-version)
1707 "\n" emacs-copyright))
1709 ;; No mouse menus, so give help using kbd commands.
1710 (defun normal-no-mouse-startup-screen ()
1712 ;; If keys have their default meanings,
1713 ;; use precomputed string to save lots of time.
1714 (if (and (eq (key-binding "\C-h") 'help-command)
1715 (eq (key-binding "\C-xu") 'advertised-undo)
1716 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
1717 (eq (key-binding "\C-ht") 'help-with-tutorial)
1718 (eq (key-binding "\C-hi") 'info)
1719 (eq (key-binding "\C-hr") 'info-emacs-manual)
1720 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1721 (progn
1722 (insert "
1723 Get help\t C-h (Hold down CTRL and press h)
1725 (insert-button "Emacs manual"
1726 'action (lambda (button) (info-emacs-manual))
1727 'follow-link t)
1728 (insert " C-h r\t")
1729 (insert-button "Browse manuals"
1730 'action (lambda (button) (Info-directory))
1731 'follow-link t)
1732 (insert "\t C-h i
1734 (insert-button "Emacs tutorial"
1735 'action (lambda (button) (help-with-tutorial))
1736 'follow-link t)
1737 (insert " C-h t\tUndo changes\t C-x u
1739 (insert-button "Buy manuals"
1740 'action (lambda (button) (view-order-manuals))
1741 'follow-link t)
1742 (insert "\t C-h C-m\tExit Emacs\t C-x C-c"))
1744 (insert (format "
1745 Get help\t %s
1747 (let ((where (where-is-internal
1748 'help-command nil t)))
1749 (if where
1750 (key-description where)
1751 "M-x help"))))
1752 (insert-button "Emacs manual"
1753 'action (lambda (button) (info-emacs-manual))
1754 'follow-link t)
1755 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1756 (insert-button "Browse manuals"
1757 'action (lambda (button) (Info-directory))
1758 'follow-link t)
1759 (insert (substitute-command-keys "\t \\[info]
1761 (insert-button "Emacs tutorial"
1762 'action (lambda (button) (help-with-tutorial))
1763 'follow-link t)
1764 (insert (substitute-command-keys
1765 "\t \\[help-with-tutorial]\tUndo changes\t \\[advertised-undo]
1767 (insert-button "Buy manuals"
1768 'action (lambda (button) (view-order-manuals))
1769 'follow-link t)
1770 (insert (substitute-command-keys
1771 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1773 ;; Say how to use the menu bar with the keyboard.
1774 (insert "\n")
1775 (insert-button "Activate menubar"
1776 'action (lambda (button) (tmm-menubar))
1777 'follow-link t)
1778 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1779 (eq (key-binding [f10]) 'tmm-menubar))
1780 (insert " F10 or ESC ` or M-`")
1781 (insert (substitute-command-keys " \\[tmm-menubar]")))
1783 ;; Many users seem to have problems with these.
1784 (insert "
1785 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1786 If you have no Meta key, you may instead type ESC followed by the character.)")
1788 ;; Insert links to useful tasks
1789 (insert "\nUseful tasks:\n")
1791 (insert-button "Visit New File"
1792 'action (lambda (button) (call-interactively 'find-file))
1793 'follow-link t)
1794 (insert "\t\t\t")
1795 (insert-button "Open Home Directory"
1796 'action (lambda (button) (dired "~"))
1797 'follow-link t)
1798 (insert "\n")
1800 (insert-button "Customize Startup"
1801 'action (lambda (button) (customize-group 'initialization))
1802 'follow-link t)
1803 (insert "\t\t")
1804 (insert-button "Open *scratch* buffer"
1805 'action (lambda (button) (switch-to-buffer
1806 (get-buffer-create "*scratch*")))
1807 'follow-link t)
1808 (insert "\n")
1809 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1811 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1812 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1813 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1814 (progn
1815 (insert
1817 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1818 (insert-button "full details"
1819 'action (lambda (button) (describe-no-warranty))
1820 'follow-link t)
1821 (insert ".
1822 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1823 of Emacs and modify it; type C-h C-c to see ")
1824 (insert-button "the conditions"
1825 'action (lambda (button) (describe-copying))
1826 'follow-link t)
1827 (insert ".
1828 Type C-h C-d for information on ")
1829 (insert-button "getting the latest version"
1830 'action (lambda (button) (describe-distribution))
1831 'follow-link t)
1832 (insert "."))
1833 (insert (substitute-command-keys
1835 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1836 (insert-button "full details"
1837 'action (lambda (button) (describe-no-warranty))
1838 'follow-link t)
1839 (insert (substitute-command-keys ".
1840 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1841 of Emacs and modify it; type \\[describe-copying] to see "))
1842 (insert-button "the conditions"
1843 'action (lambda (button) (describe-copying))
1844 'follow-link t)
1845 (insert (substitute-command-keys".
1846 Type \\[describe-distribution] for information on "))
1847 (insert-button "getting the latest version"
1848 'action (lambda (button) (describe-distribution))
1849 'follow-link t)
1850 (insert ".")))
1852 (defun normal-about-screen ()
1853 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1855 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1857 (insert-button "Authors"
1858 'action
1859 (lambda (button)
1860 (view-file (expand-file-name "AUTHORS" data-directory))
1861 (goto-char (point-min)))
1862 'follow-link t)
1863 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1865 (insert-button "Contributing"
1866 'action
1867 (lambda (button)
1868 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1869 (goto-char (point-min)))
1870 'follow-link t)
1871 (insert "\tHow to contribute improvements to Emacs\n\n")
1873 (insert-button "GNU and Freedom"
1874 'action (lambda (button) (describe-gnu-project))
1875 'follow-link t)
1876 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
1878 (insert-button "Absence of Warranty"
1879 'action (lambda (button) (describe-no-warranty))
1880 'follow-link t)
1881 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1883 (insert-button "Copying Conditions"
1884 'action (lambda (button) (describe-copying))
1885 'follow-link t)
1886 (insert "\tConditions for redistributing and changing Emacs\n")
1888 (insert-button "Getting New Versions"
1889 'action (lambda (button) (describe-distribution))
1890 'follow-link t)
1891 (insert "\tHow to get the latest version of GNU Emacs\n")
1893 (insert-button "More Manuals / Ordering Manuals"
1894 'action (lambda (button) (view-order-manuals))
1895 'follow-link t)
1896 (insert "\tBuying printed manuals from the FSF\n"))
1898 (defun startup-echo-area-message ()
1899 (if (eq (key-binding "\C-h\C-a") 'about-emacs)
1900 "For information about GNU Emacs and the GNU system, type C-h C-a."
1901 (substitute-command-keys
1902 "For information about GNU Emacs and the GNU system, type \
1903 \\[about-emacs].")))
1906 (defun display-startup-echo-area-message ()
1907 (let ((resize-mini-windows t))
1908 (or noninteractive ;(input-pending-p) init-file-had-error
1909 ;; t if the init file says to inhibit the echo area startup message.
1910 (and inhibit-startup-echo-area-message
1911 user-init-file
1912 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1913 (equal inhibit-startup-echo-area-message
1914 (if (equal init-file-user "")
1915 (user-login-name)
1916 init-file-user)))
1917 ;; Wasn't set with custom; see if .emacs has a setq.
1918 (let ((buffer (get-buffer-create " *temp*")))
1919 (prog1
1920 (condition-case nil
1921 (save-excursion
1922 (set-buffer buffer)
1923 (insert-file-contents user-init-file)
1924 (re-search-forward
1925 (concat
1926 "([ \t\n]*setq[ \t\n]+"
1927 "inhibit-startup-echo-area-message[ \t\n]+"
1928 (regexp-quote
1929 (prin1-to-string
1930 (if (equal init-file-user "")
1931 (user-login-name)
1932 init-file-user)))
1933 "[ \t\n]*)")
1934 nil t))
1935 (error nil))
1936 (kill-buffer buffer)))))
1937 (message "%s" (startup-echo-area-message)))))
1939 (defun display-startup-screen (&optional concise)
1940 "Display startup screen according to display.
1941 A fancy display is used on graphic displays, normal otherwise.
1943 If CONCISE is non-nil, display a concise version of the startup
1944 screen."
1945 ;; Prevent recursive calls from server-process-filter.
1946 (if (not (get-buffer "*GNU Emacs*"))
1947 (if (use-fancy-splash-screens-p)
1948 (fancy-startup-screen concise)
1949 (normal-splash-screen t concise))))
1951 (defun display-about-screen ()
1952 "Display the *About GNU Emacs* buffer.
1953 A fancy display is used on graphic displays, normal otherwise."
1954 (interactive)
1955 (if (use-fancy-splash-screens-p)
1956 (fancy-about-screen)
1957 (normal-splash-screen nil)))
1959 (defalias 'about-emacs 'display-about-screen)
1960 (defalias 'display-splash-screen 'display-startup-screen)
1962 (defun command-line-1 (command-line-args-left)
1963 (display-startup-echo-area-message)
1965 ;; Delay 2 seconds after an init file error message
1966 ;; was displayed, so user can read it.
1967 (when init-file-had-error
1968 (sit-for 2))
1970 (when (and pure-space-overflow
1971 (not noninteractive))
1972 (display-warning
1973 'initialization
1974 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1975 :warning))
1977 (let ((file-count 0)
1978 first-file-buffer)
1979 (when command-line-args-left
1980 ;; We have command args; process them.
1981 (let ((dir command-line-default-directory)
1983 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1984 ;; if foo is intended to be found in DIR.
1986 ;; ;; The directories listed in --directory/-L options will *appear*
1987 ;; ;; at the front of `load-path' in the order they appear on the
1988 ;; ;; command-line. We cannot do this by *placing* them at the front
1989 ;; ;; in the order they appear, so we need this variable to hold them,
1990 ;; ;; temporarily.
1991 ;; extra-load-path
1993 ;; To DTRT we keep track of the splice point and modify `load-path'
1994 ;; straight away upon any --directory/-L option.
1995 splice
1996 just-files ;; t if this follows the magic -- option.
1997 ;; This includes our standard options' long versions
1998 ;; and long versions of what's on command-switch-alist.
1999 (longopts
2000 (append '(("--funcall") ("--load") ("--insert") ("--kill")
2001 ("--directory") ("--eval") ("--execute") ("--no-splash")
2002 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
2003 (mapcar (lambda (elt)
2004 (list (concat "-" (car elt))))
2005 command-switch-alist)))
2006 (line 0)
2007 (column 0))
2009 ;; Add the long X options to longopts.
2010 (dolist (tem command-line-x-option-alist)
2011 (if (string-match "^--" (car tem))
2012 (push (list (car tem)) longopts)))
2014 ;; Loop, processing options.
2015 (while command-line-args-left
2016 (let* ((argi (car command-line-args-left))
2017 (orig-argi argi)
2018 argval completion)
2019 (setq command-line-args-left (cdr command-line-args-left))
2021 ;; Do preliminary decoding of the option.
2022 (if just-files
2023 ;; After --, don't look for options; treat all args as files.
2024 (setq argi "")
2025 ;; Convert long options to ordinary options
2026 ;; and separate out an attached option argument into argval.
2027 (when (string-match "^\\(--[^=]*\\)=" argi)
2028 (setq argval (substring argi (match-end 0))
2029 argi (match-string 1 argi)))
2030 (if (equal argi "--")
2031 (setq completion nil)
2032 (setq completion (try-completion argi longopts)))
2033 (if (eq completion t)
2034 (setq argi (substring argi 1))
2035 (if (stringp completion)
2036 (let ((elt (assoc completion longopts)))
2037 (or elt
2038 (error "Option `%s' is ambiguous" argi))
2039 (setq argi (substring (car elt) 1)))
2040 (setq argval nil
2041 argi orig-argi))))
2043 ;; Execute the option.
2044 (cond ((setq tem (assoc argi command-switch-alist))
2045 (if argval
2046 (let ((command-line-args-left
2047 (cons argval command-line-args-left)))
2048 (funcall (cdr tem) argi))
2049 (funcall (cdr tem) argi)))
2051 ((equal argi "-no-splash")
2052 (setq inhibit-startup-screen t))
2054 ((member argi '("-f" ; what the manual claims
2055 "-funcall"
2056 "-e")) ; what the source used to say
2057 (setq inhibit-startup-screen t)
2058 (setq tem (intern (or argval (pop command-line-args-left))))
2059 (if (commandp tem)
2060 (command-execute tem)
2061 (funcall tem)))
2063 ((member argi '("-eval" "-execute"))
2064 (setq inhibit-startup-screen t)
2065 (eval (read (or argval (pop command-line-args-left)))))
2067 ((member argi '("-L" "-directory"))
2068 (setq tem (expand-file-name
2069 (command-line-normalize-file-name
2070 (or argval (pop command-line-args-left)))))
2071 (cond (splice (setcdr splice (cons tem (cdr splice)))
2072 (setq splice (cdr splice)))
2073 (t (setq load-path (cons tem load-path)
2074 splice load-path))))
2076 ((member argi '("-l" "-load"))
2077 (let* ((file (command-line-normalize-file-name
2078 (or argval (pop command-line-args-left))))
2079 ;; Take file from default dir if it exists there;
2080 ;; otherwise let `load' search for it.
2081 (file-ex (expand-file-name file)))
2082 (when (file-exists-p file-ex)
2083 (setq file file-ex))
2084 (load file nil t)))
2086 ;; This is used to handle -script. It's not clear
2087 ;; we need to document it (it is totally internal).
2088 ((member argi '("-scriptload"))
2089 (let* ((file (command-line-normalize-file-name
2090 (or argval (pop command-line-args-left))))
2091 ;; Take file from default dir.
2092 (file-ex (expand-file-name file)))
2093 (load file-ex nil t t)))
2095 ((equal argi "-insert")
2096 (setq inhibit-startup-screen t)
2097 (setq tem (or argval (pop command-line-args-left)))
2098 (or (stringp tem)
2099 (error "File name omitted from `-insert' option"))
2100 (insert-file-contents (command-line-normalize-file-name tem)))
2102 ((equal argi "-kill")
2103 (kill-emacs t))
2105 ;; This is for when they use --no-desktop with -q, or
2106 ;; don't load Desktop in their .emacs. If desktop.el
2107 ;; _is_ loaded, it will handle this switch, and we
2108 ;; won't see it by the time we get here.
2109 ((equal argi "-no-desktop")
2110 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2112 ((string-match "^\\+[0-9]+\\'" argi)
2113 (setq line (string-to-number argi)))
2115 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2116 (setq line (string-to-number (match-string 1 argi))
2117 column (string-to-number (match-string 2 argi))))
2119 ((setq tem (assoc argi command-line-x-option-alist))
2120 ;; Ignore X-windows options and their args if not using X.
2121 (setq command-line-args-left
2122 (nthcdr (nth 1 tem) command-line-args-left)))
2124 ((member argi '("-find-file" "-file" "-visit"))
2125 (setq inhibit-startup-screen t)
2126 ;; An explicit option to specify visiting a file.
2127 (setq tem (or argval (pop command-line-args-left)))
2128 (unless (stringp tem)
2129 (error "File name omitted from `%s' option" argi))
2130 (setq file-count (1+ file-count))
2131 (let ((file (expand-file-name
2132 (command-line-normalize-file-name tem) dir)))
2133 (if (= file-count 1)
2134 (setq first-file-buffer (find-file file))
2135 (find-file-other-window file)))
2136 (or (zerop line)
2137 (goto-line line))
2138 (setq line 0)
2139 (unless (< column 1)
2140 (move-to-column (1- column)))
2141 (setq column 0))
2143 ((equal argi "--")
2144 (setq just-files t))
2146 ;; We have almost exhausted our options. See if the
2147 ;; user has made any other command-line options available
2148 (let ((hooks command-line-functions)
2149 (did-hook nil))
2150 (while (and hooks
2151 (not (setq did-hook (funcall (car hooks)))))
2152 (setq hooks (cdr hooks)))
2153 (if (not did-hook)
2154 ;; Presume that the argument is a file name.
2155 (progn
2156 (if (string-match "\\`-" argi)
2157 (error "Unknown option `%s'" argi))
2158 (unless initial-window-system
2159 (setq inhibit-startup-screen t))
2160 (setq file-count (1+ file-count))
2161 (let ((file
2162 (expand-file-name
2163 (command-line-normalize-file-name orig-argi)
2164 dir)))
2165 (cond ((= file-count 1)
2166 (setq first-file-buffer (find-file file)))
2167 (inhibit-startup-screen
2168 (find-file-other-window file))
2169 (t (find-file file))))
2170 (or (zerop line)
2171 (goto-line line))
2172 (setq line 0)
2173 (unless (< column 1)
2174 (move-to-column (1- column)))
2175 (setq column 0))))))
2176 ;; In unusual circumstances, the execution of Lisp code due
2177 ;; to command-line options can cause the last visible frame
2178 ;; to be deleted. In this case, kill emacs to avoid an
2179 ;; abort later.
2180 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2182 (when initial-buffer-choice
2183 (cond ((eq initial-buffer-choice t)
2184 (switch-to-buffer (get-buffer-create "*scratch*")))
2185 ((stringp initial-buffer-choice)
2186 (find-file initial-buffer-choice))))
2188 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2189 (and initial-scratch-message
2190 (get-buffer "*scratch*")
2191 (with-current-buffer "*scratch*"
2192 (when (zerop (buffer-size))
2193 (insert initial-scratch-message)
2194 (set-buffer-modified-p nil))))
2196 (if (or inhibit-startup-screen
2197 initial-buffer-choice
2198 noninteractive
2199 emacs-quick-startup)
2201 ;; Not displaying a startup screen. If 3 or more files
2202 ;; visited, and not all visible, show user what they all are.
2203 (and (> file-count 2)
2204 (not noninteractive)
2205 (not inhibit-startup-buffer-menu)
2206 (or (get-buffer-window first-file-buffer)
2207 (list-buffers)))
2209 ;; Display a startup screen, after some preparations.
2211 ;; If there are no switches to process, we might as well
2212 ;; run this hook now, and there may be some need to do it
2213 ;; before doing any output.
2214 (run-hooks 'emacs-startup-hook)
2215 (and term-setup-hook
2216 (run-hooks 'term-setup-hook))
2217 (setq inhibit-startup-hooks t)
2219 ;; It's important to notice the user settings before we
2220 ;; display the startup message; otherwise, the settings
2221 ;; won't take effect until the user gives the first
2222 ;; keystroke, and that's distracting.
2223 (when (fboundp 'frame-notice-user-settings)
2224 (frame-notice-user-settings))
2226 ;; If there are no switches to process, we might as well
2227 ;; run this hook now, and there may be some need to do it
2228 ;; before doing any output.
2229 (when window-setup-hook
2230 (run-hooks 'window-setup-hook)
2231 ;; Don't let the hook be run twice.
2232 (setq window-setup-hook nil))
2234 ;; ;; Do this now to avoid an annoying delay if the user
2235 ;; ;; clicks the menu bar during the sit-for.
2236 ;; (when (display-popup-menus-p)
2237 ;; (precompute-menubar-bindings))
2238 ;; (with-no-warnings
2239 ;; (setq menubar-bindings-done t))
2241 (if (> file-count 0)
2242 (display-startup-screen t)
2243 (display-startup-screen nil)))))
2245 (defun command-line-normalize-file-name (file)
2246 "Collapse multiple slashes to one, to handle non-Emacs file names."
2247 (save-match-data
2248 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2249 ;; That is significant on some systems.
2250 ;; However, /// at the beginning is supposed to mean just /, not //.
2251 (if (string-match "^///+" file)
2252 (setq file (replace-match "/" t t file)))
2253 (while (string-match "//+" file 1)
2254 (setq file (replace-match "/" t t file)))
2255 file))
2257 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
2258 ;;; startup.el ends here