annotate lisp/prim/novice.el @ 36:c53a95d3c46d r19-15b101

Import from CVS: tag r19-15b101
author cvs
date Mon, 13 Aug 2007 08:53:38 +0200
parents b82b59fe008d
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; novice.el --- handling of disabled commands ("novice mode") for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: internal, help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; This mode provides a hook which is, by default, attached to various
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; putatively dangerous commands in a (probably futile) attempt to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; prevent lusers from shooting themselves in the feet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; This function is called (by autoloading)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; to handle any disabled command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; The command is found in this-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; and the keys are returned by (this-command-keys).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;(setq disabled-command-hook 'disabled-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defun disabled-command-hook (&rest ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (let (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (let ((keys (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (if (or (equal keys []) ;XEmacs kludge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (eq (event-to-character (aref keys 0)) ?\r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (princ "You have invoked the disabled command ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (princ "You have typed ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (princ (key-description keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (princ ", invoking disabled command ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (princ this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (princ ":\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; Print any special message saying why the command is disabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (if (stringp (get this-command 'disabled))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (princ (get this-command 'disabled)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (princ (or (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (documentation this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "<< not documented >>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; Keep only the first paragraph of the documentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (set-buffer "*Help*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (delete-region (1- (point)) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (princ "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (princ "You can now type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 Space to try the command just this once,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 but leave it disabled,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 Y to try it and enable it (no questions if you use it again),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 N to do nothing (command remains disabled).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (help-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (message "Type y, n or Space: ")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
82 ; (let ((cursor-in-echo-area t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
83 ; (while (not (memq (setq char (downcase (read-char)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
84 ; '(? ?y ?n)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
85 ; (ding)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
86 ; (message "Please type y, n or Space: "))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
87 ;; XEmacs version
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (let ((cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (while (null char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (setq event (next-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (or quit-flag (eq 'keyboard-quit (key-binding event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (setq quit-flag nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (setq quit-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (signal 'quit '())))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (let* ((key (and (key-press-event-p event) (event-key event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (rchar (and key (event-to-character event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if rchar (setq rchar (downcase rchar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (cond ((eq rchar ?y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq char rchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ((eq rchar ?n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (setq char rchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ((eq rchar ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq char rchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (ding nil 'y-or-n-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (discard-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (message "Please type y, n or Space: ")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (message nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (= char ?y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (if (and user-init-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (not (string= "" user-init-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (y-or-n-p "Enable command for future editing sessions also? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (enable-command this-command)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
119 (put this-command 'disabled nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (if (/= char ?n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (call-interactively this-command))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defun enable-command (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 "Allow COMMAND to be executed without special confirmation from now on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 The user's .emacs file is altered so that this will apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 to future sessions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (interactive "CEnable command: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (put command 'disabled nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (set-buffer (find-file-noselect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (substitute-in-file-name user-init-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (progn (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; Explicitly enable, in case this command is disabled by default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; or in case the code we deleted was actually a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (insert "\n(put '" (symbol-name command) " 'disabled nil)\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (save-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defun disable-command (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Require special confirmation to execute COMMAND from now on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 The user's .emacs file is altered so that this will apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 to future sessions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (interactive "CDisable command: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (not (commandp command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (error "Invalid command name `%s'" command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (put command 'disabled t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (set-buffer (find-file-noselect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (substitute-in-file-name user-init-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (progn (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (insert "\n(put '" (symbol-name command) " 'disabled t)\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (save-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;; novice.el ends here