Function: python-pdbtrack-comint-output-filter-function

python-pdbtrack-comint-output-filter-function is a byte-compiled function defined in python.el.gz.

Signature

(python-pdbtrack-comint-output-filter-function OUTPUT)

Documentation

Move overlay arrow to current pdb line in tracked buffer.

Argument OUTPUT is a string with the output from the comint process.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-pdbtrack-comint-output-filter-function (output)
  "Move overlay arrow to current pdb line in tracked buffer.
Argument OUTPUT is a string with the output from the comint process."
  (when (and python-pdbtrack-activate (not (string= output "")))
    (let* ((full-output (ansi-color-filter-apply
                         (buffer-substring comint-last-input-end (point-max))))
           (line-number)
           (file-name
            (with-temp-buffer
              (insert full-output)
              ;; When the debugger encounters a pdb.set_trace()
              ;; command, it prints a single stack frame.  Sometimes
              ;; it prints a bit of extra information about the
              ;; arguments of the present function.  When ipdb
              ;; encounters an exception, it prints the _entire_ stack
              ;; trace.  To handle all of these cases, we want to find
              ;; the _last_ stack frame printed in the most recent
              ;; batch of output, then jump to the corresponding
              ;; file/line number.
              ;; Parse output only if at pdb prompt to avoid double code
              ;; run in situation when output and pdb prompt received in
              ;; different hunks
              (goto-char (point-max))
              (goto-char (line-beginning-position))
              (when (and (looking-at python-shell-prompt-pdb-regexp)
                         (re-search-backward python-pdbtrack-stacktrace-info-regexp nil t))
                (setq line-number (string-to-number
                                   (match-string-no-properties 2)))
                (match-string-no-properties 1)))))
      (when (and file-name line-number)
        (if (string-prefix-p "<" file-name)
            ;; Finish tracking session if stacktrace info is like
            ;; "> <stdin>(1)<module>()->None"
            (python-pdbtrack-tracking-finish)
          (python-pdbtrack-unset-tracked-buffer)
          (let* ((tracked-buffer (python-pdbtrack-set-tracked-buffer file-name))
                 (shell-buffer (current-buffer))
                 (tracked-buffer-window (get-buffer-window tracked-buffer))
                 (tracked-buffer-line-pos))
            (with-current-buffer tracked-buffer
              (setq-local overlay-arrow-position (make-marker))
              (setq tracked-buffer-line-pos (progn
                                              (goto-char (point-min))
                                              (forward-line (1- line-number))
                                              (point-marker)))
              (when tracked-buffer-window
                (set-window-point
                 tracked-buffer-window tracked-buffer-line-pos))
              (set-marker overlay-arrow-position tracked-buffer-line-pos))
            (pop-to-buffer tracked-buffer)
            (switch-to-buffer-other-window shell-buffer))))))
  output)