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