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 (defvar lisp-initd-dir
115 (file-name-as-directory
116 (paths-construct-path (list user-init-directory "init.d")))
117 "The default directory for the init files.")
119 ;; #### called `site-run-file' in FSFmacs
121 (defvar site-start-file "site-start"
122 "File containing site-wide run-time initializations.
123 This file is loaded at run-time before `~/.sxemacs/init.el'. It
124 contains inits that need to be in place for the entire site, but
125 which, due to their higher incidence of change, don't make sense to
126 load into SXEmacs' dumped image. Thus, the run-time load order is:
128 1. file described in this variable, if non-nil;
129 2. `~/.sxemacs/init.el';
130 3. `/path/to/sxemacs/lisp/default.el'.
132 Don't use the `site-start.el' file for things some users may not like.
133 Put them in `default.el' instead, so that users can more easily
134 override them. Users can prevent loading `default.el' with the `-q'
135 option or by setting `inhibit-default-init' in their own init files,
136 but inhibiting `site-start.el' requires `--no-site-file', which
137 is less convenient.")
139 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
140 ;; "Regexp that specifies when to enable the ISO 8859-1 character set.
141 ;;We do that if this regexp matches the locale name
142 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
144 (defcustom mail-host-address nil
145 "*Name of this machine, for purposes of naming users."
149 (defcustom user-mail-address nil
150 "*Full mailing address of this user.
151 This is initialized based on `mail-host-address',
152 after your init file is read, in case it sets `mail-host-address'."
156 (defvar init-file-debug nil)
158 (defvar init-file-had-error nil)
160 (defvar init-file-loaded nil
161 "True after the user's init file has been loaded (or suppressed with -q).
162 This will be true when `after-init-hook' is run and at all times
163 after, and will not be true at any time before.")
165 (defvar initial-frame-unmapped-p nil)
169 (defvar command-switch-alist
170 '(("-help" . command-line-do-help)
171 ("-version". command-line-do-version)
172 ("-V" . command-line-do-version)
173 ("-funcall". command-line-do-funcall)
174 ("-f" . command-line-do-funcall)
175 ("-e" . command-line-do-funcall-1)
176 ("-eval" . command-line-do-eval)
177 ("-load" . command-line-do-load)
178 ("-l" . command-line-do-load)
179 ("-insert" . command-line-do-insert)
180 ("-i" . command-line-do-insert)
181 ("-kill" . command-line-do-kill)
182 ;; Options like +35 are handled specially.
183 ;; Window-system, site, or package-specific code might add to this.
184 ;; X11 handles its options by letting Xt remove args from this list.
186 "Alist of command-line switches.
187 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
188 HANDLER-FUNCTION receives switch name as sole arg;
189 remaining command-line args are in the variable `command-line-args-left'.")
192 ;;; Note: these doc strings are semi-magical.
194 (defun command-line-do-help (arg)
195 "Print the SXEmacs usage message and exit."
196 (let ((standard-output 'external-debugging-output))
197 (princ (concat "\n" (emacs-version) "\n\n"))
200 (concat "When creating a window on an X display, "
202 " accepts all standard X Toolkit
203 command line options plus the following:
204 -iconname <title> Use title as the icon name.
205 -mc <color> Use color as the mouse color.
206 -cr <color> Use color as the text-cursor foregound color.
207 -private Install a private colormap.
211 (princ " following options are accepted:
212 -sd Show dump ID. Ignored when configured without --pdump.
213 -nd Don't load the dump file. Roughly like old temacs.
214 Ignored when configured without --pdump.
215 -t <device> Use TTY <device> instead of the terminal for input
216 and output. This implies the -nw option.
217 -nw Inhibit the use of any window-system-specific
218 display code: use the current tty.
219 -batch Execute noninteractively (messages go to stderr).
220 -debug-init Enter the debugger if an error in the init file occurs.
221 -unmapped Do not map the initial frame.
222 -no-site-file Do not load the site-specific init file (site-start.el).
223 -no-init-file Do not load the user-specific init file.
224 -no-early-packages Do not process early packages.
225 -no-autoloads Do not load global symbol files (auto-autoloads) at
226 startup. Also implies `-vanilla'.
227 -vanilla Equivalent to -q -no-site-file -no-early-packages.
228 -q Same as -no-init-file.
229 -user-init-file <file> Use <file> as init file.
230 -user-init-directory <directory> Use <directory> as init directory.
231 -user <user> Load user's init file instead of your own.
232 -u <user> Same as -user.\n")
233 (let ((l command-switch-alist)
234 (insert (lambda (&rest x)
239 (incf len (length (car x)))
242 (terpri) (setq len 0))
247 (let ((name (car (car l)))
251 ((and (symbolp fn) (get fn 'undocumented)) nil)
253 (setq doc (documentation fn))
254 (if (member doc '(nil "")) (setq doc "(undocumented)"))
255 (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
256 ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
257 (setq arg (substring doc (match-beginning 1) (match-end 1))
258 doc (substring doc 0 (match-beginning 0))))
259 ((string-match "\n+\\'" doc)
260 (setq doc (substring doc 0 (match-beginning 0)))))
261 (if (and (setq cons (rassq fn command-switch-alist))
262 (not (eq cons (car l))))
263 (setq doc (format "Same as %s." (car cons))))
265 (funcall insert name " " arg)
266 (funcall insert name))
270 (princ (concat "+N <file> Start displaying <file> at line N.
272 Anything else is considered a file name, and is placed into a buffer for
275 " (emacs-name) " has an online tutorial and manuals. Type ^Ht (Control-h t) after
276 starting SXEmacs to run the tutorial. Type ^Hi to enter the manual browser.
277 Type ^H^H^H (Control-h Control-h Control-h) to get more help options.\n")
281 (defun command-line-do-funcall (arg)
282 "Invoke the named lisp function with no arguments.
284 (funcall (intern (pop command-line-args-left))))
285 (fset 'command-line-do-funcall-1 'command-line-do-funcall)
286 (put 'command-line-do-funcall-1 'undocumented t)
288 (defun command-line-do-eval (arg)
289 "Evaluate the lisp form. Quote it carefully.
291 (eval (read (pop command-line-args-left))))
293 (defun command-line-do-load (arg)
294 "Load the named file of Lisp code into SXEmacs.
296 (let ((file (pop command-line-args-left)))
297 ;; Take file from default dir if it exists there;
298 ;; otherwise let `load' search for it.
299 (if (file-exists-p (expand-file-name file))
300 (setq file (expand-file-name file)))
303 (defun command-line-do-insert (arg)
304 "Insert file into the current buffer.
306 (insert-file-contents (pop command-line-args-left)))
308 (defun command-line-do-kill (arg)
312 (defun command-line-do-version (arg)
313 "Print version info and exit."
314 (princ (concat (emacs-version) "\n"))
318 ;;; Processing the command line and loading various init files
320 (defun early-error-handler (&rest debugger-args)
321 "You should probably not be using this."
322 ;; Used as the debugger during SXEmacs initialization; if an error occurs,
323 ;; print some diagnostics, and kill SXEmacs.
325 ;; output the contents of the warning buffer, since it won't be seen
327 ;; #### kludge! The call to Feval forces the pending warnings to
328 ;; get output. There definitely needs to be a better way.
329 (let ((buffer (eval (get-buffer-create "*Warnings*"))))
330 (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
331 'external-debugging-output))
333 (let ((string "Initialization error")
334 (error (nth 1 debugger-args))
336 (stream 'external-debugging-output))
338 (princ string stream)
339 (princ (concat "\n" string ": ") stream)
341 (display-error error stream)
342 (error (princ "<<< error printing error message >>>" stream)))
344 (if (memq (car-safe error) '(void-function void-variable))
346 This probably means that SXEmacs is picking up an old version of
347 the lisp library, or that some .elc files are not up-to-date.\n"
349 (when (not suppress-early-error-handler-backtrace)
350 (let ((print-length 1000)
352 (print-escape-newlines t)
353 (print-readably nil))
354 (when (getenv "EMACSLOADPATH")
355 (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
357 (princ (format "\nexec-directory is %S" exec-directory) stream)
358 (princ (format "\ndata-directory is %S" data-directory) stream)
359 (princ (format "\ndata-directory-list is %S" data-directory-list) stream)
360 (princ (format "\ndoc-directory is %S" doc-directory) stream)
361 (princ (format "\nload-path is %S" load-path) stream)
362 (princ "\n\n" stream)))
363 (when (not suppress-early-error-handler-backtrace)
364 (backtrace stream t)))
367 (defun normal-top-level ()
368 (if command-line-processed
369 (message "Back to top level.")
370 (setq command-line-processed t)
371 ;; Do this first for maximum likelihood of catching errors. The main
372 ;; purpose of this is so that debug-on-error can be set to catch errors
373 ;; during normal noninteractive running.
374 (when (getenv "SXEMACSDEBUG")
375 (eval (read (getenv "SXEMACSDEBUG"))))
376 ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
377 (let ((value (user-home-directory)))
379 (< (length value) (length default-directory))
380 (equal (file-attributes default-directory)
381 (file-attributes value)))
382 (setq default-directory (file-name-as-directory value))))
383 (setq default-directory (abbreviate-file-name default-directory))
384 (initialize-xemacs-paths)
386 (startup-set-invocation-environment)
388 (let ((debug-paths (or debug-paths
389 (and (getenv "EMACSDEBUGPATHS")
392 (setq emacs-roots (paths-find-emacs-roots invocation-directory
396 (princ (format "invocation: p:%S n:%S\n"
397 invocation-directory invocation-name)
398 'external-debugging-output)
399 (princ (format "emacs-roots:\n%S\n" emacs-roots)
400 'external-debugging-output))
402 (if (null emacs-roots)
403 (startup-find-roots-warning))
404 (startup-setup-paths emacs-roots
406 inhibit-early-packages
408 (startup-setup-paths-warning))
410 ;; we set up a separate function, so that a user can later decide
411 ;; to load the autoloads
412 (startup-load-autoloads)
417 ;; catch non-error signals, especially quit
418 (t (setq error-data data)))
419 ;; Do this again, in case the init file defined more abbreviations.
420 (setq default-directory (abbreviate-file-name default-directory))
421 ;; Specify the file for recording all the auto save files of
422 ;; this session. This is used by recover-session.
423 (if auto-save-list-file-prefix
424 (setq auto-save-list-file-name
427 auto-save-list-file-prefix
430 (run-hooks 'emacs-startup-hook)
432 (run-hooks 'term-setup-hook))
433 (setq term-setup-hook nil)
434 ;; ;; Modify the initial frame based on what the init file puts into
435 ;; ;; ...-frame-alist.
436 (frame-notice-user-settings)
437 ;; ;;####FSFmacs junk
438 ;; ;; Now we know the user's default font, so add it to the menu.
439 ;; (if (fboundp 'font-menu-add-default)
440 ;; (font-menu-add-default))
441 (when window-setup-hook
442 (run-hooks 'window-setup-hook))
443 (setq window-setup-hook nil)
445 ;; re-signal, and don't allow continuation as that will probably
446 ;; wipe out the user's .emacs if she hasn't migrated yet!
447 ;; Not applicable to SXEmacs --SY.
448 (signal-error (car error-data) (cdr error-data))))
450 ;; FSF calls precompute-menubar-bindings. We don't mix menubars
454 (defun command-line-early (args)
455 ;; This processes those switches which need to be processed before
456 ;; starting up the window system.
458 (setq command-line-default-directory default-directory)
460 ;; See if we should import version-control from the environment variable.
461 (let ((vc (getenv "VERSION_CONTROL")))
462 (cond ((eq vc nil)) ;don't do anything if not set
463 ((or (string= vc "t")
464 (string= vc "numbered"))
465 (setq version-control t))
466 ((or (string= vc "nil")
467 (string= vc "existing"))
468 (setq version-control nil))
469 ((or (string= vc "never")
470 (string= vc "simple"))
471 (setq version-control 'never))))
473 (setq load-user-init-file-p (not (noninteractive)))
475 ;; Allow (at least) these arguments anywhere in the command line
479 (setq arg (pop args))
481 ((or (string= arg "-q")
482 (string= arg "-no-init-file"))
483 (setq load-user-init-file-p nil))
484 ((string= arg "-no-site-file")
485 (setq site-start-file nil))
486 ((or (string= arg "-no-early-packages")
487 (string= arg "--no-early-packages"))
488 (setq inhibit-early-packages t))
489 ((or (string= arg "-warn-early-package-shadows")
490 (string= arg "--warn-early-package-shadows"))
491 (setq warn-early-package-shadows t))
492 ((or (string= arg "-vanilla")
493 (string= arg "--vanilla")
494 ;; Some work on this one already done in emacs.c.
495 (string= arg "-no-autoloads")
496 (string= arg "--no-autoloads"))
497 (setq load-user-init-file-p nil
498 site-start-file nil))
499 ((string= arg "-user-init-file")
500 (setq user-init-file (pop args)))
501 ((string= arg "-user-init-directory")
502 (setq user-init-directory (file-name-as-directory (pop args))))
503 ((or (string= arg "-u")
504 (string= arg "-user"))
505 (let* ((user (pop args))
506 (home-user (concat "~" user)))
507 (setq user-init-directory (file-name-as-directory
508 (paths-construct-path
509 (list home-user user-init-directory-base))))
511 (find-user-init-file user-init-directory))
513 (make-custom-file-name user-init-file))))
514 ((string= arg "-debug-init")
515 (setq init-file-debug t))
516 ((string= arg "-unmapped")
517 (setq initial-frame-unmapped-p t))
518 ((or (string= arg "-debug-paths")
519 (string= arg "--debug-paths"))
521 ((or (string= arg "--") (string= arg "-"))
523 (push (pop args) new-args)))
524 (t (push arg new-args))))
526 ;; obsolete, initialize for backward compatibility
527 (with-obsolete-variable 'init-file-user
528 (setq init-file-user (and load-user-init-file-p "")))
530 (nreverse new-args)))
532 (defconst initial-scratch-message
533 ";; This buffer is for notes you don't want to save, and for Lisp evaluation.
534 ;; If you want to create a file, first visit that file with C-x C-f,
535 ;; then enter the text in that file's own buffer.
537 ;; In \"SXEmacs-speak\", `C-char' and `M-char' are abbreviations that mean
538 ;; `Control+char' and `Meta+char' (hold down the Control or Meta key while
541 ;; For Lisp evaluation, type an expression, move to the end and hit C-j.
545 "Initial message displayed in *scratch* buffer at startup.
546 If this is nil, no message will be displayed.")
548 (defun command-line ()
549 (let ((command-line-args-left (cdr command-line-args)))
551 (let ((debugger 'early-error-handler)
554 ;; Process magic command-line switches like -q and -u. Do this
555 ;; before creating the first frame because some of these switches
556 ;; may affect that. I think it's ok to do this before establishing
557 ;; the X connection, and maybe someday things like -nw can be
558 ;; handled here instead of down in C.
559 (setq command-line-args-left (command-line-early command-line-args-left))
561 ;; Setup the toolbar icon directory
562 (when (featurep 'toolbar)
563 (init-toolbar-location))
565 ;; Run the window system's init function. tty is considered to be
566 ;; a type of window system for this purpose. This creates the
567 ;; initial (non stdio) device.
568 (when (and initial-window-system (not noninteractive))
569 (funcall (intern (concat "init-"
570 (symbol-name initial-window-system)
573 ;; When not in batch mode, this creates the first visible frame,
574 ;; and deletes the stdio device.
577 ;; Reinitialize faces if necessary. This function changes face if
578 ;; it is created during auto-autoloads loading. Otherwise, it
580 (startup-initialize-custom-faces)
583 ;; We have normality, I repeat, we have normality. Anything you still
584 ;; can't cope with is therefore your own problem. (And we don't need
585 ;; to kill SXEmacs for it.)
591 (with-current-buffer (get-buffer "*scratch*")
593 ;; (insert initial-scratch-message)
594 (set-buffer-modified-p nil)
595 (when (eq major-mode 'fundamental-mode)
596 (funcall initial-major-mode))
597 (font-lock-set-defaults))
599 ;; Load library for our terminal type.
600 ;; User init file can set term-file-prefix to nil to prevent this.
601 ;; Note that for any TTY's opened subsequently, the TTY init
602 ;; code will run this.
603 (when (and (eq 'tty (console-type))
604 (not (noninteractive)))
605 (load-terminal-library))
607 ;; Process the remaining args.
610 ;; it was turned on by default so that the warnings don't get displayed
611 ;; until after the splash screen.
612 (setq inhibit-warning-display nil)
613 ;; If -batch, terminate after processing the command options.
614 (when (noninteractive) (kill-emacs t))))
616 (defun load-terminal-library ()
617 "Load the terminal initialization library"
618 (when term-file-prefix
619 (let ((term (getenv "TERM"))
622 (not (load (concat term-file-prefix term) t t)))
623 ;; Strip off last hyphen and what follows, then try again
624 (if (setq colornum (string-match #r"[-+_][0-9]+\'" term))
625 (setq term (substring term 0 colornum))
626 (if (setq colornum (string-match #r"[-+_]\([0-9]+\)[^-_]+\'" term))
627 (setq term (replace-in-string term (match-string 1 term) ""))
628 (if (setq hyphend (string-match "[-+_][^-_]+\\'" term))
629 (setq term (substring term 0 hyphend))
630 (setq term nil))))))))
632 (defun find-user-init-directory-init-file (&optional init-directory)
633 "Determine the user's init file if in the init directory."
634 (let ((init-directory (or init-directory user-init-directory)))
636 (dolist (file user-init-file-base-list)
637 (let ((expanded (expand-file-name file init-directory)))
638 (when (file-readable-p expanded)
639 (throw 'found expanded)))))))
641 (defun find-user-init-file (&optional init-directory)
642 "Determine the user's init file."
643 (find-user-init-directory-init-file init-directory))
645 (defun load-user-init-file ()
646 "This function actually reads the init file."
647 (unless (paths-file-readable-directory-p user-init-directory)
648 (make-directory-path user-init-directory))
649 (if (not user-init-file)
651 (find-user-init-file user-init-directory)))
652 (if (not custom-file)
653 (setq custom-file (make-custom-file-name user-init-file)))
654 ;; #### should test load-user-init-file-p here, not in load-init-file
656 (if (and user-init-file
657 (file-readable-p user-init-file))
658 (load user-init-file t t t))
660 (or (not user-init-file)
661 (not (string= custom-file user-init-file)))
662 (file-readable-p custom-file))
663 (load custom-file t t t))
664 (unless inhibit-default-init
665 (let ((inhibit-startup-message nil))
666 ;; Users are supposed to be told their rights.
667 ;; (Plus how to get help and how to undo.)
668 ;; Don't you dare turn this off for anyone except yourself.
669 (load "default" t t))))
671 ;;; Load user's init file and default ones.
672 (defun load-init-file ()
673 (run-hooks 'before-init-hook)
675 ;; Run the site-start library if it exists. The point of this file is
676 ;; that it is run before .emacs. There is no point in doing this after
677 ;; .emacs; that is useless.
678 (when site-start-file
679 (load site-start-file t t))
681 ;; Sites should not disable this. Only individuals should disable
682 ;; the startup message.
683 (setq inhibit-startup-message nil)
685 (let (debug-on-error-from-init-file
686 debug-on-error-should-be-set
687 (debug-on-error-initial
688 (if (eq init-file-debug t) 'startup init-file-debug)))
689 (let ((debug-on-error debug-on-error-initial))
690 ;; #### I believe this test is incorrect, it leads to custom-file
691 ;; (at least) being undefined
692 (if (and load-user-init-file-p init-file-debug)
694 ;; Do this without a condition-case if the user wants to debug.
695 (load-user-init-file))
696 (condition-case error
698 ;; #### probably incorrect, see comment above
699 (if load-user-init-file-p
700 (load-user-init-file))
701 (setq init-file-had-error nil))
703 (message "Error in init file: %s" (error-message-string error))
704 (display-warning 'initialization
705 (format "An error has occurred while loading %s:
709 To ensure normal operation, you should investigate the cause of the error
710 in your initialization file and remove it. Use the `-debug-init' option
711 to SXEmacs to view a complete error backtrace."
712 user-init-file (error-message-string error))
714 (setq init-file-had-error t))))
715 ;; If we can tell that the init file altered debug-on-error,
716 ;; arrange to preserve the value that it set up.
717 (or (eq debug-on-error debug-on-error-initial)
718 (setq debug-on-error-should-be-set t
719 debug-on-error-from-init-file debug-on-error)))
720 (when debug-on-error-should-be-set
721 (setq debug-on-error debug-on-error-from-init-file)))
723 (setq init-file-loaded t)
725 ;; Do this here in case the init file sets mail-host-address.
726 ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
727 ;; (or user-mail-address
729 (setq user-mail-address (concat (user-login-name) "@"
730 (or mail-host-address
733 (run-hooks 'after-init-hook)
736 (defun load-options-file (filename)
737 "Load the file of saved options (from the Options menu) called FILENAME.
738 Currently this does nothing but call `load', but it might be redefined
739 in the future to support automatically converting older options files to
740 a new format, when variables have changed, etc."
743 (defun command-line-1 ()
745 ((null command-line-args-left)
746 (unless noninteractive
747 ;; If there are no switches to process, run the term-setup-hook
748 ;; before displaying the copyright notice; there may be some need
749 ;; to do it before doing any output. If we're not going to
750 ;; display a copyright notice (because other options are present)
751 ;; then this is run after those options are processed.
752 (run-hooks 'term-setup-hook)
753 ;; Don't let the hook be run twice.
754 (setq term-setup-hook nil)
756 ;; Don't clobber a non-scratch buffer if init file
758 (when (string= (buffer-name) "*scratch*")
759 (unless (or inhibit-startup-message
761 (let (tmout circ-tmout)
763 ;; Guts of with-timeout
765 (setq tmout (add-timeout startup-message-timeout
771 (setq circ-tmout (display-splash-frame))
772 (or nil;; (pos-visible-in-window-p (point-min))
773 (goto-char (point-min)))
775 (setq unread-command-event (next-command-event)))
776 (when tmout (disable-timeout tmout))
777 (when circ-tmout (disable-timeout circ-tmout)))))
778 (with-current-buffer (get-buffer "*scratch*")
779 ;; In case the SXEmacs server has already selected
780 ;; another buffer, erase the one our message is in.
782 (when (stringp initial-scratch-message)
783 (insert initial-scratch-message))
784 (set-buffer-modified-p nil)))))
787 ;; Command-line-options exist
788 (let ((dir command-line-default-directory)
793 (while command-line-args-left
794 (setq arg (pop command-line-args-left))
798 ((setq tem (when (eq (aref arg 0) ?-)
799 (or (assoc arg command-switch-alist)
800 (assoc (substring arg 1)
801 command-switch-alist))))
802 (funcall (cdr tem) arg))
803 ((string-match #r"\`\+[0-9]+\'" arg)
804 (setq line (string-to-int arg)))
805 ;; "- file" means don't treat "file" as a switch
806 ;; ("+0 file" has the same effect; "-" added
807 ;; for unixoidiality).
808 ;; This is worthless; the `unixoid' way is "./file". -jwz
809 ((or (string= arg "-") (string= arg "--"))
810 (setq end-of-options t))
817 (setq arg (expand-file-name arg dir))
821 (noninteractive (find-file arg))
822 (t (find-file-other-window arg)))
825 (setq line nil))))))))
827 (defvar startup-presentation-hack-keymap
828 (let ((map (make-sparse-keymap)))
829 (set-keymap-name map 'startup-presentation-hack-keymap)
830 (define-key map '[button1] 'startup-presentation-hack)
831 (define-key map '[button2] 'startup-presentation-hack)
833 "Putting yesterday in the future tomorrow.")
835 (defun startup-presentation-hack ()
837 (let ((e last-command-event))
838 (and (button-press-event-p e)
839 (setq e (extent-at (event-point e)
841 'startup-presentation-hack))
842 (setq e (extent-property e 'startup-presentation-hack))
844 (apply (car e) (cdr e))
845 (while (keymapp (indirect-function e))
847 (overriding-local-map (indirect-function e)))
848 (setq e (read-key-sequence
849 (let ((p (keymap-prompt map t)))
852 (format "%s %s " map p)
856 (prin1-to-string map))))))
857 (if (and (button-release-event-p (elt e 0))
858 (null (key-binding e)))
859 (setq e map) ; try again
860 (setq e (key-binding e)))))
861 (call-interactively e)))))
863 (defun startup-presentation-hack-help (e)
864 (setq e (extent-property e 'startup-presentation-hack))
866 (format "Evaluate %S" e)
869 (defun splash-frame-present-hack (e v)
870 ;; (set-extent-property e 'mouse-face 'highlight)
871 ;; (set-extent-property e 'keymap
872 ;; startup-presentation-hack-keymap)
873 ;; (set-extent-property e 'startup-presentation-hack v)
874 ;; (set-extent-property e 'help-echo
875 ;; 'startup-presentation-hack-help)
878 (defun splash-frame-present (l)
881 ((eq (car-safe l) 'face)
882 ;; (face name string)
884 (splash-frame-present (elt l 2))
885 (if (fboundp 'set-extent-face)
886 (set-extent-face (make-extent p (point))
888 ((eq (car-safe l) 'key)
891 (k (where-is-internal c nil t)))
892 (insert (if k (key-description k)
893 (format "M-x %s" c)))
894 (if (fboundp 'set-extent-face)
895 (let ((e (make-extent p (point))))
896 (set-extent-face e 'bold)
897 (splash-frame-present-hack e c)))))
898 ((eq (car-safe l) 'funcall)
899 ;; (funcall (fun . args) string)
901 (splash-frame-present (elt l 2))
902 (if (fboundp 'set-extent-face)
903 (splash-frame-present-hack (make-extent p (point))
906 (mapcar 'splash-frame-present l))
908 (backtrace 'external-debugging-output)
911 (defun startup-center-spaces (glyph)
912 ;; Return the number of spaces to insert in order to center
913 ;; the given glyph (may be a string or a pixmap).
914 ;; Assume spaces are as wide as avg-pixwidth.
915 ;; Won't be quite right for proportional fonts, but it's the best we can do.
916 ;; Maybe the new redisplay will export something a glyph-width function.
917 ;;; #### Yes, there is a glyph-width function but it isn't quite what
918 ;;; #### this was expecting. Or is it?
919 ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
920 ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
922 ;; This function is used in about.el too.
923 (let* ((avg-pixwidth (round (/ (frame-pixel-width) (frame-width))))
924 (fill-area-width (* avg-pixwidth (- fill-column left-margin)))
925 (glyph-pixwidth (cond ((stringp glyph)
926 (* avg-pixwidth (length glyph)))
927 ;; #### the pixmap option should be removed
929 ;; (pixmap-width glyph))
933 (error "startup-center-spaces: bad arg")))))
935 (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
937 (defun splash-frame-body ()
938 `[((face (blue bold underline)
939 "\nDistribution, copying license, warranty:\n\n")
940 "Please visit the SXEmacs website at http://www.sxemacs.org !\n\n"
941 ((key describe-no-warranty)
942 ": "(face (red bold) "SXEmacs comes with ABSOLUTELY NO WARRANTY\n"))
943 ((key describe-copying)
944 ": conditions to give out copies of SXEmacs\n")
945 ((key describe-distribution)
946 ": how to get the latest version\n")
947 ((face (blue bold underline) "\nOur Mission is:\n\n"))
949 - To provide the Open Source community with a text editing and
950 development environment that is based on XEmacs and is 2nd to
951 none in regards to stability, features, and innovation.
953 - To foster a user and developer friendly project environment.
955 - And, above all, to have fun doing it.\n"
958 Copyright (C) 2004 - 2009 Steve Youngs\n"))
959 ; Copyright (C) 1985-2001 Free Software Foundation, Inc.
960 ; Copyright (C) 1990-1994 Lucid, Inc.
961 ; Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
962 ; Copyright (C) 1994-1996 Board of Trustees, University of Illinois
963 ; Copyright (C) 1995-2001 Ben Wing\n"))
965 ((face (blue bold underline) "\nInformation, on-line help:\n\n")
966 "SXEmacs comes with plenty of documentation...\n\n"
967 ,@(if emacs-beta-version
968 `((key describe-beta)
969 ": " (face (red bold)
970 "This is an Experimental version of SXEmacs.\n"))
972 ((key sxemacs-local-faq)
973 ": read the SXEmacs FAQ (a " (face underline "capital") " F!)\n")
974 ((key help-with-tutorial)
975 ": read the SXEmacs tutorial (also available through the "
976 (face bold "Help") " menu)\n")
978 ": get help on using SXEmacs (also available through the "
979 (face bold "Help") " menu)\n")
980 ((key info) ": read the on-line documentation\n\n")
981 ((key about-sxemacs) ": see who's developing SXEmacs\n"))
983 ((face (blue bold underline) "\nUseful stuff:\n\n")
984 "Things that you should learn rather quickly...\n\n"
985 ((key find-file) ": visit a file\n")
986 ((key save-buffer) ": save changes\n")
987 ((key advertised-undo) ": undo changes\n")
988 ((key save-buffers-kill-emacs) ": exit SXEmacs\n"))
991 ;; I really hate global variables, oh well.
992 ;(defvar xemacs-startup-logo-function nil
993 ; "If non-nil, function called to provide the startup logo.
994 ;This function should return an initialized glyph if it is used.")
996 ;; This will hopefully go away when gettext is functional.
997 (defconst splash-frame-static-body
998 `(,(emacs-version) "\n\n"
999 (face italic "`C-' means the control key,`M-' means the meta key\n\n")))
1002 (defun circulate-splash-frame-elements (client-data)
1003 (with-current-buffer (aref client-data 2)
1004 (let ((buffer-read-only nil)
1005 (elements (aref client-data 3))
1006 (indice (aref client-data 0)))
1007 (goto-char (aref client-data 1))
1008 (delete-region (point) (point-max))
1009 (splash-frame-present (aref elements indice))
1010 (goto-char (point-min))
1011 (set-buffer-modified-p nil)
1013 (if (= indice (1- (length elements)))
1018 ;; #### This function now returns the (possibly nil) timeout circulating the
1019 ;; splash-frame elements
1020 (defun display-splash-frame ()
1021 (let ((logo sxemacs-logo)
1022 (buffer-read-only nil)
1023 (cramped-p (eq 'tty (console-type))))
1024 (unless cramped-p (insert "\n"))
1025 (indent-to (startup-center-spaces logo))
1026 (set-extent-begin-glyph (make-extent (point) (point)) logo)
1027 ;;(splash-frame-present-hack (make-extent p (point)) 'about-sxemacs))
1029 (splash-frame-present splash-frame-static-body)
1030 (goto-char (point-max))
1031 (let* ((after-change-functions nil) ; no font-lock, thank you
1032 (elements (splash-frame-body))
1033 (client-data `[ 1 ,(point) ,(current-buffer) ,elements ])
1035 (if (listp elements) ;; A single element to display
1036 (splash-frame-present (splash-frame-body))
1037 ;; several elements to rotate
1038 (splash-frame-present (aref elements 0))
1039 (setq tmout (add-timeout splash-frame-timeout
1040 'circulate-splash-frame-elements
1041 client-data splash-frame-timeout)))
1042 (set-buffer-modified-p nil)
1045 ;; (let ((present-file
1047 ;; (splash-frame-present
1049 ;; (list 'find-file-other-window
1050 ;; (expand-file-name f data-directory))
1052 ;; (insert "For customization examples, see the files ")
1053 ;; (funcall present-file "sample.emacs")
1055 ;; (funcall present-file "sample.Xdefaults")
1056 ;; (insert (format "\nin the directory %s." data-directory)))
1058 (defun startup-set-invocation-environment ()
1059 ;; XEmacs -- Steven Baur says invocation directory is nil if you
1060 ;; try to use XEmacs as a login shell.
1061 (or invocation-directory (setq invocation-directory default-directory))
1062 (setq invocation-directory
1063 ;; don't let /tmp_mnt/... get into the load-path or exec-path.
1064 (abbreviate-file-name invocation-directory)))
1066 (defvar Info-directory-list)
1068 (defun startup-setup-paths (roots user-init-directory
1070 inhibit-early-packages debug-paths)
1071 "Setup all the various paths.
1072 ROOTS is a list of plausible roots of the SXEmacs directory hierarchy.
1073 If INHIBIT-PACKAGES is non-NIL, don't do packages.
1074 If DEBUG-PATHS is non-NIL, print paths as they are detected.
1075 It's idempotent, so call this as often as you like!"
1077 (apply #'(lambda (early late last)
1078 (setq early-packages (and (not inhibit-early-packages)
1080 (setq late-packages late)
1081 (setq last-packages last))
1082 (packages-find-packages
1084 (packages-compute-package-locations user-init-directory)))
1086 (setq early-package-load-path
1087 (packages-find-package-load-path early-packages)
1088 late-package-load-path
1089 (packages-find-package-load-path late-packages)
1090 last-package-load-path
1091 (packages-find-package-load-path last-packages))
1095 (princ (format "configure-package-path:\n%S\n" configure-package-path)
1096 'external-debugging-output)
1097 (princ (format "early-packages and early-package-load-path:\n%S\n%S\n"
1098 early-packages early-package-load-path)
1099 'external-debugging-output)
1100 (princ (format "late-packages and late-package-load-path:\n%S\n%S\n"
1101 late-packages late-package-load-path)
1102 'external-debugging-output)
1103 (princ (format "last-packages and last-package-load-path:\n%S\n%S\n"
1104 last-packages last-package-load-path)
1105 'external-debugging-output)))
1107 (setq lisp-directory (paths-find-lisp-directory roots))
1110 (princ (format "lisp-directory:\n%S\n" lisp-directory)
1111 'external-debugging-output))
1113 (if (featurep 'mule)
1115 (setq mule-lisp-directory
1116 (paths-find-mule-lisp-directory roots
1119 (princ (format "mule-lisp-directory:\n%S\n"
1120 mule-lisp-directory)
1121 'external-debugging-output)))
1122 (setq mule-lisp-directory '()))
1124 (setq ffi-lisp-directory
1125 (when (fboundp #'ffi-defun)
1126 (paths-find-ffi-lisp-directory roots
1130 (setq module-directory (paths-find-module-directory roots))
1132 (princ (format "module-directory:\n%S\n" module-directory)
1133 'external-debugging-output))
1134 (setq site-module-directory (and (null inhibit-site-modules)
1135 (paths-find-site-module-directory roots)))
1136 (if (and debug-paths (null inhibit-site-modules))
1137 (princ (format "site-module-directory:\n%S\n" site-module-directory)
1138 'external-debugging-output))
1140 (setq load-path (paths-construct-load-path roots
1141 early-package-load-path
1142 late-package-load-path
1143 last-package-load-path
1147 ffi-lisp-directory))
1149 (setq Info-directory-list
1150 (paths-construct-info-path roots
1151 early-packages late-packages last-packages))
1155 (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1156 'external-debugging-output))
1158 (setq exec-directory (paths-find-exec-directory roots))
1161 (princ (format "exec-directory:\n%s\n" exec-directory)
1162 'external-debugging-output))
1165 (paths-construct-exec-path roots exec-directory
1166 early-packages late-packages last-packages))
1169 (princ (format "exec-path:\n%S\n" exec-path)
1170 'external-debugging-output))
1172 (setq doc-directory (paths-find-doc-directory roots))
1175 (princ (format "doc-directory:\n%S\n" doc-directory)
1176 'external-debugging-output))
1178 (setq data-directory (paths-find-data-directory roots))
1181 (princ (format "data-directory:\n%S\n" data-directory)
1182 'external-debugging-output))
1184 (setq data-directory-list
1185 (paths-construct-data-directory-list data-directory
1190 (princ (format "data-directory-list:\n%S\n" data-directory-list)
1191 'external-debugging-output)))
1193 (defun startup-find-roots-warning ()
1195 (set-buffer (get-buffer-create " *warning-tmp*"))
1197 (buffer-disable-undo (current-buffer))
1199 (insert "Couldn't find an obvious default for the root of the\n"
1200 "SXEmacs hierarchy.")
1202 (princ "\nWARNING:\n" 'external-debugging-output)
1203 (princ (buffer-string) 'external-debugging-output)))
1205 (defun startup-setup-paths-warning ()
1206 (let ((warnings '()))
1208 ((null (and lisp-directory exec-directory data-directory doc-directory
1211 (set-buffer (get-buffer-create " *warning-tmp*"))
1213 (buffer-disable-undo (current-buffer))
1214 (if (null lisp-directory) (push "lisp-directory" warnings))
1215 (if (and (featurep 'mule)
1216 (null mule-lisp-directory))
1217 (push "mule-lisp-directory" warnings))
1218 (if (null exec-directory) (push "exec-directory" warnings))
1219 (if (null data-directory) (push "data-directory" warnings))
1220 (if (null doc-directory) (push "doc-directory" warnings))
1221 (if (null load-path) (push "load-path" warnings))
1223 (insert "Couldn't find obvious defaults for:\n")
1225 (insert (car warnings) "\n")
1226 (setq warnings (cdr warnings)))
1227 (insert "Perhaps some directories don't exist, "
1228 "or the SXEmacs executable,\n"
1229 (concat invocation-directory invocation-name)
1230 "\nis in a strange place?")
1232 (princ "\nWARNING:\n" 'external-debugging-output)
1233 (princ (buffer-string) 'external-debugging-output)
1238 (defun startup-load-autoloads ()
1239 "Load autoloads from known locations."
1241 (when (and (not inhibit-autoloads)
1242 (or lisp-directory module-directory))
1243 ;; ordinary auto-autoloads in lisp/
1244 (let ((aalfile (file-name-sans-extension autoload-file-name)))
1247 (load (expand-file-name aalfile lisp-directory) nil t)
1250 ;; just load them all
1254 (load (expand-file-name (concat "lisp/" aalfile) root) nil t)
1258 (when (featurep 'mule)
1259 (load (expand-file-name aalfile
1260 (expand-file-name "mule" lisp-directory))
1262 (when (featurep 'modules)
1263 (load (expand-file-name aalfile module-directory) t t))
1265 (when (fboundp #'ffi-defun)
1266 (load (expand-file-name aalfile
1267 (expand-file-name "ffi" lisp-directory))
1270 (unless inhibit-autoloads
1271 (unless inhibit-early-packages
1272 (packages-load-package-auto-autoloads early-package-load-path))
1273 (if (and (not inhibit-early-packages) (not warn-early-package-shadows))
1274 (let ((early-path (mapcar 'file-basename early-package-load-path))
1276 (mapc (lambda (path)
1277 (unless (member (file-basename path) early-path)
1278 (setq late-load-path (append late-load-path (list path)))))
1279 late-package-load-path)
1280 (packages-load-package-auto-autoloads late-load-path))
1281 (packages-load-package-auto-autoloads late-package-load-path))
1282 (packages-load-package-auto-autoloads last-package-load-path)))
1284 ;;; startup.el ends here