75 |
:link '(info-link "(preview-latex)The Emacs interface") |
:link '(info-link "(preview-latex)The Emacs interface") |
76 |
:link '(url-link :tag "Homepage" "http://www.gnu.org/software/auctex/")) |
:link '(url-link :tag "Homepage" "http://www.gnu.org/software/auctex/")) |
77 |
|
|
78 |
(defgroup preview-gs nil "Preview's GhostScript renderer." |
(defgroup preview-gs nil "Preview's Ghostscript renderer." |
79 |
:group 'preview |
:group 'preview |
80 |
:prefix "preview-") |
:prefix "preview-") |
81 |
|
|
220 |
(jpeg jpeg "-sDEVICE=jpeg") |
(jpeg jpeg "-sDEVICE=jpeg") |
221 |
(pnm pbm "-sDEVICE=pnmraw") |
(pnm pbm "-sDEVICE=pnmraw") |
222 |
(tiff tiff "-sDEVICE=tiff12nc")) |
(tiff tiff "-sDEVICE=tiff12nc")) |
223 |
"*Alist of image types and corresponding GhostScript options. |
"*Alist of image types and corresponding Ghostscript options. |
224 |
The `dvipng' and `postscript' (don't use) entries really specify |
The `dvipng' and `postscript' (don't use) entries really specify |
225 |
a fallback device when images can't be processed by the requested |
a fallback device when images can't be processed by the requested |
226 |
method, like when PDFTeX was used." |
method, like when PDFTeX was used." |
227 |
:group 'preview-gs |
:group 'preview-gs |
228 |
:type '(repeat (list :tag nil (symbol :tag "preview image-type") |
:type '(repeat (list :tag nil (symbol :tag "preview image-type") |
229 |
(symbol :tag "Emacs image-type") |
(symbol :tag "Emacs image-type") |
230 |
(repeat :inline t :tag "GhostScript options" string)))) |
(repeat :inline t :tag "Ghostscript options" string)))) |
231 |
|
|
232 |
(defcustom preview-image-type 'png |
(defcustom preview-image-type 'png |
233 |
"*Image type to be used in images." |
"*Image type to be used in images." |
370 |
(defcustom preview-gs-outstanding-limit 2 |
(defcustom preview-gs-outstanding-limit 2 |
371 |
"*Number of requests allowed to be outstanding. |
"*Number of requests allowed to be outstanding. |
372 |
This is the number of not-yet-completed requests we |
This is the number of not-yet-completed requests we |
373 |
might at any time have piped into GhostScript. If |
might at any time have piped into Ghostscript. If |
374 |
this number is larger, the probability of GhostScript |
this number is larger, the probability of Ghostscript |
375 |
working continuously is higher when Emacs is rather |
working continuously is higher when Emacs is rather |
376 |
busy. If this number is smaller, redisplay will |
busy. If this number is smaller, redisplay will |
377 |
follow changes in the displayed buffer area faster." |
follow changes in the displayed buffer area faster." |
385 |
:tag "small number")) |
:tag "small number")) |
386 |
|
|
387 |
(defvar preview-gs-answer nil |
(defvar preview-gs-answer nil |
388 |
"Accumulated answer of GhostScript process.") |
"Accumulated answer of Ghostscript process.") |
389 |
(make-variable-buffer-local 'preview-gs-answer) |
(make-variable-buffer-local 'preview-gs-answer) |
390 |
|
|
391 |
(defvar preview-gs-image-type nil |
(defvar preview-gs-image-type nil |
411 |
(make-variable-buffer-local 'preview-colors) |
(make-variable-buffer-local 'preview-colors) |
412 |
|
|
413 |
(defvar preview-gs-init-string nil |
(defvar preview-gs-init-string nil |
414 |
"GhostScript setup string.") |
"Ghostscript setup string.") |
415 |
(make-variable-buffer-local 'preview-gs-init-string) |
(make-variable-buffer-local 'preview-gs-init-string) |
416 |
|
|
417 |
(defvar preview-ps-file nil |
(defvar preview-ps-file nil |
439 |
(defun preview-gs-behead-outstanding (err) |
(defun preview-gs-behead-outstanding (err) |
440 |
"Remove leading element of outstanding queue after error. |
"Remove leading element of outstanding queue after error. |
441 |
Return element if non-nil. ERR is the error string to |
Return element if non-nil. ERR is the error string to |
442 |
show as response of GhostScript." |
show as response of Ghostscript." |
443 |
(let ((ov (pop preview-gs-outstanding))) |
(let ((ov (pop preview-gs-outstanding))) |
444 |
(when ov |
(when ov |
445 |
(preview-gs-flag-error ov err) |
(preview-gs-flag-error ov err) |
582 |
(defun preview-gs-sentinel (process string) |
(defun preview-gs-sentinel (process string) |
583 |
"Sentinel function for rendering process. |
"Sentinel function for rendering process. |
584 |
Gets the default PROCESS and STRING arguments |
Gets the default PROCESS and STRING arguments |
585 |
and tries to restart GhostScript if necessary." |
and tries to restart Ghostscript if necessary." |
586 |
(condition-case err |
(condition-case err |
587 |
(let ((status (process-status process))) |
(let ((status (process-status process))) |
588 |
(when (memq status '(exit signal)) |
(when (memq status '(exit signal)) |
632 |
preview-gs-queue)) |
preview-gs-queue)) |
633 |
(setq preview-gs-outstanding nil) |
(setq preview-gs-outstanding nil) |
634 |
(preview-gs-restart))))))) |
(preview-gs-restart))))))) |
635 |
(error (preview-log-error err "GhostScript" process))) |
(error (preview-log-error err "Ghostscript" process))) |
636 |
(preview-reraise-error process)) |
(preview-reraise-error process)) |
637 |
|
|
638 |
(defun preview-gs-filter (process string) |
(defun preview-gs-filter (process string) |
639 |
"Filter function for processing GhostScript output. |
"Filter function for processing Ghostscript output. |
640 |
Gets the usual PROCESS and STRING parameters, see |
Gets the usual PROCESS and STRING parameters, see |
641 |
`set-process-filter' for a description." |
`set-process-filter' for a description." |
642 |
(with-current-buffer (process-buffer process) |
(with-current-buffer (process-buffer process) |
647 |
(setq preview-gs-answer (substring preview-gs-answer pos)) |
(setq preview-gs-answer (substring preview-gs-answer pos)) |
648 |
(condition-case err |
(condition-case err |
649 |
(preview-gs-transact process answer) |
(preview-gs-transact process answer) |
650 |
(error (preview-log-error err "GhostScript filter" process)))))) |
(error (preview-log-error err "Ghostscript filter" process)))))) |
651 |
(preview-reraise-error)) |
(preview-reraise-error)) |
652 |
|
|
653 |
(defun preview-gs-restart () |
(defun preview-gs-restart () |
654 |
"Start a new GhostScript conversion process." |
"Start a new Ghostscript conversion process." |
655 |
(when preview-gs-queue |
(when preview-gs-queue |
656 |
(if preview-gs-sequence |
(if preview-gs-sequence |
657 |
(setcar preview-gs-sequence (1+ (car preview-gs-sequence))) |
(setcar preview-gs-sequence (1+ (car preview-gs-sequence))) |
666 |
preview-gs-image-type)))) |
preview-gs-image-type)))) |
667 |
(process |
(process |
668 |
(apply #'start-process |
(apply #'start-process |
669 |
"Preview-GhostScript" |
"Preview-Ghostscript" |
670 |
(current-buffer) |
(current-buffer) |
671 |
preview-gs-command |
preview-gs-command |
672 |
outfile |
outfile |
673 |
preview-gs-command-line))) |
preview-gs-command-line))) |
674 |
(goto-char (point-max)) |
(goto-char (point-max)) |
675 |
(insert-before-markers "Running `Preview-GhostScript' with ``" |
(insert-before-markers "Running `Preview-Ghostscript' with ``" |
676 |
(mapconcat #'shell-quote-argument |
(mapconcat #'shell-quote-argument |
677 |
(append |
(append |
678 |
(list preview-gs-command |
(list preview-gs-command |
684 |
(set-process-sentinel process #'preview-gs-sentinel) |
(set-process-sentinel process #'preview-gs-sentinel) |
685 |
(set-process-filter process #'preview-gs-filter) |
(set-process-filter process #'preview-gs-filter) |
686 |
(process-send-string process preview-gs-init-string) |
(process-send-string process preview-gs-init-string) |
687 |
(setq mode-name "Preview-GhostScript") |
(setq mode-name "Preview-Ghostscript") |
688 |
(push process compilation-in-progress) |
(push process compilation-in-progress) |
689 |
(TeX-command-mode-line process) |
(TeX-command-mode-line process) |
690 |
(set-buffer-modified-p (buffer-modified-p)) |
(set-buffer-modified-p (buffer-modified-p)) |
691 |
process))) |
process))) |
692 |
|
|
693 |
(defun preview-gs-open (&optional setup) |
(defun preview-gs-open (&optional setup) |
694 |
"Start a GhostScript conversion pass. |
"Start a Ghostscript conversion pass. |
695 |
SETUP may contain a parser setup function." |
SETUP may contain a parser setup function." |
696 |
(let ((image-info (assq preview-image-type preview-gs-image-type-alist))) |
(let ((image-info (assq preview-image-type preview-gs-image-type-alist))) |
697 |
(setq preview-gs-image-type (nth 1 image-info)) |
(setq preview-gs-image-type (nth 1 image-info)) |
718 |
(defun preview-gs-color-value (value) |
(defun preview-gs-color-value (value) |
719 |
"Return string to be used as color value for an RGB component. |
"Return string to be used as color value for an RGB component. |
720 |
Conversion from Emacs color numbers (0 to 65535) in VALUE |
Conversion from Emacs color numbers (0 to 65535) in VALUE |
721 |
to GhostScript floats." |
to Ghostscript floats." |
722 |
(format "%g" (/ value 65535.0))) |
(format "%g" (/ value 65535.0))) |
723 |
|
|
724 |
(defun preview-gs-color-string (colors) |
(defun preview-gs-color-string (colors) |
1043 |
This function is used in fake conditional display properties |
This function is used in fake conditional display properties |
1044 |
for reordering the conversion order to prioritize on-screen |
for reordering the conversion order to prioritize on-screen |
1045 |
images. OV is the overlay in question, and BUFF is the |
images. OV is the overlay in question, and BUFF is the |
1046 |
GhostScript process buffer where the buffer-local queue |
Ghostscript process buffer where the buffer-local queue |
1047 |
is located." |
is located." |
1048 |
;; It does not matter that ov gets queued twice in that process: the |
;; It does not matter that ov gets queued twice in that process: the |
1049 |
;; first version to get rendered will clear the 'queued property. |
;; first version to get rendered will clear the 'queued property. |
1061 |
|
|
1062 |
|
|
1063 |
(defun preview-gs-place (ov snippet box run-buffer tempdir ps-file imagetype) |
(defun preview-gs-place (ov snippet box run-buffer tempdir ps-file imagetype) |
1064 |
"Generate an image placeholder rendered over by GhostScript. |
"Generate an image placeholder rendered over by Ghostscript. |
1065 |
This enters OV into all proper queues in order to make it render |
This enters OV into all proper queues in order to make it render |
1066 |
this image for real later, and returns the overlay after setting |
this image for real later, and returns the overlay after setting |
1067 |
a placeholder image. SNIPPET gives the number of the |
a placeholder image. SNIPPET gives the number of the |
1088 |
(defun preview-mouse-open-error (string) |
(defun preview-mouse-open-error (string) |
1089 |
"Display STRING in a new view buffer on click." |
"Display STRING in a new view buffer on click." |
1090 |
(let ((buff (get-buffer-create |
(let ((buff (get-buffer-create |
1091 |
"*Preview-GhostScript-Error*"))) |
"*Preview-Ghostscript-Error*"))) |
1092 |
(with-current-buffer buff |
(with-current-buffer buff |
1093 |
(kill-all-local-variables) |
(kill-all-local-variables) |
1094 |
(set (make-local-variable 'view-exit-action) #'kill-buffer) |
(set (make-local-variable 'view-exit-action) #'kill-buffer) |
1165 |
(preview-toggle ov))) |
(preview-toggle ov))) |
1166 |
|
|
1167 |
(defun preview-gs-transact (process answer) |
(defun preview-gs-transact (process answer) |
1168 |
"Work off GhostScript transaction. |
"Work off Ghostscript transaction. |
1169 |
This routine is the action routine called via the process filter. |
This routine is the action routine called via the process filter. |
1170 |
The GhostScript process buffer of PROCESS will already be selected, and |
The Ghostscript process buffer of PROCESS will already be selected, and |
1171 |
and the standard output of GhostScript up to the next prompt will be |
and the standard output of Ghostscript up to the next prompt will be |
1172 |
given as ANSWER." |
given as ANSWER." |
1173 |
(let ((ov (pop preview-gs-outstanding)) |
(let ((ov (pop preview-gs-outstanding)) |
1174 |
(have-error (not |
(have-error (not |