Merged from miles@gnu.org--gnu-2005 (patch 681)
[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-splash-screen nil
51 "*Non-nil inhibits the startup screen.
52 This is for use in your personal init file, once you are familiar
53 with the contents of the startup screen."
54 :type 'boolean
55 :group 'initialization)
56
57 (defvaralias 'inhibit-startup-message 'inhibit-splash-screen)
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 ("-nbi" 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 preloaded file names to absolute.
651 (let ((lisp-dir
652 (file-name-directory
653 (locate-file "simple" load-path
654 load-suffixes))))
655
656 (setq load-history
657 (mapcar (lambda (elt)
658 (if (and (stringp (car elt))
659 (not (file-name-absolute-p (car elt))))
660 (cons (concat lisp-dir
661 (car elt)
662 (if (string-match "[.]el$" (car elt))
663 "" ".elc"))
664 (cdr elt))
665 elt))
666 load-history)))
667
668 ;; Convert the arguments to Emacs internal representation.
669 (let ((args (cdr command-line-args)))
670 (while args
671 (setcar args
672 (decode-coding-string (car args) locale-coding-system t))
673 (pop args)))
674
675 (let ((done nil)
676 (args (cdr command-line-args)))
677
678 ;; Figure out which user's init file to load,
679 ;; either from the environment or from the options.
680 (setq init-file-user (if noninteractive nil (user-login-name)))
681 ;; If user has not done su, use current $HOME to find .emacs.
682 (and init-file-user
683 (equal init-file-user (user-real-login-name))
684 (setq init-file-user ""))
685
686 ;; Process the command-line args, and delete the arguments
687 ;; processed. This is consistent with the way main in emacs.c
688 ;; does things.
689 (while (and (not done) args)
690 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
691 ("--user") ("--iconic") ("--icon-type") ("--quick")
692 ("--no-blinking-cursor") ("--basic-display")))
693 (argi (pop args))
694 (orig-argi argi)
695 argval)
696 ;; Handle --OPTION=VALUE format.
697 (when (string-match "^\\(--[^=]*\\)=" argi)
698 (setq argval (substring argi (match-end 0))
699 argi (match-string 1 argi)))
700 (unless (equal argi "--")
701 (let ((completion (try-completion argi longopts)))
702 (if (eq completion t)
703 (setq argi (substring argi 1))
704 (if (stringp completion)
705 (let ((elt (assoc completion longopts)))
706 (or elt
707 (error "Option `%s' is ambiguous" argi))
708 (setq argi (substring (car elt) 1)))
709 (setq argval nil
710 argi orig-argi)))))
711 (cond
712 ((member argi '("-Q" "-quick"))
713 (setq init-file-user nil
714 site-run-file nil
715 emacs-quick-startup t))
716 ((member argi '("-D" "-basic-display"))
717 (setq no-blinking-cursor t
718 emacs-basic-display t)
719 (push '(vertical-scroll-bars . nil) initial-frame-alist))
720 ((member argi '("-q" "-no-init-file"))
721 (setq init-file-user nil))
722 ((member argi '("-u" "-user"))
723 (setq init-file-user (or argval (pop args))
724 argval nil))
725 ((equal argi "-no-site-file")
726 (setq site-run-file nil))
727 ((equal argi "-debug-init")
728 (setq init-file-debug t))
729 ((equal argi "-iconic")
730 (push '(visibility . icon) initial-frame-alist))
731 ((member argi '("-icon-type" "-i" "-itype"))
732 (push '(icon-type . t) default-frame-alist))
733 ((member argi '("-nbc" "-no-blinking-cursor"))
734 (setq no-blinking-cursor t))
735 ;; Push the popped arg back on the list of arguments.
736 (t
737 (push argi args)
738 (setq done t)))
739 ;; Was argval set but not used?
740 (and argval
741 (error "Option `%s' doesn't allow an argument" argi))))
742
743 ;; Re-attach the program name to the front of the arg list.
744 (and command-line-args
745 (setcdr command-line-args args)))
746
747 (run-hooks 'before-init-hook)
748
749 ;; Under X Window, this creates the X frame and deletes the terminal frame.
750 (when (fboundp 'frame-initialize)
751 (frame-initialize))
752
753 ;; Turn off blinking cursor if so specified in X resources. This is here
754 ;; only because all other settings of no-blinking-cursor are here.
755 (unless (or noninteractive
756 emacs-basic-display
757 (and (memq window-system '(x w32 mac))
758 (not (member (x-get-resource "cursorBlink" "CursorBlink")
759 '("off" "false")))))
760 (setq no-blinking-cursor t))
761
762 ;; If frame was created with a menu bar, set menu-bar-mode on.
763 (unless (or noninteractive
764 emacs-basic-display
765 (and (memq initial-window-system '(x w32))
766 (<= (frame-parameter nil 'menu-bar-lines) 0)))
767 (menu-bar-mode 1))
768
769 ;; If frame was created with a tool bar, switch tool-bar-mode on.
770 (unless (or noninteractive
771 emacs-basic-display
772 (not (display-graphic-p))
773 (<= (frame-parameter nil 'tool-bar-lines) 0))
774 (tool-bar-mode 1))
775
776 ;; Can't do this init in defcustom because the relevant variables
777 ;; are not set.
778 (custom-reevaluate-setting 'blink-cursor-mode)
779 (custom-reevaluate-setting 'tooltip-mode)
780 (custom-reevaluate-setting 'global-font-lock-mode)
781 (custom-reevaluate-setting 'mouse-wheel-down-event)
782 (custom-reevaluate-setting 'mouse-wheel-up-event)
783 (custom-reevaluate-setting 'file-name-shadow-mode)
784 (custom-reevaluate-setting 'send-mail-function)
785
786 (normal-erase-is-backspace-setup-frame)
787
788 ;; Register default TTY colors for the case the terminal hasn't a
789 ;; terminal init file. We do this regardles of whether the terminal
790 ;; supports colors or not and regardless the current display type,
791 ;; since users can connect to color-capable terminals and also
792 ;; switch color support on or off in mid-session by setting the
793 ;; tty-color-mode frame parameter.
794 (tty-register-default-colors)
795
796 ;; Record whether the tool-bar is present before the user and site
797 ;; init files are processed. frame-notice-user-settings uses this
798 ;; to determine if the tool-bar has been disabled by the init files,
799 ;; and the frame needs to be resized.
800 (when (fboundp 'frame-notice-user-settings)
801 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
802 (assq 'tool-bar-lines default-frame-alist))))
803 (setq tool-bar-originally-present
804 (and tool-bar-lines
805 (cdr tool-bar-lines)
806 (not (eq 0 (cdr tool-bar-lines)))))))
807
808 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
809 (old-font-list-limit font-list-limit)
810 (old-face-ignored-fonts face-ignored-fonts))
811
812 ;; Run the site-start library if it exists. The point of this file is
813 ;; that it is run before .emacs. There is no point in doing this after
814 ;; .emacs; that is useless.
815 (if site-run-file
816 (load site-run-file t t))
817
818 ;; Sites should not disable this. Only individuals should disable
819 ;; the startup message.
820 (setq inhibit-startup-message nil)
821
822 ;; Warn for invalid user name.
823 (when init-file-user
824 (if (string-match "[~/:\n]" init-file-user)
825 (display-warning 'initialization
826 (format "Invalid user name %s"
827 init-file-user)
828 :error)
829 (if (file-directory-p (expand-file-name (concat "~" init-file-user)))
830 nil
831 (display-warning 'initialization
832 (format "User %s has no home directory"
833 init-file-user)
834 :error))))
835
836 ;; Load that user's init file, or the default one, or none.
837 (let (debug-on-error-from-init-file
838 debug-on-error-should-be-set
839 (debug-on-error-initial
840 (if (eq init-file-debug t) 'startup init-file-debug))
841 (orig-enable-multibyte default-enable-multibyte-characters))
842 (let ((debug-on-error debug-on-error-initial)
843 ;; This function actually reads the init files.
844 (inner
845 (function
846 (lambda ()
847 (if init-file-user
848 (let ((user-init-file-1
849 (cond
850 ((eq system-type 'ms-dos)
851 (concat "~" init-file-user "/_emacs"))
852 ((eq system-type 'windows-nt)
853 ;; Prefer .emacs on Windows.
854 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
855 "~/.emacs"
856 ;; Also support _emacs for compatibility.
857 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
858 "~/_emacs"
859 ;; But default to .emacs if _emacs does not exist.
860 "~/.emacs")))
861 ((eq system-type 'vax-vms)
862 "sys$login:.emacs")
863 (t
864 (concat "~" init-file-user "/.emacs")))))
865 ;; This tells `load' to store the file name found
866 ;; into user-init-file.
867 (setq user-init-file t)
868 (load user-init-file-1 t t)
869
870 (when (eq user-init-file t)
871 ;; If we did not find ~/.emacs, try
872 ;; ~/.emacs.d/init.el.
873 (let ((otherfile
874 (expand-file-name
875 "init"
876 (file-name-as-directory
877 (concat "~" init-file-user "/.emacs.d")))))
878 (load otherfile t t)
879
880 ;; If we did not find the user's init file,
881 ;; set user-init-file conclusively.
882 ;; Don't let it be set from default.el.
883 (when (eq user-init-file t)
884 (setq user-init-file user-init-file-1))))
885
886 ;; If we loaded a compiled file, set
887 ;; `user-init-file' to the source version if that
888 ;; exists.
889 (when (and user-init-file
890 (equal (file-name-extension user-init-file)
891 "elc"))
892 (let* ((source (file-name-sans-extension user-init-file))
893 (alt (concat source ".el")))
894 (setq source (cond ((file-exists-p alt) alt)
895 ((file-exists-p source) source)
896 (t nil)))
897 (when source
898 (when (file-newer-than-file-p source user-init-file)
899 (message "Warning: %s is newer than %s"
900 source user-init-file)
901 (sit-for 1))
902 (setq user-init-file source))))
903
904 (unless inhibit-default-init
905 (let ((inhibit-startup-message nil))
906 ;; Users are supposed to be told their rights.
907 ;; (Plus how to get help and how to undo.)
908 ;; Don't you dare turn this off for anyone
909 ;; except yourself.
910 (load "default" t t)))))))))
911 (if init-file-debug
912 ;; Do this without a condition-case if the user wants to debug.
913 (funcall inner)
914 (condition-case error
915 (progn
916 (funcall inner)
917 (setq init-file-had-error nil))
918 (error
919 (let ((message-log-max nil))
920 (save-excursion
921 (set-buffer (get-buffer-create "*Messages*"))
922 (insert "\n\n"
923 (format "An error has occurred while loading `%s':\n\n"
924 user-init-file)
925 (format "%s%s%s"
926 (get (car error) 'error-message)
927 (if (cdr error) ": " "")
928 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
929 "\n\n"
930 "To ensure normal operation, you should investigate and remove the\n"
931 "cause of the error in your initialization file. Start Emacs with\n"
932 "the `--debug-init' option to view a complete error backtrace.\n\n"))
933 (message "Error in init file: %s%s%s"
934 (get (car error) 'error-message)
935 (if (cdr error) ": " "")
936 (mapconcat 'prin1-to-string (cdr error) ", "))
937 (let ((pop-up-windows nil))
938 (pop-to-buffer "*Messages*"))
939 (setq init-file-had-error t)))))
940
941 (if (and deactivate-mark transient-mark-mode)
942 (with-current-buffer (window-buffer)
943 (deactivate-mark)))
944
945 ;; If the user has a file of abbrevs, read it.
946 (if (file-exists-p abbrev-file-name)
947 (quietly-read-abbrev-file abbrev-file-name))
948
949 ;; If the abbrevs came entirely from the init file or the
950 ;; abbrevs file, they do not need saving.
951 (setq abbrevs-changed nil)
952
953 ;; If we can tell that the init file altered debug-on-error,
954 ;; arrange to preserve the value that it set up.
955 (or (eq debug-on-error debug-on-error-initial)
956 (setq debug-on-error-should-be-set t
957 debug-on-error-from-init-file debug-on-error)))
958 (if debug-on-error-should-be-set
959 (setq debug-on-error debug-on-error-from-init-file))
960 (unless (or default-enable-multibyte-characters
961 (eq orig-enable-multibyte default-enable-multibyte-characters))
962 ;; Init file changed to unibyte. Reset existing multibyte
963 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
964 ;; Arguably this should only be done if they're free of
965 ;; multibyte characters.
966 (mapcar (lambda (buffer)
967 (with-current-buffer buffer
968 (if enable-multibyte-characters
969 (set-buffer-multibyte nil))))
970 (buffer-list))
971 ;; Also re-set the language environment in case it was
972 ;; originally done before unibyte was set and is sensitive to
973 ;; unibyte (display table, terminal coding system &c).
974 (set-language-environment current-language-environment)))
975
976 ;; Do this here in case the init file sets mail-host-address.
977 (if (equal user-mail-address "")
978 (setq user-mail-address (concat (user-login-name) "@"
979 (or mail-host-address
980 (system-name)))))
981
982 ;; Originally face attributes were specified via
983 ;; `font-lock-face-attributes'. Users then changed the default
984 ;; face attributes by setting that variable. However, we try and
985 ;; be back-compatible and respect its value if set except for
986 ;; faces where M-x customize has been used to save changes for the
987 ;; face.
988 (when (boundp 'font-lock-face-attributes)
989 (let ((face-attributes font-lock-face-attributes))
990 (while face-attributes
991 (let* ((face-attribute (pop face-attributes))
992 (face (car face-attribute)))
993 ;; Rustle up a `defface' SPEC from a
994 ;; `font-lock-face-attributes' entry.
995 (unless (get face 'saved-face)
996 (let ((foreground (nth 1 face-attribute))
997 (background (nth 2 face-attribute))
998 (bold-p (nth 3 face-attribute))
999 (italic-p (nth 4 face-attribute))
1000 (underline-p (nth 5 face-attribute))
1001 face-spec)
1002 (when foreground
1003 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1004 (when background
1005 (setq face-spec (cons ':background (cons background face-spec))))
1006 (when bold-p
1007 (setq face-spec (append '(:weight bold) face-spec)))
1008 (when italic-p
1009 (setq face-spec (append '(:slant italic) face-spec)))
1010 (when underline-p
1011 (setq face-spec (append '(:underline t) face-spec)))
1012 (face-spec-set face (list (list t face-spec)) nil)))))))
1013
1014 ;; If parameter have been changed in the init file which influence
1015 ;; face realization, clear the face cache so that new faces will
1016 ;; be realized.
1017 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1018 (eq font-list-limit old-font-list-limit)
1019 (eq face-ignored-fonts old-face-ignored-fonts))
1020 (clear-face-cache)))
1021
1022 (run-hooks 'after-init-hook)
1023
1024 ;; Decode all default-directory.
1025 (if (and default-enable-multibyte-characters locale-coding-system)
1026 (save-excursion
1027 (dolist (elt (buffer-list))
1028 (set-buffer elt)
1029 (if default-directory
1030 (setq default-directory
1031 (decode-coding-string default-directory
1032 locale-coding-system t))))
1033 (setq command-line-default-directory
1034 (decode-coding-string command-line-default-directory
1035 locale-coding-system t))))
1036
1037 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1038 (if (get-buffer "*scratch*")
1039 (with-current-buffer "*scratch*"
1040 (if (eq major-mode 'fundamental-mode)
1041 (funcall initial-major-mode))))
1042
1043 ;; Load library for our terminal type.
1044 ;; User init file can set term-file-prefix to nil to prevent this.
1045 (unless (or noninteractive
1046 initial-window-system)
1047 (tty-run-terminal-initialization (selected-frame)))
1048
1049 ;; Update the out-of-memory error message based on user's key bindings
1050 ;; for save-some-buffers.
1051 (setq memory-signal-data
1052 (list 'error
1053 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1054
1055 ;; Process the remaining args.
1056 (command-line-1 (cdr command-line-args))
1057
1058 ;; If -batch, terminate after processing the command options.
1059 (if noninteractive (kill-emacs t))
1060
1061 ;; Run emacs-session-restore (session management) if started by
1062 ;; the session manager and we have a session manager connection.
1063 (if (and (boundp 'x-session-previous-id)
1064 (stringp x-session-previous-id))
1065 (with-no-warnings
1066 (emacs-session-restore x-session-previous-id))))
1067
1068 (defcustom initial-scratch-message (purecopy "\
1069 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1070 ;; If you want to create a file, visit that file with C-x C-f,
1071 ;; then enter the text in that file's own buffer.
1072
1073 ")
1074 "Initial message displayed in *scratch* buffer at startup.
1075 If this is nil, no message will be displayed."
1076 :type '(choice (text :tag "Message")
1077 (const :tag "none" nil))
1078 :group 'initialization)
1079
1080 \f
1081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1082 ;;; Fancy splash screen
1083 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1084
1085 (defvar fancy-splash-text
1086 '((:face variable-pitch
1087 "You can do basic editing with the menu bar and scroll bar \
1088 using the mouse.\n\n"
1089 :face (variable-pitch :weight bold)
1090 "Important Help menu items:\n"
1091 :face variable-pitch
1092 (lambda ()
1093 (let* ((en "TUTORIAL")
1094 (tut (or (get-language-info current-language-environment
1095 'tutorial)
1096 en))
1097 (title (with-temp-buffer
1098 (insert-file-contents
1099 (expand-file-name tut data-directory)
1100 nil 0 256)
1101 (search-forward ".")
1102 (buffer-substring (point-min) (1- (point))))))
1103 ;; If there is a specific tutorial for the current language
1104 ;; environment and it is not English, append its title.
1105 (concat
1106 "Emacs Tutorial\tLearn how to use Emacs efficiently"
1107 (if (string= en tut)
1108 ""
1109 (concat " (" title ")"))
1110 "\n")))
1111 :face variable-pitch "\
1112 Emacs FAQ\tFrequently asked questions and answers
1113 Read the Emacs Manual\tView the Emacs manual using Info
1114 \(Non)Warranty\tGNU Emacs comes with "
1115 :face (variable-pitch :slant oblique)
1116 "ABSOLUTELY NO WARRANTY\n"
1117 :face variable-pitch
1118 "\
1119 Copying Conditions\tConditions for redistributing and changing Emacs
1120 Getting New Versions\tHow to obtain the latest version of Emacs
1121 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1122 (:face variable-pitch
1123 "You can do basic editing with the menu bar and scroll bar \
1124 using the mouse.\n\n"
1125 :face (variable-pitch :weight bold)
1126 "Useful File menu items:\n"
1127 :face variable-pitch "\
1128 Exit Emacs\t(Or type Control-x followed by Control-c)
1129 Recover Crashed Session\tRecover files you were editing before a crash
1130
1131
1132
1133
1134 "
1135 ))
1136 "A list of texts to show in the middle part of splash screens.
1137 Each element in the list should be a list of strings or pairs
1138 `:face FACE', like `fancy-splash-insert' accepts them.")
1139
1140
1141 (defgroup fancy-splash-screen ()
1142 "Fancy splash screen when Emacs starts."
1143 :version "21.1"
1144 :group 'initialization)
1145
1146
1147 (defcustom fancy-splash-delay 7
1148 "*Delay in seconds between splash screens."
1149 :group 'fancy-splash-screen
1150 :type 'integer)
1151
1152
1153 (defcustom fancy-splash-max-time 30
1154 "*Show splash screens for at most this number of seconds.
1155 Values less than twice `fancy-splash-delay' are ignored."
1156 :group 'fancy-splash-screen
1157 :type 'integer)
1158
1159
1160 (defcustom fancy-splash-image nil
1161 "*The image to show in the splash screens, or nil for defaults."
1162 :group 'fancy-splash-screen
1163 :type '(choice (const :tag "Default" nil)
1164 (file :tag "File")))
1165
1166
1167 ;; These are temporary storage areas for the splash screen display.
1168
1169 (defvar fancy-current-text nil)
1170 (defvar fancy-splash-help-echo nil)
1171 (defvar fancy-splash-stop-time nil)
1172 (defvar fancy-splash-outer-buffer nil)
1173
1174 (defun fancy-splash-insert (&rest args)
1175 "Insert text into the current buffer, with faces.
1176 Arguments from ARGS should be either strings, functions called
1177 with no args that return a string, or pairs `:face FACE',
1178 where FACE is a valid face specification, as it can be used with
1179 `put-text-property'."
1180 (let ((current-face nil))
1181 (while args
1182 (if (eq (car args) :face)
1183 (setq args (cdr args) current-face (car args))
1184 (insert (propertize (let ((it (car args)))
1185 (if (functionp it)
1186 (funcall it)
1187 it))
1188 'face current-face
1189 'help-echo fancy-splash-help-echo)))
1190 (setq args (cdr args)))))
1191
1192
1193 (defun fancy-splash-head ()
1194 "Insert the head part of the splash screen into the current buffer."
1195 (let* ((image-file (cond ((stringp fancy-splash-image)
1196 fancy-splash-image)
1197 ((and (display-color-p)
1198 (image-type-available-p 'xpm))
1199 (if (and (fboundp 'x-display-planes)
1200 (= (funcall 'x-display-planes) 8))
1201 "splash8.xpm"
1202 "splash.xpm"))
1203 (t "splash.pbm")))
1204 (img (create-image image-file))
1205 (image-width (and img (car (image-size img))))
1206 (window-width (window-width (selected-window))))
1207 (when img
1208 (when (> window-width image-width)
1209 ;; Center the image in the window.
1210 (insert (propertize " " 'display
1211 `(space :align-to (+ center (-0.5 . ,img)))))
1212
1213 ;; Change the color of the XPM version of the splash image
1214 ;; so that it is visible with a dark frame background.
1215 (when (and (memq 'xpm img)
1216 (eq (frame-parameter nil 'background-mode) 'dark))
1217 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1218
1219 ;; Insert the image with a help-echo and a keymap.
1220 (let ((map (make-sparse-keymap))
1221 (help-echo "mouse-2: browse http://www.gnu.org/"))
1222 (define-key map [mouse-2]
1223 (lambda ()
1224 (interactive)
1225 (browse-url "http://www.gnu.org/")
1226 (throw 'exit nil)))
1227 (define-key map [down-mouse-2] 'ignore)
1228 (define-key map [up-mouse-2] 'ignore)
1229 (insert-image img (propertize "xxx" 'help-echo help-echo
1230 'keymap map)))
1231 (insert "\n"))))
1232 (fancy-splash-insert
1233 :face '(variable-pitch :foreground "red")
1234 (if (eq system-type 'gnu/linux)
1235 "GNU Emacs is one component of the GNU/Linux operating system."
1236 "GNU Emacs is one component of the GNU operating system."))
1237 (insert "\n")
1238 (unless (equal (buffer-name fancy-splash-outer-buffer) "*scratch*")
1239 (fancy-splash-insert :face 'variable-pitch
1240 (substitute-command-keys
1241 "Type \\[recenter] to begin editing your file.\n"))))
1242
1243
1244 (defun fancy-splash-tail ()
1245 "Insert the tail part of the splash screen into the current buffer."
1246 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1247 "cyan" "darkblue")))
1248 (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
1249 "\nThis is "
1250 (emacs-version)
1251 "\n"
1252 :face '(variable-pitch :height 0.5)
1253 "Copyright (C) 2005 Free Software Foundation, Inc.")
1254 (and auto-save-list-file-prefix
1255 ;; Don't signal an error if the
1256 ;; directory for auto-save-list files
1257 ;; does not yet exist.
1258 (file-directory-p (file-name-directory
1259 auto-save-list-file-prefix))
1260 (directory-files
1261 (file-name-directory auto-save-list-file-prefix)
1262 nil
1263 (concat "\\`"
1264 (regexp-quote (file-name-nondirectory
1265 auto-save-list-file-prefix)))
1266 t)
1267 (fancy-splash-insert :face '(variable-pitch :foreground "red")
1268 "\n\nIf an Emacs session crashed recently, "
1269 "type M-x recover-session RET\nto recover"
1270 " the files you were editing."))))
1271
1272 (defun fancy-splash-screens-1 (buffer)
1273 "Timer function displaying a splash screen."
1274 (when (> (float-time) fancy-splash-stop-time)
1275 (throw 'stop-splashing nil))
1276 (unless fancy-current-text
1277 (setq fancy-current-text fancy-splash-text))
1278 (let ((text (car fancy-current-text)))
1279 (set-buffer buffer)
1280 (erase-buffer)
1281 (if pure-space-overflow
1282 (insert "Warning Warning Pure space overflow Warning Warning\n"))
1283 (fancy-splash-head)
1284 (apply #'fancy-splash-insert text)
1285 (fancy-splash-tail)
1286 (unless (current-message)
1287 (message fancy-splash-help-echo))
1288 (set-buffer-modified-p nil)
1289 (goto-char (point-min))
1290 (force-mode-line-update)
1291 (setq fancy-current-text (cdr fancy-current-text))))
1292
1293
1294 (defun fancy-splash-default-action ()
1295 "Stop displaying the splash screen buffer.
1296 This is an internal function used to turn off the splash screen after
1297 the user caused an input event by hitting a key or clicking with the
1298 mouse."
1299 (interactive)
1300 (if (and (memq 'down (event-modifiers last-command-event))
1301 (eq (posn-window (event-start last-command-event))
1302 (selected-window)))
1303 ;; This is a mouse-down event in the spash screen window.
1304 ;; Ignore it and consume the corresponding mouse-up event.
1305 (read-event)
1306 (push last-command-event unread-command-events))
1307 (throw 'exit nil))
1308
1309
1310 (defun fancy-splash-screens ()
1311 "Display fancy splash screens when Emacs starts."
1312 (setq fancy-splash-help-echo (startup-echo-area-message))
1313 (let ((old-hourglass display-hourglass)
1314 (fancy-splash-outer-buffer (current-buffer))
1315 splash-buffer
1316 (old-minor-mode-map-alist minor-mode-map-alist)
1317 (frame (fancy-splash-frame))
1318 timer)
1319 (save-selected-window
1320 (select-frame frame)
1321 (switch-to-buffer "GNU Emacs")
1322 (setq tab-width 20)
1323 (setq splash-buffer (current-buffer))
1324 (catch 'stop-splashing
1325 (unwind-protect
1326 (let ((map (make-sparse-keymap)))
1327 (use-local-map map)
1328 (define-key map [switch-frame] 'ignore)
1329 (define-key map [t] 'fancy-splash-default-action)
1330 (define-key map [mouse-movement] 'ignore)
1331 (define-key map [mode-line t] 'ignore)
1332 (setq cursor-type nil
1333 display-hourglass nil
1334 minor-mode-map-alist nil
1335 buffer-undo-list t
1336 mode-line-format (propertize "---- %b %-"
1337 'face '(:weight bold))
1338 fancy-splash-stop-time (+ (float-time)
1339 fancy-splash-max-time)
1340 timer (run-with-timer 0 fancy-splash-delay
1341 #'fancy-splash-screens-1
1342 splash-buffer))
1343 (recursive-edit))
1344 (cancel-timer timer)
1345 (setq display-hourglass old-hourglass
1346 minor-mode-map-alist old-minor-mode-map-alist)
1347 (kill-buffer splash-buffer))))))
1348
1349 (defun fancy-splash-frame ()
1350 "Return the frame to use for the fancy splash screen.
1351 Returning non-nil does not mean we should necessarily
1352 use the fancy splash screen, but if we do use it,
1353 we put it on this frame."
1354 (let (chosen-frame)
1355 (dolist (frame (append (frame-list) (list (selected-frame))))
1356 (if (and (frame-visible-p frame)
1357 (not (window-minibuffer-p (frame-selected-window frame))))
1358 (setq chosen-frame frame)))
1359 chosen-frame))
1360
1361 (defun use-fancy-splash-screens-p ()
1362 "Return t if fancy splash screens should be used."
1363 (when (and (display-graphic-p)
1364 (or (and (display-color-p)
1365 (image-type-available-p 'xpm))
1366 (image-type-available-p 'pbm)))
1367 (let ((frame (fancy-splash-frame)))
1368 (when frame
1369 (let* ((img (create-image (or fancy-splash-image
1370 (if (and (display-color-p)
1371 (image-type-available-p 'xpm))
1372 "splash.xpm" "splash.pbm"))))
1373 (image-height (and img (cdr (image-size img))))
1374 (window-height (1- (window-height (frame-selected-window frame)))))
1375 (> window-height (+ image-height 19)))))))
1376
1377
1378 (defun normal-splash-screen ()
1379 "Display splash screen when Emacs starts."
1380 (let ((prev-buffer (current-buffer)))
1381 (unwind-protect
1382 (with-current-buffer (get-buffer-create "GNU Emacs")
1383 (let ((tab-width 8)
1384 (mode-line-format (propertize "---- %b %-"
1385 'face '(:weight bold))))
1386
1387 (if pure-space-overflow
1388 (insert "Warning Warning Pure space overflow Warning Warning\n"))
1389
1390 ;; The convention for this piece of code is that
1391 ;; each piece of output starts with one or two newlines
1392 ;; and does not end with any newlines.
1393 (insert "Welcome to GNU Emacs")
1394 (insert
1395 (if (eq system-type 'gnu/linux)
1396 ", one component of the GNU/Linux operating system.\n"
1397 ", a part of the GNU operating system.\n"))
1398
1399 (unless (equal (buffer-name prev-buffer) "*scratch*")
1400 (insert (substitute-command-keys
1401 "\nType \\[recenter] to begin editing your file.\n")))
1402
1403 (if (display-mouse-p)
1404 ;; The user can use the mouse to activate menus
1405 ;; so give help in terms of menu items.
1406 (progn
1407 (insert "\
1408 You can do basic editing with the menu bar and scroll bar using the mouse.
1409
1410 Useful File menu items:
1411 Exit Emacs (or type Control-x followed by Control-c)
1412 Recover Crashed Session Recover files you were editing before a crash
1413
1414 Important Help menu items:
1415 Emacs Tutorial Learn how to use Emacs efficiently
1416 Emacs FAQ Frequently asked questions and answers
1417 Read the Emacs Manual View the Emacs manual using Info
1418 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1419 Copying Conditions Conditions for redistributing and changing Emacs
1420 Getting New Versions How to obtain the latest version of Emacs
1421 More Manuals / Ordering Manuals How to order printed manuals from the FSF
1422 ")
1423 (insert "\n\n" (emacs-version)
1424 "
1425 Copyright (C) 2005 Free Software Foundation, Inc."))
1426
1427 ;; No mouse menus, so give help using kbd commands.
1428
1429 ;; If keys have their default meanings,
1430 ;; use precomputed string to save lots of time.
1431 (if (and (eq (key-binding "\C-h") 'help-command)
1432 (eq (key-binding "\C-xu") 'advertised-undo)
1433 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-display)
1434 (eq (key-binding "\C-ht") 'help-with-tutorial)
1435 (eq (key-binding "\C-hi") 'info)
1436 (eq (key-binding "\C-hr") 'info-emacs-manual)
1437 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1438 (insert "
1439 Get help C-h (Hold down CTRL and press h)
1440 Emacs manual C-h r
1441 Emacs tutorial C-h t Undo changes C-x u
1442 Buy manuals C-h C-m Exit Emacs C-x C-c
1443 Browse manuals C-h i")
1444
1445 (insert (substitute-command-keys
1446 (format "\n
1447 Get help %s
1448 Emacs manual \\[info-emacs-manual]
1449 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1450 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-display]
1451 Browse manuals \\[info]"
1452 (let ((where (where-is-internal
1453 'help-command nil t)))
1454 (if where
1455 (key-description where)
1456 "M-x help"))))))
1457
1458 ;; Say how to use the menu bar with the keyboard.
1459 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1460 (eq (key-binding [f10]) 'tmm-menubar))
1461 (insert "
1462 Activate menubar F10 or ESC ` or M-`")
1463 (insert (substitute-command-keys "
1464 Activate menubar \\[tmm-menubar]")))
1465
1466 ;; Many users seem to have problems with these.
1467 (insert "
1468 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1469 If you have no Meta key, you may instead type ESC followed by the character.)")
1470
1471 (insert "\n\n" (emacs-version)
1472 "
1473 Copyright (C) 2005 Free Software Foundation, Inc.")
1474
1475 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1476 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1477 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1478 (insert
1479 "\n
1480 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1481 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1482 of Emacs and modify it; type C-h C-c to see the conditions.
1483 Type C-h C-d for information on getting the latest version.")
1484 (insert (substitute-command-keys
1485 "\n
1486 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1487 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1488 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1489 Type \\[describe-distribution] for information on getting the latest version."))))
1490
1491 ;; The rest of the startup screen is the same on all
1492 ;; kinds of terminals.
1493
1494 ;; Give information on recovering, if there was a crash.
1495 (and auto-save-list-file-prefix
1496 ;; Don't signal an error if the
1497 ;; directory for auto-save-list files
1498 ;; does not yet exist.
1499 (file-directory-p (file-name-directory
1500 auto-save-list-file-prefix))
1501 (directory-files
1502 (file-name-directory auto-save-list-file-prefix)
1503 nil
1504 (concat "\\`"
1505 (regexp-quote (file-name-nondirectory
1506 auto-save-list-file-prefix)))
1507 t)
1508 (insert "\n\nIf an Emacs session crashed recently, "
1509 "type M-x recover-session RET\nto recover"
1510 " the files you were editing."))
1511
1512 ;; Display the input that we set up in the buffer.
1513 (set-buffer-modified-p nil)
1514 (goto-char (point-min))
1515 (save-window-excursion
1516 (switch-to-buffer (current-buffer))
1517 (sit-for 120))))
1518 ;; Unwind ... ensure splash buffer is killed
1519 (kill-buffer "GNU Emacs"))))
1520
1521
1522 (defun startup-echo-area-message ()
1523 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1524 "For information about the GNU Project and its goals, type C-h C-p."
1525 (substitute-command-keys
1526 "For information about the GNU Project and its goals, type \
1527 \\[describe-project].")))
1528
1529
1530 (defun display-startup-echo-area-message ()
1531 (let ((resize-mini-windows t))
1532 (message "%s" (startup-echo-area-message))))
1533
1534
1535 (defun display-splash-screen ()
1536 "Display splash screen according to display.
1537 Fancy splash screens are used on graphic displays,
1538 normal otherwise."
1539 (interactive)
1540 (if (use-fancy-splash-screens-p)
1541 (fancy-splash-screens)
1542 (normal-splash-screen)))
1543
1544
1545 (defun command-line-1 (command-line-args-left)
1546 (or noninteractive (input-pending-p) init-file-had-error
1547 ;; t if the init file says to inhibit the echo area startup message.
1548 (and inhibit-startup-echo-area-message
1549 user-init-file
1550 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1551 (equal inhibit-startup-echo-area-message
1552 (if (equal init-file-user "")
1553 (user-login-name)
1554 init-file-user)))
1555 ;; Wasn't set with custom; see if .emacs has a setq.
1556 (let ((buffer (get-buffer-create " *temp*")))
1557 (prog1
1558 (condition-case nil
1559 (save-excursion
1560 (set-buffer buffer)
1561 (insert-file-contents user-init-file)
1562 (re-search-forward
1563 (concat
1564 "([ \t\n]*setq[ \t\n]+"
1565 "inhibit-startup-echo-area-message[ \t\n]+"
1566 (regexp-quote
1567 (prin1-to-string
1568 (if (equal init-file-user "")
1569 (user-login-name)
1570 init-file-user)))
1571 "[ \t\n]*)")
1572 nil t))
1573 (error nil))
1574 (kill-buffer buffer)))))
1575 ;; display-splash-screen at the end of command-line-1 calls
1576 ;; use-fancy-splash-screens-p. This can cause image.el to be
1577 ;; loaded, putting "Loading image... done" in the echo area.
1578 ;; This hides startup-echo-area-message. So
1579 ;; use-fancy-splash-screens-p is called here simply to get the
1580 ;; loading of image.el (if needed) out of the way before
1581 ;; display-startup-echo-area-message runs.
1582 (progn
1583 (use-fancy-splash-screens-p)
1584 (display-startup-echo-area-message)))
1585
1586 ;; Delay 2 seconds after an init file error message
1587 ;; was displayed, so user can read it.
1588 (when init-file-had-error
1589 (sit-for 2))
1590
1591 (when command-line-args-left
1592 ;; We have command args; process them.
1593 (let ((dir command-line-default-directory)
1594 (file-count 0)
1595 first-file-buffer
1596 tem
1597 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1598 ;; if foo is intended to be found in DIR.
1599 ;;
1600 ;; ;; The directories listed in --directory/-L options will *appear*
1601 ;; ;; at the front of `load-path' in the order they appear on the
1602 ;; ;; command-line. We cannot do this by *placing* them at the front
1603 ;; ;; in the order they appear, so we need this variable to hold them,
1604 ;; ;; temporarily.
1605 ;; extra-load-path
1606 ;;
1607 ;; To DTRT we keep track of the splice point and modify `load-path'
1608 ;; straight away upon any --directory/-L option.
1609 splice
1610 just-files ;; t if this follows the magic -- option.
1611 ;; This includes our standard options' long versions
1612 ;; and long versions of what's on command-switch-alist.
1613 (longopts
1614 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1615 ("--directory") ("--eval") ("--execute") ("--no-splash")
1616 ("--find-file") ("--visit") ("--file"))
1617 (mapcar (lambda (elt)
1618 (list (concat "-" (car elt))))
1619 command-switch-alist)))
1620 (line 0)
1621 (column 0))
1622
1623 ;; Add the long X options to longopts.
1624 (dolist (tem command-line-x-option-alist)
1625 (if (string-match "^--" (car tem))
1626 (push (list (car tem)) longopts)))
1627
1628 ;; Loop, processing options.
1629 (while command-line-args-left
1630 (let* ((argi (car command-line-args-left))
1631 (orig-argi argi)
1632 argval completion)
1633 (setq command-line-args-left (cdr command-line-args-left))
1634
1635 ;; Do preliminary decoding of the option.
1636 (if just-files
1637 ;; After --, don't look for options; treat all args as files.
1638 (setq argi "")
1639 ;; Convert long options to ordinary options
1640 ;; and separate out an attached option argument into argval.
1641 (when (string-match "^\\(--[^=]*\\)=" argi)
1642 (setq argval (substring argi (match-end 0))
1643 argi (match-string 1 argi)))
1644 (if (equal argi "--")
1645 (setq completion nil)
1646 (setq completion (try-completion argi longopts)))
1647 (if (eq completion t)
1648 (setq argi (substring argi 1))
1649 (if (stringp completion)
1650 (let ((elt (assoc completion longopts)))
1651 (or elt
1652 (error "Option `%s' is ambiguous" argi))
1653 (setq argi (substring (car elt) 1)))
1654 (setq argval nil
1655 argi orig-argi))))
1656
1657 ;; Execute the option.
1658 (cond ((setq tem (assoc argi command-switch-alist))
1659 (if argval
1660 (let ((command-line-args-left
1661 (cons argval command-line-args-left)))
1662 (funcall (cdr tem) argi))
1663 (funcall (cdr tem) argi)))
1664
1665 ((equal argi "-no-splash")
1666 (setq inhibit-startup-message t))
1667
1668 ((member argi '("-f" ; what the manual claims
1669 "-funcall"
1670 "-e")) ; what the source used to say
1671 (setq tem (intern (or argval (pop command-line-args-left))))
1672 (if (commandp tem)
1673 (command-execute tem)
1674 (funcall tem)))
1675
1676 ((member argi '("-eval" "-execute"))
1677 (eval (read (or argval (pop command-line-args-left)))))
1678
1679 ((member argi '("-L" "-directory"))
1680 (setq tem (expand-file-name
1681 (command-line-normalize-file-name
1682 (or argval (pop command-line-args-left)))))
1683 (cond (splice (setcdr splice (cons tem (cdr splice)))
1684 (setq splice (cdr splice)))
1685 (t (setq load-path (cons tem load-path)
1686 splice load-path))))
1687
1688 ((member argi '("-l" "-load"))
1689 (let* ((file (command-line-normalize-file-name
1690 (or argval (pop command-line-args-left))))
1691 ;; Take file from default dir if it exists there;
1692 ;; otherwise let `load' search for it.
1693 (file-ex (expand-file-name file)))
1694 (when (file-exists-p file-ex)
1695 (setq file file-ex))
1696 (load file nil t)))
1697
1698 ;; This is used to handle -script. It's not clear
1699 ;; we need to document it.
1700 ((member argi '("-scriptload"))
1701 (let* ((file (command-line-normalize-file-name
1702 (or argval (pop command-line-args-left))))
1703 ;; Take file from default dir.
1704 (file-ex (expand-file-name file)))
1705 (load file-ex nil t t)))
1706
1707 ((equal argi "-insert")
1708 (setq tem (or argval (pop command-line-args-left)))
1709 (or (stringp tem)
1710 (error "File name omitted from `-insert' option"))
1711 (insert-file-contents (command-line-normalize-file-name tem)))
1712
1713 ((equal argi "-kill")
1714 (kill-emacs t))
1715
1716 ((string-match "^\\+[0-9]+\\'" argi)
1717 (setq line (string-to-number argi)))
1718
1719 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1720 (setq line (string-to-number (match-string 1 argi))
1721 column (string-to-number (match-string 2 argi))))
1722
1723 ((setq tem (assoc argi command-line-x-option-alist))
1724 ;; Ignore X-windows options and their args if not using X.
1725 (setq command-line-args-left
1726 (nthcdr (nth 1 tem) command-line-args-left)))
1727
1728 ((member argi '("-find-file" "-file" "-visit"))
1729 ;; An explicit option to specify visiting a file.
1730 (setq tem (or argval (pop command-line-args-left)))
1731 (unless (stringp tem)
1732 (error "File name omitted from `%s' option" argi))
1733 (setq file-count (1+ file-count))
1734 (let ((file (expand-file-name
1735 (command-line-normalize-file-name tem) dir)))
1736 (if (= file-count 1)
1737 (setq first-file-buffer (find-file file))
1738 (find-file-other-window file)))
1739 (or (zerop line)
1740 (goto-line line))
1741 (setq line 0)
1742 (unless (< column 1)
1743 (move-to-column (1- column)))
1744 (setq column 0))
1745
1746 ((equal argi "--")
1747 (setq just-files t))
1748 (t
1749 ;; We have almost exhausted our options. See if the
1750 ;; user has made any other command-line options available
1751 (let ((hooks command-line-functions) ;; lrs 7/31/89
1752 (did-hook nil))
1753 (while (and hooks
1754 (not (setq did-hook (funcall (car hooks)))))
1755 (setq hooks (cdr hooks)))
1756 (if (not did-hook)
1757 ;; Presume that the argument is a file name.
1758 (progn
1759 (if (string-match "\\`-" argi)
1760 (error "Unknown option `%s'" argi))
1761 (setq file-count (1+ file-count))
1762 (let ((file
1763 (expand-file-name
1764 (command-line-normalize-file-name orig-argi)
1765 dir)))
1766 (if (= file-count 1)
1767 (setq first-file-buffer (find-file file))
1768 (find-file-other-window file)))
1769 (or (zerop line)
1770 (goto-line line))
1771 (setq line 0)
1772 (unless (< column 1)
1773 (move-to-column (1- column)))
1774 (setq column 0))))))))
1775
1776 ;; If 3 or more files visited, and not all visible,
1777 ;; show user what they all are. But leave the last one current.
1778 (and (> file-count 2)
1779 (not noninteractive)
1780 (not inhibit-startup-buffer-menu)
1781 (or (get-buffer-window first-file-buffer)
1782 (list-buffers)))))
1783
1784 ;; Maybe display a startup screen.
1785 (unless (or inhibit-startup-message
1786 noninteractive
1787 emacs-quick-startup)
1788 ;; Display a startup screen, after some preparations.
1789
1790 ;; If there are no switches to process, we might as well
1791 ;; run this hook now, and there may be some need to do it
1792 ;; before doing any output.
1793 (run-hooks 'emacs-startup-hook)
1794 (and term-setup-hook
1795 (run-hooks 'term-setup-hook))
1796 (setq inhibit-startup-hooks t)
1797
1798 ;; It's important to notice the user settings before we
1799 ;; display the startup message; otherwise, the settings
1800 ;; won't take effect until the user gives the first
1801 ;; keystroke, and that's distracting.
1802 (when (fboundp 'frame-notice-user-settings)
1803 (frame-notice-user-settings))
1804
1805 ;; If there are no switches to process, we might as well
1806 ;; run this hook now, and there may be some need to do it
1807 ;; before doing any output.
1808 (when window-setup-hook
1809 (run-hooks 'window-setup-hook)
1810 ;; Don't let the hook be run twice.
1811 (setq window-setup-hook nil))
1812
1813 ;; Do this now to avoid an annoying delay if the user
1814 ;; clicks the menu bar during the sit-for.
1815 (when (display-popup-menus-p)
1816 (precompute-menubar-bindings))
1817 (with-no-warnings
1818 (setq menubar-bindings-done t))
1819
1820 ;; If *scratch* is selected and it is empty, insert an
1821 ;; initial message saying not to create a file there.
1822 (when (and initial-scratch-message
1823 (equal (buffer-name) "*scratch*")
1824 (= 0 (buffer-size)))
1825 (insert initial-scratch-message)
1826 (set-buffer-modified-p nil))
1827
1828 ;; If user typed input during all that work,
1829 ;; abort the startup screen. Otherwise, display it now.
1830 (unless (input-pending-p)
1831 (display-splash-screen))))
1832
1833
1834 (defun command-line-normalize-file-name (file)
1835 "Collapse multiple slashes to one, to handle non-Emacs file names."
1836 (save-match-data
1837 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1838 ;; That is significant on some systems.
1839 ;; However, /// at the beginning is supposed to mean just /, not //.
1840 (if (string-match "^///+" file)
1841 (setq file (replace-match "/" t t file)))
1842 (while (string-match "//+" file 1)
1843 (setq file (replace-match "/" t t file)))
1844 file))
1845
1846 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
1847 ;;; startup.el ends here