Mercurial > hg > xemacs-beta
comparison lisp/startup.el @ 4347:6b571dc4ba3f
Rework init-file migration.
2007-12-19 Mike Sperber <mike@xemacs.org>
* startup.el (user-init-file-migration-in-order-p): Factored out
check.
(maybe-migrate-user-init-file):
(migrate-user-init-file): Don't do a backup of ~/.emacs anymore.
Instead, make only a manual adjustment of the file, if at all,
i.e. don't go through customize magic anymore.
(unmigrate-user-init-file): Don't use customize to set
`load-home-init-file' anymore.
(set-load-home-init-file): Add; performs the modification
previously done through customize.
(unmigrate-user-init-file): Use `set-load-home-init-file' instead
of customize.
(command-line-1): Only wait for the first event if we're not going
to ask about migration.
author | Mike Sperber <sperber@deinprogramm.de> |
---|---|
date | Fri, 21 Dec 2007 16:51:30 +0100 |
parents | ff446f61f88f |
children | fd8a9a4d81d9 |
comparison
equal
deleted
inserted
replaced
4346:ec1103d2c1c7 | 4347:6b571dc4ba3f |
---|---|
847 (if load-home-init-file | 847 (if load-home-init-file |
848 (find-user-home-directory-init-file home-directory) | 848 (find-user-home-directory-init-file home-directory) |
849 (or (find-user-init-directory-init-file init-directory) | 849 (or (find-user-init-directory-init-file init-directory) |
850 (find-user-home-directory-init-file home-directory)))) | 850 (find-user-home-directory-init-file home-directory)))) |
851 | 851 |
852 (defun ask-about-user-init-file-migration-p () | |
853 "Check whether we want to ask the user if she wants to migrate the init file." | |
854 (and (not load-home-init-file) | |
855 (not (find-user-init-directory-init-file user-init-directory)) | |
856 (stringp user-init-file) | |
857 (file-readable-p user-init-file))) | |
858 | |
852 (defun maybe-migrate-user-init-file () | 859 (defun maybe-migrate-user-init-file () |
853 "Ask user if she wants to migrate the init file(s) to new location." | 860 "Ask user if she wants to migrate the init file(s) to new location." |
854 (if (and (not load-home-init-file) | 861 (if (ask-about-user-init-file-migration-p) |
855 (not (find-user-init-directory-init-file user-init-directory)) | |
856 (stringp user-init-file) | |
857 (file-readable-p user-init-file)) | |
858 (if (with-output-to-temp-buffer (help-buffer-name nil) | 862 (if (with-output-to-temp-buffer (help-buffer-name nil) |
859 (progn | 863 (progn |
860 (princ "XEmacs recommends that the initialization code in | 864 (princ "XEmacs recommends that the initialization code in |
861 ") | 865 ") |
862 (princ user-init-file) | 866 (princ user-init-file) |
879 (show-temp-buffer-in-current-frame standard-output) | 883 (show-temp-buffer-in-current-frame standard-output) |
880 (yes-or-no-p-minibuf (concat "Migrate init file to " | 884 (yes-or-no-p-minibuf (concat "Migrate init file to " |
881 user-init-directory | 885 user-init-directory |
882 "? ")))) | 886 "? ")))) |
883 | 887 |
884 (let ((backup (migrate-user-init-file))) | 888 (progn |
889 (migrate-user-init-file) | |
885 (with-output-to-temp-buffer (help-buffer-name nil) | 890 (with-output-to-temp-buffer (help-buffer-name nil) |
886 (progn | 891 (progn |
887 (princ "The initialization code has now been migrated to the ") | 892 (princ "The initialization code has now been migrated to the ") |
888 (princ user-init-directory) | 893 (princ user-init-directory) |
889 (princ "directory. | 894 (princ "directory. |
890 | 895 |
891 For backwards compatibility with, for example, older versions of XEmacs, | 896 For backwards compatibility with, for example, older versions of XEmacs, |
892 XEmacs can create a special old-style .emacs file in your home | 897 XEmacs can create a special old-style .emacs file in your home |
893 directory which will load the relocated initialization code.") | 898 directory which will load the relocated initialization code. |
894 (if backup | 899 |
895 (progn | 900 NOTE THAT THIS WILL OVERWRITE YOUR EXISTING .emacs FILE!") |
896 (princ "\nMoreover, a backup of your old .emacs file was created as\n") | |
897 (princ backup) | |
898 (princ ".\n"))) | |
899 (show-temp-buffer-in-current-frame standard-output) | 901 (show-temp-buffer-in-current-frame standard-output) |
900 (maybe-create-compatibility-dot-emacs)))) | 902 (maybe-create-compatibility-dot-emacs)))) |
901 (customize-save-variable 'load-home-init-file t)))) | 903 (set-load-home-init-file user-init-file t)))) |
902 | 904 |
903 (defun maybe-create-compatibility-dot-emacs () | 905 (defun maybe-create-compatibility-dot-emacs () |
904 "Ask user if she wants to create a .emacs compatibility file." | 906 "Ask user if she wants to create a .emacs compatibility file." |
905 (if (yes-or-no-p-minibuf "Create compatibility .emacs? ") | 907 (if (yes-or-no-p-minibuf "Create compatibility .emacs?") |
906 (create-compatibility-dot-emacs))) | 908 (create-compatibility-dot-emacs))) |
907 | 909 |
908 (defun migrate-user-init-file () | 910 (defun migrate-user-init-file () |
909 "Migrate the init file from the home directory. | 911 "Migrate the init file from the home directory." |
910 Return the name of backup file, if one was created." | |
911 (interactive) | 912 (interactive) |
912 (if (not (file-exists-p user-init-directory)) | 913 (if (not (file-exists-p user-init-directory)) |
913 (progn | 914 (progn |
914 (message "Creating %s directory..." user-init-directory) | 915 (message "Creating %s directory..." user-init-directory) |
915 (make-directory user-init-directory))) | 916 (make-directory user-init-directory))) |
916 (message "Migrating custom file...") | 917 (message "Migrating custom file...") |
917 (let* ((backup (concat user-init-file ".backup")) | 918 (set-load-home-init-file user-init-file nil) |
918 (backup-p | 919 (setq custom-file (make-custom-file-name user-init-file 'force-new)) |
919 (and (not (file-exists-p backup)) | 920 (custom-save-all) |
920 (progn | 921 (message "Copying init file...") |
921 (copy-file user-init-file backup) | 922 (let ((new-user-init-file (expand-file-name user-init-file-base |
922 t)))) | 923 user-init-directory))) |
923 (customize-set-value 'load-home-init-file nil) | 924 (copy-file user-init-file new-user-init-file) |
924 (custom-migrate-custom-file (make-custom-file-name user-init-file | 925 (setq user-init-file new-user-init-file)) |
925 'force-new)) | 926 (message "Migration done.")) |
926 (message "Moving init file...") | 927 |
927 (let ((new-user-init-file (expand-file-name user-init-file-base | 928 (defun set-load-home-init-file (filename val) |
928 user-init-directory))) | 929 "Put code in `filename' to set `load-home-init-file' to `val'. |
929 (rename-file user-init-file new-user-init-file) | 930 More precisely, remove the first `setq' form for `load-home-init-file', |
930 (setq user-init-file new-user-init-file)) | 931 and replace it by (setq load-home-init-file t) if `val' is non-nil." |
931 (message "Migration done.") | 932 (save-excursion |
932 (and backup-p backup))) | 933 (set-buffer (find-file-noselect filename)) |
934 (goto-char (point-min)) | |
935 (condition-case nil | |
936 (block find-existing | |
937 (while (not (eobp)) | |
938 (forward-sexp 1) | |
939 (backward-sexp 1) | |
940 (let* ((beginning (point)) | |
941 (sexp (read (current-buffer)))) | |
942 (if (and (consp sexp) | |
943 (consp (cdr sexp)) | |
944 (eq 'setq (car sexp)) | |
945 (eq 'load-home-init-file (cadr sexp))) | |
946 (progn | |
947 (forward-line 1) | |
948 (delete-region beginning (point)) | |
949 (return-from find-existing nil)) | |
950 (forward-sexp 1))))) | |
951 (error nil)) ; ignore if there are no sexprs in the file | |
952 (if val | |
953 (insert "(setq load-home-init-file t) ; don't load init file from ~/.xemacs/init.el\n")) | |
954 (save-buffer))) | |
933 | 955 |
934 (defun create-compatibility-dot-emacs () | 956 (defun create-compatibility-dot-emacs () |
935 "Create .emacs compatibility file for migrated setup." | 957 "Create .emacs compatibility file for migrated setup." |
936 (message "Creating .emacs compatibility file.") | 958 (message "Creating .emacs compatibility file.") |
937 (with-temp-file (expand-file-name ".emacs" "~") | 959 (with-temp-file (expand-file-name ".emacs" "~") |
963 (let ((target-file-name | 985 (let ((target-file-name |
964 (or target-file-name (expand-file-name ".emacs" "~")))) | 986 (or target-file-name (expand-file-name ".emacs" "~")))) |
965 (rename-file user-init-file target-file-name 'ok-if-already-exists) | 987 (rename-file user-init-file target-file-name 'ok-if-already-exists) |
966 (setq user-init-file target-file-name) | 988 (setq user-init-file target-file-name) |
967 (let ((old-custom-file custom-file)) | 989 (let ((old-custom-file custom-file)) |
968 (custom-migrate-custom-file target-file-name) | 990 (setq custom-file target-file-name) |
969 (customize-save-variable 'load-home-init-file t) | 991 (custom-save-all) |
992 (set-load-home-init-file user-init-file t) | |
970 (delete-file old-custom-file)))) | 993 (delete-file old-custom-file)))) |
971 | 994 |
972 (defun load-user-init-file () | 995 (defun load-user-init-file () |
973 "This function actually reads the init file." | 996 "This function actually reads the init file." |
974 (if (not user-init-file) | 997 (if (not user-init-file) |
1087 ;; Don't let the hook be run twice. | 1110 ;; Don't let the hook be run twice. |
1088 (setq term-setup-hook nil) | 1111 (setq term-setup-hook nil) |
1089 | 1112 |
1090 ;; Don't clobber a non-scratch buffer if init file | 1113 ;; Don't clobber a non-scratch buffer if init file |
1091 ;; has selected it. | 1114 ;; has selected it. |
1092 (when (string= (buffer-name) "*scratch*") | 1115 (when (and (string= (buffer-name) "*scratch*") |
1116 (not (ask-about-user-init-file-migration-p))) | |
1093 (unless (or inhibit-startup-message | 1117 (unless (or inhibit-startup-message |
1094 (input-pending-p)) | 1118 (input-pending-p)) |
1095 (let (tmout) | 1119 (let (tmout) |
1096 (unwind-protect | 1120 (unwind-protect |
1097 ;; Guts of with-timeout | 1121 ;; Guts of with-timeout |