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