aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2009-11-15 05:12:52 +0000
committerStefan Monnier2009-11-15 05:12:52 +0000
commit8d720a006679b8f443757cb8c8cc32fe676a4fb7 (patch)
tree1e23554cf6756ffa94f2879365b3cd4b9af2bd36 /lisp
parent68a1b09056bff25c640fff096448649e1cb8e411 (diff)
downloademacs-8d720a006679b8f443757cb8c8cc32fe676a4fb7.tar.gz
emacs-8d720a006679b8f443757cb8c8cc32fe676a4fb7.zip
(disabled-command-function): Add useful args.
Setup the help buffer so that [back] works. Remove redundant call to help-mode. (disabled-command-function): Use `case'. (en/disable-command): New function extracted from enable-command. (enable-command, disable-command): Use it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/novice.el106
2 files changed, 53 insertions, 62 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7f6b73be406..c4dddab05c6 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12009-11-15 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * novice.el (disabled-command-function): Add useful args.
4 Setup the help buffer so that [back] works.
5 Remove redundant call to help-mode.
6 (disabled-command-function): Use `case'.
7 (en/disable-command): New function extracted from enable-command.
8 (enable-command, disable-command): Use it.
9
12009-11-14 Glenn Morris <rgm@gnu.org> 102009-11-14 Glenn Morris <rgm@gnu.org>
2 11
3 * menu-bar.el (menu-bar-tools-menu): Read and send mail entries are not 12 * menu-bar.el (menu-bar-tools-menu): Read and send mail entries are not
diff --git a/lisp/novice.el b/lisp/novice.el
index 963247dc40a..048e796509e 100644
--- a/lisp/novice.el
+++ b/lisp/novice.el
@@ -34,6 +34,8 @@
34;; The command is found in this-command 34;; The command is found in this-command
35;; and the keys are returned by (this-command-keys). 35;; and the keys are returned by (this-command-keys).
36 36
37(eval-when-compile (require 'cl))
38
37;;;###autoload 39;;;###autoload
38(defvar disabled-command-function 'disabled-command-function 40(defvar disabled-command-function 'disabled-command-function
39 "Function to call to handle disabled commands. 41 "Function to call to handle disabled commands.
@@ -45,11 +47,13 @@ If nil, the feature is disabled, i.e., all commands work normally.")
45;; It is ok here to assume that this-command is a symbol 47;; It is ok here to assume that this-command is a symbol
46;; because we won't get called otherwise. 48;; because we won't get called otherwise.
47;;;###autoload 49;;;###autoload
48(defun disabled-command-function (&rest ignore) 50(defun disabled-command-function (&optional cmd keys)
51 (unless cmd (setq cmd this-command))
52 (unless keys (setq keys (this-command-keys)))
49 (let (char) 53 (let (char)
50 (save-window-excursion 54 (save-window-excursion
51 (with-output-to-temp-buffer "*Disabled Command*" 55 (help-setup-xref (list 'disabled-command-function cmd keys) nil)
52 (let ((keys (this-command-keys))) 56 (with-output-to-temp-buffer "*Disabled Command*" ;; (help-buffer)
53 (if (or (eq (aref keys 0) 57 (if (or (eq (aref keys 0)
54 (if (stringp keys) 58 (if (stringp keys)
55 (aref "\M-x" 0) 59 (aref "\M-x" 0)
@@ -57,22 +61,21 @@ If nil, the feature is disabled, i.e., all commands work normally.")
57 (and (>= (length keys) 2) 61 (and (>= (length keys) 2)
58 (eq (aref keys 0) meta-prefix-char) 62 (eq (aref keys 0) meta-prefix-char)
59 (eq (aref keys 1) ?x))) 63 (eq (aref keys 1) ?x)))
60 (princ (format "You have invoked the disabled command %s.\n" 64 (princ (format "You have invoked the disabled command %s.\n" cmd))
61 (symbol-name this-command)))
62 (princ (format "You have typed %s, invoking disabled command %s.\n" 65 (princ (format "You have typed %s, invoking disabled command %s.\n"
63 (key-description keys) (symbol-name this-command))))) 66 (key-description keys) cmd)))
64 ;; Print any special message saying why the command is disabled. 67 ;; Print any special message saying why the command is disabled.
65 (if (stringp (get this-command 'disabled)) 68 (if (stringp (get cmd 'disabled))
66 (princ (get this-command 'disabled)) 69 (princ (get cmd 'disabled))
67 (princ "It is disabled because new users often find it confusing.\n") 70 (princ "It is disabled because new users often find it confusing.\n")
68 (princ "Here's the first part of its description:\n\n") 71 (princ "Here's the first part of its description:\n\n")
69 ;; Keep only the first paragraph of the documentation. 72 ;; Keep only the first paragraph of the documentation.
70 (with-current-buffer "*Disabled Command*" 73 (with-current-buffer "*Disabled Command*" ;; standard-output
71 (goto-char (point-max)) 74 (goto-char (point-max))
72 (let ((start (point))) 75 (let ((start (point)))
73 (save-excursion 76 (save-excursion
74 (princ (or (condition-case () 77 (princ (or (condition-case ()
75 (documentation this-command) 78 (documentation cmd)
76 (error nil)) 79 (error nil))
77 "<< not documented >>"))) 80 "<< not documented >>")))
78 (if (search-forward "\n\n" nil t) 81 (if (search-forward "\n\n" nil t)
@@ -85,8 +88,10 @@ y to try it and enable it (no questions if you use it again).
85n to cancel--don't try the command, and it remains disabled. 88n to cancel--don't try the command, and it remains disabled.
86SPC to try the command just this once, but leave it disabled. 89SPC to try the command just this once, but leave it disabled.
87! to try it, and enable all disabled commands for this session only.") 90! to try it, and enable all disabled commands for this session only.")
88 (with-current-buffer standard-output 91 ;; Redundant since with-output-to-temp-buffer will do it anyway.
89 (help-mode))) 92 ;; (with-current-buffer standard-output
93 ;; (help-mode))
94 )
90 (fit-window-to-buffer (get-buffer-window "*Disabled Command*")) 95 (fit-window-to-buffer (get-buffer-window "*Disabled Command*"))
91 (message "Type y, n, ! or SPC (the space bar): ") 96 (message "Type y, n, ! or SPC (the space bar): ")
92 (let ((cursor-in-echo-area t)) 97 (let ((cursor-in-echo-area t))
@@ -97,31 +102,26 @@ SPC to try the command just this once, but leave it disabled.
97 (ding) 102 (ding)
98 (message "Please type y, n, ! or SPC (the space bar): ")))) 103 (message "Please type y, n, ! or SPC (the space bar): "))))
99 (setq char (downcase char)) 104 (setq char (downcase char))
100 (if (= char ?\C-g) 105 (case char
101 (setq quit-flag t)) 106 (?\C-g (setq quit-flag t))
102 (if (= char ?!) 107 (?! (setq disabled-command-function nil))
103 (setq disabled-command-function nil)) 108 (?y
104 (if (= char ?y)
105 (if (and user-init-file 109 (if (and user-init-file
106 (not (string= "" user-init-file)) 110 (not (string= "" user-init-file))
107 (y-or-n-p "Enable command for future editing sessions also? ")) 111 (y-or-n-p "Enable command for future editing sessions also? "))
108 (enable-command this-command) 112 (enable-command cmd)
109 (put this-command 'disabled nil))) 113 (put cmd 'disabled nil)))
110 (if (/= char ?n) 114 (?n nil)
111 (call-interactively this-command)))) 115 (t (call-interactively cmd)))))
112 116
113;;;###autoload 117(defun en/disable-command (command disable)
114(defun enable-command (command) 118 (unless (commandp command)
115 "Allow COMMAND to be executed without special confirmation from now on. 119 (error "Invalid command name `%s'" command))
116COMMAND must be a symbol. 120 (put command 'disabled disable)
117This command alters the user's .emacs file so that this will apply
118to future sessions."
119 (interactive "CEnable command: ")
120 (put command 'disabled nil)
121 (let ((init-file user-init-file) 121 (let ((init-file user-init-file)
122 (default-init-file 122 (default-init-file
123 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs"))) 123 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
124 (when (null init-file) 124 (unless init-file
125 (if (or (file-exists-p default-init-file) 125 (if (or (file-exists-p default-init-file)
126 (and (eq system-type 'windows-nt) 126 (and (eq system-type 'windows-nt)
127 (file-exists-p "~/_emacs"))) 127 (file-exists-p "~/_emacs")))
@@ -144,46 +144,28 @@ to future sessions."
144 ;; Explicitly enable, in case this command is disabled by default 144 ;; Explicitly enable, in case this command is disabled by default
145 ;; or in case the code we deleted was actually a comment. 145 ;; or in case the code we deleted was actually a comment.
146 (goto-char (point-max)) 146 (goto-char (point-max))
147 (insert "\n(put '" (symbol-name command) " 'disabled nil)\n") 147 (unless (bolp) (newline))
148 (insert "(put '" (symbol-name command) " 'disabled "
149 (symbol-name disable) ")\n")
148 (save-buffer)))) 150 (save-buffer))))
149 151
150;;;###autoload 152;;;###autoload
153(defun enable-command (command)
154 "Allow COMMAND to be executed without special confirmation from now on.
155COMMAND must be a symbol.
156This command alters the user's .emacs file so that this will apply
157to future sessions."
158 (interactive "CEnable command: ")
159 (en/disable-command command nil))
160
161;;;###autoload
151(defun disable-command (command) 162(defun disable-command (command)
152 "Require special confirmation to execute COMMAND from now on. 163 "Require special confirmation to execute COMMAND from now on.
153COMMAND must be a symbol. 164COMMAND must be a symbol.
154This command alters the user's .emacs file so that this will apply 165This command alters the user's .emacs file so that this will apply
155to future sessions." 166to future sessions."
156 (interactive "CDisable command: ") 167 (interactive "CDisable command: ")
157 (if (not (commandp command)) 168 (en/disable-command command t))
158 (error "Invalid command name `%s'" command))
159 (put command 'disabled t)
160 (let ((init-file user-init-file)
161 (default-init-file
162 (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs")))
163 (when (null init-file)
164 (if (or (file-exists-p default-init-file)
165 (and (eq system-type 'windows-nt)
166 (file-exists-p "~/_emacs")))
167 ;; Started with -q, i.e. the file containing
168 ;; enabled/disabled commands hasn't been read. Saving
169 ;; settings there would overwrite other settings.
170 (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
171 (setq init-file default-init-file)
172 (if (and (not (file-exists-p init-file))
173 (eq system-type 'windows-nt)
174 (file-exists-p "~/_emacs"))
175 (setq init-file "~/_emacs")))
176 (with-current-buffer (find-file-noselect
177 (substitute-in-file-name init-file))
178 (goto-char (point-min))
179 (if (search-forward (concat "(put '" (symbol-name command) " ") nil t)
180 (delete-region
181 (progn (beginning-of-line) (point))
182 (progn (forward-line 1) (point)))
183 (goto-char (point-max))
184 (insert ?\n))
185 (insert "(put '" (symbol-name command) " 'disabled t)\n")
186 (save-buffer))))
187 169
188(provide 'novice) 170(provide 'novice)
189 171