home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / msdos / demacs / lisp / novice.el < prev    next >
Encoding:
Text File  |  1991-11-11  |  4.2 KB  |  113 lines

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