comparison lisp/help.el @ 50565:cd863af50ea1

* help.el (describe-minor-mode): New function implementation. Accept both minor mode string and minor mode indicator. (describe-minor-mode-completion-table-for-indicator) (describe-minor-mode-completion-table-for-symbol): New functions. minor-mode-list is used here. (describe-minor-mode-from-symbol): renamed from (old) describe-minor-mode. Use describe-minor-mode-completion-table-for-symbol. Don't use eval. Just use symbol-name. (describe-minor-mode-from-indicator): Document is updated. Use `format-mode-line'. Use describe-minor-mode-from-symbol instead of describe-minor-mode. Use describe-minor-mode-completion-table-for-indicator. (expand-minor-mode-indicator-object): removed. (lookup-minor-mode-from-indicator): remove the fist white space from both indicator and anindicator before comparing them. * bindings.el (mode-line-major-mode-keymap) (mode-line-minor-mode-keymap): defined keys for the maps here in `defvar'.
author Masatake YAMATO <jet@gyve.org>
date Sat, 12 Apr 2003 17:28:24 +0000
parents e5761fbf195f
children 695cf19ef79e
comparison
equal deleted inserted replaced
50564:e634b5a332d1 50565:cd863af50ea1
610 (princ (documentation minor-mode))))) 610 (princ (documentation minor-mode)))))
611 (setq minor-modes (cdr minor-modes)))) 611 (setq minor-modes (cdr minor-modes))))
612 (print-help-return-message)))) 612 (print-help-return-message))))
613 613
614 (defun describe-minor-mode (minor-mode) 614 (defun describe-minor-mode (minor-mode)
615 "Display documentation of a minor mode given as MINOR-MODE." 615 "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"
616 (interactive (list (intern (completing-read 643 (interactive (list (intern (completing-read
617 "Minor mode: " 644 "Minor mode symbol: "
618 (delete nil (mapcar 645 (describe-minor-mode-completion-table-for-symbol)))))
619 (function (lambda (x) 646 (if (fboundp symbol)
620 (if (eval (car x)) 647 (describe-function symbol)
621 (symbol-name (car x))))) 648 (describe-variable symbol)))
622 minor-mode-alist)))))) 649
623 (if (fboundp minor-mode) 650 ;; indicator
624 (describe-function minor-mode) 651 (defun describe-minor-mode-completion-table-for-indicator ()
625 (describe-variable minor-mode))) 652 (delq nil
626 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)))
627 (defun describe-minor-mode-from-indicator (indicator) 664 (defun describe-minor-mode-from-indicator (indicator)
628 "Display documentation of a minor mode specified by INDICATOR." 665 "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."
629 (interactive (list 668 (interactive (list
630 (completing-read 669 (completing-read
631 "Minor mode indicator: " 670 "Minor mode indicator: "
632 (delete nil 671 (describe-minor-mode-completion-table-for-indicator))))
633 (mapcar
634 #'(lambda (x)
635 (if (eval (car x))
636 (let ((i (expand-minor-mode-indicator-object (cadr x))))
637 (if (and (< 0 (length i))
638 (string= " " (substring i 0 1)))
639 (substring i 1)
640 i))))
641 minor-mode-alist)))))
642 (let ((minor-mode (lookup-minor-mode-from-indicator indicator))) 672 (let ((minor-mode (lookup-minor-mode-from-indicator indicator)))
643 (if minor-mode 673 (if minor-mode
644 (describe-minor-mode minor-mode) 674 (describe-minor-mode-from-symbol minor-mode)
645 (error "Cannot find minor mode for `%s'" indicator)))) 675 (error "Cannot find minor mode for `%s'" indicator))))
646 676
647 (defun lookup-minor-mode-from-indicator (indicator) 677 (defun lookup-minor-mode-from-indicator (indicator)
648 "Return a minor mode symbol from its indicator on the modeline." 678 "Return a minor mode symbol from its indicator on the modeline."
679 ;; remove first space if existed
649 (if (and (< 0 (length indicator)) 680 (if (and (< 0 (length indicator))
650 (not (string= " " (substring indicator 0 1)))) 681 (eq (aref indicator 0) ?\ ))
651 (setq indicator (concat " " indicator))) 682 (setq indicator (substring indicator 1)))
652 (let ((minor-modes minor-mode-alist) 683 (let ((minor-modes minor-mode-alist)
653 result) 684 result)
654 (while minor-modes 685 (while minor-modes
655 (let* ((minor-mode (car (car minor-modes))) 686 (let* ((minor-mode (car (car minor-modes)))
656 (anindicator (car (cdr (car minor-modes))))) 687 (anindicator (format-mode-line
657 (setq anindicator (expand-minor-mode-indicator-object anindicator)) 688 (car (cdr (car minor-modes))))))
689 ;; remove first space if existed
658 (if (and (stringp anindicator) 690 (if (and (stringp anindicator)
659 (string= anindicator indicator)) 691 (> (length anindicator) 0)
692 (eq (aref anindicator 0) ?\ ))
693 (setq anindicator (substring anindicator 1)))
694 (if (equal indicator anindicator)
660 (setq result minor-mode 695 (setq result minor-mode
661 minor-modes nil) 696 minor-modes nil)
662 (setq minor-modes (cdr minor-modes))))) 697 (setq minor-modes (cdr minor-modes)))))
663 result)) 698 result))
664
665 (defun expand-minor-mode-indicator-object (obj)
666 "Expand OBJ that represents a minor-mode indicator.
667 cdr part of a `minor-mode-alist' element(indicator object) is the
668 indicator of minor mode that is in car part. Normally indicator
669 object is a string. However, in some case it is more compound object
670 like cons cell. This function tries to make the compound object a string."
671 ;; copied from describe-mode
672 (while (and obj (symbolp obj)
673 (boundp obj)
674 (not (eq obj (symbol-value obj))))
675 (setq obj (symbol-value obj)))
676 (when (and (consp obj)
677 (keywordp (car obj))
678 (eq :eval (car obj)))
679 (setq obj (eval (cadr obj))))
680 obj)
681 699
682 700
683 ;;; Automatic resizing of temporary buffers. 701 ;;; Automatic resizing of temporary buffers.
684 702
685 (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2)) 703 (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))