yatex

diff yatexgen.el @ 45:b0fc9c2950cd

Prepare for supporting Emacs-19.
author yuuji
date Sun, 24 Jul 1994 15:07:23 +0000
parents b7b023a74293
children cd1b63102eed
line diff
     1.1 --- a/yatexgen.el	Fri Apr 22 17:35:25 1994 +0000
     1.2 +++ b/yatexgen.el	Sun Jul 24 15:07:23 1994 +0000
     1.3 @@ -1,8 +1,8 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5 -;;; Generate add-in functions for YaTeX.
     1.6 -;;; yatexgen.el rev.1(beta2)
     1.7 +;;; YaTeX add-in function generator.
     1.8 +;;; yatexgen.el rev.2
     1.9  ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
    1.10 -;;; Last modified Sat Apr 23 02:26:34 1994 on pajero
    1.11 +;;; Last modified Fri Jul  8 00:46:09 1994 on figaro
    1.12  ;;; $Id$
    1.13  
    1.14  (require 'yatex)
    1.15 @@ -403,3 +403,195 @@
    1.16        (define-key map (char-to-string i) 'undefined)
    1.17        (setq i (1+ i))))
    1.18  )
    1.19 +
    1.20 +;;;
    1.21 +;; Auto-generate Function for Lispers.
    1.22 +;;;
    1.23 +(defun YaTeX-generate-read-completion-type (nth)
    1.24 +  (message
    1.25 +"Read type(%d): (S)tring (C)omplete (F)ile ([)option (P)osition co(O)rd. (q)uit" nth)
    1.26 +  (let ((c (read-char)))
    1.27 +    (cond
    1.28 +     ((= c ?s) 'string)
    1.29 +     ((= c ?c) 'completion)
    1.30 +     ((= c ?f) 'file)
    1.31 +     ((= c ?\[) 'option)
    1.32 +     ((= c ?p) 'oneof)
    1.33 +     ((= c ?o) 'coord)
    1.34 +     ;;((= c ?m) 'macro)
    1.35 +     (t        'quit)))
    1.36 + )
    1.37 +(defun YaTeX-generate-read-completion-table ()
    1.38 +  (let ((i 1) cand (cands "(") (cb (current-buffer))
    1.39 +	(buf (get-buffer-create " *Candidates*")))
    1.40 +    (save-window-excursion
    1.41 +      (save-excursion
    1.42 +      (YaTeX-showup-buffer buf nil)
    1.43 +      (set-buffer buf)
    1.44 +      (erase-buffer)
    1.45 +      (while (string<
    1.46 +	      ""
    1.47 +	      (setq cand (read-string (format "Item[%d](RET to exit): " i))))
    1.48 +	(setq cands (concat cands (format "(""%s"")\n" cand))
    1.49 +	      i (1+ i))
    1.50 +	(insert cand "\n"))
    1.51 +      (kill-buffer buf)))
    1.52 +    ;;(set-buffer cb)
    1.53 +    (concat cands ")"))
    1.54 +)
    1.55 +(defun YaTeX-generate-corresponding-paren (left)
    1.56 +  (cond
    1.57 +   ((equal left "{") "}")
    1.58 +   ((equal left "[") "]")
    1.59 +   ((equal left "(") ")")
    1.60 +   ((equal left "<") ">")
    1.61 +   ((equal left "\\begin{" "}"))
    1.62 +   (t left))
    1.63 +)
    1.64 +(defun YaTeX-generate-create-read-string (&optional nth)
    1.65 +  (concat
    1.66 +   "(read-string """
    1.67 +   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
    1.68 +   ": ""\n"
    1.69 +   """" (read-string "Default: ") """"
    1.70 +   ")\n")
    1.71 +)
    1.72 +(defun YaTeX-generate-create-completing-read (&optional nth)
    1.73 +  (concat
    1.74 +   "(completing-read """
    1.75 +   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
    1.76 +   ": ""\n"
    1.77 +   (format "'%s\n" (YaTeX-generate-read-completion-table))
    1.78 +   "nil "
    1.79 +   (format "%s)" (y-or-n-p "Require match? ")))
    1.80 +)
    1.81 +(defun YaTeX-generate-create-read-file-name (&optional nth)
    1.82 +  (concat
    1.83 +   "(read-file-name """
    1.84 +   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
    1.85 +   ": "" nil nil t """")\n")
    1.86 +)
    1.87 +(defun YaTeX-generate-create-read-oneof (&optional nth readpos)
    1.88 +  (concat
    1.89 +   (if readpos
    1.90 +       "(YaTeX:read-position """
    1.91 +     "(YaTeX:read-oneof """)
    1.92 +   (read-string "Acceptable characters: " "lcr") """)\n")
    1.93 +)
    1.94 +(defun YaTeX-generate-option-type (command)
    1.95 +  (let ((func (format "YaTeX:%s" command)) leftp
    1.96 +	(buf (get-buffer-create YaTeX-generate-buffer)) type (n 1))
    1.97 +    (set-buffer buf)
    1.98 +    (erase-buffer)
    1.99 +    (insert "(defun " func " ()\n  (concat\n")
   1.100 +    (catch 'done
   1.101 +      (while t
   1.102 +	(setq type (YaTeX-generate-read-completion-type n))
   1.103 +	(insert 
   1.104 +	 (cond
   1.105 +	  ;;Read string
   1.106 +	  ((eq type 'string)
   1.107 +	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
   1.108 +		   """\n"
   1.109 +		   (YaTeX-generate-create-read-string)
   1.110 +		   """" (YaTeX-generate-corresponding-paren leftp) """"
   1.111 +		   ))
   1.112 +	  
   1.113 +	  ;;Completing-read
   1.114 +	  ((eq type 'completion)
   1.115 +	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
   1.116 +		   """\n"
   1.117 +		   (YaTeX-generate-create-completing-read)
   1.118 +		   """" (YaTeX-generate-corresponding-paren leftp) """")
   1.119 +	   )
   1.120 +	  ((eq type 'file)
   1.121 +	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
   1.122 +		   """\n"
   1.123 +		   (YaTeX-generate-create-read-file-name)
   1.124 +		   """" (YaTeX-generate-corresponding-paren leftp) """")
   1.125 +	   )
   1.126 +	  ((eq type 'oneof)
   1.127 +	   (YaTeX-generate-create-read-oneof nil t)
   1.128 +	   )
   1.129 +	  ((eq type 'option)
   1.130 +	   (concat "(let ((op (read-string """
   1.131 +		   (read-string "Prompt: ")
   1.132 +		   ": "")))\n"
   1.133 +		   "(if (string< """" op)\n"
   1.134 +		   "    (concat ""["" op ""]"")\n"
   1.135 +		   "  """"))\n")
   1.136 +	   )
   1.137 +	  
   1.138 +	  ((eq type 'coord)
   1.139 +	   (concat "(YaTeX:read-coordinates """
   1.140 +		   (read-string "Prompt for coordinates: ")
   1.141 +		   ": """)
   1.142 +	   )
   1.143 +	  ((eq type 'macro)
   1.144 +	   (error "not yet supported")
   1.145 +	   )
   1.146 +	  (t (throw 'done t))))
   1.147 +	(setq n (1+ n))))
   1.148 +    (insert "))\n")			;close defun
   1.149 +    (goto-char (point-min))
   1.150 +    (while (not (eobp)) (lisp-indent-line) (forward-line 1))
   1.151 +    (eval-current-buffer)
   1.152 +    buf)
   1.153 +)
   1.154 +(defun YaTeX-generate-argument-type (command argc)
   1.155 +  "Create an argument-type add-in function."
   1.156 +  (interactive)
   1.157 +  (let ((func (format "YaTeX::%s" command)) (argp 1)
   1.158 +	(cb (current-buffer))
   1.159 +	(buf (get-buffer-create YaTeX-generate-buffer)))
   1.160 +    (set-buffer buf)
   1.161 +    (erase-buffer)
   1.162 +    (insert "(defun " func " (&optional argp)\n(cond\n")
   1.163 +    (while (<= argp argc)
   1.164 +      (insert (format "((equal argp %d)\n" argp))
   1.165 +      (setq type (YaTeX-generate-read-completion-type argp))
   1.166 +      (insert
   1.167 +       (cond
   1.168 +	((eq type 'string)
   1.169 +	 (concat (YaTeX-generate-create-read-string argp)))
   1.170 +	((eq type 'completion)
   1.171 +	 (concat (YaTeX-generate-create-completing-read argp)))
   1.172 +	((eq type 'oneof)
   1.173 +	 (YaTeX-generate-create-read-oneof))
   1.174 +	((eq type 'file)
   1.175 +	 (concat (YaTeX-generate-create-read-file-name argp)))
   1.176 +	(t ""))
   1.177 +       ")\n")
   1.178 +      (setq argp (1+ argp)))
   1.179 +    (insert "))\n")
   1.180 +    (goto-char (point-min))
   1.181 +    (while (not (eobp)) (lisp-indent-line) (forward-line 1))
   1.182 +    (eval-current-buffer)
   1.183 +    (set-buffer cb)
   1.184 +    (YaTeX-update-table
   1.185 +     (if (> argc 1) (list command argc) (list command))
   1.186 +     'section-table 'user-section-table 'tmp-section-table)
   1.187 +    buf)
   1.188 +)
   1.189 +(defun YaTeX-generate-simple (&optional command)
   1.190 +  "Simple but requiring some elisp knowledge add-in generator."
   1.191 +  (interactive)
   1.192 +  (or command
   1.193 +      (setq command
   1.194 +	    (completing-read
   1.195 +	     (format "Making add-in function for (default %s): " section-name)
   1.196 +	     (append
   1.197 +	      section-table user-section-table tmp-section-table
   1.198 +	      article-table user-article-table
   1.199 +	      env-table     user-env-table     tmp-env-table
   1.200 +	      singlecmd-table user-singlecmd-table tmp-singlecmd-table)
   1.201 +	     nil nil)
   1.202 +	    command (if (string= "" command) section-name command)))
   1.203 +  (message "(o)追加型? (a)引数型? (yatexadd.docを参照のこと) :")
   1.204 +  (YaTeX-showup-buffer
   1.205 +   (if (= (read-char) ?o)
   1.206 +       (YaTeX-generate-option-type command)
   1.207 +     (YaTeX-generate-argument-type
   1.208 +      command
   1.209 +      (string-to-int (read-string "How many arguments?: ")))) nil)
   1.210 +)