|
|
1.1 ! root 1: ;; Handling of disabled commands ("novice mode") for Emacs. ! 2: ;; Copyright (C) 1985 Richard M. Stallman. ! 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 (autoloaded) ! 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: (princ "You have typed ") ! 32: (princ (key-description (this-command-keys))) ! 33: (princ ", invoking disabled command ") ! 34: (princ this-command) ! 35: (princ ":\n") ! 36: (princ (or (documentation this-command) "<< not documented >>")) ! 37: (princ "\n\n") ! 38: (princ "You can now type ! 39: Space to try the command just this once, ! 40: but leave it disabled, ! 41: Y to try it and enable it (no questions if you use it again), ! 42: N to do nothing (command remains disabled).")) ! 43: (message "Type y, n or Space: ") ! 44: (while (not (memq (setq char (downcase (read-char))) ! 45: '(? ?y ?n))) ! 46: (ding) ! 47: (message "Please type y, n or Space: "))) ! 48: (if (= char ?y) ! 49: (if (y-or-n-p "Enable command for future editing sessions also? ") ! 50: (enable-command this-command) ! 51: (put this-command 'disabled nil))) ! 52: (if (/= char ?n) ! 53: (call-interactively this-command)))) ! 54: ! 55: (defun enable-command (command) ! 56: "Allow COMMAND to be executed without special confirmation from now on. ! 57: The user's .emacs file is altered so that this will apply ! 58: to future sessions." ! 59: (interactive "CEnable command: ") ! 60: (put command 'disabled nil) ! 61: (save-excursion ! 62: (set-buffer (find-file-noselect (substitute-in-file-name "~/.emacs"))) ! 63: (goto-char (point-min)) ! 64: (if (search-forward (concat "(put '" (symbol-name command) " ") nil t) ! 65: (delete-region ! 66: (progn (beginning-of-line) (point)) ! 67: (progn (forward-line 1) (point))) ! 68: ;; Must have been disabled by default. ! 69: (goto-char (point-max)) ! 70: (insert "\n(put '" (symbol-name command) " 'disabled nil)\n")) ! 71: (setq foo (buffer-modified-p)) ! 72: (save-buffer))) ! 73: ! 74: (defun disable-command (command) ! 75: "Require special confirmation to execute COMMAND from now on. ! 76: The user's .emacs file is altered so that this will apply ! 77: to future sessions." ! 78: (interactive "CDisable command: ") ! 79: (put command 'disabled t) ! 80: (save-excursion ! 81: (set-buffer (find-file-noselect (substitute-in-file-name "~/.emacs"))) ! 82: (goto-char (point-min)) ! 83: (if (search-forward (concat "(put '" (symbol-name command) " ") nil t) ! 84: (delete-region ! 85: (progn (beginning-of-line) (point)) ! 86: (progn (forward-line 1) (point)))) ! 87: (goto-char (point-max)) ! 88: (insert "(put '" (symbol-name command) " 'disabled t)\n") ! 89: (save-buffer))) ! 90:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.