Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexflt.el @ 530:fb4822efb1f5 dev
Workaround for Emacs26 (switch-to-buffer)
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Wed, 30 May 2018 07:03:38 +0900 |
parents | b1896ef49747 |
children | ab6c176c676a |
rev | line source |
---|---|
518 | 1 ;;; yatexflt.el --- YaTeX filter command utilizer -*- coding: sjis -*- |
2 ;;; | |
3 ;;; (c)1993-2018 by HIROSE Yuuji.[yuuji@yatex.org] | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
4 ;;; Last modified Sun Jan 21 16:33:16 2018 on firestorm |
518 | 5 ;;; $Id$ |
6 | |
7 ;;; Commentary: | |
8 ;;; | |
9 ;;; This lisp enables passing inline text to some external filter | |
10 ;;; command to generate files such as graphic files. | |
11 ;;; | |
12 ;;; Typical situation is using blockdiag/dot(graphviz) command to | |
13 ;;; generate png/pdf file. | |
14 ;;; | |
15 ;;; Example: | |
16 ;;; | |
17 ;;; [[LaTeX Source]] | |
18 ;;; %#BEGIN FILTER{foo.pdf}{dot -T %t -o o} | |
19 ;;; \if0 | |
20 ;;; === | |
21 ;;; digraph { | |
22 ;;; A -> B; | |
23 ;;; B -> C; | |
24 ;;; } | |
25 ;;; === | |
26 ;;; \fi | |
27 ;;; %#END | |
28 ;;; \includegraphics{foo.pdf} | |
29 ;;; | |
30 ;;; In this case above, when you type `[prefix] t e' between two | |
31 ;;; `===' lines, the content in a region are fed to dot command as | |
32 ;;; follows: | |
33 ;;; | |
34 ;;; echo TEXT | dot -T pdf -o foo.pdf | |
35 ;;; | |
36 ;;; Then foo.pdf file will be generated and the image (as PNG) will | |
37 ;;; be displayed in the next window. | |
38 | |
521
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
39 |
518 | 40 ;;; Code: |
521
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
41 (require 'yatexlib) |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
42 (defvar YaTeX-filter-special-env-alist-default |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
43 '((".blockdiag" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
44 "blockdiag -T %t -o %o -" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
45 "blockdiag { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
46 default_fontsize = 32; |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
47 A -> B; |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
48 }") |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
49 (".seqdiag" "seqdiag -T %t -o %o -" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
50 "seqdiag { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
51 client -> server [label = \"SYN\"]; |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
52 client <- server [label = \"SYN/ACK\"]; |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
53 client -> server [label = \"ACK\"];}") |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
54 (".actdiag" "actdiag -T %t -o %o -" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
55 "actdiag { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
56 sayHo -> ho -> hohoho |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
57 lane dj { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
58 label = \"DJ\" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
59 sayHo [label = \"Say Ho\"]; hohoho [label = \"Ho Ho Ho!\"]; } |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
60 lane mc { label = \"MC\"; ho [label = \"Hooooh!\"]}}") |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
61 (".nwdiag" "nwdiag -T %t -o %o -" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
62 "nwdiag { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
63 network ext { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
64 address = \"10.1.2.0/24\" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
65 router [address = \"10.1.2.1\"] |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
66 } |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
67 network int { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
68 address = \"192.168.22.0/24\" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
69 router [address = \"192.168.22.1\"] |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
70 websrv [address = \"192.168.22.80\"] |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
71 cli-1; cli-2 |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
72 } |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
73 }") |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
74 (".rackdiag" "rackdiag -T %t -o %o -" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
75 "rackdiag { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
76 16U; |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
77 1: UPS [4U]; 5: Storage [3U]; 8: PC [2U]; 8: PC [2U]; |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
78 }") |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
79 (".dot" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
80 "dot -T %t -o %o" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
81 "digraph { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
82 graph [charset=\"utf-8\"] |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
83 } |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
84 bigraph { |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
85 graph [charset=\"utf-8\"]}" |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
86 ))) |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
87 |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
88 (defvar YaTeX-filter-special-env-alist-private nil) |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
89 (defvar YaTeX-filter-special-env-alist |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
90 (append YaTeX-filter-special-env-alist-private |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
91 YaTeX-filter-special-env-alist-default)) |
cef987df070f
Move main stuffs of SpecialFilter to yatexflt.el
HIROSE Yuuji <yuuji@gentei.org>
parents:
518
diff
changeset
|
92 |
518 | 93 (defun YaTeX-filter-filter-set-conversion-flag () |
94 (let ((ovl (get 'YaTeX-filter-filter-sentinel 'overlay))) | |
95 (if ovl ;; When successful conversion met, | |
96 (progn ;; (1)Set conversion complete flag | |
97 (add-hook ;; (2)Add hook of seim-automatic | |
98 'write-file-hooks ;; update of convert to write- | |
99 'YaTeX-filter-update-all) ;; file hook. | |
100 (overlay-put ovl 'converted t))))) | |
101 | |
102 (defun YaTeX-filter-filter-unset-conversion-flag | |
103 (ovl after beg end &optional length) | |
104 (if after (overlay-put ovl 'converted nil))) | |
105 | |
106 | |
107 (defun YaTeX-filter-pngify-sentinel (proc msg) | |
108 (save-excursion | |
109 (let ((b (process-buffer proc)) (selw (selected-window)) | |
110 img) | |
111 (set-buffer b) | |
112 (cond | |
113 ((eq (process-status proc) 'run) | |
114 (put-text-property (point-min) (point-max) 'invisible t)) | |
115 ((eq (process-status proc) 'exit) | |
116 (set-buffer b) | |
117 (YaTeX-popup-image | |
118 (YaTeX-buffer-substring | |
119 (get 'YaTeX-filter-pngify-sentinel 'start) (point-max)) | |
120 b) | |
121 (YaTeX-filter-filter-set-conversion-flag)) | |
122 (t | |
123 (set-buffer b) | |
124 (remove-text-properties (point-min) (point-max) '(invisible t)) | |
125 (insert "\nProcess aborted %s\n" msg)))))) | |
126 | |
127 (defvar YaTeX-filter-pdf2png-stdout | |
128 (cond | |
129 ((YaTeX-executable-find "convert") "convert -trim %s PNG:-") | |
130 (t | |
131 "gs -dNOPAUSE -sDEVICE=png256 -sOutputFile=- -dBATCH -q -r75 %s")) | |
132 "Command line syntax to convert PDF file to PNG stream") | |
133 | |
134 (defun YaTeX-filter-modified-BEGEND-regions () | |
135 "Return the list of overlays which contains un-converted text." | |
136 (save-excursion | |
137 (save-restriction | |
138 (widen) | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
139 (let (r prop dest src pl (list (overlays-in (point-min) (point-max)))) |
518 | 140 (while list |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
141 (setq prop (overlay-properties (car list))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
142 (if (setq dest (plist-get prop 'filter-output)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
143 (if (if (setq src (plist-get prop 'filter-source)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
144 (file-newer-than-file-p src dest) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
145 (and (setq pl (plist-member prop 'converted)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
146 (not (plist-get pl 'converted)))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
147 (setq r (cons (car list) r)))) |
518 | 148 (setq list (cdr list))) |
149 (nconc r) | |
150 r)))) | |
151 | |
152 (defun YaTeX-filter-update-all () | |
153 "Update all destination files from built-in source text." | |
154 (interactive) | |
155 (let ((timeout 4) | |
156 ans ovl (update-list (YaTeX-filter-modified-BEGEND-regions))) | |
157 (if update-list | |
158 (save-excursion | |
159 (save-window-excursion | |
160 (catch 'abort | |
161 (while update-list | |
162 (goto-char (overlay-start (setq ovl (car update-list)))) | |
163 (or (pos-visible-in-window-p) | |
164 (set-window-start nil (point))) | |
165 (unwind-protect | |
166 (progn | |
167 (overlay-put ovl 'face 'YaTeX-on-the-fly-activated-face) | |
168 (message "Non-update source found: Update here: %s " | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
169 "Y)es N)o S)top-watching-Here A)bort") |
518 | 170 (setq ans (read-char)) |
171 (cond | |
172 ((memq ans '(?Y ?y)) | |
173 (YaTeX-filter-BEGEND) | |
174 (while (and (> (setq timeout (1- timeout))) | |
175 (eq (process-status "Filter") 'run)) | |
176 (message "Waiting for conversion process to finish") | |
177 (sit-for 1))) | |
178 ((memq ans '(?A ?a)) (throw 'abort t)) | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
179 ((memq ans '(?S ?s)) (delete-overlay ovl)) |
518 | 180 (t nil))) |
181 (overlay-put ovl 'face nil)) | |
182 (setq update-list (cdr update-list))))))) | |
183 ;; Write file hook should return nil | |
184 nil)) | |
185 | |
186 (defun YaTeX-filter-filter-sentinel (proc msg) | |
187 (put 'YaTeX-filter-pngify-sentinel 'start nil) | |
188 (let ((b (process-buffer proc)) | |
189 (imagefile (get 'YaTeX-filter-filter-sentinel 'outfile)) | |
190 ovl | |
191 (selw (selected-window))) | |
192 (save-excursion | |
193 (cond | |
194 ((eq (process-status proc) 'run)) | |
195 ((eq (process-status proc) 'exit) | |
196 (set-buffer b) | |
197 (remove-images (point-min) (point-max)) | |
198 (if (and (file-regular-p imagefile) | |
199 (file-readable-p imagefile)) | |
200 (save-excursion | |
201 (setq buffer-read-only nil) | |
202 (cond | |
203 ((string-match "\\.\\(jpg\\|png\\)" imagefile) | |
204 (erase-buffer) | |
205 (YaTeX-popup-image imagefile b) | |
206 (YaTeX-filter-filter-set-conversion-flag)) | |
207 (t ;Convert again to PNG file | |
208 (goto-char (point-max)) | |
209 (insert "\nConvert Again to PNG file...\n") | |
210 (put 'YaTeX-filter-pngify-sentinel 'start (point)) | |
211 (set-process-sentinel | |
212 (start-process | |
213 "Filter" b ;Safe to reuse | |
214 shell-file-name YaTeX-shell-command-option | |
215 (format YaTeX-filter-pdf2png-stdout imagefile)) | |
216 'YaTeX-filter-pngify-sentinel) | |
217 (set-buffer-multibyte nil) | |
218 )) | |
219 (select-window selw))) | |
220 (YaTeX-preview-image-mode) | |
221 ) | |
222 (t ;Other status might be an error | |
223 (set-buffer b) | |
224 (goto-char (point-max)) | |
225 (insert (format "%s\n" (process-status proc)))))))) | |
226 | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
227 (defun YaTeX-filter-parse-filter-region (begend-info) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
228 "Return the list of SpecialFilter region. If not on, return nil. |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
229 BEGEND-INFO is a value from the function YaTeX-in-BEGEND-p. |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
230 Return the alist of: |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
231 '((outfile $OutPutFileName) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
232 (source $InputFileName) ; or nil for embeded data source |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
233 (cmdline $CommandLine) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
234 (begin $TextRegionBeginning) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
235 (end TextRegionEnd))" |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
236 (if begend-info |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
237 (let ((b (car begend-info)) (e (nth 1 begend-info)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
238 delim (args (nth 2 begend-info)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
239 (p (point)) openb closeb outfile source cmdline point-beg point-end) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
240 (save-excursion |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
241 (and |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
242 (string-match "FILTER" args) ;easy test |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
243 (goto-char (car begend-info)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
244 (re-search-forward |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
245 "FILTER\\s *{\\([^}]+\\)}" e t) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
246 (setq outfile (YaTeX-match-string 1)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
247 (goto-char (match-end 0)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
248 (prog2 ;Step into the second brace |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
249 (skip-chars-forward "\t ") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
250 (looking-at "{") ;Check if 2nd brace surely exists |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
251 (skip-chars-forward "{") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
252 (skip-chars-forward "\t")) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
253 (setq openb (point)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
254 (condition-case nil |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
255 (progn (up-list 1) t) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
256 (error nil)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
257 (setq closeb (1- (point)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
258 cmdline (YaTeX-buffer-substring openb closeb)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
259 (cond |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
260 ((re-search-forward "^\\\\if0\\>" p t) ;; Embedded source |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
261 (forward-line 1) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
262 (setq point-beg (if (looking-at "\\(.\\)\\1\\1") ;Triple chars |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
263 (progn (setq delim (YaTeX-match-string 0)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
264 (forward-line 1) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
265 (point)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
266 (point))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
267 (re-search-forward "^\\\\fi\\>" e t) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
268 (goto-char (match-beginning 0)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
269 (setq point-end (if delim |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
270 (progn |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
271 (re-search-backward |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
272 (concat "^" (regexp-quote delim)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
273 (1+ point-beg) t) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
274 (match-beginning 0)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
275 (point)))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
276 ((re-search-forward "^\\s *%#SRC{\\(.*\\)}" e t) ; external file |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
277 (setq source (YaTeX-match-string 1) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
278 point-beg (match-beginning 0) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
279 point-end (match-end 0))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
280 (t ;; If source notation not found, |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
281 (let ((ovl (overlays-in b e))) ;; clear all remaining overlays |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
282 (while ovl |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
283 (delete-overlay (car ovl)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
284 (setq ovl (cdr ovl)))))) ;; Return nil |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
285 |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
286 ;; Then return all values |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
287 (list (cons 'outfile outfile) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
288 (cons 'source source) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
289 (cons 'cmdline cmdline) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
290 (cons 'begin point-beg) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
291 (cons 'end point-end))))))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
292 |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
293 ;;debug;; (YaTeX-filter-parse-filter-region (YaTeX-in-BEGEND-p)) |
518 | 294 (defun YaTeX-filter-pass-to-filter (begend-info) |
295 "Pass current BEGIN FILTER environment to external command." | |
296 (put 'YaTeX-filter-filter-sentinel 'outfile nil) | |
297 ;; begend-info is from YaTeX-in-BEGEND-p: (BEG END ARGS) | |
298 (let ((b (car begend-info)) (e (nth 1 begend-info)) | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
299 (r (YaTeX-filter-parse-filter-region begend-info))) |
518 | 300 (save-excursion |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
301 (if r (let*((case-fold-search t) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
302 (outfile (cdr (assq 'outfile r))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
303 (source (cdr (assq 'source r))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
304 (type (cond |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
305 ((string-match "\\.png$" outfile) "png") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
306 ((string-match "\\.svg$" outfile) "svg") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
307 ((string-match "\\.tex$" outfile) "tex") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
308 (t "pdf"))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
309 (newcmdline (YaTeX-replace-formats |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
310 (cdr (assq 'cmdline r)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
311 (list (cons "t" type) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
312 (cons "o" outfile) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
313 (cons "i" source)))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
314 (text-start (cdr (assq 'begin r))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
315 (text-end (cdr (assq 'end r))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
316 (text (and (numberp text-start) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
317 (numberp text-end) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
318 (YaTeX-buffer-substring text-start text-end))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
319 ;; |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
320 ;; Now it's time to start filter process |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
321 ;; |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
322 (procbuf (YaTeX-system newcmdline "Filter" 'force)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
323 (proc (get-buffer-process procbuf)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
324 ;;(procbuf (get-buffer-create " *Filter*")) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
325 (ovl (progn |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
326 (remove-overlays text-start text-end) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
327 (make-overlay text-start text-end))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
328 (ovlmodhook ;hook function to reset conv-success flag |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
329 'YaTeX-filter-filter-unset-conversion-flag)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
330 (if proc |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
331 (progn |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
332 (overlay-put ovl 'filter-output outfile) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
333 (overlay-put ovl 'filter-source source) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
334 (overlay-put ovl 'converted nil) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
335 (overlay-put ovl 'modification-hooks (list ovlmodhook)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
336 (set-process-coding-system proc 'undecided 'utf-8) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
337 (set-process-sentinel proc 'YaTeX-filter-filter-sentinel) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
338 (YaTeX-showup-buffer procbuf) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
339 (set-buffer procbuf) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
340 (setq buffer-read-only nil) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
341 (erase-buffer) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
342 (insert (format "Starting process `%s'...\n" newcmdline)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
343 (set-marker (process-mark proc) (point-max)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
344 (cond |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
345 (text |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
346 (process-send-string proc text) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
347 (process-send-string proc "\n") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
348 (process-send-eof proc) ;Notify stream chunk end |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
349 (process-send-eof proc))) ;Notify real EOF |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
350 (put 'YaTeX-filter-filter-sentinel 'outfile outfile) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
351 (put 'YaTeX-filter-filter-sentinel 'overlay ovl)))))))) |
518 | 352 |
353 (defun YaTeX-insert-filter-special (filter list &optional region-p) | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
354 (let*((f (YaTeX-read-string-or-skip |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
355 "Output file(Maybe *.(pdf|png|jpg|tex)): ")) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
356 (insert-default-directory) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
357 (cmdargs (car list)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
358 (template-text (car (cdr list))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
359 (ifile (read-file-name "Data source(Default: in this buffer): " nil)) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
360 (in-line (string= "" ifile))) |
518 | 361 (if region-p |
362 (if (< (point) (mark)) (exchange-point-and-mark))) | |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
363 (save-excursion |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
364 (insert (if in-line "===\n\\fi\n" "") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
365 "%#END\n" |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
366 (cond |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
367 ((string-match "\\.tex$" f) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
368 (format "\\input{%s}\n" (substring f 0 (match-beginning 0)))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
369 ((string-match "\\.\\(pdf\\|png\\|jpe?g\\|tiff?\\)$" f) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
370 (format "%%# \\includegraphics{%s}\n" f))))) |
518 | 371 (and region-p (exchange-point-and-mark)) |
524
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
372 (insert (format "%%#BEGIN FILTER{%s}{%s}\n%s" |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
373 f (or cmdargs "") |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
374 (if in-line "\\if0\n===\n" ""))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
375 (save-excursion |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
376 (insert (if in-line |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
377 (cond (template-text |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
378 (concat template-text |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
379 (or (string-match "\n$" template-text) "\n"))) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
380 (t "\n")) |
b1896ef49747
Detection of region passed to filter modified.
HIROSE Yuuji <yuuji@gentei.org>
parents:
521
diff
changeset
|
381 (format "%%#SRC{%s}\n" ifile)))))) |
518 | 382 |
383 (provide 'yatexflt) | |
384 | |
385 ; Local variables: | |
386 ; fill-prefix: ";;; " | |
387 ; paragraph-start: "^$\\|\\|;;;$" | |
388 ; paragraph-separate: "^$\\|\\|;;;$" | |
389 ; End: |