Commit e1f00930 authored by Fabián Ezequiel Gallina's avatar Fabián Ezequiel Gallina Committed by Fabián Ezequiel Gallina
Browse files

Enhancements to pdbtrack.

pdbtrack now handles correctly the case where the stacktrace
information is on the second line.

All python buffers not opened by the user and used for tracking are
closed automatically when tracking process finishes.

Simplified code for keeping the tracked buffer.

Removed vars:
 + python-pdbtrack-tracking-buffers

Removed functions:
 + python-pdbtrack-get-or-add-tracking-buffers

New vars:
 + python-pdbtrack-tracked-buffer
 + python-pdbtrack-buffers-to-kill

New functions:
 + python-pdbtrack-set-tracked-buffer
parent aeac8c27
...@@ -1680,28 +1680,27 @@ Used to extract the current line and module being inspected." ...@@ -1680,28 +1680,27 @@ Used to extract the current line and module being inspected."
:group 'python :group 'python
:safe 'stringp) :safe 'stringp)
(defvar python-pdbtrack-tracking-buffers nil (defvar python-pdbtrack-tracked-buffer nil
"Alist containing elements of form (#<buffer> . #<buffer>). "Variable containing the value of the current tracked buffer.
The car of each element of the alist is the tracking buffer and Never set this variable directly, use
the cdr is the tracked buffer.") `python-pdbtrack-set-tracked-buffer' instead.")
(make-variable-buffer-local 'python-pdbtrack-tracked-buffer)
(defun python-pdbtrack-get-or-add-tracking-buffers (file-name)
"Get/Add a tracked buffer for the current buffer and FILE-NAME. (defvar python-pdbtrack-buffers-to-kill nil
Internally it uses the `python-pdbtrack-tracking-buffers' alist. "List of buffers to be deleted after tracking finishes.")
Returns a cons with the form: (make-variable-buffer-local 'python-pdbtrack-buffers-to-kill)
* (#<tracking buffer> . #< tracked buffer>)."
(let ((tracking-buffers (defun python-pdbtrack-set-tracked-buffer (file-name)
(cons (current-buffer) "Set the buffer for FILE-NAME as the tracked buffer.
(or (get-file-buffer file-name) Internally it uses the `python-pdbtrack-tracked-buffer' variable.
(find-file-noselect file-name))))) Returns the tracked buffer."
(set-buffer (cdr tracking-buffers)) (let ((file-buffer (get-file-buffer file-name)))
(when (not (eq major-mode 'python-mode)) (if file-buffer
(python-mode)) (setq python-pdbtrack-tracked-buffer file-buffer)
(set-buffer (car tracking-buffers)) (setq file-buffer (find-file-noselect file-name))
(assq-delete-all (current-buffer) python-pdbtrack-tracking-buffers) (when (not (member file-buffer python-pdbtrack-buffers-to-kill))
(setq python-pdbtrack-tracking-buffers (add-to-list 'python-pdbtrack-buffers-to-kill file-buffer)))
(cons tracking-buffers python-pdbtrack-tracking-buffers)) file-buffer))
tracking-buffers))
(defun python-pdbtrack-comint-output-filter-function (output) (defun python-pdbtrack-comint-output-filter-function (output)
"Move overlay arrow to current pdb line in tracked buffer. "Move overlay arrow to current pdb line in tracked buffer.
...@@ -1712,21 +1711,24 @@ Argument OUTPUT is a string with the output from the comint process." ...@@ -1712,21 +1711,24 @@ Argument OUTPUT is a string with the output from the comint process."
(line-number) (line-number)
(file-name (file-name
(with-temp-buffer (with-temp-buffer
;; OK, this sucks but for some reason
;; string-match was not doing his trick.
(insert full-output) (insert full-output)
(goto-char (point-min)) (goto-char (point-min))
(when (looking-at python-pdbtrack-stacktrace-info-regexp) ;; OK, this sucked but now it became a cool hack. The
;; stacktrace information normally is on the first line
;; but in some cases (like when doing a step-in) it is
;; on the second.
(when (or (looking-at python-pdbtrack-stacktrace-info-regexp)
(and (forward-line)
(looking-at python-pdbtrack-stacktrace-info-regexp)))
(setq line-number (string-to-number (setq line-number (string-to-number
(match-string-no-properties 2))) (match-string-no-properties 2)))
(match-string-no-properties 1))))) (match-string-no-properties 1)))))
(if (and file-name line-number) (if (and file-name line-number)
(let* ((tracking-buffers (let* ((tracked-buffer (python-pdbtrack-set-tracked-buffer file-name))
(python-pdbtrack-get-or-add-tracking-buffers file-name)) (shell-buffer (current-buffer))
(tracked-buffer-window (tracked-buffer-window (get-buffer-window tracked-buffer))
(get-buffer-window (cdr tracking-buffers)))
(tracked-buffer-line-pos)) (tracked-buffer-line-pos))
(with-current-buffer (cdr tracking-buffers) (with-current-buffer tracked-buffer
(set (make-local-variable 'overlay-arrow-string) "=>") (set (make-local-variable 'overlay-arrow-string) "=>")
(set (make-local-variable 'overlay-arrow-position) (make-marker)) (set (make-local-variable 'overlay-arrow-position) (make-marker))
(setq tracked-buffer-line-pos (progn (setq tracked-buffer-line-pos (progn
...@@ -1737,16 +1739,16 @@ Argument OUTPUT is a string with the output from the comint process." ...@@ -1737,16 +1739,16 @@ Argument OUTPUT is a string with the output from the comint process."
(set-window-point (set-window-point
tracked-buffer-window tracked-buffer-line-pos)) tracked-buffer-window tracked-buffer-line-pos))
(set-marker overlay-arrow-position tracked-buffer-line-pos)) (set-marker overlay-arrow-position tracked-buffer-line-pos))
(pop-to-buffer (cdr tracking-buffers)) (pop-to-buffer tracked-buffer)
(switch-to-buffer-other-window (car tracking-buffers))) (switch-to-buffer-other-window shell-buffer))
(let ((tracking-buffers (assq (current-buffer) (when python-pdbtrack-tracked-buffer
python-pdbtrack-tracking-buffers))) (with-current-buffer python-pdbtrack-tracked-buffer
(when tracking-buffers (set-marker overlay-arrow-position nil))
(with-current-buffer (cdr tracking-buffers) (mapc #'(lambda (buffer)
(set-marker overlay-arrow-position nil)) (ignore-errors (kill-buffer buffer)))
(setq python-pdbtrack-tracking-buffers python-pdbtrack-buffers-to-kill)
(assq-delete-all (current-buffer) (setq python-pdbtrack-tracked-buffer nil
python-pdbtrack-tracking-buffers))))))) python-pdbtrack-buffers-to-kill nil)))))
output) output)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment