changeset 517:668632d9392e dev

Initial implementation of SpecialFilterRegion
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 06 Jan 2018 23:54:17 +0900
parents 603acc1caec7
children dfb71acdec98
files docs/yatexe docs/yatexe.tex docs/yatexj docs/yatexj.tex yatex.el yatex.new yatexprc.el
diffstat 7 files changed, 365 insertions(+), 172 deletions(-) [+]
line wrap: on
line diff
--- a/docs/yatexe	Fri Jan 05 00:23:36 2018 +0900
+++ b/docs/yatexe	Sat Jan 06 23:54:17 2018 +0900
@@ -249,6 +249,7 @@
 * Changing typesetter::
 * Splitting input files::
 * Static region for typesetting::
+* Special Filtering Region::
 * Lpr format::
 * Controlling which command to invoke::
 * Editing %# notation::
@@ -337,6 +338,30 @@
 
 
 
+File: yatexe, Node: Special Filtering Region, Next: Lpr format, Prev: Static region for typesetting, Up: %#notation
+
+Special Filtering Region
+========================
+  A region like below will be passed to external filter command.
+     %#BEGIN FILTER{foo.pdf}{dot -T %t -o %o}
+     \if0
+     ....blah blah blah...
+     ....blah blah blah...
+     ....blah blah blah...
+     \fi
+     %#END
+
+In this case, typing `[prefix] t e' send three `blah' lines
+to "dot -T pdf -o foo.pdf" as standard-input.  It is useful to
+have source of text-origin graphic generated by such tools as
+graphviz or blockdiag, in LaTeX source.  This special form of region
+can be inserted via feeding `.dot' into environment completion by
+`[prefix] t b'.
+
+
+
+
+
 File: yatexe, Node: Lpr format, Next: Controlling which command to invoke, Prev: Static region for typesetting, Up: %#notation
 
 Lpr format
@@ -535,7 +560,7 @@
 
 
 
-File: yatexe, Node: Section-type completion, Prev: Begin-type completion, Up: Completion
+File: yatexe, Node: Section-type completion, Next: Label Generation, Prev: Begin-type completion, Up: Completion
 
 Section-type completion
 =======================
@@ -2314,60 +2339,61 @@
 Node: Calling previewer8016
 Node: Printing out8377
 Node: %#notation8669
-Node: Changing typesetter9040
-Node: Splitting input files9404
-Node: Static region for typesetting10833
-Node: Lpr format11962
-Node: Controlling which command to invoke13035
-Node: Editing %# notation13992
-Node: Completion14536
-Node: Begin-type completion15072
-Node: Section-type completion17926
-Node: view-sectioning20318
-Node: Label Generation21897
-Node: Large-type completion22797
-Node: Maketitle-type completion23443
-Node: Arbitrary completion23995
-Node: End completion24385
-Node: Accent completion24855
-Node: Image completion25472
-Node: Greek letters completion27727
-Node: Inserting parentheses28483
-Node: Local dictionaries28890
-Node: Commenting out29827
-Node: Cursor jump31286
-Node: Jump to corresponding object31577
-Node: Invoking image processor32977
-Node: Jump to main file34320
-Node: Jumping around the environment34686
-Node: Jumping to last completion position35104
-Node: Changing and Deleting35613
-Node: Changing LaTeX commands35994
-Node: Killing LaTeX commands37171
-Node: Filling38356
-Node: Updation of includeonly40211
-Node: What column41008
-Node: Intelligent newline42093
-Node: Usepackage checker43754
-Node: Online help44345
-Node: Browsing file hierarchy46020
-Node: Cooperation with other packages47757
-Node: Customizations48462
-Node: Lisp variables48758
-Node: All customizable variables49717
-Node: Sample definitions61682
-Node: Hook variables62195
-Node: Hook file62899
-Node: Add-in functions63238
-Node: How the add-in function works64076
-Node: Defining option-add-in66262
-Node: Defining argument-add-in66984
-Node: Defining enclosing-add-in67865
-Node: How the function is called68721
-Node: Useful functions for creating add-in69397
-Node: Contribution70807
-Node: Add-in generator71081
-Node: Etcetera76657
-Node: Copying77262
+Node: Changing typesetter9069
+Node: Splitting input files9433
+Node: Static region for typesetting10862
+Node: Special Filtering Region11991
+Node: Lpr format12723
+Node: Controlling which command to invoke13796
+Node: Editing %# notation14753
+Node: Completion15297
+Node: Begin-type completion15833
+Node: Section-type completion18687
+Node: view-sectioning21103
+Node: Label Generation22682
+Node: Large-type completion23582
+Node: Maketitle-type completion24228
+Node: Arbitrary completion24780
+Node: End completion25170
+Node: Accent completion25640
+Node: Image completion26257
+Node: Greek letters completion28512
+Node: Inserting parentheses29268
+Node: Local dictionaries29675
+Node: Commenting out30612
+Node: Cursor jump32071
+Node: Jump to corresponding object32362
+Node: Invoking image processor33762
+Node: Jump to main file35105
+Node: Jumping around the environment35471
+Node: Jumping to last completion position35889
+Node: Changing and Deleting36398
+Node: Changing LaTeX commands36779
+Node: Killing LaTeX commands37956
+Node: Filling39141
+Node: Updation of includeonly40996
+Node: What column41793
+Node: Intelligent newline42878
+Node: Usepackage checker44539
+Node: Online help45130
+Node: Browsing file hierarchy46805
+Node: Cooperation with other packages48542
+Node: Customizations49247
+Node: Lisp variables49543
+Node: All customizable variables50502
+Node: Sample definitions62467
+Node: Hook variables62980
+Node: Hook file63684
+Node: Add-in functions64023
+Node: How the add-in function works64861
+Node: Defining option-add-in67047
+Node: Defining argument-add-in67769
+Node: Defining enclosing-add-in68650
+Node: How the function is called69506
+Node: Useful functions for creating add-in70182
+Node: Contribution71592
+Node: Add-in generator71866
+Node: Etcetera77442
+Node: Copying78047
 
 End tag table
