                (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))))
+                                 (save-excursion
+                                   (set-buffer buf)
+                                   (buffer-substring (point-min)
+                                                     (point-max))))))
           (setq got buf)))
     (setq py-pdbtrack-last-grubbed-buffer got)))
 

                             (max (point-min)
                                  (string-match "^\\([^#]\\|#[^#]\\|#$\\)"
                                                (buffer-substring (point-min)
                                                                  (point-max)
                                                                  funcbuffer))
                                  ))))))
             (list lineno funcbuffer))


  (let ((buffers (buffer-list))
        curbuf
        got)
    (while (and buffers (not got))
      (setq buf (car buffers)
            buffers (cdr buffers))
