aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:03:28 -0300
committerFabián Ezequiel Gallina2012-05-17 00:03:28 -0300
commitaeac8c27f2bb01fef164634747e0f5bb7cf6702e (patch)
treefcbdee04e709686ef61c7f1f2c09b3925e031058
parent8386d830a364dcd08e7dccaa480e8f7e6bb3fb9d (diff)
downloademacs-aeac8c27f2bb01fef164634747e0f5bb7cf6702e.tar.gz
emacs-aeac8c27f2bb01fef164634747e0f5bb7cf6702e.zip
Enhancements to pdbtrack
pdbtracking now autodetects the filename being tracked from the prompt and not from the `inferior-python-mode-current-file' variable. Removed vars: + `inferior-python-mode-current-file'
-rw-r--r--lisp/progmodes/python.el107
1 files changed, 48 insertions, 59 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 52c9b628b4f..89f454ed95b 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1281,10 +1281,6 @@ uniqueness for different types of configurations."
1281OUTPUT is a string with the contents of the buffer." 1281OUTPUT is a string with the contents of the buffer."
1282 (ansi-color-filter-apply output)) 1282 (ansi-color-filter-apply output))
1283 1283
1284(defvar inferior-python-mode-current-file nil
1285 "Current file from which a region was sent.")
1286(make-variable-buffer-local 'inferior-python-mode-current-file)
1287
1288(define-derived-mode inferior-python-mode comint-mode "Inferior Python" 1284(define-derived-mode inferior-python-mode comint-mode "Inferior Python"
1289 "Major mode for Python inferior process. 1285 "Major mode for Python inferior process.
1290Runs a Python interpreter as a subprocess of Emacs, with Python 1286Runs a Python interpreter as a subprocess of Emacs, with Python
@@ -1530,9 +1526,6 @@ FILE-NAME."
1530 (file-name (or (expand-file-name file-name) temp-file-name))) 1526 (file-name (or (expand-file-name file-name) temp-file-name)))
1531 (when (not file-name) 1527 (when (not file-name)
1532 (error "If FILE-NAME is nil then TEMP-FILE-NAME must be non-nil")) 1528 (error "If FILE-NAME is nil then TEMP-FILE-NAME must be non-nil"))
1533 (with-current-buffer (process-buffer process)
1534 (setq inferior-python-mode-current-file
1535 (convert-standard-filename file-name)))
1536 (python-shell-send-string 1529 (python-shell-send-string
1537 (format 1530 (format
1538 (concat "__pyfile = open('''%s''');" 1531 (concat "__pyfile = open('''%s''');"
@@ -1680,81 +1673,77 @@ to complete."
1680;;; PDB Track integration 1673;;; PDB Track integration
1681 1674
1682(defcustom python-pdbtrack-stacktrace-info-regexp 1675(defcustom python-pdbtrack-stacktrace-info-regexp
1683 "> %s(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()" 1676 "^> \\([^\"(<]+\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()"
1684 "Regular Expression matching stacktrace information. 1677 "Regular Expression matching stacktrace information.
1685Used to extract the current line and module being inspected. The 1678Used to extract the current line and module being inspected."
1686regexp should not start with a caret (^) and can contain a string
1687placeholder (\%s) which is replaced with the filename beign
1688inspected (so other files in the debugging process are not
1689opened)"
1690 :type 'string 1679 :type 'string
1691 :group 'python 1680 :group 'python
1692 :safe 'stringp) 1681 :safe 'stringp)
1693 1682
1694(defvar python-pdbtrack-tracking-buffers '() 1683(defvar python-pdbtrack-tracking-buffers nil
1695 "Alist containing elements of form (#<buffer> . #<buffer>). 1684 "Alist containing elements of form (#<buffer> . #<buffer>).
1696The car of each element of the alist is the tracking buffer and 1685The car of each element of the alist is the tracking buffer and
1697the cdr is the tracked buffer.") 1686the cdr is the tracked buffer.")
1698 1687
1699(defun python-pdbtrack-get-or-add-tracking-buffers () 1688(defun python-pdbtrack-get-or-add-tracking-buffers (file-name)
1700 "Get/Add a tracked buffer for the current buffer. 1689 "Get/Add a tracked buffer for the current buffer and FILE-NAME.
1701Internally it uses the `python-pdbtrack-tracking-buffers' alist. 1690Internally it uses the `python-pdbtrack-tracking-buffers' alist.
1702Returns a cons with the form: 1691Returns a cons with the form:
1703 * (#<tracking buffer> . #< tracked buffer>)." 1692 * (#<tracking buffer> . #< tracked buffer>)."
1704 (or 1693 (let ((tracking-buffers
1705 (assq (current-buffer) python-pdbtrack-tracking-buffers) 1694 (cons (current-buffer)
1706 (let* ((file (with-current-buffer (current-buffer) 1695 (or (get-file-buffer file-name)
1707 inferior-python-mode-current-file)) 1696 (find-file-noselect file-name)))))
1708 (tracking-buffers 1697 (set-buffer (cdr tracking-buffers))
1709 `(,(current-buffer) . 1698 (when (not (eq major-mode 'python-mode))
1710 ,(or (get-file-buffer file) 1699 (python-mode))
1711 (find-file-noselect file))))) 1700 (set-buffer (car tracking-buffers))
1712 (set-buffer (cdr tracking-buffers)) 1701 (assq-delete-all (current-buffer) python-pdbtrack-tracking-buffers)
1713 (python-mode) 1702 (setq python-pdbtrack-tracking-buffers
1714 (set-buffer (car tracking-buffers)) 1703 (cons tracking-buffers python-pdbtrack-tracking-buffers))
1715 (setq python-pdbtrack-tracking-buffers 1704 tracking-buffers))
1716 (cons tracking-buffers python-pdbtrack-tracking-buffers))
1717 tracking-buffers)))
1718 1705
1719(defun python-pdbtrack-comint-output-filter-function (output) 1706(defun python-pdbtrack-comint-output-filter-function (output)
1720 "Move overlay arrow to current pdb line in tracked buffer. 1707 "Move overlay arrow to current pdb line in tracked buffer.
1721Argument OUTPUT is a string with the output from the comint process." 1708Argument OUTPUT is a string with the output from the comint process."
1722 (when (not (string= output "")) 1709 (when (not (string= output ""))
1723 (let ((full-output (ansi-color-filter-apply 1710 (let* ((full-output (ansi-color-filter-apply
1724 (buffer-substring comint-last-input-end 1711 (buffer-substring comint-last-input-end (point-max))))
1725 (point-max))))) 1712 (line-number)
1726 (if (string-match python-shell-prompt-pdb-regexp full-output) 1713 (file-name
1727 (let* ((tracking-buffers (python-pdbtrack-get-or-add-tracking-buffers)) 1714 (with-temp-buffer
1728 (line-num 1715 ;; OK, this sucks but for some reason
1729 (save-excursion 1716 ;; string-match was not doing his trick.
1730 (string-match 1717 (insert full-output)
1731 (format python-pdbtrack-stacktrace-info-regexp 1718 (goto-char (point-min))
1732 (regexp-quote 1719 (when (looking-at python-pdbtrack-stacktrace-info-regexp)
1733 inferior-python-mode-current-file)) 1720 (setq line-number (string-to-number
1734 full-output) 1721 (match-string-no-properties 2)))
1735 (string-to-number (or (match-string-no-properties 1 full-output) "")))) 1722 (match-string-no-properties 1)))))
1736 (tracked-buffer-window (get-buffer-window (cdr tracking-buffers))) 1723 (if (and file-name line-number)
1724 (let* ((tracking-buffers
1725 (python-pdbtrack-get-or-add-tracking-buffers file-name))
1726 (tracked-buffer-window
1727 (get-buffer-window (cdr tracking-buffers)))
1737 (tracked-buffer-line-pos)) 1728 (tracked-buffer-line-pos))
1738 (when line-num 1729 (with-current-buffer (cdr tracking-buffers)
1739 (with-current-buffer (cdr tracking-buffers) 1730 (set (make-local-variable 'overlay-arrow-string) "=>")
1740 (set (make-local-variable 'overlay-arrow-string) "=>") 1731 (set (make-local-variable 'overlay-arrow-position) (make-marker))
1741 (set (make-local-variable 'overlay-arrow-position) (make-marker)) 1732 (setq tracked-buffer-line-pos (progn
1742 (setq tracked-buffer-line-pos (progn 1733 (goto-char (point-min))
1743 (goto-char (point-min)) 1734 (forward-line (1- line-number))
1744 (forward-line (1- line-num)) 1735 (point-marker)))
1745 (point-marker))) 1736 (when tracked-buffer-window
1746 (when tracked-buffer-window 1737 (set-window-point
1747 (set-window-point tracked-buffer-window tracked-buffer-line-pos)) 1738 tracked-buffer-window tracked-buffer-line-pos))
1748 (set-marker overlay-arrow-position tracked-buffer-line-pos))) 1739 (set-marker overlay-arrow-position tracked-buffer-line-pos))
1749 (pop-to-buffer (cdr tracking-buffers)) 1740 (pop-to-buffer (cdr tracking-buffers))
1750 (switch-to-buffer-other-window (car tracking-buffers))) 1741 (switch-to-buffer-other-window (car tracking-buffers)))
1751 (let ((tracking-buffers (assq (current-buffer) 1742 (let ((tracking-buffers (assq (current-buffer)
1752 python-pdbtrack-tracking-buffers))) 1743 python-pdbtrack-tracking-buffers)))
1753 (when tracking-buffers 1744 (when tracking-buffers
1754 (if inferior-python-mode-current-file 1745 (with-current-buffer (cdr tracking-buffers)
1755 (with-current-buffer (cdr tracking-buffers) 1746 (set-marker overlay-arrow-position nil))
1756 (set-marker overlay-arrow-position nil))
1757 (kill-buffer (cdr tracking-buffers)))
1758 (setq python-pdbtrack-tracking-buffers 1747 (setq python-pdbtrack-tracking-buffers
1759 (assq-delete-all (current-buffer) 1748 (assq-delete-all (current-buffer)
1760 python-pdbtrack-tracking-buffers))))))) 1749 python-pdbtrack-tracking-buffers)))))))