mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-18 18:05:07 +00:00
Give two backtrace-mode commands better names
* lisp/emacs-lisp/backtrace.el (backtrace-mode-map): Update bindings and menu items with new function names. (backtrace-collapse, backtrace-pretty-print) (backtrace--collapse, backtrace--pretty-print): Remove functions. (backtrace-single-line, backtrace-multi-line) (backtrace--single-line, backtrace--multi-line): New functions. (backtrace--reformat-sexp): Remove 'error-message' argument. * test/lisp/emacs-lisp/backtrace-tests.el (backtrace-tests--pretty-print-and-collapse): Remove. (backtrace-tests--single-and-multi-line): New test. (backtrace-tests--verify-pp-and-collapse): Remove. (backtrace-tests--verify-single-and-multi-line): New function.
This commit is contained in:
parent
83af893fc0
commit
3cd6a6846b
@ -206,8 +206,8 @@ frames where the source code location is known.")
|
||||
(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)
|
||||
@ -225,9 +225,9 @@ frames where the source code location is known.")
|
||||
: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)
|
||||
@ -524,37 +524,36 @@ initial state of the Backtrace buffer."
|
||||
(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
|
||||
@ -567,7 +566,7 @@ content of the sexp."
|
||||
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)
|
||||
@ -752,10 +751,9 @@ Format it according to VIEW."
|
||||
(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))))
|
||||
|
@ -222,9 +222,9 @@
|
||||
(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))))
|
||||
@ -249,25 +249,25 @@
|
||||
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))))
|
||||
|
||||
@ -276,7 +276,7 @@ line contains the strings \"lambda\" and \"number\"."
|
||||
(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
|
||||
|
Loading…
Reference in New Issue
Block a user