Subject: Re: bug#39805: 28.0.50; scan-sexps (scan_lists) incorrectly parsing circular list

From: No Wayman <[email-masked]>
Date: Thu, 27 Feb 2020 12:22:34 -0500

Noam Postavsky <[email-masked]> writes:

> It doesn't fail if the buffer is changed to emacs-lisp-mode 
> before the
> pp-buffer call.

In the meantime, I'd like to be able to offer the users of my 
package a solution if they hit this bug.
This seems to work for me, but I haven't written much, and am a 
bit leery of, elisp advice.
Would you consider this an appropriate workaround?:

(defun workaround/describe-variable-print-bug (original-function 
&rest args)
  "Put temp buffer in emacs-lisp before ORIGINAL-FUNCTION: 
  `pp-buffer'.
https://lists.gnu.org/archive/html/emacs-bug-tracker/2020-02/msg00376.html"
  (cl-flet ((pp-advice (original-function)
                       (when (string-prefix-p " *temp" 
                       (buffer-name))
                         (let ((mm major-mode))
                           (emacs-lisp-mode)
                           (funcall original-function)
                           (funcall mm)))))
    (advice-add #'pp-buffer :around #'pp-advice)
    (unwind-protect
        (progn
          (apply original-function args)
          nil)
      (advice-remove #'pp-buffer #'pp-advice))))

(advice-add #'describe-variable :around 
#'workaround/describe-variable-print-bug)