home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / lisp / prim / startup.el < prev    next >
Encoding:
Text File  |  1995-08-29  |  49.5 KB  |  1,319 lines

  1. ;;; startup.el --- process XEmacs shell arguments
  2.  
  3. ;; Copyright (C) 1985-1986, 1990, 1992-1994 Free Software Foundation, Inc.
  4. ;; Copyright (c) 1993, 1994 Sun Microsystems, Inc.
  5. ;; Copyright (C) 1995 Board of Trustees, University of Illinois
  6.  
  7. ;; Maintainer: XEmacs
  8. ;; Keywords: internal
  9.  
  10. ;; This file is part of XEmacs.
  11.  
  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)
  15. ;; any later version.
  16.  
  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.
  21.  
  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 Free
  24. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  
  26. ;;; Synched up with: FSF 19.28.
  27.  
  28. ;;; Code:
  29.  
  30. (defun command-line-do-help (arg)
  31.   "Print this message and exit."
  32.   (let ((standard-output 'external-debugging-output))
  33.     (princ (emacs-version))
  34.     (princ "\n\n")
  35.     (cond ((fboundp 'x-create-frame)
  36.        (princ "XEmacs")
  37.        (princ " accepts all standard X Toolkit command line options.\
  38.   In addition,\nthe "))
  39.       (t (princ "The ")))
  40.     (princ "following options are processed in the order encountered:\n\n")
  41.     (let ((l command-switch-alist)
  42.       (insert (function (lambda (&rest x)
  43.                   (princ "  ")
  44.                   (let ((len 2))
  45.                 (while x
  46.                   (princ (car x))
  47.                   (setq len (+ len (length (car x))))
  48.                   (setq x (cdr x)))
  49.                 (if (>= len 24)
  50.                     (progn (terpri) (setq len 0)))
  51.                 (while (< len 24)
  52.                   (princ " ")
  53.                   (setq len (1+ len))))))))
  54.       (while l
  55.         (let ((name (car (car l)))
  56.               (fn (cdr (car l)))
  57.           doc arg cons)
  58.       (cond
  59.        ((and (symbolp fn) (get fn 'undocumented)) nil)
  60.        (t
  61.         (setq doc (documentation fn))
  62.         (if (member doc '(nil "")) (setq doc "(undocumented)"))
  63.         (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
  64.            ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
  65.            (setq arg (substring doc (match-beginning 1) (match-end 1))
  66.              doc (substring doc 0 (match-beginning 0))))
  67.           ((string-match "\n+\\'" doc)
  68.            (setq doc (substring doc 0 (match-beginning 0)))))
  69.         (if (and (setq cons (rassq fn command-switch-alist))
  70.              (not (eq cons (car l))))
  71.         (setq doc (format "Same as %s." (car cons))))
  72.         (if arg
  73.         (funcall insert name " " arg)
  74.           (funcall insert name))
  75.         (princ doc)
  76.         (terpri))))
  77.         (setq l (cdr l))))
  78.     (princ "\
  79.   +N <file>             Start displaying <file> at line N.
  80.  
  81. These options are processed only if they appear before all other options:
  82.  
  83.   -t <device>           Use TTY <device> instead of the terminal for input
  84.                         and output.  This implies the -nw option.
  85.   -batch                Execute noninteractively (messages go to stderr).
  86.                         This option must be first in the list after -t.
  87.   -nw                   Inhibit the use of any window-system-specific
  88.                         display code: use the current tty.
  89.   -debug-init           Enter the debugger if an error in the init file occurs.
  90.   -unmapped             Do not map the initial frame.
  91.   -no-site-file         Do not load the site-specific init file (site-start.el).
  92.   -no-init-file         Do not load the user-specific init file (~/.emacs).
  93.   -q                    Same as -no-init-file.
  94.   -user <user>          Load user's init file instead of your own.
  95.   -u <user>             Same as -user.")
  96.  
  97.     (princ "
  98.  
  99. Anything else is considered a file name, and is placed into a buffer for
  100. editing.
  101.  
  102. Emacs has an online tutorial and manuals.  Type ^Ht (Control-h t) after
  103. starting emacs to run the tutorial.  Type ^Hi to enter the manual browser.\n")
  104.     (kill-emacs 0)
  105.     ))
  106.  
  107. ;;; -batch, -t, and -nw are processed by main() in emacs.c and are 
  108. ;;; never seen by lisp code.
  109.  
  110. ;;; -version and -help are special-cased as well: they imply -batch,
  111. ;;; but are left on the list for lisp code to process.
  112.  
  113.  
  114. ;; This should really be in files.el, but is used very early.
  115. ;; note: tmp_mnt bogosity conversion is established in paths.el.
  116. (defvar directory-abbrev-alist nil
  117.   "*Alist of abbreviations for file directories.
  118. A list of elements of the form (FROM . TO), each meaning to replace
  119. FROM with TO when it appears in a directory name.
  120. This replacement is done when setting up the default directory of a
  121. newly visited file.  *Every* FROM string should start with \\\\` or ^.
  122.  
  123. Use this feature when you have directories which you normally refer to
  124. via absolute symbolic links or to eliminate automounter mount points
  125. from the beginning of your filenames.  Make TO the name of the link,
  126. and FROM the name it is linked to.")
  127.  
  128. (defvar abbreviated-home-dir nil
  129.   "The user's homedir abbreviated according to `directory-abbrev-alist'.")
  130.  
  131. (defun abbreviate-file-name (filename &optional hack-homedir)
  132.   "Return a version of FILENAME shortened using `directory-abbrev-alist'.
  133. See \\[describe-variable] directory-abbrev-alist RET for more information.
  134. If optional argument HACK-HOMEDIR is non-nil, then This also substitutes
  135. \"~\" for the user's home directory."
  136.   ;; Get rid of the prefixes added by the automounter.
  137.   ;(if (and (string-match automount-dir-prefix filename)
  138.   ;         (file-exists-p (file-name-directory
  139.   ;                         (substring filename (1- (match-end 0))))))
  140.   ;    (setq filename (substring filename (1- (match-end 0)))))
  141.   (let ((tail directory-abbrev-alist))
  142.     ;; If any elt of directory-abbrev-alist matches this name,
  143.     ;; abbreviate accordingly.
  144.     (while tail
  145.       (if (string-match (car (car tail)) filename)
  146.       (setq filename
  147.         (concat (cdr (car tail)) (substring filename (match-end 0)))))
  148.       (setq tail (cdr tail))))
  149.   (if hack-homedir
  150.       (progn
  151.     ;; Compute and save the abbreviated homedir name.
  152.     ;; We defer computing this until the first time it's needed, to
  153.     ;; give time for directory-abbrev-alist to be set properly.
  154.     ;; We include a slash at the end, to avoid spurious matches
  155.     ;; such as `/usr/foobar' when the home dir is `/usr/foo'.
  156.     (or abbreviated-home-dir
  157.         (setq abbreviated-home-dir
  158.           (let ((abbreviated-home-dir "$foo"))
  159.             (concat "\\`" (regexp-quote (abbreviate-file-name
  160.                          (expand-file-name "~")))
  161.                 "\\(/\\|\\'\\)"))))
  162.         ;; If FILENAME starts with the abbreviated homedir,
  163.         ;; make it start with `~' instead.
  164.     (if (and (string-match abbreviated-home-dir filename)
  165.                  ;; If the home dir is just /, don't change it.
  166.                  (not (and (= (match-end 0) 1) ;#### unix-specific
  167.                (= (aref filename 0) ?/)))
  168.          (not (and (eq system-type 'ms-dos)
  169.                (save-match-data
  170.                  (string-match "^[a-zA-Z]:/$" filename)))))
  171.         (setq filename
  172.           (concat "~"
  173.               (substring filename
  174.                      (match-beginning 1) (match-end 1))
  175.               (substring filename (match-end 0)))))))
  176.   filename)
  177.  
  178.  
  179. (setq top-level '(normal-top-level))
  180.  
  181. (defvar command-line-processed nil "t once command line has been processed")
  182.  
  183. (defconst startup-message-timeout 120)
  184.  
  185. (defconst inhibit-startup-message nil
  186.   "*Non-nil inhibits the initial startup message.
  187. This is for use in your personal init file, once you are familiar
  188. with the contents of the startup message.")
  189.  
  190. ;; #### FSFmacs randomness
  191. ;(defconst inhibit-startup-echo-area-message nil
  192. ;  "*Non-nil inhibits the initial startup echo area message.
  193. ;Inhibition takes effect only if your `.emacs' file contains
  194. ;a line of this form:
  195. ; (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
  196. ;If your `.emacs' file is byte-compiled, use the following form instead:
  197. ; (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
  198. ;Thus, someone else using a copy of your `.emacs' file will see
  199. ;the startup message unless he personally acts to inhibit it.")
  200.  
  201. (defconst inhibit-default-init nil
  202.   "*Non-nil inhibits loading the `default' library.")
  203.  
  204. (defconst command-switch-alist nil
  205.   "Alist of command-line switches.
  206. Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
  207. HANDLER-FUNCTION receives switch name as sole arg;
  208. remaining command-line args are in the variable `command-line-args-left'.")
  209.  
  210. (defvar command-line-args-left nil
  211.   "List of command-line args not yet processed.") ; bound by `command-line'
  212.  
  213. (defvar command-line-default-directory nil
  214.   "Default directory to use for command line arguments.
  215. This is normally copied from `default-directory' when XEmacs starts.")
  216.  
  217. (defvar before-init-hook nil
  218.   "Functions to call after handling urgent options but before init files.
  219. The frame system uses this to open frames to display messages while
  220. Emacs loads the user's initialization file.")
  221.  
  222. (defvar after-init-hook nil
  223.   "Functions to call after loading the init file (`~/.emacs').
  224. The call is not protected by a condition-case, so you can set `debug-on-error'
  225. in `.emacs', and put all the actual code on `after-init-hook'.")
  226.  
  227. (defvar term-setup-hook nil
  228.   "Functions to be called after loading terminal-specific Lisp code.
  229. See `run-hooks'.  This variable exists for users to set,
  230. so as to override the definitions made by the terminal-specific file.
  231. Emacs never sets this variable itself.")
  232.  
  233. (defvar keyboard-type nil
  234.   "The brand of keyboard you are using.
  235. This variable is used to define
  236. the proper function and keypad keys for use under X.  It is used in a
  237. fashion analogous to the environment value TERM.")
  238.  
  239. (defvar window-setup-hook nil
  240.   "Normal hook run to initialize window system display.
  241. Emacs runs this hook after processing the command line arguments and loading
  242. the user's init file.")
  243.  
  244. (defconst initial-major-mode 'lisp-interaction-mode
  245.   "Major mode command symbol to use for the initial *scratch* buffer.")
  246.  
  247. (defvar init-file-user nil
  248.   "Identity of user whose `.emacs' file is or was read.
  249. The value is nil if no init file is being used; otherwise, it may be either
  250. the null string, meaning that the init file was taken from the user that
  251. originally logged in, or it may be a string containing a user's name.
  252.  
  253. In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
  254. evaluates to the name of the directory where the `.emacs' file was
  255. looked for.")
  256.  
  257. ;; #### called `site-run-file' in FSFmacs
  258.  
  259. (defvar site-start-file (purecopy "site-start")
  260.   "File containing site-wide run-time initializations.
  261. This file is loaded at run-time before `~/.emacs'.  It contains inits
  262. that need to be in place for the entire site, but which, due to their
  263. higher incidence of change, don't make sense to load into emacs'
  264. dumped image.  Thus, the run-time load order is: 1. file described in
  265. this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.")
  266.  
  267. ;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
  268. ;  "Regexp that specifies when to enable the ISO 8859-1 character set.
  269. ;We do that if this regexp matches the locale name
  270. ;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
  271.  
  272. (defvar user-mail-address nil
  273.   "Full mailing address of this user.")
  274.  
  275. (defvar init-file-debug nil)
  276.  
  277. (defvar init-file-had-error nil)
  278.  
  279. (defvar init-file-loaded nil
  280.   "True after the user's init file has been loaded (or suppressed with -q).
  281. This will be true when `after-init-hook' is run and at all times
  282. after, and will not be true at any time before.")
  283.  
  284. (defvar initial-frame-unmapped-p nil)
  285.  
  286.  
  287. ;;; default switches
  288. ;;; Note: these doc strings are semi-magical.
  289.  
  290. (defun command-line-do-funcall (arg)
  291.   "Invoke the named lisp function with no arguments.
  292. <function>"
  293.   (let ((fn (intern (car command-line-args-left))))
  294.     (setq command-line-args-left (cdr command-line-args-left))
  295.     (funcall fn)))
  296. (fset 'command-line-do-funcall-1 'command-line-do-funcall)
  297. (put 'command-line-do-funcall-1 'undocumented t)
  298.  
  299. (defun command-line-do-eval (arg)
  300.   "Evaluate the lisp form.  Quote it carefully.
  301. <form>"
  302.   (let ((form (car command-line-args-left)))
  303.     (setq command-line-args-left (cdr command-line-args-left))
  304.     (eval (read form))))
  305.  
  306. (defun command-line-do-load (arg)
  307.   "Load the named file of Lisp code into XEmacs.
  308. <file>"
  309.   (let ((file (car command-line-args-left)))
  310.     ;; Take file from default dir if it exists there;
  311.     ;; otherwise let `load' search for it.
  312.     (if (file-exists-p (expand-file-name file))
  313.     (setq file (expand-file-name file)))
  314.     (load file nil t))
  315.   (setq command-line-args-left (cdr command-line-args-left)))
  316.  
  317. (defun command-line-do-insert (arg)
  318.   "Insert file into the current buffer.
  319. <file>"
  320.   (insert-file-contents (car command-line-args-left))
  321.   (setq command-line-args-left (cdr command-line-args-left)))
  322.  
  323. (defun command-line-do-kill (arg)
  324.   "Exit XEmacs."
  325.   (kill-emacs t))
  326.  
  327. (defun command-line-do-version (arg)
  328.   "Print version info and exit."
  329.   (princ (concat (emacs-version) "\n") 'external-debugging-output)
  330.   (kill-emacs 0))
  331.  
  332. (setq command-switch-alist
  333.       (purecopy
  334.        '(("-help"    . command-line-do-help)
  335.      ("-version"    . command-line-do-version)
  336.      ("-funcall"    . command-line-do-funcall)
  337.          ("-f"        . command-line-do-funcall)
  338.      ("-e"        . command-line-do-funcall-1)
  339.      ("-eval"    . command-line-do-eval)
  340.      ("-load"    . command-line-do-load)
  341.      ("-l"        . command-line-do-load)
  342.      ("-insert"    . command-line-do-insert)
  343.      ("-i"        . command-line-do-insert)
  344.      ("-kill"    . command-line-do-kill)
  345.      ;; Options like +35 are handled specially.
  346.      ;; Window-system, site, or package-specific code might add to this.
  347.      ;; X11 handles its options by letting Xt remove args from this list.
  348.      )))
  349.  
  350. ;;; Processing the command line and loading various init files
  351.  
  352. (defun early-error-handler (&rest debugger-args)
  353.   "You should probably not be using this."
  354.   ;; Used as the debugger during emacs initialization; if an error occurs,
  355.   ;; print some diagnostics, and kill emacs.
  356.  
  357.   ;; output the contents of the warning buffer, since it won't be seen
  358.   ;; otherwise.
  359.   ;; #### kludge!  The call to Feval forces the pending warnings to
  360.   ;; get output.  There definitely needs to be a better way.
  361.   (let ((buffer (eval (get-buffer-create "*Warnings*"))))
  362.     (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
  363.        'external-debugging-output))
  364.  
  365.   (let ((string "Initialization error")
  366.     (error (nth 1 debugger-args))
  367.     (debug-on-error nil)
  368.     (stream 'external-debugging-output))
  369.     (if (null error)
  370.     (princ string stream)
  371.       (princ (concat "\n" string ": ") stream)
  372.       (condition-case ()
  373.       (display-error error stream)
  374.     (error (princ "<<< error printing error message >>>" stream)))
  375.       (princ "\n" stream)
  376.       (if (memq (car-safe error) '(void-function void-variable))
  377.       (princ "
  378.     This probably means that xemacs is picking up an old version of
  379.     the lisp library, or that some .elc files are not up-to-date.\n"
  380.          stream)))
  381.     (if (not suppress-early-error-handler-backtrace)
  382.     (let ((print-length 1000)
  383.           (print-level 1000)
  384.           (print-escape-newlines t)
  385.           (print-readably nil))
  386.       (if (getenv "EMACSLOADPATH")
  387.           (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
  388.              stream))
  389.       (princ (format "\nexec-directory is %S" exec-directory) stream)
  390.       (princ (format "\ndata-directory is %S" data-directory) stream)
  391.       (princ (format "\ndoc-directory is %S" doc-directory) stream)
  392.       (princ (format "\nload-path is %S" load-path) stream)
  393.       (princ "\n\n" stream)))
  394.     (if (not suppress-early-error-handler-backtrace)
  395.     (backtrace stream t)))
  396.   (kill-emacs -1))
  397.  
  398. (defun normal-top-level ()
  399.   (if command-line-processed
  400.       (message "Back to top level.")
  401.     (setq command-line-processed t)
  402.     ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
  403.     (if (not (eq system-type 'vax-vms))
  404.         (let ((value (getenv "HOME")))
  405.           (if (and value
  406.                    (< (length value) (length default-directory))
  407.                    (equal (file-attributes default-directory)
  408.                           (file-attributes value)))
  409.               (setq default-directory (file-name-as-directory value)))))
  410.     (setq default-directory (abbreviate-file-name default-directory))
  411.     (setq user-mail-address (concat (user-login-name) "@" (system-name)))
  412.     (unwind-protect
  413.     (command-line)
  414.       ;; Do this again, in case .emacs defined more abbreviations.
  415.       (setq default-directory (abbreviate-file-name default-directory))
  416.       (run-hooks 'emacs-startup-hook)
  417.       (and term-setup-hook
  418.        (run-hooks 'term-setup-hook))
  419.       (setq term-setup-hook nil)
  420.       ;;####FSFmacs junk
  421. ;      ;; Modify the initial frame based on what .emacs puts into
  422. ;      ;; ...-frame-alist.
  423. ;      (if (fboundp 'frame-notice-user-settings)
  424. ;      (frame-notice-user-settings))
  425. ;      ;; Now we know the user's default font, so add it to the menu.
  426. ;      (if (fboundp 'font-menu-add-default)
  427. ;      (font-menu-add-default))
  428.       (and window-setup-hook
  429.        (run-hooks 'window-setup-hook))
  430.       (setq window-setup-hook nil))
  431.       ;;####FSFmacs junk
  432. ;      (or menubar-bindings-done
  433. ;      (precompute-menubar-bindings))
  434.     ))
  435.  
  436. ;;####FSFmacs junk
  437. ;;; Precompute the keyboard equivalents in the menu bar items.
  438. ;(defun precompute-menubar-bindings ()
  439. ;  (if (eq window-system 'x)
  440. ;      (let ((submap (lookup-key global-map [menu-bar])))
  441. ;    (while submap
  442. ;      (and (consp (car submap))
  443. ;           (symbolp (car (car submap)))
  444. ;           (stringp (car-safe (cdr (car submap))))
  445. ;           (keymapp (cdr (cdr (car submap))))
  446. ;           (x-popup-menu nil (cdr (cdr (car submap)))))
  447. ;      (setq submap (cdr submap))))))
  448.  
  449. (defun command-line-early ()
  450.   ;; This processes those switches which need to be processed before
  451.   ;; starting up the window system.
  452.  
  453.   (setq command-line-default-directory default-directory)
  454.  
  455.   ;; See if we should import version-control from the environment variable.
  456.   (let ((vc (getenv "VERSION_CONTROL")))
  457.     (cond ((eq vc nil))            ;don't do anything if not set
  458.       ((or (string= vc "t")
  459.            (string= vc "numbered"))
  460.        (setq version-control t))
  461.       ((or (string= vc "nil")
  462.            (string= vc "existing"))
  463.        (setq version-control nil))
  464.       ((or (string= vc "never")
  465.            (string= vc "simple"))
  466.        (setq version-control 'never))))
  467.  
  468. ;;####FSFmacs
  469. ;  (if (let ((ctype
  470. ;         ;; Use the first of these three envvars that has a nonempty value.
  471. ;         (or (let ((string (getenv "LC_ALL")))
  472. ;           (and (not (equal string "")) string))
  473. ;         (let ((string (getenv "LC_CTYPE")))
  474. ;           (and (not (equal string "")) string))
  475. ;         (let ((string (getenv "LANG")))
  476. ;           (and (not (equal string "")) string)))))
  477. ;    (and ctype
  478. ;         (string-match iso-8859-1-locale-regexp ctype)))
  479. ;      (progn 
  480. ;    (standard-display-european t)
  481. ;    (require 'iso-syntax)))
  482.  
  483.   (let ((done nil))
  484.     ;; Figure out which user's init file to load,
  485.     ;; either from the environment or from the options.
  486.     (setq init-file-user (if (noninteractive) nil (user-login-name)))
  487.     ;; If user has not done su, use current $HOME to find .emacs.
  488.     (and init-file-user (string= init-file-user (user-real-login-name))
  489.      (setq init-file-user ""))
  490.  
  491.     (while (and (not done) command-line-args-left)
  492.       (let ((argi (car command-line-args-left)))
  493.     (cond ((or (string-equal argi "-q")
  494.            (string-equal argi "-no-init-file"))
  495.            (setq init-file-user nil
  496.              command-line-args-left (cdr command-line-args-left)))
  497.           ((string-equal argi "-no-site-file")
  498.            (setq site-start-file nil
  499.              command-line-args-left (cdr command-line-args-left)))
  500.           ((or (string-equal argi "-u")
  501.            (string-equal argi "-user"))
  502.            (setq command-line-args-left (cdr command-line-args-left)
  503.              init-file-user (car command-line-args-left)
  504.              command-line-args-left (cdr command-line-args-left)))
  505.               ((string-equal argi "-debug-init")
  506.                (setq init-file-debug t
  507.                      command-line-args-left (cdr command-line-args-left)))
  508.               ((string-equal argi "-unmapped")
  509.                (setq initial-frame-unmapped-p t
  510.                      command-line-args-left (cdr command-line-args-left)))
  511.            (t (setq done t)))))))
  512.  
  513.  
  514. (defun command-line ()
  515.   (let ((command-line-args-left (cdr command-line-args)))
  516.  
  517.     (let ((debugger 'early-error-handler)
  518.       (debug-on-error t))
  519.       (set-default-load-path)
  520.  
  521.       ;; Process magic command-line switches like -q and -u.  Do this
  522.       ;; before creating the first frame because some of these switches
  523.       ;; may affect that.  I think it's ok to do this before establishing
  524.       ;; the X connection, and maybe someday things like -nw can be
  525.       ;; handled here instead of down in C.
  526.       (command-line-early)
  527.  
  528.       ;; Setup the toolbar icon directory
  529.       (init-toolbar-location)
  530.  
  531.       ;; Initialize the built-in glyphs and the default specifier
  532.       ;; lists
  533.       (if (not noninteractive)
  534.       (init-glyphs))
  535.  
  536.       ;; Read the generic window system init file.
  537.       (if (not noninteractive)
  538.       (load "term/generic-win" nil t))
  539.  
  540.       ;; Read the window system's init file.  tty is considered to be
  541.       ;; a type of window system for this purpose.
  542.       (if (and initial-window-system (not noninteractive))
  543.       (load (concat (symbol-name initial-window-system)
  544.             "-win")
  545.         ;; Every window system should have a startup file;
  546.         ;; barf if we can't find it.
  547.         nil t))
  548.  
  549.       ;; Under a window system, this creates the first visible frame,
  550.       ;; and deletes the stdio frame.
  551.       (if (fboundp 'frame-initialize)
  552.       (frame-initialize))
  553.       )
  554.  
  555.     ;;
  556.     ;; We have normality, I repeat, we have normality.  Anything you still
  557.     ;; can't cope with is therefore your own problem.  (And we don't need
  558.     ;; to kill emacs for it.)
  559.     ;;
  560.  
  561.     ;;; Load init files.
  562.     (load-init-file)
  563.     
  564.     ;; If *scratch* exists and init file didn't change its mode, initialize it.
  565.     (if (get-buffer "*scratch*")
  566.     (save-excursion
  567.       (set-buffer "*scratch*")
  568.       (if (eq major-mode 'fundamental-mode)
  569.           (funcall initial-major-mode))))
  570.  
  571.     ;; Load library for our terminal type.
  572.     ;; User init file can set term-file-prefix to nil to prevent this.
  573.     ;; #### Short-circuit this for now because it won't work right
  574.     ;; until we finish overhauling the tty support system to fit into
  575.     ;; the device system.
  576.     (and nil
  577.      term-file-prefix
  578.      (not (noninteractive))
  579.      (not window-system)
  580.          (let ((term (getenv "TERM"))
  581.                hyphend)
  582.            (while (and term
  583.                        (not (load (concat term-file-prefix term) t t)))
  584.              ;; Strip off last hyphen and what follows, then try again
  585.              (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
  586.                  (setq term (substring term 0 hyphend))
  587.                  (setq term nil)))))
  588.  
  589.     ;; Process the remaining args.
  590.     (command-line-1)
  591.  
  592.     ;; it was turned on by default so that the warnings don't get displayed
  593.     ;; until after the splash screen.
  594.     (setq inhibit-warning-display nil)
  595.     ;; If -batch, terminate after processing the command options.
  596.     (if (noninteractive) (kill-emacs t))))
  597.  
  598. (defun load-user-init-file (init-file-user)
  599.   ;; This function actually reads the init files.
  600.   (if init-file-user
  601.       (progn
  602.     (setq user-init-file 
  603.           (cond 
  604.            ((eq system-type 'ms-dos)
  605.         (concat "~" init-file-user "/_emacs"))
  606.            ((eq system-type 'vax-vms) 
  607.         "sys$login:.emacs")
  608.            (t 
  609.         (concat "~" init-file-user "/.emacs"))))
  610.     (load user-init-file t t t)
  611.     (or inhibit-default-init
  612.         (let ((inhibit-startup-message nil))
  613.           ;; Users are supposed to be told their rights.
  614.           ;; (Plus how to get help and how to undo.)
  615.           ;; Don't you dare turn this off for anyone
  616.           ;; except yourself.
  617.           (load "default" t t))))))
  618.  
  619. ;;; Load user's init file and default ones.
  620. (defun load-init-file ()
  621.   (run-hooks 'before-init-hook)
  622.   (setq user-mail-address (concat (user-login-name) "@" (system-name)
  623.                   " (" (user-full-name) ")"))
  624.  
  625.   ;; Run the site-start library if it exists.  The point of this file is
  626.   ;; that it is run before .emacs.  There is no point in doing this after
  627.   ;; .emacs; that is useless.
  628.   (if site-start-file
  629.       (load site-start-file t t))
  630.  
  631.   ;; Sites should not disable this.  Only individuals should disable
  632.   ;; the startup message.
  633.   (setq inhibit-startup-message nil)
  634.  
  635.   (let (debug-on-error-from-init-file
  636.     debug-on-error-should-be-set
  637.     (debug-on-error-initial
  638.      (if (eq init-file-debug t) 'startup init-file-debug)))
  639.     (let ((debug-on-error debug-on-error-initial))
  640.       (if init-file-debug
  641.       ;; Do this without a condition-case if the user wants to debug.
  642.       (load-user-init-file init-file-user)
  643.     (condition-case error
  644.         (progn
  645.           (load-user-init-file init-file-user)
  646.           (setq init-file-had-error nil))
  647.           (error
  648.            (message "Error in init file: ")
  649.            (display-error error nil)
  650.        (setq init-file-had-error t))))
  651.       ;; If we can tell that the init file altered debug-on-error,
  652.       ;; arrange to preserve the value that it set up.
  653.       (or (eq debug-on-error debug-on-error-initial)
  654.       (setq debug-on-error-should-be-set t
  655.         debug-on-error-from-init-file debug-on-error)))
  656.     (if debug-on-error-should-be-set
  657.     (setq debug-on-error debug-on-error-from-init-file)))
  658.  
  659.   (setq init-file-loaded t)
  660.   (run-hooks 'after-init-hook)
  661.   nil)
  662.  
  663. (defun command-line-1 ()
  664.   (if (null command-line-args-left)
  665.       (cond ((and (not inhibit-startup-message) (not (noninteractive))
  666.           ;; Don't clobber a non-scratch buffer if init file
  667.           ;; has selected it.
  668.           (string= (buffer-name) "*scratch*")
  669.           (not (input-pending-p)))
  670.  
  671.          ;; If there are no switches to process, run the term-setup-hook
  672.          ;; before displaying the copyright notice; there may be some need
  673.          ;; to do it before doing any output.  If we're not going to
  674.          ;; display a copyright notice (because other options are present)
  675.          ;; then this is run after those options are processed.
  676.          (run-hooks 'term-setup-hook)
  677.          ;; Don't let the hook be run twice.
  678.          (setq term-setup-hook nil)
  679.  
  680.              (let ((timeout nil))
  681.                (unwind-protect
  682.                     ;; Guts of with-timeout
  683.                     (catch 'timeout
  684.                       (setq timeout (add-timeout startup-message-timeout
  685.                                                  #'(lambda (ignore)
  686.                                                      (condition-case nil
  687.                                                          (throw 'timeout t)
  688.                                                        (error nil)))
  689.                                                  nil))
  690.                       (startup-splash-frame)
  691.                       (or nil ;; (pos-visible-in-window-p (point-min))
  692.                           (goto-char (point-min)))
  693.                       (sit-for 0)
  694.                       (setq unread-command-event (next-command-event)))
  695.                  (if timeout (disable-timeout timeout))
  696.                  (save-excursion
  697.                    ;; In case the XEmacs server has already selected
  698.                    ;; another buffer, erase the one our message is in.
  699.            (progn
  700.              (set-buffer (get-buffer "*scratch*"))
  701.              (erase-buffer)
  702.              (set-buffer-modified-p nil)))))))
  703.     (let ((dir command-line-default-directory)
  704.       (file-count 0)
  705.       first-file-buffer
  706.       (line nil))
  707.       (while command-line-args-left
  708.     (let ((argi (car command-line-args-left))
  709.           tem)
  710.       (setq command-line-args-left (cdr command-line-args-left))
  711.       (or (cond (line 
  712.              nil)
  713.             ((setq tem (or (assoc argi command-switch-alist)
  714.                    (and (string-match "\\`--" argi)
  715.                     (assoc (substring argi 1)
  716.                            command-switch-alist))))
  717.              (funcall (cdr tem) argi)
  718.              t)
  719.             ((string-match "\\`\\+[0-9]+\\'" argi)
  720.              (setq line (string-to-int argi))
  721.              t)
  722.             ((or (equal argi "-") (equal argi "--"))
  723.              ;; "- file" means don't treat "file" as a switch
  724.              ;;  ("+0 file" has the same effect; "-" added
  725.              ;;   for unixoidiality).
  726.              ;; This is worthless; the `unixoid' way is "./file". -jwz
  727.              (setq line 0))
  728.             (t
  729.              nil))
  730.           (progn
  731.         (setq file-count (1+ file-count))
  732.         (setq argi (expand-file-name argi dir))
  733.         (if (= file-count 1)
  734.             (setq first-file-buffer (progn (find-file argi)
  735.                            (current-buffer)))
  736.           (if noninteractive
  737.               (find-file argi)
  738.             (find-file-other-window argi)))
  739.         (goto-line (or line 0))
  740.         (setq line nil)))))
  741.       ;; If 3 or more files visited, and not all visible,
  742.       ;; show user what they all are.
  743.       (if (and (not noninteractive)
  744.            (> file-count 2))
  745.       (or (get-buffer-window first-file-buffer)
  746.           (progn (other-window 1)
  747.              (buffer-menu nil)))))))
  748.  
  749. (defvar startup-presentation-hack-keymap
  750.   (let ((map (make-sparse-keymap)))
  751.     (set-keymap-name map 'startup-presentation-hack-keymap)
  752.     (define-key map '[button1] 'startup-presentation-hack)
  753.     (define-key map '[button2] 'startup-presentation-hack)
  754.     map)
  755.   "Putting yesterday in the future tomorrow.")
  756.  
  757. (defun startup-presentation-hack ()
  758.   (interactive)
  759.   (let ((e last-command-event))
  760.     (and (button-press-event-p e)
  761.          (setq e (extent-at (event-point e)
  762.                             (event-buffer e)
  763.                             'startup-presentation-hack))
  764.          (setq e (extent-property e 'startup-presentation-hack))
  765.          (if (consp e)
  766.              (apply (car e) (cdr e))
  767.            (progn
  768.              (while (keymapp (indirect-function e))
  769.                (let ((map e)
  770.                      (overriding-local-map (indirect-function e)))
  771.                  (setq e (read-key-sequence
  772.                           (let ((p (keymap-prompt map t)))
  773.                             (cond ((symbolp map)
  774.                                    (if p 
  775.                                        (format "%s %s " map p)
  776.                                        (format "%s " map p)))
  777.                                   (p)
  778.                                   (t
  779.                                    (prin1-to-string map))))))
  780.                  (if (and (button-release-event-p (elt e 0))
  781.                           (null (key-binding e)))
  782.                      (setq e map)       ; try again
  783.                      (setq e (key-binding e)))))
  784.              (call-interactively e))))))
  785.  
  786. (defun startup-presentation-hack-help (e)
  787.   (setq e (extent-property e 'startup-presentation-hack))
  788.   (if (consp e)
  789.       (format "Evaluate %S" e)
  790.       (symbol-name e)))
  791.  
  792. (defun splash-frame-present-hack (e v)
  793. ;  (set-extent-property e 'highlight t)
  794. ;  (set-extent-property e 'keymap
  795. ;                       startup-presentation-hack-keymap)
  796. ;  (set-extent-property e 'startup-presentation-hack v)
  797. ;  (set-extent-property e 'help-echo
  798. ;                       'startup-presentation-hack-help))
  799.   )
  800.  
  801. (defun splash-frame-present (l)
  802.   (cond ((stringp l)
  803.          (insert l))
  804.         ((eq (car-safe l) 'face)
  805.          ;; (face name string)
  806.          (let ((p (point)))
  807.            (splash-frame-present (elt l 2))
  808.            (if (fboundp 'set-extent-face)
  809.                (set-extent-face (make-extent p (point))
  810.                                 (elt l 1)))))
  811.         ((eq (car-safe l) 'key)
  812.          (let* ((c (elt l 1))
  813.                 (p (point))
  814.                 (k (where-is-internal c nil t)))
  815.            (insert (if k (key-description k)
  816.                        (format "M-x %s" c)))
  817.            (if (fboundp 'set-extent-face)
  818.                (let ((e (make-extent p (point))))
  819.                  (set-extent-face e 'bold)
  820.                  (splash-frame-present-hack e c)))))
  821.         ((eq (car-safe l) 'funcall)
  822.          ;; (funcall (fun . args) string)
  823.          (let ((p (point)))
  824.            (splash-frame-present (elt l 2))
  825.            (if (fboundp 'set-extent-face)
  826.                (splash-frame-present-hack (make-extent p (point))
  827.                                            (elt l 1)))))
  828.         (t
  829.          (error "WTF!?"))))
  830.  
  831. (defun startup-center-spaces (glyph)
  832.   ;; Return the number of spaces to insert in order to center
  833.   ;; the given glyph (may be a string or a pixmap).
  834.   ;; Assume spaces are as wide as avg-pixwidth.  
  835.   ;; Won't be quite right for proportional fonts, but it's the best we can do.
  836.   ;; Maybe the new redisplay will export something a glyph-width function.
  837.   ;;; #### Yes, there is a glyph-width function but it isn't quite what
  838.   ;;; #### this was expecting.  Or is it?
  839.   ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
  840.   ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
  841.  
  842.   ;; This function is used in about.el too.
  843.   (let* ((avg-pixwidth     (round (/ (frame-pixel-width) (frame-width))))
  844.      (fill-area-width  (* avg-pixwidth (- fill-column left-margin)))
  845.      (glyph-pixwidth   (cond ((stringp glyph) 
  846.                   (* avg-pixwidth (length glyph)))
  847.                  ;; #### the pixmap option should be removed
  848.                  ;;((pixmapp glyph)
  849.                  ;; (pixmap-width glyph))
  850.                  ((glyphp glyph)
  851.                   (glyph-width glyph))
  852.                  (t
  853.                   (error "startup-center-spaces: bad arg")))))
  854.     (+ left-margin
  855.        (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
  856.  
  857. (defun startup-splash-frame ()
  858.   (let ((p (point)))
  859.     (if (eq 'x (device-type (selected-device))) (insert "\n"))
  860.     (indent-to (startup-center-spaces xemacs-logo))
  861.     (set-extent-begin-glyph (make-extent (point) (point)) xemacs-logo)
  862.     (if (eq 'x (device-type (selected-device)))
  863.     (insert "\n\n")
  864.       (insert "\n"))
  865.     (splash-frame-present-hack (make-extent p (point)) 'about-xemacs))
  866.  
  867.   (insert "\n" (emacs-version) "\n")
  868.   (let ((after-change-functions nil) ; no font-lock, thank you
  869.     (l '((face bold-italic "Copyright (C) 1985-1995 Free Software Foundation, Inc.
  870. Copyright (C) 1990-1994 Lucid, Inc.
  871. Copyright (C) 1993-1995 Sun Microsystems, Inc. All Rights Reserved.
  872. Copyright (C) 1994-1995 Board of Trustees, University of Illinois
  873. Copyright (C) 1994-1995 Amdahl Corporation")
  874.          "\n\nSunSoft provides support for the SPARCWorks/XEmacs EOS integration package\n"
  875.          "only.  All other XEmacs packages are provided to you \"AS IS\"."
  876.  
  877.          "\n\nType " (key describe-no-warranty) " to refer to the GPL "
  878.          "Version 2, dated June 1991, for full details.\n"
  879.          "You may give out copies of XEmacs; type "
  880.          (key describe-copying) " to see the conditions.\n"
  881.          "Type " (key describe-distribution)
  882.          " for information on getting the latest version."
  883.  
  884.              "\n\nType " (key help-command) " for help; "
  885.              (key advertised-undo)
  886.              " to undo changes.  (`C-' means use the CTRL key.)\n"
  887.              "To get out of XEmacs, type " (key save-buffers-kill-emacs) ".\n"
  888.              "Type " (key help-with-tutorial)
  889.              " for a tutorial on using XEmacs.\n"
  890.              "Type " (key info) " to enter Info, "
  891.              "which you can use to read documentation.\n\n")))
  892.     (while l
  893.       (splash-frame-present (car l))
  894.       (setq l (cdr l))))
  895.   (let ((present-file
  896.          #'(lambda (f)
  897.              (splash-frame-present
  898.           (list 'funcall
  899.             (list 'find-file-other-window
  900.               (expand-file-name f data-directory))
  901.             f)))))
  902.     (insert "For customization examples, see the files ")
  903.     (funcall present-file "sample.emacs")
  904.     (insert " and ")
  905.     (funcall present-file "sample.Xdefaults")
  906.     (insert (format "\nin the directory %s" data-directory)))
  907.   (set-buffer-modified-p nil))
  908.  
  909. ;;;; Computing the default load-path, etc.
  910. ;;;
  911. ;;; This stuff is a complete mess and isn't nearly as general as it 
  912. ;;; thinks it is.  It should be rethunk.  In particular, too much logic
  913. ;;; is duplicated between the code that looks around for the various
  914. ;;; directories, and the code which suggests where to create the various
  915. ;;; directories once it decides they are missing.
  916.  
  917. ;;; The source directory has this layout:
  918. ;;;
  919. ;;;    BUILD_ROOT/src/xemacs*              argv[0]
  920. ;;;    BUILD_ROOT/xemacs*              argv[0], possibly
  921. ;;;    BUILD_ROOT/lisp/
  922. ;;;    BUILD_ROOT/etc/                  data-directory
  923. ;;;    BUILD_ROOT/info/
  924. ;;;    BUILD_ROOT/lib-src/              exec-directory, doc-directory
  925. ;;;    BUILD_ROOT/lock/
  926. ;;;
  927. ;;; The default tree created by "make install" has this layout:
  928. ;;;
  929. ;;;    PREFIX/bin/xemacs*              argv[0]
  930. ;;;    PREFIX/lib/xemacs-VERSION/lisp/
  931. ;;;    PREFIX/lib/xemacs-VERSION/etc/          data-directory
  932. ;;;    PREFIX/lib/xemacs-VERSION/info/
  933. ;;;    PREFIX/lib/xemacs-VERSION/CONFIGURATION/      exec-directory, doc-directory
  934. ;;;    PREFIX/lib/xemacs/lock/
  935. ;;;    PREFIX/lib/xemacs/site-lisp/
  936. ;;;
  937. ;;; The binary packages we ship have that layout, except that argv[0] has
  938. ;;; been moved one level deeper under the bin directory:
  939. ;;;
  940. ;;;    PREFIX/bin/CONFIGURATION/xemacs*
  941. ;;;
  942. ;;; The following code has to deal with at least the above three situations,
  943. ;;; and it should be possible for it to deal with more.  Though perhaps that
  944. ;;; does cover it all?  The trick is, when something is missing, realizing
  945. ;;; which of those three layouts is mostly in place, so that we can suggest
  946. ;;; the right directories in the error message.
  947.  
  948.  
  949. ;; extremely low-tech debugging, since this happens so early in startup.
  950. ;(or (fboundp 'orig-file-directory-p)
  951. ;    (fset 'orig-file-directory-p (symbol-function 'file-directory-p)))
  952. ;(defun file-directory-p (path)
  953. ;  (send-string-to-terminal (format "PROBING %S" path))
  954. ;  (let ((v (orig-file-directory-p path)))
  955. ;    (send-string-to-terminal (format " -> %S\n" v))
  956. ;    v))
  957.  
  958. (defun startup-make-version-dir ()
  959.   (let ((version (and (string-match "\\`[^0-9]*\\([0-9]+\\.[0-9]+\\)"
  960.                     emacs-version)
  961.               (substring emacs-version
  962.                  (match-beginning 1) (match-end 1)))))
  963.     (if (string-match "(beta *\\([0-9]+\\))" emacs-version)
  964.     (setq version (concat version "-b"
  965.                   (substring emacs-version (match-beginning 1)
  966.                      (match-end 1)))))
  967.     (if (string-match "(alpha *\\([0-9]+\\))" emacs-version)
  968.     (setq version (concat version "-a"
  969.                   (substring emacs-version (match-beginning 1)
  970.                      (match-end 1)))))
  971.     (concat "lib/xemacs-" version)))
  972.  
  973.  
  974. (defun find-emacs-root-internal (path)
  975. ;;  (send-string-to-terminal (format "FINDING ROOT FOR %S\n" path))
  976.   (let ((dir (file-name-directory path)))
  977.     (or
  978.      ;;
  979.      ;; If this directory is a plausible root of the emacs tree, return it.
  980.      ;;
  981.      (and (file-directory-p (expand-file-name "lisp/prim" dir))
  982.       (or (file-directory-p (expand-file-name "lib-src" dir))
  983.           (file-directory-p (expand-file-name system-configuration dir)))
  984.       dir)
  985.      ;;
  986.      ;; If the parent of this directory is a plausible root, use it.
  987.      ;; (But don't do so recursively!)
  988.      ;;
  989.      (and (file-directory-p (expand-file-name "../lisp/prim" dir))
  990.       (or (file-directory-p (expand-file-name
  991.                  (format "../%s" system-configuration)
  992.                  dir))
  993.           (file-directory-p (expand-file-name "../lib-src" dir)))
  994.       (expand-file-name "../" dir))
  995.  
  996.      ;; 
  997.      ;; (--run-in-place) Same thing, but from one directory level deeper.
  998.      ;;
  999.      (and (file-directory-p (expand-file-name "../../lisp/prim" dir))
  1000.       (or (file-directory-p (expand-file-name
  1001.                  (format "../%s" system-configuration)
  1002.                  dir))
  1003.           (file-directory-p 
  1004.            (expand-file-name 
  1005.         (format "../../lib-src/%s" system-configuration) dir)))
  1006.       (expand-file-name "../.." dir))
  1007.  
  1008.      ;; If ../lib/xemacs-<version> exists check it.
  1009.      ;; This is of the form "xemacs-19.10/" or "xemacs-19.10-b7/".
  1010.      ;;
  1011.      (let ((ver-dir (concat "../" (startup-make-version-dir))))
  1012.        (and (file-directory-p (expand-file-name
  1013.                    (format "%s/lisp/prim" ver-dir)
  1014.                    dir))
  1015.         (or (file-directory-p (expand-file-name
  1016.                    (format "%s/%s" ver-dir system-configuration)
  1017.                    dir))
  1018.         (file-directory-p (expand-file-name
  1019.                    (format "%s/lib-src" ver-dir)
  1020.                    dir)))
  1021.         (expand-file-name (file-name-as-directory ver-dir) dir)))
  1022.      ;;
  1023.      ;; Same thing, but one higher: ../../lib/xemacs-<version>.
  1024.      ;;
  1025.      (let ((ver-dir (concat "../../" (startup-make-version-dir))))
  1026.        (and (file-directory-p (expand-file-name
  1027.                    (format "%s/lisp/prim" ver-dir)
  1028.                    dir))
  1029.         (or (file-directory-p (expand-file-name
  1030.                    (format "%s/%s" ver-dir system-configuration)
  1031.                    dir))
  1032.         (file-directory-p (expand-file-name
  1033.                    (format "%s/lib-src" ver-dir)
  1034.                    dir)))
  1035.         (expand-file-name (file-name-as-directory ver-dir) dir)))
  1036.      ;;
  1037.      ;; If that doesn't work, and the emacs executable is a symlink, then
  1038.      ;; chase the link and try again there.
  1039.      ;;
  1040.      (and (setq path (file-symlink-p path))
  1041.       (find-emacs-root-internal (expand-file-name path dir)))
  1042.      ;;
  1043.      ;; Otherwise, this directory just doesn't cut it.
  1044.      ;; Some bozos think they can use the 18.59 lisp directory with 19.*.
  1045.      ;; This is because they're not using their brains.  But it might be
  1046.      ;; nice to notice that that is happening and point them in the
  1047.      ;; general direction of a clue.
  1048.      ;;
  1049.      nil)))
  1050.  
  1051.  
  1052. (defun set-default-load-path ()
  1053.   (setq invocation-directory
  1054.     ;; don't let /tmp_mnt/... get into the load-path or exec-path.
  1055.     (abbreviate-file-name invocation-directory))
  1056.  
  1057.   (let* ((root (find-emacs-root-internal (concat invocation-directory
  1058.                          invocation-name)))
  1059.      (lisp (and root (expand-file-name "lisp" root)))
  1060.      (site-lisp (and root
  1061.              (or
  1062.               (let ((f (expand-file-name "xemacs/site-lisp" root)))
  1063.                 (and (file-directory-p f) f))
  1064.               (let ((f (expand-file-name "../xemacs/site-lisp"
  1065.                              root)))
  1066.                 (and (file-directory-p f) f))
  1067.               ;; the next two are for --run-in-place
  1068.               (let ((f (expand-file-name "site-lisp" root)))
  1069.                 (and (file-directory-p f) f))
  1070.               (let ((f (expand-file-name "lisp/site-lisp" root)))
  1071.                 (and (file-directory-p f) f))
  1072.               )))
  1073.      (lib-src (and root
  1074.                (or
  1075.             (let ((f (expand-file-name
  1076.                   (concat "lib-src/" system-configuration)
  1077.                   root)))
  1078.               (and (file-directory-p f) f))
  1079.             (let ((f (expand-file-name "lib-src" root)))
  1080.               (and (file-directory-p f) f))
  1081.             (let ((f (expand-file-name system-configuration root)))
  1082.               (and (file-directory-p f) f)))))
  1083.      (etc  (and root
  1084.             (let ((f (expand-file-name "etc" root)))
  1085.               (and (file-directory-p f) f))))
  1086.      (info (and root
  1087.             (let ((f (expand-file-name "info" root)))
  1088.               (and (file-directory-p f) (file-name-as-directory f)))))
  1089.      (lock (and root
  1090.             (boundp 'lock-directory)
  1091.             (if (and lock-directory (file-directory-p lock-directory))
  1092.             (file-name-as-directory lock-directory)
  1093.               (or
  1094.                (let ((f (expand-file-name "xemacs/lock" root)))
  1095.              (and (file-directory-p f)
  1096.                   (file-name-as-directory f)))
  1097.                (let ((f (expand-file-name "../xemacs/lock" root)))
  1098.              (and (file-directory-p f)
  1099.                   (file-name-as-directory f)))
  1100.                (let ((f (expand-file-name "lock" root)))
  1101.              (and (file-directory-p f)
  1102.                   (file-name-as-directory f)))
  1103.                ;; if none of them exist, make the "guess" be the one that
  1104.                ;; set-default-load-path-warning will suggest.
  1105.                (file-name-as-directory
  1106.             (expand-file-name "../xemacs/lock" root))
  1107.                )))))
  1108.     ;; add site-lisp dir to load-path
  1109.     (if site-lisp
  1110.     (progn
  1111.       ;; If the site-lisp dir isn't on the load-path, add it to the end.
  1112.       (or (member site-lisp load-path)
  1113.           (setq load-path (append load-path (list site-lisp))))
  1114.       ;; Also add any direct subdirectories of the site-lisp directory
  1115.       ;; to the load-path.  But don't add dirs whose names begin
  1116.       ;; with dot or hyphen.
  1117.       (let ((files (directory-files site-lisp nil "^[^-.]" nil 'dirs-only))
  1118.         file)
  1119.         (while files
  1120.           (setq file (car files))
  1121.           (if (and (not (member file '("RCS" "CVS" "SCCS")))
  1122.                (setq file (expand-file-name file site-lisp))
  1123.                (not (member file load-path)))
  1124.           (setq load-path
  1125.             (nconc load-path
  1126.                    (list (file-name-as-directory file)))))
  1127.           (setq files (cdr files))))
  1128.       ))
  1129.     ;; add lisp dir to load-path
  1130.     (if lisp
  1131.     (progn
  1132.       ;; If the lisp dir isn't on the load-path, add it to the end.
  1133.       (or (member lisp load-path)
  1134.           (setq load-path (append load-path (list lisp))))
  1135.       ;; Also add any direct subdirectories of the lisp directory
  1136.       ;; to the load-path.  But don't add dirs whose names begin
  1137.       ;; with dot or hyphen.
  1138.       (let ((files (directory-files lisp nil "^[^-.]" nil 'dirs-only))
  1139.         file)
  1140.         (while files
  1141.           (setq file (car files))
  1142.           (if (and (not (member file '("RCS" "CVS" "SCCS")))
  1143.                (setq file (expand-file-name file lisp))
  1144.                (not (member file load-path)))
  1145.           (setq load-path
  1146.             (nconc load-path
  1147.                    (list (file-name-as-directory file)))))
  1148.           (setq files (cdr files))))
  1149.       ))
  1150.  
  1151.     ;; If running from the build directory, always prefer the exec-directory
  1152.     ;; that is here over the one that came from paths.h.
  1153.     (if (or (and (null exec-directory) lib-src)
  1154.         (and (equal lib-src (expand-file-name "lib-src" root))
  1155.          (not (equal exec-directory lib-src))))
  1156.     (setq exec-directory (file-name-as-directory lib-src)))
  1157.     (if (or (and (null doc-directory) lib-src)
  1158.         (and (equal lib-src (expand-file-name "lib-src" root))
  1159.          (not (equal doc-directory lib-src))))
  1160.     (setq doc-directory (file-name-as-directory lib-src)))
  1161.  
  1162.     (if exec-directory
  1163.     (or (member exec-directory exec-path)
  1164.         (setq exec-path (append exec-path (list exec-directory)))))
  1165.     (if (or (and (null data-directory) etc)
  1166.         (and (equal etc (expand-file-name "etc" root))
  1167.          (not (equal data-directory etc))))
  1168.     (setq data-directory (file-name-as-directory etc)))
  1169.  
  1170.  
  1171.  
  1172.     ;; If `configure' specified an info dir, use it.
  1173.     (or (boundp 'Info-default-directory-list)
  1174.     (setq Info-default-directory-list nil))
  1175.     (cond (configure-info-directory
  1176.        (setq configure-info-directory (file-name-as-directory
  1177.                        configure-info-directory))
  1178.        (or (member configure-info-directory Info-default-directory-list)
  1179.            (setq Info-default-directory-list
  1180.              (append Info-default-directory-list
  1181.                  (list configure-info-directory))))))
  1182.     ;; If we've guessed the info dir, use that (too).
  1183.     (if (and info (not (member info Info-default-directory-list)))
  1184.     (setq Info-default-directory-list
  1185.           (append Info-default-directory-list (list info))))
  1186.  
  1187.     ;; Default the lock dir to being a sibling of the data-directory.
  1188.     ;; If superlock isn't set, or is set to a file in a nonexistent
  1189.     ;; directory, derive it from the lock dir.
  1190.     (if (boundp 'lock-directory)
  1191.     (progn
  1192.       (setq lock-directory lock)
  1193.       (cond ((null lock-directory)
  1194.          (setq superlock-path nil))
  1195.         ((or (null superlock-path)
  1196.              (not (file-directory-p
  1197.                (file-name-directory superlock-path))))
  1198.          (setq superlock-path
  1199.                (expand-file-name "!!!SuperLock!!!"
  1200.                      lock-directory))))))
  1201.  
  1202.     (set-default-load-path-warning)))
  1203.  
  1204.  
  1205. (defun set-default-load-path-warning ()
  1206.   (let ((lock (if (boundp 'lock-directory) lock-directory 't))
  1207.     warnings message guess)
  1208.     (if (and (stringp lock) (not (file-directory-p lock)))
  1209.     (setq lock nil))
  1210.     (cond
  1211.      ((not (and exec-directory data-directory doc-directory load-path lock))
  1212.       (save-excursion
  1213.     (set-buffer (get-buffer-create " *warning-tmp*"))
  1214.     (erase-buffer)
  1215.     (buffer-disable-undo (current-buffer))
  1216.     (if (null lock)
  1217.         (setq warnings (cons "lock-directory" warnings)))
  1218.     (if (null exec-directory)
  1219.         (setq warnings (cons "exec-directory" warnings)))
  1220.     (if (null data-directory)
  1221.         (setq warnings (cons "data-directory" warnings)))
  1222.     (if (null doc-directory)
  1223.         (setq warnings (cons "doc-directory" warnings)))
  1224.     (if (null load-path)
  1225.         (setq warnings (cons "load-path" warnings)))
  1226.     (cond ((cdr (cdr warnings))
  1227.            (setq message (apply 'format "%s, %s, and %s" warnings)))
  1228.           ((cdr warnings)
  1229.            (setq message (apply 'format "%s and %s" warnings)))
  1230.           (t (setq message (format "variable %s" (car warnings)))))
  1231.     (insert "couldn't find an obvious default for " message
  1232.         ", and there were no defaults specified in paths.h when emacs "
  1233.         "was built.  Perhaps some directories don't exist, or the "
  1234.         "emacs executable, " (concat invocation-directory
  1235.                          invocation-name)
  1236.         " is in a strange place?")
  1237.     (setq guess (or exec-directory
  1238.             data-directory
  1239.             doc-directory
  1240.             (car load-path)
  1241.             (and (string-match "/[^/]+\\'" invocation-directory)
  1242.                  (substring invocation-directory 0
  1243.                     (match-beginning 0)))))
  1244.     (if (and guess
  1245.          (or
  1246.           ;; parent of a terminal bin/<configuration> pair (hack hack).
  1247.           (string-match (concat "/bin/"
  1248.                     (regexp-quote system-configuration)
  1249.                     "/?\\'")
  1250.                 guess)
  1251.           ;; parent of terminal src, lib-src, etc, or lisp dir.
  1252.           (string-match "/\\(bin\\|src\\|lib-src\\|etc\\|lisp\\)[^/]*/?\\'"
  1253.                 guess)))
  1254.         (setq guess (substring guess 0 (match-beginning 0))))
  1255.  
  1256.     ;; If neither the exec nor lisp dirs are around, then "guess" that
  1257.     ;; the new configure-style lib dir should be used.  Otherwise, if
  1258.     ;; only one of them appears to be missing, or it's just lock,
  1259.     ;; then guess it to be a sibling of whatever already exists.
  1260.     (if (and (null exec-directory) (null load-path))
  1261.         (setq guess (expand-file-name (startup-make-version-dir) guess)))
  1262.  
  1263.     (if (or (null exec-directory) (null load-path))
  1264.         (insert
  1265.          "\n\nWithout both exec-directory and load-path, emacs will "
  1266.          "be very broken.  "))
  1267.     (if (and (null exec-directory) guess)
  1268.         (insert
  1269.          "Consider making a symbolic link from "
  1270.          (expand-file-name system-configuration guess)
  1271.          " to wherever the appropriate emacs exec-directory directory is"))
  1272.     (if (and (null data-directory) guess)
  1273.         (insert
  1274.          (if exec-directory "\n\nConsider making a symbolic link " ", and ")
  1275.          "from "
  1276.          (expand-file-name "etc" (if load-path
  1277.                      (file-name-directory
  1278.                       (directory-file-name (car load-path)))
  1279.                        guess))
  1280.          " to wherever the appropriate emacs data-directory is"))
  1281.     (if (and (null load-path) guess)
  1282.         (insert
  1283.          (if (and exec-directory data-directory)
  1284.          "Consider making a symbolic link "
  1285.            ", and ")
  1286.          "from "
  1287.          (expand-file-name "lisp" guess)
  1288.          " to wherever the appropriate emacs lisp library is"))
  1289.     (insert ".")
  1290.  
  1291.     (if (null lock)
  1292.         (progn
  1293.           (insert
  1294.            "\n\nWithout lock-directory set, file locking won't work.  ")
  1295.           (if guess
  1296.           (insert
  1297.            "Consider creating "
  1298.            (expand-file-name "../xemacs/lock"
  1299.                      (or (find-emacs-root-internal
  1300.                       (concat invocation-directory
  1301.                           invocation-name))
  1302.                      guess))
  1303.            " as a directory or symbolic link for use as the lock "
  1304.            "directory.  (This directory must be globally writable.)"
  1305.            ))))
  1306.  
  1307.         (if (fboundp 'fill-region)
  1308.             ;; Might not be bound in the cold load environment...
  1309.         (let ((fill-column 76))
  1310.           (fill-region (point-min) (point-max))))
  1311.     (goto-char (point-min))
  1312.     (princ "\nWARNING:\n" 'external-debugging-output)
  1313.     (princ (buffer-string) 'external-debugging-output)
  1314.     (erase-buffer)
  1315.     t)))))
  1316.  
  1317.  
  1318. ;;; startup.el ends here
  1319.