From ed6000a993b5648bce306988e327bdf95c5129d5 Mon Sep 17 00:00:00 2001 From: Ken Manheimer Date: Mon, 3 Mar 2003 17:09:44 +0000 Subject: [PATCH] py-pdbtrack-grub-for-buffer(): Rectified some logic errors i introduced when shifting around some code, and added some redundancy to reduce chances of hitting the wrong source code. (This is experimental - it will improve the accuracy, but will reduce the ability of the user to deliberately select the buffer they want the buffer grubbing stuff to find. I think the accuracy improvement will be worth it, but am not sure, so may remove this.) --- Misc/python-mode.el | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Misc/python-mode.el b/Misc/python-mode.el index c8423f1e573..f654d8a5fa2 100644 --- a/Misc/python-mode.el +++ b/Misc/python-mode.el @@ -386,6 +386,13 @@ support for features needed by `python-mode'.") Currently-active file is at the head of the list.") (defvar py-pdbtrack-is-tracking-p nil) +(defvar py-pdbtrack-last-grubbed-buffer nil + "Record of the last buffer used when the source path was invalid. + +This buffer is consulted before the buffer-list history for satisfying +`py-pdbtrack-grub-for-buffer', since it's the most often the likely +prospect as debugging continues.") +(make-variable-buffer-local 'py-pdbtrack-last-grubbed-buffer) (defvar py-pychecker-history nil) @@ -1379,24 +1386,29 @@ problem as best as we can determine." (defun py-pdbtrack-grub-for-buffer (funcname lineno) "Find most recent buffer itself named or having function funcname. -Must have a least int(lineno) lines in it." +We first check the last buffer this function found, if any, then walk +throught the buffer-list history for python-mode buffers that are +named for funcname or define a function funcname." (let ((buffers (buffer-list)) - ;(buffers (list (get-buffer "workflow_do_action.py"))) curbuf got) + (if (and py-pdbtrack-last-grubbed-buffer + (member py-pdbtrack-last-grubbed-buffer buffers)) + ; Prefer last grubbed buffer by putting it at the front of the list: + (setq buffers (cons py-pdbtrack-last-grubbed-buffer buffers))) (while (and buffers (not got)) (setq buf (car buffers) buffers (cdr buffers)) - (if (or (save-excursion (set-buffer buf) - (string= major-mode "python-mode")) - (and (string-match funcname (buffer-name buf)) + (if (and (save-excursion (set-buffer buf) + (string= major-mode "python-mode")) + (or (string-match funcname (buffer-name buf)) (string-match (concat "^\\s-*\\(def\\|class\\)\\s-+" funcname "\\s-*(") (buffer-substring (point-min buf) (point-max buf) buf)))) (setq got buf))) - got)) + (setq py-pdbtrack-last-grubbed-buffer got))) (defun py-postprocess-output-buffer (buf) "Highlight exceptions found in BUF.