Mercurial > emacs
comparison lisp/apropos.el @ 54582:91f663907945
(apropos-mode): Don't autoload.
(apropos-symbols-internal): New fun. Extracted from `apropos'.
(apropos): Use it.
(apropos-print): Add optional `text' argument.
(apropos-describe-plist): Use help-buffer and hexlp-setup-xref.
Don't assume point-min == 1.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 26 Mar 2004 15:27:56 +0000 |
parents | 695cf19ef79e |
children | 5d7aec33a1ba |
comparison
equal
deleted
inserted
replaced
54581:0a5e192bf05d | 54582:91f663907945 |
---|---|
1 ;;; apropos.el --- apropos commands for users and programmers | 1 ;;; apropos.el --- apropos commands for users and programmers |
2 | 2 |
3 ;; Copyright (C) 1989, 1994, 1995, 2001, 2002, 2003 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1989,94,1995,2001,02,03,2004 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Joe Wells <jbw@bigbird.bu.edu> | 5 ;; Author: Joe Wells <jbw@bigbird.bu.edu> |
6 ;; Rewritten: Daniel Pfeiffer <occitan@esperanto.org> | 6 ;; Rewritten: Daniel Pfeiffer <occitan@esperanto.org> |
7 ;; Keywords: help | 7 ;; Keywords: help |
8 | 8 |
56 ;; from buffer in active window. | 56 ;; from buffer in active window. |
57 | 57 |
58 ;;; Code: | 58 ;;; Code: |
59 | 59 |
60 (require 'button) | 60 (require 'button) |
61 (eval-when-compile (require 'cl)) | |
61 | 62 |
62 (defgroup apropos nil | 63 (defgroup apropos nil |
63 "Apropos commands for users and programmers" | 64 "Apropos commands for users and programmers" |
64 :group 'help | 65 :group 'help |
65 :prefix "apropos") | 66 :prefix "apropos") |
346 | 347 |
347 (defun apropos-true-hit-doc (doc) | 348 (defun apropos-true-hit-doc (doc) |
348 "Return t if DOC is really matched by the current keywords." | 349 "Return t if DOC is really matched by the current keywords." |
349 (apropos-true-hit doc apropos-all-words)) | 350 (apropos-true-hit doc apropos-all-words)) |
350 | 351 |
351 ;;;###autoload | |
352 (define-derived-mode apropos-mode fundamental-mode "Apropos" | 352 (define-derived-mode apropos-mode fundamental-mode "Apropos" |
353 "Major mode for following hyperlinks in output of apropos commands. | 353 "Major mode for following hyperlinks in output of apropos commands. |
354 | 354 |
355 \\{apropos-mode-map}") | 355 \\{apropos-mode-map}") |
356 | 356 |
450 With optional prefix DO-ALL or if `apropos-do-all' is non-nil, also | 450 With optional prefix DO-ALL or if `apropos-do-all' is non-nil, also |
451 show unbound symbols and key bindings, which is a little more | 451 show unbound symbols and key bindings, which is a little more |
452 time-consuming. Returns list of symbols and documentation found." | 452 time-consuming. Returns list of symbols and documentation found." |
453 (interactive "sApropos symbol (regexp or words): \nP") | 453 (interactive "sApropos symbol (regexp or words): \nP") |
454 (setq apropos-regexp (apropos-rewrite-regexp apropos-regexp)) | 454 (setq apropos-regexp (apropos-rewrite-regexp apropos-regexp)) |
455 (setq apropos-accumulator | 455 (apropos-symbols-internal |
456 (apropos-internal apropos-regexp | 456 (apropos-internal apropos-regexp |
457 (and (not do-all) | 457 (and (not do-all) |
458 (not apropos-do-all) | 458 (not apropos-do-all) |
459 (lambda (symbol) | 459 (lambda (symbol) |
460 (or (fboundp symbol) | 460 (or (fboundp symbol) |
461 (boundp symbol) | 461 (boundp symbol) |
462 (facep symbol) | 462 (facep symbol) |
463 (symbol-plist symbol)))))) | 463 (symbol-plist symbol))))) |
464 (let ((tem apropos-accumulator)) | 464 (or do-all apropos-do-all))) |
465 (while tem | 465 |
466 (if (get (car tem) 'apropos-inhibit) | 466 (defun apropos-symbols-internal (symbols keys &optional text) |
467 (setq apropos-accumulator (delq (car tem) apropos-accumulator))) | 467 ;; Filter out entries that are marked as apropos-inhibit. |
468 (setq tem (cdr tem)))) | 468 (let ((all nil)) |
469 (let ((p apropos-accumulator) | 469 (dolist (symbol symbols) |
470 symbol doc properties) | 470 (unless (get symbol 'apropos-inhibit) |
471 (while p | 471 (push symbol all))) |
472 (setcar p (list | 472 (setq symbols all)) |
473 (setq symbol (car p)) | 473 (let ((apropos-accumulator |
474 (apropos-score-symbol symbol) | 474 (mapcar |
475 (when (fboundp symbol) | 475 (lambda (symbol) |
476 (if (setq doc (condition-case nil | 476 (let (doc properties) |
477 (documentation symbol t) | 477 (list |
478 (void-function | 478 symbol |
479 "(alias for undefined function)") | 479 (apropos-score-symbol symbol) |
480 (error | 480 (when (fboundp symbol) |
481 "(error retrieving function documentation)"))) | 481 (if (setq doc (condition-case nil |
482 (substring doc 0 (string-match "\n" doc)) | 482 (documentation symbol t) |
483 "(not documented)")) | 483 (void-function |
484 (when (boundp symbol) | 484 "(alias for undefined function)") |
485 (apropos-documentation-property | 485 (error |
486 "(can't retrieve function documentation)"))) | |
487 (substring doc 0 (string-match "\n" doc)) | |
488 "(not documented)")) | |
489 (when (boundp symbol) | |
490 (apropos-documentation-property | |
486 symbol 'variable-documentation t)) | 491 symbol 'variable-documentation t)) |
487 (when (setq properties (symbol-plist symbol)) | 492 (when (setq properties (symbol-plist symbol)) |
488 (setq doc (list (car properties))) | 493 (setq doc (list (car properties))) |
489 (while (setq properties (cdr (cdr properties))) | 494 (while (setq properties (cdr (cdr properties))) |
490 (setq doc (cons (car properties) doc))) | 495 (setq doc (cons (car properties) doc))) |
491 (mapconcat #'symbol-name (nreverse doc) " ")) | 496 (mapconcat #'symbol-name (nreverse doc) " ")) |
492 (when (get symbol 'widget-type) | 497 (when (get symbol 'widget-type) |
493 (apropos-documentation-property | 498 (apropos-documentation-property |
494 symbol 'widget-documentation t)) | 499 symbol 'widget-documentation t)) |
495 (when (facep symbol) | 500 (when (facep symbol) |
501 (apropos-documentation-property | |
502 symbol 'face-documentation t)) | |
503 (when (get symbol 'custom-group) | |
496 (apropos-documentation-property | 504 (apropos-documentation-property |
497 symbol 'face-documentation t)) | 505 symbol 'group-documentation t))))) |
498 (when (get symbol 'custom-group) | 506 symbols))) |
499 (apropos-documentation-property | 507 (apropos-print keys nil text))) |
500 symbol 'group-documentation t)))) | |
501 (setq p (cdr p)))) | |
502 (apropos-print | |
503 (or do-all apropos-do-all) | |
504 nil)) | |
505 | 508 |
506 | 509 |
507 ;;;###autoload | 510 ;;;###autoload |
508 (defun apropos-value (apropos-regexp &optional do-all) | 511 (defun apropos-value (apropos-regexp &optional do-all) |
509 "Show all symbols whose value's printed image matches APROPOS-REGEXP. | 512 "Show all symbols whose value's printed image matches APROPOS-REGEXP. |
753 (if (integerp function) | 756 (if (integerp function) |
754 nil | 757 nil |
755 function)) | 758 function)) |
756 | 759 |
757 | 760 |
758 (defun apropos-print (do-keys spacing) | 761 (defun apropos-print (do-keys spacing &optional text) |
759 "Output result of apropos searching into buffer `*Apropos*'. | 762 "Output result of apropos searching into buffer `*Apropos*'. |
760 The value of `apropos-accumulator' is the list of items to output. | 763 The value of `apropos-accumulator' is the list of items to output. |
761 Each element should have the format | 764 Each element should have the format |
762 (SYMBOL SCORE FN-DOC VAR-DOC [PLIST-DOC WIDGET-DOC FACE-DOC GROUP-DOC]). | 765 (SYMBOL SCORE FN-DOC VAR-DOC [PLIST-DOC WIDGET-DOC FACE-DOC GROUP-DOC]). |
763 The return value is the list that was in `apropos-accumulator', sorted | 766 The return value is the list that was in `apropos-accumulator', sorted |
764 alphabetically by symbol name; but this function also sets | 767 alphabetically by symbol name; but this function also sets |
765 `apropos-accumulator' to nil before returning. | 768 `apropos-accumulator' to nil before returning. |
766 | 769 |
767 If SPACING is non-nil, it should be a string; | 770 If SPACING is non-nil, it should be a string; separate items with that string. |
768 separate items with that string." | 771 If non-nil TEXT is a string that will be printed as a heading." |
769 (if (null apropos-accumulator) | 772 (if (null apropos-accumulator) |
770 (message "No apropos matches for `%s'" apropos-orig-regexp) | 773 (message "No apropos matches for `%s'" apropos-orig-regexp) |
771 (setq apropos-accumulator | 774 (setq apropos-accumulator |
772 (sort apropos-accumulator | 775 (sort apropos-accumulator |
773 (lambda (a b) | 776 (lambda (a b) |
792 "get more information.\n")) | 795 "get more information.\n")) |
793 (insert "In this buffer, go to the name of the command, or function," | 796 (insert "In this buffer, go to the name of the command, or function," |
794 " or variable,\n" | 797 " or variable,\n" |
795 (substitute-command-keys | 798 (substitute-command-keys |
796 "and type \\[apropos-follow] to get full documentation.\n\n")) | 799 "and type \\[apropos-follow] to get full documentation.\n\n")) |
800 (if text (insert text "\n\n")) | |
797 (while (consp p) | 801 (while (consp p) |
798 (when (and spacing (not (bobp))) | 802 (when (and spacing (not (bobp))) |
799 (princ spacing)) | 803 (princ spacing)) |
800 (setq apropos-item (car p) | 804 (setq apropos-item (car p) |
801 symbol (car apropos-item) | 805 symbol (car apropos-item) |
905 (error "There is nothing to follow here")))) | 909 (error "There is nothing to follow here")))) |
906 | 910 |
907 | 911 |
908 (defun apropos-describe-plist (symbol) | 912 (defun apropos-describe-plist (symbol) |
909 "Display a pretty listing of SYMBOL's plist." | 913 "Display a pretty listing of SYMBOL's plist." |
910 (with-output-to-temp-buffer "*Help*" | 914 (help-setup-xref (list 'apropos-describe-plist symbol) (interactive-p)) |
915 (with-output-to-temp-buffer (help-buffer) | |
911 (set-buffer standard-output) | 916 (set-buffer standard-output) |
912 (princ "Symbol ") | 917 (princ "Symbol ") |
913 (prin1 symbol) | 918 (prin1 symbol) |
914 (princ "'s plist is\n (") | 919 (princ "'s plist is\n (") |
915 (if apropos-symbol-face | 920 (if apropos-symbol-face |
916 (put-text-property 8 (- (point) 14) 'face apropos-symbol-face)) | 921 (put-text-property (+ (point-min) 7) (- (point) 14) |
922 'face apropos-symbol-face)) | |
917 (insert (apropos-format-plist symbol "\n ")) | 923 (insert (apropos-format-plist symbol "\n ")) |
918 (princ ")") | 924 (princ ")") |
919 (print-help-return-message))) | 925 (print-help-return-message))) |
920 | 926 |
921 | 927 |