diff options
| author | Gemini Lasswell | 2018-07-07 12:48:18 -0700 |
|---|---|---|
| committer | Gemini Lasswell | 2018-08-03 08:53:02 -0700 |
| commit | af5f3771fd49bba579d3a2047bab1b278317eb5f (patch) | |
| tree | 23c8a48df09f4033b3aebb3a2e957463dc8127f1 | |
| parent | 9aa9d79e4420f367242312aedd61594fd173dec6 (diff) | |
| download | emacs-af5f3771fd49bba579d3a2047bab1b278317eb5f.tar.gz emacs-af5f3771fd49bba579d3a2047bab1b278317eb5f.zip | |
Add link in backtraces to position in buffer being evaluated (bug#14081)
* lisp/emacs-lisp/backtrace.el (backtrace-frame): Add buffer field.
(backtrace-get-frames): Set buffer field of frame.
(backtrace-buffer-pos): New button type.
(backtrace--pop-to-buffer-pos): New function.
(backtrace--print-func-and-args): Create a button for the buffer
position if it is set.
| -rw-r--r-- | lisp/emacs-lisp/backtrace.el | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/backtrace.el b/lisp/emacs-lisp/backtrace.el index bec57f29245..aac43fec8e4 100644 --- a/lisp/emacs-lisp/backtrace.el +++ b/lisp/emacs-lisp/backtrace.el | |||
| @@ -65,7 +65,7 @@ guaranteed." | |||
| 65 | (cl-defstruct | 65 | (cl-defstruct |
| 66 | (backtrace-frame | 66 | (backtrace-frame |
| 67 | (:constructor backtrace-make-frame)) | 67 | (:constructor backtrace-make-frame)) |
| 68 | evald fun args flags locals pos) | 68 | evald fun args flags locals buffer pos) |
| 69 | 69 | ||
| 70 | (cl-defun backtrace-get-frames | 70 | (cl-defun backtrace-get-frames |
| 71 | (&optional base &key (constructor #'backtrace-make-frame)) | 71 | (&optional base &key (constructor #'backtrace-make-frame)) |
| @@ -102,9 +102,26 @@ frames before its nearest activation frame are discarded." | |||
| 102 | ;; eval-region calls for the same buffer. That's not a very | 102 | ;; eval-region calls for the same buffer. That's not a very |
| 103 | ;; useful case. | 103 | ;; useful case. |
| 104 | (with-current-buffer (pop eval-buffers) | 104 | (with-current-buffer (pop eval-buffers) |
| 105 | (setf (backtrace-frame-buffer frame) (current-buffer)) | ||
| 105 | (setf (backtrace-frame-pos frame) (point)))))) | 106 | (setf (backtrace-frame-pos frame) (point)))))) |
| 106 | frames)) | 107 | frames)) |
| 107 | 108 | ||
| 109 | ;; Button definition for jumping to a buffer position. | ||
| 110 | |||
| 111 | (define-button-type 'backtrace-buffer-pos | ||
| 112 | 'action #'backtrace--pop-to-buffer-pos | ||
| 113 | 'help-echo "mouse-2, RET: Show reading position") | ||
| 114 | |||
| 115 | (defun backtrace--pop-to-buffer-pos (button) | ||
| 116 | "Pop to the buffer and position for the BUTTON at point." | ||
| 117 | (let* ((buffer (button-get button 'backtrace-buffer)) | ||
| 118 | (pos (button-get button 'backtrace-pos))) | ||
| 119 | (if (buffer-live-p buffer) | ||
| 120 | (progn | ||
| 121 | (pop-to-buffer buffer) | ||
| 122 | (goto-char (max (point-min) (min (point-max) pos)))) | ||
| 123 | (message "Buffer has been killed")))) | ||
| 124 | |||
| 108 | ;; Font Locking support | 125 | ;; Font Locking support |
| 109 | 126 | ||
| 110 | (defconst backtrace--font-lock-keywords | 127 | (defconst backtrace--font-lock-keywords |
| @@ -685,8 +702,12 @@ Format it according to VIEW." | |||
| 685 | ;; After any frame that uses eval-buffer, insert a comment that | 702 | ;; After any frame that uses eval-buffer, insert a comment that |
| 686 | ;; states the buffer position it's reading at. | 703 | ;; states the buffer position it's reading at. |
| 687 | (when (backtrace-frame-pos frame) | 704 | (when (backtrace-frame-pos frame) |
| 688 | (insert (format " ; Reading at buffer position %d" | 705 | (insert " ; Reading at ") |
| 689 | (backtrace-frame-pos frame)))) | 706 | (let ((pos (point))) |
| 707 | (insert (format "buffer position %d" (backtrace-frame-pos frame))) | ||
| 708 | (make-button pos (point) :type 'backtrace-buffer-pos | ||
| 709 | 'backtrace-buffer (backtrace-frame-buffer frame) | ||
| 710 | 'backtrace-pos (backtrace-frame-pos frame)))) | ||
| 690 | (insert "\n") | 711 | (insert "\n") |
| 691 | (put-text-property beg (point) 'backtrace-section 'func))) | 712 | (put-text-property beg (point) 'backtrace-section 'func))) |
| 692 | 713 | ||