Function: preview-gs-transact

preview-gs-transact is a byte-compiled function defined in preview.el.

Signature

(preview-gs-transact PROCESS ANSWER)

Documentation

Work off Ghostscript transaction.

This routine is the action routine called via the process filter. The Ghostscript process buffer of PROCESS will already be selected, and and the standard output of Ghostscript up to the next prompt will be given as ANSWER.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/preview.el
(defun preview-gs-transact (process answer)
  "Work off Ghostscript transaction.
This routine is the action routine called via the process filter.
The Ghostscript process buffer of PROCESS will already be selected, and
and the standard output of Ghostscript up to the next prompt will be
given as ANSWER."
  (let ((ov (pop preview-gs-outstanding))
        (have-error (not
                     (string-match "\\`GS\\(<[0-9]+\\)?>\\'" answer ))))
    (when (and ov (overlay-buffer ov))
      (let ((queued (overlay-get ov 'queued)))
        (when queued
          (let* ((bbox (aref queued 0))
                 (filenames (overlay-get ov 'filenames))
                 (oldfile (nth 0 filenames))
                 (newfile (nth 1 filenames)))
            (if have-error
                (preview-gs-flag-error ov answer)
              (condition-case nil
                  (preview-delete-file oldfile)
                (file-error nil))
              (overlay-put ov 'filenames (cdr filenames))
              (preview-replace-active-icon
               ov
               (preview-create-icon (car newfile)
                                    preview-gs-image-type
                                    (preview-ascent-from-bb
                                     bbox)
                                    (aref preview-colors 2))))
            (overlay-put ov 'queued nil)))))
    (while (and (< (length preview-gs-outstanding)
                   preview-gs-outstanding-limit)
                (setq ov (pop preview-gs-queue)))
      (let ((queued (overlay-get ov 'queued)))
        (when (and queued
                   (not (memq ov preview-gs-outstanding))
                   (overlay-buffer ov))
          (let* ((filenames (overlay-get ov 'filenames))
                 (oldfile (car (nth 0
                                    (nconc filenames
                                           (list
                                            (preview-make-filename
                                             (format "pr%d-%d.%s"
                                                     (car preview-gs-sequence)
                                                     (cdr preview-gs-sequence)
                                                     preview-gs-image-type)
                                             TeX-active-tempdir))))))
                 (bbox (aset queued 0
                             (or (and preview-prefer-TeX-bb
                                      (aref queued 0))
                                 (and (stringp oldfile)
                                      (preview-extract-bb
                                       oldfile))
                                 (aref queued 0)
                                 (error "No bounding box"))))
                 (snippet (aref queued 2))
                 (gs-line
                  (format
                   "%s<<%s>>preview-do\n"
                   (if preview-ps-file
                       (concat "dup "
                               (preview-gs-dsc-cvx
                                snippet
                                preview-gs-dsc))
                     (format "%s(r)file cvx"
                             (preview-ps-quote-filename
                              (if (listp oldfile)
                                  (car (last oldfile))
                                oldfile))))
                   (if preview-parsed-tightpage
                       ""
                     (format "/PageSize[%g %g]/PageOffset[%g \
%g[1 1 dtransform exch]{0 ge{neg}if exch}forall]"
                             (- (aref bbox 2) (aref bbox 0))
                             (- (aref bbox 3) (aref bbox 1))
                             (aref bbox 0) (aref bbox 1))))))
            (setcdr preview-gs-sequence (1+ (cdr preview-gs-sequence)))
            (setq preview-gs-outstanding
                  (nconc preview-gs-outstanding
                         (list ov)))
            (aset queued 1 gs-line)
            ;; ignore errors because of dying processes: they will get
            ;; caught by the sentinel, anyway.
            (condition-case nil
                (process-send-string
                 process
                 gs-line)
              (error nil))))))
    (unless preview-gs-outstanding
      (condition-case nil
          (process-send-eof process)
        (error nil)))))