comparison lisp/startup.el @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of 18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details. 20 ;; General Public License for more details.
21 21
22 ;; You should have received a copy of the GNU General Public License 22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING. If not, write to the 23 ;; along with XEmacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, 59 Temple Place - Suite 330, 24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA. 25 ;; Boston, MA 02111-1307, USA.
26 26
27 ;;; Synched up with: FSF 19.34. 27 ;;; Synched up with: FSF 19.34.
28 28
105 "List of plausible roots of the XEmacs hierarchy.") 105 "List of plausible roots of the XEmacs hierarchy.")
106 106
107 (defvar user-init-directory-base ".xemacs" 107 (defvar user-init-directory-base ".xemacs"
108 "Base of directory where user-installed init files may go.") 108 "Base of directory where user-installed init files may go.")
109 109
110 (defvar user-init-file-base-list (append
111 '(".emacs.elc" ".emacs.el" ".emacs")
112 (and (eq system-type 'windows-nt)
113 '("_emacs.elc" "_emacs.el" "_emacs")))
114 "List of allowed init files. The first one found takes precedence.")
115
116 (defvar user-init-directory 110 (defvar user-init-directory
117 (file-name-as-directory 111 (file-name-as-directory
118 (paths-construct-path (list "~" user-init-directory-base))) 112 (paths-construct-path (list "~" user-init-directory-base)))
119 "Directory where user-installed init files may go.") 113 "Directory where user-installed init files may go.")
114
115 (defvar user-init-file-base "init.el"
116 "Default name of the user init file if uncompiled.
117 This should be used for migration purposes only.")
118
119 (defvar user-init-file-base-list '("init.elc" "init.el")
120 "List of allowed init files in the user's init directory.
121 The first one found takes precedence.")
122
123 (defvar user-home-init-file-base-list
124 (append '(".emacs.elc" ".emacs.el" ".emacs")
125 (and (eq system-type 'windows-nt)
126 '("_emacs.elc" "_emacs.el" "_emacs")))
127 "List of allowed init files in the user's home directory.
128 The first one found takes precedence.")
129
130 (defvar load-home-init-file nil
131 "Non-nil if XEmacs should load the init file from the home directory.
132 Otherwise, XEmacs will offer migration to the init directory.")
120 133
121 (defvar load-user-init-file-p t 134 (defvar load-user-init-file-p t
122 "Non-nil if XEmacs should load the user's init file.") 135 "Non-nil if XEmacs should load the user's init file.")
123 136
124 ;; #### called `site-run-file' in FSFmacs 137 ;; #### called `site-run-file' in FSFmacs
144 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1" 157 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
145 ;; "Regexp that specifies when to enable the ISO 8859-1 character set. 158 ;; "Regexp that specifies when to enable the ISO 8859-1 character set.
146 ;;We do that if this regexp matches the locale name 159 ;;We do that if this regexp matches the locale name
147 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.") 160 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
148 161
149 (defvar mail-host-address nil 162 (defcustom mail-host-address nil
150 "*Name of this machine, for purposes of naming users.") 163 "*Name of this machine, for purposes of naming users."
151 164 :type 'string
152 (defvar user-mail-address nil 165 :group 'mail)
166
167 (defcustom user-mail-address nil
153 "*Full mailing address of this user. 168 "*Full mailing address of this user.
154 This is initialized based on `mail-host-address', 169 This is initialized based on `mail-host-address',
155 after your init file is read, in case it sets `mail-host-address'.") 170 after your init file is read, in case it sets `mail-host-address'."
171 :type 'string
172 :group 'mail)
156 173
157 (defvar auto-save-list-file-prefix "~/.saves-" 174 (defvar auto-save-list-file-prefix "~/.saves-"
158 "Prefix for generating auto-save-list-file-name. 175 "Prefix for generating auto-save-list-file-name.
159 Emacs's pid and the system name will be appended to 176 Emacs's pid and the system name will be appended to
160 this prefix to create a unique file name.") 177 this prefix to create a unique file name.")
367 (princ (format "\ndoc-directory is %S" doc-directory) stream) 384 (princ (format "\ndoc-directory is %S" doc-directory) stream)
368 (princ (format "\nload-path is %S" load-path) stream) 385 (princ (format "\nload-path is %S" load-path) stream)
369 (princ "\n\n" stream))) 386 (princ "\n\n" stream)))
370 (when (not suppress-early-error-handler-backtrace) 387 (when (not suppress-early-error-handler-backtrace)
371 (backtrace stream t))) 388 (backtrace stream t)))
389 (if (fboundp 'mswindows-message-box)
390 (mswindows-message-box "Initialization error"))
372 (kill-emacs -1)) 391 (kill-emacs -1))
373
374 (defvar lock-directory)
375 (defvar superlock-file)
376 392
377 (defun normal-top-level () 393 (defun normal-top-level ()
378 (if command-line-processed 394 (if command-line-processed
379 (message "Back to top level.") 395 (message "Back to top level.")
380 (setq command-line-processed t) 396 (setq command-line-processed t)
446 ;; (if (fboundp 'font-menu-add-default) 462 ;; (if (fboundp 'font-menu-add-default)
447 ;; (font-menu-add-default)) 463 ;; (font-menu-add-default))
448 (when window-setup-hook 464 (when window-setup-hook
449 (run-hooks 'window-setup-hook)) 465 (run-hooks 'window-setup-hook))
450 (setq window-setup-hook nil)) 466 (setq window-setup-hook nil))
467
468 (if load-user-init-file-p
469 (maybe-migrate-user-init-file))
451 ;;####FSFmacs junk 470 ;;####FSFmacs junk
452 ;; (or menubar-bindings-done 471 ;; (or menubar-bindings-done
453 ;; (precompute-menubar-bindings)) 472 ;; (precompute-menubar-bindings))
454 )) 473 ))
455 474
529 (setq user-init-directory (file-name-as-directory (pop args)))) 548 (setq user-init-directory (file-name-as-directory (pop args))))
530 ((or (string= arg "-u") 549 ((or (string= arg "-u")
531 (string= arg "-user")) 550 (string= arg "-user"))
532 (let* ((user (pop args)) 551 (let* ((user (pop args))
533 (home-user (concat "~" user))) 552 (home-user (concat "~" user)))
534 (setq user-init-file (find-user-init-file home-user) 553 (setq user-init-directory (file-name-as-directory
535 user-init-directory (file-name-as-directory
536 (paths-construct-path 554 (paths-construct-path
537 (list home-user user-init-directory-base)))))) 555 (list home-user user-init-directory-base))))
556 (setq user-init-file
557 (find-user-init-file user-init-directory home-user))
558 (setq custom-file
559 (make-custom-file-name user-init-file))))
538 ((string= arg "-debug-init") 560 ((string= arg "-debug-init")
539 (setq init-file-debug t)) 561 (setq init-file-debug t))
540 ((string= arg "-unmapped") 562 ((string= arg "-unmapped")
541 (setq initial-frame-unmapped-p t)) 563 (setq initial-frame-unmapped-p t))
542 ((or (string= arg "-debug-paths") 564 ((or (string= arg "-debug-paths")
636 ;; Strip off last hyphen and what follows, then try again 658 ;; Strip off last hyphen and what follows, then try again
637 (if (setq hyphend (string-match "[-_][^-_]+\\'" term)) 659 (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
638 (setq term (substring term 0 hyphend)) 660 (setq term (substring term 0 hyphend))
639 (setq term nil)))))) 661 (setq term nil))))))
640 662
641 (defun find-user-init-file (&optional directory) 663 (defun find-user-init-directory-init-file (&optional init-directory)
664 "Determine the user's init file if in the init directory."
665 (let ((init-directory (or init-directory user-init-directory)))
666 (catch 'found
667 (dolist (file user-init-file-base-list)
668 (let ((expanded (expand-file-name file init-directory)))
669 (when (file-readable-p expanded)
670 (throw 'found expanded)))))))
671
672 (defun find-user-home-directory-init-file (&optional home-directory)
673 "Determine the user's init file if in the home directory."
674 (let ((home-directory (or home-directory "~")))
675 (catch 'found
676 (dolist (file user-home-init-file-base-list)
677 (let ((expanded (expand-file-name file home-directory)))
678 (when (file-readable-p expanded)
679 (throw 'found expanded))))
680 nil)))
681
682 (defun find-user-init-file (&optional init-directory home-directory)
642 "Determine the user's init file." 683 "Determine the user's init file."
643 (unless directory 684 (if load-home-init-file
644 (setq directory "~")) 685 (find-user-home-directory-init-file home-directory)
645 (dolist (file user-init-file-base-list) 686 (or (find-user-init-directory-init-file init-directory)
646 (let ((expanded (paths-construct-path (list directory file)))) 687 (find-user-home-directory-init-file home-directory))))
647 (when (file-exists-p expanded) 688
648 (return expanded))))) 689 (defun maybe-migrate-user-init-file ()
690 "Ask user if she wants to migrate the init file(s) to new location."
691 (if (and (not load-home-init-file)
692 (not (find-user-init-directory-init-file user-init-directory))
693 (stringp user-init-file)
694 (file-readable-p user-init-file))
695 (if (with-output-to-temp-buffer (help-buffer-name nil)
696 (progn
697 (princ "XEmacs recommends that the initialization code in
698 ")
699 (princ user-init-file)
700 (princ "
701 be migrated to the ")
702 (princ user-init-directory)
703 (princ " directory. XEmacs can
704 perform the migration automatically.
705
706 After the migration, init.el/init.elc holds user-written
707 initialization code. Moreover the customize settings will be in
708 custom.el.
709
710 If you choose not to do this now, XEmacs will not ask you this
711 question in the future. However, you can still make XEmacs
712 perform the migration at any time with M-x migrate-user-init-file.")
713 (show-temp-buffer-in-current-frame standard-output)
714 (yes-or-no-p-minibuf (concat "Migrate init file to "
715 user-init-directory
716 "? "))))
717 (migrate-user-init-file)
718 (customize-save-variable 'load-home-init-file t))))
719
720 (defun migrate-user-init-file ()
721 "Migrate the init file from the home directory."
722 (interactive)
723 (if (not (file-exists-p user-init-directory))
724 (progn
725 (message "Creating %s directory..." user-init-directory)
726 (make-directory user-init-directory)))
727 (message "Migrating custom file...")
728 (custom-migrate-custom-file (make-custom-file-name user-init-file
729 'force-new))
730 (message "Moving init file...")
731 (rename-file user-init-file
732 (expand-file-name user-init-file-base
733 user-init-directory))
734 (message "Migration done."))
649 735
650 (defun load-user-init-file () 736 (defun load-user-init-file ()
651 "This function actually reads the init file, .emacs." 737 "This function actually reads the init file."
652 (if (not user-init-file) 738 (if (not user-init-file)
653 (setq user-init-file (find-user-init-file))) 739 (setq user-init-file
654 (load user-init-file t t t) 740 (find-user-init-file user-init-directory)))
741 (if (and user-init-file
742 (file-readable-p user-init-file))
743 (load user-init-file t t t))
744 (if (not custom-file)
745 (setq custom-file (make-custom-file-name user-init-file)))
746 (if (and custom-file
747 (or (not user-init-file)
748 (not (string= custom-file user-init-file)))
749 (file-readable-p custom-file))
750 (load custom-file t t t))
655 (unless inhibit-default-init 751 (unless inhibit-default-init
656 (let ((inhibit-startup-message nil)) 752 (let ((inhibit-startup-message nil))
657 ;; Users are supposed to be told their rights. 753 ;; Users are supposed to be told their rights.
658 ;; (Plus how to get help and how to undo.) 754 ;; (Plus how to get help and how to undo.)
659 ;; Don't you dare turn this off for anyone except yourself. 755 ;; Don't you dare turn this off for anyone except yourself.
677 debug-on-error-should-be-set 773 debug-on-error-should-be-set
678 (debug-on-error-initial 774 (debug-on-error-initial
679 (if (eq init-file-debug t) 'startup init-file-debug))) 775 (if (eq init-file-debug t) 'startup init-file-debug)))
680 (let ((debug-on-error debug-on-error-initial)) 776 (let ((debug-on-error debug-on-error-initial))
681 (if (and load-user-init-file-p init-file-debug) 777 (if (and load-user-init-file-p init-file-debug)
682 ;; Do this without a condition-case if the user wants to debug. 778 (progn
683 (load-user-init-file) 779 ;; Do this without a condition-case if the user wants to debug.
780 (load-user-init-file))
684 (condition-case error 781 (condition-case error
685 (progn 782 (progn
686 (if load-user-init-file-p 783 (if load-user-init-file-p
687 (load-user-init-file)) 784 (load-user-init-file))
688 (setq init-file-had-error nil)) 785 (setq init-file-had-error nil))
775 ;; Command-line-options exist 872 ;; Command-line-options exist
776 (let ((dir command-line-default-directory) 873 (let ((dir command-line-default-directory)
777 (file-count 0) 874 (file-count 0)
778 (line nil) 875 (line nil)
779 (end-of-options nil) 876 (end-of-options nil)
780 first-file-buffer file-p arg tem) 877 file-p arg tem)
781 (while command-line-args-left 878 (while command-line-args-left
782 (setq arg (pop command-line-args-left)) 879 (setq arg (pop command-line-args-left))
783 (cond 880 (cond
784 (end-of-options 881 (end-of-options
785 (setq file-p t)) 882 (setq file-p t))
802 (when file-p 899 (when file-p
803 (setq file-p nil) 900 (setq file-p nil)
804 (incf file-count) 901 (incf file-count)
805 (setq arg (expand-file-name arg dir)) 902 (setq arg (expand-file-name arg dir))
806 (cond 903 (cond
807 ((= file-count 1) (setq first-file-buffer 904 ((= file-count 1)
808 (progn (find-file arg) (current-buffer)))) 905 (find-file arg))
809 (noninteractive (find-file arg)) 906 (noninteractive (find-file arg))
810 (t (find-file-other-window arg))) 907 (t (find-file-other-window arg)))
811 (when line 908 (when line
812 (goto-line line) 909 (goto-line line)
813 (setq line nil)))))))) 910 (setq line nil))))))))
1144 1241
1145 (if debug-paths 1242 (if debug-paths
1146 (princ (format "Info-directory-list:\n%S\n" Info-directory-list) 1243 (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1147 'external-debugging-output)) 1244 'external-debugging-output))
1148 1245
1149 (if (boundp 'lock-directory)
1150 (progn
1151 (setq lock-directory (paths-find-lock-directory roots))
1152 (setq superlock-file (paths-find-superlock-file lock-directory))
1153
1154 (if debug-paths
1155 (progn
1156 (princ (format "lock-directory:\n%S\n" lock-directory)
1157 'external-debugging-output)
1158 (princ (format "superlock-file:\n%S\n" superlock-file)
1159 'external-debugging-output)))))
1160
1161 (setq exec-directory (paths-find-exec-directory roots)) 1246 (setq exec-directory (paths-find-exec-directory roots))
1162 1247
1163 (if debug-paths 1248 (if debug-paths
1164 (princ (format "exec-directory:\n%s\n" exec-directory) 1249 (princ (format "exec-directory:\n%s\n" exec-directory)
1165 'external-debugging-output)) 1250 'external-debugging-output))
1203 1288
1204 (princ "\nWARNING:\n" 'external-debugging-output) 1289 (princ "\nWARNING:\n" 'external-debugging-output)
1205 (princ (buffer-string) 'external-debugging-output))) 1290 (princ (buffer-string) 'external-debugging-output)))
1206 1291
1207 (defun startup-setup-paths-warning () 1292 (defun startup-setup-paths-warning ()
1208 (let ((lock (if (boundp 'lock-directory) lock-directory 't)) 1293 (let ((warnings '()))
1209 (warnings '()))
1210 (if (and (stringp lock) (null (file-directory-p lock)))
1211 (setq lock nil))
1212 (cond 1294 (cond
1213 ((null (and lisp-directory exec-directory data-directory doc-directory 1295 ((null (and lisp-directory exec-directory data-directory doc-directory
1214 load-path 1296 load-path))
1215 lock))
1216 (save-excursion 1297 (save-excursion
1217 (set-buffer (get-buffer-create " *warning-tmp*")) 1298 (set-buffer (get-buffer-create " *warning-tmp*"))
1218 (erase-buffer) 1299 (erase-buffer)
1219 (buffer-disable-undo (current-buffer)) 1300 (buffer-disable-undo (current-buffer))
1220 (if (null lisp-directory) (push "lisp-directory" warnings)) 1301 (if (null lisp-directory) (push "lisp-directory" warnings))
1221 (if (null lock) (push "lock-directory" warnings))
1222 (if (null exec-directory) (push "exec-directory" warnings)) 1302 (if (null exec-directory) (push "exec-directory" warnings))
1223 (if (null data-directory) (push "data-directory" warnings)) 1303 (if (null data-directory) (push "data-directory" warnings))
1224 (if (null doc-directory) (push "doc-directory" warnings)) 1304 (if (null doc-directory) (push "doc-directory" warnings))
1225 (if (null load-path) (push "load-path" warnings)) 1305 (if (null load-path) (push "load-path" warnings))
1226 1306