Commit | Line | Data |
---|---|---|
6594deb0 ER |
1 | ;;; novice.el --- handling of disabled commands ("novice mode") for Emacs. |
2 | ||
a2535589 JA |
3 | ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc. |
4 | ||
5 | ;; This file is part of GNU Emacs. | |
6 | ||
7 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 | ;; it under the terms of the GNU General Public License as published by | |
9 | ;; the Free Software Foundation; either version 1, or (at your option) | |
10 | ;; any later version. | |
11 | ||
12 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;; GNU General Public License for more details. | |
16 | ||
17 | ;; You should have received a copy of the GNU General Public License | |
18 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | ||
21 | ||
22 | ;; This function is called (by autoloading) | |
23 | ;; to handle any disabled command. | |
24 | ;; The command is found in this-command | |
25 | ;; and the keys are returned by (this-command-keys). | |
26 | ||
7229064d | 27 | ;;;###autoload |
73fa8346 BP |
28 | (setq disabled-command-hook 'disabled-command-hook) |
29 | ||
1c599895 | 30 | ;;;###autoload |
a2535589 JA |
31 | (defun disabled-command-hook (&rest ignore) |
32 | (let (char) | |
33 | (save-window-excursion | |
34 | (with-output-to-temp-buffer "*Help*" | |
35 | (if (= (aref (this-command-keys) 0) ?\M-x) | |
36 | (princ "You have invoked the disabled command ") | |
37 | (princ "You have typed ") | |
38 | (princ (key-description (this-command-keys))) | |
39 | (princ ", invoking disabled command ")) | |
40 | (princ this-command) | |
41 | (princ ":\n") | |
42 | ;; Print any special message saying why the command is disabled. | |
43 | (if (stringp (get this-command 'disabled)) | |
44 | (princ (get this-command 'disabled))) | |
45 | (princ (or (condition-case () | |
46 | (documentation this-command) | |
47 | (error nil)) | |
48 | "<< not documented >>")) | |
49 | ;; Keep only the first paragraph of the documentation. | |
50 | (save-excursion | |
51 | (set-buffer "*Help*") | |
52 | (goto-char (point-min)) | |
53 | (if (search-forward "\n\n" nil t) | |
54 | (delete-region (1- (point)) (point-max)) | |
55 | (goto-char (point-max)))) | |
56 | (princ "\n\n") | |
57 | (princ "You can now type | |
58 | Space to try the command just this once, | |
59 | but leave it disabled, | |
60 | Y to try it and enable it (no questions if you use it again), | |
61 | N to do nothing (command remains disabled).")) | |
62 | (message "Type y, n or Space: ") | |
63 | (let ((cursor-in-echo-area t)) | |
64 | (while (not (memq (setq char (downcase (read-char))) | |
65 | '(? ?y ?n))) | |
66 | (ding) | |
67 | (message "Please type y, n or Space: ")))) | |
68 | (if (= char ?y) | |
69 | (if (y-or-n-p "Enable command for future editing sessions also? ") | |
70 | (enable-command this-command) | |
71 | (put this-command 'disabled nil))) | |
72 | (if (/= char ?n) | |
73 | (call-interactively this-command)))) | |
74 | ||
7229064d | 75 | ;;;###autoload |
a2535589 JA |
76 | (defun enable-command (command) |
77 | "Allow COMMAND to be executed without special confirmation from now on. | |
78 | The user's .emacs file is altered so that this will apply | |
79 | to future sessions." | |
80 | (interactive "CEnable command: ") | |
81 | (put command 'disabled nil) | |
82 | (save-excursion | |
83 | (set-buffer (find-file-noselect (substitute-in-file-name "~/.emacs"))) | |
84 | (goto-char (point-min)) | |
85 | (if (search-forward (concat "(put '" (symbol-name command) " ") nil t) | |
86 | (delete-region | |
87 | (progn (beginning-of-line) (point)) | |
88 | (progn (forward-line 1) (point))) | |
89 | ;; Must have been disabled by default. | |
90 | (goto-char (point-max)) | |
91 | (insert "\n(put '" (symbol-name command) " 'disabled nil)\n")) | |
92 | (setq foo (buffer-modified-p)) | |
93 | (save-buffer))) | |
94 | ||
7229064d | 95 | ;;;###autoload |
a2535589 JA |
96 | (defun disable-command (command) |
97 | "Require special confirmation to execute COMMAND from now on. | |
98 | The user's .emacs file is altered so that this will apply | |
99 | to future sessions." | |
100 | (interactive "CDisable command: ") | |
101 | (put command 'disabled t) | |
102 | (save-excursion | |
103 | (set-buffer (find-file-noselect (substitute-in-file-name "~/.emacs"))) | |
104 | (goto-char (point-min)) | |
105 | (if (search-forward (concat "(put '" (symbol-name command) " ") nil t) | |
106 | (delete-region | |
107 | (progn (beginning-of-line) (point)) | |
108 | (progn (forward-line 1) (point)))) | |
109 | (goto-char (point-max)) | |
110 | (insert "(put '" (symbol-name command) " 'disabled t)\n") | |
111 | (save-buffer))) | |
112 | ||
6594deb0 | 113 | ;;; novice.el ends here |