From c46863d9bb8493d0d15030df863d78b8f1738b2e Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Sat, 6 Aug 2022 13:38:12 +0200 Subject: Make force-load-doc-strings work again When load-force-doc-strings is true, read (#$ . POS) as the (unibyte) string referred to. This feature was lost by mistake in the recent nonrecursive reader rewrite. Noticed by Stefan Monnier. * src/lread.c (get_lazy_string): New function (code mostly recycled from an old version). (read0): Detect (#$ . FIXNUM) and retrieve the string if appropriate. * test/src/lread-resources/lazydoc.el: * test/src/lread-tests.el (lread-force-load-doc-strings): New test. --- test/src/lread-resources/lazydoc.el | Bin 0 -> 171 bytes test/src/lread-tests.el | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/src/lread-resources/lazydoc.el (limited to 'test') diff --git a/test/src/lread-resources/lazydoc.el b/test/src/lread-resources/lazydoc.el new file mode 100644 index 00000000000..cb434c239b5 Binary files /dev/null and b/test/src/lread-resources/lazydoc.el differ diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index f190f14781e..2f25de4cc39 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el @@ -322,4 +322,21 @@ literals (Bug#20852)." (should-error (read-from-string "?\\\n x")) (should (equal (read-from-string "\"a\\\nb\"") '("ab" . 6)))) +(ert-deftest lread-force-load-doc-strings () + ;; Verify that lazy doc strings are loaded lazily by default, + ;; but eagerly with `force-load-doc-strings' set. + (let ((file (expand-file-name "lazydoc.el" (ert-resource-directory)))) + (fmakunbound 'lazydoc-fun) + (load file) + (let ((f (symbol-function 'lazydoc-fun))) + (should (byte-code-function-p f)) + (should (equal (aref f 4) (cons file 87)))) + + (fmakunbound 'lazydoc-fun) + (let ((load-force-doc-strings t)) + (load file) + (let ((f (symbol-function 'lazydoc-fun))) + (should (byte-code-function-p f)) + (should (equal (aref f 4) "My little\ndoc string\nhere")))))) + ;;; lread-tests.el ends here -- cgit v1.2.3