changeset 392:c44910b36b95 dev

Switch to region-mode if completion called with active region.
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 15 Jan 2015 23:21:24 +0900
parents e834bbfce2ab
children 318841b09570
files docs/yatexe.tex docs/yatexj.tex yahtml.el yatex.el yatex.new yatexlib.el
diffstat 6 files changed, 215 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- a/docs/yatexe.tex	Thu Jan 15 23:20:31 2015 +0900
+++ b/docs/yatexe.tex	Thu Jan 15 23:21:24 2015 +0900
@@ -8,7 +8,7 @@
 
 @iftex
 @c @syncodeindex fn cp
-@c Last modified Sun Jan  4 18:17:02 2015 on firestorm
+@c Last modified Thu Jan 15 13:28:10 2015 on firestorm
 @syncodeindex vr cp
 @end iftex
 
@@ -77,7 +77,7 @@
         @code{\section} etc. 
         (@kbd{C-c b}, @kbd{C-c s}, @kbd{C-c l}, @kbd{C-c m})
 @item Enclosing text into La@TeX{} environments or commands
-      (@kbd{C-u} @var{AboveKeyStrokes})
+      (@var{AboveKeyStrokes} after region setting)
 @item Displaying the structure of text at entering sectioning commands
 @item Lump shifting of sectioning commands (@ref{view-sectioning})
 @item Learning unknown/new La@TeX{} commands for the next completion
@@ -146,12 +146,12 @@
 
 @table @kbd
 @item [prefix] t j
-        @dots{} invoke latex
+        @dots{} invoke typesetter
 @item [prefix] t r
-        @dots{} invoke latex on region
+        @dots{} invoke typesetter on region
 @item [prefix] t e
-        @dots{} invoke latex on current environment or whole
-         portion of current formulas in math-mode.
+        @dots{} `on-the-fly preview' on current environment or whole
+         portion of current formulas in math-mode
 @item [prefix] t d
 	@dots{} invoke dvipdfmx after successful typesetting
 @item [prefix] t k
@@ -215,9 +215,16 @@
 edit splitting files.
 
   The @kbd{[prefix] te} key automatically marks current inner environment
-or inner math mode and then call typeset-region with marked region.  This
+or inner math mode or paragraph, and then call typeset-region with marked
+region.  This
 is convenient to quick view of current tabular environment or current
-editing formulas.  Keeping previewer window for @file{texput.dvi} is handy
+editing formulas.  If running Emacs has the ability of displaying images,
+typeset image will be shown in the next window.  Further more,
+if you modify the content within that environment, YaTeX performs
+`on-the-fly' preview that automatically update preview image as you typed.
+
+If your Emacs does not supply on-the-fly preview,
+keeping previewer window for @file{texput.dvi} is handy
 for debugging.  Since @kbd{[prefix] te} selects the inner-most environment
 as region, it is not suitable for partial typesetting of doubly or more
 composed environment.  If you want to do partial typesetting for a nested