--- a/docs/yatexe.tex	Fri Jan 05 00:23:36 2018 +0900
+++ b/docs/yatexe.tex	Sat Jan 06 23:54:17 2018 +0900
@@ -8,7 +8,7 @@
 
 @iftex
 @c @syncodeindex fn cp
-@c Last modified Sat Sep  9 23:41:37 2017 on firestorm
+@c Last modified Sat Jan  6 23:42:24 2018 on firestorm
 @syncodeindex vr cp
 @end iftex
 
@@ -265,6 +265,7 @@
 * Changing typesetter::
 * Splitting input files::
 * Static region for typesetting::
+* Special Filtering Region::
 * Lpr format::
 * Controlling which command to invoke::
 * Editing %# notation::
@@ -377,6 +378,28 @@
 @code{%#BEGIN} alone at the middle of very long text.  Do not forget to
 erase @code{%#BEGIN} @code{%#END} pair.
 
+@node Special Filtering Region, Lpr format, Static region for typesetting, %#notation
+@section Special Filtering Region
+  A region like below will be passed to external filter command.
+@example
+%#BEGIN FILTER{foo.pdf}{dot -T %t -o %o}
+\if0
+....blah blah blah...
+....blah blah blah...
+....blah blah blah...
+\fi
+%#END
+@end example
+
+In this case, typing @kbd{[prefix] t e} send three `blah' lines
+to "dot -T pdf -o foo.pdf" as standard-input.  It is useful to
+have source of text-origin graphic generated by such tools as
+graphviz or blockdiag, in La@TeX{} source.  This special form of region
+can be inserted via feeding @code{.dot} into environment completion by
+@kbd{[prefix] t b}.
+
+
+
 @node Lpr format, Controlling which command to invoke, Static region for typesetting, %#notation
 @comment  node-name,  next,  previous,  up
 @section Lpr format
@@ -587,7 +610,7 @@
 begin-type completion to enclose text into a environment.
 
 
-@node Section-type completion, , Begin-type completion, Completion
+@node Section-type completion, Label Generation, Begin-type completion, Completion
 @comment  node-name,  next,  previous,  up
 @section Section-type completion
 @cindex section-type completion
--- a/docs/yatexj	Fri Jan 05 00:23:36 2018 +0900
+++ b/docs/yatexj	Sat Jan 06 23:54:17 2018 +0900
@@ -21,7 +21,7 @@
 * Main features::               主な機能
 * Installation::                インストール
 * Invocation::                  プロセス起動
-* %#notation ::                 %#記法
+* %#notation ::
 * Completion::                  補完入力
 * Local dictionary::            ローカル辞書
 * Commenting out::              コメントアウト
@@ -326,9 +326,10 @@
 * Changing typesetter::         タイプセット用コマンドの変更
 * Splitting input files::       入力ファイル分割
 * Fix region for typesetting::  領域の固定
+* Special Filtering Region::
 * lpr format::                  プリントアウトコマンド用フォーマット
 * Controlling which command to invoke::  その他の起動コマンド制御
-* Editing %# notation::         %#記法の編集
+* Editing %# notation::
 
 
 
@@ -424,6 +425,33 @@
 し忘れには十分ご注意下さい。
 
 
+
+File: yatexj, Node: Special Filtering Region, Next: lpr format, Prev: Fix region for typesetting, Up: %#notation
+
+自動外部フィルタ
+================
+
+たとえば、テキストファイルから画像を生成するようなツールに与えるソース
+をLaTeXソース中に埋め込み、その部分だけをツールの標準入力に渡すことが
+できます。そのためには以下のようなソースを文書中に書きます。
+
+     %#BEGIN FILTER{foo.pdf}{blockdiag -T %t -o %o}
+     \if0
+     ---
+     ....blah blah blah...
+     ....blah blah blah...
+     ....blah blah blah...
+     ---
+     \fi
+     %#END
+
+この領域内で `[prefix] t e' をタイプすると、この例であればblahのある3
+行が外部コマンド `"blockdiag -T pdf -o foo.pdf"' の標準入力に渡され、
+結果として foo.pdf が生成されます。この特別なブロックは`[prefix] tb'
+の環境補完で、`.blockdiag' のようなピリオドで始まる特殊環境名を入力す
+ることで自動的に挿入されます。
+
+
 
 
 File: yatexj, Node: lpr format, Next: Controlling which command to invoke, Prev: Fix region for typesetting, Up: %#notation
@@ -2255,66 +2283,67 @@
 
 Tag table:
 Node: Top257
-Node: Intro1311
-Node: Terminology1614
-Node: Main features2254
-Node: Installation3376
-Node: Invocation4636
-Node: Calling typesetter5512
-Node: Calling previewer6973
-Node: Print out7289
-Node: %#notation7555
-Node: Changing typesetter7983
-Node: Splitting input files8241
-Node: Fix region for typesetting9197
-Node: lpr format10105
-Node: Controlling which command to invoke10915
-Node: Editing %# notation11629
-Node: Completion12087
-Node: begin型補完12498
-Node: section型補完15247
-Node: 2個以上の引数をとる section型コマンド16340
-Node: Enclose section-type command17156
-Node: Recursive completion17480
-Node: view-sectioning17785
-Node: label-generation18981
-Node: large型補完19655
-Node: maketitle型補完20189
-Node: Arbitrary completion20488
-Node: end補完20801
-Node: Accent mark completion21142
-Node: Image completion21567
-Node: Greek letter completion23382
-Node: Inserting parens23866
-Node: Local dictionary24214
-Node: Commenting out24818
-Node: Cursor jump25978
-Node: 対応オブジェクトへのジャンプ26195
-Node: お絵描きツール起動27181
-Node: メインファイルへのジャンプ28099
-Node: 環境を単位としたジャンプ28435
-Node: 最後の補完位置へのジャンプ28792
-Node: Modifying/Deleting29029
-Node: Changing LaTeX command29435
-Node: Killing LaTeX command29985
-Node: Filling30857
-Node: Includeonly32187
-Node: What column32748
-Node: Intelligent newline33528
-Node: Usepackage cheker34560
-Node: Changing mode of YaTeX34987
-Node: Online help35563
-Node: Inclusion hierarchy browser36540
-Node: Cooperation with other packages37818
-Node: Customizations38273
-Node: Lisp variables38570
-Node: All customizable variables39177
-Node: Sample definitions48157
-Node: Hook variables48591
-Node: Hook file49486
-Node: Add-in functions49692
-Node: Etc49919
-Node: Copying50204
-Node: Concept Index50828
+Node: Intro1290
+Node: Terminology1593
+Node: Main features2233
+Node: Installation3355
+Node: Invocation4615
+Node: Calling typesetter5491
+Node: Calling previewer6952
+Node: Print out7268
+Node: %#notation7534
+Node: Changing typesetter7975
+Node: Splitting input files8233
+Node: Fix region for typesetting9189
+Node: Special Filtering Region10096
+Node: lpr format10732
+Node: Controlling which command to invoke11542
+Node: Editing %# notation12256
+Node: Completion12714
+Node: begin型補完13125
+Node: section型補完15874
+Node: 2個以上の引数をとる section型コマンド16967
+Node: Enclose section-type command17783
+Node: Recursive completion18107
+Node: view-sectioning18412
+Node: label-generation19608
+Node: large型補完20282
+Node: maketitle型補完20816
+Node: Arbitrary completion21115
+Node: end補完21428
+Node: Accent mark completion21769
+Node: Image completion22194
+Node: Greek letter completion24009
+Node: Inserting parens24493
+Node: Local dictionary24841
+Node: Commenting out25445
+Node: Cursor jump26605
+Node: 対応オブジェクトへのジャンプ26822
+Node: お絵描きツール起動27808
+Node: メインファイルへのジャンプ28726
+Node: 環境を単位としたジャンプ29062
+Node: 最後の補完位置へのジャンプ29419
+Node: Modifying/Deleting29656
+Node: Changing LaTeX command30062
+Node: Killing LaTeX command30612
+Node: Filling31484
+Node: Includeonly32814
+Node: What column33375
+Node: Intelligent newline34155
+Node: Usepackage cheker35187
+Node: Changing mode of YaTeX35614
+Node: Online help36190
+Node: Inclusion hierarchy browser37167
+Node: Cooperation with other packages38445
+Node: Customizations38900
+Node: Lisp variables39197
+Node: All customizable variables39804
+Node: Sample definitions48784
+Node: Hook variables49218
+Node: Hook file50113
+Node: Add-in functions50319
+Node: Etc50546
+Node: Copying50831
+Node: Concept Index51455
 
 End tag table
--- a/docs/yatexj.tex	Fri Jan 05 00:23:36 2018 +0900
+++ b/docs/yatexj.tex	Sat Jan 06 23:54:17 2018 +0900
@@ -13,7 +13,7 @@
 @c ノードいじったら C-l C-u C-n 全部のノード更新 C-l C-u C-e
 @c メニュー増やしたら C-l C-u C-m 全部のメニュー更新 C-l C-u C-a
 @c フォーマットするときは C-l C-e C-b
-@c Last modified Sat Sep  9 23:43:04 2017 on firestorm
+@c Last modified Sat Jan  6 23:49:50 2018 on firestorm
 @syncodeindex vr cp
 @end iftex
 
@@ -35,7 +35,7 @@
 * Main features::               主な機能
 * Installation::                インストール
 * Invocation::                  プロセス起動
-* %#notation ::                 %#記法
+* %#notation ::
 * Completion::                  補完入力
 * Local dictionary::            ローカル辞書
 * Commenting out::              コメントアウト
@@ -357,9 +357,10 @@
 * Changing typesetter::         タイプセット用コマンドの変更
 * Splitting input files::       入力ファイル分割
 * Fix region for typesetting::  領域の固定
+* Special Filtering Region::
 * lpr format::                  プリントアウトコマンド用フォーマット
 * Controlling which command to invoke::  その他の起動コマンド制御
-* Editing %# notation::         %#記法の編集
+* Editing %# notation::
 @end menu
 
 @node Changing typesetter, Splitting input files, %#notation , %#notation
@@ -479,6 +480,31 @@
 の消し忘れには十分ご注意下さい。
 @cindex 長いファイルの編集[なかいふあいるのへんしゆう]
 
+@node Special Filtering Region, lpr format, Fix region for typesetting, %#notation
+@section 自動外部フィルタ
+
+たとえば、テキストファイルから画像を生成するようなツールに与えるソースを
+La@TeX{}ソース中に埋め込み、その部分だけをツールの標準入力に渡すことができ
+ます。そのためには以下のようなソースを文書中に書きます。
+
+@example
+%#BEGIN FILTER{foo.pdf}{blockdiag -T %t -o %o}
+\if0
+---
+....blah blah blah...
+....blah blah blah...
+....blah blah blah...
+---
+\fi
+%#END
+@end example
+
+この領域内で @kbd{[prefix] t e} をタイプすると、この例であればblahのある3行が
+外部コマンド @code{"blockdiag -T pdf -o foo.pdf"} の標準入力に渡され、
+結果として foo.pdf が生成されます。この特別なブロックは
+@kbd{[prefix] tb} の環境補完で、@code{.blockdiag} のようなピリオドで始まる
+特殊環境名を入力することで自動的に挿入されます。
+
 @c @node  Require, lpr format, Fix region for typesetting, %#notation
 @comment  node-name,  next,  previous,  up
 
@@ -778,7 +804,7 @@
 だけが挿入され、改行はせずカーソルは自動的に中括弧の内側に移動します。
 
 @menu
-* 2個以上の引数をとる section型コマンド::  
+* 2個以上の引数をとる section型コマンド::
 * Enclose section-type command::  括り補完
 * Recursive completion::        再帰補完
 * view-sectioning::             セクション区切りのアウトライン表示
@@ -1261,11 +1287,11 @@
 
 
 @menu
-* 対応オブジェクトへのジャンプ::  
-* お絵描きツール起動::          
-* メインファイルへのジャンプ::  
-* 環境を単位としたジャンプ::    
-* 最後の補完位置へのジャンプ::  
+* 対応オブジェクトへのジャンプ::
+* お絵描きツール起動::
+* メインファイルへのジャンプ::
+* 環境を単位としたジャンプ::
+* 最後の補完位置へのジャンプ::
 @end menu
 
 @node 対応オブジェクトへのジャンプ, お絵描きツール起動, Cursor jump, Cursor jump
--- a/yatex.el	Fri Jan 05 00:23:36 2018 +0900
+++ b/yatex.el	Sat Jan 06 23:54:17 2018 +0900
@@ -1,6 +1,6 @@
 ;;; yatex.el --- Yet Another tex-mode for emacs //野鳥// -*- coding: sjis -*-
 ;;; (c)1991-2018 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Wed Jan  3 23:56:34 2018 on firestorm
+;;; Last modified Sat Jan  6 22:52:02 2018 on firestorm
 ;;; $Id$
 ;;; The latest version of this software is always available at;
 ;;; https://www.yatex.org/
@@ -376,6 +376,61 @@
   (append YaTeX-ams-math-begin-alist YaTeX-ams-math-gathering-alist)
   "*Standard AMS-LaTeX(2e) environment completion table.")
 
+(defvar YaTeX-use-dot-env-extension t
+  "*Use YaTeX's dot-env filter special environment.")
+(defvar YaTeX-filter-special-env-alist-default
+  '((".blockdiag"
+     "blockdiag -T %t -o %o -"
+     "blockdiag {
+  default_fontsize = 32;
+  A -> B;
+}")
+    (".seqdiag" "seqdiag -T %t -o %o -"
+     "seqdiag {
+  client -> server [label = \"SYN\"];
+  client <- server [label = \"SYN/ACK\"];
+  client -> server [label = \"ACK\"];}")
+    (".actdiag" "actdiag -T %t -o %o -"
+     "actdiag {
+  sayHo -> ho -> hohoho
+  lane dj {
+    label = \"DJ\"
+    sayHo [label = \"Say Ho\"]; hohoho [label = \"Ho Ho Ho!\"]; }
+  lane mc { label = \"MC\"; ho [label = \"Hooooh!\"]}}")
+    (".nwdiag" "nwdiag -T %t -o %o -"
+     "nwdiag {
+  network ext {
+    address = \"10.1.2.0/24\"
+    router [address = \"10.1.2.1\"]
+  }
+  network int {
+    address = \"192.168.22.0/24\"
+    router [address = \"192.168.22.1\"]
+    websrv [address = \"192.168.22.80\"]
+    cli-1; cli-2
+  }
+}")
+    (".rackdiag" "rackdiag -T %t -o %o -"
+     "rackdiag {
+  16U;
+  1: UPS [4U]; 5: Storage [3U]; 8: PC [2U]; 8: PC [2U];
+}")
+    (".dot"
+     "dot -T %t -o %o"
+     "digraph {
+  graph [charset=\"utf-8\"]
+}
+bigraph {
+  graph [charset=\"utf-8\"]}"
+     )))
+
+(defvar YaTeX-filter-special-env-alist-private nil)
+(defvar YaTeX-filter-special-env-alist
+  (append YaTeX-filter-special-env-alist-private
+	  YaTeX-filter-special-env-alist-default))
+
+
+
 ; Set tex-environment possible completion
 (defvar env-table
   (append
@@ -399,7 +454,11 @@
 	 ("multicols")			;defined in multicol
 	 ("breakbox")))			;defined in eclbkbox
    (if YaTeX-use-AMS-LaTeX YaTeX-ams-env-table)
-   YaTeX-math-other-env-alist)
+   YaTeX-math-other-env-alist
+   (if YaTeX-use-dot-env-extension
+       '((".blockdiag") (".nwdiag") (".seqdiag") (".rackdiag") (".packetdiag")
+	 (".dot"))
+     ))
   "Default completion table for begin-type completion.")
 
 (defvar user-env-table nil)
@@ -920,7 +979,10 @@
 by completing read.
  If you invoke this command with universal argument,
 \(key binding for universal-argument is \\[universal-argument]\)
-you can put REGION into that environment between \\begin and \\end."
+you can put REGION into that environment between \\begin and \\end.
+If the environment name begins with `.'(dot),
+that environment will be treated as `special environment', which
+enables special feature such as text conversion."
   (interactive "P")
   (let*
       ((region-p (or arg (YaTeX-region-active-p)))
@@ -928,13 +990,17 @@
        (env
 	(save-excursion		;for Emacs24 work-around to avoid point warp 
 	  (YaTeX-read-environment
-	   (format "Begin environment%s(default %s): " mode YaTeX-env-name)))))
+	   (format "Begin environment%s(default %s): " mode YaTeX-env-name))))
+       special)
     (if (string= env "")
 	(setq env YaTeX-env-name))
-    (setq YaTeX-env-name env)
+    (setq special (assoc env YaTeX-filter-special-env-alist)
+	  YaTeX-env-name env)
     (YaTeX-update-table
      (list YaTeX-env-name) 'env-table 'user-env-table 'tmp-env-table)
-    (YaTeX-insert-begin-end YaTeX-env-name region-p)))
+    (if special
+	(YaTeX-insert-filter-special YaTeX-env-name (cdr special) region-p)
+      (YaTeX-insert-begin-end YaTeX-env-name region-p))))
 
 (defun YaTeX-make-begin-end-region ()
   "Call YaTeX-make-begin-end with ARG to specify region mode."
@@ -1261,6 +1327,17 @@
     ((YaTeX-literal-p) ?\")
     ((= (preceding-char) ?\\ ) ?\")
     ;((= (preceding-char) ?\( ) ?\")
+    ((save-excursion (beginning-of-line)
+		     (skip-chars-forward "\t ")
+		     (looking-at "%#"))
+     ?\")
+    ((let ((ovl (overlays-at (point))))
+       (and ovl
+	    (catch 'found
+	      (while ovl
+		(if (overlay-get (car ovl) 'filter-input) (throw 'found t))
+		(setq ovl (cdr ovl))))))
+     ?\")
     ((or (= (preceding-char) 32)
 	 (= (preceding-char) 9)
 	 (= (preceding-char) ?\n)
--- a/yatex.new	Fri Jan 05 00:23:36 2018 +0900
+++ b/yatex.new	Sat Jan 06 23:54:17 2018 +0900
@@ -3,6 +3,7 @@
 
 1.81	== yatex ==
 	タイプセットコマンド定義中の %k を漢字コード名に変換(-kanji=%k)
+	ドット環境で外部フィルタを自動起動する機能を追加。
 
 1.80	string-to-int除外と同時に emacs-18 をサポート外に。
 	2-Clause BSDでもOKという風に書いてみた。
--- a/yatexprc.el	Fri Jan 05 00:23:36 2018 +0900
+++ b/yatexprc.el	Sat Jan 06 23:54:17 2018 +0900
@@ -1,7 +1,7 @@
 ;;; yatexprc.el --- YaTeX process handler -*- coding: sjis -*-
 ;;; 
 ;;; (c)1993-2018 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Thu Jan  4 00:09:28 2018 on firestorm
+;;; Last modified Fri Jan  5 22:48:43 2018 on firestorm
 ;;; $Id$
 
 ;;; Code:
@@ -353,7 +353,7 @@
 	 reg-begin reg-end lineinfo)
       (setq ppcmd (if (stringp pp) (concat pp " " texputroot) pp))
       (save-excursion
-	(if (search-backward "%#BEGIN" nil t)
+	(if (re-search-backward "%#BEGIN\\s *$" nil t)
 	    (progn
 	      (setq typeout "--- Region from BEGIN to "
 		    end "the end of the buffer ---"
@@ -478,6 +478,36 @@
 The value is generated from YaTeX-typeset-pdf2image-chain and
 YaTeX-typeset-dvi2image-chain.")
 
+(defun YaTeX-popup-image (imagesrc buffer &optional func)
+  (let ((sw (selected-window)) image
+	(data-p (and (> (length imagesrc) 128)
+		     (not (file-readable-p imagesrc)))))
+    (save-excursion
+      (cond
+       ((featurep 'image) window-system
+	(YaTeX-showup-buffer		;showup and select
+	 (get-buffer-create buffer)
+	 (or func 'YaTeX-showup-buffer-bottom-most)
+	 t)
+	(remove-images (point-min) (point-max))
+	(erase-buffer)
+	(insert-image
+	 (setq image (create-image
+		      (if data-p imagesrc (expand-file-name imagesrc))
+		      nil data-p)))
+	(YaTeX-preview-image-mode)
+	(let ((height (1+ (cdr (image-size image)))))
+	  (enlarge-window
+	   (- (ceiling (min height (/ (frame-height) 2)))
+	      (window-height))))
+	(select-window sw))
+       (t	;; Without direct image, display image with image viewer
+	(YaTeX-system
+	 (format "%s %s" YaTeX-cmd-view-images target)
+	 "YaTeX-region-image"
+	 'noask)))
+  )))
+
 (defvar YaTeX-typeset-conv2image-process nil "Process of conv2image chain")
 (defun YaTeX-typeset-conv2image-chain ()
   (let*((proc (or YaTeX-typeset-process YaTeX-typeset-conv2image-process))
@@ -531,39 +561,11 @@
 			     'YaTeX-typeset-conv2image-chain)
 		       (get 'YaTeX-typeset-process 'ppcmd))))
 	;; After all chain executed, display image in current window
-	(cond
-	 ((and (featurep 'image) window-system)
-	  ;; If direct image displaying available in running Emacs,
-	  ;; display target image into the next window in Emacs.
-	  (select-window w)
-	  ;(setq foo (selected-window))
-	  (YaTeX-showup-buffer
-	   (get-buffer-create " *YaTeX-region-image*")
-	   'YaTeX-showup-buffer-bottom-most t)
-	  (remove-images (point-min) (point-max))
-	  (erase-buffer)
-	  (cd pwd)			;when reuse from other source
-					;(put-image (create-image (expand-file-name target)) (point))
-	  (insert-image-file target)
-	  (setq img (plist-get (text-properties-at (point)) 'intangible))
-	  (YaTeX-preview-image-mode)
-	  (if img
-	      (let ((height (1+ (cdr (image-size img)))))
-		(enlarge-window
-		 (- (ceiling (min height (/ (frame-height) 2)))
-		    (window-height)))))
-	  ;; Remember elapsed time, which will be threshold in onthefly-preview
-	  (put 'YaTeX-typeset-conv2image-chain 'elapse
-	       (YaTeX-elapsed-time
-		(get 'YaTeX-typeset-conv2image-chain 'start) (current-time))))
-	 (t
-	  ;; Without direct image, display image with image viewer
-	  (YaTeX-system
-	   (format "%s %s" YaTeX-cmd-view-images target)
-	   "YaTeX-region-image"
-	   'noask)
-	  )
-	 )))))
+	(YaTeX-popup-image target " *YaTeX-popup-image*")
+	(put 'YaTeX-typeset-conv2image-chain 'elapse
+	     (YaTeX-elapsed-time
+	      (get 'YaTeX-typeset-conv2image-chain 'start) (current-time)))
+	))))
 
 
 (defvar YaTeX-typeset-environment-timer nil)
@@ -657,6 +659,14 @@
 	  (if usetimer (YaTeX-typeset-environment-auto b e)))
       (YaTeX-typeset-region))))
 
+(defun YaTeX-filter-BEGEND ()
+  (let ((begend-info (YaTeX-in-BEGEND-p)))
+    (if begend-info
+	(progn
+	  (require 'yatexflt)
+	  (YaTeX-filter-pass-to-filter begend-info)
+	  ))))
+
 (defun YaTeX-typeset-environment ()
   "Typeset current environment or paragraph.
 If region activated, use it."
@@ -664,7 +674,8 @@
   (let ((md (match-data)))
     (unwind-protect
 	(save-excursion
-	  (YaTeX-typeset-environment-1))
+	  (or (YaTeX-filter-BEGEND)
+	      (YaTeX-typeset-environment-1)))
       (store-match-data md))))
 
 

yatex.org