annotate yatexflt.el @ 556:fbb636ff0fe3 dev yatex-1.81

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

yatex.org