Merge from emacs--rel--22
[emacs.git] / lisp / startup.el
blobc82a627e2087175f6394e3123907596cfd36bde0
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 (let ((dir default-directory))
400 (with-current-buffer "*Messages*"
401 ;; Make it easy to do like "tail -f".
402 (set (make-local-variable 'window-point-insertion-type) t)
403 ;; Give *Messages* the same default-directory as *scratch*,
404 ;; just to keep things predictable.
405 (setq default-directory dir)))
406 ;; `user-full-name' is now known; reset its standard-value here.
407 (put 'user-full-name 'standard-value
408 (list (default-value 'user-full-name)))
409 ;; For root, preserve owner and group when editing files.
410 (if (equal (user-uid) 0)
411 (setq backup-by-copying-when-mismatch t))
412 ;; Look in each dir in load-path for a subdirs.el file.
413 ;; If we find one, load it, which will add the appropriate subdirs
414 ;; of that dir into load-path,
415 ;; Look for a leim-list.el file too. Loading it will register
416 ;; available input methods.
417 (let ((tail load-path) dir)
418 (while tail
419 (setq dir (car tail))
420 (let ((default-directory dir))
421 (load (expand-file-name "subdirs.el") t t t))
422 (let ((default-directory dir))
423 (load (expand-file-name "leim-list.el") t t t))
424 ;; We don't use a dolist loop and we put this "setq-cdr" command at
425 ;; the end, because the subdirs.el files may add elements to the end
426 ;; of load-path and we want to take it into account.
427 (setq tail (cdr tail))))
428 (unless (eq system-type 'vax-vms)
429 ;; If the PWD environment variable isn't accurate, delete it.
430 (let ((pwd (getenv "PWD")))
431 (and (stringp pwd)
432 ;; Use FOO/., so that if FOO is a symlink, file-attributes
433 ;; describes the directory linked to, not FOO itself.
434 (or (equal (file-attributes
435 (concat (file-name-as-directory pwd) "."))
436 (file-attributes
437 (concat (file-name-as-directory default-directory)
438 ".")))
439 (setq process-environment
440 (delete (concat "PWD=" pwd)
441 process-environment))))))
442 (setq default-directory (abbreviate-file-name default-directory))
443 (let ((menubar-bindings-done nil))
444 (unwind-protect
445 (command-line)
446 ;; Do this again, in case .emacs defined more abbreviations.
447 (setq default-directory (abbreviate-file-name default-directory))
448 ;; Specify the file for recording all the auto save files of this session.
449 ;; This is used by recover-session.
450 (or auto-save-list-file-name
451 (and auto-save-list-file-prefix
452 (setq auto-save-list-file-name
453 ;; Under MS-DOS our PID is almost always reused between
454 ;; Emacs invocations. We need something more unique.
455 (cond ((eq system-type 'ms-dos)
456 ;; We are going to access the auto-save
457 ;; directory, so make sure it exists.
458 (make-directory
459 (file-name-directory auto-save-list-file-prefix)
461 (concat
462 (make-temp-name
463 (expand-file-name
464 auto-save-list-file-prefix))
465 "~"))
467 (expand-file-name
468 (format "%s%d-%s~"
469 auto-save-list-file-prefix
470 (emacs-pid)
471 (system-name))))))))
472 (unless inhibit-startup-hooks
473 (run-hooks 'emacs-startup-hook)
474 (and term-setup-hook
475 (run-hooks 'term-setup-hook)))
477 ;; Don't do this if we failed to create the initial frame,
478 ;; for instance due to a dense colormap.
479 (when (or frame-initial-frame
480 ;; If frame-initial-frame has no meaning, do this anyway.
481 (not (and initial-window-system
482 (not noninteractive)
483 (not (eq initial-window-system 'pc)))))
484 ;; Modify the initial frame based on what .emacs puts into
485 ;; ...-frame-alist.
486 (if (fboundp 'frame-notice-user-settings)
487 (frame-notice-user-settings))
488 ;; Set the faces for the initial background mode even if
489 ;; frame-notice-user-settings didn't (such as on a tty).
490 ;; frame-set-background-mode is idempotent, so it won't
491 ;; cause any harm if it's already been done.
492 (if (fboundp 'frame-set-background-mode)
493 (frame-set-background-mode (selected-frame))))
495 ;; Now we know the user's default font, so add it to the menu.
496 (if (fboundp 'font-menu-add-default)
497 (font-menu-add-default))
498 (and window-setup-hook
499 (run-hooks 'window-setup-hook))
500 (or menubar-bindings-done
501 (if (display-popup-menus-p)
502 (precompute-menubar-bindings)))))
503 ;; Subprocesses of Emacs do not have direct access to the terminal, so
504 ;; unless told otherwise they should only assume a dumb terminal.
505 ;; We are careful to do it late (after term-setup-hook), although the
506 ;; new multi-tty code does not use $TERM any more there anyway.
507 (setenv "TERM" "dumb")
508 ;; Remove DISPLAY from the process-environment as well. This allows
509 ;; `callproc.c' to give it a useful adaptive default which is either
510 ;; the value of the `display' frame-parameter or the DISPLAY value
511 ;; from initial-environment.
512 (let ((display (frame-parameter nil 'display)))
513 ;; Be careful which DISPLAY to remove from process-environment: follow
514 ;; the logic of `callproc.c'.
515 (if (stringp display) (setq display (concat "DISPLAY=" display))
516 (dolist (varval initial-environment)
517 (if (string-match "\\`DISPLAY=" varval)
518 (setq display varval))))
519 (when display
520 (delete display process-environment)))))
522 ;; Precompute the keyboard equivalents in the menu bar items.
523 (defun precompute-menubar-bindings ()
524 (let ((submap (lookup-key global-map [menu-bar])))
525 (while submap
526 (and (consp (car submap))
527 (symbolp (car (car submap)))
528 (stringp (car-safe (cdr (car submap))))
529 (keymapp (cdr (cdr (car submap))))
530 (progn
531 (x-popup-menu nil (cdr (cdr (car submap))))
532 (if purify-flag
533 (garbage-collect))))
534 (setq submap (cdr submap))))
535 (setq define-key-rebound-commands t))
537 ;; Command-line options supported by tty's:
538 (defconst tty-long-option-alist
539 '(("--name" . "-name")
540 ("--title" . "-T")
541 ("--reverse-video" . "-reverse")
542 ("--foreground-color" . "-fg")
543 ("--background-color" . "-bg")
544 ("--color" . "-color")))
546 (defconst tool-bar-images-pixel-height 24
547 "Height in pixels of images in the tool bar.")
549 (defvar tool-bar-originally-present nil
550 "Non-nil if tool-bars are present before user and site init files are read.")
552 (defvar handle-args-function-alist '((nil . tty-handle-args))
553 "Functions for processing window-system dependent command-line arguments.
554 Window system startup files should add their own function to this
555 alist, which should parse the command line arguments. Those
556 pertaining to the window system should be processed and removed
557 from the returned command line.")
559 (defvar window-system-initialization-alist '((nil . ignore))
560 "Alist of window-system initialization functions.
561 Window-system startup files should add their own initialization
562 function to this list. The function should take no arguments,
563 and initialize the window system environment to prepare for
564 opening the first frame (e.g. open a connection to an X server).")
566 ;; Handle the X-like command-line arguments "-fg", "-bg", "-name", etc.
567 (defun tty-handle-args (args)
568 (let (rest)
569 (message "%S" args)
570 (while (and args
571 (not (equal (car args) "--")))
572 (let* ((argi (pop args))
573 (orig-argi argi)
574 argval completion)
575 ;; Check for long options with attached arguments
576 ;; and separate out the attached option argument into argval.
577 (when (string-match "^\\(--[^=]*\\)=" argi)
578 (setq argval (substring argi (match-end 0))
579 argi (match-string 1 argi)))
580 (when (string-match "^--" argi)
581 (setq completion (try-completion argi tty-long-option-alist))
582 (if (eq completion t)
583 ;; Exact match for long option.
584 (setq argi (cdr (assoc argi tty-long-option-alist)))
585 (if (stringp completion)
586 (let ((elt (assoc completion tty-long-option-alist)))
587 ;; Check for abbreviated long option.
588 (or elt
589 (error "Option `%s' is ambiguous" argi))
590 (setq argi (cdr elt)))
591 ;; Check for a short option.
592 (setq argval nil
593 argi orig-argi))))
594 (cond ((member argi '("-fg" "-foreground"))
595 (push (cons 'foreground-color (or argval (pop args)))
596 default-frame-alist))
597 ((member argi '("-bg" "-background"))
598 (push (cons 'background-color (or argval (pop args)))
599 default-frame-alist))
600 ((member argi '("-T" "-name"))
601 (unless argval (setq argval (pop args)))
602 (push (cons 'title
603 (if (stringp argval)
604 argval
605 (let ((case-fold-search t)
607 (setq argval (invocation-name))
609 ;; Change any . or * characters in name to
610 ;; hyphens, so as to emulate behavior on X.
611 (while
612 (setq i (string-match "[.*]" argval))
613 (aset argval i ?-))
614 argval)))
615 default-frame-alist))
616 ((member argi '("-r" "-rv" "-reverse"))
617 (push '(reverse . t)
618 default-frame-alist))
619 ((equal argi "-color")
620 (unless argval (setq argval 8)) ; default --color means 8 ANSI colors
621 (push (cons 'tty-color-mode
622 (cond
623 ((numberp argval) argval)
624 ((string-match "-?[0-9]+" argval)
625 (string-to-number argval))
626 (t (intern argval))))
627 default-frame-alist))
629 (push argi rest)))))
630 (nreverse rest)))
632 (declare-function x-get-resource "frame.c"
633 (attribute class &optional component subclass))
634 (declare-function tool-bar-mode "tool-bar" (&optional arg))
636 (defun command-line ()
637 (setq before-init-time (current-time)
638 command-line-default-directory default-directory)
640 ;; Choose a reasonable location for temporary files.
641 (custom-reevaluate-setting 'temporary-file-directory)
642 (custom-reevaluate-setting 'small-temporary-file-directory)
643 (custom-reevaluate-setting 'auto-save-file-name-transforms)
645 ;; See if we should import version-control from the environment variable.
646 (let ((vc (getenv "VERSION_CONTROL")))
647 (cond ((eq vc nil)) ;don't do anything if not set
648 ((member vc '("t" "numbered"))
649 (setq version-control t))
650 ((member vc '("nil" "existing"))
651 (setq version-control nil))
652 ((member vc '("never" "simple"))
653 (setq version-control 'never))))
655 ;;! This has been commented out; I currently find the behavior when
656 ;;! split-window-keep-point is nil disturbing, but if I can get used
657 ;;! to it, then it would be better to eliminate the option.
658 ;;! ;; Choose a good default value for split-window-keep-point.
659 ;;! (setq split-window-keep-point (> baud-rate 2400))
661 ;; Set the default strings to display in mode line for
662 ;; end-of-line formats that aren't native to this platform.
663 (cond
664 ((memq system-type '(ms-dos windows-nt emx))
665 (setq eol-mnemonic-unix "(Unix)"
666 eol-mnemonic-mac "(Mac)"))
667 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
668 ;; abbreviated strings `/' and `:' set in coding.c for them.
669 ((eq system-type 'macos)
670 (setq eol-mnemonic-dos "(DOS)"))
671 (t ; this is for Unix/GNU/Linux systems
672 (setq eol-mnemonic-dos "(DOS)"
673 eol-mnemonic-mac "(Mac)")))
675 ;; Make sure window system's init file was loaded in loadup.el if using a window system.
676 (condition-case error
677 (unless noninteractive
678 (if (and initial-window-system
679 (not (featurep
680 (intern (concat (symbol-name initial-window-system) "-win")))))
681 (error "Unsupported window system `%s'" initial-window-system))
682 ;; Process window-system specific command line parameters.
683 (setq command-line-args
684 (funcall (or (cdr (assq initial-window-system handle-args-function-alist))
685 (error "Unsupported window system `%s'" initial-window-system))
686 command-line-args))
687 ;; Initialize the window system. (Open connection, etc.)
688 (funcall (or (cdr (assq initial-window-system window-system-initialization-alist))
689 (error "Unsupported window system `%s'" initial-window-system))))
690 ;; If there was an error, print the error message and exit.
691 (error
692 (princ
693 (if (eq (car error) 'error)
694 (apply 'concat (cdr error))
695 (if (memq 'file-error (get (car error) 'error-conditions))
696 (format "%s: %s"
697 (nth 1 error)
698 (mapconcat (lambda (obj) (prin1-to-string obj t))
699 (cdr (cdr error)) ", "))
700 (format "%s: %s"
701 (get (car error) 'error-message)
702 (mapconcat (lambda (obj) (prin1-to-string obj t))
703 (cdr error) ", "))))
704 'external-debugging-output)
705 (terpri 'external-debugging-output)
706 (setq initial-window-system nil)
707 (kill-emacs)))
709 (set-locale-environment nil)
711 ;; Convert preloaded file names in load-history to absolute.
712 (let ((simple-file-name
713 ;; Look for simple.el or simple.elc and use their directory
714 ;; as the place where all Lisp files live.
715 (locate-file "simple" load-path (get-load-suffixes)))
716 lisp-dir)
717 ;; Don't abort if simple.el cannot be found, but print a warning.
718 (if (null simple-file-name)
719 (progn
720 (princ "Warning: Could not find simple.el nor simple.elc"
721 'external-debugging-output)
722 (terpri 'external-debugging-output))
723 (setq lisp-dir (file-truename (file-name-directory simple-file-name)))
724 (setq load-history
725 (mapcar (lambda (elt)
726 (if (and (stringp (car elt))
727 (not (file-name-absolute-p (car elt))))
728 (cons (concat lisp-dir
729 (car elt))
730 (cdr elt))
731 elt))
732 load-history))))
734 ;; Convert the arguments to Emacs internal representation.
735 (let ((args (cdr command-line-args)))
736 (while args
737 (setcar args
738 (decode-coding-string (car args) locale-coding-system t))
739 (pop args)))
741 (let ((done nil)
742 (args (cdr command-line-args)))
744 ;; Figure out which user's init file to load,
745 ;; either from the environment or from the options.
746 (setq init-file-user (if noninteractive nil (user-login-name)))
747 ;; If user has not done su, use current $HOME to find .emacs.
748 (and init-file-user
749 (equal init-file-user (user-real-login-name))
750 (setq init-file-user ""))
752 ;; Process the command-line args, and delete the arguments
753 ;; processed. This is consistent with the way main in emacs.c
754 ;; does things.
755 (while (and (not done) args)
756 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
757 ("--user") ("--iconic") ("--icon-type") ("--quick")
758 ("--no-blinking-cursor") ("--basic-display")))
759 (argi (pop args))
760 (orig-argi argi)
761 argval)
762 ;; Handle --OPTION=VALUE format.
763 (when (string-match "^\\(--[^=]*\\)=" argi)
764 (setq argval (substring argi (match-end 0))
765 argi (match-string 1 argi)))
766 (unless (equal argi "--")
767 (let ((completion (try-completion argi longopts)))
768 (if (eq completion t)
769 (setq argi (substring argi 1))
770 (if (stringp completion)
771 (let ((elt (assoc completion longopts)))
772 (or elt
773 (error "Option `%s' is ambiguous" argi))
774 (setq argi (substring (car elt) 1)))
775 (setq argval nil
776 argi orig-argi)))))
777 (cond
778 ((member argi '("-Q" "-quick"))
779 (setq init-file-user nil
780 site-run-file nil
781 emacs-quick-startup t))
782 ((member argi '("-D" "-basic-display"))
783 (setq no-blinking-cursor t
784 emacs-basic-display t)
785 (push '(vertical-scroll-bars . nil) initial-frame-alist))
786 ((member argi '("-q" "-no-init-file"))
787 (setq init-file-user nil))
788 ((member argi '("-u" "-user"))
789 (setq init-file-user (or argval (pop args))
790 argval nil))
791 ((equal argi "-no-site-file")
792 (setq site-run-file nil))
793 ((equal argi "-debug-init")
794 (setq init-file-debug t))
795 ((equal argi "-iconic")
796 (push '(visibility . icon) initial-frame-alist))
797 ((member argi '("-icon-type" "-i" "-itype"))
798 (push '(icon-type . t) default-frame-alist))
799 ((member argi '("-nbc" "-no-blinking-cursor"))
800 (setq no-blinking-cursor t))
801 ;; Push the popped arg back on the list of arguments.
803 (push argi args)
804 (setq done t)))
805 ;; Was argval set but not used?
806 (and argval
807 (error "Option `%s' doesn't allow an argument" argi))))
809 ;; Re-attach the program name to the front of the arg list.
810 (and command-line-args
811 (setcdr command-line-args args)))
813 (run-hooks 'before-init-hook)
815 ;; Under X Window, this creates the X frame and deletes the terminal frame.
816 (when (fboundp 'frame-initialize)
817 (frame-initialize))
819 ;; Turn off blinking cursor if so specified in X resources. This is here
820 ;; only because all other settings of no-blinking-cursor are here.
821 (unless (or noninteractive
822 emacs-basic-display
823 (and (memq window-system '(x w32 mac))
824 (not (member (x-get-resource "cursorBlink" "CursorBlink")
825 '("off" "false")))))
826 (setq no-blinking-cursor t))
828 ;; If frame was created with a menu bar, set menu-bar-mode on.
829 (unless (or noninteractive
830 emacs-basic-display
831 (and (memq initial-window-system '(x w32))
832 (<= (frame-parameter nil 'menu-bar-lines) 0)))
833 (menu-bar-mode 1))
835 ;; If frame was created with a tool bar, switch tool-bar-mode on.
836 (unless (or noninteractive
837 emacs-basic-display
838 (not (display-graphic-p))
839 (<= (frame-parameter nil 'tool-bar-lines) 0))
840 (tool-bar-mode 1))
842 ;; Can't do this init in defcustom because the relevant variables
843 ;; are not set.
844 (custom-reevaluate-setting 'blink-cursor-mode)
845 (custom-reevaluate-setting 'tooltip-mode)
846 (custom-reevaluate-setting 'global-font-lock-mode)
847 (custom-reevaluate-setting 'mouse-wheel-down-event)
848 (custom-reevaluate-setting 'mouse-wheel-up-event)
849 (custom-reevaluate-setting 'file-name-shadow-mode)
850 (custom-reevaluate-setting 'send-mail-function)
851 (custom-reevaluate-setting 'focus-follows-mouse)
852 (custom-reevaluate-setting 'global-auto-composition-mode)
853 (custom-reevaluate-setting 'transient-mark-mode)
854 (custom-reevaluate-setting 'auto-encryption-mode)
856 (normal-erase-is-backspace-setup-frame)
858 ;; Register default TTY colors for the case the terminal hasn't a
859 ;; terminal init file. We do this regardles of whether the terminal
860 ;; supports colors or not and regardless the current display type,
861 ;; since users can connect to color-capable terminals and also
862 ;; switch color support on or off in mid-session by setting the
863 ;; tty-color-mode frame parameter.
864 (tty-register-default-colors)
866 ;; Record whether the tool-bar is present before the user and site
867 ;; init files are processed. frame-notice-user-settings uses this
868 ;; to determine if the tool-bar has been disabled by the init files,
869 ;; and the frame needs to be resized.
870 (when (fboundp 'frame-notice-user-settings)
871 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
872 (assq 'tool-bar-lines default-frame-alist))))
873 (setq tool-bar-originally-present
874 (and tool-bar-lines
875 (cdr tool-bar-lines)
876 (not (eq 0 (cdr tool-bar-lines)))))))
878 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
879 (old-font-list-limit font-list-limit)
880 (old-face-ignored-fonts face-ignored-fonts))
882 ;; Run the site-start library if it exists. The point of this file is
883 ;; that it is run before .emacs. There is no point in doing this after
884 ;; .emacs; that is useless.
885 ;; Note that user-init-file is nil at this point. Code that might
886 ;; be loaded from site-run-file and wants to test if -q was given
887 ;; should check init-file-user instead, since that is already set.
888 ;; See cus-edit.el for an example.
889 (if site-run-file
890 (load site-run-file t t))
892 ;; Sites should not disable this. Only individuals should disable
893 ;; the startup screen.
894 (setq inhibit-startup-screen nil)
896 ;; Warn for invalid user name.
897 (when init-file-user
898 (if (string-match "[~/:\n]" init-file-user)
899 (display-warning 'initialization
900 (format "Invalid user name %s"
901 init-file-user)
902 :error)
903 (if (file-directory-p (expand-file-name
904 ;; We don't support ~USER on MS-Windows except
905 ;; for the current user, and always load .emacs
906 ;; from the current user's home directory (see
907 ;; below). So always check "~", even if invoked
908 ;; with "-u USER", or if $USER or $LOGNAME are
909 ;; set to something different.
910 (if (eq system-type 'windows-nt)
912 (concat "~" init-file-user))))
914 (display-warning 'initialization
915 (format "User %s has no home directory"
916 init-file-user)
917 :error))))
919 ;; Load that user's init file, or the default one, or none.
920 (let (debug-on-error-from-init-file
921 debug-on-error-should-be-set
922 (debug-on-error-initial
923 (if (eq init-file-debug t) 'startup init-file-debug))
924 (orig-enable-multibyte default-enable-multibyte-characters))
925 (let ((debug-on-error debug-on-error-initial)
926 ;; This function actually reads the init files.
927 (inner
928 (function
929 (lambda ()
930 (if init-file-user
931 (let ((user-init-file-1
932 (cond
933 ((eq system-type 'ms-dos)
934 (concat "~" init-file-user "/_emacs"))
935 ((eq system-type 'windows-nt)
936 ;; Prefer .emacs on Windows.
937 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
938 "~/.emacs"
939 ;; Also support _emacs for compatibility.
940 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
941 "~/_emacs"
942 ;; But default to .emacs if _emacs does not exist.
943 "~/.emacs")))
944 ((eq system-type 'vax-vms)
945 "sys$login:.emacs")
947 (concat "~" init-file-user "/.emacs")))))
948 ;; This tells `load' to store the file name found
949 ;; into user-init-file.
950 (setq user-init-file t)
951 (load user-init-file-1 t t)
953 (when (eq user-init-file t)
954 ;; If we did not find ~/.emacs, try
955 ;; ~/.emacs.d/init.el.
956 (let ((otherfile
957 (expand-file-name
958 "init"
959 (file-name-as-directory
960 (concat "~" init-file-user "/.emacs.d")))))
961 (load otherfile t t)
963 ;; If we did not find the user's init file,
964 ;; set user-init-file conclusively.
965 ;; Don't let it be set from default.el.
966 (when (eq user-init-file t)
967 (setq user-init-file user-init-file-1))))
969 ;; If we loaded a compiled file, set
970 ;; `user-init-file' to the source version if that
971 ;; exists.
972 (when (and user-init-file
973 (equal (file-name-extension user-init-file)
974 "elc"))
975 (let* ((source (file-name-sans-extension user-init-file))
976 (alt (concat source ".el")))
977 (setq source (cond ((file-exists-p alt) alt)
978 ((file-exists-p source) source)
979 (t nil)))
980 (when source
981 (when (file-newer-than-file-p source user-init-file)
982 (message "Warning: %s is newer than %s"
983 source user-init-file)
984 (sit-for 1))
985 (setq user-init-file source))))
987 (unless inhibit-default-init
988 (let ((inhibit-startup-screen nil))
989 ;; Users are supposed to be told their rights.
990 ;; (Plus how to get help and how to undo.)
991 ;; Don't you dare turn this off for anyone
992 ;; except yourself.
993 (load "default" t t)))))))))
994 (if init-file-debug
995 ;; Do this without a condition-case if the user wants to debug.
996 (funcall inner)
997 (condition-case error
998 (progn
999 (funcall inner)
1000 (setq init-file-had-error nil))
1001 (error
1002 (let ((message-log-max nil))
1003 (with-current-buffer (get-buffer-create "*Messages*")
1004 (insert "\n\n"
1005 (format "An error has occurred while loading `%s':\n\n"
1006 user-init-file)
1007 (format "%s%s%s"
1008 (get (car error) 'error-message)
1009 (if (cdr error) ": " "")
1010 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
1011 "\n\n"
1012 "To ensure normal operation, you should investigate and remove the\n"
1013 "cause of the error in your initialization file. Start Emacs with\n"
1014 "the `--debug-init' option to view a complete error backtrace.\n\n"))
1015 (message "Error in init file: %s%s%s"
1016 (get (car error) 'error-message)
1017 (if (cdr error) ": " "")
1018 (mapconcat 'prin1-to-string (cdr error) ", "))
1019 (let ((pop-up-windows nil))
1020 (pop-to-buffer "*Messages*"))
1021 (setq init-file-had-error t)))))
1023 (if (and deactivate-mark transient-mark-mode)
1024 (with-current-buffer (window-buffer)
1025 (deactivate-mark)))
1027 ;; If the user has a file of abbrevs, read it (unless -batch).
1028 (when (and (not noninteractive)
1029 (file-exists-p abbrev-file-name)
1030 (file-readable-p abbrev-file-name))
1031 (quietly-read-abbrev-file abbrev-file-name))
1033 ;; If the abbrevs came entirely from the init file or the
1034 ;; abbrevs file, they do not need saving.
1035 (setq abbrevs-changed nil)
1037 ;; If we can tell that the init file altered debug-on-error,
1038 ;; arrange to preserve the value that it set up.
1039 (or (eq debug-on-error debug-on-error-initial)
1040 (setq debug-on-error-should-be-set t
1041 debug-on-error-from-init-file debug-on-error)))
1042 (if debug-on-error-should-be-set
1043 (setq debug-on-error debug-on-error-from-init-file))
1044 (unless (or default-enable-multibyte-characters
1045 (eq orig-enable-multibyte default-enable-multibyte-characters))
1046 ;; Init file changed to unibyte. Reset existing multibyte
1047 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1048 ;; Arguably this should only be done if they're free of
1049 ;; multibyte characters.
1050 (mapc (lambda (buffer)
1051 (with-current-buffer buffer
1052 (if enable-multibyte-characters
1053 (set-buffer-multibyte nil))))
1054 (buffer-list))
1055 ;; Also re-set the language environment in case it was
1056 ;; originally done before unibyte was set and is sensitive to
1057 ;; unibyte (display table, terminal coding system &c).
1058 (set-language-environment current-language-environment)))
1060 ;; Do this here in case the init file sets mail-host-address.
1061 (if (equal user-mail-address "")
1062 (setq user-mail-address (or (getenv "EMAIL")
1063 (concat (user-login-name) "@"
1064 (or mail-host-address
1065 (system-name))))))
1067 ;; Originally face attributes were specified via
1068 ;; `font-lock-face-attributes'. Users then changed the default
1069 ;; face attributes by setting that variable. However, we try and
1070 ;; be back-compatible and respect its value if set except for
1071 ;; faces where M-x customize has been used to save changes for the
1072 ;; face.
1073 (when (boundp 'font-lock-face-attributes)
1074 (let ((face-attributes font-lock-face-attributes))
1075 (while face-attributes
1076 (let* ((face-attribute (pop face-attributes))
1077 (face (car face-attribute)))
1078 ;; Rustle up a `defface' SPEC from a
1079 ;; `font-lock-face-attributes' entry.
1080 (unless (get face 'saved-face)
1081 (let ((foreground (nth 1 face-attribute))
1082 (background (nth 2 face-attribute))
1083 (bold-p (nth 3 face-attribute))
1084 (italic-p (nth 4 face-attribute))
1085 (underline-p (nth 5 face-attribute))
1086 face-spec)
1087 (when foreground
1088 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1089 (when background
1090 (setq face-spec (cons ':background (cons background face-spec))))
1091 (when bold-p
1092 (setq face-spec (append '(:weight bold) face-spec)))
1093 (when italic-p
1094 (setq face-spec (append '(:slant italic) face-spec)))
1095 (when underline-p
1096 (setq face-spec (append '(:underline t) face-spec)))
1097 (face-spec-set face (list (list t face-spec)) nil)))))))
1099 ;; If parameter have been changed in the init file which influence
1100 ;; face realization, clear the face cache so that new faces will
1101 ;; be realized.
1102 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1103 (eq font-list-limit old-font-list-limit)
1104 (eq face-ignored-fonts old-face-ignored-fonts))
1105 (clear-face-cache)))
1107 (setq after-init-time (current-time))
1108 (run-hooks 'after-init-hook)
1110 ;; Decode all default-directory.
1111 (if (and default-enable-multibyte-characters locale-coding-system)
1112 (save-excursion
1113 (dolist (elt (buffer-list))
1114 (set-buffer elt)
1115 (if default-directory
1116 (setq default-directory
1117 (decode-coding-string default-directory
1118 locale-coding-system t))))
1119 (setq command-line-default-directory
1120 (decode-coding-string command-line-default-directory
1121 locale-coding-system t))))
1123 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1124 (if (get-buffer "*scratch*")
1125 (with-current-buffer "*scratch*"
1126 (if (eq major-mode 'fundamental-mode)
1127 (funcall initial-major-mode))))
1129 ;; Load library for our terminal type.
1130 ;; User init file can set term-file-prefix to nil to prevent this.
1131 (unless (or noninteractive
1132 initial-window-system)
1133 (tty-run-terminal-initialization (selected-frame)))
1135 ;; Update the out-of-memory error message based on user's key bindings
1136 ;; for save-some-buffers.
1137 (setq memory-signal-data
1138 (list 'error
1139 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1141 ;; Process the remaining args.
1142 (command-line-1 (cdr command-line-args))
1144 ;; If -batch, terminate after processing the command options.
1145 (if noninteractive (kill-emacs t))
1147 ;; Run emacs-session-restore (session management) if started by
1148 ;; the session manager and we have a session manager connection.
1149 (if (and (boundp 'x-session-previous-id)
1150 (stringp x-session-previous-id))
1151 (with-no-warnings
1152 (emacs-session-restore x-session-previous-id))))
1154 (defcustom initial-scratch-message (purecopy "\
1155 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1156 ;; If you want to create a file, visit that file with C-x C-f,
1157 ;; then enter the text in that file's own buffer.
1160 "Initial message displayed in *scratch* buffer at startup.
1161 If this is nil, no message will be displayed."
1162 :type '(choice (text :tag "Message")
1163 (const :tag "none" nil))
1164 :group 'initialization)
1167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1168 ;;; Fancy splash screen
1169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1171 (defvar fancy-startup-text
1172 '((:face (variable-pitch (:foreground "red"))
1173 "Welcome to "
1174 :link ("GNU Emacs"
1175 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1176 "Browse http://www.gnu.org/software/emacs/")
1177 ", one component of the "
1178 :link
1179 (lambda ()
1180 (if (eq system-type 'gnu/linux)
1181 '("GNU/Linux"
1182 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1183 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1184 '("GNU" (lambda (button) (describe-gnu-project))
1185 "Display info on the GNU project")))
1186 " operating system.\n"
1187 :face variable-pitch "To quit a partially entered command, type "
1188 :face default "Control-g"
1189 :face variable-pitch ".\n\n"
1190 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1191 "\tLearn basic keystroke commands"
1192 (lambda ()
1193 (let* ((en "TUTORIAL")
1194 (tut (or (get-language-info current-language-environment
1195 'tutorial)
1196 en))
1197 (title (with-temp-buffer
1198 (insert-file-contents
1199 (expand-file-name tut tutorial-directory)
1200 nil 0 256)
1201 (search-forward ".")
1202 (buffer-substring (point-min) (1- (point))))))
1203 ;; If there is a specific tutorial for the current language
1204 ;; environment and it is not English, append its title.
1205 (if (string= en tut)
1207 (concat " (" title ")"))))
1208 "\n"
1209 :face variable-pitch
1210 :link ("Emacs Guided Tour"
1211 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1212 "Browse http://www.gnu.org/software/emacs/tour/")
1213 "\tOverview of Emacs features\n"
1214 :link ("View Emacs Manual" (lambda (button) (info-emacs-manual)))
1215 "\tView the Emacs manual using Info\n"
1216 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1217 "\tGNU Emacs comes with "
1218 :face (variable-pitch (:slant oblique))
1219 "ABSOLUTELY NO WARRANTY\n"
1220 :face variable-pitch
1221 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1222 "\tConditions for redistributing and changing Emacs\n"
1223 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1224 "\tPurchasing printed copies of manuals\n"
1225 "\n"))
1226 "A list of texts to show in the middle part of splash screens.
1227 Each element in the list should be a list of strings or pairs
1228 `:face FACE', like `fancy-splash-insert' accepts them.")
1230 (defvar fancy-about-text
1231 '((:face (variable-pitch (:foreground "red"))
1232 "This is "
1233 :link ("GNU Emacs"
1234 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1235 "Browse http://www.gnu.org/software/emacs/")
1236 ", one component of the "
1237 :link
1238 (lambda ()
1239 (if (eq system-type 'gnu/linux)
1240 '("GNU/Linux"
1241 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1242 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1243 '("GNU" (lambda (button) (describe-gnu-project))
1244 "Display info on the GNU project.")))
1245 " operating system.\n"
1246 :face (lambda ()
1247 (list 'variable-pitch
1248 (list :foreground
1249 (if (eq (frame-parameter nil 'background-mode) 'dark)
1250 "cyan" "darkblue"))))
1251 "\n"
1252 (lambda () (emacs-version))
1253 "\n"
1254 :face (variable-pitch (:height 0.5))
1255 (lambda () emacs-copyright)
1256 "\n\n"
1257 :face variable-pitch
1258 :link ("Authors"
1259 (lambda (button)
1260 (view-file (expand-file-name "AUTHORS" data-directory))
1261 (goto-char (point-min))))
1262 "\tMany people have contributed code included in GNU Emacs\n"
1263 :link ("Contributing"
1264 (lambda (button)
1265 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1266 (goto-char (point-min))))
1267 "\tHow to contribute improvements to Emacs\n"
1268 "\n"
1269 :link ("GNU and Freedom" (lambda (button) (describe-gnu-project)))
1270 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1271 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1272 "\tGNU Emacs comes with "
1273 :face (variable-pitch (:slant oblique))
1274 "ABSOLUTELY NO WARRANTY\n"
1275 :face variable-pitch
1276 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1277 "\tConditions for redistributing and changing Emacs\n"
1278 :link ("Getting New Versions" (lambda (button) (describe-distribution)))
1279 "\tHow to obtain the latest version of Emacs\n"
1280 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1281 "\tBuying printed manuals from the FSF\n"
1282 "\n"
1283 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1284 "\tLearn basic Emacs keystroke commands"
1285 (lambda ()
1286 (let* ((en "TUTORIAL")
1287 (tut (or (get-language-info current-language-environment
1288 'tutorial)
1289 en))
1290 (title (with-temp-buffer
1291 (insert-file-contents
1292 (expand-file-name tut tutorial-directory)
1293 nil 0 256)
1294 (search-forward ".")
1295 (buffer-substring (point-min) (1- (point))))))
1296 ;; If there is a specific tutorial for the current language
1297 ;; environment and it is not English, append its title.
1298 (if (string= en tut)
1300 (concat " (" title ")"))))
1301 "\n"
1302 :link ("Emacs Guided Tour"
1303 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1304 "Browse http://www.gnu.org/software/emacs/tour/")
1305 "\tSee an overview of the many facilities of GNU Emacs"
1307 "A list of texts to show in the middle part of the About screen.
1308 Each element in the list should be a list of strings or pairs
1309 `:face FACE', like `fancy-splash-insert' accepts them.")
1312 (defgroup fancy-splash-screen ()
1313 "Fancy splash screen when Emacs starts."
1314 :version "21.1"
1315 :group 'initialization)
1317 (defcustom fancy-splash-image nil
1318 "*The image to show in the splash screens, or nil for defaults."
1319 :group 'fancy-splash-screen
1320 :type '(choice (const :tag "Default" nil)
1321 (file :tag "File")))
1324 (defvar splash-screen-keymap
1325 (let ((map (make-sparse-keymap)))
1326 (suppress-keymap map)
1327 (set-keymap-parent map button-buffer-map)
1328 (define-key map "\C-?" 'scroll-down)
1329 (define-key map " " 'scroll-up)
1330 (define-key map "q" 'exit-splash-screen)
1331 map)
1332 "Keymap for splash screen buffer.")
1334 ;; These are temporary storage areas for the splash screen display.
1336 (defun fancy-splash-insert (&rest args)
1337 "Insert text into the current buffer, with faces.
1338 Arguments from ARGS should be either strings; functions called
1339 with no args that return a string; pairs `:face FACE', where FACE
1340 is a face specification usable with `put-text-property'; or pairs
1341 `:link LINK' where LINK is a list of arguments to pass to
1342 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1343 specifies the button's label, `action' property and help-echo string.
1344 FACE and LINK can also be functions, which are evaluated to obtain
1345 a face or button specification."
1346 (let ((current-face nil))
1347 (while args
1348 (cond ((eq (car args) :face)
1349 (setq args (cdr args) current-face (car args))
1350 (if (functionp current-face)
1351 (setq current-face (funcall current-face))))
1352 ((eq (car args) :link)
1353 (setq args (cdr args))
1354 (let ((spec (car args)))
1355 (if (functionp spec)
1356 (setq spec (funcall spec)))
1357 (insert-button (car spec)
1358 'face (list 'link current-face)
1359 'action (cadr spec)
1360 'help-echo (concat "mouse-2, RET: "
1361 (or (nth 2 spec)
1362 "Follow this link"))
1363 'follow-link t)))
1364 (t (insert (propertize (let ((it (car args)))
1365 (if (functionp it)
1366 (funcall it)
1367 it))
1368 'face current-face
1369 'help-echo (startup-echo-area-message)))))
1370 (setq args (cdr args)))))
1372 (declare-function image-size "image.c" (spec &optional pixels frame))
1374 (defun fancy-splash-head ()
1375 "Insert the head part of the splash screen into the current buffer."
1376 (let* ((image-file (cond ((stringp fancy-splash-image)
1377 fancy-splash-image)
1378 ((and (display-color-p)
1379 (image-type-available-p 'xpm))
1380 (if (and (fboundp 'x-display-planes)
1381 (= (funcall 'x-display-planes) 8))
1382 "splash8.xpm"
1383 "splash.xpm"))
1384 (t "splash.pbm")))
1385 (img (create-image image-file))
1386 (image-width (and img (car (image-size img))))
1387 (window-width (window-width (selected-window))))
1388 (when img
1389 (when (> window-width image-width)
1390 ;; Center the image in the window.
1391 (insert (propertize " " 'display
1392 `(space :align-to (+ center (-0.5 . ,img)))))
1394 ;; Change the color of the XPM version of the splash image
1395 ;; so that it is visible with a dark frame background.
1396 (when (and (memq 'xpm img)
1397 (eq (frame-parameter nil 'background-mode) 'dark))
1398 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1400 ;; Insert the image with a help-echo and a link.
1401 (make-button (prog1 (point) (insert-image img)) (point)
1402 'face 'default
1403 'help-echo "mouse-2, RET: Browse http://www.gnu.org/"
1404 'action (lambda (button) (browse-url "http://www.gnu.org/"))
1405 'follow-link t)
1406 (insert "\n\n")))))
1408 (defun fancy-startup-tail (&optional concise)
1409 "Insert the tail part of the splash screen into the current buffer."
1410 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1411 "cyan" "darkblue")))
1412 (unless concise
1413 (fancy-splash-insert
1414 :face 'variable-pitch
1415 "\nTo start... "
1416 :link '("Open a File"
1417 (lambda (button) (call-interactively 'find-file))
1418 "Specify a new file's name, to edit the file")
1420 :link '("Open Home Directory"
1421 (lambda (button) (dired "~"))
1422 "Open your home directory, to operate on its files")
1424 :link '("Customize Startup"
1425 (lambda (button) (customize-group 'initialization))
1426 "Change initialization settings including this screen")
1427 "\n"))
1428 (fancy-splash-insert :face `(variable-pitch (:foreground ,fg))
1429 "\nThis is "
1430 (emacs-version)
1431 "\n"
1432 :face '(variable-pitch (:height 0.5))
1433 emacs-copyright
1434 "\n")
1435 (and auto-save-list-file-prefix
1436 ;; Don't signal an error if the
1437 ;; directory for auto-save-list files
1438 ;; does not yet exist.
1439 (file-directory-p (file-name-directory
1440 auto-save-list-file-prefix))
1441 (directory-files
1442 (file-name-directory auto-save-list-file-prefix)
1444 (concat "\\`"
1445 (regexp-quote (file-name-nondirectory
1446 auto-save-list-file-prefix)))
1448 (fancy-splash-insert :face '(variable-pitch (:foreground "red"))
1449 "\nIf an Emacs session crashed recently, "
1450 "type "
1451 :face '(fixed-pitch :foreground "red")
1452 "Meta-x recover-session RET"
1453 :face '(variable-pitch (:foreground "red"))
1454 "\nto recover"
1455 " the files you were editing."))
1457 (when concise
1458 (fancy-splash-insert
1459 :face 'variable-pitch "\n"
1460 :link '("Dismiss this startup screen"
1461 (lambda (button)
1462 (when startup-screen-inhibit-startup-screen
1463 (customize-set-variable 'inhibit-startup-screen t)
1464 (customize-mark-to-save 'inhibit-startup-screen)
1465 (custom-save-all))
1466 (let ((w (get-buffer-window "*GNU Emacs*")))
1467 (and w (not (one-window-p)) (delete-window w)))
1468 (kill-buffer "*GNU Emacs*")))
1469 " ")
1470 (when (or user-init-file custom-file)
1471 (let ((checked (create-image "\300\300\141\143\067\076\034\030"
1472 'xbm t :width 8 :height 8 :background "grey75"
1473 :foreground "black" :relief -2 :ascent 'center))
1474 (unchecked (create-image (make-string 8 0)
1475 'xbm t :width 8 :height 8 :background "grey75"
1476 :foreground "black" :relief -2 :ascent 'center)))
1477 (insert-button
1478 " " :on-glyph checked :off-glyph unchecked 'checked nil
1479 'display unchecked 'follow-link t
1480 'action (lambda (button)
1481 (if (overlay-get button 'checked)
1482 (progn (overlay-put button 'checked nil)
1483 (overlay-put button 'display (overlay-get button :off-glyph))
1484 (setq startup-screen-inhibit-startup-screen nil))
1485 (overlay-put button 'checked t)
1486 (overlay-put button 'display (overlay-get button :on-glyph))
1487 (setq startup-screen-inhibit-startup-screen t)))))
1488 (fancy-splash-insert :face '(variable-pitch (:height 0.9))
1489 " Never show it again.")))))
1491 (defun exit-splash-screen ()
1492 "Stop displaying the splash screen buffer."
1493 (interactive)
1494 (quit-window t))
1496 (defun fancy-startup-screen (&optional concise)
1497 "Display fancy startup screen.
1498 If CONCISE is non-nil, display a concise version of the
1499 splash screen in another window."
1500 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1501 (with-current-buffer splash-buffer
1502 (let ((inhibit-read-only t))
1503 (erase-buffer)
1504 (setq default-directory command-line-default-directory)
1505 (make-local-variable 'startup-screen-inhibit-startup-screen)
1506 (if pure-space-overflow
1507 (insert pure-space-overflow-message))
1508 (unless concise
1509 (fancy-splash-head))
1510 (dolist (text fancy-startup-text)
1511 (apply #'fancy-splash-insert text)
1512 (insert "\n"))
1513 (skip-chars-backward "\n")
1514 (delete-region (point) (point-max))
1515 (insert "\n")
1516 (fancy-startup-tail concise))
1517 (use-local-map splash-screen-keymap)
1518 (setq tab-width 22
1519 buffer-read-only t)
1520 (set-buffer-modified-p nil)
1521 (if (and view-read-only (not view-mode))
1522 (view-mode-enter nil 'kill-buffer))
1523 (goto-char (point-min))
1524 (forward-line (if concise 2 4)))
1525 (if concise
1526 (progn
1527 (display-buffer splash-buffer)
1528 ;; If the splash screen is in a split window, fit it.
1529 (let ((window (get-buffer-window splash-buffer t)))
1530 (or (null window)
1531 (eq window (selected-window))
1532 (eq window (next-window window))
1533 (fit-window-to-buffer window))))
1534 (switch-to-buffer splash-buffer))))
1536 (defun fancy-about-screen ()
1537 "Display fancy About screen."
1538 (let ((frame (fancy-splash-frame)))
1539 (save-selected-window
1540 (select-frame frame)
1541 (switch-to-buffer "*About GNU Emacs*")
1542 (setq buffer-undo-list t
1543 mode-line-format (propertize "---- %b %-"
1544 'face 'mode-line-buffer-id))
1545 (let ((inhibit-read-only t))
1546 (erase-buffer)
1547 (if pure-space-overflow
1548 (insert pure-space-overflow-message))
1549 (fancy-splash-head)
1550 (dolist (text fancy-about-text)
1551 (apply #'fancy-splash-insert text)
1552 (insert "\n"))
1553 (set-buffer-modified-p nil)
1554 (goto-char (point-min))
1555 (force-mode-line-update))
1556 (use-local-map splash-screen-keymap)
1557 (setq tab-width 22)
1558 (message "%s" (startup-echo-area-message))
1559 (setq buffer-read-only t)
1560 (goto-char (point-min))
1561 (forward-line 3))))
1563 (defun fancy-splash-frame ()
1564 "Return the frame to use for the fancy splash screen.
1565 Returning non-nil does not mean we should necessarily
1566 use the fancy splash screen, but if we do use it,
1567 we put it on this frame."
1568 (let (chosen-frame)
1569 (dolist (frame (append (frame-list) (list (selected-frame))))
1570 (if (and (frame-visible-p frame)
1571 (not (window-minibuffer-p (frame-selected-window frame))))
1572 (setq chosen-frame frame)))
1573 chosen-frame))
1575 (defun use-fancy-splash-screens-p ()
1576 "Return t if fancy splash screens should be used."
1577 (when (and (display-graphic-p)
1578 (or (and (display-color-p)
1579 (image-type-available-p 'xpm))
1580 (image-type-available-p 'pbm)))
1581 (let ((frame (fancy-splash-frame)))
1582 (when frame
1583 (let* ((img (create-image (or fancy-splash-image
1584 (if (and (display-color-p)
1585 (image-type-available-p 'xpm))
1586 "splash.xpm" "splash.pbm"))))
1587 (image-height (and img (cdr (image-size img nil frame))))
1588 ;; We test frame-height so that, if the frame is split
1589 ;; by displaying a warning, that doesn't cause the normal
1590 ;; splash screen to be used.
1591 (frame-height (1- (frame-height frame))))
1592 (> frame-height (+ image-height 19)))))))
1595 (defun normal-splash-screen (&optional startup concise)
1596 "Display non-graphic splash screen.
1597 If optional argument STARTUP is non-nil, display the startup screen
1598 after Emacs starts. If STARTUP is nil, display the About screen.
1599 If CONCISE is non-nil, display a concise version of the
1600 splash screen in another window."
1601 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1602 (with-current-buffer splash-buffer
1603 (setq buffer-read-only nil)
1604 (erase-buffer)
1605 (setq default-directory command-line-default-directory)
1606 (set (make-local-variable 'tab-width) 8)
1607 (if (not startup)
1608 (set (make-local-variable 'mode-line-format)
1609 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1611 (if pure-space-overflow
1612 (insert pure-space-overflow-message))
1614 ;; The convention for this piece of code is that
1615 ;; each piece of output starts with one or two newlines
1616 ;; and does not end with any newlines.
1617 (insert (if startup "Welcome to GNU Emacs" "This is GNU Emacs"))
1618 (insert
1619 (if (eq system-type 'gnu/linux)
1620 ", one component of the GNU/Linux operating system.\n"
1621 ", a part of the GNU operating system.\n"))
1623 (if startup
1624 (if (display-mouse-p)
1625 ;; The user can use the mouse to activate menus
1626 ;; so give help in terms of menu items.
1627 (normal-mouse-startup-screen)
1629 ;; No mouse menus, so give help using kbd commands.
1630 (normal-no-mouse-startup-screen))
1632 (normal-about-screen))
1634 ;; The rest of the startup screen is the same on all
1635 ;; kinds of terminals.
1637 ;; Give information on recovering, if there was a crash.
1638 (and startup
1639 auto-save-list-file-prefix
1640 ;; Don't signal an error if the
1641 ;; directory for auto-save-list files
1642 ;; does not yet exist.
1643 (file-directory-p (file-name-directory
1644 auto-save-list-file-prefix))
1645 (directory-files
1646 (file-name-directory auto-save-list-file-prefix)
1648 (concat "\\`"
1649 (regexp-quote (file-name-nondirectory
1650 auto-save-list-file-prefix)))
1652 (insert "\n\nIf an Emacs session crashed recently, "
1653 "type Meta-x recover-session RET\nto recover"
1654 " the files you were editing.\n"))
1656 (use-local-map splash-screen-keymap)
1658 ;; Display the input that we set up in the buffer.
1659 (set-buffer-modified-p nil)
1660 (setq buffer-read-only t)
1661 (if (and view-read-only (not view-mode))
1662 (view-mode-enter nil 'kill-buffer))
1663 (if startup (rename-buffer "*GNU Emacs*" t))
1664 (goto-char (point-min)))
1665 (if concise
1666 (display-buffer splash-buffer)
1667 (switch-to-buffer splash-buffer))))
1669 (defun normal-mouse-startup-screen ()
1670 ;; The user can use the mouse to activate menus
1671 ;; so give help in terms of menu items.
1672 (insert "\
1673 To follow a link, click Mouse-1 on it, or move to it and type RET.
1674 To quit a partially entered command, type Control-g.\n")
1676 (insert "\nImportant Help menu items:\n")
1677 (insert-button "Emacs Tutorial"
1678 'action (lambda (button) (help-with-tutorial))
1679 'follow-link t)
1680 (insert "\t\tLearn basic Emacs keystroke commands\n")
1681 (insert-button "Read the Emacs Manual"
1682 'action (lambda (button) (info-emacs-manual))
1683 'follow-link t)
1684 (insert "\tView the Emacs manual using Info\n")
1685 (insert-button "\(Non)Warranty"
1686 'action (lambda (button) (describe-no-warranty))
1687 'follow-link t)
1688 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1689 (insert-button "Copying Conditions"
1690 'action (lambda (button) (describe-copying))
1691 'follow-link t)
1692 (insert "\tConditions for redistributing and changing Emacs\n")
1693 (insert-button "More Manuals / Ordering Manuals"
1694 'action (lambda (button) (view-order-manuals))
1695 'follow-link t)
1696 (insert " How to order printed manuals from the FSF\n")
1698 (insert "\nUseful tasks:\n")
1699 (insert-button "Visit New File"
1700 'action (lambda (button) (call-interactively 'find-file))
1701 'follow-link t)
1702 (insert "\t\tSpecify a new file's name, to edit the file\n")
1703 (insert-button "Open Home Directory"
1704 'action (lambda (button) (dired "~"))
1705 'follow-link t)
1706 (insert "\tOpen your home directory, to operate on its files\n")
1707 (insert-button "Customize Startup"
1708 'action (lambda (button) (customize-group 'initialization))
1709 'follow-link t)
1710 (insert "\tChange initialization settings including this screen\n")
1712 (insert "\n" (emacs-version)
1713 "\n" emacs-copyright))
1715 ;; No mouse menus, so give help using kbd commands.
1716 (defun normal-no-mouse-startup-screen ()
1718 ;; If keys have their default meanings,
1719 ;; use precomputed string to save lots of time.
1720 (if (and (eq (key-binding "\C-h") 'help-command)
1721 (eq (key-binding "\C-xu") 'advertised-undo)
1722 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
1723 (eq (key-binding "\C-ht") 'help-with-tutorial)
1724 (eq (key-binding "\C-hi") 'info)
1725 (eq (key-binding "\C-hr") 'info-emacs-manual)
1726 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1727 (progn
1728 (insert "
1729 Get help\t C-h (Hold down CTRL and press h)
1731 (insert-button "Emacs manual"
1732 'action (lambda (button) (info-emacs-manual))
1733 'follow-link t)
1734 (insert " C-h r\t")
1735 (insert-button "Browse manuals"
1736 'action (lambda (button) (Info-directory))
1737 'follow-link t)
1738 (insert "\t C-h i
1740 (insert-button "Emacs tutorial"
1741 'action (lambda (button) (help-with-tutorial))
1742 'follow-link t)
1743 (insert " C-h t\tUndo changes\t C-x u
1745 (insert-button "Buy manuals"
1746 'action (lambda (button) (view-order-manuals))
1747 'follow-link t)
1748 (insert "\t C-h C-m\tExit Emacs\t C-x C-c"))
1750 (insert (format "
1751 Get help\t %s
1753 (let ((where (where-is-internal
1754 'help-command nil t)))
1755 (if where
1756 (key-description where)
1757 "M-x help"))))
1758 (insert-button "Emacs manual"
1759 'action (lambda (button) (info-emacs-manual))
1760 'follow-link t)
1761 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1762 (insert-button "Browse manuals"
1763 'action (lambda (button) (Info-directory))
1764 'follow-link t)
1765 (insert (substitute-command-keys "\t \\[info]
1767 (insert-button "Emacs tutorial"
1768 'action (lambda (button) (help-with-tutorial))
1769 'follow-link t)
1770 (insert (substitute-command-keys
1771 "\t \\[help-with-tutorial]\tUndo changes\t \\[advertised-undo]
1773 (insert-button "Buy manuals"
1774 'action (lambda (button) (view-order-manuals))
1775 'follow-link t)
1776 (insert (substitute-command-keys
1777 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1779 ;; Say how to use the menu bar with the keyboard.
1780 (insert "\n")
1781 (insert-button "Activate menubar"
1782 'action (lambda (button) (tmm-menubar))
1783 'follow-link t)
1784 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1785 (eq (key-binding [f10]) 'tmm-menubar))
1786 (insert " F10 or ESC ` or M-`")
1787 (insert (substitute-command-keys " \\[tmm-menubar]")))
1789 ;; Many users seem to have problems with these.
1790 (insert "
1791 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1792 If you have no Meta key, you may instead type ESC followed by the character.)")
1794 ;; Insert links to useful tasks
1795 (insert "\nUseful tasks:\n")
1797 (insert-button "Visit New File"
1798 'action (lambda (button) (call-interactively 'find-file))
1799 'follow-link t)
1800 (insert "\t\t\t")
1801 (insert-button "Open Home Directory"
1802 'action (lambda (button) (dired "~"))
1803 'follow-link t)
1804 (insert "\n")
1806 (insert-button "Customize Startup"
1807 'action (lambda (button) (customize-group 'initialization))
1808 'follow-link t)
1809 (insert "\t\t")
1810 (insert-button "Open *scratch* buffer"
1811 'action (lambda (button) (switch-to-buffer
1812 (get-buffer-create "*scratch*")))
1813 'follow-link t)
1814 (insert "\n")
1815 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1817 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1818 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1819 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1820 (progn
1821 (insert
1823 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1824 (insert-button "full details"
1825 'action (lambda (button) (describe-no-warranty))
1826 'follow-link t)
1827 (insert ".
1828 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1829 of Emacs and modify it; type C-h C-c to see ")
1830 (insert-button "the conditions"
1831 'action (lambda (button) (describe-copying))
1832 'follow-link t)
1833 (insert ".
1834 Type C-h C-d for information on ")
1835 (insert-button "getting the latest version"
1836 'action (lambda (button) (describe-distribution))
1837 'follow-link t)
1838 (insert "."))
1839 (insert (substitute-command-keys
1841 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1842 (insert-button "full details"
1843 'action (lambda (button) (describe-no-warranty))
1844 'follow-link t)
1845 (insert (substitute-command-keys ".
1846 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1847 of Emacs and modify it; type \\[describe-copying] to see "))
1848 (insert-button "the conditions"
1849 'action (lambda (button) (describe-copying))
1850 'follow-link t)
1851 (insert (substitute-command-keys".
1852 Type \\[describe-distribution] for information on "))
1853 (insert-button "getting the latest version"
1854 'action (lambda (button) (describe-distribution))
1855 'follow-link t)
1856 (insert ".")))
1858 (defun normal-about-screen ()
1859 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1861 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1863 (insert-button "Authors"
1864 'action
1865 (lambda (button)
1866 (view-file (expand-file-name "AUTHORS" data-directory))
1867 (goto-char (point-min)))
1868 'follow-link t)
1869 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1871 (insert-button "Contributing"
1872 'action
1873 (lambda (button)
1874 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1875 (goto-char (point-min)))
1876 'follow-link t)
1877 (insert "\tHow to contribute improvements to Emacs\n\n")
1879 (insert-button "GNU and Freedom"
1880 'action (lambda (button) (describe-gnu-project))
1881 'follow-link t)
1882 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
1884 (insert-button "Absence of Warranty"
1885 'action (lambda (button) (describe-no-warranty))
1886 'follow-link t)
1887 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1889 (insert-button "Copying Conditions"
1890 'action (lambda (button) (describe-copying))
1891 'follow-link t)
1892 (insert "\tConditions for redistributing and changing Emacs\n")
1894 (insert-button "Getting New Versions"
1895 'action (lambda (button) (describe-distribution))
1896 'follow-link t)
1897 (insert "\tHow to get the latest version of GNU Emacs\n")
1899 (insert-button "More Manuals / Ordering Manuals"
1900 'action (lambda (button) (view-order-manuals))
1901 'follow-link t)
1902 (insert "\tBuying printed manuals from the FSF\n"))
1904 (defun startup-echo-area-message ()
1905 (if (eq (key-binding "\C-h\C-a") 'about-emacs)
1906 "For information about GNU Emacs and the GNU system, type C-h C-a."
1907 (substitute-command-keys
1908 "For information about GNU Emacs and the GNU system, type \
1909 \\[about-emacs].")))
1912 (defun display-startup-echo-area-message ()
1913 (let ((resize-mini-windows t))
1914 (or noninteractive ;(input-pending-p) init-file-had-error
1915 ;; t if the init file says to inhibit the echo area startup message.
1916 (and inhibit-startup-echo-area-message
1917 user-init-file
1918 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1919 (equal inhibit-startup-echo-area-message
1920 (if (equal init-file-user "")
1921 (user-login-name)
1922 init-file-user)))
1923 ;; Wasn't set with custom; see if .emacs has a setq.
1924 (let ((buffer (get-buffer-create " *temp*")))
1925 (prog1
1926 (condition-case nil
1927 (save-excursion
1928 (set-buffer buffer)
1929 (insert-file-contents user-init-file)
1930 (re-search-forward
1931 (concat
1932 "([ \t\n]*setq[ \t\n]+"
1933 "inhibit-startup-echo-area-message[ \t\n]+"
1934 (regexp-quote
1935 (prin1-to-string
1936 (if (equal init-file-user "")
1937 (user-login-name)
1938 init-file-user)))
1939 "[ \t\n]*)")
1940 nil t))
1941 (error nil))
1942 (kill-buffer buffer)))))
1943 (message "%s" (startup-echo-area-message)))))
1945 (defun display-startup-screen (&optional concise)
1946 "Display startup screen according to display.
1947 A fancy display is used on graphic displays, normal otherwise.
1949 If CONCISE is non-nil, display a concise version of the startup
1950 screen."
1951 ;; Prevent recursive calls from server-process-filter.
1952 (if (not (get-buffer "*GNU Emacs*"))
1953 (if (use-fancy-splash-screens-p)
1954 (fancy-startup-screen concise)
1955 (normal-splash-screen t concise))))
1957 (defun display-about-screen ()
1958 "Display the *About GNU Emacs* buffer.
1959 A fancy display is used on graphic displays, normal otherwise."
1960 (interactive)
1961 (if (use-fancy-splash-screens-p)
1962 (fancy-about-screen)
1963 (normal-splash-screen nil)))
1965 (defalias 'about-emacs 'display-about-screen)
1966 (defalias 'display-splash-screen 'display-startup-screen)
1968 (defun command-line-1 (command-line-args-left)
1969 (display-startup-echo-area-message)
1971 ;; Delay 2 seconds after an init file error message
1972 ;; was displayed, so user can read it.
1973 (when init-file-had-error
1974 (sit-for 2))
1976 (when (and pure-space-overflow
1977 (not noninteractive))
1978 (display-warning
1979 'initialization
1980 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1981 :warning))
1983 (let ((file-count 0)
1984 first-file-buffer)
1985 (when command-line-args-left
1986 ;; We have command args; process them.
1987 (let ((dir command-line-default-directory)
1989 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1990 ;; if foo is intended to be found in DIR.
1992 ;; ;; The directories listed in --directory/-L options will *appear*
1993 ;; ;; at the front of `load-path' in the order they appear on the
1994 ;; ;; command-line. We cannot do this by *placing* them at the front
1995 ;; ;; in the order they appear, so we need this variable to hold them,
1996 ;; ;; temporarily.
1997 ;; extra-load-path
1999 ;; To DTRT we keep track of the splice point and modify `load-path'
2000 ;; straight away upon any --directory/-L option.
2001 splice
2002 just-files ;; t if this follows the magic -- option.
2003 ;; This includes our standard options' long versions
2004 ;; and long versions of what's on command-switch-alist.
2005 (longopts
2006 (append '(("--funcall") ("--load") ("--insert") ("--kill")
2007 ("--directory") ("--eval") ("--execute") ("--no-splash")
2008 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
2009 (mapcar (lambda (elt)
2010 (list (concat "-" (car elt))))
2011 command-switch-alist)))
2012 (line 0)
2013 (column 0))
2015 ;; Add the long X options to longopts.
2016 (dolist (tem command-line-x-option-alist)
2017 (if (string-match "^--" (car tem))
2018 (push (list (car tem)) longopts)))
2020 ;; Loop, processing options.
2021 (while command-line-args-left
2022 (let* ((argi (car command-line-args-left))
2023 (orig-argi argi)
2024 argval completion)
2025 (setq command-line-args-left (cdr command-line-args-left))
2027 ;; Do preliminary decoding of the option.
2028 (if just-files
2029 ;; After --, don't look for options; treat all args as files.
2030 (setq argi "")
2031 ;; Convert long options to ordinary options
2032 ;; and separate out an attached option argument into argval.
2033 (when (string-match "^\\(--[^=]*\\)=" argi)
2034 (setq argval (substring argi (match-end 0))
2035 argi (match-string 1 argi)))
2036 (if (equal argi "--")
2037 (setq completion nil)
2038 (setq completion (try-completion argi longopts)))
2039 (if (eq completion t)
2040 (setq argi (substring argi 1))
2041 (if (stringp completion)
2042 (let ((elt (assoc completion longopts)))
2043 (or elt
2044 (error "Option `%s' is ambiguous" argi))
2045 (setq argi (substring (car elt) 1)))
2046 (setq argval nil
2047 argi orig-argi))))
2049 ;; Execute the option.
2050 (cond ((setq tem (assoc argi command-switch-alist))
2051 (if argval
2052 (let ((command-line-args-left
2053 (cons argval command-line-args-left)))
2054 (funcall (cdr tem) argi))
2055 (funcall (cdr tem) argi)))
2057 ((equal argi "-no-splash")
2058 (setq inhibit-startup-screen t))
2060 ((member argi '("-f" ; what the manual claims
2061 "-funcall"
2062 "-e")) ; what the source used to say
2063 (setq inhibit-startup-screen t)
2064 (setq tem (intern (or argval (pop command-line-args-left))))
2065 (if (commandp tem)
2066 (command-execute tem)
2067 (funcall tem)))
2069 ((member argi '("-eval" "-execute"))
2070 (setq inhibit-startup-screen t)
2071 (eval (read (or argval (pop command-line-args-left)))))
2073 ((member argi '("-L" "-directory"))
2074 (setq tem (expand-file-name
2075 (command-line-normalize-file-name
2076 (or argval (pop command-line-args-left)))))
2077 (cond (splice (setcdr splice (cons tem (cdr splice)))
2078 (setq splice (cdr splice)))
2079 (t (setq load-path (cons tem load-path)
2080 splice load-path))))
2082 ((member argi '("-l" "-load"))
2083 (let* ((file (command-line-normalize-file-name
2084 (or argval (pop command-line-args-left))))
2085 ;; Take file from default dir if it exists there;
2086 ;; otherwise let `load' search for it.
2087 (file-ex (expand-file-name file)))
2088 (when (file-exists-p file-ex)
2089 (setq file file-ex))
2090 (load file nil t)))
2092 ;; This is used to handle -script. It's not clear
2093 ;; we need to document it (it is totally internal).
2094 ((member argi '("-scriptload"))
2095 (let* ((file (command-line-normalize-file-name
2096 (or argval (pop command-line-args-left))))
2097 ;; Take file from default dir.
2098 (file-ex (expand-file-name file)))
2099 (load file-ex nil t t)))
2101 ((equal argi "-insert")
2102 (setq inhibit-startup-screen t)
2103 (setq tem (or argval (pop command-line-args-left)))
2104 (or (stringp tem)
2105 (error "File name omitted from `-insert' option"))
2106 (insert-file-contents (command-line-normalize-file-name tem)))
2108 ((equal argi "-kill")
2109 (kill-emacs t))
2111 ;; This is for when they use --no-desktop with -q, or
2112 ;; don't load Desktop in their .emacs. If desktop.el
2113 ;; _is_ loaded, it will handle this switch, and we
2114 ;; won't see it by the time we get here.
2115 ((equal argi "-no-desktop")
2116 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2118 ((string-match "^\\+[0-9]+\\'" argi)
2119 (setq line (string-to-number argi)))
2121 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2122 (setq line (string-to-number (match-string 1 argi))
2123 column (string-to-number (match-string 2 argi))))
2125 ((setq tem (assoc argi command-line-x-option-alist))
2126 ;; Ignore X-windows options and their args if not using X.
2127 (setq command-line-args-left
2128 (nthcdr (nth 1 tem) command-line-args-left)))
2130 ((member argi '("-find-file" "-file" "-visit"))
2131 (setq inhibit-startup-screen t)
2132 ;; An explicit option to specify visiting a file.
2133 (setq tem (or argval (pop command-line-args-left)))
2134 (unless (stringp tem)
2135 (error "File name omitted from `%s' option" argi))
2136 (setq file-count (1+ file-count))
2137 (let ((file (expand-file-name
2138 (command-line-normalize-file-name tem) dir)))
2139 (if (= file-count 1)
2140 (setq first-file-buffer (find-file file))
2141 (find-file-other-window file)))
2142 (or (zerop line)
2143 (goto-line line))
2144 (setq line 0)
2145 (unless (< column 1)
2146 (move-to-column (1- column)))
2147 (setq column 0))
2149 ((equal argi "--")
2150 (setq just-files t))
2152 ;; We have almost exhausted our options. See if the
2153 ;; user has made any other command-line options available
2154 (let ((hooks command-line-functions)
2155 (did-hook nil))
2156 (while (and hooks
2157 (not (setq did-hook (funcall (car hooks)))))
2158 (setq hooks (cdr hooks)))
2159 (if (not did-hook)
2160 ;; Presume that the argument is a file name.
2161 (progn
2162 (if (string-match "\\`-" argi)
2163 (error "Unknown option `%s'" argi))
2164 (unless initial-window-system
2165 (setq inhibit-startup-screen t))
2166 (setq file-count (1+ file-count))
2167 (let ((file
2168 (expand-file-name
2169 (command-line-normalize-file-name orig-argi)
2170 dir)))
2171 (cond ((= file-count 1)
2172 (setq first-file-buffer (find-file file)))
2173 (inhibit-startup-screen
2174 (find-file-other-window file))
2175 (t (find-file file))))
2176 (or (zerop line)
2177 (goto-line line))
2178 (setq line 0)
2179 (unless (< column 1)
2180 (move-to-column (1- column)))
2181 (setq column 0))))))
2182 ;; In unusual circumstances, the execution of Lisp code due
2183 ;; to command-line options can cause the last visible frame
2184 ;; to be deleted. In this case, kill emacs to avoid an
2185 ;; abort later.
2186 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2188 (when initial-buffer-choice
2189 (cond ((eq initial-buffer-choice t)
2190 (switch-to-buffer (get-buffer-create "*scratch*")))
2191 ((stringp initial-buffer-choice)
2192 (find-file initial-buffer-choice))))
2194 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2195 (and initial-scratch-message
2196 (get-buffer "*scratch*")
2197 (with-current-buffer "*scratch*"
2198 (when (zerop (buffer-size))
2199 (insert initial-scratch-message)
2200 (set-buffer-modified-p nil))))
2202 (if (or inhibit-startup-screen
2203 initial-buffer-choice
2204 noninteractive
2205 emacs-quick-startup)
2207 ;; Not displaying a startup screen. If 3 or more files
2208 ;; visited, and not all visible, show user what they all are.
2209 (and (> file-count 2)
2210 (not noninteractive)
2211 (not inhibit-startup-buffer-menu)
2212 (or (get-buffer-window first-file-buffer)
2213 (list-buffers)))
2215 ;; Display a startup screen, after some preparations.
2217 ;; If there are no switches to process, we might as well
2218 ;; run this hook now, and there may be some need to do it
2219 ;; before doing any output.
2220 (run-hooks 'emacs-startup-hook)
2221 (and term-setup-hook
2222 (run-hooks 'term-setup-hook))
2223 (setq inhibit-startup-hooks t)
2225 ;; It's important to notice the user settings before we
2226 ;; display the startup message; otherwise, the settings
2227 ;; won't take effect until the user gives the first
2228 ;; keystroke, and that's distracting.
2229 (when (fboundp 'frame-notice-user-settings)
2230 (frame-notice-user-settings))
2232 ;; If there are no switches to process, we might as well
2233 ;; run this hook now, and there may be some need to do it
2234 ;; before doing any output.
2235 (when window-setup-hook
2236 (run-hooks 'window-setup-hook)
2237 ;; Don't let the hook be run twice.
2238 (setq window-setup-hook nil))
2240 ;; ;; Do this now to avoid an annoying delay if the user
2241 ;; ;; clicks the menu bar during the sit-for.
2242 ;; (when (display-popup-menus-p)
2243 ;; (precompute-menubar-bindings))
2244 ;; (with-no-warnings
2245 ;; (setq menubar-bindings-done t))
2247 (if (> file-count 0)
2248 (display-startup-screen t)
2249 (display-startup-screen nil)))))
2251 (defun command-line-normalize-file-name (file)
2252 "Collapse multiple slashes to one, to handle non-Emacs file names."
2253 (save-match-data
2254 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2255 ;; That is significant on some systems.
2256 ;; However, /// at the beginning is supposed to mean just /, not //.
2257 (if (string-match "^///+" file)
2258 (setq file (replace-match "/" t t file)))
2259 (while (string-match "//+" file 1)
2260 (setq file (replace-match "/" t t file)))
2261 file))
2263 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
2264 ;;; startup.el ends here