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