aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2002-05-23 20:21:30 +0000
committerKim F. Storm2002-05-23 20:21:30 +0000
commitd2b30292673a1eb6d4a0b22b23040d30ecc9c560 (patch)
treee8afa7db7f187af2c38ad6421f2976e5b30740f5
parent01b886b76e4fd6b0889163b96b3b45c6ddad7ceb (diff)
downloademacs-d2b30292673a1eb6d4a0b22b23040d30ecc9c560.tar.gz
emacs-d2b30292673a1eb6d4a0b22b23040d30ecc9c560.zip
(apropos-true-hit, apropos-false-hit-symbol)
(apropos-false-hit-str, apropos-true-hit-doc): New functions. (apropos-command, apropos-value, apropos-documentation-internal) (apropos-documentation-check-doc-file) (apropos-documentation-check-elc-file): Use them to filter out false matches where only one keyword matches, but more than once.
-rw-r--r--lisp/apropos.el127
1 files changed, 79 insertions, 48 deletions
diff --git a/lisp/apropos.el b/lisp/apropos.el
index 8d1e163bd80..5f19f72ad8e 100644
--- a/lisp/apropos.el
+++ b/lisp/apropos.el
@@ -324,6 +324,27 @@ Value is a list of offsets of the words into the string."
324 (dolist (s (apropos-calc-scores symbol apropos-words) (* score (or weight 3))) 324 (dolist (s (apropos-calc-scores symbol apropos-words) (* score (or weight 3)))
325 (setq score (+ score (- 60 l) (/ (* (- l s) 60) l)))))) 325 (setq score (+ score (- 60 l) (/ (* (- l s) 60) l))))))
326 326
327(defun apropos-true-hit (str words)
328 "Return t if STR is a genuine hit.
329This may fail if only one of the keywords is matched more than once.
330This requires that at least 2 keywords (unless only one was given)."
331 (or (not str)
332 (not words)
333 (not (cdr words))
334 (> (length (apropos-calc-scores str words)) 1)))
335
336(defun apropos-false-hit-symbol (symbol)
337 "Return t if SYMBOL is not really matched by the current keywords."
338 (not (apropos-true-hit (symbol-name symbol) apropos-words)))
339
340(defun apropos-false-hit-str (str)
341 "Return t if STR is not really matched by the current keywords."
342 (not (apropos-true-hit str apropos-words)))
343
344(defun apropos-true-hit-doc (doc)
345 "Return t if DOC is really matched by the current keywords."
346 (apropos-true-hit doc apropos-all-words))
347
327;;;###autoload 348;;;###autoload
328(define-derived-mode apropos-mode fundamental-mode "Apropos" 349(define-derived-mode apropos-mode fundamental-mode "Apropos"
329 "Major mode for following hyperlinks in output of apropos commands. 350 "Major mode for following hyperlinks in output of apropos commands.
@@ -378,7 +399,8 @@ satisfy the predicate VAR-PREDICATE."
378 (if do-all 'functionp 'commandp)))) 399 (if do-all 'functionp 'commandp))))
379 (let ((tem apropos-accumulator)) 400 (let ((tem apropos-accumulator))
380 (while tem 401 (while tem
381 (if (get (car tem) 'apropos-inhibit) 402 (if (or (get (car tem) 'apropos-inhibit)
403 (apropos-false-hit-symbol (car tem)))
382 (setq apropos-accumulator (delq (car tem) apropos-accumulator))) 404 (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
383 (setq tem (cdr tem)))) 405 (setq tem (cdr tem))))
384 (let ((p apropos-accumulator) 406 (let ((p apropos-accumulator)
@@ -501,6 +523,12 @@ Returns list of symbols and values found."
501 (if do-all 523 (if do-all
502 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function) 524 (setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
503 p (apropos-format-plist symbol "\n " t))) 525 p (apropos-format-plist symbol "\n " t)))
526 (if (apropos-false-hit-str v)
527 (setq v nil))
528 (if (apropos-false-hit-str f)
529 (setq f nil))
530 (if (apropos-false-hit-str p)
531 (setq p nil))
504 (if (or f v p) 532 (if (or f v p)
505 (setq apropos-accumulator (cons (list symbol 533 (setq apropos-accumulator (cons (list symbol
506 (+ (apropos-score-str f) 534 (+ (apropos-score-str f)
@@ -576,6 +604,7 @@ Returns list of symbols and documentation found."
576 (apropos-documentation-check-elc-file (car doc)) 604 (apropos-documentation-check-elc-file (car doc))
577 (and doc 605 (and doc
578 (string-match apropos-all-regexp doc) 606 (string-match apropos-all-regexp doc)
607 (save-match-data (apropos-true-hit-doc doc))
579 (progn 608 (progn
580 (if apropos-match-face 609 (if apropos-match-face
581 (put-text-property (match-beginning 0) 610 (put-text-property (match-beginning 0)
@@ -624,25 +653,26 @@ Returns list of symbols and documentation found."
624 (setq beg (match-beginning 0) 653 (setq beg (match-beginning 0)
625 end (point)) 654 end (point))
626 (goto-char (1+ sepa)) 655 (goto-char (1+ sepa))
627 (or (and (setq type (if (eq ?F (preceding-char)) 656 (setq type (if (eq ?F (preceding-char))
628 2 ; function documentation 657 2 ; function documentation
629 3) ; variable documentation 658 3) ; variable documentation
630 symbol (read) 659 symbol (read)
631 beg (- beg (point) 1) 660 beg (- beg (point) 1)
632 end (- end (point) 1) 661 end (- end (point) 1)
633 doc (buffer-substring (1+ (point)) (1- sepb)) 662 doc (buffer-substring (1+ (point)) (1- sepb)))
634 apropos-item (assq symbol apropos-accumulator)) 663 (when (apropos-true-hit-doc doc)
635 (setcar (cdr apropos-item) 664 (or (and (setq apropos-item (assq symbol apropos-accumulator))
636 (+ (cadr apropos-item) (apropos-score-doc doc)))) 665 (setcar (cdr apropos-item)
637 (setq apropos-item (list symbol 666 (+ (cadr apropos-item) (apropos-score-doc doc))))
638 (+ (apropos-score-symbol symbol 2) 667 (setq apropos-item (list symbol
639 (apropos-score-doc doc)) 668 (+ (apropos-score-symbol symbol 2)
640 nil nil) 669 (apropos-score-doc doc))
641 apropos-accumulator (cons apropos-item 670 nil nil)
642 apropos-accumulator))) 671 apropos-accumulator (cons apropos-item
643 (if apropos-match-face 672 apropos-accumulator)))
644 (put-text-property beg end 'face apropos-match-face doc)) 673 (if apropos-match-face
645 (setcar (nthcdr type apropos-item) doc))) 674 (put-text-property beg end 'face apropos-match-face doc))
675 (setcar (nthcdr type apropos-item) doc))))
646 (setq sepa (goto-char sepb))))) 676 (setq sepa (goto-char sepb)))))
647 677
648(defun apropos-documentation-check-elc-file (file) 678(defun apropos-documentation-check-elc-file (file)
@@ -666,34 +696,35 @@ Returns list of symbols and documentation found."
666 (goto-char (+ end 2)) 696 (goto-char (+ end 2))
667 (setq doc (buffer-substring beg end) 697 (setq doc (buffer-substring beg end)
668 end (- (match-end 0) beg) 698 end (- (match-end 0) beg)
669 beg (- (match-beginning 0) beg) 699 beg (- (match-beginning 0) beg))
670 this-is-a-variable (looking-at "(def\\(var\\|const\\) ") 700 (when (apropos-true-hit-doc doc)
671 symbol (progn 701 (setq this-is-a-variable (looking-at "(def\\(var\\|const\\) ")
672 (skip-chars-forward "(a-z") 702 symbol (progn
673 (forward-char) 703 (skip-chars-forward "(a-z")
674 (read)) 704 (forward-char)
675 symbol (if (consp symbol) 705 (read))
676 (nth 1 symbol) 706 symbol (if (consp symbol)
677 symbol)) 707 (nth 1 symbol)
678 (if (if this-is-a-variable 708 symbol))
679 (get symbol 'variable-documentation) 709 (if (if this-is-a-variable
680 (and (fboundp symbol) (apropos-safe-documentation symbol))) 710 (get symbol 'variable-documentation)
681 (progn 711 (and (fboundp symbol) (apropos-safe-documentation symbol)))
682 (or (and (setq apropos-item (assq symbol apropos-accumulator)) 712 (progn
683 (setcar (cdr apropos-item) 713 (or (and (setq apropos-item (assq symbol apropos-accumulator))
684 (+ (cadr apropos-item) (apropos-score-doc doc)))) 714 (setcar (cdr apropos-item)
685 (setq apropos-item (list symbol 715 (+ (cadr apropos-item) (apropos-score-doc doc))))
686 (+ (apropos-score-symbol symbol 2) 716 (setq apropos-item (list symbol
687 (apropos-score-doc doc)) 717 (+ (apropos-score-symbol symbol 2)
688 nil nil) 718 (apropos-score-doc doc))
689 apropos-accumulator (cons apropos-item 719 nil nil)
690 apropos-accumulator))) 720 apropos-accumulator (cons apropos-item
691 (if apropos-match-face 721 apropos-accumulator)))
692 (put-text-property beg end 'face apropos-match-face 722 (if apropos-match-face
693 doc)) 723 (put-text-property beg end 'face apropos-match-face
694 (setcar (nthcdr (if this-is-a-variable 3 2) 724 doc))
695 apropos-item) 725 (setcar (nthcdr (if this-is-a-variable 3 2)
696 doc))))))))) 726 apropos-item)
727 doc))))))))))
697 728
698 729
699 730