yatex

diff yatexlib.el @ 392:c44910b36b95

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 f061b37c7542
children 318841b09570
line diff
     1.1 --- a/yatexlib.el	Sun Jan 04 21:41:00 2015 +0900
     1.2 +++ b/yatexlib.el	Thu Jan 15 23:21:24 2015 +0900
     1.3 @@ -1,7 +1,7 @@
     1.4  ;;; yatexlib.el --- YaTeX and yahtml common libraries
     1.5  ;;; 
     1.6  ;;; (c)1994-2013 by HIROSE Yuuji.[yuuji@yatex.org]
     1.7 -;;; Last modified Sun Jan  4 21:04:29 2015 on firestorm
     1.8 +;;; Last modified Thu Jan 15 11:22:54 2015 on firestorm
     1.9  ;;; $Id$
    1.10  
    1.11  ;;; Code:
    1.12 @@ -974,6 +974,64 @@
    1.13  	   (progn (skip-chars-forward open) (1+ (point)))
    1.14  	   (progn (skip-chars-forward close) (point)))))))
    1.15  
    1.16 +(defun YaTeX-in-environment-p (env)
    1.17 +  "Return if current LaTeX environment is ENV.
    1.18 +ENV is given in the form of environment's name or its list."
    1.19 +  (let ((md (match-data)) (nest 0) p envrx)
    1.20 +    (cond
    1.21 +     ((atom env)
    1.22 +      (setq envrx
    1.23 +	    (concat "\\("
    1.24 +		    (regexp-quote
    1.25 +		     (YaTeX-replace-format-args
    1.26 +		      YaTeX-struct-begin env "" ""))
    1.27 +		    "\\>\\)\\|\\("
    1.28 +		    (regexp-quote
    1.29 +		     (YaTeX-replace-format-args
    1.30 +		      YaTeX-struct-end env "" ""))
    1.31 +		    "\\)"))
    1.32 +      (save-excursion
    1.33 +	(setq p (catch 'open
    1.34 +		  (while (YaTeX-re-search-active-backward
    1.35 +			  envrx YaTeX-comment-prefix nil t)
    1.36 +		    (if (match-beginning 2)
    1.37 +			(setq nest (1+ nest))
    1.38 +		      (setq nest (1- nest)))
    1.39 +		    (if (< nest 0)
    1.40 +			(throw 'open (cons env (match-beginning 0)))))))))
    1.41 +     ((listp env)
    1.42 +      (setq p
    1.43 +	    (or (YaTeX-in-environment-p (car env))
    1.44 +		(and (cdr env) (YaTeX-in-environment-p (cdr env)))))))
    1.45 +    (store-match-data md)
    1.46 +    p;(or p (YaTeX-in-verb-p (match-beginning 0)))
    1.47 +    ))
    1.48 +
    1.49 +(defun YaTeX-quick-in-environment-p (env)
    1.50 +  "Check quickly but unsure if current environment is ENV.
    1.51 +ENV is given in the form of environment's name or its list.
    1.52 +This function returns correct result only if ENV is NOT nested."
    1.53 +  (save-excursion
    1.54 +    (let ((md (match-data)) m0 (p (point)) rc clfound)
    1.55 +      (cond
    1.56 +       ((listp env)
    1.57 +	(or (YaTeX-quick-in-environment-p (car env))
    1.58 +	    (and (cdr env) (YaTeX-quick-in-environment-p (cdr env)))))
    1.59 +       (t
    1.60 +	(unwind-protect
    1.61 +	    (if (prog1
    1.62 +		    (YaTeX-search-active-backward
    1.63 +		     (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
    1.64 +		     YaTeX-comment-prefix nil t)
    1.65 +		  (setq m0 (match-beginning 0)))
    1.66 +		(if (YaTeX-search-active-forward
    1.67 +		     (YaTeX-replace-format-args
    1.68 +		      YaTeX-struct-end env)
    1.69 +		     YaTeX-comment-prefix p t nil)
    1.70 +		    nil			;if \end{env} found, return nil
    1.71 +		  (cons env m0)))	;else, return meaningful values
    1.72 +	  (store-match-data md)))))))
    1.73 +
    1.74  (defun YaTeX-goto-corresponding-environment (&optional allow-mismatch noerr)
    1.75    "Go to corresponding begin/end enclosure.
    1.76  Optional argument ALLOW-MISMATCH allows mismatch open/clese.  Use this
    1.77 @@ -1299,6 +1357,9 @@
    1.78  	  'buffer-substring-no-properties
    1.79  	'buffer-substring))
    1.80  
    1.81 +(defun YaTeX-region-active-p ()
    1.82 +  (and (fboundp 'region-active-p) (region-active-p)))
    1.83 +
    1.84  ;;;
    1.85  ;; hilit19 vs. font-lock
    1.86  ;;;