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 - 2015 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 (defun find-user-init-directory ()
96 "Find the user's init directory.
98 If no init directory currently exists, this will return:
99 \"$XDG_CONFIG_HOME/sxemacs\", which falls back to
100 \"~/.config/sxemacs\" if $XDG_CONFIG_HOME is not set in the user's
103 If the legacy init directory, \"~/.sxemacs\" exists, return that.
105 If both the legacy directory and the XDG-based directory exist, return
106 the XDG-based directory unless $SXE_USE_LEGACY is set in the user's
108 (let* ((legacy (getenv "SXE_USE_LEGACY"))
109 (xdg (getenv "XDG_CONFIG_HOME"))
111 (paths-construct-path
112 (list xdg "sxemacs")))
113 (paths-construct-path
114 (list (user-home-directory) ".config" "sxemacs"))))
115 (legacydir (paths-construct-path
116 (list (user-home-directory) ".sxemacs")))
117 (locations (list xdgdir legacydir)))
119 (file-name-as-directory legacydir)
121 (dolist (dir locations)
122 (and (paths-file-readable-directory-p dir)
123 (throw 'found (file-name-as-directory dir))))
124 (file-name-as-directory xdgdir)))))
126 (defvar user-init-directory ""
127 "Directory where user-installed init files may go.
129 See: `find-user-init-directory'.")
131 (defvar user-init-file-base-list '("init.elc" "init.el")
132 "List of allowed init files in the user's init directory.
133 The first one found takes precedence.")
135 (defvar load-user-init-file-p t
136 "Non-nil if SXEmacs should load the user's init file.")
138 ;; #### called `site-run-file' in FSFmacs
140 (defvar site-start-file "site-start"
141 "File containing site-wide run-time initializations.
142 This file is loaded at run-time before `user-init-file'. It
143 contains inits that need to be in place for the entire site, but
144 which, due to their higher incidence of change, don't make sense to
145 load into SXEmacs' dumped image. Thus, the run-time load order is:
147 1. file described in this variable, if non-nil;
149 3. `/path/to/sxemacs/lisp/default.el'.
151 Don't use the `site-start.el' file for things some users may not like.
152 Put them in `default.el' instead, so that users can more easily
153 override them. Users can prevent loading `default.el' with the `-q'
154 option or by setting `inhibit-default-init' in their own init files,
155 but inhibiting `site-start.el' requires `--no-site-file', which
156 is less convenient.")
158 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
159 ;; "Regexp that specifies when to enable the ISO 8859-1 character set.
160 ;;We do that if this regexp matches the locale name
161 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
163 (defcustom mail-host-address nil
164 "*Name of this machine, for purposes of naming users."
168 (defcustom user-mail-address nil
169 "*Full mailing address of this user.
170 This is initialized based on `mail-host-address',
171 after your init file is read, in case it sets `mail-host-address'."
175 (defvar init-file-debug nil)
177 (defvar init-file-had-error nil)
179 (defvar init-file-loaded nil
180 "True after the user's init file has been loaded (or suppressed with -q).
181 This will be true when `after-init-hook' is run and at all times
182 after, and will not be true at any time before.")
184 (defvar initial-frame-unmapped-p nil)
188 (defvar command-switch-alist
189 '(("-help" . command-line-do-help)
190 ("-version". command-line-do-version)
191 ("-V" . command-line-do-version)
192 ("-funcall". command-line-do-funcall)
193 ("-f" . command-line-do-funcall)
194 ("-e" . command-line-do-funcall-1)
195 ("-eval" . command-line-do-eval)
196 ("-load" . command-line-do-load)
197 ("-l" . command-line-do-load)
198 ("-insert" . command-line-do-insert)
199 ("-i" . command-line-do-insert)
200 ("-kill" . command-line-do-kill)
201 ;; Options like +35 are handled specially.
202 ;; Window-system, site, or package-specific code might add to this.
203 ;; X11 handles its options by letting Xt remove args from this list.
205 "Alist of command-line switches.
206 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
207 HANDLER-FUNCTION receives switch name as sole arg;
208 remaining command-line args are in the variable `command-line-args-left'.")
211 ;;; Note: these doc strings are semi-magical.
213 (defun command-line-do-help (arg)
214 "Print the SXEmacs usage message and exit."
215 (let ((standard-output 'external-debugging-output))
216 (princ (concat "\n" (emacs-version) "\n\n"))
219 (concat "When creating a window on an X display, "
221 " accepts all standard X Toolkit
222 command line options plus the following:
223 -iconname <title> Use title as the icon name.
224 -mc <color> Use color as the mouse color.
225 -cr <color> Use color as the text-cursor foregound color.
226 -private Install a private colormap.
230 (princ " following options are accepted:
231 -sd Show dump ID. Ignored when configured without --pdump.
232 -nd Don't load the dump file. Roughly like old temacs.
233 Ignored when configured without --pdump.
234 -t <device> Use TTY <device> instead of the terminal for input
235 and output. This implies the -nw option.
236 -nw Inhibit the use of any window-system-specific
237 display code: use the current tty.
238 -batch Execute noninteractively (messages go to stderr).
239 -debug-init Enter the debugger if an error in the init file occurs.
240 -unmapped Do not map the initial frame.
241 -no-site-file Do not load the site-specific init file (site-start.el).
242 -no-init-file Do not load the user-specific init file.
243 -no-early-packages Do not process early packages.
244 -no-autoloads Do not load global symbol files (auto-autoloads) at
245 startup. Also implies `-vanilla'.
246 -vanilla Equivalent to -q -no-site-file -no-early-packages.
247 -q Same as -no-init-file.
248 -user-init-file <file> Use <file> as init file.
249 -user-init-directory <directory> Use <directory> as init directory.
250 -user <user> Load user's init file instead of your own.
251 Probably not a wise thing to do.
252 -u <user> Same as -user.\n")
253 (let ((l command-switch-alist)
254 (insert (lambda (&rest x)
259 (incf len (length (car x)))
262 (terpri) (setq len 0))
267 (let ((name (car (car l)))
271 ((and (symbolp fn) (get fn 'undocumented)) nil)
273 (setq doc (documentation fn))
274 (if (member doc '(nil "")) (setq doc "(undocumented)"))
275 (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
276 ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
277 (setq arg (substring doc (match-beginning 1) (match-end 1))
278 doc (substring doc 0 (match-beginning 0))))
279 ((string-match "\n+\\'" doc)
280 (setq doc (substring doc 0 (match-beginning 0)))))
281 (if (and (setq cons (rassq fn command-switch-alist))
282 (not (eq cons (car l))))
283 (setq doc (format "Same as %s." (car cons))))
285 (funcall insert name " " arg)
286 (funcall insert name))
290 (princ (concat "+N <file> Start displaying <file> at line N.
292 Anything else is considered a file name, and is placed into a buffer for
295 " (emacs-name) " has an online tutorial and manuals. Type ^Ht (Control-h t) after
296 starting SXEmacs to run the tutorial. Type ^Hi to enter the manual browser.
297 Type ^H^H^H (Control-h Control-h Control-h) to get more help options.\n")
301 (defun command-line-do-funcall (arg)
302 "Invoke the named lisp function with no arguments.
304 (funcall (intern (pop command-line-args-left))))
305 (fset 'command-line-do-funcall-1 'command-line-do-funcall)
306 (put 'command-line-do-funcall-1 'undocumented t)
308 (defun command-line-do-eval (arg)
309 "Evaluate the lisp form. Quote it carefully.
311 (eval (read (pop command-line-args-left))))
313 (defun command-line-do-load (arg)
314 "Load the named file of Lisp code into SXEmacs.
316 (let ((file (pop command-line-args-left)))
317 ;; Take file from default dir if it exists there;
318 ;; otherwise let `load' search for it.
319 (if (file-exists-p (expand-file-name file))
320 (setq file (expand-file-name file)))
323 (defun command-line-do-insert (arg)
324 "Insert file into the current buffer.
326 (insert-file-contents (pop command-line-args-left)))
328 (defun command-line-do-kill (arg)
332 (defun command-line-do-version (arg)
333 "Print version info and exit."
334 (princ (concat (emacs-version) "\n"))
338 ;;; Processing the command line and loading various init files
340 (defun early-error-handler (&rest debugger-args)
341 "You should probably not be using this."
342 ;; Used as the debugger during SXEmacs initialization; if an error occurs,
343 ;; print some diagnostics, and kill SXEmacs.
345 ;; output the contents of the warning buffer, since it won't be seen
347 ;; #### kludge! The call to Feval forces the pending warnings to
348 ;; get output. There definitely needs to be a better way.
349 (let ((buffer (eval (get-buffer-create "*Warnings*"))))
350 (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
351 'external-debugging-output))
353 (let ((string "Initialization error")
354 (error (nth 1 debugger-args))
356 (stream 'external-debugging-output))
358 (princ string stream)
359 (princ (concat "\n" string ": ") stream)
361 (display-error error stream)
362 (error (princ "<<< error printing error message >>>" stream)))
364 (if (memq (car-safe error) '(void-function void-variable))
366 This probably means that SXEmacs is picking up an old version of
367 the lisp library, or that some .elc files are not up-to-date.\n"
369 (when (not suppress-early-error-handler-backtrace)
370 (let ((print-length 1000)
372 (print-escape-newlines t)
373 (print-readably nil))
374 (when (getenv "EMACSLOADPATH")
375 (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
377 (princ (format "\nexec-directory is %S" exec-directory) stream)
378 (princ (format "\ndata-directory is %S" data-directory) stream)
379 (princ (format "\ndata-directory-list is %S" data-directory-list) stream)
380 (princ (format "\ndoc-directory is %S" doc-directory) stream)
381 (princ (format "\nload-path is %S" load-path) stream)
382 (princ "\n\n" stream)))
383 (when (not suppress-early-error-handler-backtrace)
384 (backtrace stream t)))
387 (defun normal-top-level ()
388 (if command-line-processed
389 (message "Back to top level.")
390 (setq command-line-processed t)
391 ;; Do this first for maximum likelihood of catching errors. The main
392 ;; purpose of this is so that debug-on-error can be set to catch errors
393 ;; during normal noninteractive running.
394 (when (getenv "SXEMACSDEBUG")
395 (eval (read (getenv "SXEMACSDEBUG"))))
396 ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
397 (let ((value (user-home-directory)))
399 (< (length value) (length default-directory))
400 (equal (file-attributes default-directory)
401 (file-attributes value)))
402 (setq default-directory (file-name-as-directory value))))
403 (setq default-directory (abbreviate-file-name default-directory))
404 (initialize-xemacs-paths)
406 (startup-set-invocation-environment)
408 (let ((debug-paths (or debug-paths
409 (and (getenv "EMACSDEBUGPATHS")
412 (setq emacs-roots (paths-find-emacs-roots invocation-directory
416 (princ (format "invocation: p:%S n:%S\n"
417 invocation-directory invocation-name)
418 'external-debugging-output)
419 (princ (format "emacs-roots:\n%S\n" emacs-roots)
420 'external-debugging-output))
422 (if (null emacs-roots)
423 (startup-find-roots-warning))
424 (startup-setup-paths emacs-roots
426 inhibit-early-packages
428 (startup-setup-paths-warning))
430 ;; we set up a separate function, so that a user can later decide
431 ;; to load the autoloads
432 (startup-load-autoloads)
437 ;; catch non-error signals, especially quit
438 (t (setq error-data data)))
439 ;; Do this again, in case the init file defined more abbreviations.
440 (setq default-directory (abbreviate-file-name default-directory))
441 ;; Specify the file for recording all the auto save files of
442 ;; this session. This is used by recover-session.
443 (if auto-save-list-file-prefix
444 (setq auto-save-list-file-name
447 auto-save-list-file-prefix
450 (run-hooks 'emacs-startup-hook)
452 (run-hooks 'term-setup-hook))
453 (setq term-setup-hook nil)
454 ;; ;; Modify the initial frame based on what the init file puts into
455 ;; ;; ...-frame-alist.
456 (frame-notice-user-settings)
457 ;; ;;####FSFmacs junk
458 ;; ;; Now we know the user's default font, so add it to the menu.
459 ;; (if (fboundp 'font-menu-add-default)
460 ;; (font-menu-add-default))
461 (when window-setup-hook
462 (run-hooks 'window-setup-hook))
463 (setq window-setup-hook nil)
465 ;; re-signal, and don't allow continuation as that will probably
466 ;; wipe out the user's .emacs if she hasn't migrated yet!
467 ;; Not applicable to SXEmacs --SY.
468 (signal-error (car error-data) (cdr error-data))))
470 ;; FSF calls precompute-menubar-bindings. We don't mix menubars
474 (defun command-line-early (args)
475 ;; This processes those switches which need to be processed before
476 ;; starting up the window system.
478 (setq command-line-default-directory default-directory)
480 ;; See if we should import version-control from the environment variable.
481 (let ((vc (getenv "VERSION_CONTROL")))
482 (cond ((eq vc nil)) ;don't do anything if not set
483 ((or (string= vc "t")
484 (string= vc "numbered"))
485 (setq version-control t))
486 ((or (string= vc "nil")
487 (string= vc "existing"))
488 (setq version-control nil))
489 ((or (string= vc "never")
490 (string= vc "simple"))
491 (setq version-control 'never))))
493 (setq load-user-init-file-p (not (noninteractive)))
495 ;; Allow (at least) these arguments anywhere in the command line
499 (setq arg (pop args))
501 ((or (string= arg "-q")
502 (string= arg "-no-init-file"))
503 (setq load-user-init-file-p nil))
504 ((string= arg "-no-site-file")
505 (setq site-start-file nil))
506 ((or (string= arg "-no-early-packages")
507 (string= arg "--no-early-packages"))
508 (setq inhibit-early-packages t))
509 ((or (string= arg "-warn-early-package-shadows")
510 (string= arg "--warn-early-package-shadows"))
511 (setq warn-early-package-shadows t))
512 ((or (string= arg "-vanilla")
513 (string= arg "--vanilla")
514 ;; Some work on this one already done in emacs.c.
515 (string= arg "-no-autoloads")
516 (string= arg "--no-autoloads"))
517 (setq load-user-init-file-p nil
518 site-start-file nil))
519 ((string= arg "-user-init-file")
520 (setq user-init-file (pop args)))
521 ((string= arg "-user-init-directory")
522 (setq user-init-directory (file-name-as-directory (pop args))))
523 ((or (string= arg "-u")
524 (string= arg "-user"))
525 (let* ((user (pop args))
526 (home-user (concat "~" user))
527 (xdgdir (paths-construct-path
528 (list home-user ".config" "sxemacs")))
529 (legacydir (paths-construct-path (list home-user ".sxemacs")))
530 (dir-user (or (and (file-directory-p xdgdir)
531 (file-name-as-directory xdgdir))
532 (file-name-as-directory legacydir))))
533 (setq user-init-directory dir-user)
535 (find-user-init-file user-init-directory))
537 (make-custom-file-name user-init-file))))
538 ((string= arg "-debug-init")
539 (setq init-file-debug t))
540 ((string= arg "-unmapped")
541 (setq initial-frame-unmapped-p t))
542 ((or (string= arg "-debug-paths")
543 (string= arg "--debug-paths"))
545 ((or (string= arg "--") (string= arg "-"))
547 (push (pop args) new-args)))
548 (t (push arg new-args))))
550 ;; obsolete, initialize for backward compatibility
551 (with-obsolete-variable 'init-file-user
552 (setq init-file-user (and load-user-init-file-p "")))
554 (nreverse new-args)))
556 (defconst initial-scratch-message
557 ";; This buffer is for notes you don't want to save, and for Lisp evaluation.
558 ;; If you want to create a file, first visit that file with C-x C-f,
559 ;; then enter the text in that file's own buffer.
561 ;; In \"SXEmacs-speak\", `C-char' and `M-char' are abbreviations that mean
562 ;; `Control+char' and `Meta+char' (hold down the Control or Meta key while
565 ;; For Lisp evaluation, type an expression, move to the end and hit C-j.
569 "Initial message displayed in *scratch* buffer at startup.
570 If this is nil, no message will be displayed.")
572 (defun command-line ()
573 (let ((command-line-args-left (cdr command-line-args)))
575 (let ((debugger 'early-error-handler)
578 ;; Process magic command-line switches like -q and -u. Do this
579 ;; before creating the first frame because some of these switches
580 ;; may affect that. I think it's ok to do this before establishing
581 ;; the X connection, and maybe someday things like -nw can be
582 ;; handled here instead of down in C.
583 (setq command-line-args-left (command-line-early command-line-args-left))
585 ;; Setup the toolbar icon directory
586 (when (featurep 'toolbar)
587 (init-toolbar-location))
589 ;; Run the window system's init function. tty is considered to be
590 ;; a type of window system for this purpose. This creates the
591 ;; initial (non stdio) device.
592 (when (and initial-window-system (not noninteractive))
593 (funcall (intern (concat "init-"
594 (symbol-name initial-window-system)
597 ;; When not in batch mode, this creates the first visible frame,
598 ;; and deletes the stdio device.
601 ;; Reinitialize faces if necessary. This function changes face if
602 ;; it is created during auto-autoloads loading. Otherwise, it
604 (startup-initialize-custom-faces)
607 ;; We have normality, I repeat, we have normality. Anything you still
608 ;; can't cope with is therefore your own problem. (And we don't need
609 ;; to kill SXEmacs for it.)
615 (with-current-buffer (get-buffer "*scratch*")
617 ;; (insert initial-scratch-message)
618 (set-buffer-modified-p nil)
619 (when (eq major-mode 'fundamental-mode)
620 (funcall initial-major-mode))
621 (font-lock-set-defaults))
623 ;; Load library for our terminal type.
624 ;; User init file can set term-file-prefix to nil to prevent this.
625 ;; Note that for any TTY's opened subsequently, the TTY init
626 ;; code will run this.
627 (when (and (eq 'tty (console-type))
628 (not (noninteractive)))
629 (load-terminal-library))
631 ;; Process the remaining args.
634 ;; it was turned on by default so that the warnings don't get displayed
635 ;; until after the splash screen.
636 (setq inhibit-warning-display nil)
637 ;; If -batch, terminate after processing the command options.
638 (when (noninteractive) (kill-emacs t))))
640 (defun load-terminal-library ()
641 "Load the terminal initialization library"
642 (when term-file-prefix
643 (let ((term (getenv "TERM"))
646 (not (load (concat term-file-prefix term) t t)))
647 ;; Strip off last hyphen and what follows, then try again
648 (if (setq colornum (string-match #r"[-+_][0-9]+\'" term))
649 (setq term (substring term 0 colornum))
650 (if (setq colornum (string-match #r"[-+_]\([0-9]+\)[^-_]+\'" term))
651 (setq term (replace-in-string term (match-string 1 term) ""))
652 (if (setq hyphend (string-match "[-+_][^-_]+\\'" term))
653 (setq term (substring term 0 hyphend))
654 (setq term nil))))))))
656 (defun find-user-init-directory-init-file (&optional init-directory)
657 "Determine the user's init file if in the init directory."
658 (let ((init-directory (or init-directory user-init-directory)))
660 (dolist (file user-init-file-base-list)
661 (let ((expanded (expand-file-name file init-directory)))
662 (when (file-readable-p expanded)
663 (throw 'found expanded)))))))
665 (defun find-user-init-file (&optional init-directory)
666 "Determine the user's init file."
667 (find-user-init-directory-init-file init-directory))
669 (defun load-user-init-file ()
670 "This function actually reads the init file."
671 (unless (paths-file-readable-directory-p user-init-directory)
672 (make-directory-path user-init-directory))
673 (if (not user-init-file)
675 (find-user-init-file user-init-directory)))
676 (if (not custom-file)
677 (setq custom-file (make-custom-file-name user-init-file)))
678 ;; #### should test load-user-init-file-p here, not in load-init-file
680 (if (and user-init-file
681 (file-readable-p user-init-file))
682 (load user-init-file t t t))
684 (or (not user-init-file)
685 (not (string= custom-file user-init-file)))
686 (file-readable-p custom-file))
687 (load custom-file t t t))
688 (unless inhibit-default-init
689 (let ((inhibit-startup-message nil))
690 ;; Users are supposed to be told their rights.
691 ;; (Plus how to get help and how to undo.)
692 ;; Don't you dare turn this off for anyone except yourself.
693 (load "default" t t))))
695 ;;; Load user's init file and default ones.
696 (defun load-init-file ()
697 (run-hooks 'before-init-hook)
699 ;; Run the site-start library if it exists. The point of this file is
700 ;; that it is run before .emacs. There is no point in doing this after
701 ;; .emacs; that is useless.
702 (when site-start-file
703 (load site-start-file t t))
705 ;; Sites should not disable this. Only individuals should disable
706 ;; the startup message.
707 (setq inhibit-startup-message nil)
709 (let (debug-on-error-from-init-file
710 debug-on-error-should-be-set
711 (debug-on-error-initial
712 (if (eq init-file-debug t) 'startup init-file-debug)))
713 (let ((debug-on-error debug-on-error-initial))
714 ;; #### I believe this test is incorrect, it leads to custom-file
715 ;; (at least) being undefined
716 (if (and load-user-init-file-p init-file-debug)
718 ;; Do this without a condition-case if the user wants to debug.
719 (load-user-init-file))
720 (condition-case error
722 ;; #### probably incorrect, see comment above
723 (if load-user-init-file-p
724 (load-user-init-file))
725 (setq init-file-had-error nil))
727 (message "Error in init file: %s" (error-message-string error))
728 (display-warning 'initialization
729 (format "An error has occurred while loading %s:
733 To ensure normal operation, you should investigate the cause of the error
734 in your initialization file and remove it. Use the `-debug-init' option
735 to SXEmacs to view a complete error backtrace."
736 user-init-file (error-message-string error))
738 (setq init-file-had-error t))))
739 ;; If we can tell that the init file altered debug-on-error,
740 ;; arrange to preserve the value that it set up.
741 (or (eq debug-on-error debug-on-error-initial)
742 (setq debug-on-error-should-be-set t
743 debug-on-error-from-init-file debug-on-error)))
744 (when debug-on-error-should-be-set
745 (setq debug-on-error debug-on-error-from-init-file)))
747 (setq init-file-loaded t)
749 ;; Do this here in case the init file sets mail-host-address.
750 ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
751 ;; (or user-mail-address
753 (setq user-mail-address (concat (user-login-name) "@"
754 (or mail-host-address
757 (run-hooks 'after-init-hook)
760 (defun load-options-file (filename)
761 "Load the file of saved options (from the Options menu) called FILENAME.
762 Currently this does nothing but call `load', but it might be redefined
763 in the future to support automatically converting older options files to
764 a new format, when variables have changed, etc."
767 (defun command-line-1 ()
769 ((null command-line-args-left)
770 (unless noninteractive
771 ;; If there are no switches to process, run the term-setup-hook
772 ;; before displaying the copyright notice; there may be some need
773 ;; to do it before doing any output. If we're not going to
774 ;; display a copyright notice (because other options are present)
775 ;; then this is run after those options are processed.
776 (run-hooks 'term-setup-hook)
777 ;; Don't let the hook be run twice.
778 (setq term-setup-hook nil)
780 ;; Don't clobber a non-scratch buffer if init file
782 (when (string= (buffer-name) "*scratch*")
783 (unless (or inhibit-startup-message
785 (let (tmout circ-tmout)
787 ;; Guts of with-timeout
789 (setq tmout (add-timeout startup-message-timeout
795 (setq circ-tmout (display-splash-frame))
796 (or nil;; (pos-visible-in-window-p (point-min))
797 (goto-char (point-min)))
799 (setq unread-command-event (next-command-event)))
800 (when tmout (disable-timeout tmout))
801 (when circ-tmout (disable-timeout circ-tmout)))))
802 (with-current-buffer (get-buffer "*scratch*")
803 ;; In case the SXEmacs server has already selected
804 ;; another buffer, erase the one our message is in.
806 (when (stringp initial-scratch-message)
807 (insert initial-scratch-message))
808 (set-buffer-modified-p nil)))))
811 ;; Command-line-options exist
812 (let ((dir command-line-default-directory)
817 (while command-line-args-left
818 (setq arg (pop command-line-args-left))
822 ((setq tem (when (eq (aref arg 0) ?-)
823 (or (assoc arg command-switch-alist)
824 (assoc (substring arg 1)
825 command-switch-alist))))
826 (funcall (cdr tem) arg))
827 ((string-match #r"\`\+[0-9]+\'" arg)
828 (setq line (string-to-int arg)))
829 ;; "- file" means don't treat "file" as a switch
830 ;; ("+0 file" has the same effect; "-" added
831 ;; for unixoidiality).
832 ;; This is worthless; the `unixoid' way is "./file". -jwz
833 ((or (string= arg "-") (string= arg "--"))
834 (setq end-of-options t))
841 (setq arg (expand-file-name arg dir))
845 (noninteractive (find-file arg))
846 (t (find-file-other-window arg)))
849 (setq line nil))))))))
851 (defvar startup-presentation-hack-keymap
852 (let ((map (make-sparse-keymap)))
853 (set-keymap-name map 'startup-presentation-hack-keymap)
854 (define-key map '[button1] 'startup-presentation-hack)
855 (define-key map '[button2] 'startup-presentation-hack)
857 "Putting yesterday in the future tomorrow.")
859 (defun startup-presentation-hack ()
861 (let ((e last-command-event))
862 (and (button-press-event-p e)
863 (setq e (extent-at (event-point e)
865 'startup-presentation-hack))
866 (setq e (extent-property e 'startup-presentation-hack))
868 (apply (car e) (cdr e))
869 (while (keymapp (indirect-function e))
871 (overriding-local-map (indirect-function e)))
872 (setq e (read-key-sequence
873 (let ((p (keymap-prompt map t)))
876 (format "%s %s " map p)
880 (prin1-to-string map))))))
881 (if (and (button-release-event-p (elt e 0))
882 (null (key-binding e)))
883 (setq e map) ; try again
884 (setq e (key-binding e)))))
885 (call-interactively e)))))
887 (defun startup-presentation-hack-help (e)
888 (setq e (extent-property e 'startup-presentation-hack))
890 (format "Evaluate %S" e)
893 (defun splash-frame-present-hack (e v)
894 ;; (set-extent-property e 'mouse-face 'highlight)
895 ;; (set-extent-property e 'keymap
896 ;; startup-presentation-hack-keymap)
897 ;; (set-extent-property e 'startup-presentation-hack v)
898 ;; (set-extent-property e 'help-echo
899 ;; 'startup-presentation-hack-help)
902 (defun splash-frame-present (l)
905 ((eq (car-safe l) 'face)
906 ;; (face name string)
908 (splash-frame-present (elt l 2))
909 (if (fboundp 'set-extent-face)
910 (set-extent-face (make-extent p (point))
912 ((eq (car-safe l) 'key)
915 (k (where-is-internal c nil t)))
916 (insert (if k (key-description k)
917 (format "M-x %s" c)))
918 (if (fboundp 'set-extent-face)
919 (let ((e (make-extent p (point))))
920 (set-extent-face e 'bold)
921 (splash-frame-present-hack e c)))))
922 ((eq (car-safe l) 'funcall)
923 ;; (funcall (fun . args) string)
925 (splash-frame-present (elt l 2))
926 (if (fboundp 'set-extent-face)
927 (splash-frame-present-hack (make-extent p (point))
930 (mapcar 'splash-frame-present l))
932 (backtrace 'external-debugging-output)
935 (defun startup-center-spaces (glyph)
936 ;; Return the number of spaces to insert in order to center
937 ;; the given glyph (may be a string or a pixmap).
938 ;; Assume spaces are as wide as avg-pixwidth.
939 ;; Won't be quite right for proportional fonts, but it's the best we can do.
940 ;; Maybe the new redisplay will export something a glyph-width function.
941 ;;; #### Yes, there is a glyph-width function but it isn't quite what
942 ;;; #### this was expecting. Or is it?
943 ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
944 ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
946 ;; This function is used in about.el too.
947 (let* ((avg-pixwidth (round (/ (frame-pixel-width) (frame-width))))
948 (fill-area-width (* avg-pixwidth (- fill-column left-margin)))
949 (glyph-pixwidth (cond ((stringp glyph)
950 (* avg-pixwidth (length glyph)))
951 ;; #### the pixmap option should be removed
953 ;; (pixmap-width glyph))
957 (error "startup-center-spaces: bad arg")))))
959 (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
961 (defun splash-frame-body ()
962 `[((face (blue bold underline)
963 "\nDistribution, copying license, warranty:\n\n")
964 "Please visit the SXEmacs website at http://www.sxemacs.org !\n\n"
965 ((key describe-no-warranty)
966 ": "(face (red bold) "SXEmacs comes with ABSOLUTELY NO WARRANTY\n"))
967 ((key describe-copying)
968 ": conditions to give out copies of SXEmacs\n")
969 ((key describe-distribution)
970 ": how to get the latest version\n")
971 ((face (blue bold underline) "\nOur Mission is:\n\n"))
973 - To provide the Open Source community with a text editing and
974 development environment that is based on XEmacs and is 2nd to
975 none in regards to stability, features, and innovation.
977 - To foster a user and developer friendly project environment.
979 - And, above all, to have fun doing it.\n"
982 Copyright (C) 2004 - 2012 Steve Youngs\n"))
983 ; Copyright (C) 1985-2001 Free Software Foundation, Inc.
984 ; Copyright (C) 1990-1994 Lucid, Inc.
985 ; Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
986 ; Copyright (C) 1994-1996 Board of Trustees, University of Illinois
987 ; Copyright (C) 1995-2001 Ben Wing\n"))
989 ((face (blue bold underline) "\nInformation, on-line help:\n\n")
990 "SXEmacs comes with plenty of documentation...\n\n"
991 ,@(if emacs-beta-version
992 `((key describe-beta)
993 ": " (face (red bold)
994 "This is an Experimental version of SXEmacs.\n"))
996 ((key sxemacs-local-faq)
997 ": read the SXEmacs FAQ (a " (face underline "capital") " F!)\n")
998 ((key help-with-tutorial)
999 ": read the SXEmacs tutorial (also available through the "
1000 (face bold "Help") " menu)\n")
1002 ": get help on using SXEmacs (also available through the "
1003 (face bold "Help") " menu)\n")
1004 ((key info) ": read the on-line documentation\n\n")
1005 ((key about-sxemacs) ": see who's developing SXEmacs\n"))
1007 ((face (blue bold underline) "\nUseful stuff:\n\n")
1008 "Things that you should learn rather quickly...\n\n"
1009 ((key find-file) ": visit a file\n")
1010 ((key save-buffer) ": save changes\n")
1011 ((key advertised-undo) ": undo changes\n")
1012 ((key save-buffers-kill-emacs) ": exit SXEmacs\n"))
1015 ;; I really hate global variables, oh well.
1016 ;(defvar xemacs-startup-logo-function nil
1017 ; "If non-nil, function called to provide the startup logo.
1018 ;This function should return an initialized glyph if it is used.")
1020 ;; This will hopefully go away when gettext is functional.
1021 (defconst splash-frame-static-body
1022 `(,(emacs-version) "\n\n"
1023 (face italic "`C-' means the control key,`M-' means the meta key\n\n")))
1026 (defun circulate-splash-frame-elements (client-data)
1027 (with-current-buffer (aref client-data 2)
1028 (let ((buffer-read-only nil)
1029 (elements (aref client-data 3))
1030 (indice (aref client-data 0)))
1031 (goto-char (aref client-data 1))
1032 (delete-region (point) (point-max))
1033 (splash-frame-present (aref elements indice))
1034 (goto-char (point-min))
1035 (set-buffer-modified-p nil)
1037 (if (= indice (1- (length elements)))
1042 ;; #### This function now returns the (possibly nil) timeout circulating the
1043 ;; splash-frame elements
1044 (defun display-splash-frame ()
1045 (let ((logo sxemacs-logo)
1046 (buffer-read-only nil)
1047 (cramped-p (eq 'tty (console-type))))
1048 (unless cramped-p (insert "\n"))
1049 (indent-to (startup-center-spaces logo))
1050 (set-extent-begin-glyph (make-extent (point) (point)) logo)
1051 ;;(splash-frame-present-hack (make-extent p (point)) 'about-sxemacs))
1053 (splash-frame-present splash-frame-static-body)
1054 (goto-char (point-max))
1055 (let* ((after-change-functions nil) ; no font-lock, thank you
1056 (elements (splash-frame-body))
1057 (client-data `[ 1 ,(point) ,(current-buffer) ,elements ])
1059 (if (listp elements) ;; A single element to display
1060 (splash-frame-present (splash-frame-body))
1061 ;; several elements to rotate
1062 (splash-frame-present (aref elements 0))
1063 (setq tmout (add-timeout splash-frame-timeout
1064 'circulate-splash-frame-elements
1065 client-data splash-frame-timeout)))
1066 (set-buffer-modified-p nil)
1069 ;; (let ((present-file
1071 ;; (splash-frame-present
1073 ;; (list 'find-file-other-window
1074 ;; (expand-file-name f data-directory))
1076 ;; (insert "For customization examples, see the files ")
1077 ;; (funcall present-file "sample.emacs")
1079 ;; (funcall present-file "sample.Xdefaults")
1080 ;; (insert (format "\nin the directory %s." data-directory)))
1082 (defun startup-set-invocation-environment ()
1083 ;; XEmacs -- Steven Baur says invocation directory is nil if you
1084 ;; try to use XEmacs as a login shell.
1085 (or invocation-directory (setq invocation-directory default-directory))
1086 (setq invocation-directory
1087 ;; don't let /tmp_mnt/... get into the load-path or exec-path.
1088 (abbreviate-file-name invocation-directory)))
1090 (defvar Info-directory-list)
1092 (defun startup-setup-paths (roots user-init-directory
1094 inhibit-early-packages debug-paths)
1095 "Setup all the various paths.
1096 ROOTS is a list of plausible roots of the SXEmacs directory hierarchy.
1097 If INHIBIT-PACKAGES is non-NIL, don't do packages.
1098 If DEBUG-PATHS is non-NIL, print paths as they are detected.
1099 It's idempotent, so call this as often as you like!"
1101 (apply #'(lambda (early late last)
1102 (setq early-packages (and (not inhibit-early-packages)
1104 (setq late-packages late)
1105 (setq last-packages last))
1106 (packages-find-packages
1108 (packages-compute-package-locations user-init-directory)))
1110 (setq early-package-load-path
1111 (packages-find-package-load-path early-packages)
1112 late-package-load-path
1113 (packages-find-package-load-path late-packages)
1114 last-package-load-path
1115 (packages-find-package-load-path last-packages))
1119 (princ (format "configure-package-path:\n%S\n" configure-package-path)
1120 'external-debugging-output)
1121 (princ (format "early-packages and early-package-load-path:\n%S\n%S\n"
1122 early-packages early-package-load-path)
1123 'external-debugging-output)
1124 (princ (format "late-packages and late-package-load-path:\n%S\n%S\n"
1125 late-packages late-package-load-path)
1126 'external-debugging-output)
1127 (princ (format "last-packages and last-package-load-path:\n%S\n%S\n"
1128 last-packages last-package-load-path)
1129 'external-debugging-output)))
1131 (setq lisp-directory (paths-find-lisp-directory roots))
1134 (princ (format "lisp-directory:\n%S\n" lisp-directory)
1135 'external-debugging-output))
1137 (if (featurep 'mule)
1139 (setq mule-lisp-directory
1140 (paths-find-mule-lisp-directory roots
1143 (princ (format "mule-lisp-directory:\n%S\n"
1144 mule-lisp-directory)
1145 'external-debugging-output)))
1146 (setq mule-lisp-directory '()))
1148 (setq ffi-lisp-directory
1149 (when (fboundp #'ffi-defun)
1150 (paths-find-ffi-lisp-directory roots
1154 (setq module-directory (paths-find-module-directory roots))
1156 (princ (format "module-directory:\n%S\n" module-directory)
1157 'external-debugging-output))
1158 (setq site-module-directory (and (null inhibit-site-modules)
1159 (paths-find-site-module-directory roots)))
1160 (if (and debug-paths (null inhibit-site-modules))
1161 (princ (format "site-module-directory:\n%S\n" site-module-directory)
1162 'external-debugging-output))
1164 (setq load-path (paths-construct-load-path roots
1165 early-package-load-path
1166 late-package-load-path
1167 last-package-load-path
1171 ffi-lisp-directory))
1173 (setq Info-directory-list
1174 (paths-construct-info-path roots
1175 early-packages late-packages last-packages))
1179 (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1180 'external-debugging-output))
1182 (setq exec-directory (paths-find-exec-directory roots))
1185 (princ (format "exec-directory:\n%s\n" exec-directory)
1186 'external-debugging-output))
1189 (paths-construct-exec-path roots exec-directory
1190 early-packages late-packages last-packages))
1193 (princ (format "exec-path:\n%S\n" exec-path)
1194 'external-debugging-output))
1196 (setq doc-directory (paths-find-doc-directory roots))
1199 (princ (format "doc-directory:\n%S\n" doc-directory)
1200 'external-debugging-output))
1202 (setq data-directory (paths-find-data-directory roots))
1205 (princ (format "data-directory:\n%S\n" data-directory)
1206 'external-debugging-output))
1208 (setq data-directory-list
1209 (paths-construct-data-directory-list data-directory
1214 (princ (format "data-directory-list:\n%S\n" data-directory-list)
1215 'external-debugging-output)))
1217 (defun startup-find-roots-warning ()
1219 (set-buffer (get-buffer-create " *warning-tmp*"))
1221 (buffer-disable-undo (current-buffer))
1223 (insert "Couldn't find an obvious default for the root of the\n"
1224 "SXEmacs hierarchy.")
1226 (princ "\nWARNING:\n" 'external-debugging-output)
1227 (princ (buffer-string) 'external-debugging-output)))
1229 (defun startup-setup-paths-warning ()
1230 (let ((warnings '()))
1232 ((null (and lisp-directory exec-directory data-directory doc-directory
1235 (set-buffer (get-buffer-create " *warning-tmp*"))
1237 (buffer-disable-undo (current-buffer))
1238 (if (null lisp-directory) (push "lisp-directory" warnings))
1239 (if (and (featurep 'mule)
1240 (null mule-lisp-directory))
1241 (push "mule-lisp-directory" warnings))
1242 (if (null exec-directory) (push "exec-directory" warnings))
1243 (if (null data-directory) (push "data-directory" warnings))
1244 (if (null doc-directory) (push "doc-directory" warnings))
1245 (if (null load-path) (push "load-path" warnings))
1247 (insert "Couldn't find obvious defaults for:\n")
1249 (insert (car warnings) "\n")
1250 (setq warnings (cdr warnings)))
1251 (insert "Perhaps some directories don't exist, "
1252 "or the SXEmacs executable,\n"
1253 (concat invocation-directory invocation-name)
1254 "\nis in a strange place?")
1256 (princ "\nWARNING:\n" 'external-debugging-output)
1257 (princ (buffer-string) 'external-debugging-output)
1262 (defun startup-load-autoloads ()
1263 "Load autoloads from known locations."
1265 (when (and (not inhibit-autoloads)
1266 (or lisp-directory module-directory))
1267 ;; ordinary auto-autoloads in lisp/
1268 (let ((aalfile (file-name-sans-extension autoload-file-name)))
1271 (load (expand-file-name aalfile lisp-directory) nil t)
1274 ;; just load them all
1278 (load (expand-file-name (concat "lisp/" aalfile) root) nil t)
1282 (when (featurep 'mule)
1283 (load (expand-file-name aalfile
1284 (expand-file-name "mule" lisp-directory))
1286 (when (featurep 'modules)
1287 (load (expand-file-name aalfile module-directory) t t))
1289 (when (fboundp #'ffi-defun)
1290 (load (expand-file-name aalfile
1291 (expand-file-name "ffi" lisp-directory))
1294 (unless inhibit-autoloads
1295 (unless inhibit-early-packages
1296 (packages-load-package-auto-autoloads early-package-load-path))
1297 (if (and (not inhibit-early-packages) (not warn-early-package-shadows))
1298 (let ((early-path (mapcar 'file-basename early-package-load-path))
1300 (mapc (lambda (path)
1301 (unless (member (file-basename path) early-path)
1302 (setq late-load-path (append late-load-path (list path)))))
1303 late-package-load-path)
1304 (packages-load-package-auto-autoloads late-load-path))
1305 (packages-load-package-auto-autoloads late-package-load-path))
1306 (packages-load-package-auto-autoloads last-package-load-path)))
1308 ;;; startup.el ends here