Subject: Re: 29.0.60; apropos-documentation does not work for preloaded symbols

From: Stefan Monnier <[email-masked]>
Date: Fri, 13 Jan 2023 15:10:02 -0500

> For `emacs-29` the better option is probably to just revert the
> above commit.

Then again, since \n#@ can also match false positives, we may as well
keep the above commit and just search for #@ instead.

The patch below should fix both problems in a kind of "minimalist" way
(i.e. meant for `emacs-29`).
Can someone confirm it also works for them while I clean it up?

        Stefan

diff --git a/lisp/apropos.el b/lisp/apropos.el
index b260d889955..b66f27b8a9e 100644
--- a/lisp/apropos.el
+++ b/lisp/apropos.el
@@ -913,8 +913,19 @@
           (apropos-sort-by-scores apropos-documentation-sort-by-scores)
           f v sf sv)
       (apropos-documentation-check-doc-file)
-      (if do-all
-          (mapatoms
+      (funcall
+       (if do-all #'mapatoms
+         (lambda (f)
+           (let ((preloaded-regexp
+                  (concat "\\`"
+                          (regexp-quote lisp-directory)
+                          (regexp-opt preloaded-file-list)
+                          "\\.elc?\\'")))
+             (dolist (x load-history)
+               (when (string-match preloaded-regexp (car x))
+                 (dolist (def (cdr x))
+                   (when (eq 'defun (car-safe def))
+                     (funcall f (cdr def)))))))))
            (lambda (symbol)
              (setq f (apropos-safe-documentation symbol)
                    v (get symbol 'variable-documentation))
@@ -939,7 +950,7 @@
                          (cons (list symbol
                                      (+ (apropos-score-symbol symbol 2) sf sv)
                                      f v)
-                               apropos-accumulator)))))))
+                           apropos-accumulator))))))
       (apropos-print nil "\n----------------\n" nil t))))
 
 
@@ -1064,10 +1064,12 @@
       (setq apropos-files-scanned (cons file apropos-files-scanned))
       (erase-buffer)
       (insert-file-contents file)
-      (while (search-forward "\n#@" nil t)
+      (while (search-forward "#@" nil t)
 	;; Read the comment length, and advance over it.
-	(setq end (read)
-	      beg (1+ (point))
+	;; This #@ may be a false positive, so don't get upset if
+	;; it's not followed by the expected number of bytes to skip.
+	(when (and (setq end (ignore-errors (read))) (natnump end))
+	  (setq beg (1+ (point))
 	      end (+ (point) end -1))
 	(forward-char)
 	(if (save-restriction
@@ -1110,7 +1112,7 @@
 					       'face apropos-match-face doc)))
 		      (setcar (nthcdr (if this-is-a-variable 3 2)
 				      apropos-item)
-			      doc))))))))))
+				doc)))))))))))