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