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