|
|
1.1 root 1: ;; Handling of disabled commands ("novice mode") for Emacs.
2: ;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.
3:
4: ;; This file is part of GNU Emacs.
5:
6: ;; GNU Emacs is distributed in the hope that it will be useful,
7: ;; but WITHOUT ANY WARRANTY. No author or distributor
8: ;; accepts responsibility to anyone for the consequences of using it
9: ;; or for whether it serves any particular purpose or works at all,
10: ;; unless he says so in writing. Refer to the GNU Emacs General Public
11: ;; License for full details.
12:
13: ;; Everyone is granted permission to copy, modify and redistribute
14: ;; GNU Emacs, but only under the conditions described in the
15: ;; GNU Emacs General Public License. A copy of this license is
16: ;; supposed to have been given to you along with GNU Emacs so you
17: ;; can know your rights and responsibilities. It should be in a
18: ;; file named COPYING. Among other things, the copyright notice
19: ;; and this notice must be preserved on all copies.
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:
27: (defun disabled-command-hook (&rest ignore)
28: (let (char)
29: (save-window-excursion
30: (with-output-to-temp-buffer "*Help*"
31: (if (= (aref (this-command-keys) 0) ?\M-x)
32: (princ "You have invoked the disabled command ")
33: (princ "You have typed ")
34: (princ (key-description (this-command-keys)))
35: (princ ", invoking disabled command "))
36: (princ this-command)
37: (princ ":\n")
38: ;; Print any special message saying why the command is disabled.
39: (if (stringp (get this-command 'disabled))
40: (princ (get this-command 'disabled)))
41: (princ (or (condition-case ()
42: (documentation this-command)
43: (error nil))
44: "<< not documented >>"))
45: ;; Keep only the first paragraph of the documentation.
46: (save-excursion
47: (set-buffer "*Help*")
48: (goto-char (point-min))
49: (if (search-forward "\n\n" nil t)
50: (delete-region (1- (point)) (point-max))
51: (goto-char (point-max))))
52: (princ "\n\n")
53: (princ "You can now type
54: Space to try the command just this once,
55: but leave it disabled,
56: Y to try it and enable it (no questions if you use it again),
57: N to do nothing (command remains disabled)."))
58: (message "Type y, n or Space: ")
59: (let ((cursor-in-echo-area t))
60: (while (not (memq (setq char (downcase (read-char)))
61: '(? ?y ?n)))
62: (ding)
63: (message "Please type y, n or Space: "))))
64: (if (= char ?y)
65: (if (y-or-n-p "Enable command for future editing sessions also? ")
66: (enable-command this-command)
67: (put this-command 'disabled nil)))
68: (if (/= char ?n)
69: (call-interactively this-command))))
70:
71: (defun enable-command (command)
72: "Allow COMMAND to be executed without special confirmation from now on.
73: The user's .emacs file is altered so that this will apply
74: to future sessions."
75: (interactive "CEnable command: ")
76: (put command 'disabled nil)
77: (save-excursion
78: (set-buffer (find-file-noselect (substitute-in-file-name "~/.emacs")))
79: (goto-char (point-min))
80: (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
81: (delete-region
82: (progn (beginning-of-line) (point))
83: (progn (forward-line 1) (point)))
84: ;; Must have been disabled by default.
85: (goto-char (point-max))
86: (insert "\n(put '" (symbol-name command) " 'disabled nil)\n"))
87: (setq foo (buffer-modified-p))
88: (save-buffer)))
89:
90: (defun disable-command (command)
91: "Require special confirmation to execute COMMAND from now on.
92: The user's .emacs file is altered so that this will apply
93: to future sessions."
94: (interactive "CDisable command: ")
95: (put command 'disabled t)
96: (save-excursion
97: (set-buffer (find-file-noselect (substitute-in-file-name "~/.emacs")))
98: (goto-char (point-min))
99: (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
100: (delete-region
101: (progn (beginning-of-line) (point))
102: (progn (forward-line 1) (point))))
103: (goto-char (point-max))
104: (insert "(put '" (symbol-name command) " 'disabled t)\n")
105: (save-buffer)))
106:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.