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