annotate lisp/prim/novice.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This mode provides a hook which is, by default, attached to various
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; putatively dangerous commands in a (probably futile) attempt to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; prevent lusers from shooting themselves in the feet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; This function is called (by autoloading)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; to handle any disabled command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; The command is found in this-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; and the keys are returned by (this-command-keys).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;(setq disabled-command-hook 'disabled-command-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun disabled-command-hook (&rest ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (let (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (let ((keys (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (if (or (equal keys []) ;XEmacs kludge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (eq (event-to-character (aref keys 0)) ?\r))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (princ "You have invoked the disabled command ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (princ "You have typed ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (princ (key-description keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (princ ", invoking disabled command ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (princ this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (princ ":\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; Print any special message saying why the command is disabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (if (stringp (get this-command 'disabled))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (princ (get this-command 'disabled)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (princ (or (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (documentation this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "<< not documented >>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; Keep only the first paragraph of the documentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (set-buffer "*Help*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (delete-region (1- (point)) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (princ "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (princ "You can now type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 Space to try the command just this once,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 but leave it disabled,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 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
76 N to do nothing (command remains disabled).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (help-mode)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (message "Type y, n or Space: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (let ((cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (while (null char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (if (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq event (next-command-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (or quit-flag (eq 'keyboard-quit (key-binding event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq quit-flag nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq quit-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (signal 'quit '())))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (let* ((key (and (key-press-event-p event) (event-key event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (rchar (and key (event-to-character event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if rchar (setq rchar (downcase rchar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (cond ((eq rchar ?y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq char rchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ((eq rchar ?n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (setq char rchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ((eq rchar ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq char rchar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (ding nil 'y-or-n-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (discard-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (message "Please type y, n or Space: ")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (message nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (= char ?y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (if (and user-init-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (not (string= "" user-init-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (y-or-n-p "Enable command for future editing sessions also? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (enable-command this-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (put this-command 'disabled nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if (/= char ?n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (call-interactively this-command))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defun enable-command (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "Allow COMMAND to be executed without special confirmation from now on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 The user's .emacs file is altered so that this will apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 to future sessions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (interactive "CEnable command: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (put command 'disabled nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (set-buffer (find-file-noselect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (substitute-in-file-name user-init-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (progn (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; Explicitly enable, in case this command is disabled by default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; or in case the code we deleted was actually a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (insert "\n(put '" (symbol-name command) " 'disabled nil)\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (save-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defun disable-command (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "Require special confirmation to execute COMMAND from now on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 The user's .emacs file is altered so that this will apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 to future sessions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (interactive "CDisable command: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (if (not (commandp command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (error "Invalid command name `%s'" command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (put command 'disabled t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (set-buffer (find-file-noselect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (substitute-in-file-name user-init-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (delete-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (progn (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (insert "\n(put '" (symbol-name command) " 'disabled t)\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (save-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;; novice.el ends here