Function: backtrace-mode

backtrace-mode is an interactive and byte-compiled function defined in backtrace.el.gz.

Signature

(backtrace-mode)

Documentation

Generic major mode for examining an Elisp stack backtrace.

This mode can be used directly, or other major modes can be derived from it, using define-derived-mode.

In this major mode, the buffer contains some optional lines of header text followed by backtrace frames, each consisting of one or more whole lines.

Letters in this mode do not insert themselves; instead they are commands.
# backtrace-toggle-print-circle
+ backtrace-multi-line
- backtrace-single-line
. backtrace-expand-ellipses
: backtrace-toggle-print-gensym
<backtab> backward-button
<follow-link> mouse-face
<keymap> - negative-argument
<keymap> 0 digit-argument
<keymap> 1 digit-argument
<keymap> 2 digit-argument
<keymap> 3 digit-argument
<keymap> 4 digit-argument
<keymap> 5 digit-argument
<keymap> 6 digit-argument
<keymap> 7 digit-argument
<keymap> 8 digit-argument
<keymap> 9 digit-argument
<keymap> < beginning-of-buffer
<keymap> > end-of-buffer
<keymap> ? describe-mode
<keymap> DEL scroll-down-command
<keymap> S-SPC scroll-down-command
<keymap> SPC scroll-up-command
<keymap> SPC..~ undefined
<keymap> h describe-mode
<keymap> q quit-window
<mouse-2> mouse-select-window
C-M-i backward-button
C-] abort-recursive-edit
RET backtrace-help-follow-symbol
TAB forward-button
n backtrace-forward-frame
p backtrace-backward-frame
v backtrace-toggle-locals

A mode which inherits from Backtrace mode, or a command which creates a backtrace-mode buffer, should usually do the following:

 - Set backtrace-revert-hook, if the buffer contents need
   to be specially recomputed prior to revert-buffer.
 - Maybe set backtrace-insert-header-function to a function to create
   header text for the buffer.
 - Set backtrace-frames(var)/backtrace-frames(fun) (see below).
 - Maybe modify backtrace-view (see below).
 - Maybe set backtrace-print-function.

A command which creates or switches to a Backtrace mode buffer, such as ert-results-pop-to-backtrace-for-test-at-point, should initialize backtrace-frames(var)/backtrace-frames(fun) to a list of backtrace-frame objects (backtrace-get-frames is provided for that purpose, if desired), and may optionally modify backtrace-view, which is a plist describing the appearance of the backtrace. Finally, it should call backtrace-print.

backtrace-print calls backtrace-insert-header-function followed by backtrace-print-frame, once for each stack frame.

In addition to any hooks its parent mode special-mode might have run, this mode runs the hook backtrace-mode-hook, as the final or penultimate step during initialization.

Probably introduced at or before Emacs version 27.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/backtrace.el.gz
;;; The mode definition

(define-derived-mode backtrace-mode special-mode "Backtrace"
  "Generic major mode for examining an Elisp stack backtrace.
This mode can be used directly, or other major modes can be
derived from it, using `define-derived-mode'.

In this major mode, the buffer contains some optional lines of
header text followed by backtrace frames, each consisting of one
or more whole lines.

Letters in this mode do not insert themselves; instead they are
commands.
\\<backtrace-mode-map>
\\{backtrace-mode-map}

A mode which inherits from Backtrace mode, or a command which
creates a `backtrace-mode' buffer, should usually do the following:

 - Set `backtrace-revert-hook', if the buffer contents need
   to be specially recomputed prior to `revert-buffer'.
 - Maybe set `backtrace-insert-header-function' to a function to create
   header text for the buffer.
 - Set `backtrace-frames' (see below).
 - Maybe modify `backtrace-view' (see below).
 - Maybe set `backtrace-print-function'.

A command which creates or switches to a Backtrace mode buffer,
such as `ert-results-pop-to-backtrace-for-test-at-point', should
initialize `backtrace-frames' to a list of `backtrace-frame'
objects (`backtrace-get-frames' is provided for that purpose, if
desired), and may optionally modify `backtrace-view', which is a
plist describing the appearance of the backtrace.  Finally, it
should call `backtrace-print'.

`backtrace-print' calls `backtrace-insert-header-function'
followed by `backtrace-print-frame', once for each stack frame."
  :syntax-table emacs-lisp-mode-syntax-table
  (when backtrace-fontify
    (setq font-lock-defaults
          '((backtrace-font-lock-keywords
             backtrace-font-lock-keywords-1
             backtrace-font-lock-keywords-2)
            nil nil nil nil
	    (font-lock-syntactic-face-function
	     . lisp-font-lock-syntactic-face-function))))
  (setq truncate-lines t)
  (buffer-disable-undo)
  ;; In debug.el, from 1998 to 2009 this was set to nil, reason stated
  ;; was because of bytecode. Since 2009 it's been set to t, but the
  ;; default is t so I think this isn't necessary.
  ;; (set-buffer-multibyte t)
  (setq-local revert-buffer-function #'backtrace-revert)
  (setq-local filter-buffer-substring-function #'backtrace--filter-visible)
  (setq-local indent-line-function #'lisp-indent-line)
  (setq-local indent-region-function #'lisp-indent-region)
  (add-function :around (local 'cl-print-expand-ellipsis-function)
                #'backtrace--expand-ellipsis)
  (add-hook 'xref-backend-functions #'backtrace--xref-backend nil t))