yatex

diff yatexmth.el @ 34:c61405ef1bd1

Change the message of dictionary selection menu.
author yuuji
date Wed, 13 Jul 1994 16:11:27 +0000
parents b7b023a74293
children 433b27a11019
line diff
     1.1 --- a/yatexmth.el	Fri Apr 22 17:35:25 1994 +0000
     1.2 +++ b/yatexmth.el	Wed Jul 13 16:11:27 1994 +0000
     1.3 @@ -1,18 +1,18 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5 -;;; YaTeX interface for math-mode.
     1.6 +;;; YaTeX math-mode-specific functions.
     1.7  ;;; yatexmth.el rev.2
     1.8  ;;; (c )1993-1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
     1.9 -;;; Last modified Sat Apr 23 02:26:57 1994 on pajero
    1.10 +;;; Last modified Fri Jul  8 00:48:24 1994 on figaro
    1.11  ;;; $Id$
    1.12  
    1.13  ;;; [Customization guide]
    1.14  ;;;
    1.15  ;;;	  By default,  you can use two  completion  groups in YaTeX math
    1.16 -;;;	mode, `,' for mathematical signs and `/' for greek letters.  But
    1.17 +;;;	mode, `;' for mathematical signs and `/' for greek letters.  But
    1.18  ;;;	you  can add other completion groups   by defining the  alist of
    1.19  ;;;	`prefix  key'    vs   `completion   list'    into  the  variable
    1.20  ;;;	YaTeX-math-key-list-private.  If  you wish  to    accomplish the
    1.21 -;;;	completion as follows(prefix key is `;'):
    1.22 +;;;	completion as follows(prefix key is `,'):
    1.23  ;;;
    1.24  ;;;		KEY		COMPLETION
    1.25  ;;;		s		\sin
    1.26 @@ -24,7 +24,7 @@
    1.27  ;;;		l		\log
    1.28  ;;;		hs		\sinh
    1.29  ;;;
    1.30 -;;;	Typing `s' after `;' makes `\sin', `hs' after `;' makes `\sinh'
    1.31 +;;;	Typing `s' after `,' makes `\sin', `hs' after `,' makes `\sinh'
    1.32  ;;;	and so on.  First, you have to define list of key-completion
    1.33  ;;;	pairs.  Variable name(YaTeX-math-funcs-list) is arbitrary.
    1.34  ;;;
    1.35 @@ -38,21 +38,21 @@
    1.36  ;;;	above) into the variable YaTeX-math-key-list-private.
    1.37  ;;;
    1.38  ;;;		(setq YaTeX-math-key-list-private
    1.39 -;;;		      '((";" . YaTeX-math-funcs-list)
    1.40 +;;;		      '(("," . YaTeX-math-funcs-list)
    1.41  ;;;			("'" . Other-List-if-any)))
    1.42  ;;;
    1.43  ;;;	  Put these expressions into your ~/.emacs, and you can use this
    1.44  ;;;	completion in the YaTeX-math-mode.
    1.45  ;;;
    1.46  ;;;	  And you can add your favorite completion sequences to the
    1.47 -;;;	default completion list invoked with `,', by defining those lists
    1.48 +;;;	default completion list invoked with `;', by defining those lists
    1.49  ;;;	into variable YaTeX-math-sign-alist-private.
    1.50  
    1.51  ;;; 【イメージ補完の追加方法】
    1.52  ;;;
    1.53 -;;;	  標準のイメージ補完では、「,」で始まる数式記号補完と、「/」で始
    1.54 +;;;	  標準のイメージ補完では、「;」で始まる数式記号補完と、「/」で始
    1.55  ;;;	まるギリシャ文字補完が使用可能ですが、これ以外の文字で始まる補完
    1.56 -;;;	シリーズも定義することができます。例えば、「;」で始まる次のよう
    1.57 +;;;	シリーズも定義することができます。例えば、「,」で始まる次のよう
    1.58  ;;;	な補完シリーズを定義する場合を考えてみます。
    1.59  ;;;
    1.60  ;;;		補完キー	補完結果
    1.61 @@ -65,7 +65,7 @@
    1.62  ;;;		l		\log
    1.63  ;;;		hs		\sinh
    1.64  ;;;
    1.65 -;;;	「;」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
    1.66 +;;;	「,」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
    1.67  ;;;	す。このような補完リストの登録は以下のようにします(変数名は任意)。
    1.68  ;;;
    1.69  ;;;		(setq YaTeX-math-funcs-list
    1.70 @@ -74,11 +74,11 @@
    1.71  ;;;				:
    1.72  ;;;			("hs"	"sinh")))
    1.73  ;;;
    1.74 -;;;	さらに、「;」を押した時にイメージ補完が始まるよう次の変数に、起動キー
    1.75 +;;;	さらに、「,」を押した時にイメージ補完が始まるよう次の変数に、起動キー
    1.76  ;;;	と上で定義した補完用変数の登録を行ないます。
    1.77  ;;;
    1.78  ;;;		(setq YaTeX-math-key-list-private
    1.79 -;;;		      '((";" . YaTeX-math-funcs-list)
    1.80 +;;;		      '(("," . YaTeX-math-funcs-list)
    1.81  ;;;			("'" . ほかに定義したいシリーズがあれば…)))
    1.82  ;;;
    1.83  ;;;	これらを ~/.emacs に書いておけば、野鳥の math-mode で自分専用の
    1.84 @@ -106,6 +106,7 @@
    1.85  (YaTeX-setq-math-sym YaTeX-image-bot		"|\n ̄"	"⊥")
    1.86  (YaTeX-setq-math-sym YaTeX-image-neg		"イ"		"¬")
    1.87  (YaTeX-setq-math-sym YaTeX-image-flat		"b"		"♭")
    1.88 +(YaTeX-setq-math-sym YaTeX-image-sqrt		""		"√")
    1.89  
    1.90  (setq
    1.91   YaTeX-math-sign-alist-default
    1.92 @@ -116,6 +117,8 @@
    1.93     ("sigma"	"sum"		("\\-+\n >\n/-+" "Σ"))
    1.94     ("integral"	"int"		(" /\\\n \\\n\\/" YaTeX-image-int))
    1.95     ("ointegral"	"oint"		" /\\\n(\\)\n\\/")
    1.96 +   ("sqrt"	"sqrt"		("  __\n,/" YaTeX-image-sqrt))
    1.97 +   ("root"	"sqrt"		("  __\n,/" YaTeX-image-sqrt))
    1.98     ("A"		"forall"	"|_|\nV")
    1.99     ("E"		"exists"	"-+\n-+\n-+")
   1.100     ("!"		"neg"		("--+\n  |" YaTeX-image-neg))
   1.101 @@ -127,6 +130,7 @@
   1.102     ("-+"	"mp"		"-\n+")
   1.103     ("x"		"times"		("x" "×"))
   1.104     ("/"		"div"		(",\n-\n'" "÷"))
   1.105 +   ("f"		"frac"		"xxx\n---\nyyy" "÷")
   1.106     ("*"		"ast"		"*")
   1.107     ("#"		"star"		("_/\\_\n\\  /\n//\\\\" "★"))
   1.108     ("o"		"circ"		"o")
   1.109 @@ -366,18 +370,6 @@
   1.110    (define-key YaTeX-math-menu-map "\^m"	'exit-recursive-edit)
   1.111    (define-key YaTeX-math-menu-map "q"	'abort-recursive-edit))
   1.112  
   1.113 -(defvar YaTeX-math-key-list-default
   1.114 -  '(("," . YaTeX-math-sign-alist)
   1.115 -    ("/" . YaTeX-greek-key-alist))
   1.116 -  "Default key sequence to invoke math-mode's image completion."
   1.117 -)
   1.118 -(defvar YaTeX-math-key-list-private nil
   1.119 -  "*User defined alist, math-mode-prefix vs completion alist"
   1.120 -)
   1.121 -(defvar YaTeX-math-key-list
   1.122 -  (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
   1.123 -  "Key sequence to invoke math-mode's image completion."
   1.124 -)
   1.125  (defvar YaTeX-math-exit-key "\e"
   1.126    "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode."
   1.127  )
   1.128 @@ -390,43 +382,30 @@
   1.129  ;;;
   1.130  ;;YaTeX math-mode functions
   1.131  ;;;
   1.132 -;##autoload from yatex.el
   1.133 +;;;###autoload from yatex.el
   1.134  (defun YaTeX-toggle-math-mode (&optional arg)
   1.135    (interactive "P")
   1.136 -  (require 'yatexmth)
   1.137    (or (memq 'YaTeX-math-mode mode-line-format) nil
   1.138        (setq mode-line-format
   1.139  	    (append (list "" 'YaTeX-math-mode) mode-line-format)))
   1.140 -  (if (or arg (null YaTeX-math-mode))
   1.141 -      (let ((keys ""))
   1.142 -	(setq YaTeX-math-mode "math:")
   1.143 -	(mapcar
   1.144 -	 (function (lambda (x)
   1.145 -		     (let ((key (car x)) (list (cdr x)))
   1.146 -		       (setq keys (concat keys " " key))
   1.147 -		       (put 'YaTeX-math-key-list list (key-binding key))
   1.148 -		       (define-key YaTeX-mode-map key
   1.149 -			 'YaTeX-math-insert-sequence))))
   1.150 -	 YaTeX-math-key-list)
   1.151 -	(message "Turn on math mode. Prefix keys are %s" keys)
   1.152 -	(sit-for 3)
   1.153 -	(message
   1.154 -	 (concat "To exit from math-mode, type `ESC' after prefix, "
   1.155 -		 "or type `"
   1.156 -		 (key-description
   1.157 -		  (car
   1.158 -		   (where-is-internal 'YaTeX-switch-mode-menu YaTeX-mode-map)))
   1.159 -		 " $'")))
   1.160 -    (setq YaTeX-math-mode nil)
   1.161 -    (mapcar
   1.162 -     (function (lambda (x)
   1.163 -		 (let ((key (car x)) (list (cdr x)))
   1.164 -		   (define-key YaTeX-mode-map key
   1.165 -		     (get 'YaTeX-math-key-list list)))))
   1.166 -     YaTeX-math-key-list)
   1.167 -    (setq YaTeX-math-mode nil)
   1.168 -    (message "Exit from math mode."))
   1.169 -  (set-buffer-modified-p (buffer-modified-p))
   1.170 +  (if YaTeX-auto-math-mode nil		;Only effective on manual mode.
   1.171 +    (if (or arg (null YaTeX-math-mode))
   1.172 +	(let (keys)
   1.173 +	  (setq YaTeX-math-mode "math:")
   1.174 +	  (message "Turn on math mode. Prefix keys are %s"
   1.175 +		   (mapconcat 'car YaTeX-math-key-list " "))
   1.176 +	  (sit-for 3)
   1.177 +	  (message
   1.178 +	   (concat "To exit from math-mode, type `ESC' after prefix, "
   1.179 +		   "or type `"
   1.180 +		   (key-description
   1.181 +		    (car
   1.182 +		     (where-is-internal
   1.183 +		      'YaTeX-switch-mode-menu YaTeX-mode-map)))
   1.184 +		   " $'")))
   1.185 +      (setq YaTeX-math-mode nil)
   1.186 +      (message "Exit from math mode."))
   1.187 +    (set-buffer-modified-p (buffer-modified-p)))
   1.188  )
   1.189  
   1.190  (defun YaTeX-math-forward (arg)
   1.191 @@ -455,6 +434,47 @@
   1.192    (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))
   1.193  )
   1.194  
   1.195 +(defun YaTeX-in-math-mode-p ()
   1.196 +  "If current position is supposed to be in LaTeX-math-mode, return t."
   1.197 +  (or (YaTeX-quick-in-environment-p
   1.198 +       '("math" "eqnarray" "equation" "eqnarray*" "displaymath"))
   1.199 +      (let ((p (point)) (nest 0) me0
   1.200 +	    (boundary
   1.201 +	     (save-excursion
   1.202 +	       (if (looking-at YaTeX-paragraph-delimiter)
   1.203 +		   (goto-char (max (point-min) (1- (point)))))
   1.204 +	       (re-search-backward YaTeX-paragraph-delimiter nil 1)
   1.205 +	       (point))))
   1.206 +	(save-excursion
   1.207 +	  (cond
   1.208 +	   ((catch 'open
   1.209 +	      (save-excursion
   1.210 +		(while (and (>= nest 0)
   1.211 +			    (re-search-backward
   1.212 +			     (concat YaTeX-ec-regexp	;\
   1.213 +				     "\\([()]\\|[][]\\)") boundary t))
   1.214 +		  (setq me0 (match-end 0))
   1.215 +		  (if (or (YaTeX-on-comment-p)
   1.216 +			  (YaTeX-quick-in-environment-p "verbatim")) nil
   1.217 +		    (if (or (= (char-after (1- me0)) ?\))
   1.218 +			    (= (char-after (1- me0)) ?\]))
   1.219 +			(setq nest (1+ nest))
   1.220 +		      (setq nest (1- nest)))))
   1.221 +		(if (< nest 0) (throw 'open t))))
   1.222 +	    t)
   1.223 +	   (t (catch 'dollar
   1.224 +		(while (search-backward "$" boundary t)
   1.225 +		  (cond
   1.226 +		   ((equal (char-after (1- (point))) ?$) ; $$ equation $$
   1.227 +		    (backward-char 1)
   1.228 +		    (setq nest (1+ nest)))
   1.229 +		   ((and (equal (char-after (1- (point))) ?\\ )
   1.230 +			 (not (equal (char-after (- (point) 3)) ?\\ )))
   1.231 +		    nil)		;\$
   1.232 +		   (t (setq nest (1+ nest)))))
   1.233 +		(if (= (% nest 2) 1) (throw 'dollar t))))))))
   1.234 +)
   1.235 +
   1.236  (defun YaTeX-math-display-list (list cols)
   1.237    (goto-char (point-max))
   1.238    (if (= cols 0) (if (not (eolp)) (newline 1))
   1.239 @@ -551,8 +571,9 @@
   1.240  	  (setq buffer-file-name name)
   1.241  	  (set-buffer-modified-p modified)))))
   1.242  
   1.243 -(defun YaTeX-math-insert-sequence ()
   1.244 -  (interactive)
   1.245 +(defun YaTeX-math-insert-sequence (&optional force)
   1.246 +  "Insert math-mode sequence with image completion."
   1.247 +  (interactive "P")
   1.248    (let*((key "") regkey str  last-char list i
   1.249  	(case-fold-search nil) match sign
   1.250  	(this-key (char-to-string last-command-char))
   1.251 @@ -560,8 +581,12 @@
   1.252  	(n (length alist)) (beg (point)) result)
   1.253      (setq result
   1.254  	  (catch 'complete
   1.255 +	    (if (and (not force)
   1.256 +		     (or (and (not YaTeX-auto-math-mode) (not YaTeX-math-mode))
   1.257 +			 (not (YaTeX-in-math-mode-p))))
   1.258 +		(throw 'complete 'escape));this tag should be exit, but...
   1.259  	    (while t
   1.260 -	      (message "Sequence: %s" key)
   1.261 +	      (message "Sequence(TAB for menu): %s" key)
   1.262  	      (setq last-char (read-char)
   1.263  		    key (concat key (char-to-string last-char))
   1.264  		    i 0)
   1.265 @@ -570,20 +595,24 @@
   1.266  		(throw 'complete 'escape))
   1.267  	       ((string= key YaTeX-math-exit-key)	;;exit from math-mode
   1.268  		(throw 'complete 'exit))
   1.269 -	       ((string-match "[\C-g\C-c]" key) (throw 'complete 'abort))
   1.270 -	       ((string-match "[\n\r]" key) (throw 'complete 'menu))
   1.271 -	       ((string-match "[\C-h\C-?]" key)
   1.272 -		(if (string= key "") (throw 'complete 'abort))
   1.273 +	       ((string-match "\r" key)			;;RET = kakutei
   1.274 +		(throw 'complete 'select))
   1.275 +	       ((string-match "[\C-g\C-c]" key)		;;C-g = abort
   1.276 +		(throw 'complete 'abort))
   1.277 +	       ((string-match "[\t\n]" key)		;;TAB, LFD = menu
   1.278 +		(throw 'complete 'menu))
   1.279 +	       ((string-match "[\C-h\C-?]" key)		;;BS, DEL = BS
   1.280 +		(if (< (length key) 2) (throw 'complete 'abort))
   1.281  		(setq key (substring key 0 -2))))
   1.282  	      
   1.283  	      (setq regkey (concat "^" (regexp-quote key)))
   1.284 -	      (message "Sequence: %s" key)
   1.285 +	      (message "Sequence(TAB for menu): %s" key)
   1.286  	      (if
   1.287  		  (catch 'found
   1.288  		    ;;(1)input string strictly matches with alist
   1.289 -		    (setq single-command (car (cdr match))
   1.290 -			  ;;remember previous match
   1.291 -			  match (assoc key alist))
   1.292 +		    (setq match (assoc key alist))
   1.293 +		    ;;remember previous match
   1.294 +
   1.295  		    ;;(2)search partial match into alist
   1.296  		    (setq list alist)
   1.297  		    (while (< i n)
   1.298 @@ -591,8 +620,7 @@
   1.299  			   regkey
   1.300  			   ;;(aref array i)
   1.301  			   ;;(car (nth i alist))
   1.302 -			   (car (car list))
   1.303 -			   )
   1.304 +			   (car (car list)))
   1.305  			  (progn
   1.306  			    (or match
   1.307  				;;(setq match (nth i alist))
   1.308 @@ -602,11 +630,12 @@
   1.309  		  nil ;;if any match, continue reading
   1.310  		;;else reading of sequence has been done.
   1.311  		(message "complete.")
   1.312 -		(throw 'complete t)
   1.313 -		)
   1.314 +		(throw 'complete t))
   1.315 +
   1.316  	      (if match
   1.317  		  (progn (delete-region beg (point))
   1.318 -			 (insert YaTeX-ec (car (cdr match)))
   1.319 +			 (setq single-command (car (cdr match)))
   1.320 +			 (insert YaTeX-ec single-command)
   1.321  			 (if (and YaTeX-math-need-image
   1.322  				  (setq sign (YaTeX-math-get-sign match)))
   1.323  			     (YaTeX-math-show-image (concat sign "\n")))
   1.324 @@ -616,12 +645,7 @@
   1.325      (cond
   1.326       ((eq result t)
   1.327        (setq YaTeX-current-completion-type 'maketitle)
   1.328 -      (if t nil
   1.329 -	(delete-region beg (point))
   1.330 -	(setq single-command (car (cdr match)))
   1.331 -	;;(recursive-edit)
   1.332 -	(insert YaTeX-ec single-command)
   1.333 -	)
   1.334 +
   1.335        ;;;(sit-for 1)
   1.336        (setq unread-command-char last-char)
   1.337        (insert (YaTeX-addin single-command)))
   1.338 @@ -631,6 +655,8 @@
   1.339       ((eq result 'escape)
   1.340        (delete-region beg (point))
   1.341        (insert this-key))
   1.342 +     ((eq result 'select)
   1.343 +      (message "Done."))
   1.344       ((eq result 'exit)
   1.345        (delete-region beg (point))
   1.346        (YaTeX-toggle-math-mode))