aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGemini Lasswell2019-07-30 10:00:27 -0700
committerGemini Lasswell2019-09-13 13:43:07 -0700
commit2093395dbf8563af38f206950d95f0bc20183b9c (patch)
tree0e4c7788113b296bf768c125925e3061546e898a
parent224534ab8d3f60fea28b271859f8eaf373f95089 (diff)
downloademacs-2093395dbf8563af38f206950d95f0bc20183b9c.tar.gz
emacs-2093395dbf8563af38f206950d95f0bc20183b9c.zip
Improve print output options commands in backtrace-mode (bug#36566)
* lisp/emacs-lisp/backtrace.el (backtrace-view): Mention :print-gensym in docstring. (backtrace-mode-map): Add keyboard binding for backtrace-toggle-print-gensym. Add menu entries for backtrace-toggle-print-circle and backtrace-toggle-print-gensym. (backtrace--with-output-variables): Bind print-gensym with value of :print-gensym found in view plist. (backtrace-toggle-print-circle): Remove description of implementation details from docstring. (backtrace-toggle-print-gensym): New command. (backtrace--toggle-feature): Add echo area message describing result of command. * test/lisp/emacs-lisp/backtrace-tests.el (backtrace-tests--print-circle): New test. * doc/lispref/debugging.texi (Backtraces): Document keyboard binding for backtrace-toggle-print-gensym.
-rw-r--r--doc/lispref/debugging.texi3
-rw-r--r--lisp/emacs-lisp/backtrace.el44
-rw-r--r--test/lisp/emacs-lisp/backtrace-tests.el49
3 files changed, 86 insertions, 10 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi
index 12caeaf1289..71e767d0a66 100644
--- a/doc/lispref/debugging.texi
+++ b/doc/lispref/debugging.texi
@@ -457,6 +457,9 @@ Collapse the top-level Lisp form at point back to a single line.
457@item # 457@item #
458Toggle @code{print-circle} for the frame at point. 458Toggle @code{print-circle} for the frame at point.
459 459
460@item :
461Toggle @code{print-gensym} for the frame at point.
462
460@item . 463@item .
461Expand all the forms abbreviated with ``...'' in the frame at point. 464Expand all the forms abbreviated with ``...'' in the frame at point.
462 465
diff --git a/lisp/emacs-lisp/backtrace.el b/lisp/emacs-lisp/backtrace.el
index 60d146e24a8..0c4c7987c3c 100644
--- a/lisp/emacs-lisp/backtrace.el
+++ b/lisp/emacs-lisp/backtrace.el
@@ -175,7 +175,8 @@ This should be a list of `backtrace-frame' objects.")
175 175
176(defvar-local backtrace-view nil 176(defvar-local backtrace-view nil
177 "A plist describing how to render backtrace frames. 177 "A plist describing how to render backtrace frames.
178Possible entries are :show-flags, :show-locals and :print-circle.") 178Possible entries are :show-flags, :show-locals, :print-circle
179and :print-gensym.")
179 180
180(defvar-local backtrace-insert-header-function nil 181(defvar-local backtrace-insert-header-function nil
181 "Function for inserting a header for the current Backtrace buffer. 182 "Function for inserting a header for the current Backtrace buffer.
@@ -205,6 +206,7 @@ frames where the source code location is known.")
205 (define-key map "p" 'backtrace-backward-frame) 206 (define-key map "p" 'backtrace-backward-frame)
206 (define-key map "v" 'backtrace-toggle-locals) 207 (define-key map "v" 'backtrace-toggle-locals)
207 (define-key map "#" 'backtrace-toggle-print-circle) 208 (define-key map "#" 'backtrace-toggle-print-circle)
209 (define-key map ":" 'backtrace-toggle-print-gensym)
208 (define-key map "s" 'backtrace-goto-source) 210 (define-key map "s" 'backtrace-goto-source)
209 (define-key map "\C-m" 'backtrace-help-follow-symbol) 211 (define-key map "\C-m" 'backtrace-help-follow-symbol)
210 (define-key map "+" 'backtrace-multi-line) 212 (define-key map "+" 'backtrace-multi-line)
@@ -224,6 +226,18 @@ frames where the source code location is known.")
224 :active (backtrace-get-index) 226 :active (backtrace-get-index)
225 :selected (plist-get (backtrace-get-view) :show-locals) 227 :selected (plist-get (backtrace-get-view) :show-locals)
226 :help "Show or hide the local variables for the frame at point"] 228 :help "Show or hide the local variables for the frame at point"]
229 ["Show Circular Structures" backtrace-toggle-print-circle
230 :style toggle
231 :active (backtrace-get-index)
232 :selected (plist-get (backtrace-get-view) :print-circle)
233 :help
234 "Condense or expand shared or circular structures in the frame at point"]
235 ["Show Uninterned Symbols" backtrace-toggle-print-gensym
236 :style toggle
237 :active (backtrace-get-index)
238 :selected (plist-get (backtrace-get-view) :print-gensym)
239 :help
240 "Toggle unique printing of uninterned symbols in the frame at point"]
227 ["Expand \"...\"s" backtrace-expand-ellipses 241 ["Expand \"...\"s" backtrace-expand-ellipses
228 :help "Expand all the abbreviated forms in the current frame"] 242 :help "Expand all the abbreviated forms in the current frame"]
229 ["Show on Multiple Lines" backtrace-multi-line 243 ["Show on Multiple Lines" backtrace-multi-line
@@ -339,6 +353,7 @@ It runs `backtrace-revert-hook', then calls `backtrace-print'."
339 `(let ((print-escape-control-characters t) 353 `(let ((print-escape-control-characters t)
340 (print-escape-newlines t) 354 (print-escape-newlines t)
341 (print-circle (plist-get ,view :print-circle)) 355 (print-circle (plist-get ,view :print-circle))
356 (print-gensym (plist-get ,view :print-gensym))
342 (standard-output (current-buffer))) 357 (standard-output (current-buffer)))
343 ,@body)) 358 ,@body))
344 359
@@ -420,12 +435,18 @@ Set it to VALUE unless the button is a `backtrace-ellipsis' button."
420 435
421(defun backtrace-toggle-print-circle (&optional all) 436(defun backtrace-toggle-print-circle (&optional all)
422 "Toggle `print-circle' for the backtrace frame at point. 437 "Toggle `print-circle' for the backtrace frame at point.
423With prefix argument ALL, toggle the value of :print-circle in 438With prefix argument ALL, toggle the default value bound to
424`backtrace-view', which affects all of the backtrace frames in 439`print-circle' for all the frames in the buffer."
425the buffer."
426 (interactive "P") 440 (interactive "P")
427 (backtrace--toggle-feature :print-circle all)) 441 (backtrace--toggle-feature :print-circle all))
428 442
443(defun backtrace-toggle-print-gensym (&optional all)
444 "Toggle `print-gensym' for the backtrace frame at point.
445With prefix argument ALL, toggle the default value bound to
446`print-gensym' for all the frames in the buffer."
447 (interactive "P")
448 (backtrace--toggle-feature :print-gensym all))
449
429(defun backtrace--toggle-feature (feature all) 450(defun backtrace--toggle-feature (feature all)
430 "Toggle FEATURE for the current backtrace frame or for the buffer. 451 "Toggle FEATURE for the current backtrace frame or for the buffer.
431FEATURE should be one of the options in `backtrace-view'. If ALL 452FEATURE should be one of the options in `backtrace-view'. If ALL
@@ -450,12 +471,15 @@ position point at the start of the frame it was in before."
450 (goto-char (point-min)) 471 (goto-char (point-min))
451 (while (and (not (eql index (backtrace-get-index))) 472 (while (and (not (eql index (backtrace-get-index)))
452 (< (point) (point-max))) 473 (< (point) (point-max)))
453 (goto-char (backtrace-get-frame-end))))) 474 (goto-char (backtrace-get-frame-end))))
454 (let ((index (backtrace-get-index))) 475 (message "%s is now %s for all frames"
455 (unless index 476 (substring (symbol-name feature) 1) value))
456 (user-error "Not in a stack frame")) 477 (unless (backtrace-get-index)
457 (backtrace--set-feature feature 478 (user-error "Not in a stack frame"))
458 (not (plist-get (backtrace-get-view) feature)))))) 479 (let ((value (not (plist-get (backtrace-get-view) feature))))
480 (backtrace--set-feature feature value)
481 (message "%s is now %s for this frame"
482 (substring (symbol-name feature) 1) value))))
459 483
460(defun backtrace--set-feature (feature value) 484(defun backtrace--set-feature (feature value)
461 "Set FEATURE in the view plist of the frame at point to VALUE. 485 "Set FEATURE in the view plist of the frame at point to VALUE.
diff --git a/test/lisp/emacs-lisp/backtrace-tests.el b/test/lisp/emacs-lisp/backtrace-tests.el
index ce827e0166f..be154953423 100644
--- a/test/lisp/emacs-lisp/backtrace-tests.el
+++ b/test/lisp/emacs-lisp/backtrace-tests.el
@@ -335,6 +335,55 @@ line contains the strings \"lambda\" and \"number\"."
335 (should (string-match-p results 335 (should (string-match-p results
336 (backtrace-tests--get-substring (point-min) (point-max))))))) 336 (backtrace-tests--get-substring (point-min) (point-max)))))))
337 337
338(ert-deftest backtrace-tests--print-gensym ()
339 "Backtrace buffers can toggle `print-gensym' syntax."
340 (ert-with-test-buffer (:name "print-gensym")
341 (let* ((print-gensym nil)
342 (arg (list (gensym "first") (gensym) (gensym "last")))
343 (results (backtrace-tests--make-regexp
344 (backtrace-tests--result arg)))
345 (results-gensym (regexp-quote (let ((print-gensym t))
346 (backtrace-tests--result arg))))
347 (last-frame (backtrace-tests--make-regexp
348 (format (nth (1- backtrace-tests--line-count)
349 (backtrace-tests--backtrace-lines))
350 arg)))
351 (last-frame-gensym (regexp-quote
352 (let ((print-gensym t))
353 (format (nth (1- backtrace-tests--line-count)
354 (backtrace-tests--backtrace-lines))
355 arg)))))
356 (backtrace-tests--make-backtrace arg)
357 (backtrace-print)
358 (should (string-match-p results
359 (backtrace-tests--get-substring (point-min) (point-max))))
360 ;; Go to the last frame.
361 (goto-char (point-max))
362 (forward-line -1)
363 ;; Turn on print-gensym for that frame.
364 (backtrace-toggle-print-gensym)
365 (should (string-match-p last-frame-gensym
366 (backtrace-tests--get-substring (point) (point-max))))
367 ;; Turn off print-gensym for the frame.
368 (backtrace-toggle-print-gensym)
369 (should (string-match-p last-frame
370 (backtrace-tests--get-substring (point) (point-max))))
371 (should (string-match-p results
372 (backtrace-tests--get-substring (point-min) (point-max))))
373 ;; Turn print-gensym on for the buffer.
374 (backtrace-toggle-print-gensym '(4))
375 (should (string-match-p last-frame-gensym
376 (backtrace-tests--get-substring (point) (point-max))))
377 (should (string-match-p results-gensym
378 (backtrace-tests--get-substring (point-min) (point-max))))
379 ;; Turn print-gensym off.
380 (backtrace-toggle-print-gensym '(4))
381 (should (string-match-p last-frame
382 (backtrace-tests--get-substring
383 (point) (+ (point) (length last-frame)))))
384 (should (string-match-p results
385 (backtrace-tests--get-substring (point-min) (point-max)))))))
386
338(defun backtrace-tests--make-regexp (str) 387(defun backtrace-tests--make-regexp (str)
339 "Make regexp from STR for `backtrace-tests--print-circle'. 388 "Make regexp from STR for `backtrace-tests--print-circle'.
340Used for results of printing circular objects without 389Used for results of printing circular objects without