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