/[emacs]/emacs/lisp/help.el
ViewVC logotype

Diff of /emacs/lisp/help.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.258 by lektu, Mon Mar 31 20:22:58 2003 UTC revision 1.259 by jet, Sat Apr 12 17:28:23 2003 UTC
# Line 612  For minor modes, see following pages.\n\ Line 612  For minor modes, see following pages.\n\
612        (print-help-return-message))))        (print-help-return-message))))
613    
614  (defun describe-minor-mode (minor-mode)  (defun describe-minor-mode (minor-mode)
615    "Display documentation of a minor mode given as MINOR-MODE."    "Display documentation of a minor mode given as MINOR-MODE.
616    MINOR-MODE can be a minor mode symbol or a minor mode indicator string
617    appeared on the mode-line."
618      (interactive (list (completing-read
619                          "Minor mode: "
620                                  (nconc
621                                   (describe-minor-mode-completion-table-for-symbol)
622                                   (describe-minor-mode-completion-table-for-indicator)
623                                   ))))
624      (if (symbolp minor-mode)
625          (setq minor-mode (symbol-name minor-mode)))
626      (let ((symbols (describe-minor-mode-completion-table-for-symbol))
627            (indicators (describe-minor-mode-completion-table-for-indicator)))
628        (cond
629         ((member minor-mode symbols)
630          (describe-minor-mode-from-symbol (intern minor-mode)))
631         ((member minor-mode indicators)
632          (describe-minor-mode-from-indicator minor-mode))
633         (t
634          (error "No such minor mode: %s" minor-mode)))))
635    
636    ;; symbol    
637    (defun describe-minor-mode-completion-table-for-symbol ()
638      ;; In order to list up all minor modes, minor-mode-list
639      ;; is used here instead of minor-mode-alist.
640      (delq nil (mapcar 'symbol-name minor-mode-list)))
641    (defun describe-minor-mode-from-symbol (symbol)
642      "Display documentation of a minor mode given as a symbol, SYMBOL"
643    (interactive (list (intern (completing-read    (interactive (list (intern (completing-read
644                                "Minor mode: "                                "Minor mode symbol: "
645                                (delete nil (mapcar                                (describe-minor-mode-completion-table-for-symbol)))))
646                                             (function (lambda (x)    (if (fboundp symbol)
647                                                         (if (eval (car x))        (describe-function symbol)
648                                                             (symbol-name (car x)))))      (describe-variable symbol)))
                                            minor-mode-alist))))))  
   (if (fboundp minor-mode)  
       (describe-function minor-mode)  
     (describe-variable minor-mode)))  
649    
650    ;; indicator
651    (defun describe-minor-mode-completion-table-for-indicator ()
652      (delq nil
653            (mapcar (lambda (x)
654                      (let ((i (format-mode-line x)))
655                        ;; remove first space if existed
656                        (cond
657                         ((= 0 (length i))
658                          nil)
659                         ((eq (aref i 0) ?\ )
660                          (substring i 1))
661                         (t
662                          i))))
663                    minor-mode-alist)))
664  (defun describe-minor-mode-from-indicator (indicator)  (defun describe-minor-mode-from-indicator (indicator)
665    "Display documentation of a minor mode specified by INDICATOR."    "Display documentation of a minor mode specified by INDICATOR.
666    If you call this function interactively, you can give indicator which
667    is currently activated with completion."
668    (interactive (list    (interactive (list
669                  (completing-read                  (completing-read
670                   "Minor mode indicator: "                   "Minor mode indicator: "
671                   (delete nil                   (describe-minor-mode-completion-table-for-indicator))))
                          (mapcar  
                           #'(lambda (x)  
                               (if (eval (car x))  
                                   (let ((i (expand-minor-mode-indicator-object (cadr x))))  
                                     (if (and (< 0 (length i))  
                                              (string= " " (substring i 0 1)))  
                                         (substring i 1)  
                                       i))))  
                           minor-mode-alist)))))  
672    (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))    (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
673      (if minor-mode      (if minor-mode
674          (describe-minor-mode minor-mode)          (describe-minor-mode-from-symbol minor-mode)
675        (error "Cannot find minor mode for `%s'" indicator))))        (error "Cannot find minor mode for `%s'" indicator))))
676    
677  (defun lookup-minor-mode-from-indicator (indicator)  (defun lookup-minor-mode-from-indicator (indicator)
678    "Return a minor mode symbol from its indicator on the modeline."    "Return a minor mode symbol from its indicator on the modeline."
679      ;; remove first space if existed
680    (if (and (< 0 (length indicator))    (if (and (< 0 (length indicator))
681             (not (string= " " (substring indicator 0 1))))             (eq (aref indicator 0) ?\ ))
682        (setq indicator (concat " " indicator)))        (setq indicator (substring indicator 1)))
683    (let ((minor-modes minor-mode-alist)    (let ((minor-modes minor-mode-alist)
684          result)          result)
685      (while minor-modes      (while minor-modes
686        (let* ((minor-mode (car (car minor-modes)))        (let* ((minor-mode (car (car minor-modes)))
687               (anindicator (car (cdr (car minor-modes)))))               (anindicator (format-mode-line
688          (setq anindicator (expand-minor-mode-indicator-object anindicator))                             (car (cdr (car minor-modes))))))
689            ;; remove first space if existed
690          (if (and (stringp anindicator)          (if (and (stringp anindicator)
691                   (string= anindicator indicator))                   (> (length anindicator) 0)
692                     (eq (aref anindicator 0) ?\ ))
693                (setq anindicator (substring anindicator 1)))
694            (if (equal indicator anindicator)
695              (setq result minor-mode              (setq result minor-mode
696                    minor-modes nil)                    minor-modes nil)
697            (setq minor-modes (cdr minor-modes)))))            (setq minor-modes (cdr minor-modes)))))
698      result))      result))
699    
 (defun expand-minor-mode-indicator-object (obj)  
   "Expand OBJ that represents a minor-mode indicator.  
 cdr part of a `minor-mode-alist' element(indicator object) is the  
 indicator of minor mode that is in car part.  Normally indicator  
 object is a string. However, in some case it is more compound object  
 like cons cell. This function tries to make the compound object a string."  
   ;; copied from describe-mode  
   (while (and obj (symbolp obj)  
               (boundp obj)  
               (not (eq obj (symbol-value obj))))  
     (setq obj (symbol-value obj)))  
   (when (and (consp obj)  
              (keywordp (car obj))  
              (eq :eval (car obj)))  
     (setq obj (eval (cadr obj))))  
   obj)  
   
700    
701  ;;; Automatic resizing of temporary buffers.  ;;; Automatic resizing of temporary buffers.
702    

Legend:
Removed from v.1.258  
changed lines
  Added in v.1.259

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26