1 ;;; startup.el --- process SXEmacs shell arguments
3 ;; Copyright (C) 1985-1986, 1990, 1992-1997 Free Software Foundation, Inc.
4 ;; Copyright (c) 1993, 1994 Sun Microsystems, Inc.
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
6 ;; Copyright (C) 2004 Steve Youngs
8 ;; Maintainer: SXEmacs Development Team
9 ;; Keywords: internal, dumped
11 ;; This file is part of SXEmacs.
13 ;; SXEmacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; SXEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Synched up with: FSF 19.34.
30 ;; This file is dumped with SXEmacs.
32 ;; -batch, -t, and -nw are processed by main() in emacs.c and are
33 ;; never seen by lisp code.
35 ;; -version and -help are special-cased as well: they imply -batch,
36 ;; but are left on the list for lisp code to process.
40 (setq top-level '(normal-top-level))
42 (defvar command-line-processed nil "t once command line has been processed")
44 (defconst startup-message-timeout 12000) ; More or less disable the timeout
45 (defconst splash-frame-timeout 10) ; interval between splash frame elements
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.")
52 (defconst inhibit-default-init nil
53 "*Non-nil inhibits loading the `default' library.")
55 (defvar command-line-args-left nil
56 "List of command-line args not yet processed.") ; bound by `command-line'
58 (defvar command-line-default-directory nil
59 "Default directory to use for command line arguments.
60 This is normally copied from `default-directory' when SXEmacs starts.")
62 (defvar before-init-hook nil
63 "Functions to call after handling urgent options but before init files.
64 The frame system uses this to open frames to display messages while
65 SXEmacs loads the user's initialization file.")
67 (defvar after-init-hook nil
68 "*Functions to call after loading the init file.
69 The call is not protected by a condition-case, so you can set `debug-on-error'
70 in the init file, and put all the actual code on `after-init-hook'.")
72 (defvar term-setup-hook nil
73 "*Functions to be called after loading terminal-specific Lisp code.
74 See `run-hooks'. This variable exists for users to set, so as to
75 override the definitions made by the terminal-specific file. SXEmacs
76 never sets this variable itself.")
78 (defvar keyboard-type nil
79 "The brand of keyboard you are using.
80 This variable is used to define the proper function and keypad keys
81 for use under X. It is used in a fashion analogous to the environment
84 (defvar window-setup-hook nil
85 "Normal hook run to initialize window system display.
86 SXEmacs runs this hook after processing the command line arguments and loading
87 the user's init file.")
89 (defconst initial-major-mode 'lisp-interaction-mode
90 "Major mode command symbol to use for the initial *scratch* buffer.")
92 (defvar emacs-roots nil
93 "List of plausible roots of the SXEmacs hierarchy.")
95 (defvar user-init-directory-base ".sxemacs"
96 "Base of directory where user-installed init files may go.")
98 (defvar user-init-directory
99 (file-name-as-directory
100 (paths-construct-path (list "~" user-init-directory-base)))
101 "Directory where user-installed init files may go.
103 This defaults to \"~/.sxemacs\". Old XEmacs users can get up and
104 running quickly by symlinking \"~/.sxemacs\" to their existing
105 \"~/.xemacs\" directory.")
107 (defvar user-init-file-base-list '("init.elc" "init.el")
108 "List of allowed init files in the user's init directory.
109 The first one found takes precedence.")
111 (defvar load-user-init-file-p t
112 "Non-nil if SXEmacs should load the user's init file.")
114 ;; #### called `site-run-file' in FSFmacs
116 (defvar site-start-file "site-start"
117 "File containing site-wide run-time initializations.
118 This file is loaded at run-time before `~/.sxemacs/init.el'. It
119 contains inits that need to be in place for the entire site, but
120 which, due to their higher incidence of change, don't make sense to
121 load into SXEmacs' dumped image. Thus, the run-time load order is:
123 1. file described in this variable, if non-nil;
124 2. `~/.sxemacs/init.el';
125 3. `/path/to/sxemacs/lisp/default.el'.
127 Don't use the `site-start.el' file for things some users may not like.
128 Put them in `default.el' instead, so that users can more easily
129 override them. Users can prevent loading `default.el' with the `-q'
130 option or by setting `inhibit-default-init' in their own init files,
131 but inhibiting `site-start.el' requires `--no-site-file', which
132 is less convenient.")
134 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
135 ;; "Regexp that specifies when to enable the ISO 8859-1 character set.
136 ;;We do that if this regexp matches the locale name
137 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
139 (defcustom mail-host-address nil
140 "*Name of this machine, for purposes of naming users."
144 (defcustom 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'."
151 (defvar init-file-debug nil)
153 (defvar init-file-had-error nil)
155 (defvar init-file-loaded nil
156 "True after the user's init file has been loaded (or suppressed with -q).
157 This will be true when `after-init-hook' is run and at all times
158 after, and will not be true at any time before.")
160 (defvar initial-frame-unmapped-p nil)
164 (defvar command-switch-alist
165 '(("-help" . command-line-do-help)
166 ("-version". command-line-do-version)
167 ("-V" . command-line-do-version)
168 ("-funcall". command-line-do-funcall)
169 ("-f" . command-line-do-funcall)
170 ("-e" . command-line-do-funcall-1)
171 ("-eval" . command-line-do-eval)
172 ("-load" . command-line-do-load)
173 ("-l" . command-line-do-load)
174 ("-insert" . command-line-do-insert)
175 ("-i" . command-line-do-insert)
176 ("-kill" . command-line-do-kill)
177 ;; Options like +35 are handled specially.
178 ;; Window-system, site, or package-specific code might add to this.
179 ;; X11 handles its options by letting Xt remove args from this list.
181 "Alist of command-line switches.
182 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
183 HANDLER-FUNCTION receives switch name as sole arg;
184 remaining command-line args are in the variable `command-line-args-left'.")
187 ;;; Note: these doc strings are semi-magical.
189 (defun command-line-do-help (arg)
190 "Print the SXEmacs usage message and exit."
191 (let ((standard-output 'external-debugging-output))
192 (princ (concat "\n" (emacs-version) "\n\n"))
195 (concat "When creating a window on an X display, "
197 " accepts all standard X Toolkit
198 command line options plus the following:
199 -iconname <title> Use title as the icon name.
200 -mc <color> Use color as the mouse color.
201 -cr <color> Use color as the text-cursor foregound color.
202 -private Install a private colormap.
206 (princ " following options are accepted:
207 -sd Show dump ID. Ignored when configured without --pdump.
208 -nd Don't load the dump file. Roughly like old temacs.
209 Ignored when configured without --pdump.
210 -t <device> Use TTY <device> instead of the terminal for input
211 and output. This implies the -nw option.
212 -nw Inhibit the use of any window-system-specific
213 display code: use the current tty.
214 -batch Execute noninteractively (messages go to stderr).
215 -debug-init Enter the debugger if an error in the init file occurs.
216 -unmapped Do not map the initial frame.
217 -no-site-file Do not load the site-specific init file (site-start.el).
218 -no-init-file Do not load the user-specific init file.
219 -no-early-packages Do not process early packages.
220 -no-autoloads Do not load global symbol files (auto-autoloads) at
221 startup. Also implies `-vanilla'.
222 -vanilla Equivalent to -q -no-site-file -no-early-packages.
223 -q Same as -no-init-file.
224 -user-init-file <file> Use <file> as init file.
225 -user-init-directory <directory> Use <directory> as init directory.
226 -user <user> Load user's init file instead of your own.
227 -u <user> Same as -user.\n")
228 (let ((l command-switch-alist)
229 (insert (lambda (&rest x)
234 (incf len (length (car x)))
237 (terpri) (setq len 0))
242 (let ((name (car (car l)))
246 ((and (symbolp fn) (get fn 'undocumented)) nil)
248 (setq doc (documentation fn))
249 (if (member doc '(nil "")) (setq doc "(undocumented)"))
250 (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
251 ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
252 (setq arg (substring doc (match-beginning 1) (match-end 1))
253 doc (substring doc 0 (match-beginning 0))))
254 ((string-match "\n+\\'" doc)
255 (setq doc (substring doc 0 (match-beginning 0)))))
256 (if (and (setq cons (rassq fn command-switch-alist))
257 (not (eq cons (car l))))
258 (setq doc (format "Same as %s." (car cons))))
260 (funcall insert name " " arg)
261 (funcall insert name))
265 (princ (concat "+N <file> Start displaying <file> at line N.
267 Anything else is considered a file name, and is placed into a buffer for
270 " (emacs-name) " has an online tutorial and manuals. Type ^Ht (Control-h t) after
271 starting SXEmacs to run the tutorial. Type ^Hi to enter the manual browser.
272 Type ^H^H^H (Control-h Control-h Control-h) to get more help options.\n")
276 (defun command-line-do-funcall (arg)
277 "Invoke the named lisp function with no arguments.
279 (funcall (intern (pop command-line-args-left))))
280 (fset 'command-line-do-funcall-1 'command-line-do-funcall)
281 (put 'command-line-do-funcall-1 'undocumented t)
283 (defun command-line-do-eval (arg)
284 "Evaluate the lisp form. Quote it carefully.
286 (eval (read (pop command-line-args-left))))
288 (defun command-line-do-load (arg)
289 "Load the named file of Lisp code into SXEmacs.
291 (let ((file (pop command-line-args-left)))
292 ;; Take file from default dir if it exists there;
293 ;; otherwise let `load' search for it.
294 (if (file-exists-p (expand-file-name file))
295 (setq file (expand-file-name file)))
298 (defun command-line-do-insert (arg)
299 "Insert file into the current buffer.
301 (insert-file-contents (pop command-line-args-left)))
303 (defun command-line-do-kill (arg)
307 (defun command-line-do-version (arg)
308 "Print version info and exit."
309 (princ (concat (emacs-version) "\n"))
313 ;;; Processing the command line and loading various init files
315 (defun early-error-handler (&rest debugger-args)
316 "You should probably not be using this."
317 ;; Used as the debugger during SXEmacs initialization; if an error occurs,
318 ;; print some diagnostics, and kill SXEmacs.
320 ;; output the contents of the warning buffer, since it won't be seen
322 ;; #### kludge! The call to Feval forces the pending warnings to
323 ;; get output. There definitely needs to be a better way.
324 (let ((buffer (eval (get-buffer-create "*Warnings*"))))
325 (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
326 'external-debugging-output))
328 (let ((string "Initialization error")
329 (error (nth 1 debugger-args))
331 (stream 'external-debugging-output))
333 (princ string stream)
334 (princ (concat "\n" string ": ") stream)
336 (display-error error stream)
337 (error (princ "<<< error printing error message >>>" stream)))
339 (if (memq (car-safe error) '(void-function void-variable))
341 This probably means that SXEmacs is picking up an old version of
342 the lisp library, or that some .elc files are not up-to-date.\n"
344 (when (not suppress-early-error-handler-backtrace)
345 (let ((print-length 1000)
347 (print-escape-newlines t)
348 (print-readably nil))
349 (when (getenv "EMACSLOADPATH")
350 (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
352 (princ (format "\nexec-directory is %S" exec-directory) stream)
353 (princ (format "\ndata-directory is %S" data-directory) stream)
354 (princ (format "\ndata-directory-list is %S" data-directory-list) stream)
355 (princ (format "\ndoc-directory is %S" doc-directory) stream)
356 (princ (format "\nload-path is %S" load-path) stream)
357 (princ "\n\n" stream)))
358 (when (not suppress-early-error-handler-backtrace)
359 (backtrace stream t)))
362 (defun normal-top-level ()
363 (if command-line-processed
364 (message "Back to top level.")
365 (setq command-line-processed t)
366 ;; Do this first for maximum likelihood of catching errors. The main
367 ;; purpose of this is so that debug-on-error can be set to catch errors
368 ;; during normal noninteractive running.
369 (when (getenv "SXEMACSDEBUG")
370 (eval (read (getenv "SXEMACSDEBUG"))))
371 ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
372 (let ((value (user-home-directory)))
374 (< (length value) (length default-directory))
375 (equal (file-attributes default-directory)
376 (file-attributes value)))
377 (setq default-directory (file-name-as-directory value))))
378 (setq default-directory (abbreviate-file-name default-directory))
379 (initialize-xemacs-paths)
381 (startup-set-invocation-environment)
383 (let ((debug-paths (or debug-paths
384 (and (getenv "EMACSDEBUGPATHS")
387 (setq emacs-roots (paths-find-emacs-roots invocation-directory
391 (princ (format "invocation: p:%S n:%S\n"
392 invocation-directory invocation-name)
393 'external-debugging-output)
394 (princ (format "emacs-roots:\n%S\n" emacs-roots)
395 'external-debugging-output))
397 (if (null emacs-roots)
398 (startup-find-roots-warning))
399 (startup-setup-paths emacs-roots
401 inhibit-early-packages
403 (startup-setup-paths-warning))
405 ;; we set up a separate function, so that a user can later decide
406 ;; to load the autoloads
407 (startup-load-autoloads)
412 ;; catch non-error signals, especially quit
413 (t (setq error-data data)))
414 ;; Do this again, in case the init file defined more abbreviations.
415 (setq default-directory (abbreviate-file-name default-directory))
416 ;; Specify the file for recording all the auto save files of
417 ;; this session. This is used by recover-session.
418 (if auto-save-list-file-prefix
419 (setq auto-save-list-file-name
422 auto-save-list-file-prefix
425 (run-hooks 'emacs-startup-hook)
427 (run-hooks 'term-setup-hook))
428 (setq term-setup-hook nil)
429 ;; ;; Modify the initial frame based on what the init file puts into
430 ;; ;; ...-frame-alist.
431 (frame-notice-user-settings)
432 ;; ;;####FSFmacs junk
433 ;; ;; Now we know the user's default font, so add it to the menu.
434 ;; (if (fboundp 'font-menu-add-default)
435 ;; (font-menu-add-default))
436 (when window-setup-hook
437 (run-hooks 'window-setup-hook))
438 (setq window-setup-hook nil)
440 ;; re-signal, and don't allow continuation as that will probably
441 ;; wipe out the user's .emacs if she hasn't migrated yet!
442 ;; Not applicable to SXEmacs --SY.
443 (signal-error (car error-data) (cdr error-data))))
445 ;; FSF calls precompute-menubar-bindings. We don't mix menubars
449 (defun command-line-early (args)
450 ;; This processes those switches which need to be processed before
451 ;; starting up the window system.
453 (setq command-line-default-directory default-directory)
455 ;; See if we should import version-control from the environment variable.
456 (let ((vc (getenv "VERSION_CONTROL")))
457 (cond ((eq vc nil)) ;don't do anything if not set
458 ((or (string= vc "t")
459 (string= vc "numbered"))
460 (setq version-control t))
461 ((or (string= vc "nil")
462 (string= vc "existing"))
463 (setq version-control nil))
464 ((or (string= vc "never")
465 (string= vc "simple"))
466 (setq version-control 'never))))
468 (setq load-user-init-file-p (not (noninteractive)))
470 ;; Allow (at least) these arguments anywhere in the command line
474 (setq arg (pop args))
476 ((or (string= arg "-q")
477 (string= arg "-no-init-file"))
478 (setq load-user-init-file-p nil))
479 ((string= arg "-no-site-file")
480 (setq site-start-file nil))
481 ((or (string= arg "-no-early-packages")
482 (string= arg "--no-early-packages"))
483 (setq inhibit-early-packages t))
484 ((or (string= arg "-warn-early-package-shadows")
485 (string= arg "--warn-early-package-shadows"))
486 (setq warn-early-package-shadows t))
487 ((or (string= arg "-vanilla")
488 (string= arg "--vanilla")
489 ;; Some work on this one already done in emacs.c.
490 (string= arg "-no-autoloads")
491 (string= arg "--no-autoloads"))
492 (setq load-user-init-file-p nil
493 site-start-file nil))
494 ((string= arg "-user-init-file")
495 (setq user-init-file (pop args)))
496 ((string= arg "-user-init-directory")
497 (setq user-init-directory (file-name-as-directory (pop args))))
498 ((or (string= arg "-u")
499 (string= arg "-user"))
500 (let* ((user (pop args))
501 (home-user (concat "~" user)))
502 (setq user-init-directory (file-name-as-directory
503 (paths-construct-path
504 (list home-user user-init-directory-base))))
506 (find-user-init-file user-init-directory))
508 (make-custom-file-name user-init-file))))
509 ((string= arg "-debug-init")
510 (setq init-file-debug t))
511 ((string= arg "-unmapped")
512 (setq initial-frame-unmapped-p t))
513 ((or (string= arg "-debug-paths")
514 (string= arg "--debug-paths"))
516 ((or (string= arg "--") (string= arg "-"))
518 (push (pop args) new-args)))
519 (t (push arg new-args))))
521 ;; obsolete, initialize for backward compatibility
522 (with-obsolete-variable 'init-file-user
523 (setq init-file-user (and load-user-init-file-p "")))
525 (nreverse new-args)))
527 (defconst initial-scratch-message
528 ";; This buffer is for notes you don't want to save, and for Lisp evaluation.
529 ;; If you want to create a file, first visit that file with C-x C-f,
530 ;; then enter the text in that file's own buffer.
532 ;; In \"SXEmacs-speak\", `C-char' and `M-char' are abbreviations that mean
533 ;; `Control+char' and `Meta+char' (hold down the Control or Meta key while
536 ;; For Lisp evaluation, type an expression, move to the end and hit C-j.
540 "Initial message displayed in *scratch* buffer at startup.
541 If this is nil, no message will be displayed.")
543 (defun command-line ()
544 (let ((command-line-args-left (cdr command-line-args)))
546 (let ((debugger 'early-error-handler)
549 ;; Process magic command-line switches like -q and -u. Do this
550 ;; before creating the first frame because some of these switches
551 ;; may affect that. I think it's ok to do this before establishing
552 ;; the X connection, and maybe someday things like -nw can be
553 ;; handled here instead of down in C.
554 (setq command-line-args-left (command-line-early command-line-args-left))
556 ;; Setup the toolbar icon directory
557 (when (featurep 'toolbar)
558 (init-toolbar-location))
560 ;; Run the window system's init function. tty is considered to be
561 ;; a type of window system for this purpose. This creates the
562 ;; initial (non stdio) device.
563 (when (and initial-window-system (not noninteractive))
564 (funcall (intern (concat "init-"
565 (symbol-name initial-window-system)
568 ;; When not in batch mode, this creates the first visible frame,
569 ;; and deletes the stdio device.
572 ;; Reinitialize faces if necessary. This function changes face if
573 ;; it is created during auto-autoloads loading. Otherwise, it
575 (startup-initialize-custom-faces)
578 ;; We have normality, I repeat, we have normality. Anything you still
579 ;; can't cope with is therefore your own problem. (And we don't need
580 ;; to kill SXEmacs for it.)
586 (with-current-buffer (get-buffer "*scratch*")
588 ;; (insert initial-scratch-message)
589 (set-buffer-modified-p nil)
590 (when (eq major-mode 'fundamental-mode)
591 (funcall initial-major-mode))
592 (font-lock-set-defaults))
594 ;; Load library for our terminal type.
595 ;; User init file can set term-file-prefix to nil to prevent this.
596 ;; Note that for any TTY's opened subsequently, the TTY init
597 ;; code will run this.
598 (when (and (eq 'tty (console-type))
599 (not (noninteractive)))
600 (load-terminal-library))
602 ;; Process the remaining args.
605 ;; it was turned on by default so that the warnings don't get displayed
606 ;; until after the splash screen.
607 (setq inhibit-warning-display nil)
608 ;; If -batch, terminate after processing the command options.
609 (when (noninteractive) (kill-emacs t))))
611 (defun load-terminal-library ()
612 "Load the terminal initialization library"
613 (when term-file-prefix
614 (let ((term (getenv "TERM"))
617 (not (load (concat term-file-prefix term) t t)))
618 ;; Strip off last hyphen and what follows, then try again
619 (if (setq colornum (string-match #r"[-+_][0-9]+\'" term))
620 (setq term (substring term 0 colornum))
621 (if (setq colornum (string-match #r"[-+_]\([0-9]+\)[^-_]+\'" term))
622 (setq term (replace-in-string term (match-string 1 term) ""))
623 (if (setq hyphend (string-match "[-+_][^-_]+\\'" term))
624 (setq term (substring term 0 hyphend))
625 (setq term nil))))))))
627 (defun find-user-init-directory-init-file (&optional init-directory)
628 "Determine the user's init file if in the init directory."
629 (let ((init-directory (or init-directory user-init-directory)))
631 (dolist (file user-init-file-base-list)
632 (let ((expanded (expand-file-name file init-directory)))
633 (when (file-readable-p expanded)
634 (throw 'found expanded)))))))
636 (defun find-user-init-file (&optional init-directory)
637 "Determine the user's init file."
638 (find-user-init-directory-init-file init-directory))
640 (defun load-user-init-file ()
641 "This function actually reads the init file."
642 (unless (paths-file-readable-directory-p user-init-directory)
643 (make-directory-path user-init-directory))
644 (if (not user-init-file)
646 (find-user-init-file user-init-directory)))
647 (if (not custom-file)
648 (setq custom-file (make-custom-file-name user-init-file)))
649 ;; #### should test load-user-init-file-p here, not in load-init-file
651 (if (and user-init-file
652 (file-readable-p user-init-file))
653 (load user-init-file t t t))
655 (or (not user-init-file)
656 (not (string= custom-file user-init-file)))
657 (file-readable-p custom-file))
658 (load custom-file t t t))
659 (unless inhibit-default-init
660 (let ((inhibit-startup-message nil))
661 ;; Users are supposed to be told their rights.
662 ;; (Plus how to get help and how to undo.)
663 ;; Don't you dare turn this off for anyone except yourself.
664 (load "default" t t))))
666 ;;; Load user's init file and default ones.
667 (defun load-init-file ()
668 (run-hooks 'before-init-hook)
670 ;; Run the site-start library if it exists. The point of this file is
671 ;; that it is run before .emacs. There is no point in doing this after
672 ;; .emacs; that is useless.
673 (when site-start-file
674 (load site-start-file t t))
676 ;; Sites should not disable this. Only individuals should disable
677 ;; the startup message.
678 (setq inhibit-startup-message nil)
680 (let (debug-on-error-from-init-file
681 debug-on-error-should-be-set
682 (debug-on-error-initial
683 (if (eq init-file-debug t) 'startup init-file-debug)))
684 (let ((debug-on-error debug-on-error-initial))
685 ;; #### I believe this test is incorrect, it leads to custom-file
686 ;; (at least) being undefined
687 (if (and load-user-init-file-p init-file-debug)
689 ;; Do this without a condition-case if the user wants to debug.
690 (load-user-init-file))
691 (condition-case error
693 ;; #### probably incorrect, see comment above
694 (if load-user-init-file-p
695 (load-user-init-file))
696 (setq init-file-had-error nil))
698 (message "Error in init file: %s" (error-message-string error))
699 (display-warning 'initialization
700 (format "An error has occurred while loading %s:
704 To ensure normal operation, you should investigate the cause of the error
705 in your initialization file and remove it. Use the `-debug-init' option
706 to SXEmacs to view a complete error backtrace."
707 user-init-file (error-message-string error))
709 (setq init-file-had-error t))))
710 ;; If we can tell that the init file altered debug-on-error,
711 ;; arrange to preserve the value that it set up.
712 (or (eq debug-on-error debug-on-error-initial)
713 (setq debug-on-error-should-be-set t
714 debug-on-error-from-init-file debug-on-error)))
715 (when debug-on-error-should-be-set
716 (setq debug-on-error debug-on-error-from-init-file)))
718 (setq init-file-loaded t)
720 ;; Do this here in case the init file sets mail-host-address.
721 ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
722 ;; (or user-mail-address
724 (setq user-mail-address (concat (user-login-name) "@"
725 (or mail-host-address
728 (run-hooks 'after-init-hook)
731 (defun load-options-file (filename)
732 "Load the file of saved options (from the Options menu) called FILENAME.
733 Currently this does nothing but call `load', but it might be redefined
734 in the future to support automatically converting older options files to
735 a new format, when variables have changed, etc."
738 (defun command-line-1 ()
740 ((null command-line-args-left)
741 (unless noninteractive
742 ;; If there are no switches to process, run the term-setup-hook
743 ;; before displaying the copyright notice; there may be some need
744 ;; to do it before doing any output. If we're not going to
745 ;; display a copyright notice (because other options are present)
746 ;; then this is run after those options are processed.
747 (run-hooks 'term-setup-hook)
748 ;; Don't let the hook be run twice.
749 (setq term-setup-hook nil)
751 ;; Don't clobber a non-scratch buffer if init file
753 (when (string= (buffer-name) "*scratch*")
754 (unless (or inhibit-startup-message
756 (let (tmout circ-tmout)
758 ;; Guts of with-timeout
760 (setq tmout (add-timeout startup-message-timeout
766 (setq circ-tmout (display-splash-frame))
767 (or nil;; (pos-visible-in-window-p (point-min))
768 (goto-char (point-min)))
770 (setq unread-command-event (next-command-event)))
771 (when tmout (disable-timeout tmout))
772 (when circ-tmout (disable-timeout circ-tmout)))))
773 (with-current-buffer (get-buffer "*scratch*")
774 ;; In case the SXEmacs server has already selected
775 ;; another buffer, erase the one our message is in.
777 (when (stringp initial-scratch-message)
778 (insert initial-scratch-message))
779 (set-buffer-modified-p nil)))))
782 ;; Command-line-options exist
783 (let ((dir command-line-default-directory)
788 (while command-line-args-left
789 (setq arg (pop command-line-args-left))
793 ((setq tem (when (eq (aref arg 0) ?-)
794 (or (assoc arg command-switch-alist)
795 (assoc (substring arg 1)
796 command-switch-alist))))
797 (funcall (cdr tem) arg))
798 ((string-match #r"\`\+[0-9]+\'" arg)
799 (setq line (string-to-int arg)))
800 ;; "- file" means don't treat "file" as a switch
801 ;; ("+0 file" has the same effect; "-" added
802 ;; for unixoidiality).
803 ;; This is worthless; the `unixoid' way is "./file". -jwz
804 ((or (string= arg "-") (string= arg "--"))
805 (setq end-of-options t))
812 (setq arg (expand-file-name arg dir))
816 (noninteractive (find-file arg))
817 (t (find-file-other-window arg)))
820 (setq line nil))))))))
822 (defvar startup-presentation-hack-keymap
823 (let ((map (make-sparse-keymap)))
824 (set-keymap-name map 'startup-presentation-hack-keymap)
825 (define-key map '[button1] 'startup-presentation-hack)
826 (define-key map '[button2] 'startup-presentation-hack)
828 "Putting yesterday in the future tomorrow.")
830 (defun startup-presentation-hack ()
832 (let ((e last-command-event))
833 (and (button-press-event-p e)
834 (setq e (extent-at (event-point e)
836 'startup-presentation-hack))
837 (setq e (extent-property e 'startup-presentation-hack))
839 (apply (car e) (cdr e))
840 (while (keymapp (indirect-function e))
842 (overriding-local-map (indirect-function e)))
843 (setq e (read-key-sequence
844 (let ((p (keymap-prompt map t)))
847 (format "%s %s " map p)
851 (prin1-to-string map))))))
852 (if (and (button-release-event-p (elt e 0))
853 (null (key-binding e)))
854 (setq e map) ; try again
855 (setq e (key-binding e)))))
856 (call-interactively e)))))
858 (defun startup-presentation-hack-help (e)
859 (setq e (extent-property e 'startup-presentation-hack))
861 (format "Evaluate %S" e)
864 (defun splash-frame-present-hack (e v)
865 ;; (set-extent-property e 'mouse-face 'highlight)
866 ;; (set-extent-property e 'keymap
867 ;; startup-presentation-hack-keymap)
868 ;; (set-extent-property e 'startup-presentation-hack v)
869 ;; (set-extent-property e 'help-echo
870 ;; 'startup-presentation-hack-help)
873 (defun splash-frame-present (l)
876 ((eq (car-safe l) 'face)
877 ;; (face name string)
879 (splash-frame-present (elt l 2))
880 (if (fboundp 'set-extent-face)
881 (set-extent-face (make-extent p (point))
883 ((eq (car-safe l) 'key)
886 (k (where-is-internal c nil t)))
887 (insert (if k (key-description k)
888 (format "M-x %s" c)))
889 (if (fboundp 'set-extent-face)
890 (let ((e (make-extent p (point))))
891 (set-extent-face e 'bold)
892 (splash-frame-present-hack e c)))))
893 ((eq (car-safe l) 'funcall)
894 ;; (funcall (fun . args) string)
896 (splash-frame-present (elt l 2))
897 (if (fboundp 'set-extent-face)
898 (splash-frame-present-hack (make-extent p (point))
901 (mapcar 'splash-frame-present l))
903 (backtrace 'external-debugging-output)
906 (defun startup-center-spaces (glyph)
907 ;; Return the number of spaces to insert in order to center
908 ;; the given glyph (may be a string or a pixmap).
909 ;; Assume spaces are as wide as avg-pixwidth.
910 ;; Won't be quite right for proportional fonts, but it's the best we can do.
911 ;; Maybe the new redisplay will export something a glyph-width function.
912 ;;; #### Yes, there is a glyph-width function but it isn't quite what
913 ;;; #### this was expecting. Or is it?
914 ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
915 ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
917 ;; This function is used in about.el too.
918 (let* ((avg-pixwidth (round (/ (frame-pixel-width) (frame-width))))
919 (fill-area-width (* avg-pixwidth (- fill-column left-margin)))
920 (glyph-pixwidth (cond ((stringp glyph)
921 (* avg-pixwidth (length glyph)))
922 ;; #### the pixmap option should be removed
924 ;; (pixmap-width glyph))
928 (error "startup-center-spaces: bad arg")))))
930 (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
932 (defun splash-frame-body ()
933 `[((face (blue bold underline)
934 "\nDistribution, copying license, warranty:\n\n")
935 "Please visit the SXEmacs website at http://www.sxemacs.org !\n\n"
936 ((key describe-no-warranty)
937 ": "(face (red bold) "SXEmacs comes with ABSOLUTELY NO WARRANTY\n"))
938 ((key describe-copying)
939 ": conditions to give out copies of SXEmacs\n")
940 ((key describe-distribution)
941 ": how to get the latest version\n")
942 ((face (blue bold underline) "\nOur Mission is:\n\n"))
944 - To provide the Open Source community with a text editing and
945 development environment that is based on XEmacs and is 2nd to
946 none in regards to stability, features, and innovation.
948 - To foster a user and developer friendly project environment.
950 - And, above all, to have fun doing it.\n"
953 Copyright (C) 2004 - 2009 Steve Youngs\n"))
954 ; Copyright (C) 1985-2001 Free Software Foundation, Inc.
955 ; Copyright (C) 1990-1994 Lucid, Inc.
956 ; Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
957 ; Copyright (C) 1994-1996 Board of Trustees, University of Illinois
958 ; Copyright (C) 1995-2001 Ben Wing\n"))
960 ((face (blue bold underline) "\nInformation, on-line help:\n\n")
961 "SXEmacs comes with plenty of documentation...\n\n"
962 ,@(if emacs-beta-version
963 `((key describe-beta)
964 ": " (face (red bold)
965 "This is an Experimental version of SXEmacs.\n"))
967 ((key sxemacs-local-faq)
968 ": read the SXEmacs FAQ (a " (face underline "capital") " F!)\n")
969 ((key help-with-tutorial)
970 ": read the SXEmacs tutorial (also available through the "
971 (face bold "Help") " menu)\n")
973 ": get help on using SXEmacs (also available through the "
974 (face bold "Help") " menu)\n")
975 ((key info) ": read the on-line documentation\n\n")
976 ((key about-sxemacs) ": see who's developing SXEmacs\n"))
978 ((face (blue bold underline) "\nUseful stuff:\n\n")
979 "Things that you should learn rather quickly...\n\n"
980 ((key find-file) ": visit a file\n")
981 ((key save-buffer) ": save changes\n")
982 ((key advertised-undo) ": undo changes\n")
983 ((key save-buffers-kill-emacs) ": exit SXEmacs\n"))
986 ;; I really hate global variables, oh well.
987 ;(defvar xemacs-startup-logo-function nil
988 ; "If non-nil, function called to provide the startup logo.
989 ;This function should return an initialized glyph if it is used.")
991 ;; This will hopefully go away when gettext is functional.
992 (defconst splash-frame-static-body
993 `(,(emacs-version) "\n\n"
994 (face italic "`C-' means the control key,`M-' means the meta key\n\n")))
997 (defun circulate-splash-frame-elements (client-data)
998 (with-current-buffer (aref client-data 2)
999 (let ((buffer-read-only nil)
1000 (elements (aref client-data 3))
1001 (indice (aref client-data 0)))
1002 (goto-char (aref client-data 1))
1003 (delete-region (point) (point-max))
1004 (splash-frame-present (aref elements indice))
1005 (goto-char (point-min))
1006 (set-buffer-modified-p nil)
1008 (if (= indice (1- (length elements)))
1013 ;; #### This function now returns the (possibly nil) timeout circulating the
1014 ;; splash-frame elements
1015 (defun display-splash-frame ()
1016 (let ((logo sxemacs-logo)
1017 (buffer-read-only nil)
1018 (cramped-p (eq 'tty (console-type))))
1019 (unless cramped-p (insert "\n"))
1020 (indent-to (startup-center-spaces logo))
1021 (set-extent-begin-glyph (make-extent (point) (point)) logo)
1022 ;;(splash-frame-present-hack (make-extent p (point)) 'about-sxemacs))
1024 (splash-frame-present splash-frame-static-body)
1025 (goto-char (point-max))
1026 (let* ((after-change-functions nil) ; no font-lock, thank you
1027 (elements (splash-frame-body))
1028 (client-data `[ 1 ,(point) ,(current-buffer) ,elements ])
1030 (if (listp elements) ;; A single element to display
1031 (splash-frame-present (splash-frame-body))
1032 ;; several elements to rotate
1033 (splash-frame-present (aref elements 0))
1034 (setq tmout (add-timeout splash-frame-timeout
1035 'circulate-splash-frame-elements
1036 client-data splash-frame-timeout)))
1037 (set-buffer-modified-p nil)
1040 ;; (let ((present-file
1042 ;; (splash-frame-present
1044 ;; (list 'find-file-other-window
1045 ;; (expand-file-name f data-directory))
1047 ;; (insert "For customization examples, see the files ")
1048 ;; (funcall present-file "sample.emacs")
1050 ;; (funcall present-file "sample.Xdefaults")
1051 ;; (insert (format "\nin the directory %s." data-directory)))
1053 (defun startup-set-invocation-environment ()
1054 ;; XEmacs -- Steven Baur says invocation directory is nil if you
1055 ;; try to use XEmacs as a login shell.
1056 (or invocation-directory (setq invocation-directory default-directory))
1057 (setq invocation-directory
1058 ;; don't let /tmp_mnt/... get into the load-path or exec-path.
1059 (abbreviate-file-name invocation-directory)))
1061 (defvar Info-directory-list)
1063 (defun startup-setup-paths (roots user-init-directory
1065 inhibit-early-packages debug-paths)
1066 "Setup all the various paths.
1067 ROOTS is a list of plausible roots of the SXEmacs directory hierarchy.
1068 If INHIBIT-PACKAGES is non-NIL, don't do packages.
1069 If DEBUG-PATHS is non-NIL, print paths as they are detected.
1070 It's idempotent, so call this as often as you like!"
1072 (apply #'(lambda (early late last)
1073 (setq early-packages (and (not inhibit-early-packages)
1075 (setq late-packages late)
1076 (setq last-packages last))
1077 (packages-find-packages
1079 (packages-compute-package-locations user-init-directory)))
1081 (setq early-package-load-path
1082 (packages-find-package-load-path early-packages)
1083 late-package-load-path
1084 (packages-find-package-load-path late-packages)
1085 last-package-load-path
1086 (packages-find-package-load-path last-packages))
1090 (princ (format "configure-package-path:\n%S\n" configure-package-path)
1091 'external-debugging-output)
1092 (princ (format "early-packages and early-package-load-path:\n%S\n%S\n"
1093 early-packages early-package-load-path)
1094 'external-debugging-output)
1095 (princ (format "late-packages and late-package-load-path:\n%S\n%S\n"
1096 late-packages late-package-load-path)
1097 'external-debugging-output)
1098 (princ (format "last-packages and last-package-load-path:\n%S\n%S\n"
1099 last-packages last-package-load-path)
1100 'external-debugging-output)))
1102 (setq lisp-directory (paths-find-lisp-directory roots))
1105 (princ (format "lisp-directory:\n%S\n" lisp-directory)
1106 'external-debugging-output))
1108 (if (featurep 'mule)
1110 (setq mule-lisp-directory
1111 (paths-find-mule-lisp-directory roots
1114 (princ (format "mule-lisp-directory:\n%S\n"
1115 mule-lisp-directory)
1116 'external-debugging-output)))
1117 (setq mule-lisp-directory '()))
1119 (setq ffi-lisp-directory
1120 (when (fboundp #'ffi-defun)
1121 (paths-find-ffi-lisp-directory roots
1125 (setq module-directory (paths-find-module-directory roots))
1127 (princ (format "module-directory:\n%S\n" module-directory)
1128 'external-debugging-output))
1129 (setq site-module-directory (and (null inhibit-site-modules)
1130 (paths-find-site-module-directory roots)))
1131 (if (and debug-paths (null inhibit-site-modules))
1132 (princ (format "site-module-directory:\n%S\n" site-module-directory)
1133 'external-debugging-output))
1135 (setq load-path (paths-construct-load-path roots
1136 early-package-load-path
1137 late-package-load-path
1138 last-package-load-path
1142 ffi-lisp-directory))
1144 (setq Info-directory-list
1145 (paths-construct-info-path roots
1146 early-packages late-packages last-packages))
1150 (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1151 'external-debugging-output))
1153 (setq exec-directory (paths-find-exec-directory roots))
1156 (princ (format "exec-directory:\n%s\n" exec-directory)
1157 'external-debugging-output))
1160 (paths-construct-exec-path roots exec-directory
1161 early-packages late-packages last-packages))
1164 (princ (format "exec-path:\n%S\n" exec-path)
1165 'external-debugging-output))
1167 (setq doc-directory (paths-find-doc-directory roots))
1170 (princ (format "doc-directory:\n%S\n" doc-directory)
1171 'external-debugging-output))
1173 (setq data-directory (paths-find-data-directory roots))
1176 (princ (format "data-directory:\n%S\n" data-directory)
1177 'external-debugging-output))
1179 (setq data-directory-list
1180 (paths-construct-data-directory-list data-directory
1185 (princ (format "data-directory-list:\n%S\n" data-directory-list)
1186 'external-debugging-output)))
1188 (defun startup-find-roots-warning ()
1190 (set-buffer (get-buffer-create " *warning-tmp*"))
1192 (buffer-disable-undo (current-buffer))
1194 (insert "Couldn't find an obvious default for the root of the\n"
1195 "SXEmacs hierarchy.")
1197 (princ "\nWARNING:\n" 'external-debugging-output)
1198 (princ (buffer-string) 'external-debugging-output)))
1200 (defun startup-setup-paths-warning ()
1201 (let ((warnings '()))
1203 ((null (and lisp-directory exec-directory data-directory doc-directory
1206 (set-buffer (get-buffer-create " *warning-tmp*"))
1208 (buffer-disable-undo (current-buffer))
1209 (if (null lisp-directory) (push "lisp-directory" warnings))
1210 (if (and (featurep 'mule)
1211 (null mule-lisp-directory))
1212 (push "mule-lisp-directory" warnings))
1213 (if (null exec-directory) (push "exec-directory" warnings))
1214 (if (null data-directory) (push "data-directory" warnings))
1215 (if (null doc-directory) (push "doc-directory" warnings))
1216 (if (null load-path) (push "load-path" warnings))
1218 (insert "Couldn't find obvious defaults for:\n")
1220 (insert (car warnings) "\n")
1221 (setq warnings (cdr warnings)))
1222 (insert "Perhaps some directories don't exist, "
1223 "or the SXEmacs executable,\n"
1224 (concat invocation-directory invocation-name)
1225 "\nis in a strange place?")
1227 (princ "\nWARNING:\n" 'external-debugging-output)
1228 (princ (buffer-string) 'external-debugging-output)
1233 (defun startup-load-autoloads ()
1234 "Load autoloads from known locations."
1236 (when (and (not inhibit-autoloads)
1237 (or lisp-directory module-directory))
1238 ;; ordinary auto-autoloads in lisp/
1239 (let ((aalfile (file-name-sans-extension autoload-file-name)))
1242 (load (expand-file-name aalfile lisp-directory) nil t)
1245 ;; just load them all
1249 (load (expand-file-name (concat "lisp/" aalfile) root) nil t)
1253 (when (featurep 'mule)
1254 (load (expand-file-name aalfile
1255 (expand-file-name "mule" lisp-directory))
1257 (when (featurep 'modules)
1258 (load (expand-file-name aalfile module-directory) t t))
1260 (when (fboundp #'ffi-defun)
1261 (load (expand-file-name aalfile
1262 (expand-file-name "ffi" lisp-directory))
1265 (unless inhibit-autoloads
1266 (unless inhibit-early-packages
1267 (packages-load-package-auto-autoloads early-package-load-path))
1268 (if (and (not inhibit-early-packages) (not warn-early-package-shadows))
1269 (let ((early-path (mapcar 'file-basename early-package-load-path))
1271 (mapc (lambda (path)
1272 (unless (member (file-basename path) early-path)
1273 (setq late-load-path (append late-load-path (list path)))))
1274 late-package-load-path)
1275 (packages-load-package-auto-autoloads late-load-path))
1276 (packages-load-package-auto-autoloads late-package-load-path))
1277 (packages-load-package-auto-autoloads last-package-load-path)))
1279 ;;; startup.el ends here