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