emacs-devel
[Top][All Lists]
Advanced

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

Re: describe-mode should first summarize all modes in effect


From: Richard Stallman
Subject: Re: describe-mode should first summarize all modes in effect
Date: Mon, 29 Sep 2003 15:32:27 -0400

What do you think of this version?

(defun describe-mode (&optional buffer)
  "Display documentation of current major mode and minor modes.
The major mode description comes first, followed by the minor modes,
each on a separate page.
For this to work correctly for a minor mode, the mode's indicator variable
\(listed in `minor-mode-alist') must also be a function whose documentation
describes the minor mode."
  (interactive)
  (help-setup-xref (list #'describe-mode (or buffer (current-buffer)))
                   (interactive-p))
  ;; For the sake of help-do-xref and help-xref-go-back,
  ;; don't switch buffers before calling `help-buffer'.
  (with-output-to-temp-buffer (help-buffer)
    (save-excursion
      (when buffer (set-buffer buffer))
      (let (minor-modes)
        ;; Find enabled minor mode we will want to mention.
        (dolist (mode minor-mode-list)
          ;; Document a minor mode if it is listed in minor-mode-alist,
          ;; non-nil, and has a function definition.
          (and (boundp mode) (symbol-value mode)
               (fboundp mode)
               (let ((pretty-minor-mode mode)
                     indicator)
                 (if (string-match "\\(-minor\\)?-mode\\'"
                                   (symbol-name mode))
                     (setq pretty-minor-mode
                           (capitalize
                            (substring (symbol-name mode)
                                       0 (match-beginning 0)))))
                 (setq indicator (cadr (assq mode minor-mode-alist)))
                 (while (and indicator (symbolp indicator)
                             (boundp indicator)
                             (not (eq indicator (symbol-value indicator))))
                   (setq indicator (symbol-value indicator)))
                 (push (list pretty-minor-mode mode indicator)
                       minor-modes))))
        (if auto-fill-function
            (push '("Auto Fill" auto-fill-mode " Fill")
                  minor-modes))
        (setq minor-modes
              (sort minor-modes
                    (lambda (a b) (string-lessp (car a) (car b)))))
        (when minor-modes
          (princ "Summary of minor modes:\n")
          (dolist (mode minor-modes)
            (let ((pretty-minor-mode (nth 0 mode))
                  (indicator (nth 2 mode)))
              (princ (format "  %s minor mode (%s):\n"
                             pretty-minor-mode
                             (if indicator
                                 (format "indicator%s" indicator)
                               "no indicator")))))
          (princ "\n(Full information about these minor modes
follows the description of the major mode.)\n\n"))
        ;; Document the major mode.
        (princ mode-name)
        (princ " mode:\n")
        (princ (documentation major-mode))
        ;; Document the minor modes fully.
        (dolist (mode minor-modes)
          (let ((pretty-minor-mode (nth 0 mode))
                (mode-function (nth 1 mode))
                (indicator (nth 2 mode)))
            (princ "\n\f\n")
            (princ (format "%s minor mode (%s):\n"
                           pretty-minor-mode
                           (if indicator
                               (format "indicator%s" indicator)
                             "no indicator")))
            (princ (documentation mode-function)))))
      (print-help-return-message))))




reply via email to

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