yatex

annotate yatexadd.el @ 18:adc2f1472409

Make variables for temporary dictionary buffer-local. Change the default value of YaTeX-nervous to t. Create a temporary dictionary file when `T' is selected at the dictionary selection menu.
author yuuji
date Mon, 16 May 1994 09:30:52 +0000
parents cb9afa9c1213
children b00c74813e56
rev   line source
yuuji@6 1 ;;; -*- Emacs-Lisp -*-
yuuji@8 2 ;;; YaTeX add-in functions.
yuuji@16 3 ;;; yatexadd.el rev.8
yuuji@14 4 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@18 5 ;;; Last modified Sun May 15 18:00:12 1994 on 98fa
yuuji@8 6 ;;; $Id$
yuuji@6 7
yuuji@6 8 (provide 'yatexadd)
yuuji@6 9
yuuji@6 10 ;;;
yuuji@6 11 ;;Sample functions for LaTeX environment.
yuuji@6 12 ;;;
yuuji@6 13 (defvar YaTeX:tabular-default-rule
yuuji@6 14 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
yuuji@6 15 "*Your favorite default rule format."
yuuji@6 16 )
yuuji@6 17 (defun YaTeX:tabular ()
yuuji@18 18 "YaTeX add-in function for tabular environment.
yuuji@18 19 Notice that this function refers the let-variable `env' in
yuuji@18 20 YaTeX-make-begin-end."
yuuji@18 21 (let ((width "") bars (rule "") (j 0) loc)
yuuji@18 22 (if (string= env "tabular*")
yuuji@18 23 (setq width (concat "{" (read-string "Width: ") "}")))
yuuji@18 24 (setq loc (YaTeX:read-position "tb")
yuuji@18 25 bars (string-to-int (read-string "Number of `|': ")))
yuuji@6 26 (if (> bars 0)
yuuji@6 27 (while (< j bars) (setq rule (concat rule "|")) (setq j (1+ j)))
yuuji@6 28 (setq rule YaTeX:tabular-default-rule))
yuuji@6 29 (setq rule (read-string "rule format: " rule))
yuuji@6 30
yuuji@8 31 (message "")
yuuji@18 32 (format "%s%s{%s}" width loc rule))
yuuji@18 33 )
yuuji@18 34 (fset 'YaTeX:tabular* 'YaTeX:tabular)
yuuji@18 35 (defun YaTeX:array ()
yuuji@18 36 (concat (YaTeX:read-position "tb")
yuuji@18 37 "{" (read-string "Column format: ") "}")
yuuji@6 38 )
yuuji@6 39
yuuji@8 40 (defun YaTeX:read-position (oneof)
yuuji@8 41 (let ((pos "") loc)
yuuji@6 42 (while (not (string-match
yuuji@8 43 (setq loc (read-key-sequence
yuuji@8 44 (format "Position (`%s') [%s]: " oneof pos)))
yuuji@6 45 "\r\^g\n"))
yuuji@6 46 (cond
yuuji@8 47 ((string-match loc oneof)
yuuji@6 48 (if (not (string-match loc pos))
yuuji@6 49 (setq pos (concat pos loc))))
yuuji@6 50 ((and (string-match loc "\C-h\C-?") (> (length pos) 0))
yuuji@6 51 (setq pos (substring pos 0 (1- (length pos)))))
yuuji@6 52 (t
yuuji@6 53 (ding)
yuuji@8 54 (message "Please input one of `%s'." oneof)
yuuji@6 55 (sit-for 3))))
yuuji@8 56 (message "")
yuuji@8 57 (if (string= pos "") ""
yuuji@8 58 (concat "[" pos "]")))
yuuji@8 59 )
yuuji@8 60
yuuji@8 61 (defun YaTeX:table ()
yuuji@8 62 "YaTeX add-in function for table environment."
yuuji@8 63 (YaTeX:read-position "htbp")
yuuji@6 64 )
yuuji@6 65
yuuji@6 66 (defun YaTeX:description ()
yuuji@6 67 "Truly poor service:-)"
yuuji@6 68 (setq single-command "item[]")
yuuji@8 69 ""
yuuji@6 70 )
yuuji@6 71
yuuji@6 72 (defun YaTeX:itemize ()
yuuji@6 73 "It's also poor service."
yuuji@6 74 (setq single-command "item")
yuuji@8 75 ""
yuuji@6 76 )
yuuji@6 77
yuuji@6 78 (fset 'YaTeX:enumerate 'YaTeX:itemize)
yuuji@8 79
yuuji@11 80 (defun YaTeX:picture ()
yuuji@11 81 "Ask the size of coordinates of picture environment."
yuuji@11 82 (concat (YaTeX:read-coordinates "Picture size")
yuuji@11 83 (YaTeX:read-coordinates "Initial position"))
yuuji@11 84 )
yuuji@11 85
yuuji@12 86 (defun YaTeX:equation ()
yuuji@12 87 (if (fboundp 'YaTeX-toggle-math-mode)
yuuji@12 88 (YaTeX-toggle-math-mode t)) ;force math-mode ON.
yuuji@12 89 )
yuuji@12 90 (fset 'YaTeX:eqnarray 'YaTeX:equation)
yuuji@12 91 (fset 'YaTeX:displaymath 'YaTeX:equation)
yuuji@12 92
yuuji@16 93 (defun YaTeX:list ()
yuuji@16 94 "%\n{} %default label\n{} %formatting parameter"
yuuji@16 95 )
yuuji@16 96
yuuji@18 97 (defun YaTeX:minipage ()
yuuji@18 98 (concat (YaTeX:read-position "cbt")
yuuji@18 99 "{" (read-string "Width: ") "}")
yuuji@18 100 )
yuuji@18 101
yuuji@8 102 ;;;
yuuji@8 103 ;;Sample functions for section-type command.
yuuji@8 104 ;;;
yuuji@8 105 (defun YaTeX:multiput ()
yuuji@8 106 (concat (YaTeX:read-coordinates "Pos")
yuuji@8 107 (YaTeX:read-coordinates "Step")
yuuji@8 108 "{" (read-string "How many times: ") "}")
yuuji@8 109 )
yuuji@8 110
yuuji@8 111 (defun YaTeX:put ()
yuuji@8 112 (YaTeX:read-coordinates "Pos")
yuuji@8 113 )
yuuji@8 114
yuuji@8 115 (defun YaTeX:makebox ()
yuuji@8 116 (concat (YaTeX:read-coordinates "Dimension")
yuuji@8 117 (YaTeX:read-position "lrtb"))
yuuji@8 118 )
yuuji@8 119
yuuji@8 120 (defun YaTeX:framebox ()
yuuji@8 121 (if (YaTeX-quick-in-environment-p "picture")
yuuji@8 122 (YaTeX:makebox))
yuuji@8 123 )
yuuji@8 124
yuuji@8 125 (defun YaTeX:dashbox ()
yuuji@8 126 (concat "{" (read-string "Dash dimension: ") "}"
yuuji@8 127 (YaTeX:read-coordinates "Dimension"))
yuuji@8 128 )
yuuji@8 129
yuuji@8 130 (defun YaTeX:read-coordinates (&optional mes varX varY)
yuuji@8 131 (concat
yuuji@8 132 "("
yuuji@8 133 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X")))
yuuji@8 134 ","
yuuji@8 135 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y")))
yuuji@8 136 ")")
yuuji@8 137 )
yuuji@8 138
yuuji@8 139 ;;;
yuuji@8 140 ;;Sample functions for maketitle-type command.
yuuji@8 141 ;;;
yuuji@8 142 (defun YaTeX:sum ()
yuuji@8 143 "Read range of summation."
yuuji@8 144 (YaTeX:check-completion-type 'maketitle)
yuuji@8 145 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^"))
yuuji@8 146 )
yuuji@8 147
yuuji@8 148 (fset 'YaTeX:int 'YaTeX:sum)
yuuji@8 149
yuuji@8 150 (defun YaTeX:lim ()
yuuji@8 151 "Insert limit notation of \\lim."
yuuji@8 152 (YaTeX:check-completion-type 'maketitle)
yuuji@8 153 (let ((var (read-string "Variable: ")) limit)
yuuji@8 154 (if (string= "" var) ""
yuuji@8 155 (setq limit (read-string "Limit ($ means infinity): "))
yuuji@8 156 (if (string= "$" limit) (setq limit "\\infty"))
yuuji@8 157 (concat "_{" var " \\rightarrow " limit "}")))
yuuji@8 158 )
yuuji@8 159
yuuji@8 160 (defun YaTeX:gcd ()
yuuji@8 161 "Add-in function for \\gcd(m,n)."
yuuji@8 162 (YaTeX:check-completion-type 'maketitle)
yuuji@8 163 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)")
yuuji@8 164 )
yuuji@8 165
yuuji@8 166 (defun YaTeX:read-boundary (ULchar)
yuuji@8 167 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar."
yuuji@11 168 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): "))))
yuuji@8 169 (if (string= bndry "") ""
yuuji@11 170 (if (string= bndry "$") (setq bndry "\\infty"))
yuuji@8 171 (concat ULchar "{" bndry "}")))
yuuji@8 172 )
yuuji@8 173
yuuji@14 174 (defun YaTeX:verb ()
yuuji@14 175 "Enclose \\verb's contents with the same characters."
yuuji@14 176 (let ((quote-char (read-string "Quoting char: " "|"))
yuuji@14 177 (contents (read-string "Quoted contents: ")))
yuuji@14 178 (concat quote-char contents quote-char))
yuuji@14 179 )
yuuji@14 180
yuuji@14 181 ;;;
yuuji@14 182 ;;Subroutine
yuuji@14 183 ;;;
yuuji@14 184
yuuji@8 185 (defun YaTeX:check-completion-type (type)
yuuji@8 186 "Check valid completion type."
yuuji@8 187 (if (not (eq type YaTeX-current-completion-type))
yuuji@8 188 (error "This should be completed with %s-type completion." type))
yuuji@8 189 )
yuuji@11 190
yuuji@11 191
yuuji@11 192 ;;;
yuuji@11 193 ;;; [[Add-in functions for reading section arguments]]
yuuji@11 194 ;;;
yuuji@11 195 ;; All of add-in functions for reading sections arguments should
yuuji@11 196 ;; take an argument ARGP that specify the argument position.
yuuji@11 197 ;; If argument position is out of range, nil should be returned,
yuuji@11 198 ;; else nil should NOT be returned.
yuuji@13 199
yuuji@13 200 ;;
yuuji@13 201 ; Label selection
yuuji@13 202 ;;
yuuji@11 203 (defvar YaTeX-label-menu-other
yuuji@11 204 (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
yuuji@11 205 (defvar YaTeX-label-menu-any
yuuji@11 206 (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
yuuji@11 207 (defvar YaTeX-label-buffer "*Label completions*")
yuuji@11 208 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.")
yuuji@11 209 (defvar YaTeX-label-select-map nil
yuuji@11 210 "Key map used in label selection buffer.")
yuuji@11 211 (defun YaTeX::label-setup-key-map ()
yuuji@11 212 (if YaTeX-label-select-map nil
yuuji@11 213 (message "Setting up label selection mode map...")
yuuji@11 214 (setq YaTeX-label-select-map (copy-keymap global-map))
yuuji@11 215 (suppress-keymap YaTeX-label-select-map)
yuuji@11 216 (substitute-all-key-definition
yuuji@11 217 'previous-line 'YaTeX::label-previous YaTeX-label-select-map)
yuuji@11 218 (substitute-all-key-definition
yuuji@11 219 'next-line 'YaTeX::label-next YaTeX-label-select-map)
yuuji@11 220 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next)
yuuji@11 221 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous)
yuuji@11 222 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer)
yuuji@11 223 (define-key YaTeX-label-select-map ">" 'end-of-buffer)
yuuji@11 224 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit)
yuuji@11 225 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit)
yuuji@11 226 (define-key YaTeX-label-select-map " " 'exit-recursive-edit)
yuuji@11 227 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit)
yuuji@11 228 (define-key YaTeX-label-select-map "/" 'isearch-forward)
yuuji@11 229 (define-key YaTeX-label-select-map "?" 'isearch-backward)
yuuji@11 230 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag)
yuuji@11 231 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag)
yuuji@11 232 (message "Setting up label selection mode map...Done")
yuuji@11 233 (let ((key ?A))
yuuji@11 234 (while (<= key ?Z)
yuuji@11 235 (define-key YaTeX-label-select-map (char-to-string key)
yuuji@11 236 'YaTeX::label-search-tag)
yuuji@11 237 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A)))
yuuji@11 238 'YaTeX::label-search-tag)
yuuji@11 239 (setq key (1+ key)))))
yuuji@11 240 )
yuuji@11 241 (defun YaTeX::label-next ()
yuuji@11 242 (interactive) (forward-line 1) (message YaTeX-label-guide-msg))
yuuji@11 243 (defun YaTeX::label-previous ()
yuuji@11 244 (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
yuuji@11 245 (defun YaTeX::label-search-tag ()
yuuji@11 246 (interactive)
yuuji@11 247 (let ((case-fold-search t))
yuuji@11 248 (cond
yuuji@11 249 ((save-excursion
yuuji@11 250 (forward-char 1)
yuuji@11 251 (re-search-forward (concat "^" (this-command-keys)) nil t))
yuuji@11 252 (goto-char (match-beginning 0)))
yuuji@11 253 ((save-excursion
yuuji@11 254 (goto-char (point-min))
yuuji@11 255 (re-search-forward (concat "^" (this-command-keys)) nil t))
yuuji@11 256 (goto-char (match-beginning 0))))
yuuji@11 257 (message YaTeX-label-guide-msg))
yuuji@11 258 )
yuuji@11 259 (defun YaTeX::ref (argp)
yuuji@11 260 (cond
yuuji@11 261 ((= argp 1)
yuuji@11 262 (save-excursion
yuuji@11 263 (let ((lnum 0) e0 m1 e1 label label-list (buf (current-buffer))
yuuji@11 264 (p (point)) initl line)
yuuji@11 265 (goto-char (point-min))
yuuji@11 266 (message "Collecting labels...")
yuuji@11 267 (save-window-excursion
yuuji@12 268 (YaTeX-showup-buffer
yuuji@12 269 YaTeX-label-buffer (function (lambda (x) (window-width x))))
yuuji@11 270 (with-output-to-temp-buffer YaTeX-label-buffer
yuuji@11 271 (while (re-search-forward "\\label{\\([^}]+\\)}" nil t)
yuuji@11 272 (setq e0 (match-end 0) m1 (match-beginning 1) e1 (match-end 1))
yuuji@11 273 (if (search-backward
yuuji@11 274 YaTeX-comment-prefix (point-beginning-of-line) t) nil
yuuji@11 275 (setq label (buffer-substring m1 e1)
yuuji@11 276 label-list (cons label label-list))
yuuji@11 277 (or initl
yuuji@11 278 (if (< p (point)) (setq initl lnum)))
yuuji@11 279 (beginning-of-line)
yuuji@11 280 (skip-chars-forward " \t\n" nil)
yuuji@11 281 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label
yuuji@11 282 (buffer-substring (point) (point-end-of-line))))
yuuji@11 283 (setq lnum (1+ lnum))
yuuji@11 284 (message "Collecting \\label{}... %d" lnum))
yuuji@11 285 (goto-char e0))
yuuji@11 286 (princ YaTeX-label-menu-other)
yuuji@11 287 (princ YaTeX-label-menu-any)
yuuji@11 288 );with
yuuji@11 289 (goto-char p)
yuuji@11 290 (message "Collecting labels...Done")
yuuji@11 291 (pop-to-buffer YaTeX-label-buffer)
yuuji@11 292 (YaTeX::label-setup-key-map)
yuuji@11 293 (setq truncate-lines t)
yuuji@11 294 (setq buffer-read-only t)
yuuji@11 295 (use-local-map YaTeX-label-select-map)
yuuji@11 296 (message YaTeX-label-guide-msg)
yuuji@11 297 (goto-line (or initl lnum)) ;goto recently defined label line
yuuji@11 298 (unwind-protect
yuuji@11 299 (progn
yuuji@11 300 (recursive-edit)
yuuji@11 301 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion
yuuji@11 302 (beginning-of-line)
yuuji@11 303 (setq line (count-lines (point-min)(point)))
yuuji@11 304 (cond
yuuji@11 305 ((= line lnum) (setq label (YaTeX-label-other)))
yuuji@11 306 ((>= line (1+ lnum ))
yuuji@11 307 (setq label (read-string "\\ref{???}: ")))
yuuji@11 308 (t (setq label (nth (- lnum line 1) label-list)))))
yuuji@11 309 (bury-buffer YaTeX-label-buffer)))
yuuji@11 310 label
yuuji@11 311 ))
yuuji@11 312 ))
yuuji@11 313 )
yuuji@16 314 (fset 'YaTeX::pageref 'YaTeX::ref)
yuuji@11 315
yuuji@11 316 (defun YaTeX-label-other ()
yuuji@11 317 (let ((lbuf "*YaTeX mode buffers*") (blist (buffer-list)) (lnum -1) buf rv
yuuji@11 318 (ff "**find-file**"))
yuuji@12 319 (YaTeX-showup-buffer
yuuji@12 320 lbuf (function (lambda (x) 1))) ;;Select next window surely.
yuuji@11 321 (with-output-to-temp-buffer lbuf
yuuji@11 322 (while blist
yuuji@11 323 (if (and (buffer-file-name (setq buf (car blist)))
yuuji@11 324 (progn (set-buffer buf) (eq major-mode 'yatex-mode)))
yuuji@11 325 (princ
yuuji@11 326 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A)
yuuji@11 327 (buffer-name buf))))
yuuji@11 328 (setq blist (cdr blist)))
yuuji@11 329 (princ (format "':{%s}" ff)))
yuuji@11 330 (pop-to-buffer lbuf)
yuuji@11 331 (YaTeX::label-setup-key-map)
yuuji@11 332 (setq buffer-read-only t)
yuuji@11 333 (use-local-map YaTeX-label-select-map)
yuuji@11 334 (message YaTeX-label-guide-msg)
yuuji@11 335 (unwind-protect
yuuji@11 336 (progn
yuuji@11 337 (recursive-edit)
yuuji@11 338 (set-buffer lbuf)
yuuji@11 339 (beginning-of-line)
yuuji@11 340 (setq rv
yuuji@11 341 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t)
yuuji@11 342 (buffer-substring (match-beginning 1) (match-end 1)) nil)))
yuuji@11 343 (kill-buffer lbuf))
yuuji@11 344 (cond
yuuji@11 345 ((null rv) "")
yuuji@11 346 ((string= rv ff)
yuuji@11 347 (call-interactively 'find-file)
yuuji@11 348 (YaTeX::ref argp))
yuuji@11 349 (t
yuuji@11 350 (set-buffer rv)
yuuji@11 351 (YaTeX::ref argp)))
yuuji@11 352 )
yuuji@11 353 )
yuuji@11 354
yuuji@13 355 ;;
yuuji@13 356 ; completion for the arguments of \newcommand
yuuji@13 357 ;;
yuuji@13 358 (defun YaTeX::newcommand (&optional argp)
yuuji@13 359 (cond
yuuji@13 360 ((= argp 1)
yuuji@13 361 (let ((command (read-string "Define newcommand: " "\\")))
yuuji@13 362 (put 'YaTeX::newcommand 'command (substring command 1))
yuuji@13 363 command))
yuuji@13 364 ((= argp 2)
yuuji@13 365 (let ((argc
yuuji@13 366 (string-to-int (read-string "Number of arguments(Default 0): ")))
yuuji@13 367 (def (read-string "Definition: "))
yuuji@13 368 (command (get 'YaTeX::newcommand 'command)))
yuuji@13 369 ;;!!! It's illegal to insert string in the add-in function !!!
yuuji@13 370 (if (> argc 0) (insert (format "[%d]" argc)))
yuuji@13 371 (if (and (stringp command)
yuuji@13 372 (string< "" command)
yuuji@13 373 (y-or-n-p "Update user completion table?"))
yuuji@18 374 (cond
yuuji@18 375 ((= argc 0)
yuuji@18 376 (YaTeX-update-table
yuuji@18 377 (list command)
yuuji@18 378 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table))
yuuji@18 379 ((= argc 1)
yuuji@18 380 (YaTeX-update-table
yuuji@18 381 (list command)
yuuji@18 382 'section-table 'user-section-table 'tmp-section-table))
yuuji@18 383 (t (YaTeX-update-table
yuuji@18 384 (list command argc)
yuuji@18 385 'section-table 'user-section-table 'tmp-section-table))))
yuuji@13 386 (message "")
yuuji@13 387 def ;return command name
yuuji@13 388 ))
yuuji@13 389 (t ""))
yuuji@13 390 )
yuuji@13 391
yuuji@16 392 ;;
yuuji@16 393 ; completion for the arguments of \pagestyle
yuuji@16 394 ;;
yuuji@16 395 (defun YaTeX::pagestyle (&optional argp)
yuuji@16 396 "Read the pagestyle with completion."
yuuji@16 397 (completing-read
yuuji@16 398 "Page style: "
yuuji@16 399 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil))
yuuji@16 400 )
yuuji@16 401 ;;
yuuji@16 402 ; completion for the arguments of \pagenumbering
yuuji@16 403 ;;
yuuji@16 404 (defun YaTeX::pagenumbering (&optional argp)
yuuji@16 405 "Read the numbering style."
yuuji@16 406 (completing-read
yuuji@16 407 "Page numbering style: "
yuuji@16 408 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
yuuji@16 409 )
yuuji@13 410
yuuji@11 411 ;;;
yuuji@11 412 ;; global subroutines
yuuji@11 413 ;;;
yuuji@11 414 (defun substitute-all-key-definition (olddef newdef keymap)
yuuji@11 415 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
yuuji@11 416 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
yuuji@11 417 where ever it appears."
yuuji@11 418 (if (arrayp keymap)
yuuji@11 419 (let ((len (length keymap))
yuuji@11 420 (i 0))
yuuji@11 421 (while (< i len)
yuuji@11 422 (let ((map (aref keymap i)))
yuuji@11 423 (cond
yuuji@11 424 ((arrayp map) (substitute-key-definition olddef newdef map))
yuuji@11 425 ((equal map olddef)
yuuji@11 426 (aset keymap i newdef)))
yuuji@11 427 (setq i (1+ i)))))
yuuji@11 428 (while keymap
yuuji@11 429 (if (equal (cdr-safe (car-safe keymap)) olddef)
yuuji@11 430 (setcdr (car keymap) newdef))
yuuji@11 431 (setq keymap (cdr keymap)))))