diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 89f454ed95b..17afb0ee309 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1680,28 +1680,27 @@ Used to extract the current line and module being inspected." | |||
| 1680 | :group 'python | 1680 | :group 'python |
| 1681 | :safe 'stringp) | 1681 | :safe 'stringp) |
| 1682 | 1682 | ||
| 1683 | (defvar python-pdbtrack-tracking-buffers nil | 1683 | (defvar python-pdbtrack-tracked-buffer nil |
| 1684 | "Alist containing elements of form (#<buffer> . #<buffer>). | 1684 | "Variable containing the value of the current tracked buffer. |
| 1685 | The car of each element of the alist is the tracking buffer and | 1685 | Never set this variable directly, use |
| 1686 | the cdr is the tracked buffer.") | 1686 | `python-pdbtrack-set-tracked-buffer' instead.") |
| 1687 | 1687 | (make-variable-buffer-local 'python-pdbtrack-tracked-buffer) | |
| 1688 | (defun python-pdbtrack-get-or-add-tracking-buffers (file-name) | 1688 | |
| 1689 | "Get/Add a tracked buffer for the current buffer and FILE-NAME. | 1689 | (defvar python-pdbtrack-buffers-to-kill nil |
| 1690 | Internally it uses the `python-pdbtrack-tracking-buffers' alist. | 1690 | "List of buffers to be deleted after tracking finishes.") |
| 1691 | Returns a cons with the form: | 1691 | (make-variable-buffer-local 'python-pdbtrack-buffers-to-kill) |
| 1692 | * (#<tracking buffer> . #< tracked buffer>)." | 1692 | |
| 1693 | (let ((tracking-buffers | 1693 | (defun python-pdbtrack-set-tracked-buffer (file-name) |
| 1694 | (cons (current-buffer) | 1694 | "Set the buffer for FILE-NAME as the tracked buffer. |
| 1695 | (or (get-file-buffer file-name) | 1695 | Internally it uses the `python-pdbtrack-tracked-buffer' variable. |
| 1696 | (find-file-noselect file-name))))) | 1696 | Returns the tracked buffer." |
| 1697 | (set-buffer (cdr tracking-buffers)) | 1697 | (let ((file-buffer (get-file-buffer file-name))) |
| 1698 | (when (not (eq major-mode 'python-mode)) | 1698 | (if file-buffer |
| 1699 | (python-mode)) | 1699 | (setq python-pdbtrack-tracked-buffer file-buffer) |
| 1700 | (set-buffer (car tracking-buffers)) | 1700 | (setq file-buffer (find-file-noselect file-name)) |
| 1701 | (assq-delete-all (current-buffer) python-pdbtrack-tracking-buffers) | 1701 | (when (not (member file-buffer python-pdbtrack-buffers-to-kill)) |
| 1702 | (setq python-pdbtrack-tracking-buffers | 1702 | (add-to-list 'python-pdbtrack-buffers-to-kill file-buffer))) |
| 1703 | (cons tracking-buffers python-pdbtrack-tracking-buffers)) | 1703 | file-buffer)) |
| 1704 | tracking-buffers)) | ||
| 1705 | 1704 | ||
| 1706 | (defun python-pdbtrack-comint-output-filter-function (output) | 1705 | (defun python-pdbtrack-comint-output-filter-function (output) |
| 1707 | "Move overlay arrow to current pdb line in tracked buffer. | 1706 | "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 | (line-number) | 1711 | (line-number) |
| 1713 | (file-name | 1712 | (file-name |
| 1714 | (with-temp-buffer | 1713 | (with-temp-buffer |
| 1715 | ;; OK, this sucks but for some reason | ||
| 1716 | ;; string-match was not doing his trick. | ||
| 1717 | (insert full-output) | 1714 | (insert full-output) |
| 1718 | (goto-char (point-min)) | 1715 | (goto-char (point-min)) |
| 1719 | (when (looking-at python-pdbtrack-stacktrace-info-regexp) | 1716 | ;; OK, this sucked but now it became a cool hack. The |
| 1717 | ;; stacktrace information normally is on the first line | ||
| 1718 | ;; but in some cases (like when doing a step-in) it is | ||
| 1719 | ;; on the second. | ||
| 1720 | (when (or (looking-at python-pdbtrack-stacktrace-info-regexp) | ||
| 1721 | (and (forward-line) | ||
| 1722 | (looking-at python-pdbtrack-stacktrace-info-regexp))) | ||
| 1720 | (setq line-number (string-to-number | 1723 | (setq line-number (string-to-number |
| 1721 | (match-string-no-properties 2))) | 1724 | (match-string-no-properties 2))) |
| 1722 | (match-string-no-properties 1))))) | 1725 | (match-string-no-properties 1))))) |
| 1723 | (if (and file-name line-number) | 1726 | (if (and file-name line-number) |
| 1724 | (let* ((tracking-buffers | 1727 | (let* ((tracked-buffer (python-pdbtrack-set-tracked-buffer file-name)) |
| 1725 | (python-pdbtrack-get-or-add-tracking-buffers file-name)) | 1728 | (shell-buffer (current-buffer)) |
| 1726 | (tracked-buffer-window | 1729 | (tracked-buffer-window (get-buffer-window tracked-buffer)) |
| 1727 | (get-buffer-window (cdr tracking-buffers))) | ||
| 1728 | (tracked-buffer-line-pos)) | 1730 | (tracked-buffer-line-pos)) |
| 1729 | (with-current-buffer (cdr tracking-buffers) | 1731 | (with-current-buffer tracked-buffer |
| 1730 | (set (make-local-variable 'overlay-arrow-string) "=>") | 1732 | (set (make-local-variable 'overlay-arrow-string) "=>") |
| 1731 | (set (make-local-variable 'overlay-arrow-position) (make-marker)) | 1733 | (set (make-local-variable 'overlay-arrow-position) (make-marker)) |
| 1732 | (setq tracked-buffer-line-pos (progn | 1734 | (setq tracked-buffer-line-pos (progn |
| @@ -1737,16 +1739,16 @@ Argument OUTPUT is a string with the output from the comint process." | |||
| 1737 | (set-window-point | 1739 | (set-window-point |
| 1738 | tracked-buffer-window tracked-buffer-line-pos)) | 1740 | tracked-buffer-window tracked-buffer-line-pos)) |
| 1739 | (set-marker overlay-arrow-position tracked-buffer-line-pos)) | 1741 | (set-marker overlay-arrow-position tracked-buffer-line-pos)) |
| 1740 | (pop-to-buffer (cdr tracking-buffers)) | 1742 | (pop-to-buffer tracked-buffer) |
| 1741 | (switch-to-buffer-other-window (car tracking-buffers))) | 1743 | (switch-to-buffer-other-window shell-buffer)) |
| 1742 | (let ((tracking-buffers (assq (current-buffer) | 1744 | (when python-pdbtrack-tracked-buffer |
| 1743 | python-pdbtrack-tracking-buffers))) | 1745 | (with-current-buffer python-pdbtrack-tracked-buffer |
| 1744 | (when tracking-buffers | 1746 | (set-marker overlay-arrow-position nil)) |
| 1745 | (with-current-buffer (cdr tracking-buffers) | 1747 | (mapc #'(lambda (buffer) |
| 1746 | (set-marker overlay-arrow-position nil)) | 1748 | (ignore-errors (kill-buffer buffer))) |
| 1747 | (setq python-pdbtrack-tracking-buffers | 1749 | python-pdbtrack-buffers-to-kill) |
| 1748 | (assq-delete-all (current-buffer) | 1750 | (setq python-pdbtrack-tracked-buffer nil |
| 1749 | python-pdbtrack-tracking-buffers))))))) | 1751 | python-pdbtrack-buffers-to-kill nil))))) |
| 1750 | output) | 1752 | output) |
| 1751 | 1753 | ||
| 1752 | 1754 | ||