@@ -369,7 +376,7 @@
 @code{%#BEGIN} alone at the middle of very long text.  Do not forget to
 erase @code{%#BEGIN} @code{%#END} pair.
 
-@node Lpr format, Controlling which command to invoke, Static region for typesetting, %#notation
+@node Lpr format,  , Static region for typesetting, %#notation
 @comment  node-name,  next,  previous,  up
 @section Lpr format
 @cindex lpr format
@@ -464,15 +471,16 @@
 kinds of completion type, begin-type, section-type, large-type, etc...
 
 @menu
-* Begin-type completion::       
-* Section-type completion::     
-* Large-type completion::       
-* Maketitle-type completion::   
-* Arbitrary completion::        
-* End completion::              
-* Accent completion::           
-* Image completion::            
-* Greek letters completion::    
+* Begin-type completion::
+* Section-type completion::
+* Large-type completion::
+* Maketitle-type completion::
+* Arbitrary completion::
+* End completion::
+* Accent completion::
+* Image completion::
+* Greek letters completion::
+* Inserting parentheses::
 @end menu
 
 @node Begin-type completion, Section-type completion, Completion, Completion
@@ -559,26 +567,15 @@
 automatically inserted such as @code{\item} for @code{itemize}
 environment.  If you don't want the entry, it can be removed by undoing.
 
-  If you want to  enclose some paragraphs  which have already been
-written, invoke the  begin-type completion with changing  the case
-of @kbd{b} of key sequence upper(or invoke it with  universal argument
-by @kbd{C-u} prefix).
+  If you want to enclose some paragraphs which have already been written
+into environment, invoke the begin-type completion right after region marking.
 @cindex enclose region into environment
 
-  The following example encloses a region with `description'
-environment.
-
-@table @kbd
-@item [prefix] B D
-@itemx (or ESC 1 [prefix] b D)
-@itemx (or  C-u  [prefix] b D)
-
-        @dots{} begin-type completion for region
-@end table
-
-  This enclosing holds good for the completing input by @kbd{[prefix] b
-SPC}.  @kbd{[prefix] B SPC} enclose a region with the environment selected
-by completing-read.
+If you set @code{transient-mark-mode} to @code{nil} in your
+@file{~/.emacs},  typing @kbd{C-space} (@code{set-mark-command}) twice
+turns @code{transient-mark-mode} on temporarily.  Then, type call
+begin-type completion to enclose text into a environment.
+
 
 @node Section-type completion, Large-type completion, Begin-type completion, Completion
 @comment  node-name,  next,  previous,  up
@@ -755,9 +752,8 @@
 TeX commands to change fonts or sizes, @code{it}, @code{huge} and so on,
 in the completion table.
 
-  Region-based completion is also invoked by changing the letter after
-prefix key stroke as @kbd{[prefix] L}.  It encloses the region by braces
-with large-type command.
+  Region-based completion is also invoked by calling completion
+after region activated.
 
 @node Maketitle-type completion, Arbitrary completion, Large-type completion, Completion
 @comment  node-name,  next,  previous,  up
@@ -912,7 +908,7 @@
 Emacs-Lisp variable @code{YaTeX-math-sign-alist-private}.  See also
 @file{yatexmth.el} for the information of the structure of this variable.
 
-@node Greek letters completion,  , Image completion, Completion
+@node Greek letters completion, Inserting parentheses, Image completion, Completion
 @comment  node-name,  next,  previous,  up
 @section Greek letters completion
 @cindex Greek letters completion
@@ -930,6 +926,15 @@
 @kbd{;} or @kbd{:} after universal-argument(@kbd{C-u}) which forces
 @kbd{;} and @kbd{:} to work as math-prefix.
 
+@node Inserting parentheses,  , Greek letters completion, Completion
+@section Inserting parentheses
+
+  Typing opening parenthesis, one of @code{(}, @code{@{ and @code{[}},
+automatically inserts the closing one.  If a opening bracket is typed
+after @code{\}, @code{\]} is automatically inserted with computed
+indentation.  If you stop automatic insertion, type @kbd{C-q} before
+opening parenthesis.
+
 @node Local dictionaries, Commenting out, Completion, Top
 @comment  node-name,  next,  previous,  up
 @chapter Local dictionaries
@@ -1700,6 +1705,16 @@
 @code{Nil} disables on-the-fly preview.
 @end defvar
 
+@defvar YaTeX-on-the-fly-math-preview-engine
+Function symbol to use on-the-fly preview of MATH environment
+started by @kbd{[prefix] t e} (@code{'YaTeX-typeset-environment-by-lmp}
+which calls latex-math-preview-expression function if latex-math-preview
+is available, otherwise @code{'YaTeX-typeset-environment-by-builtin} which
+alls built-in function).
+
+@code{Nil} disables on-the-fly preview.
+@end defvar
+
 @defvar YaTeX-cmd-gimp
 Command name of GIMP (code{"gimp"})
 @end defvar
--- a/docs/yatexj.tex	Thu Jan 15 23:20:31 2015 +0900
+++ b/docs/yatexj.tex	Thu Jan 15 23:21:24 2015 +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 Sun Jan  4 18:15:05 2015 on firestorm
+@c Last modified Thu Jan 15 12:42:54 2015 on firestorm
 @syncodeindex vr cp
 @end iftex
 
@@ -124,7 +124,7 @@
 コマンドの補完入力
 (@kbd{C-c b}, @kbd{C-c s}, @kbd{C-c l}, @kbd{C-c m})
 @item 既に入力したテキストを環境やコマンド引数の中に取り込む括り補完
-(@kbd{C-u} +通常補完キー)
+(リジョン指定後に通常補完キー)
 @item セクション区切り入力時の文書構造アウトライン表示
 @item セクションコマンドの一括シフト (@ref{view-sectioning})
 @item 補完辞書の学習
@@ -228,8 +228,9 @@
 @item [prefix] t r
         @dots{} タイプセッタ起動(領域指定)
 @item [prefix] t e
-        @dots{} タイプセッタ起動
-        (ポイント位置の環境または数式モードのみ対象)
+        @dots{} 部分タイプセット&プレヴュー
+        (ポイント位置の段落、環境または数式モードのみをタイプセットして
+        隣のバッファに組版結果の画像を出す)
 @item [prefix] t k
         @dots{} 動作中のタイプセッタの停止
 @item [prefix] t b
@@ -296,11 +297,20 @@
 @subsection 環境タイプセット
 
   @kbd{[prefix] te} を押すと、ポイント位置の最も内側の環境、または数式モー
-ド内の場合はその数式モード全体が自動的に領域選択されて、領域タイプセットを
-呼び出します。tabular環境や数式モードで複雑なものを作っている場合は確かめた
-い部分だけを確認できるので便利です。これも @file{texput.tex} に該当部分を
-書き出します。プレヴューアで @file{texput.dvi} を開いたままにしておけば
-修正と確認が素早くできるでしょう。
+ド内の場合はその数式モード全体、あるいは環境がなければその段落が自動的に
+領域選択されて、領域タイプセットを呼び出します。
+tabular環境や数式モードで複雑なものを作っている場合は確かめたい部分だけを
+確認できるので便利です。Emacsが画像表示可能な場合は、
+部分タイプセットの結果を画像化して隣のウィンドウに表示します。また、
+特定の環境で呼び出した場合は、環境内の文字を書き換える度に自動的に
+プレビュー画像を更新します(on-the-flyプレヴュー)。
+自動表示されない場合はプレヴューアで @file{texput.dvi}
+を開いたままにしておけば修正と確認が素早くできるでしょう。
+
+  画像プレヴューの場合の大きさ(解像度)はデフォルトで200dpi(数式は300dpi)です。
+dpiを変えたい場合はLaTeXソースのどこかに
+@code{%#PREVIEWDPI 150}
+のようにdpi値を書いてください。
 
 @node Calling previewer, Print out, Calling typesetter, Invocation
 @comment  node-name,  next,  previous,  up
@@ -570,15 +580,16 @@
 ができます。
 
 @menu
-* begin型補完::                 
-* section型補完::               
-* large型補完::                 
-* maketitle型補完::             
+* begin型補完::
+* section型補完::
+* large型補完::
+* maketitle型補完::
 * Arbitrary completion::        随時補完
-* end補完::                     
+* end補完::
 * Accent mark completion::      アクセント記号補完
 * Image completion::            数式記号イメージ補完
 * Greek letter completion::     ギリシャ文字補完
+* Inserting parens::
 @end menu
 
 @node begin型補完, section型補完, Completion, Completion
@@ -678,17 +689,19 @@
 @cindex 閉じ込める[としこめる]
 
   例えばあるパラグラフを description 環境の中に入れたいときは、
-そのパラグラフをマークしてから、
-
-@table @kbd
-@item [prefix] B D
-@itemx (または ESC 1 [prefix] b D)
-@itemx (または  C-u  [prefix] b D など)
-@end table
-
-とタイプしてください。これは、@kbd{[prefix] b SPC}の補完入力にもあてはまり、
-@kbd{b} を大文字に変えて、@kbd{[prefix] B SPC} とタイプすれば、あらかじめ
-マークしておいたリジョンを、begin と end の環境で括ります。
+そのパラグラフをマークしてから、補完機能を呼び出してください(description
+環境の場合は @kbd{[prefix] b D})。
+
+選択された領域を括ります。ただしこれは @code{transient-mark-mode} が t
+(Emacsの標準)になっている場合のみで、普段
+@code{transient-mark-mode} を @code{nil} にしている場合は、
+補完キー前に @code{universal-argument} 指定(@kbd{C-u})
+をタイプしてから @kbd{[prefix] b D} など、補完キーを
+タイプすれば括り補完になります。
+なおEmacs22以降であれば @code{transient-mark-mode} 無効時も
+@code{set-mark-command} (@kbd{C-space})の連打で一時的に
+@code{transient-mark-mode} が有効になります。
+
 
 @node section型補完, large型補完, begin型補完, Completion
 @comment  node-name,  next,  previous,  up
@@ -801,8 +814,11 @@
 @subsection 既に書いたテキストを括る
 @cindex 括る[くくる]
 
-  また、起動コマンドの@kbd{s}を大文字に変えて起動すると、あらかじめ書
-いた文章を section 型コマンドの第一引数として括ります。
+  また、section型補完機能の呼び出し時に領域選択状態にしておくと
+領域内のテキストを section 型コマンドの第一引数として括ります。
+これも普段 @code{transient-mark-mode} を @code{nil} にしている場合は
+@kbd{C-u} のあとに補完キーをタイプすれば強制的に括り補完になります。
+
 
 @node Recursive completion, view-sectioning, Enclose section-type command, section型補完
 @comment  node-name,  next,  previous,  up
@@ -911,8 +927,7 @@
 
   また、begin型補完の時と同様、先に書いてしまった一連の文章の文字のサイズ
 を変えたいと思う時がありますが、そのような時は、サイズや大きさを変えたい文
-字の範囲をマークしてから、呼び出しキーを @kbd{[prefix] L} と、大文字の L 
-に変えて呼び出せば、そのリジョン全体が、ブレースで囲まれます。
+字の範囲をマークしてからlarge型補完を呼んでください。
 
 @node maketitle型補完, Arbitrary completion, large型補完, Completion
 @comment  node-name,  next,  previous,  up
@@ -1082,7 +1097,7 @@
 照してください。
 @cindex YaTeX-math-sign-alist-private
 
-@node Greek letter completion,  , Image completion, Completion
+@node Greek letter completion, Inserting parens, Image completion, Completion
 @comment  node-name,  next,  previous,  up
 @section ギリシャ文字補完
 @cindex ギリシャ文字補完[きりしやもしほかん]
@@ -1100,6 +1115,18 @@
 とにより、強制的にイメージ補完に入ることができます。また、この時にどのよう
 な状態で数式環境内判定に失敗したかをご連絡下さい。
 
+@node Inserting parens,  , Greek letter completion, Completion
+@section 括弧入力補助
+@cindex 括弧入力補助[かつこにゆうりよくほしよ]
+
+  3種類ある括弧 () {} [] の開き括弧を入れたときに閉じ括弧を自動的に入れます。
+@code{\} の直後にの @code{[} を入れると行を分けてインデントを揃え、
+数式入力に備えます。その他 La@TeX{} のマクロに応じて括弧の釣合の取れた
+状態に導きます。開き括弧そのものを1つだけ入れたいときは @kbd{C-q} で
+クォート入力するか、@kbd{[prefix] w m} で修正モードをOFFにしてください。
+
+  領域選択してから開き括弧を入れるとその領域をその種類の括弧で括ります。
+
 @node Local dictionary, Commenting out, Completion, Top
 @comment  node-name,  next,  previous,  up
 @chapter ローカル辞書
@@ -1898,11 +1925,18 @@
 @end defvar
 
 @defvar YaTeX-on-the-fly-preview-interval
-@kbd{[prefix] t e}で環境即時プレヴューをする場合の変換処理までの
+@kbd{[prefix] t e}で環境即時previewをする場合の変換処理までの
 無操作時間(秒) (0.9)
 @code{nil} の場合は即時プレヴューをしない。
 @end defvar
 
+@defvar YaTeX-on-the-fly-math-preview-engine
+@kbd{[prefix] t e}で数式環境を即時previewする時に用いるエンジン
+(latex-math-previewが利用可能なときは latex-math-preview-expression を呼ぶ
+@code{'YaTeX-typeset-environment-by-lmp}
+そうでないときは内蔵関数を呼ぶ @code{'YaTeX-typeset-environment-by-builtin})
+@end defvar
+
 @defvar YaTeX-cmd-gimp
 GIMPを起動するコマンド (code{"gimp"})
 @end defvar
--- a/yahtml.el	Thu Jan 15 23:20:31 2015 +0900
+++ b/yahtml.el	Thu Jan 15 23:21:24 2015 +0900
@@ -1,6 +1,6 @@
 ;;; yahtml.el --- Yet Another HTML mode -*- coding: sjis -*-
 ;;; (c) 1994-2013 by HIROSE Yuuji [yuuji(@)yatex.org]
-;;; Last modified Mon Dec 22 22:17:24 2014 on firestorm
+;;; Last modified Thu Jan 15 11:34:59 2015 on firestorm
 ;;; $Id$
 
 (defconst yahtml-revision-number "1.77"
@@ -830,7 +830,8 @@
 (defun yahtml-insert-begend (&optional region env)
   "Insert <cmd> ... </cmd>."
   (interactive "P")
-  (setq yahtml-current-completion-type 'multiline)
+  (setq yahtml-current-completion-type 'multiline
+	region (or region (YaTeX-region-active-p)))
   (let*((completion-ignore-case t)
 	(cmd
 	 (or env
@@ -1646,7 +1647,8 @@
 (defun yahtml-insert-tag (region-mode &optional tag)
   "Insert <TAG> </TAG> and put cursor inside of them."
   (interactive "P")
-  (setq yahtml-current-completion-type 'inline)
+  (setq yahtml-current-completion-type 'inline
+	region-mode (or region-mode (YaTeX-region-active-p)))
   (or tag
       (let ((completion-ignore-case t))
 	(setq tag
@@ -2493,13 +2495,6 @@
 		    (match-beginning 0))))
 	(fset 'move-to-column yahtml-saved-move-to-column)))))
 
-;(defun yahtml-indent-new-commnet-line ()
-;  (unwind-protect
-;      (progn
-;	(fset 'move-to-column 'yahtml-move-to-column)
-;	(apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
-;    (fset 'move-to-column yahtml-saved-move-to-column)))
-
 ;;;
 ;;; ---------- move forward/backward field ----------
 ;;;
--- a/yatex.el	Thu Jan 15 23:20:31 2015 +0900
+++ b/yatex.el	Thu Jan 15 23:21:24 2015 +0900
@@ -1,6 +1,6 @@
 ;;; yatex.el --- Yet Another tex-mode for emacs //野鳥// -*- coding: sjis -*-
 ;;; (c)1991-2015 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Thu Jan 15 10:42:01 2015 on firestorm
+;;; Last modified Thu Jan 15 23:15:51 2015 on firestorm
 ;;; $Id$
 ;;; The latest version of this software is always available at;
 ;;; http://www.yatex.org/
@@ -8,7 +8,7 @@
 ;;; Code:
 (require 'comment)
 (require 'yatexlib)
-(defconst YaTeX-revision-number "1.78.5"
+(defconst YaTeX-revision-number "1.78.6"
   "Revision number of running yatex.el")
 
 ;---------- Local variables ----------
@@ -864,16 +864,18 @@
 you can put REGION into that environment between \\begin and \\end."
   (interactive "P")
   (let*
-      ((mode (if arg " region" ""))
+      ((region-p (or arg (YaTeX-region-active-p)))
+       (mode (if region-p " region" ""))
        (env
-	(YaTeX-read-environment
-	 (format "Begin environment%s(default %s): " mode YaTeX-env-name))))
+	(save-excursion		;for Emacs24 work-around to avoid point warp 
+	  (YaTeX-read-environment
+	   (format "Begin environment%s(default %s): " mode YaTeX-env-name)))))
     (if (string= env "")
 	(setq env YaTeX-env-name))
     (setq 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 arg)))
+    (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."
@@ -928,7 +930,8 @@
 Optional 4th arg CMD is LaTeX command name, for non-interactive use."
   (interactive "P")
   (setq YaTeX-current-completion-type 'section)
-  (if (equal arg '(4)) (setq beg (region-beginning) end (region-end)))
+  (if (or (equal arg '(4)) (YaTeX-region-active-p))
+      (setq beg (region-beginning) end (region-end)))
   (unwind-protect
       (let*
 	  ((source-window (selected-window))
@@ -1028,7 +1031,9 @@
 \(key binding for universal-argument is \\[universal-argument]\)"
   (interactive "P")
   (YaTeX-sync-local-table 'tmp-fontsize-table)
-  (let* ((mode (if arg "region" ""))
+  (let* ((region-p (if (or arg (YaTeX-region-active-p))
+		       (cons (region-beginning) (region-end))))
+	 (mode (if region-p "region" ""))
 	 (fontsize
 	  (or fontsize
 	      (YaTeX-read-fontsize
@@ -1050,12 +1055,14 @@
 	 (setq fontsize
 	       (cdr (assoc YaTeX-fontsize-name LaTeX2e-fontstyle-alist)))
 	 (setq YaTeX-fontsize-name fontsize))
-    (if arg
-	(save-excursion
-	  (if (> (point) (mark)) (exchange-point-and-mark))
+    (if region-p
+	(let ((b (car region-p))
+	      (e (set-marker (make-marker) (cdr region-p))))
+	  (goto-char b)
 	  (insert "{\\" YaTeX-fontsize-name " ")
-	  (exchange-point-and-mark)
-	  (insert "}"))
+ 	  (goto-char e)
+	  (insert "}")
+	  (set-marker e nil))
       (insert (concat "{\\" YaTeX-fontsize-name " }"))
       (forward-char -1)
       (if YaTeX-current-position-register
@@ -1267,7 +1274,7 @@
 			  (get 'YaTeX-insert-braces 'begend-guide)))))))))
 	env macro not-literal b e)
     (cond
-     ((and (fboundp 'region-active-p) (region-active-p))
+     ((YaTeX-region-active-p)
       (YaTeX-insert-braces-region (region-beginning) (region-end)))
      ((YaTeX-jmode) (YaTeX-self-insert arg))
      ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
@@ -1388,6 +1395,8 @@
   (interactive "p")
   (let ((col (1- (current-column))))
     (cond
+     ((YaTeX-region-active-p)
+      (YaTeX-insert-brackets-region (region-beginning) (region-end)))
      ((YaTeX-jmode) (YaTeX-self-insert arg))
      ((not (YaTeX-closable-p))
       (YaTeX-self-insert arg))
@@ -1434,6 +1443,8 @@
   "Insert parenthesis pair."
   (interactive "p")
   (cond
+   ((YaTeX-region-active-p)
+    (YaTeX-insert-parens-region (region-beginning) (region-end)))
    ((YaTeX-jmode) (YaTeX-self-insert arg))
    ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
    ((save-excursion
@@ -2668,64 +2679,6 @@
 		      YaTeX-verbatim-environments))))))
       (store-match-data md))))
 
-(defun YaTeX-in-environment-p (env)
-  "Return if current LaTeX environment is ENV.
-ENV is given in the form of environment's name or its list."
-  (let ((md (match-data)) (nest 0) p envrx)
-    (cond
-     ((atom env)
-      (setq envrx
-	    (concat "\\("
-		    (regexp-quote
-		     (YaTeX-replace-format-args
-		      YaTeX-struct-begin env "" ""))
-		    "\\>\\)\\|\\("
-		    (regexp-quote
-		     (YaTeX-replace-format-args
-		      YaTeX-struct-end env "" ""))
-		    "\\)"))
-      (save-excursion
-	(setq p (catch 'open
-		  (while (YaTeX-re-search-active-backward
-			  envrx YaTeX-comment-prefix nil t)
-		    (if (match-beginning 2)
-			(setq nest (1+ nest))
-		      (setq nest (1- nest)))
-		    (if (< nest 0)
-			(throw 'open (cons env (match-beginning 0)))))))))
-     ((listp env)
-      (setq p
-	    (or (YaTeX-in-environment-p (car env))
-		(and (cdr env) (YaTeX-in-environment-p (cdr env)))))))
-    (store-match-data md)
-    p;(or p (YaTeX-in-verb-p (match-beginning 0)))
-    ))
-
-(defun YaTeX-quick-in-environment-p (env)
-  "Check quickly but unsure if current environment is ENV.
-ENV is given in the form of environment's name or its list.
-This function returns correct result only if ENV is NOT nested."
-  (save-excursion
-    (let ((md (match-data)) m0 (p (point)) rc clfound)
-      (cond
-       ((listp env)
-	(or (YaTeX-quick-in-environment-p (car env))
-	    (and (cdr env) (YaTeX-quick-in-environment-p (cdr env)))))
-       (t
-	(unwind-protect
-	    (if (prog1
-		    (YaTeX-search-active-backward
-		     (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
-		     YaTeX-comment-prefix nil t)
-		  (setq m0 (match-beginning 0)))
-		(if (YaTeX-search-active-forward
-		     (YaTeX-replace-format-args
-		      YaTeX-struct-end env)
-		     YaTeX-comment-prefix p t nil)
-		    nil			;if \end{env} found, return nil
-		  (cons env m0)))	;else, return meaningful values
-	  (store-match-data md)))))))
-
 ;; Filling \item
 (defun YaTeX-remove-trailing-comment (start end)
   "Remove trailing comment from START to end."
--- a/yatex.new	Thu Jan 15 23:20:31 2015 +0900
+++ b/yatex.new	Thu Jan 15 23:21:24 2015 +0900
@@ -4,6 +4,9 @@
 1.79	=== yatex ===
 	数式環境など特定環境内の [prefix] t e で On-the-fly preview 発動。
 	YaTeX-help-file のデフォルト位置を site-lisp/yatex/help/ に変更。
+	領域活性時に呼び出す補完は領域括りになるようにした。
+	=== yahtml ===
+	領域活性時に呼び出す補完は領域括りになるようにした。
 	...
 
 
--- a/yatexlib.el	Thu Jan 15 23:20:31 2015 +0900
+++ b/yatexlib.el	Thu Jan 15 23:21:24 2015 +0900
@@ -1,7 +1,7 @@
 ;;; yatexlib.el --- YaTeX and yahtml common libraries
 ;;; 
 ;;; (c)1994-2013 by HIROSE Yuuji.[yuuji@yatex.org]
-;;; Last modified Sun Jan  4 21:04:29 2015 on firestorm
+;;; Last modified Thu Jan 15 11:22:54 2015 on firestorm
 ;;; $Id$
 
 ;;; Code:
@@ -974,6 +974,64 @@
 	   (progn (skip-chars-forward open) (1+ (point)))
 	   (progn (skip-chars-forward close) (point)))))))
 
+(defun YaTeX-in-environment-p (env)
+  "Return if current LaTeX environment is ENV.
+ENV is given in the form of environment's name or its list."
+  (let ((md (match-data)) (nest 0) p envrx)
+    (cond
+     ((atom env)
+      (setq envrx
+	    (concat "\\("
+		    (regexp-quote
+		     (YaTeX-replace-format-args
+		      YaTeX-struct-begin env "" ""))
+		    "\\>\\)\\|\\("
+		    (regexp-quote
+		     (YaTeX-replace-format-args
+		      YaTeX-struct-end env "" ""))
+		    "\\)"))
+      (save-excursion
+	(setq p (catch 'open
+		  (while (YaTeX-re-search-active-backward
+			  envrx YaTeX-comment-prefix nil t)
+		    (if (match-beginning 2)
+			(setq nest (1+ nest))
+		      (setq nest (1- nest)))
+		    (if (< nest 0)
+			(throw 'open (cons env (match-beginning 0)))))))))
+     ((listp env)
+      (setq p
+	    (or (YaTeX-in-environment-p (car env))
+		(and (cdr env) (YaTeX-in-environment-p (cdr env)))))))
+    (store-match-data md)
+    p;(or p (YaTeX-in-verb-p (match-beginning 0)))
+    ))
+
+(defun YaTeX-quick-in-environment-p (env)
+  "Check quickly but unsure if current environment is ENV.
+ENV is given in the form of environment's name or its list.
+This function returns correct result only if ENV is NOT nested."
+  (save-excursion
+    (let ((md (match-data)) m0 (p (point)) rc clfound)
+      (cond
+       ((listp env)
+	(or (YaTeX-quick-in-environment-p (car env))
+	    (and (cdr env) (YaTeX-quick-in-environment-p (cdr env)))))
+       (t
+	(unwind-protect
+	    (if (prog1
+		    (YaTeX-search-active-backward
+		     (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
+		     YaTeX-comment-prefix nil t)
+		  (setq m0 (match-beginning 0)))
+		(if (YaTeX-search-active-forward
+		     (YaTeX-replace-format-args
+		      YaTeX-struct-end env)
+		     YaTeX-comment-prefix p t nil)
+		    nil			;if \end{env} found, return nil
+		  (cons env m0)))	;else, return meaningful values
+	  (store-match-data md)))))))
+
 (defun YaTeX-goto-corresponding-environment (&optional allow-mismatch noerr)
   "Go to corresponding begin/end enclosure.
 Optional argument ALLOW-MISMATCH allows mismatch open/clese.  Use this
@@ -1299,6 +1357,9 @@
 	  'buffer-substring-no-properties
 	'buffer-substring))
 
+(defun YaTeX-region-active-p ()
+  (and (fboundp 'region-active-p) (region-active-p)))
+
 ;;;
 ;; hilit19 vs. font-lock
 ;;;

yatex.org