emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: disable-command (Re: [PATCH] Show/Hide menu)


From: Richard Stallman
Subject: Re: disable-command (Re: [PATCH] Show/Hide menu)
Date: Fri, 1 Feb 2002 07:04:15 -0700 (MST)

What do you think of this version?

(defun disabled-command-hook (&rest ignore)
  (let (char)
    (save-window-excursion
     (with-output-to-temp-buffer "*Help*"
       (let ((keys (this-command-keys)))
         (if (or (eq (aref keys 0)
                     (if (stringp keys)
                         (aref "\M-x" 0)
                       ?\M-x))
                 (and (>= (length keys) 2)
                      (eq (aref keys 0) meta-prefix-char)
                      (eq (aref keys 1) ?x)))
             (princ "You have invoked the disabled command ")
           (princ "You have typed ")
           (princ (key-description keys))
           (princ ", invoking disabled command ")))
       (princ this-command)
       (princ ".\n")
       ;; Print any special message saying why the command is disabled.
       (if (stringp (get this-command 'disabled))
           (princ (get this-command 'disabled))
         (princ "It is disabled because new users often find it confusing.\n")
         (princ "Here's the first part of its description:\n\n")
         ;; Keep only the first paragraph of the documentation.
         (with-current-buffer "*Help*"
           (goto-char (point-max))
           (let ((start (point)))
             (save-excursion
               (princ (or (condition-case ()
                              (documentation this-command)
                            (error nil))
                          "<< not documented >>")))
             (if (search-forward "\n\n" nil t)
                 (delete-region (match-beginning 0) (point-max)))
             (goto-char (point-max))
             (indent-rigidly start (point) 3))))
       (princ "\n\nDo you want to use this command anyway?\n\n")
       (princ "You can now type
Y   to try it and enable it (no questions if you use it again).
N   to cancel--don't try the command and it remains disabled.
SPC to try the command just this once, but leave it disabled.
!   to try it, and enable all disabled commands for this session only.")
       (save-excursion
        (set-buffer standard-output)
        (help-mode)))
     (message "Type y, n, ! or Space: ")
     (let ((cursor-in-echo-area t))
       (while (not (memq (setq char (downcase (read-char)))
                         '(?! ?  ?y ?n)))
         (ding)
         (message "Please type y, n, ! or Space: "))))
    (if (= char ?!)
        (setq disabled-command-hook nil))
    (if (= char ?y)
        (if (and user-init-file
                 (not (string= "" user-init-file))
                 (y-or-n-p "Enable command for future editing sessions also? "))
            (enable-command this-command)
          (put this-command 'disabled nil)))
    (if (/= char ?n)
        (call-interactively this-command))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]