(define-key map "#" 'backtrace-toggle-print-circle)
(define-key map "s" 'backtrace-goto-source)
(define-key map "\C-m" 'backtrace-help-follow-symbol)
- (define-key map "+" 'backtrace-pretty-print)
- (define-key map "-" 'backtrace-collapse)
+ (define-key map "+" 'backtrace-multi-line)
+ (define-key map "-" 'backtrace-single-line)
(define-key map "." 'backtrace-expand-ellipses)
(define-key map [follow-link] 'mouse-face)
(define-key map [mouse-2] 'mouse-select-window)
:help "Show or hide the local variables for the frame at point"]
["Expand \"...\"s" backtrace-expand-ellipses
:help "Expand all the abbreviated forms in the current frame"]
- ["Show on Multiple Lines" backtrace-pretty-print
+ ["Show on Multiple Lines" backtrace-multi-line
:help "Use line breaks and indentation to make a form more readable"]
- ["Collapse to Single Line" backtrace-collapse]
+ ["Show on Single Line" backtrace-single-line]
"--"
["Go to Source" backtrace-goto-source
:active (and (backtrace-get-index)
(push-button (point)))
(goto-char next))))))
-(defun backtrace-pretty-print ()
- "Pretty-print the top level s-expression at point."
+(defun backtrace-multi-line ()
+ "Show the top level s-expression at point on multiple lines with indentation."
(interactive)
- (backtrace--reformat-sexp #'backtrace--pretty-print
- "No form here to pretty-print"))
+ (backtrace--reformat-sexp #'backtrace--multi-line))
-(defun backtrace--pretty-print ()
+(defun backtrace--multi-line ()
"Pretty print the current buffer, then remove the trailing newline."
(set-syntax-table emacs-lisp-mode-syntax-table)
(pp-buffer)
(goto-char (1- (point-max)))
(delete-char 1))
-(defun backtrace-collapse ()
- "Collapse the top level s-expression at point onto one line."
+(defun backtrace-single-line ()
+ "Show the top level s-expression at point on one line."
(interactive)
- (backtrace--reformat-sexp #'backtrace--collapse "No form here to collapse"))
+ (backtrace--reformat-sexp #'backtrace--single-line))
-(defun backtrace--collapse ()
+(defun backtrace--single-line ()
"Replace line breaks and following indentation with spaces.
Works on the current buffer."
(goto-char (point-min))
(while (re-search-forward "\n[[:blank:]]*" nil t)
(replace-match " ")))
-(defun backtrace--reformat-sexp (format-function error-message)
+(defun backtrace--reformat-sexp (format-function)
"Reformat the top level sexp at point.
Locate the top level sexp at or following point on the same line,
and reformat it with FORMAT-FUNCTION, preserving the location of
point within the sexp. If no sexp is found before the end of
-the line or buffer, show ERROR-MESSAGE instead.
+the line or buffer, signal an error.
FORMAT-FUNCTION will be called without arguments, with the
current buffer set to a temporary buffer containing only the
nil (point-min))))
(unless tag
(when (or (= end (point-max)) (> end (point-at-eol)))
- (user-error error-message))
+ (user-error "No form here to reformat"))
(goto-char end)
(setq pos end
end (next-single-property-change pos 'backtrace-form)
(insert (backtrace--print-to-string
args (max (truncate (/ backtrace-line-length 5))
(- backtrace-line-length (- (point) beg)))))
- ;; The backtrace-form property is so that
- ;; backtrace-pretty-print will find it.
- ;; backtrace-pretty-print doesn't do anything useful with it,
- ;; just being consistent.
+ ;; The backtrace-form property is so that backtrace-multi-line
+ ;; will find it. backtrace-multi-line doesn't do anything
+ ;; useful with it, just being consistent.
(let ((start (point)))
(insert "()")
(put-text-property start (point) 'backtrace-form t))))
(goto-char (point-max))
(should-error (backtrace-forward-frame)))))
-(ert-deftest backtrace-tests--pretty-print-and-collapse ()
- "Forms in backtrace frames can be pretty-printed and collapsed."
- (ert-with-test-buffer (:name "pp-and-collapse")
+(ert-deftest backtrace-tests--single-and-multi-line ()
+ "Forms in backtrace frames can be on a single line or on multiple lines."
+ (ert-with-test-buffer (:name "single-multi-line")
(let* ((arg '(lambda (x) ; Quote this so it isn't made into a closure.
(let ((number (1+ x)))
(+ x number))))
results))
;; Check pp and collapse for the form in the header.
(goto-char (point-min))
- (backtrace-tests--verify-pp-and-collapse header)
+ (backtrace-tests--verify-single-and-multi-line header)
;; Check pp and collapse for the last frame.
(goto-char (point-max))
(backtrace-backward-frame)
- (backtrace-tests--verify-pp-and-collapse last-line)
+ (backtrace-tests--verify-single-and-multi-line last-line)
;; Check pp and collapse for local variables in the last line.
(goto-char (point-max))
(backtrace-backward-frame)
(backtrace-toggle-locals)
(forward-line)
- (backtrace-tests--verify-pp-and-collapse last-line-locals))))
+ (backtrace-tests--verify-single-and-multi-line last-line-locals))))
-(defun backtrace-tests--verify-pp-and-collapse (line)
- "Verify that `backtrace-pretty-print' and `backtrace-collapse' work at point.
+(defun backtrace-tests--verify-single-and-multi-line (line)
+ "Verify that `backtrace-single-line' and `backtrace-multi-line' work at point.
Point should be at the beginning of a line, and LINE should be a
string containing the text of the line at point. Assume that the
line contains the strings \"lambda\" and \"number\"."
(let ((pos (point)))
- (backtrace-pretty-print)
+ (backtrace-multi-line)
;; Verify point is still at the start of the line.
(should (= pos (point))))
(search-forward "number")
(should-not (= pos (point-at-bol))))
;; Collapse the form.
- (backtrace-collapse)
+ (backtrace-single-line)
;; Verify that the form is now back on one line,
;; and that point is at the same place.
(should (string= (backtrace-tests--get-substring