Subject: bug#48063: 28.0.50: apropos-value{,-internal}: suppress false positives

From: Boruch Baum <[email-masked]>
Date: Tue, 27 Apr 2021 11:17:27 -0400

Function apropos-value will always return false positive, some of which
entail printing out very long variable value strings. The attached patch
apropos-value.patch fixes those cases. The second patch just changes
what seems to be an indentation bug in the function.

The cases of false positives are:

+ variables reflecting the apropos request itself
  + (car minibuffer-history)
  + (car command-history)

+ variables internal to apropos:
  + apropos--current
  + apropos-pattern-quoted
  + pattern

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0
diff --git a/apropos.el b/apropos.el
index 6d8c784..44c87ee 100644
--- a/apropos.el
+++ b/apropos.el
@@ -817,6 +817,7 @@ Returns list of symbols and values found."
       (lambda (symbol)
 	(setq f nil v nil p nil)
 	(or (memq symbol '(apropos-regexp
+                           apropos--current apropos-pattern-quoted pattern
 			   apropos-pattern apropos-all-words-regexp
 			   apropos-words apropos-all-words
 			   do-all apropos-accumulator
@@ -933,7 +934,10 @@ Returns list of symbols and documentation found."
 
 (defun apropos-value-internal (predicate symbol function)
   (when (funcall predicate symbol)
-    (setq symbol (prin1-to-string (funcall function symbol)))
+    (setq symbol (prin1-to-string
+      (if (memq symbol '(command-history minibuffer-history))
+        (cdr (funcall function symbol))
+       (funcall function symbol))))
     (when (string-match apropos-regexp symbol)
       (if apropos-match-face
           (put-text-property (match-beginning 0) (match-end 0)
diff --git a/apropos.el b/apropos.el
index 44c87ee..9529271 100644
--- a/apropos.el
+++ b/apropos.el
@@ -812,35 +812,35 @@ Returns list of symbols and values found."
   (apropos-parse-pattern pattern t)
   (or do-all (setq do-all apropos-do-all))
   (setq apropos-accumulator ())
-   (let (f v p)
-     (mapatoms
-      (lambda (symbol)
-	(setq f nil v nil p nil)
-	(or (memq symbol '(apropos-regexp
-                           apropos--current apropos-pattern-quoted pattern
-			   apropos-pattern apropos-all-words-regexp
-			   apropos-words apropos-all-words
-			   do-all apropos-accumulator
-			   symbol f v p))
-	    (setq v (apropos-value-internal 'boundp symbol 'symbol-value)))
-	(if do-all
-	    (setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
-		  p (apropos-format-plist symbol "\n    " t)))
-	(if (apropos-false-hit-str v)
-	    (setq v nil))
-	(if (apropos-false-hit-str f)
-	    (setq f nil))
-	(if (apropos-false-hit-str p)
-	    (setq p nil))
-	(if (or f v p)
-	    (setq apropos-accumulator (cons (list symbol
-						  (+ (apropos-score-str f)
-						     (apropos-score-str v)
-						     (apropos-score-str p))
-						  f v p)
-					    apropos-accumulator))))))
-   (let ((apropos-multi-type do-all))
-     (apropos-print nil "\n----------------\n")))
+  (let (f v p)
+    (mapatoms
+     (lambda (symbol)
+       (setq f nil v nil p nil)
+       (or (memq symbol '(apropos-regexp
+                          apropos--current apropos-pattern-quoted pattern
+       		   apropos-pattern apropos-all-words-regexp
+       		   apropos-words apropos-all-words
+       		   do-all apropos-accumulator
+       		   symbol f v p))
+           (setq v (apropos-value-internal 'boundp symbol 'symbol-value)))
+       (if do-all
+           (setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
+       	  p (apropos-format-plist symbol "\n    " t)))
+       (if (apropos-false-hit-str v)
+           (setq v nil))
+       (if (apropos-false-hit-str f)
+           (setq f nil))
+       (if (apropos-false-hit-str p)
+           (setq p nil))
+       (if (or f v p)
+           (setq apropos-accumulator (cons (list symbol
+       					  (+ (apropos-score-str f)
+       					     (apropos-score-str v)
+       					     (apropos-score-str p))
+       					  f v p)
+       				    apropos-accumulator))))))
+  (let ((apropos-multi-type do-all))
+    (apropos-print nil "\n----------------\n")))

 ;;;###autoload
 (defun apropos-local-value (pattern &optional buffer)