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 user-init-directory-base ".xemacs"
108 "Base of directory where user-installed init files may go.")
110 (defvar user-init-directory
111 (file-name-as-directory
112 (paths-construct-path (list "~" user-init-directory-base)))
113 "Directory where user-installed init files may go.")
115 (defvar user-init-file-base "init.el"
116 "Default name of the user init file if uncompiled.
117 This should be used for migration purposes only.")
119 (defvar user-init-file-base-list '("init.elc" "init.el")
120 "List of allowed init files in the user's init directory.
121 The first one found takes precedence.")
123 (defvar user-home-init-file-base-list
124 (append '(".emacs.elc" ".emacs.el" ".emacs")
125 (and (eq system-type 'windows-nt)
126 '("_emacs.elc" "_emacs.el" "_emacs")))
127 "List of allowed init files in the user's home directory.
128 The first one found takes precedence.")
130 (defvar load-home-init-file nil
131 "Non-nil if XEmacs should load the init file from the home directory.
132 Otherwise, XEmacs will offer migration to the init directory.")
134 (defvar load-user-init-file-p t
135 "Non-nil if XEmacs should load the user's init file.")
137 ;; #### called `site-run-file' in FSFmacs
139 (defvar site-start-file "site-start"
140 "File containing site-wide run-time initializations.
141 This file is loaded at run-time before `.emacs'. It
142 contains inits that need to be in place for the entire site, but
143 which, due to their higher incidence of change, don't make sense to
144 load into XEmacs' dumped image. Thus, the run-time load order is:
146 1. file described in this variable, if non-nil;
148 3. `/path/to/xemacs/lisp/default.el'.
150 Don't use the `site-start.el' file for things some users may not like.
151 Put them in `default.el' instead, so that users can more easily
152 override them. Users can prevent loading `default.el' with the `-q'
153 option or by setting `inhibit-default-init' in their own init files,
154 but inhibiting `site-start.el' requires `--no-site-file', which
155 is less convenient.")
157 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
158 ;; "Regexp that specifies when to enable the ISO 8859-1 character set.
159 ;;We do that if this regexp matches the locale name
160 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
162 (defcustom mail-host-address nil
163 "*Name of this machine, for purposes of naming users."
167 (defcustom user-mail-address nil
168 "*Full mailing address of this user.
169 This is initialized based on `mail-host-address',
170 after your init file is read, in case it sets `mail-host-address'."
174 (defvar init-file-debug nil)
176 (defvar init-file-had-error nil)
178 (defvar init-file-loaded nil
179 "True after the user's init file has been loaded (or suppressed with -q).
180 This will be true when `after-init-hook' is run and at all times
181 after, and will not be true at any time before.")
183 (defvar initial-frame-unmapped-p nil)
187 (defvar command-switch-alist
188 '(("-help" . command-line-do-help)
189 ("-version". command-line-do-version)
190 ("-V" . command-line-do-version)
191 ("-funcall". command-line-do-funcall)
192 ("-f" . command-line-do-funcall)
193 ("-e" . command-line-do-funcall-1)
194 ("-eval" . command-line-do-eval)
195 ("-load" . command-line-do-load)
196 ("-l" . command-line-do-load)
197 ("-insert" . command-line-do-insert)
198 ("-i" . command-line-do-insert)
199 ("-kill" . command-line-do-kill)
200 ;; Options like +35 are handled specially.
201 ;; Window-system, site, or package-specific code might add to this.
202 ;; X11 handles its options by letting Xt remove args from this list.
204 "Alist of command-line switches.
205 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
206 HANDLER-FUNCTION receives switch name as sole arg;
207 remaining command-line args are in the variable `command-line-args-left'.")
210 ;;; Note: these doc strings are semi-magical.
212 (defun command-line-do-help (arg)
213 "Print the XEmacs usage message and exit."
214 (let ((standard-output 'external-debugging-output))
215 (princ (concat "\n" (emacs-version) "\n\n"))
218 (concat "When creating a window on an X display, "
220 " accepts all standard X Toolkit
221 command line options plus the following:
222 -iconname <title> Use title as the icon name.
223 -mc <color> Use color as the mouse color.
224 -cr <color> Use color as the text-cursor foregound color.
225 -private Install a private colormap.
229 (princ " following options are accepted:
230 -sd Show dump ID. Ignored when configured without --pdump.
231 -nd Don't load the dump file. Roughly like old temacs.
232 Ignored when configured without --pdump.
233 -t <device> Use TTY <device> instead of the terminal for input
234 and output. This implies the -nw option.
235 -nw Inhibit the use of any window-system-specific
236 display code: use the current tty.
237 -batch Execute noninteractively (messages go to stderr).
238 -debug-init Enter the debugger if an error in the init file occurs.
239 -unmapped Do not map the initial frame.
240 -no-site-file Do not load the site-specific init file (site-start.el).
241 -no-init-file Do not load the user-specific init file (~/.emacs).
242 -no-early-packages Do not process early packages.
243 -no-autoloads Do not load global symbol files (auto-autoloads) at
244 startup. Also implies `-vanilla'.
245 -vanilla Equivalent to -q -no-site-file -no-early-packages.
246 -q Same as -no-init-file.
247 -user-init-file <file> Use <file> as init file.
248 -user-init-directory <directory> Use <directory> as init directory.
249 -user <user> Load user's init file instead of your own.
250 Equivalent to -user-init-file ~<user>/.emacs
251 -user-init-directory ~<user>/.xemacs/
252 -u <user> Same as -user.\n")
253 (let ((l command-switch-alist)
254 (insert (lambda (&rest x)
259 (incf len (length (car x)))
262 (terpri) (setq len 0))
267 (let ((name (car (car l)))
271 ((and (symbolp fn) (get fn 'undocumented)) nil)
273 (setq doc (documentation fn))
274 (if (member doc '(nil "")) (setq doc "(undocumented)"))
275 (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
276 ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
277 (setq arg (substring doc (match-beginning 1) (match-end 1))
278 doc (substring doc 0 (match-beginning 0))))
279 ((string-match "\n+\\'" doc)
280 (setq doc (substring doc 0 (match-beginning 0)))))
281 (if (and (setq cons (rassq fn command-switch-alist))
282 (not (eq cons (car l))))
283 (setq doc (format "Same as %s." (car cons))))
285 (funcall insert name " " arg)
286 (funcall insert name))
291 +N <file> Start displaying <file> at line N.
293 Anything else is considered a file name, and is placed into a buffer for
296 " (emacs-name) " has an online tutorial and manuals. Type ^Ht (Control-h t) after
297 starting XEmacs to run the tutorial. Type ^Hi to enter the manual browser.
298 Type ^H^H^H (Control-h Control-h Control-h) to get more help options.\n")
302 (defun command-line-do-funcall (arg)
303 "Invoke the named lisp function with no arguments.
305 (funcall (intern (pop command-line-args-left))))
306 (fset 'command-line-do-funcall-1 'command-line-do-funcall)
307 (put 'command-line-do-funcall-1 'undocumented t)
309 (defun command-line-do-eval (arg)
310 "Evaluate the lisp form. Quote it carefully.
312 (eval (read (pop command-line-args-left))))
314 (defun command-line-do-load (arg)
315 "Load the named file of Lisp code into XEmacs.
317 (let ((file (pop command-line-args-left)))
318 ;; Take file from default dir if it exists there;
319 ;; otherwise let `load' search for it.
320 (if (file-exists-p (expand-file-name file))
321 (setq file (expand-file-name file)))
324 (defun command-line-do-insert (arg)
325 "Insert file into the current buffer.
327 (insert-file-contents (pop command-line-args-left)))
329 (defun command-line-do-kill (arg)
333 (defun command-line-do-version (arg)
334 "Print version info and exit."
335 (princ (concat (emacs-version) "\n"))
339 ;;; Processing the command line and loading various init files
341 (defun early-error-handler (&rest debugger-args)
342 "You should probably not be using this."
343 ;; Used as the debugger during XEmacs initialization; if an error occurs,
344 ;; print some diagnostics, and kill XEmacs.
346 ;; output the contents of the warning buffer, since it won't be seen
348 ;; #### kludge! The call to Feval forces the pending warnings to
349 ;; get output. There definitely needs to be a better way.
350 (let ((buffer (eval (get-buffer-create "*Warnings*"))))
351 (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
352 'external-debugging-output))
354 (let ((string "Initialization error")
355 (error (nth 1 debugger-args))
357 (stream 'external-debugging-output))
359 (princ string stream)
360 (princ (concat "\n" string ": ") stream)
362 (display-error error stream)
363 (error (princ "<<< error printing error message >>>" stream)))
365 (if (memq (car-safe error) '(void-function void-variable))
367 This probably means that XEmacs is picking up an old version of
368 the lisp library, or that some .elc files are not up-to-date.\n"
370 (when (not suppress-early-error-handler-backtrace)
371 (let ((print-length 1000)
373 (print-escape-newlines t)
374 (print-readably nil))
375 (when (getenv "EMACSLOADPATH")
376 (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
378 (princ (format "\nexec-directory is %S" exec-directory) stream)
379 (princ (format "\ndata-directory is %S" data-directory) stream)
380 (princ (format "\ndata-directory-list is %S" data-directory-list) stream)
381 (princ (format "\ndoc-directory is %S" doc-directory) stream)
382 (princ (format "\nload-path is %S" load-path) stream)
383 (princ "\n\n" stream)))
384 (when (not suppress-early-error-handler-backtrace)
385 (backtrace stream t)))
386 (if (fboundp 'mswindows-message-box)
387 (mswindows-message-box "Initialization error"))
390 (defun normal-top-level ()
391 (if command-line-processed
392 (message "Back to top level.")
393 (setq command-line-processed t)
394 ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
395 (let ((value (user-home-directory)))
397 (< (length value) (length default-directory))
398 (equal (file-attributes default-directory)
399 (file-attributes value)))
400 (setq default-directory (file-name-as-directory value))))
401 (setq default-directory (abbreviate-file-name default-directory))
402 (initialize-xemacs-paths)
404 (startup-set-invocation-environment)
406 (let ((debug-paths (or debug-paths
407 (and (getenv "EMACSDEBUGPATHS")
410 (setq emacs-roots (paths-find-emacs-roots invocation-directory
414 (princ (format "emacs-roots:\n%S\n" emacs-roots)
415 'external-debugging-output))
417 (if (null emacs-roots)
418 (startup-find-roots-warning)
419 (startup-setup-paths emacs-roots
421 inhibit-early-packages
424 (startup-setup-paths-warning))
426 (when (and (not inhibit-autoloads)
428 (load (expand-file-name (file-name-sans-extension autoload-file-name)
429 lisp-directory) nil t)
430 (if (featurep 'utf-2000)
431 (load (expand-file-name
432 (file-name-sans-extension autoload-file-name)
433 (expand-file-name "utf-2000" lisp-directory))
436 (if (not inhibit-autoloads)
438 (if (not inhibit-early-packages)
439 (packages-load-package-auto-autoloads early-package-load-path))
440 (packages-load-package-auto-autoloads late-package-load-path)
441 (packages-load-package-auto-autoloads last-package-load-path)))
445 ;; Do this again, in case .emacs defined more abbreviations.
446 (setq default-directory (abbreviate-file-name default-directory))
447 ;; Specify the file for recording all the auto save files of
448 ;; this session. This is used by recover-session.
449 (if auto-save-list-file-prefix
450 (setq auto-save-list-file-name
453 auto-save-list-file-prefix
456 (run-hooks 'emacs-startup-hook)
458 (run-hooks 'term-setup-hook))
459 (setq term-setup-hook nil)
460 ;; ;; Modify the initial frame based on what .emacs puts into
461 ;; ;; ...-frame-alist.
462 (frame-notice-user-settings)
463 ;; ;;####FSFmacs junk
464 ;; ;; Now we know the user's default font, so add it to the menu.
465 ;; (if (fboundp 'font-menu-add-default)
466 ;; (font-menu-add-default))
467 (when window-setup-hook
468 (run-hooks 'window-setup-hook))
469 (setq window-setup-hook nil))
471 (if load-user-init-file-p
472 (maybe-migrate-user-init-file))
474 ;; (or menubar-bindings-done
475 ;; (precompute-menubar-bindings))
479 ;;; Precompute the keyboard equivalents in the menu bar items.
480 ;;(defun precompute-menubar-bindings ()
481 ;; (if (eq window-system 'x)
482 ;; (let ((submap (lookup-key global-map [menu-bar])))
484 ;; (and (consp (car submap))
485 ;; (symbolp (car (car submap)))
486 ;; (stringp (car-safe (cdr (car submap))))
487 ;; (keymapp (cdr (cdr (car submap))))
488 ;; (x-popup-menu nil (cdr (cdr (car submap)))))
489 ;; (setq submap (cdr submap))))))
491 (defun command-line-early (args)
492 ;; This processes those switches which need to be processed before
493 ;; starting up the window system.
495 (setq command-line-default-directory default-directory)
497 ;; See if we should import version-control from the environment variable.
498 (let ((vc (getenv "VERSION_CONTROL")))
499 (cond ((eq vc nil)) ;don't do anything if not set
500 ((or (string= vc "t")
501 (string= vc "numbered"))
502 (setq version-control t))
503 ((or (string= vc "nil")
504 (string= vc "existing"))
505 (setq version-control nil))
506 ((or (string= vc "never")
507 (string= vc "simple"))
508 (setq version-control 'never))))
512 ;; ;; Use the first of these three envvars that has a nonempty value.
513 ;; (or (let ((string (getenv "LC_ALL")))
514 ;; (and (not (equal string "")) string))
515 ;; (let ((string (getenv "LC_CTYPE")))
516 ;; (and (not (equal string "")) string))
517 ;; (let ((string (getenv "LANG")))
518 ;; (and (not (equal string "")) string)))))
520 ;; (string-match iso-8859-1-locale-regexp ctype)))
522 ;; (standard-display-european t)
523 ;; (require 'iso-syntax)))
525 (setq load-user-init-file-p (not (noninteractive)))
527 ;; Allow (at least) these arguments anywhere in the command line
531 (setq arg (pop args))
533 ((or (string= arg "-q")
534 (string= arg "-no-init-file"))
535 (setq load-user-init-file-p nil))
536 ((string= arg "-no-site-file")
537 (setq site-start-file nil))
538 ((or (string= arg "-no-early-packages")
539 (string= arg "--no-early-packages"))
540 (setq inhibit-early-packages t))
541 ((or (string= arg "-vanilla")
542 (string= arg "--vanilla")
543 ;; Some work on this one already done in emacs.c.
544 (string= arg "-no-autoloads")
545 (string= arg "--no-autoloads"))
546 (setq load-user-init-file-p nil
547 site-start-file nil))
548 ((string= arg "-user-init-file")
549 (setq user-init-file (pop args)))
550 ((string= arg "-user-init-directory")
551 (setq user-init-directory (file-name-as-directory (pop args))))
552 ((or (string= arg "-u")
553 (string= arg "-user"))
554 (let* ((user (pop args))
555 (home-user (concat "~" user)))
556 (setq user-init-directory (file-name-as-directory
557 (paths-construct-path
558 (list home-user user-init-directory-base))))
560 (find-user-init-file user-init-directory home-user))
562 (make-custom-file-name user-init-file))))
563 ((string= arg "-debug-init")
564 (setq init-file-debug t))
565 ((string= arg "-unmapped")
566 (setq initial-frame-unmapped-p t))
567 ((or (string= arg "-debug-paths")
568 (string= arg "--debug-paths"))
570 ((or (string= arg "--") (string= arg "-"))
572 (push (pop args) new-args)))
573 (t (push arg new-args))))
575 (setq init-file-user (and load-user-init-file-p ""))
577 (nreverse new-args)))
579 (defconst initial-scratch-message "\
580 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
581 ;; If you want to create a file, first visit that file with C-x C-f,
582 ;; then enter the text in that file's own buffer.
585 "Initial message displayed in *scratch* buffer at startup.
586 If this is nil, no message will be displayed.")
588 (defun command-line ()
589 (let ((command-line-args-left (cdr command-line-args)))
591 (let ((debugger 'early-error-handler)
594 ;; Process magic command-line switches like -q and -u. Do this
595 ;; before creating the first frame because some of these switches
596 ;; may affect that. I think it's ok to do this before establishing
597 ;; the X connection, and maybe someday things like -nw can be
598 ;; handled here instead of down in C.
599 (setq command-line-args-left (command-line-early command-line-args-left))
601 ;; Setup the toolbar icon directory
602 (when (featurep 'toolbar)
603 (init-toolbar-location))
605 ;; Run the window system's init function. tty is considered to be
606 ;; a type of window system for this purpose. This creates the
607 ;; initial (non stdio) device.
608 (when (and initial-window-system (not noninteractive))
609 (funcall (intern (concat "init-"
610 (symbol-name initial-window-system)
613 ;; When not in batch mode, this creates the first visible frame,
614 ;; and deletes the stdio device.
617 ;; Reinitialize faces if necessary. This function changes face if
618 ;; it is created during auto-autoloads loading. Otherwise, it
620 (startup-initialize-custom-faces)
623 ;; We have normality, I repeat, we have normality. Anything you still
624 ;; can't cope with is therefore your own problem. (And we don't need
625 ;; to kill XEmacs for it.)
631 (with-current-buffer (get-buffer "*scratch*")
633 ;; (insert initial-scratch-message)
634 (set-buffer-modified-p nil)
635 (when (eq major-mode 'fundamental-mode)
636 (funcall initial-major-mode)))
638 ;; Load library for our terminal type.
639 ;; User init file can set term-file-prefix to nil to prevent this.
640 ;; Note that for any TTY's opened subsequently, the TTY init
641 ;; code will run this.
642 (when (and (eq 'tty (console-type))
643 (not (noninteractive)))
644 (load-terminal-library))
646 ;; Process the remaining args.
649 ;; it was turned on by default so that the warnings don't get displayed
650 ;; until after the splash screen.
651 (setq inhibit-warning-display nil)
652 ;; If -batch, terminate after processing the command options.
653 (when (noninteractive) (kill-emacs t))))
655 (defun load-terminal-library ()
656 (when term-file-prefix
657 (let ((term (getenv "TERM"))
660 (not (load (concat term-file-prefix term) t t)))
661 ;; Strip off last hyphen and what follows, then try again
662 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
663 (setq term (substring term 0 hyphend))
666 (defun find-user-init-directory-init-file (&optional init-directory)
667 "Determine the user's init file if in the init directory."
668 (let ((init-directory (or init-directory user-init-directory)))
670 (dolist (file user-init-file-base-list)
671 (let ((expanded (expand-file-name file init-directory)))
672 (when (file-readable-p expanded)
673 (throw 'found expanded)))))))
675 (defun find-user-home-directory-init-file (&optional home-directory)
676 "Determine the user's init file if in the home directory."
677 (let ((home-directory (or home-directory "~")))
679 (dolist (file user-home-init-file-base-list)
680 (let ((expanded (expand-file-name file home-directory)))
681 (when (file-readable-p expanded)
682 (throw 'found expanded))))
685 (defun find-user-init-file (&optional init-directory home-directory)
686 "Determine the user's init file."
687 (if load-home-init-file
688 (find-user-home-directory-init-file home-directory)
689 (or (find-user-init-directory-init-file init-directory)
690 (find-user-home-directory-init-file home-directory))))
692 (defun maybe-migrate-user-init-file ()
693 "Ask user if she wants to migrate the init file(s) to new location."
694 (if (and (not load-home-init-file)
695 (not (find-user-init-directory-init-file user-init-directory))
696 (stringp user-init-file)
697 (file-readable-p user-init-file))
698 (if (with-output-to-temp-buffer (help-buffer-name nil)
700 (princ "XEmacs recommends that the initialization code in
702 (princ user-init-file)
704 be migrated to the ")
705 (princ user-init-directory)
706 (princ " directory. XEmacs can
707 perform the migration automatically.
709 After the migration, init.el/init.elc holds user-written
710 initialization code. Moreover the customize settings will be in
713 If you choose not to do this now, XEmacs will not ask you this
714 question in the future. However, you can still make XEmacs
715 perform the migration at any time with M-x migrate-user-init-file.")
716 (show-temp-buffer-in-current-frame standard-output)
717 (yes-or-no-p-minibuf (concat "Migrate init file to "
720 (migrate-user-init-file)
721 (customize-save-variable 'load-home-init-file t))))
723 (defun migrate-user-init-file ()
724 "Migrate the init file from the home directory."
726 (if (not (file-exists-p user-init-directory))
728 (message "Creating %s directory..." user-init-directory)
729 (make-directory user-init-directory)))
730 (message "Migrating custom file...")
731 (custom-migrate-custom-file (make-custom-file-name user-init-file
733 (message "Moving init file...")
734 (rename-file user-init-file
735 (expand-file-name user-init-file-base
736 user-init-directory))
737 (message "Migration done."))
739 (defun load-user-init-file ()
740 "This function actually reads the init file."
741 (if (not user-init-file)
743 (find-user-init-file user-init-directory)))
744 (if (and user-init-file
745 (file-readable-p user-init-file))
746 (load user-init-file t t t))
747 (if (not custom-file)
748 (setq custom-file (make-custom-file-name user-init-file)))
750 (or (not user-init-file)
751 (not (string= custom-file user-init-file)))
752 (file-readable-p custom-file))
753 (load custom-file t t t))
754 (unless inhibit-default-init
755 (let ((inhibit-startup-message nil))
756 ;; Users are supposed to be told their rights.
757 ;; (Plus how to get help and how to undo.)
758 ;; Don't you dare turn this off for anyone except yourself.
759 (load "default" t t))))
761 ;;; Load user's init file and default ones.
762 (defun load-init-file ()
763 (run-hooks 'before-init-hook)
765 ;; Run the site-start library if it exists. The point of this file is
766 ;; that it is run before .emacs. There is no point in doing this after
767 ;; .emacs; that is useless.
768 (when site-start-file
769 (load site-start-file t t))
771 ;; Sites should not disable this. Only individuals should disable
772 ;; the startup message.
773 (setq inhibit-startup-message nil)
775 (let (debug-on-error-from-init-file
776 debug-on-error-should-be-set
777 (debug-on-error-initial
778 (if (eq init-file-debug t) 'startup init-file-debug)))
779 (let ((debug-on-error debug-on-error-initial))
780 (if (and load-user-init-file-p init-file-debug)
782 ;; Do this without a condition-case if the user wants to debug.
783 (load-user-init-file))
784 (condition-case error
786 (if load-user-init-file-p
787 (load-user-init-file))
788 (setq init-file-had-error nil))
790 (message "Error in init file: %s" (error-message-string error))
791 (display-warning 'initialization
793 An error has occurred while loading %s:
797 To ensure normal operation, you should investigate the cause of the error
798 in your initialization file and remove it. Use the `-debug-init' option
799 to XEmacs to view a complete error backtrace."
800 user-init-file (error-message-string error))
802 (setq init-file-had-error t))))
803 ;; If we can tell that the init file altered debug-on-error,
804 ;; arrange to preserve the value that it set up.
805 (or (eq debug-on-error debug-on-error-initial)
806 (setq debug-on-error-should-be-set t
807 debug-on-error-from-init-file debug-on-error)))
808 (when debug-on-error-should-be-set
809 (setq debug-on-error debug-on-error-from-init-file)))
811 (setq init-file-loaded t)
813 ;; Do this here in case the init file sets mail-host-address.
814 ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
815 ;; (or user-mail-address
817 (setq user-mail-address (concat (user-login-name) "@"
818 (or mail-host-address
821 (run-hooks 'after-init-hook)
824 (defun load-options-file (filename)
825 "Load the file of saved options (from the Options menu) called FILENAME.
826 Currently this does nothing but call `load', but it might be redefined
827 in the future to support automatically converting older options files to
828 a new format, when variables have changed, etc."
831 (defun command-line-1 ()
833 ((null command-line-args-left)
834 (unless noninteractive
835 ;; If there are no switches to process, run the term-setup-hook
836 ;; before displaying the copyright notice; there may be some need
837 ;; to do it before doing any output. If we're not going to
838 ;; display a copyright notice (because other options are present)
839 ;; then this is run after those options are processed.
840 (run-hooks 'term-setup-hook)
841 ;; Don't let the hook be run twice.
842 (setq term-setup-hook nil)
844 ;; Don't clobber a non-scratch buffer if init file
846 (when (string= (buffer-name) "*scratch*")
847 (unless (or inhibit-startup-message
849 (let (tmout circ-tmout)
851 ;; Guts of with-timeout
853 (setq tmout (add-timeout startup-message-timeout
859 (setq circ-tmout (display-splash-frame))
860 (or nil;; (pos-visible-in-window-p (point-min))
861 (goto-char (point-min)))
863 (setq unread-command-event (next-command-event)))
864 (when tmout (disable-timeout tmout))
865 (when circ-tmout (disable-timeout circ-tmout)))))
866 (with-current-buffer (get-buffer "*scratch*")
867 ;; In case the XEmacs server has already selected
868 ;; another buffer, erase the one our message is in.
870 (when (stringp initial-scratch-message)
871 (insert initial-scratch-message))
872 (set-buffer-modified-p nil)))))
875 ;; Command-line-options exist
876 (let ((dir command-line-default-directory)
881 (while command-line-args-left
882 (setq arg (pop command-line-args-left))
886 ((setq tem (when (eq (aref arg 0) ?-)
887 (or (assoc arg command-switch-alist)
888 (assoc (substring arg 1)
889 command-switch-alist))))
890 (funcall (cdr tem) arg))
891 ((string-match "\\`\\+[0-9]+\\'" arg)
892 (setq line (string-to-int arg)))
893 ;; "- file" means don't treat "file" as a switch
894 ;; ("+0 file" has the same effect; "-" added
895 ;; for unixoidiality).
896 ;; This is worthless; the `unixoid' way is "./file". -jwz
897 ((or (string= arg "-") (string= arg "--"))
898 (setq end-of-options t))
905 (setq arg (expand-file-name arg dir))
909 (noninteractive (find-file arg))
910 (t (find-file-other-window arg)))
913 (setq line nil))))))))
915 (defvar startup-presentation-hack-keymap
916 (let ((map (make-sparse-keymap)))
917 (set-keymap-name map 'startup-presentation-hack-keymap)
918 (define-key map '[button1] 'startup-presentation-hack)
919 (define-key map '[button2] 'startup-presentation-hack)
921 "Putting yesterday in the future tomorrow.")
923 (defun startup-presentation-hack ()
925 (let ((e last-command-event))
926 (and (button-press-event-p e)
927 (setq e (extent-at (event-point e)
929 'startup-presentation-hack))
930 (setq e (extent-property e 'startup-presentation-hack))
932 (apply (car e) (cdr e))
933 (while (keymapp (indirect-function e))
935 (overriding-local-map (indirect-function e)))
936 (setq e (read-key-sequence
937 (let ((p (keymap-prompt map t)))
940 (format "%s %s " map p)
944 (prin1-to-string map))))))
945 (if (and (button-release-event-p (elt e 0))
946 (null (key-binding e)))
947 (setq e map) ; try again
948 (setq e (key-binding e)))))
949 (call-interactively e)))))
951 (defun startup-presentation-hack-help (e)
952 (setq e (extent-property e 'startup-presentation-hack))
954 (format "Evaluate %S" e)
957 (defun splash-frame-present-hack (e v)
958 ;; (set-extent-property e 'mouse-face 'highlight)
959 ;; (set-extent-property e 'keymap
960 ;; startup-presentation-hack-keymap)
961 ;; (set-extent-property e 'startup-presentation-hack v)
962 ;; (set-extent-property e 'help-echo
963 ;; 'startup-presentation-hack-help)
966 (defun splash-hack-version-string ()
969 (goto-char (point-min))
970 (re-search-forward "^XEmacs" nil t)
971 (narrow-to-region (point-at-bol) (point-at-eol))
972 (goto-char (point-min))
973 (when (re-search-forward " \\[Lucid\\]" nil t)
974 (delete-region (match-beginning 0) (match-end 0)))
975 (when (re-search-forward "[^(][^)]*-[^)]*-" nil t)
976 (delete-region (1+ (match-beginning 0)) (match-end 0))
978 (goto-char (point-max))
979 (search-backward " " nil t)
980 (when (search-forward "." nil t)
981 (delete-region (1- (point)) (point-max))))))
983 (defun splash-frame-present (l)
986 ((eq (car-safe l) 'face)
987 ;; (face name string)
989 (splash-frame-present (elt l 2))
990 (if (fboundp 'set-extent-face)
991 (set-extent-face (make-extent p (point))
993 ((eq (car-safe l) 'key)
996 (k (where-is-internal c nil t)))
997 (insert (if k (key-description k)
998 (format "M-x %s" c)))
999 (if (fboundp 'set-extent-face)
1000 (let ((e (make-extent p (point))))
1001 (set-extent-face e 'bold)
1002 (splash-frame-present-hack e c)))))
1003 ((eq (car-safe l) 'funcall)
1004 ;; (funcall (fun . args) string)
1006 (splash-frame-present (elt l 2))
1007 (if (fboundp 'set-extent-face)
1008 (splash-frame-present-hack (make-extent p (point))
1011 (mapcar 'splash-frame-present l))
1015 (defun startup-center-spaces (glyph)
1016 ;; Return the number of spaces to insert in order to center
1017 ;; the given glyph (may be a string or a pixmap).
1018 ;; Assume spaces are as wide as avg-pixwidth.
1019 ;; Won't be quite right for proportional fonts, but it's the best we can do.
1020 ;; Maybe the new redisplay will export something a glyph-width function.
1021 ;;; #### Yes, there is a glyph-width function but it isn't quite what
1022 ;;; #### this was expecting. Or is it?
1023 ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
1024 ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
1026 ;; This function is used in about.el too.
1027 (let* ((avg-pixwidth (round (/ (frame-pixel-width) (frame-width))))
1028 (fill-area-width (* avg-pixwidth (- fill-column left-margin)))
1029 (glyph-pixwidth (cond ((stringp glyph)
1030 (* avg-pixwidth (length glyph)))
1031 ;; #### the pixmap option should be removed
1033 ;; (pixmap-width glyph))
1035 (glyph-width glyph))
1037 (error "startup-center-spaces: bad arg")))))
1039 (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
1041 (defun splash-frame-body ()
1042 `[((face (blue bold underline)
1043 "\nDistribution, copying license, warranty:\n\n")
1044 "Please visit the XEmacs website at http://www.xemacs.org !\n\n"
1045 ,@(if (featurep 'sparcworks)
1047 Sun provides support for the WorkShop/XEmacs integration package only.
1048 All other XEmacs packages are provided to you \"AS IS\".\n"
1049 ,@(let ((lang (or (getenv "LC_ALL") (getenv "LC_MESSAGES")
1052 (not (featurep 'mule)) ;; Already got mule?
1053 ;; No Mule support on tty's yet
1054 (not (eq 'tty (console-type)))
1055 lang ;; Non-English locale?
1056 (not (string= lang "C"))
1057 (not (string-match "^en" lang))
1058 ;; Comes with Sun WorkShop
1059 (locate-file "xemacs-mule" exec-path))
1061 This version of XEmacs has been built with support for Latin-1 languages only.
1062 To handle other languages you need to run a Multi-lingual (`Mule') version of
1063 XEmacs, by either running the command `xemacs-mule', or by using the X resource
1064 `ESERVE*defaultXEmacsPath: xemacs-mule' when starting XEmacs from Sun WorkShop.
1066 ((key describe-no-warranty)
1067 ": "(face (red bold) "XEmacs comes with ABSOLUTELY NO WARRANTY\n"))
1068 ((key describe-copying)
1069 ": conditions to give out copies of XEmacs\n")
1070 ((key describe-distribution)
1071 ": how to get the latest version\n")
1074 Copyright (C) 1985-1999 Free Software Foundation, Inc.
1075 Copyright (C) 1990-1994 Lucid, Inc.
1076 Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
1077 Copyright (C) 1994-1996 Board of Trustees, University of Illinois
1078 Copyright (C) 1995-1996 Ben Wing
1079 Copyright (C) 1996-2000 MORIOKA Tomohiko
1082 ((face (blue bold underline) "\nInformation, on-line help:\n\n")
1083 "XEmacs comes with plenty of documentation...\n\n"
1084 ,@(if (string-match "beta" emacs-version)
1085 `((key describe-beta)
1086 ": " (face (red bold)
1087 "This is an Experimental version of XEmacs.\n"))
1089 ((key xemacs-local-faq)
1090 ": read the XEmacs FAQ (a " (face underline "capital") " F!)\n")
1091 ((key help-with-tutorial)
1092 ": read the XEmacs tutorial (also available through the "
1093 (face bold "Help") " menu)\n")
1095 ": get help on using XEmacs (also available through the "
1096 (face bold "Help") " menu)\n")
1097 ((key info) ": read the on-line documentation\n\n")
1098 ((key describe-project) ": read about the GNU project\n")
1099 ((key about-xemacs) ": see who's developing XEmacs\n"))
1101 ((face (blue bold underline) "\nUseful stuff:\n\n")
1102 "Things that you should know rather quickly...\n\n"
1103 ((key find-file) ": visit a file\n")
1104 ((key save-buffer) ": save changes\n")
1105 ((key advertised-undo) ": undo changes\n")
1106 ((key save-buffers-kill-emacs) ": exit XEmacs\n"))
1109 ;; I really hate global variables, oh well.
1110 ;(defvar xemacs-startup-logo-function nil
1111 ; "If non-nil, function called to provide the startup logo.
1112 ;This function should return an initialized glyph if it is used.")
1114 ;; This will hopefully go away when gettext is functional.
1115 (defconst splash-frame-static-body
1116 `(,(emacs-version) "\n\n"
1117 (face italic "`C-' means the control key,`M-' means the meta key\n\n")))
1120 (defun circulate-splash-frame-elements (client-data)
1121 (with-current-buffer (aref client-data 2)
1122 (let ((buffer-read-only nil)
1123 (elements (aref client-data 3))
1124 (indice (aref client-data 0)))
1125 (goto-char (aref client-data 1))
1126 (delete-region (point) (point-max))
1127 (splash-frame-present (aref elements indice))
1128 (set-buffer-modified-p nil)
1130 (if (= indice (- (length elements) 1))
1135 ;; #### This function now returns the (possibly nil) timeout circulating the
1136 ;; splash-frame elements
1137 (defun display-splash-frame ()
1138 (let ((logo xemacs-logo)
1139 (buffer-read-only nil)
1140 (cramped-p (eq 'tty (console-type))))
1141 (unless cramped-p (insert "\n"))
1142 (indent-to (startup-center-spaces logo))
1143 (set-extent-begin-glyph (make-extent (point) (point)) logo)
1144 ;;(splash-frame-present-hack (make-extent p (point)) 'about-xemacs))
1146 (splash-frame-present splash-frame-static-body)
1147 (splash-hack-version-string)
1148 (goto-char (point-max))
1149 (let* ((after-change-functions nil) ; no font-lock, thank you
1150 (elements (splash-frame-body))
1151 (client-data `[ 1 ,(point) ,(current-buffer) ,elements ])
1153 (if (listp elements) ;; A single element to display
1154 (splash-frame-present (splash-frame-body))
1155 ;; several elements to rotate
1156 (splash-frame-present (aref elements 0))
1157 (setq tmout (add-timeout splash-frame-timeout
1158 'circulate-splash-frame-elements
1159 client-data splash-frame-timeout)))
1160 (set-buffer-modified-p nil)
1163 ;; (let ((present-file
1165 ;; (splash-frame-present
1167 ;; (list 'find-file-other-window
1168 ;; (expand-file-name f data-directory))
1170 ;; (insert "For customization examples, see the files ")
1171 ;; (funcall present-file "sample.emacs")
1173 ;; (funcall present-file "sample.Xdefaults")
1174 ;; (insert (format "\nin the directory %s." data-directory)))
1176 (defun startup-set-invocation-environment ()
1177 ;; XEmacs -- Steven Baur says invocation directory is nil if you
1178 ;; try to use XEmacs as a login shell.
1179 (or invocation-directory (setq invocation-directory default-directory))
1180 (setq invocation-directory
1181 ;; don't let /tmp_mnt/... get into the load-path or exec-path.
1182 (abbreviate-file-name invocation-directory)))
1184 (defun startup-setup-paths (roots user-init-directory
1186 inhibit-early-packages inhibit-site-lisp
1188 "Setup all the various paths.
1189 ROOTS is a list of plausible roots of the XEmacs directory hierarchy.
1190 If INHIBIT-PACKAGES is non-NIL, don't do packages.
1191 If INHIBIT-SITE-LISP is non-NIL, don't do site-lisp.
1192 If DEBUG-PATHS is non-NIL, print paths as they are detected.
1193 It's idempotent, so call this as often as you like!"
1195 (apply #'(lambda (early late last)
1196 (setq early-packages (and (not inhibit-early-packages)
1198 (setq late-packages late)
1199 (setq last-packages last))
1200 (packages-find-packages
1202 (packages-compute-package-locations user-init-directory)))
1204 (setq early-package-load-path (packages-find-package-load-path early-packages))
1205 (setq late-package-load-path (packages-find-package-load-path late-packages))
1206 (setq last-package-load-path (packages-find-package-load-path last-packages))
1210 (princ (format "configure-package-path:\n%S\n" configure-package-path)
1211 'external-debugging-output)
1212 (princ (format "early-packages and early-package-load-path:\n%S\n%S\n"
1213 early-packages early-package-load-path)
1214 'external-debugging-output)
1215 (princ (format "late-packages and late-package-load-path:\n%S\n%S\n"
1216 late-packages late-package-load-path)
1217 'external-debugging-output)
1218 (princ (format "last-packages and last-package-load-path:\n%S\n%S\n"
1219 last-packages last-package-load-path)
1220 'external-debugging-output)))
1222 (setq lisp-directory (paths-find-lisp-directory roots))
1225 (princ (format "lisp-directory:\n%S\n" lisp-directory)
1226 'external-debugging-output))
1228 (setq site-directory (and (null inhibit-site-lisp)
1229 (paths-find-site-lisp-directory roots)))
1231 (if (and debug-paths (null inhibit-site-lisp))
1232 (princ (format "site-directory:\n%S\n" site-directory)
1233 'external-debugging-output))
1235 (setq load-path (paths-construct-load-path roots
1236 early-package-load-path
1237 late-package-load-path
1238 last-package-load-path
1242 (setq Info-directory-list
1243 (paths-construct-info-path roots
1244 early-packages late-packages last-packages))
1248 (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1249 'external-debugging-output))
1251 (setq exec-directory (paths-find-exec-directory roots))
1254 (princ (format "exec-directory:\n%s\n" exec-directory)
1255 'external-debugging-output))
1258 (paths-construct-exec-path roots exec-directory
1259 early-packages late-packages last-packages))
1262 (princ (format "exec-path:\n%S\n" exec-path)
1263 'external-debugging-output))
1265 (setq doc-directory (paths-find-doc-directory roots))
1268 (princ (format "doc-directory:\n%S\n" doc-directory)
1269 'external-debugging-output))
1271 (setq data-directory (paths-find-data-directory roots))
1274 (princ (format "data-directory:\n%S\n" data-directory)
1275 'external-debugging-output))
1277 (setq data-directory-list (paths-construct-data-directory-list data-directory
1282 (princ (format "data-directory-list:\n%S\n" data-directory-list)
1283 'external-debugging-output)))
1285 (defun startup-find-roots-warning ()
1287 (set-buffer (get-buffer-create " *warning-tmp*"))
1289 (buffer-disable-undo (current-buffer))
1291 (insert "Couldn't find an obvious default for the root of the\n"
1292 "XEmacs hierarchy.")
1294 (princ "\nWARNING:\n" 'external-debugging-output)
1295 (princ (buffer-string) 'external-debugging-output)))
1297 (defun startup-setup-paths-warning ()
1298 (let ((warnings '()))
1300 ((null (and lisp-directory exec-directory data-directory doc-directory
1303 (set-buffer (get-buffer-create " *warning-tmp*"))
1305 (buffer-disable-undo (current-buffer))
1306 (if (null lisp-directory) (push "lisp-directory" warnings))
1307 (if (null exec-directory) (push "exec-directory" warnings))
1308 (if (null data-directory) (push "data-directory" warnings))
1309 (if (null doc-directory) (push "doc-directory" warnings))
1310 (if (null load-path) (push "load-path" warnings))
1312 (insert "Couldn't find obvious defaults for:\n")
1314 (insert (car warnings) "\n")
1315 (setq warnings (cdr warnings)))
1316 (insert "Perhaps some directories don't exist, "
1317 "or the XEmacs executable,\n" (concat invocation-directory
1319 "\nis in a strange place?")
1321 (princ "\nWARNING:\n" 'external-debugging-output)
1322 (princ (buffer-string) 'external-debugging-output)
1326 ;;; startup.el ends here