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