1 ;;; startup.el --- process XEmacs shell arguments
3 ;; Copyright (C) 1985-1986, 1990, 1992-1997 Free Software Foundation, Inc.
4 ;; Copyright (c) 1993, 1994 Sun Microsystems, Inc.
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
7 ;; Maintainer: XEmacs Development Team
8 ;; Keywords: internal, dumped
10 ;; This file is part of XEmacs.
12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; XEmacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Synched up with: FSF 19.34.
31 ;; This file is dumped with XEmacs.
33 ;; -batch, -t, and -nw are processed by main() in emacs.c and are
34 ;; never seen by lisp code.
36 ;; -version and -help are special-cased as well: they imply -batch,
37 ;; but are left on the list for lisp code to process.
41 (setq top-level '(normal-top-level))
43 (defvar command-line-processed nil "t once command line has been processed")
45 (defconst startup-message-timeout 12000) ; More or less disable the timeout
46 (defconst splash-frame-timeout 7) ; interval between splash frame elements
48 (defconst inhibit-startup-message nil
49 "*Non-nil inhibits the initial startup message.
50 This is for use in your personal init file, once you are familiar
51 with the contents of the startup message.")
53 ;; #### FSFmacs randomness
54 ;;(defconst inhibit-startup-echo-area-message nil
55 ;; "*Non-nil inhibits the initial startup echo area message.
56 ;;Inhibition takes effect only if your `.emacs' file contains
57 ;;a line of this form:
58 ;; (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
59 ;;If your `.emacs' file is byte-compiled, use the following form instead:
60 ;; (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
61 ;;Thus, someone else using a copy of your `.emacs' file will see
62 ;;the startup message unless he personally acts to inhibit it.")
64 (defconst inhibit-default-init nil
65 "*Non-nil inhibits loading the `default' library.")
67 (defvar command-line-args-left nil
68 "List of command-line args not yet processed.") ; bound by `command-line'
70 (defvar command-line-default-directory nil
71 "Default directory to use for command line arguments.
72 This is normally copied from `default-directory' when XEmacs starts.")
74 (defvar before-init-hook nil
75 "Functions to call after handling urgent options but before init files.
76 The frame system uses this to open frames to display messages while
77 XEmacs loads the user's initialization file.")
79 (defvar after-init-hook nil
80 "*Functions to call after loading the init file (`.emacs').
81 The call is not protected by a condition-case, so you can set `debug-on-error'
82 in `.emacs', and put all the actual code on `after-init-hook'.")
84 (defvar term-setup-hook nil
85 "*Functions to be called after loading terminal-specific Lisp code.
86 See `run-hooks'. This variable exists for users to set, so as to
87 override the definitions made by the terminal-specific file. XEmacs
88 never sets this variable itself.")
90 (defvar keyboard-type nil
91 "The brand of keyboard you are using.
92 This variable is used to define the proper function and keypad keys
93 for use under X. It is used in a fashion analogous to the environment
96 (defvar window-setup-hook nil
97 "Normal hook run to initialize window system display.
98 XEmacs runs this hook after processing the command line arguments and loading
99 the user's init file.")
101 (defconst initial-major-mode 'lisp-interaction-mode
102 "Major mode command symbol to use for the initial *scratch* buffer.")
104 (defvar emacs-roots nil
105 "List of plausible roots of the XEmacs hierarchy.")
107 (defvar init-file-user nil
108 "Identity of user whose `.emacs' file is or was read.
109 The value is nil if no init file is being used; otherwise, it may be either
110 the null string, meaning that the init file was taken from the user that
111 originally logged in, or it may be a string containing a user's name.
113 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
114 evaluates to the name of the directory in which the `.emacs' file was
117 Setting `init-file-user' does not prevent Emacs from loading
118 `site-start.el'. The only way to do that is to use `--no-site-file'.")
120 ;; #### called `site-run-file' in FSFmacs
122 (defvar site-start-file (purecopy "site-start")
123 "File containing site-wide run-time initializations.
124 This file is loaded at run-time before `.emacs'. It
125 contains inits that need to be in place for the entire site, but
126 which, due to their higher incidence of change, don't make sense to
127 load into XEmacs' dumped image. Thus, the run-time load order is:
129 1. file described in this variable, if non-nil;
131 3. `/path/to/xemacs/lisp/default.el'.
133 Don't use the `site-start.el' file for things some users may not like.
134 Put them in `default.el' instead, so that users can more easily
135 override them. Users can prevent loading `default.el' with the `-q'
136 option or by setting `inhibit-default-init' in their own init files,
137 but inhibiting `site-start.el' requires `--no-site-file', which
138 is less convenient.")
140 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
141 ;; "Regexp that specifies when to enable the ISO 8859-1 character set.
142 ;;We do that if this regexp matches the locale name
143 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
145 (defvar mail-host-address nil
146 "*Name of this machine, for purposes of naming users.")
148 (defvar user-mail-address nil
149 "*Full mailing address of this user.
150 This is initialized based on `mail-host-address',
151 after your init file is read, in case it sets `mail-host-address'.")
153 (defvar auto-save-list-file-prefix "~/.saves-"
154 "Prefix for generating auto-save-list-file-name.
155 Emacs's pid and the system name will be appended to
156 this prefix to create a unique file name.")
158 (defvar init-file-debug nil)
160 (defvar init-file-had-error nil)
162 (defvar init-file-loaded nil
163 "True after the user's init file has been loaded (or suppressed with -q).
164 This will be true when `after-init-hook' is run and at all times
165 after, and will not be true at any time before.")
167 (defvar initial-frame-unmapped-p nil)
171 (defvar command-switch-alist
173 '(("-help" . command-line-do-help)
174 ("-version". command-line-do-version)
175 ("-V" . command-line-do-version)
176 ("-funcall". command-line-do-funcall)
177 ("-f" . command-line-do-funcall)
178 ("-e" . command-line-do-funcall-1)
179 ("-eval" . command-line-do-eval)
180 ("-load" . command-line-do-load)
181 ("-l" . command-line-do-load)
182 ("-insert" . command-line-do-insert)
183 ("-i" . command-line-do-insert)
184 ("-kill" . command-line-do-kill)
185 ;; Options like +35 are handled specially.
186 ;; Window-system, site, or package-specific code might add to this.
187 ;; X11 handles its options by letting Xt remove args from this list.
189 "Alist of command-line switches.
190 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
191 HANDLER-FUNCTION receives switch name as sole arg;
192 remaining command-line args are in the variable `command-line-args-left'.")
195 ;;; Note: these doc strings are semi-magical.
197 (defun command-line-do-help (arg)
198 "Print the XEmacs usage message and exit."
199 (let ((standard-output 'external-debugging-output))
200 (princ (concat "\n" (emacs-version) "\n\n"))
203 (concat "When creating a window on an X display, "
205 " accepts all standard X Toolkit
206 command line options plus the following:
207 -iconname <title> Use title as the icon name.
208 -mc <color> Use color as the mouse color.
209 -cr <color> Use color as the text-cursor foregound color.
210 -private Install a private colormap.
214 (princ " following options are accepted:
215 -t <device> Use TTY <device> instead of the terminal for input
216 and output. This implies the -nw option.
217 -nw Inhibit the use of any window-system-specific
218 display code: use the current tty.
219 -batch Execute noninteractively (messages go to stderr).
220 -debug-init Enter the debugger if an error in the init file occurs.
221 -unmapped Do not map the initial frame.
222 -no-site-file Do not load the site-specific init file (site-start.el).
223 -no-init-file Do not load the user-specific init file (~/.emacs).
224 -no-early-packages Do not process early packages.
225 -no-autoloads Do not load global symbol files (auto-autoloads) at
226 startup. Also implies `-vanilla'.
227 -vanilla Equivalent to -q -no-site-file -no-early-packages.
228 -q Same as -no-init-file.
229 -user <user> Load user's init file instead of your own.
230 -u <user> Same as -user.\n")
231 (let ((l command-switch-alist)
232 (insert (lambda (&rest x)
237 (incf len (length (car x)))
240 (terpri) (setq len 0))
245 (let ((name (car (car l)))
249 ((and (symbolp fn) (get fn 'undocumented)) nil)
251 (setq doc (documentation fn))
252 (if (member doc '(nil "")) (setq doc "(undocumented)"))
253 (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
254 ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
255 (setq arg (substring doc (match-beginning 1) (match-end 1))
256 doc (substring doc 0 (match-beginning 0))))
257 ((string-match "\n+\\'" doc)
258 (setq doc (substring doc 0 (match-beginning 0)))))
259 (if (and (setq cons (rassq fn command-switch-alist))
260 (not (eq cons (car l))))
261 (setq doc (format "Same as %s." (car cons))))
263 (funcall insert name " " arg)
264 (funcall insert name))
269 +N <file> Start displaying <file> at line N.
271 Anything else is considered a file name, and is placed into a buffer for
274 " (emacs-name) " has an online tutorial and manuals. Type ^Ht (Control-h t) after
275 starting XEmacs to run the tutorial. Type ^Hi to enter the manual browser.
276 Type ^H^H^H (Control-h Control-h Control-h) to get more help options.\n")
280 (defun command-line-do-funcall (arg)
281 "Invoke the named lisp function with no arguments.
283 (funcall (intern (pop command-line-args-left))))
284 (fset 'command-line-do-funcall-1 'command-line-do-funcall)
285 (put 'command-line-do-funcall-1 'undocumented t)
287 (defun command-line-do-eval (arg)
288 "Evaluate the lisp form. Quote it carefully.
290 (eval (read (pop command-line-args-left))))
292 (defun command-line-do-load (arg)
293 "Load the named file of Lisp code into XEmacs.
295 (let ((file (pop command-line-args-left)))
296 ;; Take file from default dir if it exists there;
297 ;; otherwise let `load' search for it.
298 (if (file-exists-p (expand-file-name file))
299 (setq file (expand-file-name file)))
302 (defun command-line-do-insert (arg)
303 "Insert file into the current buffer.
305 (insert-file-contents (pop command-line-args-left)))
307 (defun command-line-do-kill (arg)
311 (defun command-line-do-version (arg)
312 "Print version info and exit."
313 (princ (concat (emacs-version) "\n"))
317 ;;; Processing the command line and loading various init files
319 (defun early-error-handler (&rest debugger-args)
320 "You should probably not be using this."
321 ;; Used as the debugger during XEmacs initialization; if an error occurs,
322 ;; print some diagnostics, and kill XEmacs.
324 ;; output the contents of the warning buffer, since it won't be seen
326 ;; #### kludge! The call to Feval forces the pending warnings to
327 ;; get output. There definitely needs to be a better way.
328 (let ((buffer (eval (get-buffer-create "*Warnings*"))))
329 (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
330 'external-debugging-output))
332 (let ((string "Initialization error")
333 (error (nth 1 debugger-args))
335 (stream 'external-debugging-output))
337 (princ string stream)
338 (princ (concat "\n" string ": ") stream)
340 (display-error error stream)
341 (error (princ "<<< error printing error message >>>" stream)))
343 (if (memq (car-safe error) '(void-function void-variable))
345 This probably means that XEmacs is picking up an old version of
346 the lisp library, or that some .elc files are not up-to-date.\n"
348 (when (not suppress-early-error-handler-backtrace)
349 (let ((print-length 1000)
351 (print-escape-newlines t)
352 (print-readably nil))
353 (when (getenv "EMACSLOADPATH")
354 (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
356 (princ (format "\nexec-directory is %S" exec-directory) stream)
357 (princ (format "\ndata-directory is %S" data-directory) stream)
358 (princ (format "\ndata-directory-list is %S" data-directory-list) stream)
359 (princ (format "\ndoc-directory is %S" doc-directory) stream)
360 (princ (format "\nload-path is %S" load-path) stream)
361 (princ "\n\n" stream)))
362 (when (not suppress-early-error-handler-backtrace)
363 (backtrace stream t)))
366 (defvar lock-directory)
367 (defvar superlock-file)
369 (defun normal-top-level ()
370 (if command-line-processed
371 (message "Back to top level.")
372 (setq command-line-processed t)
373 ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
374 (let ((value (user-home-directory)))
376 (< (length value) (length default-directory))
377 (equal (file-attributes default-directory)
378 (file-attributes value)))
379 (setq default-directory (file-name-as-directory value))))
380 (setq default-directory (abbreviate-file-name default-directory))
381 (initialize-xemacs-paths)
383 (startup-set-invocation-environment)
385 (let ((debug-paths (or debug-paths
386 (and (getenv "EMACSDEBUGPATHS")
389 (setq emacs-roots (paths-find-emacs-roots invocation-directory
393 (princ (format "emacs-roots:\n%S\n" emacs-roots)
394 'external-debugging-output))
396 (if (null emacs-roots)
397 (startup-find-roots-warning)
398 (startup-setup-paths emacs-roots
399 inhibit-early-packages
402 (startup-setup-paths-warning))
404 (if (and (not inhibit-autoloads)
406 (load (expand-file-name (file-name-sans-extension autoload-file-name)
407 lisp-directory) nil t))
409 (if (not inhibit-autoloads)
411 (if (not inhibit-early-packages)
412 (packages-load-package-auto-autoloads early-package-load-path))
413 (packages-load-package-auto-autoloads late-package-load-path)
414 (packages-load-package-auto-autoloads last-package-load-path)))
418 ;; Do this again, in case .emacs defined more abbreviations.
419 (setq default-directory (abbreviate-file-name default-directory))
420 ;; Specify the file for recording all the auto save files of
421 ;; this session. This is used by recover-session.
422 (setq auto-save-list-file-name
425 auto-save-list-file-prefix
428 (run-hooks 'emacs-startup-hook)
430 (run-hooks 'term-setup-hook))
431 (setq term-setup-hook nil)
432 ;; ;; Modify the initial frame based on what .emacs puts into
433 ;; ;; ...-frame-alist.
434 (frame-notice-user-settings)
435 ;; ;;####FSFmacs junk
436 ;; ;; Now we know the user's default font, so add it to the menu.
437 ;; (if (fboundp 'font-menu-add-default)
438 ;; (font-menu-add-default))
439 (when window-setup-hook
440 (run-hooks 'window-setup-hook))
441 (setq window-setup-hook nil))
443 ;; (or menubar-bindings-done
444 ;; (precompute-menubar-bindings))
448 ;;; Precompute the keyboard equivalents in the menu bar items.
449 ;;(defun precompute-menubar-bindings ()
450 ;; (if (eq window-system 'x)
451 ;; (let ((submap (lookup-key global-map [menu-bar])))
453 ;; (and (consp (car submap))
454 ;; (symbolp (car (car submap)))
455 ;; (stringp (car-safe (cdr (car submap))))
456 ;; (keymapp (cdr (cdr (car submap))))
457 ;; (x-popup-menu nil (cdr (cdr (car submap)))))
458 ;; (setq submap (cdr submap))))))
460 (defun command-line-early (args)
461 ;; This processes those switches which need to be processed before
462 ;; starting up the window system.
464 (setq command-line-default-directory default-directory)
466 ;; See if we should import version-control from the environment variable.
467 (let ((vc (getenv "VERSION_CONTROL")))
468 (cond ((eq vc nil)) ;don't do anything if not set
469 ((or (string= vc "t")
470 (string= vc "numbered"))
471 (setq version-control t))
472 ((or (string= vc "nil")
473 (string= vc "existing"))
474 (setq version-control nil))
475 ((or (string= vc "never")
476 (string= vc "simple"))
477 (setq version-control 'never))))
481 ;; ;; Use the first of these three envvars that has a nonempty value.
482 ;; (or (let ((string (getenv "LC_ALL")))
483 ;; (and (not (equal string "")) string))
484 ;; (let ((string (getenv "LC_CTYPE")))
485 ;; (and (not (equal string "")) string))
486 ;; (let ((string (getenv "LANG")))
487 ;; (and (not (equal string "")) string)))))
489 ;; (string-match iso-8859-1-locale-regexp ctype)))
491 ;; (standard-display-european t)
492 ;; (require 'iso-syntax)))
494 ;; Figure out which user's init file to load,
495 ;; either from the environment or from the options.
496 (setq init-file-user (if (noninteractive) nil (user-login-name)))
497 ;; If user has not done su, use current $HOME to find .emacs.
498 (and init-file-user (string= init-file-user (user-real-login-name))
499 (setq init-file-user ""))
501 ;; Allow (at least) these arguments anywhere in the command line
505 (setq arg (pop args))
507 ((or (string= arg "-q")
508 (string= arg "-no-init-file"))
509 (setq init-file-user nil))
510 ((string= arg "-no-site-file")
511 (setq site-start-file nil))
512 ((or (string= arg "-no-early-packages")
513 (string= arg "--no-early-packages"))
514 (setq inhibit-early-packages t))
515 ((or (string= arg "-vanilla")
516 (string= arg "--vanilla")
517 ;; Some work on this one already done in emacs.c.
518 (string= arg "-no-autoloads")
519 (string= arg "--no-autoloads"))
520 (setq init-file-user nil
521 site-start-file nil))
522 ((or (string= arg "-u")
523 (string= arg "-user"))
524 (setq init-file-user (pop args)))
525 ((string= arg "-debug-init")
526 (setq init-file-debug t))
527 ((string= arg "-unmapped")
528 (setq initial-frame-unmapped-p t))
529 ((or (string= arg "-debug-paths")
530 (string= arg "--debug-paths"))
532 ((or (string= arg "--") (string= arg "-"))
534 (push (pop args) new-args)))
535 (t (push arg new-args))))
537 (nreverse new-args)))
539 (defconst initial-scratch-message "\
540 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
541 ;; If you want to create a file, first visit that file with C-x C-f,
542 ;; then enter the text in that file's own buffer.
545 "Initial message displayed in *scratch* buffer at startup.
546 If this is nil, no message will be displayed.")
548 (defun command-line ()
549 (let ((command-line-args-left (cdr command-line-args)))
551 (let ((debugger 'early-error-handler)
554 ;; Process magic command-line switches like -q and -u. Do this
555 ;; before creating the first frame because some of these switches
556 ;; may affect that. I think it's ok to do this before establishing
557 ;; the X connection, and maybe someday things like -nw can be
558 ;; handled here instead of down in C.
559 (setq command-line-args-left (command-line-early command-line-args-left))
561 ;; Setup the toolbar icon directory
562 (when (featurep 'toolbar)
563 (init-toolbar-location))
565 ;; Run the window system's init function. tty is considered to be
566 ;; a type of window system for this purpose. This creates the
567 ;; initial (non stdio) device.
568 (when (and initial-window-system (not noninteractive))
569 (funcall (intern (concat "init-"
570 (symbol-name initial-window-system)
573 ;; When not in batch mode, this creates the first visible frame,
574 ;; and deletes the stdio device.
578 ;; We have normality, I repeat, we have normality. Anything you still
579 ;; can't cope with is therefore your own problem. (And we don't need
580 ;; to kill XEmacs for it.)
586 (with-current-buffer (get-buffer "*scratch*")
588 ;; (insert initial-scratch-message)
589 (set-buffer-modified-p nil)
590 (when (eq major-mode 'fundamental-mode)
591 (funcall initial-major-mode)))
593 ;; Load library for our terminal type.
594 ;; User init file can set term-file-prefix to nil to prevent this.
595 ;; Note that for any TTY's opened subsequently, the TTY init
596 ;; code will run this.
597 (when (and (eq 'tty (console-type))
598 (not (noninteractive)))
599 (load-terminal-library))
601 ;; Process the remaining args.
604 ;; it was turned on by default so that the warnings don't get displayed
605 ;; until after the splash screen.
606 (setq inhibit-warning-display nil)
607 ;; If -batch, terminate after processing the command options.
608 (when (noninteractive) (kill-emacs t))))
610 (defun load-terminal-library ()
611 (when term-file-prefix
612 (let ((term (getenv "TERM"))
615 (not (load (concat term-file-prefix term) t t)))
616 ;; Strip off last hyphen and what follows, then try again
617 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
618 (setq term (substring term 0 hyphend))
621 (defconst user-init-directory "/.xemacs/"
622 "Directory where user-installed packages may go.")
623 (define-obsolete-variable-alias
624 'emacs-user-extension-dir
625 'user-init-directory)
627 (defun load-user-init-file (init-file-user)
628 "This function actually reads the init file, .emacs."
630 ;; purge references to init.el and options.el
631 ;; convert these to use paths-construct-path for eventual migration to init.el
632 ;; needs to be converted when idiom for constructing "~user" paths is created
633 ; (setq user-init-file
634 ; (paths-construct-path (list (concat "~" init-file-user)
635 ; user-init-directory
637 ; (unless (file-exists-p (expand-file-name user-init-file))
639 (paths-construct-path (list (concat "~" init-file-user)
641 ((eq system-type 'ms-dos) "_emacs")
644 (load user-init-file t t t)
645 ;; This should not be loaded since custom stuff currently goes into .emacs
646 ; (let ((default-custom-file
647 ; (paths-construct-path (list (concat "~" init-file-user)
648 ; user-init-directory
650 ; (when (string= custom-file default-custom-file)
651 ; (load default-custom-file t t)))
652 (unless inhibit-default-init
653 (let ((inhibit-startup-message nil))
654 ;; Users are supposed to be told their rights.
655 ;; (Plus how to get help and how to undo.)
656 ;; Don't you dare turn this off for anyone except yourself.
657 (load "default" t t)))))
659 ;;; Load user's init file and default ones.
660 (defun load-init-file ()
661 (run-hooks 'before-init-hook)
663 ;; Run the site-start library if it exists. The point of this file is
664 ;; that it is run before .emacs. There is no point in doing this after
665 ;; .emacs; that is useless.
666 (when site-start-file
667 (load site-start-file t t))
669 ;; Sites should not disable this. Only individuals should disable
670 ;; the startup message.
671 (setq inhibit-startup-message nil)
673 (let (debug-on-error-from-init-file
674 debug-on-error-should-be-set
675 (debug-on-error-initial
676 (if (eq init-file-debug t) 'startup init-file-debug)))
677 (let ((debug-on-error debug-on-error-initial))
679 ;; Do this without a condition-case if the user wants to debug.
680 (load-user-init-file init-file-user)
681 (condition-case error
683 (load-user-init-file init-file-user)
684 (setq init-file-had-error nil))
686 (message "Error in init file: %s" (error-message-string error))
687 (display-warning 'initialization
689 An error has occurred while loading %s:
693 To ensure normal operation, you should investigate the cause of the error
694 in your initialization file and remove it. Use the `-debug-init' option
695 to XEmacs to view a complete error backtrace."
696 user-init-file (error-message-string error))
698 (setq init-file-had-error t))))
699 ;; If we can tell that the init file altered debug-on-error,
700 ;; arrange to preserve the value that it set up.
701 (or (eq debug-on-error debug-on-error-initial)
702 (setq debug-on-error-should-be-set t
703 debug-on-error-from-init-file debug-on-error)))
704 (when debug-on-error-should-be-set
705 (setq debug-on-error debug-on-error-from-init-file)))
707 (setq init-file-loaded t)
709 ;; Do this here in case the init file sets mail-host-address.
710 ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
711 ;; (or user-mail-address
713 (setq user-mail-address (concat (user-login-name) "@"
714 (or mail-host-address
717 (run-hooks 'after-init-hook)
720 (defun load-options-file (filename)
721 "Load the file of saved options (from the Options menu) called FILENAME.
722 Currently this does nothing but call `load', but it might be redefined
723 in the future to support automatically converting older options files to
724 a new format, when variables have changed, etc."
727 (defun command-line-1 ()
729 ((null command-line-args-left)
730 (unless noninteractive
731 ;; If there are no switches to process, run the term-setup-hook
732 ;; before displaying the copyright notice; there may be some need
733 ;; to do it before doing any output. If we're not going to
734 ;; display a copyright notice (because other options are present)
735 ;; then this is run after those options are processed.
736 (run-hooks 'term-setup-hook)
737 ;; Don't let the hook be run twice.
738 (setq term-setup-hook nil)
740 ;; Don't clobber a non-scratch buffer if init file
742 (when (string= (buffer-name) "*scratch*")
743 (unless (or inhibit-startup-message
745 (let (tmout circ-tmout)
747 ;; Guts of with-timeout
749 (setq tmout (add-timeout startup-message-timeout
755 (setq circ-tmout (display-splash-frame))
756 (or nil;; (pos-visible-in-window-p (point-min))
757 (goto-char (point-min)))
759 (setq unread-command-event (next-command-event)))
760 (when tmout (disable-timeout tmout))
761 (when circ-tmout (disable-timeout circ-tmout)))))
762 (with-current-buffer (get-buffer "*scratch*")
763 ;; In case the XEmacs server has already selected
764 ;; another buffer, erase the one our message is in.
766 (when (stringp initial-scratch-message)
767 (insert initial-scratch-message))
768 (set-buffer-modified-p nil)))))
771 ;; Command-line-options exist
772 (let ((dir command-line-default-directory)
776 first-file-buffer file-p arg tem)
777 (while command-line-args-left
778 (setq arg (pop command-line-args-left))
782 ((setq tem (when (eq (aref arg 0) ?-)
783 (or (assoc arg command-switch-alist)
784 (assoc (substring arg 1)
785 command-switch-alist))))
786 (funcall (cdr tem) arg))
787 ((string-match "\\`\\+[0-9]+\\'" arg)
788 (setq line (string-to-int arg)))
789 ;; "- file" means don't treat "file" as a switch
790 ;; ("+0 file" has the same effect; "-" added
791 ;; for unixoidiality).
792 ;; This is worthless; the `unixoid' way is "./file". -jwz
793 ((or (string= arg "-") (string= arg "--"))
794 (setq end-of-options t))
801 (setq arg (expand-file-name arg dir))
803 ((= file-count 1) (setq first-file-buffer
804 (progn (find-file arg) (current-buffer))))
805 (noninteractive (find-file arg))
806 (t (find-file-other-window arg)))
809 (setq line nil))))))))
811 (defvar startup-presentation-hack-keymap
812 (let ((map (make-sparse-keymap)))
813 (set-keymap-name map 'startup-presentation-hack-keymap)
814 (define-key map '[button1] 'startup-presentation-hack)
815 (define-key map '[button2] 'startup-presentation-hack)
817 "Putting yesterday in the future tomorrow.")
819 (defun startup-presentation-hack ()
821 (let ((e last-command-event))
822 (and (button-press-event-p e)
823 (setq e (extent-at (event-point e)
825 'startup-presentation-hack))
826 (setq e (extent-property e 'startup-presentation-hack))
828 (apply (car e) (cdr e))
829 (while (keymapp (indirect-function e))
831 (overriding-local-map (indirect-function e)))
832 (setq e (read-key-sequence
833 (let ((p (keymap-prompt map t)))
836 (format "%s %s " map p)
840 (prin1-to-string map))))))
841 (if (and (button-release-event-p (elt e 0))
842 (null (key-binding e)))
843 (setq e map) ; try again
844 (setq e (key-binding e)))))
845 (call-interactively e)))))
847 (defun startup-presentation-hack-help (e)
848 (setq e (extent-property e 'startup-presentation-hack))
850 (format "Evaluate %S" e)
853 (defun splash-frame-present-hack (e v)
854 ;; (set-extent-property e 'mouse-face 'highlight)
855 ;; (set-extent-property e 'keymap
856 ;; startup-presentation-hack-keymap)
857 ;; (set-extent-property e 'startup-presentation-hack v)
858 ;; (set-extent-property e 'help-echo
859 ;; 'startup-presentation-hack-help)
862 (defun splash-hack-version-string ()
865 (goto-char (point-min))
866 (re-search-forward "^XEmacs" nil t)
867 (narrow-to-region (point-at-bol) (point-at-eol))
868 (goto-char (point-min))
869 (when (re-search-forward " \\[Lucid\\]" nil t)
870 (delete-region (match-beginning 0) (match-end 0)))
871 (when (re-search-forward "[^(][^)]*-[^)]*-" nil t)
872 (delete-region (1+ (match-beginning 0)) (match-end 0))
874 (goto-char (point-max))
875 (search-backward " " nil t)
876 (when (search-forward "." nil t)
877 (delete-region (1- (point)) (point-max))))))
879 (defun splash-frame-present (l)
882 ((eq (car-safe l) 'face)
883 ;; (face name string)
885 (splash-frame-present (elt l 2))
886 (if (fboundp 'set-extent-face)
887 (set-extent-face (make-extent p (point))
889 ((eq (car-safe l) 'key)
892 (k (where-is-internal c nil t)))
893 (insert (if k (key-description k)
894 (format "M-x %s" c)))
895 (if (fboundp 'set-extent-face)
896 (let ((e (make-extent p (point))))
897 (set-extent-face e 'bold)
898 (splash-frame-present-hack e c)))))
899 ((eq (car-safe l) 'funcall)
900 ;; (funcall (fun . args) string)
902 (splash-frame-present (elt l 2))
903 (if (fboundp 'set-extent-face)
904 (splash-frame-present-hack (make-extent p (point))
907 (mapcar 'splash-frame-present l))
911 (defun startup-center-spaces (glyph)
912 ;; Return the number of spaces to insert in order to center
913 ;; the given glyph (may be a string or a pixmap).
914 ;; Assume spaces are as wide as avg-pixwidth.
915 ;; Won't be quite right for proportional fonts, but it's the best we can do.
916 ;; Maybe the new redisplay will export something a glyph-width function.
917 ;;; #### Yes, there is a glyph-width function but it isn't quite what
918 ;;; #### this was expecting. Or is it?
919 ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
920 ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
922 ;; This function is used in about.el too.
923 (let* ((avg-pixwidth (round (/ (frame-pixel-width) (frame-width))))
924 (fill-area-width (* avg-pixwidth (- fill-column left-margin)))
925 (glyph-pixwidth (cond ((stringp glyph)
926 (* avg-pixwidth (length glyph)))
927 ;; #### the pixmap option should be removed
929 ;; (pixmap-width glyph))
933 (error "startup-center-spaces: bad arg")))))
935 (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
937 (defun splash-frame-body ()
938 `[((face (blue bold underline)
939 "\nDistribution, copying license, warranty:\n\n")
940 "Please visit the XEmacs website at http://www.xemacs.org !\n\n"
941 ,@(if (featurep 'sparcworks)
943 Sun provides support for the WorkShop/XEmacs integration package only.
944 All other XEmacs packages are provided to you \"AS IS\".\n"
945 ,@(let ((lang (or (getenv "LC_ALL") (getenv "LC_MESSAGES")
948 (not (featurep 'mule)) ;; Already got mule?
949 ;; No Mule support on tty's yet
950 (not (eq 'tty (console-type)))
951 lang ;; Non-English locale?
952 (not (string= lang "C"))
953 (not (string-match "^en" lang))
954 ;; Comes with Sun WorkShop
955 (locate-file "xemacs-mule" exec-path))
957 This version of XEmacs has been built with support for Latin-1 languages only.
958 To handle other languages you need to run a Multi-lingual (`Mule') version of
959 XEmacs, by either running the command `xemacs-mule', or by using the X resource
960 `ESERVE*defaultXEmacsPath: xemacs-mule' when starting XEmacs from Sun WorkShop.
962 ((key describe-no-warranty)
963 ": "(face (red bold) "XEmacs comes with ABSOLUTELY NO WARRANTY\n"))
964 ((key describe-copying)
965 ": conditions to give out copies of XEmacs\n")
966 ((key describe-distribution)
967 ": how to get the latest version\n")
970 Copyright (C) 1985-1999 Free Software Foundation, Inc.
971 Copyright (C) 1995-1999 Electrotechnical Laboratory, JAPAN.
972 Copyright (C) 1990-1994 Lucid, Inc.
973 Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
974 Copyright (C) 1994-1996 Board of Trustees, University of Illinois
975 Copyright (C) 1995-1996 Ben Wing\n"))
977 ((face (blue bold underline) "\nInformation, on-line help:\n\n")
978 "XEmacs comes with plenty of documentation...\n\n"
979 ,@(if (string-match "beta" emacs-version)
980 `((key describe-beta)
981 ": " (face (red bold)
982 "This is an Experimental version of XEmacs.\n"))
984 ((key xemacs-local-faq)
985 ": read the XEmacs FAQ (a " (face underline "capital") " F!)\n")
986 ((key help-with-tutorial)
987 ": read the XEmacs tutorial (also available through the "
988 (face bold "Help") " menu)\n")
990 ": get help on using XEmacs (also available through the "
991 (face bold "Help") " menu)\n")
992 ((key info) ": read the on-line documentation\n\n")
993 ((key describe-project) ": read about the GNU project\n")
994 ((key about-xemacs) ": see who's developing XEmacs\n"))
996 ((face (blue bold underline) "\nUseful stuff:\n\n")
997 "Things that you should know rather quickly...\n\n"
998 ((key find-file) ": visit a file\n")
999 ((key save-buffer) ": save changes\n")
1000 ((key advertised-undo) ": undo changes\n")
1001 ((key save-buffers-kill-emacs) ": exit XEmacs\n"))
1004 ;; I really hate global variables, oh well.
1005 ;(defvar xemacs-startup-logo-function nil
1006 ; "If non-nil, function called to provide the startup logo.
1007 ;This function should return an initialized glyph if it is used.")
1009 ;; This will hopefully go away when gettext is functionnal.
1010 (defconst splash-frame-static-body
1011 `(,(emacs-version) "\n\n"
1012 (face italic "`C-' means the control key,`M-' means the meta key\n\n")))
1015 (defun circulate-splash-frame-elements (client-data)
1016 (with-current-buffer (aref client-data 2)
1017 (let ((buffer-read-only nil)
1018 (elements (aref client-data 3))
1019 (indice (aref client-data 0)))
1020 (goto-char (aref client-data 1))
1021 (delete-region (point) (point-max))
1022 (splash-frame-present (aref elements indice))
1023 (set-buffer-modified-p nil)
1025 (if (= indice (- (length elements) 1))
1030 ;; ### This function now returns the (possibly nil) timeout circulating the
1031 ;; splash-frame elements
1032 (defun display-splash-frame ()
1033 (let ((logo xemacs-logo)
1034 (buffer-read-only nil)
1035 (cramped-p (eq 'tty (console-type))))
1036 (unless cramped-p (insert "\n"))
1037 (indent-to (startup-center-spaces logo))
1038 (set-extent-begin-glyph (make-extent (point) (point)) logo)
1039 ;;(splash-frame-present-hack (make-extent p (point)) 'about-xemacs))
1041 (splash-frame-present splash-frame-static-body)
1042 (splash-hack-version-string)
1043 (goto-char (point-max))
1044 (let* ((after-change-functions nil) ; no font-lock, thank you
1045 (elements (splash-frame-body))
1046 (client-data `[ 1 ,(point) ,(current-buffer) ,elements ])
1048 (if (listp elements) ;; A single element to display
1049 (splash-frame-present (splash-frame-body))
1050 ;; several elements to rotate
1051 (splash-frame-present (aref elements 0))
1052 (setq tmout (add-timeout splash-frame-timeout
1053 'circulate-splash-frame-elements
1054 client-data splash-frame-timeout)))
1055 (set-buffer-modified-p nil)
1058 ;; (let ((present-file
1060 ;; (splash-frame-present
1062 ;; (list 'find-file-other-window
1063 ;; (expand-file-name f data-directory))
1065 ;; (insert "For customization examples, see the files ")
1066 ;; (funcall present-file "sample.emacs")
1068 ;; (funcall present-file "sample.Xdefaults")
1069 ;; (insert (format "\nin the directory %s." data-directory)))
1071 (defun startup-set-invocation-environment ()
1072 ;; XEmacs -- Steven Baur says invocation directory is nil if you
1073 ;; try to use XEmacs as a login shell.
1074 (or invocation-directory (setq invocation-directory default-directory))
1075 (setq invocation-directory
1076 ;; don't let /tmp_mnt/... get into the load-path or exec-path.
1077 (abbreviate-file-name invocation-directory)))
1079 (defun startup-setup-paths (roots &optional
1080 inhibit-early-packages inhibit-site-lisp
1082 "Setup all the various paths.
1083 ROOTS is a list of plausible roots of the XEmacs directory hierarchy.
1084 If INHIBIT-PACKAGES is non-NIL, don't do packages.
1085 If INHIBIT-SITE-LISP is non-NIL, don't do site-lisp.
1086 If DEBUG-PATHS is non-NIL, print paths as they are detected.
1087 It's idempotent, so call this as often as you like!"
1089 (apply #'(lambda (early late last)
1090 (setq early-packages (and (not inhibit-early-packages)
1092 (setq late-packages late)
1093 (setq last-packages last))
1094 (packages-find-packages roots))
1096 (setq early-package-load-path (packages-find-package-load-path early-packages))
1097 (setq late-package-load-path (packages-find-package-load-path late-packages))
1098 (setq last-package-load-path (packages-find-package-load-path last-packages))
1102 (princ (format "configure-package-path:\n%S\n" configure-package-path)
1103 'external-debugging-output)
1104 (princ (format "early-packages and early-package-load-path:\n%S\n%S\n"
1105 early-packages early-package-load-path)
1106 'external-debugging-output)
1107 (princ (format "late-packages and late-package-load-path:\n%S\n%S\n"
1108 late-packages late-package-load-path)
1109 'external-debugging-output)
1110 (princ (format "last-packages and last-package-load-path:\n%S\n%S\n"
1111 last-packages last-package-load-path)
1112 'external-debugging-output)))
1114 (setq lisp-directory (paths-find-lisp-directory roots))
1117 (princ (format "lisp-directory:\n%S\n" lisp-directory)
1118 'external-debugging-output))
1120 (setq site-directory (and (null inhibit-site-lisp)
1121 (paths-find-site-lisp-directory roots)))
1123 (if (and debug-paths (null inhibit-site-lisp))
1124 (princ (format "site-directory:\n%S\n" site-directory)
1125 'external-debugging-output))
1127 (setq load-path (paths-construct-load-path roots
1128 early-package-load-path
1129 late-package-load-path
1130 last-package-load-path
1134 (setq Info-directory-list
1135 (paths-construct-info-path roots
1136 early-packages late-packages last-packages))
1140 (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1141 'external-debugging-output))
1143 (if (boundp 'lock-directory)
1145 (setq lock-directory (paths-find-lock-directory roots))
1146 (setq superlock-file (paths-find-superlock-file lock-directory))
1150 (princ (format "lock-directory:\n%S\n" lock-directory)
1151 'external-debugging-output)
1152 (princ (format "superlock-file:\n%S\n" superlock-file)
1153 'external-debugging-output)))))
1155 (setq exec-directory (paths-find-exec-directory roots))
1158 (princ (format "exec-directory:\n%s\n" exec-directory)
1159 'external-debugging-output))
1162 (paths-construct-exec-path roots exec-directory
1163 early-packages late-packages last-packages))
1166 (princ (format "exec-path:\n%S\n" exec-path)
1167 'external-debugging-output))
1169 (setq doc-directory (paths-find-doc-directory roots))
1172 (princ (format "doc-directory:\n%S\n" doc-directory)
1173 'external-debugging-output))
1175 (setq data-directory (paths-find-data-directory roots))
1178 (princ (format "data-directory:\n%S\n" data-directory)
1179 'external-debugging-output))
1181 (setq data-directory-list (paths-construct-data-directory-list data-directory
1186 (princ (format "data-directory-list:\n%S\n" data-directory-list)
1187 'external-debugging-output)))
1189 (defun startup-find-roots-warning ()
1191 (set-buffer (get-buffer-create " *warning-tmp*"))
1193 (buffer-disable-undo (current-buffer))
1195 (insert "Couldn't find an obvious default for the root of the\n"
1196 "XEmacs hierarchy.")
1198 (princ "\nWARNING:\n" 'external-debugging-output)
1199 (princ (buffer-string) 'external-debugging-output)))
1201 (defun startup-setup-paths-warning ()
1202 (let ((lock (if (boundp 'lock-directory) lock-directory 't))
1204 (if (and (stringp lock) (null (file-directory-p lock)))
1207 ((null (and lisp-directory exec-directory data-directory doc-directory
1211 (set-buffer (get-buffer-create " *warning-tmp*"))
1213 (buffer-disable-undo (current-buffer))
1214 (if (null lisp-directory) (push "lisp-directory" warnings))
1215 (if (null lock) (push "lock-directory" warnings))
1216 (if (null exec-directory) (push "exec-directory" warnings))
1217 (if (null data-directory) (push "data-directory" warnings))
1218 (if (null doc-directory) (push "doc-directory" warnings))
1219 (if (null load-path) (push "load-path" warnings))
1221 (insert "Couldn't find obvious defaults for:\n")
1223 (insert (car warnings) "\n")
1224 (setq warnings (cdr warnings)))
1225 (insert "Perhaps some directories don't exist, "
1226 "or the XEmacs executable,\n" (concat invocation-directory
1228 "\nis in a strange place?")
1230 (princ "\nWARNING:\n" 'external-debugging-output)
1231 (princ (buffer-string) 'external-debugging-output)
1235 ;;; startup.el ends here