# HG changeset patch # User Eli Zaretskii # Date 1012654074 0 # Node ID 0a91a443d0913b7903d52bb3c12fab3f41f89793 # Parent 39be9e04a9a4f4fb0807cecd6839857164e4ca4e (enable-command): If Emacs was invoked as "emacs -q", don't alter the user's ~/.emacs. (disable-command): If user-init-file is nil or does not exist, default to "~/.emacs" (~/_emacs on DOS and, maybe, Windows). But don't alter the init file if Emacs was invoked as "emacs -q" diff -r 39be9e04a9a4 -r 0a91a443d091 lisp/novice.el --- a/lisp/novice.el Sat Feb 02 10:11:45 2002 +0000 +++ b/lisp/novice.el Sat Feb 02 12:47:54 2002 +0000 @@ -107,10 +107,18 @@ to future sessions." (interactive "CEnable command: ") (put command 'disabled nil) - (let ((init-file user-init-file)) - (when (or (not (stringp init-file)) - (not (file-exists-p init-file))) - (setq init-file (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")) + (let ((init-file user-init-file) + (default-init-file + (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs"))) + (when (null init-file) + (if (or (file-exists-p default-init-file) + (and (eq system-type 'windows-nt) + (file-exists-p "~/_emacs"))) + ;; Started with -q, i.e. the file containing + ;; enabled/disabled commands hasn't been read. Saving + ;; settings there would overwrite other settings. + (error "Saving settings from \"emacs -q\" would overwrite existing customizations")) + (setq init-file default-init-file) (if (and (not (file-exists-p init-file)) (eq system-type 'windows-nt) (file-exists-p "~/_emacs")) @@ -138,17 +146,33 @@ (if (not (commandp command)) (error "Invalid command name `%s'" command)) (put command 'disabled t) - (save-excursion - (set-buffer (find-file-noselect - (substitute-in-file-name user-init-file))) - (goto-char (point-min)) - (if (search-forward (concat "(put '" (symbol-name command) " ") nil t) - (delete-region - (progn (beginning-of-line) (point)) - (progn (forward-line 1) (point)))) - (goto-char (point-max)) - (insert "\n(put '" (symbol-name command) " 'disabled t)\n") - (save-buffer))) + (let ((init-file user-init-file) + (default-init-file + (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs"))) + (when (null init-file) + (if (or (file-exists-p default-init-file) + (and (eq system-type 'windows-nt) + (file-exists-p "~/_emacs"))) + ;; Started with -q, i.e. the file containing + ;; enabled/disabled commands hasn't been read. Saving + ;; settings there would overwrite other settings. + (error "Saving settings from \"emacs -q\" would overwrite existing customizations")) + (setq init-file default-init-file) + (if (and (not (file-exists-p init-file)) + (eq system-type 'windows-nt) + (file-exists-p "~/_emacs")) + (setq init-file "~/_emacs"))) + (save-excursion + (set-buffer (find-file-noselect + (substitute-in-file-name init-file))) + (goto-char (point-min)) + (if (search-forward (concat "(put '" (symbol-name command) " ") nil t) + (delete-region + (progn (beginning-of-line) (point)) + (progn (forward-line 1) (point)))) + (goto-char (point-max)) + (insert "\n(put '" (symbol-name command) " 'disabled t)\n") + (save-buffer)))) (provide 'novice)