Subject: Re: bug#40728: 27.0.91; Removed public functions from debugger.el

From: Gemini Lasswell <[email-masked]>
Date: Mon, 27 Apr 2020 13:54:27 -0700

Eli Zaretskii <[email-masked]> writes:

> Gemini, could you please write replacements for the functions you
> removed, or defalias them to some equivalent replacements?  I agree
> that public functions should not be removed, not without deprecating
> them first (if indeed they don't make sense).

Here is a patch to bring those functions back.

>From 6e1141592bc259bab9c61f3212351c92d0eb16e7 Mon Sep 17 00:00:00 2001
From: Gemini Lasswell <[email-masked]>
Date: Sun, 26 Apr 2020 10:14:38 -0700
Subject: [PATCH] Restore some public functions to debug.el (Bug#40728)

In "Add backtrace-mode and use it in the debugger, ERT and Edebug", on
19 June 2018, three public functions in debug.el were removed.
Restore them so as not to break users' workflows.  Since
backtrace-mode now provides the functionality that used to come from
the buttons created by debugger-insert-backtrace, it is now obsolete.

* lisp/emacs-lisp/debug.el (debugger-insert-backtrace): New function.
Mark it as obsolete.
(debugger-toggle-locals, debug-help-follow): New aliases.

* lisp/emacs-lisp/backtrace.el (backtrace--to-string): New function.
(backtrace-to-string): Use it.  Fix whitespace.
---
 lisp/emacs-lisp/backtrace.el | 11 +++++++----
 lisp/emacs-lisp/debug.el     | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lisp/emacs-lisp/backtrace.el b/lisp/emacs-lisp/backtrace.el
index 37dad8db16..5874ba72fc 100644
--- a/lisp/emacs-lisp/backtrace.el
+++ b/lisp/emacs-lisp/backtrace.el
@@ -922,11 +922,15 @@ backtrace
   (princ (backtrace-to-string (backtrace-get-frames 'backtrace)))
   nil)
 
-(defun backtrace-to-string(&optional frames)
+(defun backtrace-to-string (&optional frames)
   "Format FRAMES, a list of `backtrace-frame' objects, for output.
 Return the result as a string.  If FRAMES is nil, use all
 function calls currently active."
-  (unless frames (setq frames (backtrace-get-frames 'backtrace-to-string)))
+  (substring-no-properties
+   (backtrace--to-string
+    (or frames (backtrace-get-frames 'backtrace-to-string)))))
+
+(defun backtrace--to-string (frames)
   (let ((backtrace-fontify nil))
     (with-temp-buffer
       (backtrace-mode)
@@ -934,8 +938,7 @@ backtrace-to-string
             backtrace-frames frames
             backtrace-print-function #'cl-prin1)
       (backtrace-print)
-      (substring-no-properties (filter-buffer-substring (point-min)
-                                                        (point-max))))))
+      (filter-buffer-substring (point-min) (point-max)))))
 
 (provide 'backtrace)
 
diff --git a/lisp/emacs-lisp/debug.el b/lisp/emacs-lisp/debug.el
index ed28997292..14957eae0f 100644
--- a/lisp/emacs-lisp/debug.el
+++ b/lisp/emacs-lisp/debug.el
@@ -320,6 +320,17 @@ debugger--print
      (message "Error in debug printer: %S" err)
      (prin1 obj stream))))
 
+(make-obsolete 'debugger-insert-backtrace
+               "use a `backtrace-mode' buffer or `backtrace-to-string'."
+               "Emacs 27.1")
+
+(defun debugger-insert-backtrace (frames do-xrefs)
+  "Format and insert the backtrace FRAMES at point.
+Make functions into cross-reference buttons if DO-XREFS is non-nil."
+  (insert (if do-xrefs
+              (backtrace--to-string frames)
+            (backtrace-to-string frames))))
+
 (defun debugger-setup-buffer (args)
   "Initialize the `*Backtrace*' buffer for entry to the debugger.
 That buffer should be current already and in debugger-mode."
@@ -527,6 +538,8 @@ debugger-eval-expression
           (let ((str (eval-expression-print-format val)))
             (if str (princ str t))))))))
 
+(defalias 'debugger-toggle-locals 'backtrace-toggle-locals)
+
 
 (defvar debugger-mode-map
   (let ((map (make-keymap)))
@@ -621,6 +634,8 @@ debugger-record-expression
 	     (buffer-substring (line-beginning-position 0)
 			       (line-end-position 0)))))
 
+(defalias 'debug-help-follow 'backtrace-help-follow-symbol)
+
 
 ;; When you change this, you may also need to change the number of
 ;; frames that the debugger skips.
-- 
2.23.1