Function: pdf-info--tq-workaround

pdf-info--tq-workaround is a natively compiled function defined in pdf-info.el.

Signature

(pdf-info--tq-workaround ORIG-FUN TQ &rest ARGS)

Documentation

Fix a bug in trunk where the wrong callback gets called.

ORIG-FUN is the callback that should be called. TQ and ARGS are the transmission-queue and arguments to the callback.

Source Code

;; Defined in /nix/store/63h5z2vmzn0mfavcxi2idi23g5xcgkbl-emacs-packages-deps/share/emacs/site-lisp/elpa/pdf-tools-20260102.1101/pdf-info.el
(defun pdf-info--tq-workaround (orig-fun tq &rest args)
  "Fix a bug in trunk where the wrong callback gets called.

ORIG-FUN is the callback that should be called. TQ and ARGS are
the transmission-queue and arguments to the callback."
  ;; FIXME: Make me iterative.
  (if (not (equal (car (process-command (tq-process tq)))
                  pdf-info-epdfinfo-program))
      (apply orig-fun tq args)
    (let ((buffer (tq-buffer tq))
          done)
      (when (buffer-live-p buffer)
        (set-buffer buffer)
        (while (and (not done)
                    (> (buffer-size) 0))
          (setq done t)
          (if (tq-queue-empty tq)
              (let ((buf (generate-new-buffer "*spurious*")))
                (copy-to-buffer buf (point-min) (point-max))
                (delete-region (point-min) (point))
                (pop-to-buffer buf nil)
                (error "Spurious communication from process %s, see buffer %s"
                       (process-name (tq-process tq))
                       (buffer-name buf)))
            (goto-char (point-min))
            (when (re-search-forward (tq-queue-head-regexp tq) nil t)
              (setq done nil)
              (let ((answer (buffer-substring (point-min) (point)))
                    (fn (tq-queue-head-fn tq))
                    (closure (tq-queue-head-closure tq)))
                (delete-region (point-min) (point))
                (tq-queue-pop tq)
                (condition-case-unless-debug err
                    (funcall fn closure answer)
                  (error
                   (message "Error while processing tq callback: %s"
                            (error-message-string err))))))))))))