aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGemini Lasswell2018-07-21 12:27:32 -0700
committerGemini Lasswell2018-08-03 08:54:08 -0700
commit3cd6a6846b5f8f67216eba61b761a0e1daff7895 (patch)
treeaa3c4afdb3b943234eb6e1eab09e8ac86410fd18
parent83af893fc0e7cc87c0fb0626fb48ef96e00b3f8b (diff)
downloademacs-3cd6a6846b5f8f67216eba61b761a0e1daff7895.tar.gz
emacs-3cd6a6846b5f8f67216eba61b761a0e1daff7895.zip
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.
-rw-r--r--lisp/emacs-lisp/backtrace.el38
-rw-r--r--test/lisp/emacs-lisp/backtrace-tests.el20
2 files changed, 28 insertions, 30 deletions
diff --git a/lisp/emacs-lisp/backtrace.el b/lisp/emacs-lisp/backtrace.el
index d162983c017..f13b43b465c 100644
--- a/lisp/emacs-lisp/backtrace.el
+++ b/lisp/emacs-lisp/backtrace.el
@@ -206,8 +206,8 @@ frames where the source code location is known.")
206 (define-key map "#" 'backtrace-toggle-print-circle) 206 (define-key map "#" 'backtrace-toggle-print-circle)
207 (define-key map "s" 'backtrace-goto-source) 207 (define-key map "s" 'backtrace-goto-source)
208 (define-key map "\C-m" 'backtrace-help-follow-symbol) 208 (define-key map "\C-m" 'backtrace-help-follow-symbol)
209 (define-key map "+" 'backtrace-pretty-print) 209 (define-key map "+" 'backtrace-multi-line)
210 (define-key map "-" 'backtrace-collapse) 210 (define-key map "-" 'backtrace-single-line)
211 (define-key map "." 'backtrace-expand-ellipses) 211 (define-key map "." 'backtrace-expand-ellipses)
212 (define-key map [follow-link] 'mouse-face) 212 (define-key map [follow-link] 'mouse-face)
213 (define-key map [mouse-2] 'mouse-select-window) 213 (define-key map [mouse-2] 'mouse-select-window)
@@ -225,9 +225,9 @@ frames where the source code location is known.")
225 :help "Show or hide the local variables for the frame at point"] 225 :help "Show or hide the local variables for the frame at point"]
226 ["Expand \"...\"s" backtrace-expand-ellipses 226 ["Expand \"...\"s" backtrace-expand-ellipses
227 :help "Expand all the abbreviated forms in the current frame"] 227 :help "Expand all the abbreviated forms in the current frame"]
228 ["Show on Multiple Lines" backtrace-pretty-print 228 ["Show on Multiple Lines" backtrace-multi-line
229 :help "Use line breaks and indentation to make a form more readable"] 229 :help "Use line breaks and indentation to make a form more readable"]
230 ["Collapse to Single Line" backtrace-collapse] 230 ["Show on Single Line" backtrace-single-line]
231 "--" 231 "--"
232 ["Go to Source" backtrace-goto-source 232 ["Go to Source" backtrace-goto-source
233 :active (and (backtrace-get-index) 233 :active (and (backtrace-get-index)
@@ -524,37 +524,36 @@ initial state of the Backtrace buffer."
524 (push-button (point))) 524 (push-button (point)))
525 (goto-char next)))))) 525 (goto-char next))))))
526 526
527(defun backtrace-pretty-print () 527(defun backtrace-multi-line ()
528 "Pretty-print the top level s-expression at point." 528 "Show the top level s-expression at point on multiple lines with indentation."
529 (interactive) 529 (interactive)
530 (backtrace--reformat-sexp #'backtrace--pretty-print 530 (backtrace--reformat-sexp #'backtrace--multi-line))
531 "No form here to pretty-print"))
532 531
533(defun backtrace--pretty-print () 532(defun backtrace--multi-line ()
534 "Pretty print the current buffer, then remove the trailing newline." 533 "Pretty print the current buffer, then remove the trailing newline."
535 (set-syntax-table emacs-lisp-mode-syntax-table) 534 (set-syntax-table emacs-lisp-mode-syntax-table)
536 (pp-buffer) 535 (pp-buffer)
537 (goto-char (1- (point-max))) 536 (goto-char (1- (point-max)))
538 (delete-char 1)) 537 (delete-char 1))
539 538
540(defun backtrace-collapse () 539(defun backtrace-single-line ()
541 "Collapse the top level s-expression at point onto one line." 540 "Show the top level s-expression at point on one line."
542 (interactive) 541 (interactive)
543 (backtrace--reformat-sexp #'backtrace--collapse "No form here to collapse")) 542 (backtrace--reformat-sexp #'backtrace--single-line))
544 543
545(defun backtrace--collapse () 544(defun backtrace--single-line ()
546 "Replace line breaks and following indentation with spaces. 545 "Replace line breaks and following indentation with spaces.
547Works on the current buffer." 546Works on the current buffer."
548 (goto-char (point-min)) 547 (goto-char (point-min))
549 (while (re-search-forward "\n[[:blank:]]*" nil t) 548 (while (re-search-forward "\n[[:blank:]]*" nil t)
550 (replace-match " "))) 549 (replace-match " ")))
551 550
552(defun backtrace--reformat-sexp (format-function error-message) 551(defun backtrace--reformat-sexp (format-function)
553 "Reformat the top level sexp at point. 552 "Reformat the top level sexp at point.
554Locate the top level sexp at or following point on the same line, 553Locate the top level sexp at or following point on the same line,
555and reformat it with FORMAT-FUNCTION, preserving the location of 554and reformat it with FORMAT-FUNCTION, preserving the location of
556point within the sexp. If no sexp is found before the end of 555point within the sexp. If no sexp is found before the end of
557the line or buffer, show ERROR-MESSAGE instead. 556the line or buffer, signal an error.
558 557
559FORMAT-FUNCTION will be called without arguments, with the 558FORMAT-FUNCTION will be called without arguments, with the
560current buffer set to a temporary buffer containing only the 559current buffer set to a temporary buffer containing only the
@@ -567,7 +566,7 @@ content of the sexp."
567 nil (point-min)))) 566 nil (point-min))))
568 (unless tag 567 (unless tag
569 (when (or (= end (point-max)) (> end (point-at-eol))) 568 (when (or (= end (point-max)) (> end (point-at-eol)))
570 (user-error error-message)) 569 (user-error "No form here to reformat"))
571 (goto-char end) 570 (goto-char end)
572 (setq pos end 571 (setq pos end
573 end (next-single-property-change pos 'backtrace-form) 572 end (next-single-property-change pos 'backtrace-form)
@@ -752,10 +751,9 @@ Format it according to VIEW."
752 (insert (backtrace--print-to-string 751 (insert (backtrace--print-to-string
753 args (max (truncate (/ backtrace-line-length 5)) 752 args (max (truncate (/ backtrace-line-length 5))
754 (- backtrace-line-length (- (point) beg))))) 753 (- backtrace-line-length (- (point) beg)))))
755 ;; The backtrace-form property is so that 754 ;; The backtrace-form property is so that backtrace-multi-line
756 ;; backtrace-pretty-print will find it. 755 ;; will find it. backtrace-multi-line doesn't do anything
757 ;; backtrace-pretty-print doesn't do anything useful with it, 756 ;; useful with it, just being consistent.
758 ;; just being consistent.
759 (let ((start (point))) 757 (let ((start (point)))
760 (insert "()") 758 (insert "()")
761 (put-text-property start (point) 'backtrace-form t)))) 759 (put-text-property start (point) 'backtrace-form t))))
diff --git a/test/lisp/emacs-lisp/backtrace-tests.el b/test/lisp/emacs-lisp/backtrace-tests.el
index ff26112ab9a..edd45c770c5 100644
--- a/test/lisp/emacs-lisp/backtrace-tests.el
+++ b/test/lisp/emacs-lisp/backtrace-tests.el
@@ -222,9 +222,9 @@
222 (goto-char (point-max)) 222 (goto-char (point-max))
223 (should-error (backtrace-forward-frame))))) 223 (should-error (backtrace-forward-frame)))))
224 224
225(ert-deftest backtrace-tests--pretty-print-and-collapse () 225(ert-deftest backtrace-tests--single-and-multi-line ()
226 "Forms in backtrace frames can be pretty-printed and collapsed." 226 "Forms in backtrace frames can be on a single line or on multiple lines."
227 (ert-with-test-buffer (:name "pp-and-collapse") 227 (ert-with-test-buffer (:name "single-multi-line")
228 (let* ((arg '(lambda (x) ; Quote this so it isn't made into a closure. 228 (let* ((arg '(lambda (x) ; Quote this so it isn't made into a closure.
229 (let ((number (1+ x))) 229 (let ((number (1+ x)))
230 (+ x number)))) 230 (+ x number))))
@@ -249,25 +249,25 @@
249 results)) 249 results))
250 ;; Check pp and collapse for the form in the header. 250 ;; Check pp and collapse for the form in the header.
251 (goto-char (point-min)) 251 (goto-char (point-min))
252 (backtrace-tests--verify-pp-and-collapse header) 252 (backtrace-tests--verify-single-and-multi-line header)
253 ;; Check pp and collapse for the last frame. 253 ;; Check pp and collapse for the last frame.
254 (goto-char (point-max)) 254 (goto-char (point-max))
255 (backtrace-backward-frame) 255 (backtrace-backward-frame)
256 (backtrace-tests--verify-pp-and-collapse last-line) 256 (backtrace-tests--verify-single-and-multi-line last-line)
257 ;; Check pp and collapse for local variables in the last line. 257 ;; Check pp and collapse for local variables in the last line.
258 (goto-char (point-max)) 258 (goto-char (point-max))
259 (backtrace-backward-frame) 259 (backtrace-backward-frame)
260 (backtrace-toggle-locals) 260 (backtrace-toggle-locals)
261 (forward-line) 261 (forward-line)
262 (backtrace-tests--verify-pp-and-collapse last-line-locals)))) 262 (backtrace-tests--verify-single-and-multi-line last-line-locals))))
263 263
264(defun backtrace-tests--verify-pp-and-collapse (line) 264(defun backtrace-tests--verify-single-and-multi-line (line)
265 "Verify that `backtrace-pretty-print' and `backtrace-collapse' work at point. 265 "Verify that `backtrace-single-line' and `backtrace-multi-line' work at point.
266Point should be at the beginning of a line, and LINE should be a 266Point should be at the beginning of a line, and LINE should be a
267string containing the text of the line at point. Assume that the 267string containing the text of the line at point. Assume that the
268line contains the strings \"lambda\" and \"number\"." 268line contains the strings \"lambda\" and \"number\"."
269 (let ((pos (point))) 269 (let ((pos (point)))
270 (backtrace-pretty-print) 270 (backtrace-multi-line)
271 ;; Verify point is still at the start of the line. 271 ;; Verify point is still at the start of the line.
272 (should (= pos (point)))) 272 (should (= pos (point))))
273 273
@@ -276,7 +276,7 @@ line contains the strings \"lambda\" and \"number\"."
276 (search-forward "number") 276 (search-forward "number")
277 (should-not (= pos (point-at-bol)))) 277 (should-not (= pos (point-at-bol))))
278 ;; Collapse the form. 278 ;; Collapse the form.
279 (backtrace-collapse) 279 (backtrace-single-line)
280 ;; Verify that the form is now back on one line, 280 ;; Verify that the form is now back on one line,
281 ;; and that point is at the same place. 281 ;; and that point is at the same place.
282 (should (string= (backtrace-tests--get-substring 282 (should (string= (backtrace-tests--get-substring