yatex

annotate yatex.el @ 495:9c857ce72a03

Copy "copying" clause from yatexe.tex
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 11 Sep 2017 14:44:13 +0859
parents 791fd80d22ed
children c0827f80b18e
rev   line source
yuuji@286 1 ;;; yatex.el --- Yet Another tex-mode for emacs //野鳥// -*- coding: sjis -*-
yuuji@443 2 ;;; (c)1991-2017 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@495 3 ;;; Last modified Mon Sep 11 14:43:29 2017 on firestorm
yuuji@366 4 ;;; $Id$
yuuji@69 5 ;;; The latest version of this software is always available at;
yuuji@484 6 ;;; https://www.yatex.org/
yuuji@0 7
yuuji@495 8 ;;; This program is distributed as a free software. You can
yuuji@495 9 ;;; use/copy/modify/redistribute this software freely but with NO
yuuji@495 10 ;;; warranty to anything as a result of using this software. Adopting
yuuji@495 11 ;;; code from this program is also free. But I would not do contract
yuuji@495 12 ;;; act.
yuuji@495 13 ;;;
yuuji@495 14 ;;; This software can be treated with: ``The 2-Clause BSD License''
yuuji@495 15 ;;; (since 2017-09-09, yatex 1.80).
yuuji@495 16
yuuji@286 17 ;;; Code:
yuuji@64 18 (require 'yatexlib)
yuuji@495 19 (defconst YaTeX-revision-number "1.80.1"
yuuji@69 20 "Revision number of running yatex.el")
yuuji@69 21
yuuji@0 22 ;---------- Local variables ----------
yuuji@22 23 (defvar YaTeX-prefix "\C-c"
yuuji@59 24 "*Prefix key to call YaTeX functions.
yuuji@69 25 You can select favorite prefix key by setq in your ~/.emacs.")
yuuji@69 26
yuuji@11 27 (defvar YaTeX-environment-indent 1
yuuji@69 28 "*Indentation depth at column width in LaTeX environments.")
yuuji@69 29
yuuji@64 30 (defvar YaTeX-fill-prefix nil
yuuji@5 31 "*fill-prefix used for auto-fill-mode.
yuuji@69 32 The default value is nil.")
yuuji@69 33
yuuji@5 34 (defvar YaTeX-fill-column 72
yuuji@69 35 "*fill-column used for auto-fill-mode.")
yuuji@69 36
yuuji@4 37 (defvar YaTeX-comment-prefix "%"
yuuji@69 38 "TeX comment prefix.")
yuuji@69 39
yuuji@5 40 (defvar YaTeX-current-position-register ?3
yuuji@22 41 "*Position register to keep where the last completion was done.
yuuji@22 42 All of YaTeX completing input store the current position into
yuuji@5 43 the register YaTeX-current-position-register. So every time you
yuuji@52 44 make a trip to any other part of text other than you are writing, you can
yuuji@13 45 return to the editing paragraph by calling register-to-point with argument
yuuji@69 46 YaTeX-current-position-register.")
yuuji@69 47
yuuji@286 48 (defvar YaTeX-use-LaTeX2e t "*Use LaTeX2e or not. Nil means latex 2.09")
yuuji@72 49
yuuji@72 50 (defvar tex-command
yuuji@72 51 (cond
yuuji@72 52 (YaTeX-use-LaTeX2e "platex")
yuuji@72 53 (YaTeX-japan "jlatex")
yuuji@72 54 (t "latex"))
yuuji@412 55 "*Default command for typesetting LaTeX text.
yuuji@412 56 Overridden with `%#! CommandLine...' in the buffer.")
yuuji@69 57
yuuji@7 58 (defvar bibtex-command (if YaTeX-japan "jbibtex" "bibtex")
yuuji@412 59 "*Default command of BibTeX.
yuuji@412 60 Overridden with `%#BIBTEX CommandLine...' in the buffer.")
yuuji@69 61
yuuji@0 62 (defvar dvi2-command ;previewer command for your site
yuuji@468 63 (cond (YaTeX-dos "dviout -wait=0")
yuuji@468 64 (YaTeX-macos "open -a Preview")
yuuji@468 65 (t "xdvi -geo +0+0 -s 4"))
yuuji@5 66 "*Default previewer command including its option.
yuuji@412 67 Overridden with `%#PREVIEW CommandLine...' in the buffer.")
yuuji@69 68
yuuji@334 69 (defvar YaTeX-cmd-gimp "gimp")
yuuji@334 70 (defvar YaTeX-cmd-tgif "tgif")
yuuji@334 71 (defvar YaTeX-cmd-inkscape "inkscape")
yuuji@334 72 (defvar YaTeX-cmd-dia "dia")
yuuji@334 73 (defvar YaTeX-cmd-ooo "soffice")
yuuji@334 74 (defvar YaTeX-cmd-gs "gs")
yuuji@400 75 (defvar YaTeX-cmd-dvips
yuuji@400 76 (if (YaTeX-executable-find "pdvips") "pdvips" "dvips"))
yuuji@361 77 (defvar YaTeX-cmd-displayline
yuuji@361 78 "/Applications/Skim.app/Contents/SharedSupport/displayline")
yuuji@334 79 (defvar YaTeX-cmd-edit-ps YaTeX-cmd-gimp)
yuuji@334 80 (defvar YaTeX-cmd-edit-pdf YaTeX-cmd-ooo)
yuuji@334 81 (defvar YaTeX-cmd-edit-ai YaTeX-cmd-inkscape)
yuuji@334 82 (defvar YaTeX-cmd-edit-svg YaTeX-cmd-inkscape)
yuuji@334 83 (defvar YaTeX-cmd-edit-images YaTeX-cmd-gimp)
yuuji@362 84 (defvar YaTeX-cmd-view-images "display -geometry +0+0")
yuuji@334 85
yuuji@327 86 (defvar tex-pdfview-command ;previewer command for your site
yuuji@327 87 (cond
yuuji@327 88 (YaTeX-dos "acroread")
yuuji@361 89 (YaTeX-macos (cond
yuuji@361 90 ((file-executable-p YaTeX-cmd-displayline) "open -a Skim")
yuuji@361 91 (t "open")))
yuuji@327 92 (t "evince"))
yuuji@412 93 "*Default PDF viewer command including its option.
yuuji@412 94 Overridden with `%#PDFVIEW CommandLine...' in the buffer.")
yuuji@327 95
yuuji@13 96 (defvar makeindex-command (if YaTeX-dos "makeind" "makeindex")
yuuji@412 97 "*Default makeindex command.
yuuji@412 98 Overridden with `%#MAKEINDEX CommandLine...' in the buffer.")
yuuji@69 99
yuuji@5 100 (defvar dviprint-command-format
yuuji@13 101 (if YaTeX-dos "dviprt %s %f%t"
yuuji@5 102 "dvi2ps %f %t %s | lpr")
yuuji@22 103 "*Command line string to print out current file.
yuuji@412 104 Overridden with `%#LPR CommandLine...' in the buffer.
yuuji@22 105 Format string %s will be replaced by the filename. Do not forget to
yuuji@22 106 specify the `from usage' and `to usage' with their option by format string
yuuji@22 107 %f and %t.
yuuji@69 108 See also documentation of dviprint-from-format and dviprint-to-format.")
yuuji@69 109
yuuji@5 110 (defvar dviprint-from-format
yuuji@13 111 (if YaTeX-dos "%b-" "-f %b")
yuuji@69 112 "*`From' page format of dvi filter. %b will turn to beginning page number.")
yuuji@69 113
yuuji@5 114 (defvar dviprint-to-format
yuuji@13 115 (if YaTeX-dos "%e" "-t %e")
yuuji@69 116 "*`To' page format of dvi filter. %e will turn to end page number.")
yuuji@69 117
yuuji@123 118 (defvar YaTeX-dvipdf-command
yuuji@123 119 "dvipdfmx"
yuuji@412 120 "*Command name to convert dvi file to PDF.
yuuji@412 121 Overridden with `%#DVIPDF CommandLine...' in the buffer.")
yuuji@123 122
yuuji@5 123 (defvar YaTeX-default-document-style
yuuji@347 124 (concat (if YaTeX-japan "js") "article")
yuuji@69 125 "*Default LaTeX Documentstyle for YaTeX-typeset-region.")
yuuji@69 126
yuuji@5 127 (defvar YaTeX-need-nonstop nil
yuuji@69 128 "*T for adding `\\nonstopmode{}' to text before invoking latex command.")
yuuji@69 129
yuuji@0 130 (defvar latex-warning-regexp "line.* [0-9]*"
yuuji@69 131 "*Regular expression of line number of warning message by latex command.")
yuuji@69 132
yuuji@0 133 (defvar latex-error-regexp "l\\.[1-9][0-9]*"
yuuji@22 134 "*Regular expression of line number of latex error.
yuuji@22 135 Perhaps your latex command stops at this error message with line number of
yuuji@69 136 LaTeX source text.")
yuuji@69 137
yuuji@1 138 (defvar latex-dos-emergency-message
yuuji@3 139 "Emergency stop" ;<- for Micro tex, ASCII-pTeX 1.6
yuuji@22 140 "Message pattern of emergency stop of typesetting.
yuuji@22 141 Because Demacs (GNU Emacs on DOS) cannot have concurrent process, the
yuuji@0 142 latex command which is stopping on a LaTeX error, is terminated by Demacs.
yuuji@13 143 Many latex command on DOS display some messages when it is terminated by
yuuji@13 144 other process, user or OS. Define to this variable a message string of your
yuuji@13 145 latex command on DOS shown at abnormal termination.
yuuji@0 146 Remember Demacs's call-process function is not oriented for interactive
yuuji@69 147 process.")
yuuji@69 148
yuuji@64 149 (defvar NTT-jTeX nil
yuuji@64 150 "*T for using NTT-jTeX for latex command.
yuuji@64 151 More precisely, setting t to this variables inhibits inter-word break on
yuuji@64 152 typeset document by line-break of source text. That is, YaTeX automatically
yuuji@64 153 put % after each line at filling.
yuuji@64 154 改行+インデントによって、タイプセット後の字間が空いてしまうのを抑制する場合に
yuuji@64 155 tにする(古いNTT-jTeXで顕著に現れる)。具体的には、fillするときに各行の終わりに
yuuji@69 156 %を付加する。")
yuuji@69 157
yuuji@70 158
yuuji@64 159 (defvar YaTeX-item-regexp
yuuji@64 160 (concat (regexp-quote "\\") "\\(sub\\|bib\\)*item")
yuuji@69 161 "*Regular expression of item command.")
yuuji@69 162
yuuji@7 163 (defvar YaTeX-sectioning-regexp
yuuji@69 164 "\\(part\\|chapter\\*?\\|\\(sub\\)*\\(section\\|paragraph\\)\\)\\(\\*\\|\\b\\)"
yuuji@69 165 "*LaTeX sectioning commands regexp.")
yuuji@69 166
yuuji@58 167 (defvar YaTeX-paragraph-start
yuuji@59 168 (concat "^[ \t]*%\\|^[ \t]*$\\|\\'\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
yuuji@13 169 YaTeX-sectioning-regexp ;sectioning commands
yuuji@7 170 "\\|[A-z]*item\\|begin{\\|end{" ;special declaration
yuuji@70 171 "\\|\\[\\|\\]"
yuuji@59 172 "\\|newpage\\b\\|vspace\\b"
yuuji@7 173 "\\)")
yuuji@58 174 "*Paragraph starting regexp of common LaTeX source. Use this value
yuuji@69 175 for YaTeX-uncomment-paragraph.")
yuuji@69 176
yuuji@58 177 (defvar YaTeX-paragraph-separate
yuuji@58 178 (concat "^[ \t]*%\\|^[ \t]*$\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
yuuji@58 179 YaTeX-sectioning-regexp ;sectioning commands
yuuji@58 180 "\\|begin{\\|end{" ;special declaration
yuuji@68 181 "\\|\\[\\|\\]"
yuuji@59 182 "\\|newpage\\b\\|vspace\\b"
yuuji@58 183 "\\)")
yuuji@7 184 "*Paragraph delimiter regexp of common LaTeX source. Use this value
yuuji@69 185 for YaTeX-uncomment-paragraph.")
yuuji@69 186
yuuji@49 187 (defvar YaTeX-verbatim-environments
yuuji@177 188 '("verbatim" "verbatim*" "alltt")
yuuji@49 189 "*Assume these environments of this variable disable LaTeX commands.")
yuuji@177 190 (defvar YaTeX-verb-regexp "verb\\*?\\|path"
yuuji@51 191 "*Regexp of verb family. Do not contain preceding \\\\ nor \\(\\).")
yuuji@49 192 (defvar YaTeX-fill-inhibit-environments
yuuji@49 193 (append '("tabular" "tabular*" "array" "picture" "eqnarray" "eqnarray*"
yuuji@307 194 "longtable"
yuuji@69 195 "equation" "equation*" "math" "displaymath")
yuuji@49 196 YaTeX-verbatim-environments)
yuuji@13 197 "*In these environments, YaTeX inhibits fill-paragraph from formatting.
yuuji@69 198 Define those environments as a form of list.")
yuuji@69 199
yuuji@52 200 (defvar YaTeX-itemizing-env-regexp
yuuji@64 201 "itemize\\|enumerate\\|description\\|list\\|thebibliography"
yuuji@53 202 "*Regexp of itemizing environments")
yuuji@53 203 (defvar YaTeX-equation-env-regexp
yuuji@54 204 "array\\*?\\|equation\\*?"
yuuji@53 205 "*Regexp of environments for equations")
yuuji@57 206 (defvar YaTeX-array-env-regexp
yuuji@58 207 (concat
yuuji@58 208 "array\\*?\\|eqnarray\\*?\\|tabbing\\|tabular\\*?\\|" ;LaTeX
yuuji@307 209 "longtable\\|" ;LaTeX2e
yuuji@69 210 "matrix\\|pmatrix\\|bmatrix\\|vmatrix\\|Vmatrix\\|" ;AMS-LaTeX
yuuji@58 211 "align\\*?\\|split\\*?\\|aligned\\*?\\|alignat\\*?\\|" ;AMS-LaTeX
yuuji@68 212 "[bpvV]?matrix\\|smallmatrix\\|cases\\|" ;AMS-LaTeX
yuuji@58 213 "xalignat\\*?\\|xxalignat\\*?") ;AMS-LaTeX
yuuji@57 214 "*Regexp of environments where `&' becomes field delimiter.")
yuuji@11 215 (defvar YaTeX-uncomment-once t
yuuji@22 216 "*T for removing all continuous commenting character(%).
yuuji@69 217 Nil for removing only one commenting character at the beginning-of-line.")
yuuji@69 218
yuuji@22 219 (defvar YaTeX-close-paren-always t
yuuji@69 220 "*Close parenthesis always when YaTeX-modify-mode is nil.")
yuuji@69 221
yuuji@22 222 (defvar YaTeX-greek-by-maketitle-completion nil
yuuji@69 223 "*T for greek letters completion by maketitle-type completion.")
yuuji@69 224
yuuji@22 225 (defvar YaTeX-auto-math-mode t
yuuji@22 226 "*T for changing YaTeX-math mode automatically.")
yuuji@316 227 (defvar YaTeX-use-AMS-LaTeX t
yuuji@69 228 "*T for using AMS-LaTeX")
yuuji@69 229
yuuji@22 230 (defvar yatex-mode-hook nil
yuuji@69 231 "*List of functions to be called at the end of yatex-mode initializations.")
yuuji@69 232
yuuji@70 233 (defvar YaTeX-search-file-from-top-directory t
yuuji@72 234 "*Non-nil means to search input-files from the directory where main file exists.")
yuuji@72 235
yuuji@72 236 (defvar YaTeX-use-font-lock (and (featurep 'font-lock)
yuuji@72 237 (fboundp 'x-color-values)
yuuji@72 238 (fboundp 'font-lock-fontify-region))
yuuji@72 239 "*Use font-lock to fontify buffer or not.")
yuuji@72 240
yuuji@72 241 (defvar YaTeX-use-hilit19 (and (featurep 'hilit19) (fboundp 'x-color-values)
yuuji@73 242 (fboundp 'hilit-translate)
yuuji@73 243 (not YaTeX-use-font-lock))
yuuji@72 244 "*Use hilit19 to highlight buffer or not.")
yuuji@70 245
yuuji@82 246 (defvar YaTeX-tabular-indentation 4
yuuji@82 247 "*Indentation column-depth of continueing line in tabular environment.")
yuuji@82 248
yuuji@409 249 (defvar YaTeX-electric-indent-mode -1
yuuji@409 250 "*(for Emacs 24.4+) Pass this value to electric-indent-local-mode.
yuuji@409 251 -1 means `off'.")
yuuji@409 252
yuuji@22 253 ;;-- Math mode values --
yuuji@22 254
yuuji@22 255 (defvar YaTeX-math-key-list-default
yuuji@22 256 '((";" . YaTeX-math-sign-alist)
yuuji@52 257 (":" . YaTeX-greek-key-alist))
yuuji@69 258 "Default key sequence to invoke math-mode's image completion.")
yuuji@69 259
yuuji@22 260 (defvar YaTeX-math-key-list-private nil
yuuji@69 261 "*User defined alist, math-mode-prefix vs completion alist.")
yuuji@69 262
yuuji@22 263 (defvar YaTeX-math-key-list
yuuji@22 264 (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
yuuji@69 265 "Key sequence to invoke math-mode's image completion.")
yuuji@69 266
yuuji@54 267 (defvar YaTeX-skip-default-reader nil
yuuji@69 268 "Non-nil skips default argument reader of section-type completion.")
yuuji@69 269
yuuji@54 270 (defvar YaTeX-simple-messages nil
yuuji@69 271 "Non-nil makes minibuffer messages simpler.")
yuuji@69 272
yuuji@64 273 (defvar YaTeX-template-file "~/work/template.tex"
yuuji@69 274 "*Template TeX source file. This will be inserted to empty file.")
yuuji@69 275
yuuji@57 276 (defvar YaTeX-addin-prefix "YaTeX:")
yuuji@73 277
yuuji@73 278 (defvar yatex-mode-abbrev-table nil
yuuji@73 279 "*Abbrev table in use in yatex-mode buffers.")
yuuji@73 280 (define-abbrev-table 'yatex-mode-abbrev-table ())
yuuji@73 281
yuuji@73 282
yuuji@0 283 ;------------ Completion table ------------
yuuji@0 284 ; Set tex-section-like command possible completion
yuuji@22 285 (defvar section-table
yuuji@70 286 (append
yuuji@70 287 '(("part") ("chapter") ("chapter*") ("section") ("section*")
yuuji@70 288 ("subsection") ("subsection*")
yuuji@70 289 ("subsubsection") ("paragraph") ("subparagraph")
yuuji@72 290 ("author") ("thanks") ("documentstyle") ("pagestyle") ("thispagestyle")
yuuji@70 291 ("title") ("underline") ("label") ("makebox")
yuuji@70 292 ("footnote") ("footnotetext") ("index")
yuuji@70 293 ("hspace*") ("vspace*") ("bibliography") ("bibitem") ("cite")
yuuji@70 294 ("input") ("include") ("includeonly") ("mbox") ("hbox") ("caption")
yuuji@442 295 ("arabic") ("cetering") ("uline")
yuuji@82 296 ("newcounter")
yuuji@70 297 ("newlength") ("setlength" 2) ("addtolength" 2) ("settowidth" 2)
yuuji@70 298 ("setcounter" 2) ("addtocounter" 2) ("stepcounter" 2)
yuuji@70 299 ("newcommand" 2) ("renewcommand" 2)
yuuji@82 300 ("newenvironment" 3) ("newtheorem" 2)
yuuji@70 301 ("cline") ("framebox") ("savebox" 2) ("sbox" 2) ("newsavebox") ("usebox")
yuuji@82 302 ("date") ("put") ("ref") ("pageref") ("tabref") ("figref") ("raisebox" 2)
yuuji@82 303 ("multicolumn" 3) ("shortstack") ("parbox" 2)
yuuji@70 304 ;; for mathmode accent
yuuji@70 305 ("tilde") ("hat") ("check") ("bar") ("dot") ("ddot") ("vec")
yuuji@70 306 ("widetilde") ("widehat") ("overline") ("overrightarrow")
yuuji@70 307 ;; section types in mathmode
yuuji@456 308 ("frac" 2) ("sqrt") ("mathrm") ("mathbf") ("mathit") ("mathbb")
yuuji@456 309 ("mathscr") ("mathrsfs")
yuuji@314 310 ;;cleveref
yuuji@314 311 ("cref") ("crefrange") ("cpageref") ("labelcref") ("labelcpageref")
yuuji@422 312 ;; beamer
yuuji@422 313 ("frametitle") ("framesubtitle")
yuuji@70 314 )
yuuji@70 315 (if YaTeX-use-LaTeX2e
yuuji@70 316 '(("documentclass") ("usepackage")
yuuji@70 317 ("textbf") ("textgt") ("textit") ("textmc") ("textmd") ("textnormal")
yuuji@70 318 ("textrm") ("textsc") ("textsf") ("textsl") ("texttt") ("textup")
yuuji@70 319 ("mathbf") ("mathcal") ("mathit") ("mathnormal") ("mathrm")
yuuji@440 320 ("mathsf") ("mathtt") ("text")
yuuji@82 321 ("textcircled")
yuuji@70 322 ("scalebox" 1) ;is faking of argument position
yuuji@82 323 ("rotatebox" 2) ("resizebox" 3) ("reflectbox")
yuuji@82 324 ("colorbox" 2) ("fcolorbox" 3) ("textcolor" 2) ("color") ("pagecolor")
yuuji@70 325 ("includegraphics") ("includegraphics*")
yuuji@79 326 ("bou") ;defined in plext
yuuji@79 327 ("url") ;defined in url
yuuji@79 328 ("shadowbox") ("doublebox") ("ovalbox") ("Ovalbox")
yuuji@79 329 ("fancyoval") ;defined in fancybox
yuuji@79 330 ("keytop") ("mask" 2) ("maskbox" 5) ;defined in ascmac
yuuji@79 331 ("bm") ;deined in bm
yuuji@79 332 ("verbfile") ("listing") ;defined in misc
yuuji@82 333 ("slashbox" 2) ("backslashbox" 2) ;defined in slashbox
yuuji@82 334 ))
yuuji@82 335 (if YaTeX-use-AMS-LaTeX
yuuji@82 336 '(("DeclareMathOperator" 2) ("boldsymbol") ("pmb") ("eqref")
yuuji@82 337 ("tag") ("tag*"))))
yuuji@69 338 "Default completion table for section-type completion.")
yuuji@69 339
yuuji@0 340 (defvar user-section-table nil)
yuuji@6 341 (defvar tmp-section-table nil)
yuuji@82 342 (defvar YaTeX-ams-math-begin-alist
yuuji@82 343 '(("align") ("align*") ("multline") ("multline*") ("gather") ("gather*")
yuuji@82 344 ("alignat") ("alignat*") ("xalignat") ("xalignat*")
yuuji@82 345 ("xxalignat") ("xxalignat*") ("flalign") ("flalign*") ("equation*")))
yuuji@82 346 (defvar YaTeX-ams-math-gathering-alist
yuuji@82 347 '(("matrix") ("pmatrix") ("bmatrix") ("Bmatrix") ("vmatrix") ("Vmatrix")
yuuji@82 348 ("split") ("split*") ("aligned") ("aligned*") ("alignedat") ("gathered")
yuuji@82 349 ("smallmatrix") ("cases") ("subequations")))
yuuji@82 350 ;; Prepare list(not alist) for YaTeX::ref in yatexadd.el
yuuji@449 351 (defvar YaTeX-math-other-env-alist-default
yuuji@450 352 '(("numcases") ("subnumcases"))
yuuji@449 353 "Default alist of additional environments for equations")
yuuji@449 354 (defvar YaTeX-math-other-env-alist-private nil
yuuji@449 355 "*User defined alist of additional environments for equations")
yuuji@449 356 (defvar YaTeX-math-other-env-alist
yuuji@449 357 (append YaTeX-math-other-env-alist-default
yuuji@449 358 YaTeX-math-other-env-alist-private)
yuuji@449 359 "Alist of additional environments for equations")
yuuji@450 360 (defvar YaTeX-math-other-env-list
yuuji@450 361 (mapcar 'car YaTeX-math-other-env-alist))
yuuji@449 362
yuuji@82 363 (defvar YaTeX-math-begin-list
yuuji@82 364 (mapcar 'car YaTeX-ams-math-begin-alist))
yuuji@82 365 (defvar YaTeX-math-gathering-list ;used in yatexadd.el#yatex::ref
yuuji@82 366 (mapcar 'car YaTeX-ams-math-gathering-alist))
yuuji@82 367
yuuji@82 368 (defvar YaTeX-ams-env-table
yuuji@82 369 (append YaTeX-ams-math-begin-alist YaTeX-ams-math-gathering-alist)
yuuji@82 370 "*Standard AMS-LaTeX(2e) environment completion table.")
yuuji@0 371
yuuji@0 372 ; Set tex-environment possible completion
yuuji@22 373 (defvar env-table
yuuji@79 374 (append
yuuji@434 375 '(("quote") ("quotation") ("center") ("verse") ("document")
yuuji@79 376 ("verbatim") ("itemize") ("enumerate") ("description")
yuuji@79 377 ("list") ("tabular") ("tabular*") ("table") ("tabbing") ("titlepage")
yuuji@79 378 ("sloppypar") ("picture") ("displaymath")
yuuji@240 379 ("eqnarray") ("eqnarray*") ("figure") ("equation") ("equation*")
yuuji@240 380 ("abstract") ("array")
yuuji@79 381 ("thebibliography") ("theindex") ("flushleft") ("flushright")
yuuji@79 382 ("minipage")
yuuji@82 383 ("supertabular")
yuuji@345 384 ("wrapfigure") ("wraptable")
yuuji@424 385 ("frame") ("block") ("example") ("columns") ("column") ;beamer
yuuji@79 386 )
yuuji@79 387 (if YaTeX-use-LaTeX2e
yuuji@79 388 '(("comment") ;defined in version
yuuji@79 389 ("longtable") ;defined in longtable
yuuji@82 390 ("screen") ("boxnote") ("shadebox") ;; ("itembox") ;in ascmac
yuuji@79 391 ("alltt") ;defined in alltt
yuuji@82 392 ("multicols") ;defined in multicol
yuuji@82 393 ("breakbox"))) ;defined in eclbkbox
yuuji@449 394 (if YaTeX-use-AMS-LaTeX YaTeX-ams-env-table)
yuuji@449 395 YaTeX-math-other-env-alist)
yuuji@69 396 "Default completion table for begin-type completion.")
yuuji@69 397
yuuji@0 398 (defvar user-env-table nil)
yuuji@6 399 (defvar tmp-env-table nil)
yuuji@0 400
yuuji@13 401 ; Set {\Large }-like completion
yuuji@22 402 (defvar fontsize-table
yuuji@22 403 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
yuuji@22 404 ("dg") ("dm")
yuuji@22 405 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
yuuji@22 406 ("large") ("Large") ("LARGE") ("huge") ("Huge")
yuuji@70 407 ("rmfamily") ("sffamily") ("ttfamily")
yuuji@70 408 ("mdseries") ("bfseries") ("upshape")
yuuji@70 409 ("itshape") ("slshape") ("scshape")
yuuji@22 410 )
yuuji@69 411 "Default completion table for large-type completion.")
yuuji@69 412
yuuji@70 413 (defvar LaTeX2e-fontstyle-alist
yuuji@70 414 '(("rm" . "rmfamily")
yuuji@70 415 ("sf" . "sffamily")
yuuji@70 416 ("tt" . "ttfamily")
yuuji@70 417 ("md" . "mdseries")
yuuji@70 418 ("bf" . "bfseries")
yuuji@70 419 ("up" . "upshape")
yuuji@70 420 ("it" . "itshape")
yuuji@70 421 ("sl" . "slshape")
yuuji@70 422 ("sc" . "scshape")))
yuuji@70 423
yuuji@0 424 (defvar user-fontsize-table nil)
yuuji@6 425 (defvar tmp-fontsize-table nil)
yuuji@0 426
yuuji@22 427 (defvar singlecmd-table
yuuji@51 428 (append
yuuji@400 429 '(("maketitle") ("makeindex") ("sloppy") ("protect") ("par") ("and")
yuuji@70 430 ("LaTeX") ("TeX") ("item") ("item[]") ("appendix") ("hline") ("kill")
yuuji@54 431 ;;("rightarrow") ("Rightarrow") ("leftarrow") ("Leftarrow")
yuuji@70 432 ("pagebreak") ("nopagebreak") ("tableofcontents")
yuuji@68 433 ("newpage") ("clearpage") ("cleardoublepage")
yuuji@51 434 ("footnotemark") ("verb") ("verb*")
yuuji@59 435 ("linebreak") ("pagebreak") ("noindent") ("indent")
yuuji@495 436 ("raggedright") ("raggedleft") ("centering")
yuuji@70 437 ("left") ("right") ("dots") ("smallskip") ("medskip") ("bigskip")
yuuji@82 438 ("displaystyle")
yuuji@422 439 ("onslide") ("pause") ;beamer
yuuji@51 440 )
yuuji@51 441 (if YaTeX-greek-by-maketitle-completion
yuuji@51 442 '(("alpha") ("beta") ("gamma") ("delta") ("epsilon")
yuuji@51 443 ("varepsilon") ("zeta") ("eta") ("theta")("vartheta")
yuuji@51 444 ("iota") ("kappa") ("lambda") ("mu") ("nu") ("xi") ("pi")
yuuji@51 445 ("varpi") ("rho") ("varrho") ("sigma") ("varsigma") ("tau")
yuuji@51 446 ("upsilon") ("phi") ("varphi") ("chi") ("psi") ("omega")
yuuji@51 447 ("Gamma") ("Delta") ("Theta") ("Lambda")("Xi") ("Pi")
yuuji@79 448 ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")))
yuuji@79 449 (if YaTeX-use-LaTeX2e
yuuji@82 450 '(("return") ("Return") ("yen"))) ;defined in ascmac
yuuji@86 451 (if YaTeX-use-AMS-LaTeX
yuuji@86 452 '(("nonumber")))
yuuji@82 453 )
yuuji@69 454 "Default completion table for maketitle-type completion.")
yuuji@69 455
yuuji@0 456 (defvar user-singlecmd-table nil)
yuuji@6 457 (defvar tmp-singlecmd-table nil)
yuuji@0 458
yuuji@0 459 ;---------- Key mode map ----------
yuuji@0 460 ;;;
yuuji@0 461 ;; Create new key map: YaTeX-mode-map
yuuji@0 462 ;; Do not change this section.
yuuji@0 463 ;;;
yuuji@0 464 (defvar YaTeX-mode-map nil
yuuji@69 465 "Keymap used in YaTeX mode")
yuuji@69 466
yuuji@4 467 (defvar YaTeX-prefix-map nil
yuuji@69 468 "Keymap used when YaTeX-prefix key pushed")
yuuji@69 469
yuuji@54 470 (defvar YaTeX-user-extensional-map (make-sparse-keymap)
yuuji@54 471 "*Keymap used for the user's customization")
yuuji@7 472 (defvar YaTeX-current-completion-type nil
yuuji@69 473 "Has current completion type. This may be used in YaTeX addin functions.")
yuuji@69 474
yuuji@22 475 (defvar YaTeX-modify-mode nil
yuuji@51 476 "*Current editing mode.
yuuji@51 477 When non-nil, each opening parentheses only opens,
yuuji@69 478 nil enters both open/close parentheses when opening parentheses key pressed.")
yuuji@69 479
yuuji@22 480 (defvar YaTeX-math-mode nil
yuuji@69 481 "Holds whether current mode is math-mode.")
yuuji@0 482 ;;;
yuuji@0 483 ;; Define key table
yuuji@0 484 ;;;
yuuji@0 485 (if YaTeX-mode-map
yuuji@0 486 nil
yuuji@0 487 (setq YaTeX-mode-map (make-sparse-keymap))
yuuji@4 488 (setq YaTeX-prefix-map (make-sparse-keymap))
yuuji@4 489 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
yuuji@5 490 (define-key YaTeX-mode-map "{" 'YaTeX-insert-braces)
yuuji@22 491 (define-key YaTeX-mode-map "(" 'YaTeX-insert-parens)
yuuji@7 492 (define-key YaTeX-mode-map "$" 'YaTeX-insert-dollar)
yuuji@69 493 (define-key YaTeX-mode-map "|" 'YaTeX-insert-bar)
yuuji@57 494 (define-key YaTeX-mode-map "&" 'YaTeX-insert-amper)
yuuji@22 495 (define-key YaTeX-mode-map "[" 'YaTeX-insert-brackets)
yuuji@4 496 (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
yuuji@22 497 (define-key YaTeX-mode-map "\M-\C-@" 'YaTeX-mark-environment)
yuuji@22 498 (define-key YaTeX-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
yuuji@22 499 (define-key YaTeX-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
yuuji@22 500 (define-key YaTeX-mode-map "\M-\C-m" 'YaTeX-intelligent-newline)
yuuji@32 501 (define-key YaTeX-mode-map "\C-i" 'YaTeX-indent-line)
yuuji@13 502 (YaTeX-define-key "%" 'YaTeX-%-menu)
yuuji@4 503 (YaTeX-define-key "t" 'YaTeX-typeset-menu)
yuuji@11 504 (YaTeX-define-key "w" 'YaTeX-switch-mode-menu)
yuuji@5 505 (YaTeX-define-key "'" 'YaTeX-prev-error)
yuuji@5 506 (YaTeX-define-key "^" 'YaTeX-visit-main)
yuuji@5 507 (YaTeX-define-key "4^" 'YaTeX-visit-main-other-window)
yuuji@51 508 (YaTeX-define-key "4g" 'YaTeX-goto-corresponding-*-other-window)
yuuji@53 509 (YaTeX-define-key "44" 'YaTeX-switch-to-window)
yuuji@53 510 (and YaTeX-emacs-19 window-system
yuuji@53 511 (progn
yuuji@53 512 (YaTeX-define-key "5^" 'YaTeX-visit-main-other-frame)
yuuji@53 513 (YaTeX-define-key "5g" 'YaTeX-goto-corresponding-*-other-frame)
yuuji@53 514 (YaTeX-define-key "55" 'YaTeX-switch-to-window)))
yuuji@5 515 (YaTeX-define-key " " 'YaTeX-do-completion)
yuuji@4 516 (YaTeX-define-key "v" 'YaTeX-version)
yuuji@0 517
yuuji@5 518 (YaTeX-define-key "}" 'YaTeX-insert-braces-region)
yuuji@5 519 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region)
yuuji@11 520 (YaTeX-define-key ")" 'YaTeX-insert-parens-region)
yuuji@11 521 (YaTeX-define-key "$" 'YaTeX-insert-dollars-region)
yuuji@5 522 (YaTeX-define-key "i" 'YaTeX-fill-item)
yuuji@165 523 (YaTeX-define-key "\\"
yuuji@353 524 (function(lambda () (interactive)
yuuji@353 525 (insert (if (YaTeX-in-math-mode-p) "\\backslash" "\\textbackslash")))))
yuuji@22 526 (if YaTeX-no-begend-shortcut
yuuji@22 527 (progn
yuuji@22 528 (YaTeX-define-key "B" 'YaTeX-make-begin-end-region)
yuuji@22 529 (YaTeX-define-key "b" 'YaTeX-make-begin-end))
yuuji@22 530 (YaTeX-define-begend-key "bc" "center")
yuuji@22 531 (YaTeX-define-begend-key "bd" "document")
yuuji@22 532 (YaTeX-define-begend-key "bD" "description")
yuuji@22 533 (YaTeX-define-begend-key "be" "enumerate")
yuuji@22 534 (YaTeX-define-begend-key "bE" "equation")
yuuji@22 535 (YaTeX-define-begend-key "bi" "itemize")
yuuji@22 536 (YaTeX-define-begend-key "bl" "flushleft")
yuuji@22 537 (YaTeX-define-begend-key "bm" "minipage")
yuuji@22 538 (YaTeX-define-begend-key "bt" "tabbing")
yuuji@22 539 (YaTeX-define-begend-key "bT" "tabular")
yuuji@22 540 (YaTeX-define-begend-key "b\^t" "table")
yuuji@22 541 (YaTeX-define-begend-key "bp" "picture")
yuuji@22 542 (YaTeX-define-begend-key "bq" "quote")
yuuji@22 543 (YaTeX-define-begend-key "bQ" "quotation")
yuuji@22 544 (YaTeX-define-begend-key "br" "flushright")
yuuji@22 545 (YaTeX-define-begend-key "bv" "verbatim")
yuuji@22 546 (YaTeX-define-begend-key "bV" "verse")
yuuji@22 547 (YaTeX-define-key "B " 'YaTeX-make-begin-end-region)
yuuji@22 548 (YaTeX-define-key "b " 'YaTeX-make-begin-end))
yuuji@4 549 (YaTeX-define-key "e" 'YaTeX-end-environment)
yuuji@14 550 (YaTeX-define-key "S" 'YaTeX-make-section-region)
yuuji@4 551 (YaTeX-define-key "s" 'YaTeX-make-section)
yuuji@4 552 (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
yuuji@4 553 (YaTeX-define-key "l" 'YaTeX-make-fontsize)
yuuji@4 554 (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
yuuji@22 555 (YaTeX-define-key "." 'YaTeX-comment-paragraph)
yuuji@22 556 (YaTeX-define-key "," 'YaTeX-uncomment-paragraph)
yuuji@22 557 (YaTeX-define-key ">" 'YaTeX-comment-region)
yuuji@22 558 (YaTeX-define-key "<" 'YaTeX-uncomment-region)
yuuji@5 559 (YaTeX-define-key "g" 'YaTeX-goto-corresponding-*)
yuuji@5 560 (YaTeX-define-key "k" 'YaTeX-kill-*)
yuuji@5 561 (YaTeX-define-key "c" 'YaTeX-change-*)
yuuji@5 562 (YaTeX-define-key "a" 'YaTeX-make-accent)
yuuji@16 563 (YaTeX-define-key "?" 'YaTeX-help)
yuuji@22 564 (YaTeX-define-key "/" 'YaTeX-apropos)
yuuji@22 565 (YaTeX-define-key "&" 'YaTeX-what-column)
yuuji@52 566 (YaTeX-define-key "d" 'YaTeX-display-hierarchy)
yuuji@54 567 (YaTeX-define-key "x" YaTeX-user-extensional-map)
yuuji@5 568 (YaTeX-define-key "n"
yuuji@353 569 (function(lambda () (interactive)
yuuji@353 570 (insert "\\" (if (YaTeX-on-section-command-p "o?oalign") "crcr" "\\")))))
yuuji@13 571 (if YaTeX-dos
yuuji@7 572 (define-key YaTeX-prefix-map "\C-r"
yuuji@353 573 (function(lambda () (interactive)
yuuji@353 574 (YaTeX-set-screen-height YaTeX-saved-screen-height) (recenter))))))
yuuji@0 575
yuuji@49 576 (defvar YaTeX-section-completion-map nil
yuuji@22 577 "*Key map used at YaTeX completion in the minibuffer.")
yuuji@49 578 (if YaTeX-section-completion-map nil
yuuji@49 579 (setq YaTeX-section-completion-map
yuuji@22 580 (copy-keymap (or (and (boundp 'gmhist-completion-map)
yuuji@22 581 gmhist-completion-map)
yuuji@22 582 minibuffer-local-completion-map)))
yuuji@49 583 (define-key YaTeX-section-completion-map
yuuji@22 584 " " 'YaTeX-minibuffer-complete)
yuuji@49 585 (define-key YaTeX-section-completion-map
yuuji@22 586 "\C-i" 'YaTeX-minibuffer-complete)
yuuji@49 587 (define-key YaTeX-section-completion-map
yuuji@22 588 "\C-v" 'YaTeX-read-section-with-overview))
yuuji@22 589
yuuji@14 590 (defvar YaTeX-recursive-map nil
yuuji@22 591 "*Key map used at YaTeX reading arguments in the minibuffer.")
yuuji@14 592 (if YaTeX-recursive-map nil
yuuji@14 593 (setq YaTeX-recursive-map (copy-keymap global-map))
yuuji@82 594 (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map)
yuuji@82 595 (mapcar
yuuji@82 596 (function
yuuji@82 597 (lambda (key)
yuuji@82 598 (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)
yuuji@82 599 (define-key YaTeX-recursive-map (car key) 'YaTeX-math-insert-sequence)))
yuuji@82 600 YaTeX-math-key-list))
yuuji@0 601 ;---------- Define other variable ----------
yuuji@72 602 (defvar YaTeX-env-name "document" "*Initial tex-environment completion")
yuuji@72 603 (defvar YaTeX-section-name
yuuji@72 604 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle")
yuuji@72 605 "*Initial tex-section completion")
yuuji@72 606 (defvar YaTeX-fontsize-name "large" "*Initial fontsize completion")
yuuji@72 607 (defvar YaTeX-single-command "maketitle" "*Initial LaTeX single command")
yuuji@469 608 (defvar YaTeX-kanji-code nil
yuuji@79 609 "*File kanji code used by Japanese TeX.
yuuji@79 610 nil: Do not care (Preserve coding-system)
yuuji@79 611 0: no-converion (mule)
yuuji@79 612 1: Shift JIS
yuuji@79 613 2: JIS
yuuji@86 614 3: EUC
yuuji@86 615 4: UTF-8")
yuuji@69 616
yuuji@22 617 (defvar YaTeX-coding-system nil "File coding system used by Japanese TeX.")
yuuji@5 618 (cond
yuuji@64 619 (YaTeX-emacs-20
yuuji@64 620 (setq YaTeX-coding-system
yuuji@64 621 (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))
yuuji@5 622 ((boundp 'MULE)
yuuji@22 623 (setq YaTeX-coding-system
yuuji@79 624 (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))))
yuuji@64 625
yuuji@64 626 (defvar YaTeX-mode-syntax-table nil
yuuji@64 627 "*Syntax table for yatex-mode")
yuuji@64 628
yuuji@64 629 (if YaTeX-mode-syntax-table nil
yuuji@64 630 (setq YaTeX-mode-syntax-table (make-syntax-table (standard-syntax-table)))
yuuji@64 631 (modify-syntax-entry ?\n " " YaTeX-mode-syntax-table)
yuuji@68 632 (modify-syntax-entry ?\{ "(}" YaTeX-mode-syntax-table)
yuuji@70 633 (modify-syntax-entry ?\} "){" YaTeX-mode-syntax-table)
yuuji@70 634 (modify-syntax-entry ?\t " " YaTeX-mode-syntax-table)
yuuji@70 635 (modify-syntax-entry ?\f ">" YaTeX-mode-syntax-table)
yuuji@70 636 (modify-syntax-entry ?\n ">" YaTeX-mode-syntax-table)
yuuji@70 637 (modify-syntax-entry ?$ "$$" YaTeX-mode-syntax-table)
yuuji@70 638 (modify-syntax-entry ?% "<" YaTeX-mode-syntax-table)
yuuji@70 639 (modify-syntax-entry ?\\ "/" YaTeX-mode-syntax-table)
yuuji@70 640 (modify-syntax-entry ?~ " " YaTeX-mode-syntax-table))
yuuji@52 641
yuuji@414 642 (defvar YaTeX-mode-syntax-table-nonparen nil
yuuji@414 643 "Syntax table for yatex-mode with normal parentheses treated white spaces")
yuuji@414 644 (if YaTeX-mode-syntax-table-nonparen nil
yuuji@414 645 (setq YaTeX-mode-syntax-table-nonparen
yuuji@414 646 (make-syntax-table YaTeX-mode-syntax-table))
yuuji@416 647 (let ((zenparens "()()「」『』【】[]{}《》〈〉〔〕") (i 0) s)
yuuji@414 648 (while (string-match "." zenparens i)
yuuji@414 649 (setq s (substring zenparens (match-beginning 0) (match-end 0))
yuuji@414 650 i (1+ i))
yuuji@414 651 (modify-syntax-entry
yuuji@414 652 (string-to-char s) " " YaTeX-mode-syntax-table-nonparen))))
yuuji@414 653
yuuji@14 654 ;---------- Provide YaTeX-mode ----------
yuuji@0 655 ;;;
yuuji@0 656 ;; Major mode definition
yuuji@0 657 ;;;
yuuji@0 658 (defun yatex-mode ()
yuuji@7 659 " Yet Another LaTeX mode: Major mode for editing input files of LaTeX.
yuuji@13 660 -You can invoke processes concerning LaTeX typesetting by
yuuji@7 661 \\[YaTeX-typeset-menu]
yuuji@22 662 -Complete LaTeX environment form of `\\begin{env} ... \\end{env}' by
yuuji@7 663 \\[YaTeX-make-begin-end]
yuuji@7 664 -Enclose region into some environment by
yuuji@7 665 \\[universal-argument] \\[YaTeX-make-begin-end]
yuuji@7 666 -Complete LaTeX command which takes argument like `\\section{}' by
yuuji@7 667 \\[YaTeX-make-section]
yuuji@7 668 -Put LaTeX command which takes no arguments like `\\maketitle' by
yuuji@7 669 \\[YaTeX-make-singlecmd]
yuuji@7 670 -Complete font or character size descriptor like `{\\large }' by
yuuji@7 671 \\[YaTeX-make-fontsize]
yuuji@22 672 -Enclose region into those descriptors above by
yuuji@7 673 \\[universal-argument] \\[YaTeX-make-fontsize]
yuuji@54 674 -Enter European accent notations by
yuuji@7 675 \\[YaTeX-make-accent]
yuuji@13 676 -Toggle various modes of YaTeX by
yuuji@13 677 \\[YaTeX-switch-mode-menu]
yuuji@22 678 -Change environt name (on the begin/end line) by
yuuji@22 679 \\[YaTeX-change-*]
yuuji@22 680 -Kill LaTeX command/environment sequences by
yuuji@22 681 \\[YaTeX-kill-*]
yuuji@22 682 -Kill LaTeX command/environment with its contents
yuuji@22 683 \\[universal-argument] \\[YaTeX-kill-*]
yuuji@22 684 -Go to corresponding object (begin/end, file, labels) by
yuuji@54 685 \\[YaTeX-goto-corresponding-*] or
yuuji@54 686 \\[YaTeX-goto-corresponding-*-other-window] (in other window)
yuuji@54 687 \\[YaTeX-goto-corresponding-*-other-frame] (in other frame)
yuuji@22 688 -Go to main LaTeX source text by
yuuji@54 689 \\[YaTeX-visit-main] or
yuuji@54 690 \\[YaTeX-visit-main-other-window] (in other window)
yuuji@54 691 \\[YaTeX-visit-main-other-frame] (in other frame)
yuuji@22 692 -Comment out or uncomment region by
yuuji@22 693 \\[YaTeX-comment-region] or \\[YaTeX-uncomment-region]
yuuji@22 694 -Comment out or uncomment paragraph by
yuuji@22 695 \\[YaTeX-comment-paragraph] or \\[YaTeX-uncomment-paragraph]
yuuji@22 696 -Make an \\item entry hang-indented by
yuuji@22 697 \\[YaTeX-fill-item]
yuuji@22 698 -Enclose the region with parentheses by
yuuji@22 699 \\[YaTeX-insert-parens-region]
yuuji@22 700 \\[YaTeX-insert-braces-region]
yuuji@22 701 \\[YaTeX-insert-brackets-region]
yuuji@22 702 \\[YaTeX-insert-dollars-region]
yuuji@22 703 -Look up the corresponding column header of tabular environment by
yuuji@22 704 \\[YaTeX-what-column]
yuuji@54 705 -Enter a newline and an entry suitable for environment by
yuuji@54 706 \\[YaTeX-intelligent-newline]
yuuji@54 707 -View the structure of file inclusion by
yuuji@54 708 \\[YaTeX-display-hierarchy]
yuuji@22 709 -Refer the online help of popular LaTeX commands by
yuuji@54 710 \\[YaTeX-help] (help)
yuuji@54 711 \\[YaTeX-apropos] (apropos)
yuuji@13 712 -Edit `%# notation' by
yuuji@13 713 \\[YaTeX-%-menu]
yuuji@7 714
yuuji@7 715 Those are enough for fastening your editing of LaTeX source. But further
yuuji@22 716 more features are available and they are documented in the manual.
yuuji@22 717 "
yuuji@0 718 (interactive)
yuuji@0 719 (kill-all-local-variables)
yuuji@7 720 (setq major-mode 'yatex-mode)
yuuji@55 721 (setq mode-name (if YaTeX-japan "やてふ" "YaTeX"))
yuuji@18 722 (mapcar 'make-local-variable
yuuji@52 723 '(dvi2-command fill-column fill-prefix
yuuji@18 724 tmp-env-table tmp-section-table tmp-fontsize-table
yuuji@52 725 tmp-singlecmd-table paragraph-start paragraph-separate
yuuji@77 726 YaTeX-math-mode indent-line-function comment-line-break-function
yuuji@58 727 comment-start comment-start-skip
yuuji@22 728 ))
yuuji@354 729 (YaTeX-set-file-coding-system YaTeX-kanji-code YaTeX-coding-system)
yuuji@5 730 (setq fill-column YaTeX-fill-column
yuuji@7 731 fill-prefix YaTeX-fill-prefix
yuuji@58 732 paragraph-start YaTeX-paragraph-start
yuuji@58 733 paragraph-separate YaTeX-paragraph-separate
yuuji@52 734 indent-line-function 'YaTeX-indent-line
yuuji@58 735 comment-start YaTeX-comment-prefix
yuuji@60 736 comment-end ""
yuuji@70 737 comment-start-skip "[^\\\\]%+[ \t]*"
yuuji@73 738 local-abbrev-table yatex-mode-abbrev-table)
yuuji@77 739 (if (fboundp 'comment-indent-new-line) ;for Emacs21
yuuji@77 740 (setq comment-line-break-function 'YaTeX-comment-line-break))
yuuji@330 741 ;; +dnd for X11 w/ emacs23+
yuuji@330 742 (and window-system (featurep 'dnd) (require 'yatex23 nil t)
yuuji@330 743 (set (make-local-variable 'dnd-protocol-alist)
yuuji@330 744 (cons (cons "^file:" 'YaTeX-dnd-handler) dnd-protocol-alist)))
yuuji@77 745
yuuji@72 746 (if (and YaTeX-use-font-lock (featurep 'font-lock))
yuuji@72 747 (progn
yuuji@77 748 (require 'yatex19)
yuuji@72 749 (YaTeX-font-lock-set-default-keywords)
yuuji@72 750 (or (featurep 'xemacs)
yuuji@72 751 (set (make-local-variable 'font-lock-defaults)
yuuji@72 752 (get 'yatex-mode 'font-lock-defaults)))
yuuji@72 753 ;;(font-lock-mode 1)
yuuji@72 754 ))
yuuji@0 755 (use-local-map YaTeX-mode-map)
yuuji@64 756 (set-syntax-table YaTeX-mode-syntax-table)
yuuji@182 757 (if YaTeX-dos (setq YaTeX-saved-screen-height (YaTeX-screen-height)))
yuuji@6 758 (YaTeX-read-user-completion-table)
yuuji@73 759 (and (fboundp 'YaTeX-hilit-setup-alist) (YaTeX-hilit-setup-alist))
yuuji@70 760 (makunbound 'inenv)
yuuji@409 761 ;(turn-on-auto-fill) ;1.63 -> 1.79off
yuuji@409 762 (if (fboundp 'electric-indent-local-mode)
yuuji@409 763 (electric-indent-local-mode YaTeX-electric-indent-mode))
yuuji@64 764 (and (= 0 (buffer-size)) (file-exists-p YaTeX-template-file)
yuuji@64 765 (y-or-n-p (format "Insert %s?" YaTeX-template-file))
yuuji@64 766 (insert-file-contents (expand-file-name YaTeX-template-file)))
yuuji@69 767 (run-hooks 'text-mode-hook 'yatex-mode-hook))
yuuji@5 768
yuuji@0 769 ;---------- Define YaTeX-mode functions ----------
yuuji@13 770 (defvar YaTeX-ec "\\" "Escape character of current mark-up language.")
yuuji@22 771 (defvar YaTeX-ec-regexp (regexp-quote YaTeX-ec))
yuuji@13 772 (defvar YaTeX-struct-begin
yuuji@13 773 (concat YaTeX-ec "begin{%1}%2")
yuuji@64 774 "Keyword format of begin-environment.")
yuuji@64 775 (defvar YaTeX-struct-end
yuuji@64 776 (concat YaTeX-ec "end{%1}")
yuuji@64 777 "Keyword format of end-environment.")
yuuji@217 778 (defvar YaTeX-struct-name-regexp "[^}]*"
yuuji@13 779 "Environment name regexp.")
yuuji@22 780 (defvar YaTeX-TeX-token-regexp
yuuji@82 781 (cond (YaTeX-japan "[A-Za-z*ぁ-ん亜-龠]+")
yuuji@22 782 (t "[A-Za-z*]+"))
yuuji@22 783 "Regexp of characters which can be a member of TeX command's name.")
yuuji@82 784 (defvar YaTeX-kanji-regexp "[ぁ-ん亜-龠]"
yuuji@82 785 "Generic regexp of Japanese Kanji (and symbol) characters.")
yuuji@32 786 (defvar YaTeX-command-token-regexp YaTeX-TeX-token-regexp
yuuji@51 787 "Regexp of characters which can be a member of current mark up language's command name.")
yuuji@49 788
yuuji@13 789 ;;(defvar YaTeX-struct-section
yuuji@13 790 ;; (concat YaTeX-ec "%1{%2}")
yuuji@13 791 ;; "Keyword to make section.")
yuuji@13 792
yuuji@0 793 ;;;
yuuji@22 794 ;; autoload section
yuuji@22 795 ;;;
yuuji@22 796
yuuji@22 797 ;;autoload from yatexprc.el
yuuji@22 798 (autoload 'YaTeX-visit-main "yatexprc" "Visit main LaTeX file." t)
yuuji@22 799 (autoload 'YaTeX-visit-main-other-window "yatexprc"
yuuji@52 800 "Visit main other window." t)
yuuji@53 801 (autoload 'YaTeX-main-file-p "yatexprc" "Check if the file is main." t)
yuuji@51 802 (autoload 'YaTeX-get-builtin "yatexprc" "Get %# built-in." t)
yuuji@59 803 (autoload 'YaTeX-system "yatexprc" "Call system command" t)
yuuji@60 804 (autoload 'YaTeX-save-buffers "yatexprc" "Save buffers of same major mode" t)
yuuji@350 805 (autoload 'YaTeX-goto-corresponding-viewer "yatexprc" "Viewer jump line" t)
yuuji@22 806
yuuji@22 807 ;;autoload from yatexmth.el
yuuji@22 808 (autoload 'YaTeX-math-insert-sequence "yatexmth" "Image input." t)
yuuji@22 809 (autoload 'YaTeX-in-math-mode-p "yatexmth" "Check if in math-env." t)
yuuji@22 810 (autoload 'YaTeX-toggle-math-mode "yatexmth" "YaTeX math-mode interfaces." t)
yuuji@52 811 (autoload 'YaTeX-math-member-p "yatexmth" "Check if a word is math command." t)
yuuji@69 812 (autoload 'YaTeX-insert-amsparens-region "yatexmth" "AMS parens region" t)
yuuji@69 813 (autoload 'YaTeX-insert-amsbraces-region "yatexmth" "AMS braces region" t)
yuuji@69 814 (autoload 'YaTeX-insert-amsbrackets-region "yatexmth" "AMS brackets region" t)
yuuji@69 815 (autoload 'YaTeX-on-parenthesis-p "yatexmth" "Check if on math-parens" t)
yuuji@69 816 (autoload 'YaTeX-goto-open-paren "yatexmth" "Goto opening paren" t)
yuuji@69 817 (autoload 'YaTeX-change-parentheses "yatexmth" "Change corresponding parens" t)
yuuji@77 818 (autoload 'YaTeX-goto-corresponding-paren "yatexmth" "\bigl\bigr jumps" t)
yuuji@130 819 (autoload 'YaTeX-typeset-math-region "yatexmth" "Typeset math-region" t)
yuuji@22 820
yuuji@22 821 ;;autoload from yatexhlp.el
yuuji@22 822 (autoload 'YaTeX-help "yatexhlp" "YaTeX helper with LaTeX commands." t)
yuuji@22 823 (autoload 'YaTeX-apropos "yatexhlp" "Apropos for (La)TeX commands." t)
yuuji@22 824
yuuji@22 825 ;;autoload from yatexgen.el
yuuji@22 826 (autoload 'YaTeX-generate "yatexgen" "YaTeX add-in function generator." t)
yuuji@22 827 (autoload 'YaTeX-generate-simple "yatexgen" "YaTeX add-in support." t)
yuuji@22 828
yuuji@22 829 ;;autoload from yatexsec.el
yuuji@69 830 (autoload 'YaTeX-section-overview "yatexsec" "YaTeX sectioning(view)" t)
yuuji@22 831 (autoload 'YaTeX-read-section-in-minibuffer "yatexsec" "YaTeX sectioning" t)
yuuji@22 832 (autoload 'YaTeX-make-section-with-overview "yatexsec" "YaTeX sectioning" t)
yuuji@22 833
yuuji@22 834 ;;autoload from yatexenv.el
yuuji@22 835 (autoload 'YaTeX-what-column "yatexenv" "YaTeX env. specific funcs" t)
yuuji@22 836 (autoload 'YaTeX-intelligent-newline "yatexenv" "YaTeX env. specific funcs" t)
yuuji@53 837 (autoload 'YaTeX-indent-line-equation "yatexenv" "Indent equation lines." t)
yuuji@53 838 (autoload 'YaTeX-goto-corresponding-leftright "yatexenv" "\left\right jumps" t)
yuuji@22 839
yuuji@52 840 ;;autoload from yatexhie.el
yuuji@52 841 (autoload 'YaTeX-display-hierarchy "yatexhie"
yuuji@52 842 "YaTeX document hierarchy browser" t)
yuuji@61 843 (autoload 'YaTeX-display-hierarchy-directly "yatexhie"
yuuji@61 844 "Same as YaTeX-display-hierarchy. Call from mouse." t)
yuuji@52 845
yuuji@79 846 ;;autoload from yatexpkg.el
yuuji@79 847 (autoload 'YaTeX-package-auto-usepackage "yatexpkg" "Auto \\usepackage" t)
yuuji@60 848
yuuji@22 849 ;;;
yuuji@0 850 ;; YaTeX-mode functions
yuuji@0 851 ;;;
yuuji@22 852 (defun YaTeX-insert-begin-end (env region-mode)
yuuji@45 853 "Insert \\begin{mode-name} and \\end{mode-name}.
yuuji@22 854 This works also for other defined begin/end tokens to define the structure."
yuuji@7 855 (setq YaTeX-current-completion-type 'begin)
yuuji@58 856 (let*((ccol (current-column)) beg beg2 exchange
yuuji@22 857 (arg region-mode) ;for old compatibility
yuuji@58 858 (indent-column (+ ccol YaTeX-environment-indent))(i 1) func)
yuuji@22 859 (if (and region-mode (> (point) (mark)))
yuuji@16 860 (progn (exchange-point-and-mark)
yuuji@16 861 (setq exchange t
yuuji@16 862 ccol (current-column)
yuuji@16 863 indent-column (+ ccol YaTeX-environment-indent))))
yuuji@16 864 ;;VER2 (insert "\\begin{" env "}" (YaTeX-addin env))
yuuji@16 865 (setq beg (point))
yuuji@16 866 (YaTeX-insert-struc 'begin env)
yuuji@58 867 (setq beg2 (point))
yuuji@16 868 (insert "\n")
yuuji@16 869 (indent-to indent-column)
yuuji@16 870 (save-excursion
yuuji@16 871 ;;indent optional argument of \begin{env}, if any
yuuji@16 872 (while (> (point-beginning-of-line) beg)
yuuji@16 873 (skip-chars-forward "\\s " (point-end-of-line))
yuuji@16 874 (indent-to indent-column)
yuuji@16 875 (forward-line -1)))
yuuji@58 876 (require 'yatexenv)
yuuji@22 877 (if region-mode
yuuji@16 878 ;;if region-mode, indent all text in the region
yuuji@7 879 (save-excursion
yuuji@53 880 (if (fboundp (intern-soft (concat "YaTeX-enclose-" env)))
yuuji@53 881 (funcall (intern-soft (concat "YaTeX-enclose-" env))
yuuji@53 882 (point) (mark))
yuuji@53 883 (while (< (progn (forward-line 1) (point)) (mark))
yuuji@53 884 (if (eolp) nil
yuuji@53 885 (skip-chars-forward " \t\n")
yuuji@58 886 (indent-to indent-column))))))
yuuji@22 887 (if region-mode (exchange-point-and-mark))
yuuji@16 888 (indent-to ccol)
yuuji@16 889 ;;VER2 (insert "\\end{" env "}\n")
yuuji@16 890 (YaTeX-insert-struc 'end env)
yuuji@58 891 (YaTeX-reindent ccol)
yuuji@22 892 (if region-mode
yuuji@16 893 (progn
yuuji@54 894 (insert "\n")
yuuji@16 895 (or exchange (exchange-point-and-mark)))
yuuji@58 896 (goto-char beg2)
yuuji@215 897 (YaTeX-intelligent-newline nil)
yuuji@218 898 (if (fboundp (intern-soft (concat "YaTeX-intelligent-newline-" env)))
yuuji@194 899 (progn
yuuji@194 900 (message
yuuji@194 901 (cond
yuuji@194 902 (YaTeX-japan "%s で次の行の入力に進みます。")
yuuji@194 903 (t "`%s' produces the next line's template."))
yuuji@194 904 (key-description
yuuji@194 905 (car (where-is-internal 'YaTeX-intelligent-newline))))))
yuuji@64 906 (YaTeX-indent-line))
yuuji@79 907 (YaTeX-package-auto-usepackage env 'env)
yuuji@5 908 (if YaTeX-current-position-register
yuuji@69 909 (point-to-register YaTeX-current-position-register))))
yuuji@0 910
yuuji@0 911 (defun YaTeX-make-begin-end (arg)
yuuji@0 912 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
yuuji@0 913 by completing read.
yuuji@0 914 If you invoke this command with universal argument,
yuuji@5 915 \(key binding for universal-argument is \\[universal-argument]\)
yuuji@0 916 you can put REGION into that environment between \\begin and \\end."
yuuji@0 917 (interactive "P")
yuuji@0 918 (let*
yuuji@392 919 ((region-p (or arg (YaTeX-region-active-p)))
yuuji@392 920 (mode (if region-p " region" ""))
yuuji@0 921 (env
yuuji@392 922 (save-excursion ;for Emacs24 work-around to avoid point warp
yuuji@392 923 (YaTeX-read-environment
yuuji@392 924 (format "Begin environment%s(default %s): " mode YaTeX-env-name)))))
yuuji@0 925 (if (string= env "")
yuuji@72 926 (setq env YaTeX-env-name))
yuuji@72 927 (setq YaTeX-env-name env)
yuuji@7 928 (YaTeX-update-table
yuuji@72 929 (list YaTeX-env-name) 'env-table 'user-env-table 'tmp-env-table)
yuuji@392 930 (YaTeX-insert-begin-end YaTeX-env-name region-p)))
yuuji@0 931
yuuji@0 932 (defun YaTeX-make-begin-end-region ()
yuuji@0 933 "Call YaTeX-make-begin-end with ARG to specify region mode."
yuuji@0 934 (interactive)
yuuji@69 935 (YaTeX-make-begin-end t))
yuuji@0 936
yuuji@72 937 (defun YaTeX-guess-section-type ()
yuuji@72 938 (if (eq major-mode 'yatex-mode)
yuuji@72 939 (save-excursion
yuuji@72 940 (cond
yuuji@72 941 ((save-excursion (not (search-backward YaTeX-ec nil t)))
yuuji@72 942 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle"))
yuuji@79 943 ((progn
yuuji@79 944 (if (= (char-after (1- (point))) ?~) (forward-char -1))
yuuji@82 945 (forward-char -1) (looking-at "表\\|図\\|式\\|第"))
yuuji@72 946 "ref")
yuuji@72 947 ((and (looking-at "[a-z \t]")
yuuji@72 948 (progn (skip-chars-backward "a-z \t")
yuuji@314 949 (looking-at "table\\|figure\\|formula\\|eq\\(\\.\\|uation\\)")))
yuuji@72 950 "ref")
yuuji@72 951 ((save-excursion
yuuji@72 952 (skip-chars-backward "[^ア-ン]")
yuuji@72 953 (looking-at "プログラム\\|リスト"))
yuuji@72 954 "ref")
yuuji@72 955 ((YaTeX-re-search-active-backward
yuuji@72 956 (concat YaTeX-ec-regexp "begin{\\([^}]+\\)}")
yuuji@72 957 (regexp-quote YaTeX-comment-prefix)
yuuji@72 958 (save-excursion (forward-line -1) (point))
yuuji@72 959 t)
yuuji@72 960 (let ((env (YaTeX-match-string 1)))
yuuji@72 961 (cdr (assoc env
yuuji@72 962 '(("table" . "caption"))))))
yuuji@72 963 ))))
yuuji@72 964
yuuji@46 965 (defun YaTeX-make-section (arg &optional beg end cmd)
yuuji@0 966 "Make LaTeX \\section{} type command with completing read.
yuuji@13 967 With numeric ARG, you can specify the number of arguments of
yuuji@0 968 LaTeX command.
yuuji@0 969 For example, if you want to produce LaTeX command
yuuji@0 970
yuuji@0 971 \\addtolength{\\topmargin}{8mm}
yuuji@0 972
yuuji@5 973 which has two arguments. You can produce that sequence by typing...
yuuji@0 974 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
yuuji@0 975 \(by default\)
yuuji@13 976 Then yatex will automatically complete `addtolength' with two arguments
yuuji@6 977 next time.
yuuji@14 978 You can complete symbol at LaTeX command and the 1st argument.
yuuji@14 979
yuuji@14 980 If the optional 2nd and 3rd argument BEG END are specified, enclose
yuuji@46 981 the region from BEG to END into the first argument of the LaTeX sequence.
yuuji@46 982 Optional 4th arg CMD is LaTeX command name, for non-interactive use."
yuuji@6 983 (interactive "P")
yuuji@7 984 (setq YaTeX-current-completion-type 'section)
yuuji@392 985 (if (or (equal arg '(4)) (YaTeX-region-active-p))
yuuji@392 986 (setq beg (region-beginning) end (region-end)))
yuuji@14 987 (unwind-protect
yuuji@14 988 (let*
yuuji@22 989 ((source-window (selected-window))
yuuji@72 990 guess
yuuji@22 991 (section
yuuji@46 992 (or cmd
yuuji@72 993 (progn
yuuji@72 994 (setq guess
yuuji@72 995 (or (YaTeX-guess-section-type) YaTeX-section-name))
yuuji@72 996 (YaTeX-read-section
yuuji@72 997 (if YaTeX-simple-messages
yuuji@72 998 (format "Section-type (default %s): " guess)
yuuji@72 999 (if (> (minibuffer-depth) 0)
yuuji@72 1000 (format "%s???{} (default %s)%s: "
yuuji@72 1001 YaTeX-ec guess
yuuji@72 1002 (format "[level:%d]" (minibuffer-depth)))
yuuji@72 1003 (format "(C-v for view-section) %s???{%s} (default %s): "
yuuji@72 1004 YaTeX-ec (if beg "region" "") guess)))
yuuji@72 1005 nil))))
yuuji@72 1006 (section (if (string= section "") guess section))
yuuji@14 1007 (numarg ;; The number of section-type command's argument
yuuji@68 1008 (or (and (numberp arg) arg)
yuuji@51 1009 (nth 1 (YaTeX-lookup-table section 'section))
yuuji@14 1010 1))
yuuji@14 1011 (arg-reader (intern-soft (concat "YaTeX::" section)))
yuuji@14 1012 (addin-args (and arg-reader (fboundp arg-reader)))
yuuji@14 1013 (title "")
yuuji@54 1014 (j 1)
yuuji@72 1015 (after-change-functions nil) ;inhibit font-locking temporarily
yuuji@82 1016 (enable-recursive-minibuffers t)
yuuji@82 1017 (mkarg-func
yuuji@82 1018 (function
yuuji@82 1019 (lambda (n)
yuuji@82 1020 (while (<= j n)
yuuji@216 1021 (unwind-protect
yuuji@216 1022 (setq title
yuuji@216 1023 (cond
yuuji@216 1024 (addin-args (funcall arg-reader j))
yuuji@216 1025 (YaTeX-skip-default-reader "")
yuuji@216 1026 (t
yuuji@394 1027 (read-string-with-history
yuuji@216 1028 (format "Argument %d of %s: " j section)))))
yuuji@216 1029 (insert
yuuji@216 1030 (concat ;to allow nil return value
yuuji@216 1031 "{" title "}")))
yuuji@82 1032 (setq j (1+ j))))))
yuuji@82 1033 );;let
yuuji@72 1034 (setq YaTeX-section-name section)
yuuji@14 1035 (if beg
yuuji@79 1036 (let*((e (make-marker))
yuuji@79 1037 (ar2 (intern-soft (concat "YaTeX::" section "-region")))
yuuji@79 1038 (arp (and ar2 (fboundp ar2))))
yuuji@14 1039 (goto-char end)
yuuji@14 1040 (insert "}")
yuuji@14 1041 (set-marker e (point))
yuuji@14 1042 (goto-char beg)
yuuji@216 1043 (unwind-protect
yuuji@216 1044 (progn
yuuji@216 1045 (insert YaTeX-ec YaTeX-section-name
yuuji@216 1046 (YaTeX-addin YaTeX-section-name))
yuuji@216 1047 (if (> numarg 1) (funcall mkarg-func (1- numarg))))
yuuji@216 1048 (insert "{"))
yuuji@79 1049 (if arp (funcall ar2 (point) e))
yuuji@68 1050 (goto-char e)
yuuji@68 1051 (set-marker e nil))
yuuji@14 1052 (use-global-map YaTeX-recursive-map)
yuuji@72 1053 (if (= numarg 0) (YaTeX-make-singlecmd YaTeX-section-name)
yuuji@72 1054 (progn (insert YaTeX-ec YaTeX-section-name)
yuuji@72 1055 (insert (YaTeX-addin YaTeX-section-name))))
yuuji@82 1056 ;;read arguments with add-in
yuuji@82 1057 (funcall mkarg-func numarg))
yuuji@14 1058 (YaTeX-update-table
yuuji@14 1059 (if (/= numarg 1) (list section numarg)
yuuji@14 1060 (list section))
yuuji@14 1061 'section-table 'user-section-table 'tmp-section-table)
yuuji@14 1062 (if YaTeX-current-position-register
yuuji@14 1063 (point-to-register YaTeX-current-position-register))
yuuji@165 1064 (if (string= (YaTeX-buffer-substring (- (point) 2) (point))
yuuji@165 1065 "{}")
yuuji@165 1066 (forward-char -1))
yuuji@165 1067 (while (string= (YaTeX-buffer-substring (- (point) 3) (1- (point)))
yuuji@165 1068 "{}")
yuuji@79 1069 (forward-char -2))
yuuji@79 1070 (YaTeX-package-auto-usepackage section 'section))
yuuji@72 1071 (if (<= (minibuffer-depth) 0) (use-global-map global-map))
yuuji@72 1072 (insert ""))) ;insert dummy string to fontify(Emacs20)
yuuji@0 1073
yuuji@14 1074 (defun YaTeX-make-section-region (args beg end)
yuuji@14 1075 "Call YaTeX-make-section with arguments to specify region mode."
yuuji@14 1076 (interactive "P\nr")
yuuji@69 1077 (YaTeX-make-section args beg end))
yuuji@0 1078
yuuji@54 1079 (defun YaTeX-make-fontsize (arg &optional fontsize)
yuuji@0 1080 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
yuuji@0 1081 If you invoke this command with universal argument, you can put region
yuuji@0 1082 into {\\xxx } braces.
yuuji@5 1083 \(key binding for universal-argument is \\[universal-argument]\)"
yuuji@0 1084 (interactive "P")
yuuji@49 1085 (YaTeX-sync-local-table 'tmp-fontsize-table)
yuuji@392 1086 (let* ((region-p (if (or arg (YaTeX-region-active-p))
yuuji@392 1087 (cons (region-beginning) (region-end))))
yuuji@392 1088 (mode (if region-p "region" ""))
yuuji@0 1089 (fontsize
yuuji@54 1090 (or fontsize
yuuji@54 1091 (YaTeX-read-fontsize
yuuji@54 1092 (if YaTeX-simple-messages
yuuji@72 1093 (format "Font or size (default %s): " YaTeX-fontsize-name)
yuuji@72 1094 (format "{\\??? %s} (default %s)%s: " mode YaTeX-fontsize-name
yuuji@54 1095 (if (> (minibuffer-depth) 0)
yuuji@54 1096 (format "[level:%d]" (minibuffer-depth)) "")))
yuuji@54 1097 nil nil))))
yuuji@0 1098 (if (string= fontsize "")
yuuji@72 1099 (setq fontsize YaTeX-fontsize-name))
yuuji@68 1100 (setq YaTeX-current-completion-type 'large)
yuuji@72 1101 (setq YaTeX-fontsize-name fontsize)
yuuji@6 1102 (YaTeX-update-table
yuuji@72 1103 (list YaTeX-fontsize-name)
yuuji@6 1104 'fontsize-table 'user-fontsize-table 'tmp-fontsize-table)
yuuji@70 1105 (and YaTeX-use-LaTeX2e
yuuji@70 1106 (YaTeX-latex2e-p)
yuuji@72 1107 (setq fontsize
yuuji@72 1108 (cdr (assoc YaTeX-fontsize-name LaTeX2e-fontstyle-alist)))
yuuji@72 1109 (setq YaTeX-fontsize-name fontsize))
yuuji@392 1110 (if region-p
yuuji@392 1111 (let ((b (car region-p))
yuuji@392 1112 (e (set-marker (make-marker) (cdr region-p))))
yuuji@392 1113 (goto-char b)
yuuji@72 1114 (insert "{\\" YaTeX-fontsize-name " ")
yuuji@392 1115 (goto-char e)
yuuji@392 1116 (insert "}")
yuuji@392 1117 (set-marker e nil))
yuuji@72 1118 (insert (concat "{\\" YaTeX-fontsize-name " }"))
yuuji@72 1119 (forward-char -1)
yuuji@5 1120 (if YaTeX-current-position-register
yuuji@5 1121 (point-to-register YaTeX-current-position-register))
yuuji@68 1122 (save-excursion
yuuji@79 1123 (insert (YaTeX-addin YaTeX-fontsize-name)))
yuuji@79 1124 (YaTeX-package-auto-usepackage YaTeX-fontsize-name 'large))))
yuuji@0 1125
yuuji@0 1126 (defun YaTeX-make-fontsize-region ()
yuuji@5 1127 "Call function:YaTeX-make-fontsize with ARG to specify region mode."
yuuji@0 1128 (interactive)
yuuji@69 1129 (YaTeX-make-fontsize t))
yuuji@0 1130
yuuji@52 1131 (defvar YaTeX-singlecmd-suffix "" "*Suffix for maketitle-type commands.")
yuuji@51 1132 (defvar YaTeX-read-singlecmd-history nil "Holds maketitle-type history.")
yuuji@51 1133 (put 'YaTeX-read-singlecmd-history 'no-default t)
yuuji@0 1134 (defun YaTeX-make-singlecmd (single)
yuuji@0 1135 (interactive
yuuji@49 1136 (list (YaTeX-cplread-with-learning
yuuji@54 1137 (if YaTeX-simple-messages
yuuji@72 1138 (format "maketitle-type (default %s): " YaTeX-single-command)
yuuji@72 1139 (format "%s??? (default %s)%s: " YaTeX-ec YaTeX-single-command
yuuji@54 1140 (if (> (minibuffer-depth) 0)
yuuji@54 1141 (format "[level:%d]" (minibuffer-depth)) "")))
yuuji@49 1142 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table
yuuji@51 1143 nil nil nil 'YaTeX-read-singlecmd-history)))
yuuji@0 1144 (if (string= single "")
yuuji@72 1145 (setq single YaTeX-single-command))
yuuji@72 1146 (setq YaTeX-single-command single)
yuuji@7 1147 (setq YaTeX-current-completion-type 'maketitle)
yuuji@54 1148 (let ((dollar (and (not (YaTeX-in-math-mode-p))
yuuji@72 1149 (YaTeX-math-member-p YaTeX-single-command)))
yuuji@54 1150 p q)
yuuji@54 1151 (if dollar (insert "$"))
yuuji@72 1152 (insert YaTeX-ec YaTeX-single-command)
yuuji@52 1153 (setq p (point))
yuuji@52 1154 (insert (YaTeX-addin single) YaTeX-singlecmd-suffix)
yuuji@54 1155 (if dollar (insert "$"))
yuuji@52 1156 (setq q (point))
yuuji@52 1157 (goto-char p)
yuuji@52 1158 (forward-char -2)
yuuji@52 1159 (if (looking-at "\\[\\]") (forward-char 1) (goto-char q)))
yuuji@79 1160 (YaTeX-package-auto-usepackage YaTeX-single-command 'maketitle)
yuuji@5 1161 (if YaTeX-current-position-register
yuuji@69 1162 (point-to-register YaTeX-current-position-register)))
yuuji@0 1163
yuuji@0 1164 (defvar YaTeX-completion-begin-regexp "[{\\]"
yuuji@51 1165 "Regular expression of limit where LaTeX command's completion begins.")
yuuji@0 1166
yuuji@0 1167 (defun YaTeX-do-completion ()
yuuji@0 1168 "Try completion on LaTeX command preceding point."
yuuji@0 1169 (interactive)
yuuji@0 1170 (if
yuuji@0 1171 (or (eq (preceding-char) ? )
yuuji@0 1172 (eq (preceding-char) ?\t)
yuuji@0 1173 (eq (preceding-char) ?\n)
yuuji@0 1174 (bobp))
yuuji@0 1175 (message "Nothing to complete.") ;Do not complete
yuuji@0 1176 (let* ((end (point))
yuuji@6 1177 (limit (point-beginning-of-line))
yuuji@0 1178 (completion-begin
yuuji@6 1179 (progn (re-search-backward "[ \t\n]" limit 1) (point)))
yuuji@0 1180 (begin (progn
yuuji@0 1181 (goto-char end)
yuuji@0 1182 (if (re-search-backward YaTeX-completion-begin-regexp
yuuji@0 1183 completion-begin t)
yuuji@0 1184 (1+ (point))
yuuji@0 1185 nil))))
yuuji@0 1186 (goto-char end)
yuuji@0 1187 (cond
yuuji@0 1188 ((null begin)
yuuji@13 1189 (message "I think it is not a LaTeX sequence."))
yuuji@0 1190 (t
yuuji@49 1191 (mapcar 'YaTeX-sync-local-table
yuuji@18 1192 '(tmp-section-table tmp-env-table tmp-singlecmd-table))
yuuji@165 1193 (let*((pattern (YaTeX-buffer-substring begin end))
yuuji@6 1194 (all-table
yuuji@6 1195 (append
yuuji@6 1196 section-table user-section-table tmp-section-table
yuuji@6 1197 env-table user-env-table tmp-env-table
yuuji@6 1198 singlecmd-table user-singlecmd-table tmp-singlecmd-table))
yuuji@6 1199 ;; First,
yuuji@6 1200 ;; search completion without backslash.
yuuji@6 1201 (completion (try-completion pattern all-table)))
yuuji@0 1202 (if
yuuji@0 1203 (eq completion nil)
yuuji@0 1204 ;; Next,
yuuji@0 1205 ;; search completion with backslash
yuuji@0 1206 (setq completion
yuuji@165 1207 (try-completion
yuuji@165 1208 (YaTeX-buffer-substring (1- begin) end)
yuuji@165 1209 all-table nil)
yuuji@0 1210 begin (1- begin)))
yuuji@0 1211 (cond
yuuji@0 1212 ((null completion)
yuuji@0 1213 (message (concat "Can't find completion for '" pattern "'"))
yuuji@0 1214 (ding))
yuuji@0 1215 ((eq completion t) (message "Sole completion."))
yuuji@0 1216 ((not (string= completion pattern))
yuuji@82 1217 (delete-region begin end)
yuuji@0 1218 (insert completion)
yuuji@0 1219 )
yuuji@0 1220 (t
yuuji@0 1221 (message "Making completion list...")
yuuji@0 1222 (with-output-to-temp-buffer "*Help*"
yuuji@0 1223 (display-completion-list
yuuji@69 1224 (all-completions pattern all-table)))))))))))
yuuji@0 1225
yuuji@12 1226 (defun YaTeX-toggle-modify-mode (&optional arg)
yuuji@12 1227 (interactive "P")
yuuji@12 1228 (or (memq 'YaTeX-modify-mode mode-line-format)
yuuji@12 1229 (setq mode-line-format
yuuji@12 1230 (append (list "" 'YaTeX-modify-mode) mode-line-format)))
yuuji@11 1231 (if (or arg (null YaTeX-modify-mode))
yuuji@11 1232 (progn
yuuji@12 1233 (setq YaTeX-modify-mode "*m*")
yuuji@11 1234 (message "Modify mode"))
yuuji@11 1235 (setq YaTeX-modify-mode nil)
yuuji@11 1236 (message "Cancel modify mode."))
yuuji@69 1237 (set-buffer-modified-p (buffer-modified-p))) ;redraw mode-line
yuuji@11 1238
yuuji@46 1239 (defun YaTeX-switch-mode-menu (arg &optional char)
yuuji@11 1240 (interactive "P")
yuuji@22 1241 (message "Toggle: (M)odify-mode ma(T)h-mode")
yuuji@46 1242 (let ((c (or char (read-char))))
yuuji@11 1243 (cond
yuuji@11 1244 ((= c ?m) (YaTeX-toggle-modify-mode arg))
yuuji@22 1245 ((or (= c ?$) (= c ?t))
yuuji@22 1246 (if YaTeX-auto-math-mode
yuuji@22 1247 (message "Makes no sense in YaTeX-auto-math-mode.")
yuuji@69 1248 (YaTeX-toggle-math-mode arg))))))
yuuji@11 1249
yuuji@0 1250 (defun YaTeX-insert-quote ()
yuuji@0 1251 (interactive)
yuuji@0 1252 (insert
yuuji@0 1253 (cond
yuuji@49 1254 ((YaTeX-literal-p) ?\")
yuuji@0 1255 ((= (preceding-char) ?\\ ) ?\")
yuuji@57 1256 ;((= (preceding-char) ?\( ) ?\")
yuuji@22 1257 ((or (= (preceding-char) 32)
yuuji@22 1258 (= (preceding-char) 9)
yuuji@22 1259 (= (preceding-char) ?\n)
yuuji@22 1260 (bobp)
yuuji@22 1261 (string-match
yuuji@57 1262 (regexp-quote (char-to-string (preceding-char)))
yuuji@57 1263 "、。,.?!「」『』【】()"))
yuuji@22 1264 "``")
yuuji@69 1265 (t "''"))))
yuuji@22 1266
yuuji@22 1267 (defun YaTeX-closable-p ()
yuuji@22 1268 (and (not YaTeX-modify-mode)
yuuji@54 1269 (not (eq YaTeX-close-paren-always 'never))
yuuji@22 1270 (or YaTeX-close-paren-always (eolp))
yuuji@22 1271 (not (input-pending-p))
yuuji@49 1272 (not (YaTeX-literal-p)))
yuuji@22 1273 ;;(or YaTeX-modify-mode
yuuji@22 1274 ;; (and (not YaTeX-close-paren-always) (not (eolp)))
yuuji@22 1275 ;; (input-pending-p)
yuuji@22 1276 ;; (YaTeX-quick-in-environment-p "verbatim"))
yuuji@69 1277 )
yuuji@0 1278
yuuji@5 1279 (defun YaTeX-insert-braces-region (beg end &optional open close)
yuuji@0 1280 (interactive "r")
yuuji@0 1281 (save-excursion
yuuji@0 1282 (goto-char end)
yuuji@184 1283 (YaTeX-insert-inherit (or close "}"))
yuuji@0 1284 (goto-char beg)
yuuji@184 1285 (YaTeX-insert-inherit (or open "{"))))
yuuji@0 1286
yuuji@194 1287 (defun YaTeX-get-macro-at-point (&optional p)
yuuji@194 1288 "Get (La)TeX macro around point P."
yuuji@194 1289 (interactive "d")
yuuji@194 1290 (save-excursion
yuuji@194 1291 (goto-char (setq p (or p (point))))
yuuji@198 1292 (let ((token (substring (substring YaTeX-TeX-token-regexp 1) 0 -2))
yuuji@198 1293 bsend)
yuuji@198 1294 (and (not (bobp))
yuuji@198 1295 (or (looking-at YaTeX-TeX-token-regexp)
yuuji@198 1296 (string-match
yuuji@198 1297 YaTeX-TeX-token-regexp (char-to-string (preceding-char))))
yuuji@198 1298 (progn
yuuji@198 1299 (skip-chars-backward token)
yuuji@198 1300 (equal (preceding-char) ?\\))
yuuji@198 1301 (save-excursion
yuuji@198 1302 (setq bsend (point))
yuuji@198 1303 (skip-chars-backward "\\\\") ;emacs18 doesn't return distance
yuuji@198 1304 (/= (% (- bsend (point)) 2) 0)) ;consider \\
yuuji@198 1305 (looking-at YaTeX-TeX-token-regexp)
yuuji@198 1306 (YaTeX-match-string 0)))))
yuuji@194 1307
yuuji@49 1308 (defun YaTeX-insert-braces (arg &optional open close)
yuuji@49 1309 (interactive "p")
yuuji@194 1310 (let ((begend-guide
yuuji@194 1311 (function
yuuji@194 1312 (lambda ()
yuuji@194 1313 (if (equal (get 'YaTeX-insert-braces 'begend-guide) 2)
yuuji@194 1314 nil ;if triggered thrice, do nothing
yuuji@194 1315 (momentary-string-display
yuuji@194 1316 (format
yuuji@194 1317 (cond
yuuji@196 1318 (YaTeX-japan "begin/end入力には %s を使いましょう")
yuuji@196 1319 (t "You don't understand Zen of `%s'!"))
yuuji@194 1320 (key-description
yuuji@194 1321 (car (where-is-internal 'YaTeX-make-begin-end))))
yuuji@194 1322 (point))
yuuji@194 1323 (put 'YaTeX-insert-braces 'begend-guide
yuuji@451 1324 (+ 1 (YaTeX-str2int ;increment counter of beg-end guidance
yuuji@194 1325 (prin1-to-string
yuuji@194 1326 (get 'YaTeX-insert-braces 'begend-guide)))))))))
yuuji@196 1327 env macro not-literal b e)
yuuji@22 1328 (cond
yuuji@392 1329 ((YaTeX-region-active-p)
yuuji@390 1330 (YaTeX-insert-braces-region (region-beginning) (region-end)))
yuuji@51 1331 ((YaTeX-jmode) (YaTeX-self-insert arg))
yuuji@49 1332 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
yuuji@53 1333 ((save-excursion
yuuji@59 1334 (and (> (- (point) (point-min)) 6)
yuuji@59 1335 (condition-case () (forward-char -6) (error nil)))
yuuji@53 1336 (looking-at "\\\\left\\\\"))
yuuji@53 1337 (insert "{\\right\\}")
yuuji@53 1338 (forward-char -8))
yuuji@193 1339 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
yuuji@69 1340 (and (> (- (point) (point-min)) 6) (forward-char -6))
yuuji@69 1341 (looking-at "\\\\[bB]igl\\\\"))
yuuji@69 1342 (insert
yuuji@69 1343 (concat
yuuji@69 1344 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
yuuji@69 1345 (forward-char -7))
yuuji@69 1346 ((save-excursion
yuuji@69 1347 (and (> (- (point) (point-min)) 7)
yuuji@69 1348 (condition-case () (forward-char -7) (error nil)))
yuuji@69 1349 (looking-at "\\\\[bB]iggl\\\\"))
yuuji@69 1350 (insert
yuuji@69 1351 (concat
yuuji@69 1352 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
yuuji@69 1353 (forward-char -8))
yuuji@69 1354 ((= (preceding-char) ?\\ )
yuuji@69 1355 (insert "{\\}")
yuuji@69 1356 (forward-char -2)) ;matsu's hack ends here
yuuji@194 1357 ((and (setq not-literal (not (YaTeX-literal-p)))
yuuji@194 1358 (equal "end" (setq macro (YaTeX-get-macro-at-point)))
yuuji@22 1359 (setq env (YaTeX-inner-environment)))
yuuji@194 1360 (funcall begend-guide)
yuuji@196 1361 (insert "{" env "}"))
yuuji@194 1362 ((and not-literal (equal "begin" macro))
yuuji@196 1363 (insert "{")
yuuji@196 1364 (save-excursion
yuuji@196 1365 (indent-to (prog1 (- (current-column) 7) (insert "}\n")))
yuuji@196 1366 (insert "\\end{}")
yuuji@196 1367 (setq e (point)))
yuuji@194 1368 (setq env
yuuji@194 1369 (YaTeX-read-environment
yuuji@194 1370 (format "Begin environment(default %s): " YaTeX-env-name)))
yuuji@194 1371 (if (string= "" env) (setq env YaTeX-env-name))
yuuji@194 1372 (setq YaTeX-env-name env)
yuuji@194 1373 (funcall begend-guide)
yuuji@196 1374 (delete-region (- (point) 7) e)
yuuji@194 1375 (YaTeX-insert-begin-end env nil))
yuuji@22 1376 (t
yuuji@47 1377 (insert (or open "{") (or close "}"))
yuuji@60 1378 (forward-char -1)
yuuji@196 1379 (if (and (eq (char-after (point)) ?\}) ;; the case `\\{}'
yuuji@60 1380 (eq (char-after (- (point) 2)) ?\\ ))
yuuji@60 1381 (progn (insert "\\") (forward-char -1)))
yuuji@69 1382 ))))
yuuji@22 1383
yuuji@22 1384 (defun YaTeX-jmode ()
yuuji@22 1385 (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
yuuji@179 1386 (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
yuuji@186 1387 (and (boundp 'skk-mode) skk-mode (not skk-latin-mode))
yuuji@179 1388 (and (boundp 'default-input-method) default-input-method
yuuji@179 1389 current-input-method)))
yuuji@52 1390
yuuji@59 1391 (defun YaTeX-jmode-off ()
yuuji@179 1392 (if (cond
yuuji@179 1393 ((and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
yuuji@179 1394 (canna-toggle-japanese-mode) t)
yuuji@179 1395 ((and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
yuuji@179 1396 (egg:toggle-egg-mode-on-off) t)
yuuji@179 1397 ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode)
yuuji@179 1398 (cond
yuuji@186 1399 ((fboundp 'skk-latin-mode)
yuuji@186 1400 (or (and (boundp 'skk-henkan-mode) skk-henkan-mode)
yuuji@186 1401 (and (boundp 'skk-henkan-on)
yuuji@186 1402 (or skk-henkan-mode skk-henkan-active))
yuuji@186 1403 (and (boundp 'j-henkan-on)
yuuji@186 1404 (or j-henkan-on j-henkan-active))
yuuji@186 1405 ;; Deactivate jmode if henkan-mode is not running.
yuuji@186 1406 ;; Suggested by tt.tetsuo.tsukamoto.
yuuji@186 1407 (progn
yuuji@186 1408 (put 'YaTeX-jmode-on 'skkkata skk-katakana)
yuuji@186 1409 (skk-latin-mode t))))
yuuji@179 1410 ((fboundp 'skk-mode-off) (skk-mode-off))
yuuji@179 1411 (t (j-mode-off)))
yuuji@179 1412 t)
yuuji@179 1413 ((and (fboundp 'toggle-input-method) current-input-method)
yuuji@179 1414 (toggle-input-method) t)
yuuji@179 1415 ((and (fboundp 'fep-force-off) (fep-force-off))))
yuuji@179 1416 (put 'YaTeX-jmode 'jmode t)))
yuuji@179 1417
yuuji@179 1418 (defun YaTeX-jmode-on ()
yuuji@59 1419 (cond
yuuji@179 1420 ((boundp 'canna:*japanese-mode*)
yuuji@179 1421 (if (not canna:*japanese-mode*) (canna-toggle-japanese-mode)))
yuuji@179 1422 ((boundp 'egg:*mode-on*)
yuuji@179 1423 (and (not egg:*mode-on*) (not egg:*input-mode*)
yuuji@179 1424 (egg:toggle-egg-mode-on-off)))
yuuji@179 1425 ((and (fboundp 'skk-mode) (boundp 'skk-mode))
yuuji@186 1426 (if (get 'YaTeX-jmode-on 'skkkata)
yuuji@186 1427 (skk-j-mode-on t)
yuuji@186 1428 (skk-mode 1))
yuuji@186 1429 (put 'YaTeX-jmode-on 'skkkata nil))
yuuji@179 1430 ((fboundp 'toggle-input-method)
yuuji@179 1431 (if (not current-input-method) (toggle-input-method)))
yuuji@179 1432 ((and (fboundp 'fep-force-on) (fep-force-on)))))
yuuji@179 1433
yuuji@179 1434 (defun YaTeX-jmode-back ()
yuuji@179 1435 (if (get 'YaTeX-jmode 'jmode)
yuuji@179 1436 (YaTeX-jmode-on))
yuuji@179 1437 (setplist 'YaTeX-jmode nil))
yuuji@59 1438
yuuji@22 1439 (defun YaTeX-self-insert (arg)
yuuji@290 1440 (call-interactively (global-key-binding (char-to-string (YaTeX-last-key)))))
yuuji@184 1441 (defun YaTeX-insert-inherit (&rest args)
yuuji@184 1442 (apply (if (fboundp 'insert-and-inherit) 'insert-and-inherit 'insert)
yuuji@184 1443 args))
yuuji@52 1444
yuuji@22 1445 (defun YaTeX-insert-brackets (arg)
yuuji@22 1446 "Insert Kagi-kakko or \\ [ \\] pair or simply \[."
yuuji@22 1447 (interactive "p")
yuuji@22 1448 (let ((col (1- (current-column))))
yuuji@22 1449 (cond
yuuji@392 1450 ((YaTeX-region-active-p)
yuuji@392 1451 (YaTeX-insert-brackets-region (region-beginning) (region-end)))
yuuji@22 1452 ((YaTeX-jmode) (YaTeX-self-insert arg))
yuuji@22 1453 ((not (YaTeX-closable-p))
yuuji@22 1454 (YaTeX-self-insert arg))
yuuji@53 1455 ((save-excursion
yuuji@53 1456 (and (> (- (point) (point-min)) 5) (forward-char -5))
yuuji@53 1457 (looking-at "\\\\left"))
yuuji@184 1458 (YaTeX-insert-inherit "[\\right]")
yuuji@53 1459 (forward-char -7))
yuuji@193 1460 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
yuuji@69 1461 (and (> (- (point) (point-min)) 5) (forward-char -5))
yuuji@69 1462 (looking-at "\\\\[bB]igl"))
yuuji@184 1463 (YaTeX-insert-inherit
yuuji@69 1464 (concat
yuuji@69 1465 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
yuuji@69 1466 (forward-char -6))
yuuji@69 1467 ((save-excursion
yuuji@69 1468 (and (> (- (point) (point-min)) 6) (forward-char -6))
yuuji@69 1469 (looking-at "\\\\[bB]iggl"))
yuuji@184 1470 (YaTeX-insert-inherit
yuuji@69 1471 (concat
yuuji@69 1472 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
yuuji@69 1473 (forward-char -7)) ;matsu's hack ends here
yuuji@36 1474 ((and (= (preceding-char) ?\\ )
yuuji@36 1475 (/= (char-after (- (point) 2)) ?\\ )
yuuji@36 1476 (not (YaTeX-in-math-mode-p)))
yuuji@290 1477 (YaTeX-insert-inherit (YaTeX-last-key) "\n")
yuuji@22 1478 (indent-to (max 0 col))
yuuji@184 1479 (YaTeX-insert-inherit "\\]")
yuuji@22 1480 (beginning-of-line)
yuuji@22 1481 (open-line 1)
yuuji@53 1482 (delete-region (point) (progn (beginning-of-line) (point)))
yuuji@22 1483 (indent-to (+ YaTeX-environment-indent (max 0 col)))
yuuji@53 1484 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1)))
yuuji@22 1485 ((YaTeX-closable-p)
yuuji@184 1486 (YaTeX-insert-inherit "[]")
yuuji@22 1487 (backward-char 1))
yuuji@69 1488 (t (YaTeX-self-insert arg)))))
yuuji@0 1489
yuuji@5 1490 (defun YaTeX-insert-brackets-region (beg end)
yuuji@5 1491 (interactive "r")
yuuji@69 1492 (YaTeX-insert-braces-region beg end "[" "]"))
yuuji@5 1493
yuuji@22 1494 (defun YaTeX-insert-parens (arg)
yuuji@22 1495 "Insert parenthesis pair."
yuuji@22 1496 (interactive "p")
yuuji@22 1497 (cond
yuuji@392 1498 ((YaTeX-region-active-p)
yuuji@392 1499 (YaTeX-insert-parens-region (region-beginning) (region-end)))
yuuji@22 1500 ((YaTeX-jmode) (YaTeX-self-insert arg))
yuuji@22 1501 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
yuuji@53 1502 ((save-excursion
yuuji@53 1503 (and (> (- (point) (point-min)) 5) (forward-char -5))
yuuji@53 1504 (looking-at "\\\\left"))
yuuji@184 1505 (YaTeX-insert-inherit "(\\right)")
yuuji@53 1506 (forward-char -7))
yuuji@193 1507 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
yuuji@69 1508 (and (> (- (point) (point-min)) 5) (forward-char -5))
yuuji@69 1509 (looking-at "\\\\[bB]igl"))
yuuji@184 1510 (YaTeX-insert-inherit
yuuji@69 1511 (concat
yuuji@69 1512 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
yuuji@69 1513 (forward-char -6))
yuuji@69 1514 ((save-excursion
yuuji@69 1515 (and (> (- (point) (point-min)) 6) (forward-char -6))
yuuji@69 1516 (looking-at "\\\\[bB]iggl"))
yuuji@184 1517 (YaTeX-insert-inherit
yuuji@69 1518 (concat
yuuji@69 1519 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
yuuji@69 1520 (forward-char -7))
yuuji@69 1521 ((= (preceding-char) ?\\ ) ;matsu's hack ends here
yuuji@184 1522 (YaTeX-insert-inherit "(\\)")
yuuji@22 1523 (backward-char 2))
yuuji@22 1524 ((YaTeX-closable-p)
yuuji@184 1525 (YaTeX-insert-inherit "()")
yuuji@22 1526 (backward-char 1))
yuuji@69 1527 (t (YaTeX-self-insert arg))))
yuuji@22 1528
yuuji@11 1529 (defun YaTeX-insert-parens-region (beg end)
yuuji@11 1530 (interactive "r")
yuuji@69 1531 (YaTeX-insert-braces-region beg end "(" ")"))
yuuji@69 1532
yuuji@69 1533 (defun YaTeX-insert-bar (arg)
yuuji@69 1534 "Insert bar pair."
yuuji@69 1535 (interactive "p")
yuuji@69 1536 (cond
yuuji@69 1537 ((YaTeX-jmode) (YaTeX-self-insert arg))
yuuji@69 1538 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
yuuji@69 1539 ((save-excursion
yuuji@69 1540 (and (> (- (point) (point-min)) 5) (forward-char -5))
yuuji@69 1541 (looking-at "\\\\left"))
yuuji@184 1542 (YaTeX-insert-inherit "|\\right|")
yuuji@69 1543 (forward-char -7))
yuuji@193 1544 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
yuuji@69 1545 (and (> (- (point) (point-min)) 5) (forward-char -5))
yuuji@69 1546 (looking-at "\\\\[bB]igl"))
yuuji@69 1547 (insert
yuuji@69 1548 (concat
yuuji@69 1549 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
yuuji@69 1550 (forward-char -6))
yuuji@69 1551 ((save-excursion
yuuji@69 1552 (and (> (- (point) (point-min)) 6) (forward-char -6))
yuuji@69 1553 (looking-at "\\\\[bB]iggl"))
yuuji@69 1554 (insert
yuuji@69 1555 (concat
yuuji@69 1556 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
yuuji@69 1557 (forward-char -7))
yuuji@193 1558 ((save-excursion ; added by Jin <MAF01011<at>nifty.ne.jp>
yuuji@69 1559 (and (> (- (point) (point-min)) 6) (forward-char -6))
yuuji@69 1560 (looking-at "\\\\left\\\\"))
yuuji@184 1561 (YaTeX-insert-inherit "|\\right\\|")
yuuji@69 1562 (forward-char -8))
yuuji@69 1563 ((save-excursion
yuuji@69 1564 (and (> (- (point) (point-min)) 6) (forward-char -6))
yuuji@69 1565 (looking-at "\\\\[bB]igl\\\\"))
yuuji@69 1566 (insert
yuuji@69 1567 (concat
yuuji@69 1568 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
yuuji@69 1569 (forward-char -7))
yuuji@69 1570 ((save-excursion
yuuji@69 1571 (and (> (- (point) (point-min)) 7) (forward-char -7))
yuuji@69 1572 (looking-at "\\\\[bB]iggl\\\\"))
yuuji@69 1573 (insert
yuuji@69 1574 (concat
yuuji@69 1575 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
yuuji@69 1576 (forward-char -8)) ; added by Jin up to here.
yuuji@69 1577 ((= (preceding-char) ?\\ )
yuuji@184 1578 (YaTeX-insert-inherit "|\\|")
yuuji@69 1579 (backward-char 2))
yuuji@69 1580 ; ((and (YaTeX-closable-p)
yuuji@69 1581 ; (/= (preceding-char) ?|)
yuuji@69 1582 ; (/= (following-char) ?|))
yuuji@184 1583 ; (YaTeX-insert-inherit "||")
yuuji@69 1584 ; (backward-char 1))
yuuji@69 1585 (t (YaTeX-self-insert arg))))
yuuji@11 1586
yuuji@285 1587 (defvar YaTeX-use-jmode-hook
yuuji@285 1588 (and (featurep 'canna) (boundp 'canna:*initialized*) canna:*initialized*)
yuuji@285 1589 ;; (not (and (fboundp 'skk-mode) (boundp 'skk-mode)))
yuuji@197 1590 "*Non-nil means activate automatic jmode switcher within/out math mode.
yuuji@197 1591 Hopefully, change default to t in the next version of 1.75.")
yuuji@179 1592 (defun YaTeX-jmode-hook (old new)
yuuji@179 1593 "A hook controling jmode on/off."
yuuji@186 1594 ;; This function is called via point-entered/leave hook, so that
yuuji@186 1595 ;; codes in it is evaluated on such emacsen as having text-properties.
yuuji@179 1596 (let ((inhibit-point-motion-hooks t)
yuuji@179 1597 (oldp (plist-get (text-properties-at old) 'point-left))
yuuji@179 1598 (newp (plist-get (text-properties-at new) 'point-left))
yuuji@179 1599 (lnew (plist-get (text-properties-at new) 'last-new))
yuuji@186 1600 (mjmode (plist-get (text-properties-at new) 'mjmode))
yuuji@186 1601 (bmp (buffer-modified-p))
yuuji@179 1602 (jm (YaTeX-jmode)) b e)
yuuji@181 1603 (unwind-protect
yuuji@181 1604 (cond
yuuji@181 1605 ((eq lnew new) nil) ;Do nothing if continuous entry
yuuji@181 1606 ((and (not (eq newp 'YaTeX-jmode-hook))
yuuji@186 1607 (eq oldp 'YaTeX-jmode-hook)
yuuji@186 1608 (plist-get (text-properties-at old) 'entered))
yuuji@181 1609 ;; leave
yuuji@181 1610 (remove-text-properties
yuuji@186 1611 (setq b (1+ (or (previous-single-property-change old 'point-left)
yuuji@186 1612 (1- (point)))))
yuuji@186 1613 (setq e (1- (or (next-single-property-change old 'point-left)
yuuji@186 1614 (1+ (point)))))
yuuji@186 1615 (list 'last-new nil 'entered nil))
yuuji@186 1616 (add-text-properties b e (list 'mjmode jm))
yuuji@186 1617 (if (boundp 'skk-katakana)
yuuji@186 1618 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
yuuji@181 1619 (if (plist-get (text-properties-at old) 'jmode)
yuuji@181 1620 (YaTeX-jmode-on)))
yuuji@181 1621 ((and (not (eq oldp 'YaTeX-jmode-hook))
yuuji@186 1622 (eq newp 'YaTeX-jmode-hook)
yuuji@186 1623 (not (plist-get (text-properties-at new) 'entered)))
yuuji@181 1624 ;; enter
yuuji@181 1625 (add-text-properties
yuuji@181 1626 (1+ (or (previous-single-property-change new 'point-left)
yuuji@181 1627 (1- (point))))
yuuji@181 1628 (1- (or (next-single-property-change new 'point-left)
yuuji@181 1629 (1+ (point))))
yuuji@186 1630 (list 'jmode jm 'last-new new 'entered t))
yuuji@186 1631 (if (boundp 'skk-katakana) ;care for skk katakana mode
yuuji@186 1632 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
yuuji@186 1633 (if mjmode (YaTeX-jmode-on) (YaTeX-jmode-off))))
yuuji@181 1634 ;;unwind job
yuuji@181 1635 (set-buffer-modified-p bmp))))
yuuji@179 1636
yuuji@0 1637 (defun YaTeX-insert-dollar ()
yuuji@0 1638 (interactive)
yuuji@22 1639 (if (or (not (YaTeX-closable-p))
yuuji@57 1640 (= (preceding-char) 92)
yuuji@58 1641 (and (YaTeX-in-math-mode-p)
yuuji@58 1642 (or (/= (preceding-char) ?$) (/= (following-char) ?$))))
yuuji@7 1643 (insert "$")
yuuji@7 1644 (insert "$$")
yuuji@22 1645 (forward-char -1)
yuuji@197 1646 (and YaTeX-use-jmode-hook
yuuji@197 1647 (fboundp 'add-text-properties)
yuuji@197 1648 (add-text-properties
yuuji@197 1649 (1- (point)) (1+ (point))
yuuji@197 1650 (list 'point-left 'YaTeX-jmode-hook
yuuji@197 1651 'point-entered 'YaTeX-jmode-hook
yuuji@197 1652 'front-sticky t
yuuji@197 1653 'rear-nonsticky t
yuuji@197 1654 'mjmode nil
yuuji@197 1655 'jmode (YaTeX-jmode))))
yuuji@59 1656 (YaTeX-jmode-off)
yuuji@69 1657 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1))))
yuuji@0 1658
yuuji@11 1659 (defun YaTeX-insert-dollars-region (beg end)
yuuji@11 1660 (interactive "r")
yuuji@69 1661 (YaTeX-insert-braces-region beg end "$" "$"))
yuuji@11 1662
yuuji@57 1663 (defun YaTeX-insert-amper ()
yuuji@57 1664 (interactive)
yuuji@57 1665 (if (or (string-match YaTeX-array-env-regexp
yuuji@57 1666 (or (YaTeX-inner-environment t) "document"))
yuuji@57 1667 (= (preceding-char) 92)
yuuji@77 1668 (YaTeX-literal-p)
yuuji@77 1669 (YaTeX-in-math-mode-p))
yuuji@57 1670 (insert "&")
yuuji@69 1671 (insert "\\&")))
yuuji@57 1672
yuuji@0 1673 (defun YaTeX-version ()
yuuji@0 1674 "Return string of the version of running YaTeX."
yuuji@0 1675 (interactive)
yuuji@0 1676 (message
yuuji@5 1677 (concat "Yet Another tex-mode "
yuuji@55 1678 (if YaTeX-japan "「野鳥」" "`Wild Bird'")
yuuji@7 1679 " Revision "
yuuji@69 1680 YaTeX-revision-number)))
yuuji@0 1681
yuuji@46 1682 (defun YaTeX-typeset-menu (arg &optional char)
yuuji@46 1683 "Typeset, preview, visit error and miscellaneous convenient menu.
yuuji@46 1684 Optional second argument CHAR is for non-interactive call from menu."
yuuji@5 1685 (interactive "P")
yuuji@7 1686 (message
yuuji@130 1687 (concat "J)latex R)egion E)nv B)ibtex mk(I)dx "
yuuji@123 1688 "latex+p(D)f "
yuuji@123 1689 (if (fboundp 'start-process) "K)ill ")
yuuji@58 1690 "P)review "
yuuji@58 1691 (and (boundp 'window-system) window-system "S)earch ")
yuuji@123 1692 "V)iewErr L)pr"))
yuuji@46 1693 (let ((sw (selected-window)) (c (or char (read-char))))
yuuji@32 1694 (require 'yatexprc) ;for Nemacs's bug
yuuji@32 1695 (select-window sw)
yuuji@4 1696 (cond
yuuji@327 1697 ((memq c '(?j ?\C-j)) (YaTeX-typeset-buffer) ; memq for usability test
yuuji@327 1698 (put 'dvi2-command 'format 'dvi))
yuuji@5 1699 ((= c ?r) (YaTeX-typeset-region))
yuuji@130 1700 ((= c ?e) (YaTeX-typeset-environment))
yuuji@224 1701 ((= c ?b) (YaTeX-call-builtin-on-file
yuuji@227 1702 "BIBTEX" bibtex-command arg))
yuuji@224 1703 ((= c ?i) (YaTeX-call-builtin-on-file
yuuji@227 1704 "MAKEINDEX" makeindex-command arg))
yuuji@7 1705 ((= c ?k) (YaTeX-kill-typeset-process YaTeX-typeset-process))
yuuji@4 1706 ((= c ?p) (call-interactively 'YaTeX-preview))
yuuji@351 1707 ((= c ?q) (YaTeX-system "lpq" "Printer queue"))
yuuji@288 1708 ((= c ?d) (YaTeX-typeset-buffer
yuuji@327 1709 (or (YaTeX-get-builtin "DVIPDF") YaTeX-dvipdf-command))
yuuji@327 1710 (put 'dvi2-command 'format 'pdf))
yuuji@4 1711 ((= c ?v) (YaTeX-view-error))
yuuji@5 1712 ((= c ?l) (YaTeX-lpr arg))
yuuji@13 1713 ((= c ?m) (YaTeX-switch-mode-menu arg))
yuuji@69 1714 ((= c ?s) (YaTeX-xdvi-remote-search arg)))))
yuuji@4 1715
yuuji@72 1716 (if (fboundp 'wrap-function-to-control-ime)
yuuji@72 1717 (wrap-function-to-control-ime 'YaTeX-typeset-menu t "P"))
yuuji@72 1718
yuuji@72 1719
yuuji@46 1720 (defun YaTeX-%-menu (&optional beg end char)
yuuji@13 1721 "Operate %# notation."
yuuji@16 1722 ;;Do not use interactive"r" for the functions which require no mark
yuuji@16 1723 (interactive)
yuuji@410 1724 (message "!)Edit-%%#! D)VIPDF B)EGIN-END P)review pdf(V)iew L)PR M)akeidx b)ibtex dp(I)")
yuuji@46 1725 (let ((c (or char (read-char))) (string "") key
yuuji@13 1726 (b (make-marker)) (e (make-marker)))
yuuji@13 1727 (save-excursion
yuuji@13 1728 (cond
yuuji@410 1729 ((rindex "!plmibdv" c) ;Edit %#xxx
yuuji@227 1730 (setq key (cdr (assq c '((?! . "!")
yuuji@227 1731 (?p . "PREVIEW")
yuuji@227 1732 (?l . "LPR")
yuuji@407 1733 (?m . "MAKEINDEX")
yuuji@386 1734 (?d . "DVIPDF")
yuuji@410 1735 (?v . "PDFVIEW")
yuuji@407 1736 (?i . "IMAGEDPI")
yuuji@227 1737 (?b . "BIBTEX")))))
yuuji@227 1738 (YaTeX-getset-builtin key t))
yuuji@13 1739
yuuji@385 1740 ((= c ?B) ;%#BEGIN %#END region
yuuji@16 1741 (or end (setq beg (min (point) (mark)) end (max (point) (mark))))
yuuji@13 1742 (set-marker b beg)
yuuji@13 1743 (set-marker e end)
yuuji@13 1744 (goto-char (point-min))
yuuji@13 1745 (while (re-search-forward "^%#\\(BEGIN\\)\\|\\(END\\)$" nil t)
yuuji@53 1746 (beginning-of-line)
yuuji@53 1747 (delete-region (point) (progn (forward-line 1) (point))))
yuuji@68 1748 (goto-char b)
yuuji@13 1749 (open-line 1)
yuuji@53 1750 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
yuuji@13 1751 (insert "%#BEGIN")
yuuji@68 1752 (goto-char e)
yuuji@68 1753 (insert "%#END\n")
yuuji@68 1754 (set-marker b nil)
yuuji@386 1755 (set-marker e nil))))))
yuuji@13 1756
yuuji@168 1757 (defvar YaTeX-refcommand-def-regexp-default
yuuji@168 1758 "label\\|bibitem")
yuuji@168 1759 (defvar YaTeX-refcommand-def-regexp-private nil
yuuji@168 1760 "*Regexp of defining label commands")
yuuji@168 1761 (defvar YaTeX-refcommand-def-regexp
yuuji@168 1762 (concat (if YaTeX-refcommand-def-regexp-private
yuuji@168 1763 (concat YaTeX-refcommand-def-regexp-private "\\|"))
yuuji@168 1764 YaTeX-refcommand-def-regexp-default))
yuuji@168 1765
yuuji@168 1766 (defvar YaTeX-refcommand-ref-regexp-default
yuuji@314 1767 "\\(page\\|eq\\|fig\\)?ref\\|cite"
yuuji@314 1768 "Regexp of LaTeX's label-referring macros.
yuuji@314 1769 Searching for this will be done without `\\\\'.
yuuji@314 1770 So you need not add patterns if new referring macro ends with \"ref\".")
yuuji@168 1771 (defvar YaTeX-refcommand-ref-regexp-private nil
yuuji@314 1772 "*Regexp of referring label commands.
yuuji@314 1773 See documentation of `YaTeX-refcommand-ref-regexp-default'.")
yuuji@168 1774 (defvar YaTeX-refcommand-ref-regexp
yuuji@168 1775 (concat (if YaTeX-refcommand-ref-regexp-private
yuuji@168 1776 (concat YaTeX-refcommand-ref-regexp-private "\\|"))
yuuji@168 1777 YaTeX-refcommand-ref-regexp-default))
yuuji@168 1778
yuuji@168 1779 (defvar YaTeX-refcommand-regexp
yuuji@168 1780 (concat YaTeX-refcommand-def-regexp
yuuji@168 1781 "\\|" YaTeX-refcommand-ref-regexp)
yuuji@168 1782 "Regexp of label defining/referring command name.")
yuuji@168 1783
yuuji@51 1784 (defun YaTeX-goto-corresponding-label (reverse &optional otherwin)
yuuji@48 1785 "Jump to corresponding \\label{} and \\ref{} or \\cite and \\bibitem.
yuuji@48 1786 The default search direction depends on the command at the cursor position.
yuuji@48 1787 When the cursor is on \\ref(\\cite), YaTeX will try to search the
yuuji@48 1788 corresponding \\label(\\bibitem) backward,
yuuji@48 1789 and if it fails search forward again. And when the cursor is
yuuji@48 1790 on \\label(\\bibitem), YaTeX will search the corresponding \\ref(\\cite)
yuuji@48 1791 forward at first and secondary backward.
yuuji@48 1792 Argument REVERSE non-nil makes the default
yuuji@48 1793 direction rule reverse. Since Search string is automatically set in
yuuji@13 1794 search-last-string, you can repeat search the same label/ref by typing
yuuji@51 1795 \\[isearch-forward] or \\[isearch-backward].
yuuji@51 1796 If optional second argument OTHERWIN is non-nil, move to other window."
yuuji@13 1797
yuuji@51 1798 (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
yuuji@168 1799 (refcommands YaTeX-refcommand-regexp)
yuuji@82 1800 (foundmsg (format "Type %s %c to return to original position."
yuuji@82 1801 (key-description
yuuji@82 1802 (car
yuuji@82 1803 (or (where-is-internal 'register-to-point)
yuuji@82 1804 (where-is-internal 'jump-to-register))))
yuuji@82 1805 YaTeX-current-position-register))
yuuji@48 1806 (func (function (lambda (string sfunc)
yuuji@48 1807 (or
yuuji@48 1808 (funcall sfunc string nil t)
yuuji@68 1809 (funcall (if (eq sfunc 're-search-forward)
yuuji@68 1810 're-search-backward 're-search-forward)
yuuji@48 1811 string nil t))))))
yuuji@7 1812 (cond
yuuji@48 1813 ((YaTeX-on-section-command-p refcommands)
yuuji@82 1814 (setq scmd
yuuji@82 1815 (cdr
yuuji@82 1816 (assoc
yuuji@82 1817 (YaTeX-match-string 1)
yuuji@82 1818 '(("label" . "\\\\\\(page\\|eq\\)?ref{%k}")
yuuji@82 1819 ("ref" . "\\\\label{%k}")
yuuji@82 1820 ("eqref" . "\\\\label{%k}")
yuuji@82 1821 ("pageref" . "\\\\label{%k}")
yuuji@82 1822 ("cite" .
yuuji@82 1823 "\\\\bibitem\\(\\[[^]]+\\]\\)?{%k}\\|^\\s *@[a-z]+{%k,")
yuuji@82 1824 ("bibitem" . "\\\\cite\\(\\[[^]]+\\]\\)?")))))
yuuji@7 1825 (goto-char (match-end 0))
yuuji@165 1826 (let ((label (YaTeX-buffer-substring
yuuji@82 1827 (1- (point)) (progn (backward-list 1) (1+ (point)))))
yuuji@82 1828 (fp (make-marker))fl fn
yuuji@82 1829 (goother (function (lambda (buffer point)
yuuji@82 1830 (goto-char point)
yuuji@82 1831 (if (one-window-p)
yuuji@82 1832 (split-window-calculate-height
yuuji@82 1833 YaTeX-default-pop-window-height))
yuuji@82 1834 (select-window (get-lru-window))
yuuji@82 1835 (switch-to-buffer buffer)))))
yuuji@68 1836 ;(setq string (concat "\\" scmd "{" label "}"))
yuuji@82 1837 ;(setq string (concat "\\\\" scmd "{" (regexp-quote label) "}"))
yuuji@82 1838 (setq string (YaTeX-replace-format scmd "k" (regexp-quote label)))
yuuji@48 1839 (setq direc (if (string-match "ref\\|cite" scmd)
yuuji@68 1840 're-search-forward 're-search-backward))
yuuji@48 1841 (if YaTeX-current-position-register
yuuji@48 1842 (point-to-register YaTeX-current-position-register))
yuuji@68 1843 (if reverse (setq direc (if (eq direc 're-search-forward)
yuuji@68 1844 're-search-backward 're-search-forward)))
yuuji@48 1845 (if (funcall func string direc) ;label/ref found!
yuuji@13 1846 (progn
yuuji@82 1847 (if otherwin (funcall goother cb p))
yuuji@13 1848 (goto-char (match-beginning 0))
yuuji@51 1849 (push-mark p))
yuuji@51 1850 ;;if label/ref not found, search through all yatex buffers.
yuuji@51 1851 (goto-char p) ;resume position of current buffer
yuuji@48 1852 (catch 'found
yuuji@82 1853 (setq blist (YaTeX-yatex-buffer-list))
yuuji@48 1854 (while blist
yuuji@82 1855 ;; search for corresponding keyword
yuuji@48 1856 (set-buffer (car blist))
yuuji@48 1857 (if (YaTeX-on-section-command-p refcommands)
yuuji@48 1858 (goto-char (match-beginning 0)))
yuuji@82 1859 (cond
yuuji@82 1860 ; cond1
yuuji@82 1861 ((funcall func string direc)
yuuji@82 1862 (cond
yuuji@82 1863 (otherwin
yuuji@82 1864 (set-buffer cb)
yuuji@82 1865 (funcall goother (car blist) p))
yuuji@82 1866 ((or (get-buffer-window (car blist))
yuuji@82 1867 (and YaTeX-emacs-19
yuuji@82 1868 (get-buffer-window (car blist) t)))
yuuji@82 1869 (goto-buffer-window (car blist)))
yuuji@82 1870 (t
yuuji@82 1871 (switch-to-buffer (car blist))
yuuji@82 1872 (message foundmsg)))
yuuji@82 1873 (goto-char (match-beginning 0))
yuuji@82 1874 (throw 'found t))
yuuji@82 1875 ; cond2
yuuji@82 1876 ((and
yuuji@82 1877 (string-match "bibitem" scmd)
yuuji@82 1878 (catch 'found2
yuuji@82 1879 (save-excursion
yuuji@82 1880 (goto-char (point-min))
yuuji@82 1881 (while (YaTeX-re-search-active-forward
yuuji@82 1882 "\\\\bibliography{\\([^}]*\\)}" "%" nil t)
yuuji@82 1883 (setq fl (YaTeX-split-string (YaTeX-match-string 1) ","))
yuuji@82 1884 (while fl
yuuji@82 1885 (if (or (file-exists-p (setq fn (car fl)))
yuuji@82 1886 (file-exists-p (setq fn (concat fn ".bib"))))
yuuji@82 1887 (progn
yuuji@82 1888 (set-buffer (find-file-noselect fn))
yuuji@82 1889 (save-excursion
yuuji@82 1890 (goto-char (point-min))
yuuji@82 1891 (if (YaTeX-re-search-active-forward
yuuji@82 1892 string "%" nil t)
yuuji@82 1893 (throw 'found2
yuuji@82 1894 (set-marker fp (point)))))))
yuuji@82 1895 (setq fl (cdr fl)))))))
yuuji@82 1896 (if otherwin
yuuji@82 1897 (funcall goother (marker-buffer fp) fp)
yuuji@82 1898 (switch-to-buffer (marker-buffer fp))
yuuji@82 1899 (goto-char fp))
yuuji@82 1900 (set-marker fp nil)
yuuji@82 1901 (message foundmsg)
yuuji@82 1902 (throw 'found t)))
yuuji@82 1903 (setq blist (cdr blist)))
yuuji@82 1904 ;; search for bibliography
yuuji@82 1905 )))
yuuji@48 1906 (if YaTeX-emacs-19
yuuji@68 1907 (setq regexp-search-ring
yuuji@68 1908 (cons string (delete string regexp-search-ring)))
yuuji@68 1909 (setq search-last-regexp string)))
yuuji@69 1910 (t nil))))
yuuji@5 1911
yuuji@73 1912 ;;YaTeX-goto-corresponding-environment was moved to yatexlib
yuuji@3 1913
yuuji@60 1914 (defun YaTeX-goto-corresponding-file (&optional other)
yuuji@60 1915 "Visit or switch buffer of corresponding file,
yuuji@176 1916 looking at \\input or \\include or \\includeonly on current line."
yuuji@60 1917 (if (not (YaTeX-on-includes-p)) nil
yuuji@70 1918 (let ((parent buffer-file-name) input-file b)
yuuji@60 1919 (save-excursion
yuuji@86 1920 (if (and (re-search-forward "[{%]" (point-end-of-line) t)
yuuji@86 1921 (= ?{ (char-after (match-beginning 0))))
yuuji@60 1922 nil
yuuji@60 1923 (skip-chars-backward "^,{"))
yuuji@60 1924 (setq input-file
yuuji@165 1925 (YaTeX-buffer-substring
yuuji@60 1926 (point) (progn (skip-chars-forward "^ ,}") (point))))
yuuji@60 1927 (if (not (string-match "\\.\\(tex\\|sty\\)$" input-file))
yuuji@60 1928 (setq input-file (concat input-file ".tex"))))
yuuji@60 1929 (cond
yuuji@60 1930 (other (YaTeX-switch-to-buffer-other-window input-file))
yuuji@70 1931 ((setq b (YaTeX-get-file-buffer input-file))
yuuji@70 1932 (goto-buffer-window b))
yuuji@60 1933 (t (YaTeX-switch-to-buffer input-file)))
yuuji@60 1934 (or (YaTeX-get-builtin "!")
yuuji@60 1935 YaTeX-parent-file
yuuji@69 1936 (setq YaTeX-parent-file parent)))))
yuuji@5 1937
yuuji@5 1938 (defun YaTeX-goto-corresponding-BEGIN-END ()
yuuji@5 1939 (if (not (YaTeX-on-BEGIN-END-p)) nil
yuuji@5 1940 (if (cond
yuuji@5 1941 ((equal (match-beginning 0) (match-beginning 1)) ;if on %#BEGIN
yuuji@5 1942 (not (search-forward "%#END" nil t)))
yuuji@5 1943 (t ; if on %#END
yuuji@5 1944 (not (search-backward "%#BEGIN" nil t))))
yuuji@7 1945 (error "Corresponding %%#BEGIN/END not found."))
yuuji@5 1946 (beginning-of-line)
yuuji@69 1947 t))
yuuji@5 1948
yuuji@59 1949 (defvar YaTeX-processed-file-regexp-alist nil
yuuji@59 1950 "Alist of regexp of processed file regexp vs. its file name part;
yuuji@59 1951 For example, if you include image file with `\\epsfile{file=FILE}' where
yuuji@59 1952 `FILE' is processed file. You might want to view FILE with other previewer
yuuji@59 1953 such as ghostview, or want to preview its source which was drawn with
yuuji@59 1954 other drawing tool, tgif for example. Then you should set entire regexp
yuuji@59 1955 of including expression and enclose its file name part with \\\\( and \\\\).
yuuji@59 1956
yuuji@59 1957 Ex. (\"\\\\\\\\epsfile{[^}]*file=\\\\([^,} ]+\\\\)\\\\(\\\\.e?ps\\\\)?[^}]*}\" 1)
yuuji@59 1958
yuuji@59 1959 Where the first group surrounded by \\\\( and \\\\) is the file name part
yuuji@59 1960 of expression. So you should set 1 to second element. And the first
yuuji@59 1961 matching group is sent to (image) processor defined by the variable
yuuji@59 1962 YaTeX-file-processor-alist. See also the documentation of
yuuji@59 1963 YaTeX-file-processor-alist.
yuuji@59 1964
yuuji@59 1965 ↑じゃ良くわかんないすね。例えば tgif hoge.obj して hoge.eps を
yuuji@59 1966 \\epsfile{file=hoge.eps} でインクルードしているとしよう。その行で
yuuji@59 1967 \[prefix\] g を押した時に tgif を起動して欲しかったら、まず上のような
yuuji@59 1968 正規表現を設定する。\\\\(と\\\\)で囲んだところがファイル名になるように
yuuji@59 1969 注意する。でファイル名部分が何番目の\\\\(\\\\)になるかをリストの2番目に書く。
yuuji@59 1970 すると、その部分が変数 YaTeX-file-processor-alist で定義された
yuuji@59 1971 処理プログラムに渡される。というわけ。
yuuji@59 1972 ん〜やっぱりむずかしいね。分からない時は隣の Lisper に聞くか、
yuuji@59 1973 fj野鳥の会で聞こう!
yuuji@59 1974 ")
yuuji@59 1975
yuuji@59 1976 (defvar YaTeX-processed-file-regexp-alist-default
yuuji@64 1977 '(("\\\\epsfile\\(\\[[^]]+\\]\\)?{[^},]*file=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
yuuji@60 1978 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
yuuji@60 1979 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 1)
yuuji@274 1980 ("\\\\\\(epsfbox\\|epsfig\\)\\*?{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 2) ;\epsfbox{hoge.ps}
yuuji@275 1981 ("\\\\includegraphics\\*?\\(.*\\]\\|\\s \\)?{\\(.*\\)\\(\\.ai\\|\\.pdf\\|\\.svg\\|\\.png\\|\\.jpe?g\\|\\.e?ps\\)}" 2) ;\includegraphics[options...]{hoge.eps}
yuuji@60 1982 ("\\\\\\(psbox\\)\\(\\[[^]]+\\]\\)?{\\(\\([^,} ]*/\\)?[^} ]+\\)\\(\\.e?ps\\)}" 3) ;\psbox[options...]{hoge.eps} (97/1/11)
yuuji@68 1983 ("\\\\input{\\([^} ]+\\)\\(\\.tps\\)}" 1) ;tgif2tex (1998/9/16)
yuuji@59 1984 )
yuuji@69 1985 "See the documentation of YaTeX-processed-file-regexp-alist.")
yuuji@59 1986
yuuji@59 1987 (defvar YaTeX-file-processor-alist nil
yuuji@59 1988 "*Alist of files' processor vs. its extension;
yuuji@69 1989 See also the documentation of YaTeX-processed-file-regexp-alist.")
yuuji@274 1990
yuuji@59 1991 (defvar YaTeX-file-processor-alist-default
yuuji@334 1992 (list (cons YaTeX-cmd-tgif ".obj")
yuuji@334 1993 (cons YaTeX-cmd-gimp ".xcf")
yuuji@334 1994 (cons YaTeX-cmd-gimp ".xcf.gz")
yuuji@334 1995 (cons YaTeX-cmd-gimp ".xcf.bz2")
yuuji@334 1996 (cons YaTeX-cmd-edit-svg ".svg")
yuuji@334 1997 (cons YaTeX-cmd-edit-svg ".svgz")
yuuji@334 1998 (cons YaTeX-cmd-edit-ai ".ai")
yuuji@334 1999 '("dia" . ".dia")
yuuji@334 2000 (cons YaTeX-cmd-ooo ".odg")
yuuji@334 2001 (cons YaTeX-cmd-edit-images ".jpeg")
yuuji@334 2002 (cons YaTeX-cmd-edit-images ".jpg")
yuuji@334 2003 (cons YaTeX-cmd-edit-images ".png")
yuuji@334 2004 (cons YaTeX-cmd-edit-ps ".ps")
yuuji@334 2005 (cons YaTeX-cmd-edit-ps ".eps")
yuuji@334 2006 (cons YaTeX-cmd-edit-pdf ".pdf")
yuuji@334 2007 '(t . ".tex")
yuuji@334 2008 '(t . ".sty")
yuuji@334 2009 '(t . ""))
yuuji@69 2010 "See the documentation of YaTeX-file-processor-alist.")
yuuji@59 2011
yuuji@59 2012 (defun YaTeX-goto-corresponding-file-processor (&optional other)
yuuji@59 2013 "Execute corresponding file processor."
yuuji@59 2014 (save-excursion
yuuji@59 2015 (or (looking-at YaTeX-ec-regexp)
yuuji@59 2016 (skip-chars-backward (concat "^" YaTeX-ec) (point-beginning-of-line)))
yuuji@59 2017 (let ((list (append YaTeX-processed-file-regexp-alist
yuuji@59 2018 YaTeX-processed-file-regexp-alist-default))
yuuji@59 2019 (p (point)) flist file
yuuji@70 2020 (peol (point-end-of-line))
yuuji@70 2021 (basedir
yuuji@70 2022 (if YaTeX-search-file-from-top-directory
yuuji@70 2023 (save-excursion (YaTeX-visit-main t) default-directory)
yuuji@70 2024 ".")))
yuuji@59 2025 (setq flist (catch 'found
yuuji@70 2026 (while list
yuuji@70 2027 (goto-char p)
yuuji@70 2028 (if (re-search-forward (car (car list)) peol t)
yuuji@70 2029 (progn
yuuji@70 2030 (setq file (YaTeX-match-string
yuuji@70 2031 (car (cdr (car list)))))
yuuji@70 2032 (throw 'found (cdr (car list)))))
yuuji@70 2033 (setq list (cdr list)))))
yuuji@59 2034 (if flist ;if pattern and file name found
yuuji@59 2035 (let*((plist (append YaTeX-file-processor-alist
yuuji@59 2036 YaTeX-file-processor-alist-default))
yuuji@59 2037 (plist0 plist)
yuuji@59 2038 ext cmd src buf (alt (car (cdr flist))))
yuuji@59 2039 (if (and (re-search-forward
yuuji@59 2040 (concat YaTeX-comment-prefix "\\s *\\(.*\\)$") peol t)
yuuji@59 2041 (assoc (setq cmd (YaTeX-match-string 1))
yuuji@59 2042 YaTeX-file-processor-alist))
yuuji@59 2043 (setq src ;if processor is specified
yuuji@59 2044 (concat file
yuuji@59 2045 (cdr (assoc cmd YaTeX-file-processor-alist))))
yuuji@59 2046 (while plist ;if processor is not specified
yuuji@59 2047 (setq ext (cdr (car plist)))
yuuji@60 2048 (if (and (string< "" (concat file ext))
yuuji@70 2049 (file-exists-p
yuuji@70 2050 (expand-file-name (concat file ext) basedir)))
yuuji@70 2051 (setq cmd (car (car plist))
yuuji@70 2052 src (concat file ext) plist nil))
yuuji@59 2053 (setq plist (cdr plist)))
yuuji@59 2054 (if (and (null src) alt YaTeX-create-file-prefix-g)
yuuji@59 2055 (setq cmd alt
yuuji@59 2056 src (concat file (cdr (assoc alt plist0))))))
yuuji@70 2057 (if src ;if processor and src file found
yuuji@70 2058 (let ((default-directory basedir))
yuuji@59 2059 (cond
yuuji@70 2060 ((stringp cmd)
yuuji@351 2061 (YaTeX-system (concat cmd " " src) cmd)
yuuji@351 2062 t)
yuuji@70 2063 ((eq t cmd)
yuuji@70 2064 (let ((parent buffer-file-name))
yuuji@70 2065 (funcall
yuuji@70 2066 (cond
yuuji@70 2067 (other 'YaTeX-switch-to-buffer-other-window)
yuuji@70 2068 ((get-file-buffer src) 'goto-buffer-window)
yuuji@70 2069 (t 'YaTeX-switch-to-buffer))
yuuji@70 2070 src)
yuuji@70 2071 (or (YaTeX-get-builtin "!")
yuuji@70 2072 YaTeX-parent-file
yuuji@70 2073 (setq YaTeX-parent-file parent))
yuuji@70 2074 t))
yuuji@70 2075 ((symbolp cmd)
yuuji@70 2076 (cond
yuuji@70 2077 ((symbol-function cmd)
yuuji@70 2078 (funcall cmd src other)))
yuuji@70 2079 t)))))))))
yuuji@59 2080
yuuji@14 2081 (defun YaTeX-on-section-command-p (command)
yuuji@53 2082 "Check if point is on the LaTeX command: COMMAND(regexp).
yuuji@49 2083 Return nil if point is not on it. Otherwise return the
yuuji@49 2084 number of argument position.
yuuji@82 2085 Section command name is stored in match-data #1.
yuuji@82 2086 Parsing information is stored to plist.
yuuji@82 2087 Macros name stored to propname 'command.
yuuji@82 2088 Macro's argument number stored to propname 'argc."
yuuji@82 2089 (let ((p (point)) md (parg 0) (argc 1) word (grouping 0) (i 0)
yuuji@82 2090 (ec+command (concat YaTeX-ec-regexp "\\(" command "\\)")))
yuuji@82 2091 (setplist 'YaTeX-on-section-command-p nil)
yuuji@53 2092 (while (setq i (string-match "\\\\(" command i))
yuuji@53 2093 (setq grouping (1+ grouping) i (+ i 2)))
yuuji@7 2094 (save-excursion
yuuji@82 2095 (if (looking-at ec+command) nil
yuuji@49 2096 (catch 'found ;caught value has no meaning
yuuji@77 2097 ;;(1) looking at current position
yuuji@82 2098 (and (looking-at command)
yuuji@82 2099 (save-excursion
yuuji@82 2100 (while (and (not (bobp)) (looking-at command))
yuuji@82 2101 (forward-char -1))
yuuji@82 2102 (looking-at ec+command))
yuuji@82 2103 (goto-char (match-beginning 0))
yuuji@82 2104 (throw 'found t))
yuuji@245 2105 ;;If inside of parentheses, try to escape.
yuuji@414 2106 (unwind-protect
yuuji@414 2107 (progn
yuuji@414 2108 (set-syntax-table YaTeX-mode-syntax-table-nonparen)
yuuji@414 2109 (while (and (not (= (preceding-char) ?\])) ;skip optional arg
yuuji@414 2110 (condition-case err
yuuji@414 2111 (progn (up-list -1) t)
yuuji@414 2112 (error nil)))))
yuuji@414 2113 (set-syntax-table YaTeX-mode-syntax-table))
yuuji@245 2114 (while (equal (preceding-char) ?\]) (backward-list))
yuuji@77 2115 ;;(2) search command directly
yuuji@77 2116 (skip-chars-forward "^{}[]")
yuuji@77 2117 (and (YaTeX-re-search-active-backward
yuuji@82 2118 ec+command
yuuji@82 2119 YaTeX-comment-prefix nil t)
yuuji@77 2120 (>= p (match-beginning 0))
yuuji@77 2121 (throw 'found (goto-char (match-beginning 0))))
yuuji@77 2122 ;;(3) search token
yuuji@77 2123 (goto-char p)
yuuji@49 2124 (while t
yuuji@49 2125 (if (bobp) (throw 'found nil))
yuuji@49 2126 (cond
yuuji@49 2127 ((looking-at YaTeX-ec-regexp) (throw 'found t))
yuuji@49 2128 ((looking-at "[[{]") nil)
yuuji@53 2129 ((looking-at "[]}]")(condition-case nil (up-list -1) (error nil)))
yuuji@49 2130 (t (skip-chars-backward " \t\r\n")))
yuuji@49 2131 (skip-chars-backward (concat "^ \t\r\n{}[]" YaTeX-ec-regexp))
yuuji@51 2132 (or (bobp) (forward-char -1)))))
yuuji@51 2133 (if (and
yuuji@82 2134 (looking-at (concat ec+command
yuuji@82 2135 "\\(\\(\\[[^]]+\\]\\|([0-9,]+)\\)*\\)" ;optional arg
yuuji@60 2136 ;"[ \t\n\r]*{[^}]+}")) ;arg braces
yuuji@60 2137 "[ \t\n\r]*{[^}]*}")) ;arg braces
yuuji@51 2138 (not (YaTeX-lookup-table
yuuji@51 2139 (setq word (YaTeX-match-string 1)) 'singlecmd)))
yuuji@46 2140 (progn
yuuji@49 2141 (setq md (match-data))
yuuji@49 2142 (skip-chars-forward "^{")
yuuji@49 2143 (if (<= (point) p) (setq parg (1+ parg)))
yuuji@49 2144 (setq argc
yuuji@51 2145 (or (car (cdr (YaTeX-lookup-table word 'section)))
yuuji@49 2146 argc))
yuuji@82 2147 (put 'YaTeX-on-section-command-p 'argc argc)
yuuji@82 2148 (put 'YaTeX-on-section-command-p 'command argc)
yuuji@53 2149 (while (and (>= (setq argc (1- argc)) 0)
yuuji@53 2150 (progn (skip-chars-forward " \t\n\r")
yuuji@53 2151 (looking-at "{")))
yuuji@49 2152 (forward-list 1)
yuuji@53 2153 (if (<= (point) p) (setq parg (1+ parg))))
yuuji@49 2154 (store-match-data md)
yuuji@53 2155 (setq i (+ 2 grouping))
yuuji@53 2156 (if (and (match-beginning i)
yuuji@53 2157 (>= p (match-beginning i)) (< p (match-end i)))
yuuji@49 2158 -1 ;return -1 if point is on optional arg
yuuji@49 2159 (if (< p (point)) parg))
yuuji@69 2160 )))))
yuuji@5 2161
yuuji@52 2162 (defun YaTeX-on-maketitle-p ()
yuuji@52 2163 "Check if point is on maketitle type commands.
yuuji@52 2164 Call this function after YaTeX-on-section-command-p."
yuuji@52 2165 (let ((p (point)))
yuuji@52 2166 (save-excursion
yuuji@52 2167 (or (= (char-after (point)) ?\\ )
yuuji@52 2168 (progn
yuuji@52 2169 (skip-chars-backward
yuuji@52 2170 (concat "^" YaTeX-ec-regexp) (point-beginning-of-line))
yuuji@52 2171 (or (bobp) (bolp) (backward-char 1))))
yuuji@52 2172 (and (looking-at (concat YaTeX-ec-regexp YaTeX-TeX-token-regexp))
yuuji@52 2173 (<= (match-beginning 0) p)
yuuji@52 2174 (> (match-end 0) p)))))
yuuji@52 2175
yuuji@5 2176 (defun YaTeX-on-begin-end-p ()
yuuji@5 2177 (save-excursion
yuuji@77 2178 (if (and (boundp 'in-leftright-p) in-leftright-p)
yuuji@77 2179 ;; Dirty workaround for YaTeX-goto-corresponding-leftright 2003/3/28
yuuji@77 2180 (let ((md (match-data))) ; for safety
yuuji@77 2181 (if (looking-at YaTeX-ec-regexp)
yuuji@77 2182 nil ; stay here
yuuji@77 2183 (cond
yuuji@77 2184 ((looking-at "\\w") (skip-chars-backward "A-Za-z"))
yuuji@77 2185 ((looking-at "\\.()\\[\\]|") (forward-char -1)))
yuuji@77 2186 (if (equal (char-after (1- (point)))
yuuji@77 2187 (string-to-char YaTeX-ec))
yuuji@77 2188 (forward-char -1))))
yuuji@82 2189 ;(beginning-of-line)
yuuji@82 2190 (if (equal (char-after (point)) ?\\) nil ;stay here
yuuji@82 2191 (skip-chars-backward "^\n\\\\")
yuuji@82 2192 (or (bolp) (forward-char -1))))
yuuji@5 2193 (re-search-forward
yuuji@13 2194 ;;"\\\\begin{\\([^}]+\\)}\\|\\\\end{\\([^}]+\\)}"
yuuji@13 2195 (concat
yuuji@13 2196 (YaTeX-replace-format-args
yuuji@13 2197 (regexp-quote YaTeX-struct-begin)
yuuji@13 2198 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
yuuji@13 2199 "\\|"
yuuji@13 2200 (YaTeX-replace-format-args
yuuji@13 2201 (regexp-quote YaTeX-struct-end)
yuuji@70 2202 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
yuuji@70 2203 "\\|\\("
yuuji@70 2204 YaTeX-ec-regexp ;;"[][()]\\)"
yuuji@412 2205 "[\\]\\[]\\)"
yuuji@70 2206 )
yuuji@69 2207 (point-end-of-line) t)))
yuuji@6 2208
yuuji@5 2209 (defun YaTeX-on-includes-p ()
yuuji@5 2210 (save-excursion
yuuji@5 2211 (beginning-of-line)
yuuji@86 2212 (re-search-forward "\\(\\(include[^}]*\\)\\|\\(input\\)\\){[^}]*}"
yuuji@69 2213 (point-end-of-line) t)))
yuuji@6 2214
yuuji@7 2215 (defun YaTeX-on-comment-p (&optional sw)
yuuji@22 2216 "Return t if current line is commented out.
yuuji@22 2217 Optional argument SW t to treat all `%' lines as comment,
yuuji@7 2218 even if on `%#' notation."
yuuji@7 2219 (save-excursion
yuuji@7 2220 (beginning-of-line)
yuuji@22 2221 (skip-chars-forward "\\s ")
yuuji@69 2222 (looking-at (if sw "%" "%[^#]"))))
yuuji@7 2223
yuuji@5 2224 (defun YaTeX-on-BEGIN-END-p ()
yuuji@5 2225 (save-excursion
yuuji@7 2226 (let ((case-fold-search nil))
yuuji@5 2227 (beginning-of-line)
yuuji@69 2228 (re-search-forward
yuuji@69 2229 "\\(%#BEGIN\\)\\|\\(%#END\\)" (point-end-of-line) t))))
yuuji@6 2230
yuuji@7 2231 (defun YaTeX-goto-corresponding-* (arg)
yuuji@5 2232 "Parse current line and call suitable function."
yuuji@7 2233 (interactive "P")
yuuji@77 2234 (let (mm)
yuuji@77 2235 (cond
yuuji@77 2236 ((YaTeX-goto-corresponding-label arg))
yuuji@77 2237 ((YaTeX-goto-corresponding-environment))
yuuji@77 2238 ((YaTeX-goto-corresponding-file-processor arg))
yuuji@77 2239 ((YaTeX-goto-corresponding-file arg))
yuuji@77 2240 ((YaTeX-goto-corresponding-BEGIN-END))
yuuji@77 2241 ((and (setq mm (YaTeX-in-math-mode-p))
yuuji@77 2242 (YaTeX-goto-corresponding-leftright)))
yuuji@82 2243 ((and ;;mm YaTeX-use-AMS-LaTeX
yuuji@77 2244 (YaTeX-goto-corresponding-paren)))
yuuji@77 2245 ;;((and (string-match
yuuji@77 2246 ;; YaTeX-equation-env-regexp ;to delay loading
yuuji@77 2247 ;; (or (YaTeX-inner-environment t) "document"))
yuuji@77 2248 ;; (YaTeX-goto-corresponding-leftright)))
yuuji@350 2249 ((YaTeX-goto-corresponding-viewer))
yuuji@77 2250 (t (message "I don't know where to go.")))))
yuuji@5 2251
yuuji@51 2252 (defun YaTeX-goto-corresponding-*-other-window (arg)
yuuji@51 2253 "Parse current line and call suitable function."
yuuji@51 2254 (interactive "P")
yuuji@51 2255 (cond
yuuji@51 2256 ((YaTeX-goto-corresponding-label arg t))
yuuji@51 2257 ;;((YaTeX-goto-corresponding-environment))
yuuji@51 2258 ((YaTeX-goto-corresponding-file t))
yuuji@51 2259 ;;((YaTeX-goto-corresponding-BEGIN-END))
yuuji@69 2260 (t (message "I don't know where to go."))))
yuuji@51 2261
yuuji@5 2262 (defun YaTeX-comment-region (alt-prefix)
yuuji@22 2263 "Comment out region by '%'.
yuuji@22 2264 If you call this function on the 'begin{}' or 'end{}' line,
yuuji@22 2265 it comments out whole environment"
yuuji@5 2266 (interactive "P")
yuuji@4 2267 (if (not (YaTeX-on-begin-end-p))
yuuji@482 2268 (YaTeX-comment-region-sub
yuuji@5 2269 (if alt-prefix
yuuji@394 2270 (read-string-with-history "Insert prefix: ")
yuuji@5 2271 YaTeX-comment-prefix))
yuuji@482 2272 (YaTeX-comment-uncomment-env 'YaTeX-comment-region-sub)))
yuuji@4 2273
yuuji@5 2274 (defun YaTeX-uncomment-region (alt-prefix)
yuuji@4 2275 "Uncomment out region by '%'."
yuuji@5 2276 (interactive "P")
yuuji@4 2277 (if (not (YaTeX-on-begin-end-p))
yuuji@482 2278 (YaTeX-uncomment-region-sub
yuuji@394 2279 (if alt-prefix (read-string-with-history "Remove prefix: ")
yuuji@11 2280 YaTeX-comment-prefix)
yuuji@49 2281 (region-beginning) (region-end) YaTeX-uncomment-once)
yuuji@482 2282 (YaTeX-comment-uncomment-env 'YaTeX-uncomment-region-sub)))
yuuji@4 2283
yuuji@4 2284 (defun YaTeX-comment-uncomment-env (func)
yuuji@4 2285 "Comment or uncomment out one LaTeX environment switching function by FUNC."
yuuji@482 2286 (let (beg beg2 (p (point)))
yuuji@49 2287 (save-excursion
yuuji@482 2288 (beginning-of-line)
yuuji@482 2289 (setq beg (point))
yuuji@482 2290 (save-match-data
yuuji@482 2291 (while (and (not (eobp))
yuuji@482 2292 (not (eolp))
yuuji@482 2293 (looking-at YaTeX-comment-prefix))
yuuji@482 2294 (goto-char (match-end 0))))
yuuji@482 2295 (setq beg2 (point))
yuuji@482 2296 (YaTeX-goto-corresponding-environment)
yuuji@482 2297 (beginning-of-line)
yuuji@482 2298 (if (> p (point)) (setq beg (1+ beg2)) (forward-char 1))
yuuji@482 2299 (funcall func YaTeX-comment-prefix beg (point) YaTeX-uncomment-once)))
yuuji@45 2300 (message "%sommented out current environment."
yuuji@482 2301 (if (string-match "uncom" (symbol-name func)) "Un-c" "C")))
yuuji@4 2302
yuuji@3 2303 (defun YaTeX-comment-paragraph ()
yuuji@3 2304 "Comment out current paragraph."
yuuji@3 2305 (interactive)
yuuji@3 2306 (save-excursion
yuuji@7 2307 (cond
yuuji@7 2308 ((YaTeX-on-begin-end-p)
yuuji@7 2309 (beginning-of-line)
yuuji@7 2310 (insert YaTeX-comment-prefix)
yuuji@7 2311 (YaTeX-goto-corresponding-environment)
yuuji@7 2312 (beginning-of-line)
yuuji@7 2313 (insert YaTeX-comment-prefix))
yuuji@7 2314 ((YaTeX-on-comment-p)
yuuji@7 2315 (message "Already commented out."))
yuuji@7 2316 (t
yuuji@4 2317 (mark-paragraph)
yuuji@7 2318 (if (looking-at paragraph-separate) (forward-line 1))
yuuji@482 2319 (YaTeX-comment-region-sub "%")))))
yuuji@3 2320
yuuji@3 2321 (defun YaTeX-uncomment-paragraph ()
yuuji@3 2322 "Uncomment current paragraph."
yuuji@3 2323 (interactive)
yuuji@3 2324 (save-excursion
yuuji@4 2325 (if (YaTeX-on-begin-end-p)
yuuji@68 2326 (let ((p (point-marker)))
yuuji@22 2327 (YaTeX-goto-corresponding-environment)
yuuji@11 2328 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
yuuji@68 2329 (goto-char p)
yuuji@68 2330 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
yuuji@68 2331 (set-marker p nil))
yuuji@7 2332 (if (YaTeX-on-comment-p)
yuuji@7 2333 (let*((fill-prefix "")
yuuji@7 2334 ;;append `^%' to head of paragraph delimiter.
yuuji@7 2335 (paragraph-start
yuuji@7 2336 (concat
yuuji@61 2337 "^$\\|^%\\(" YaTeX-paragraph-separate "\\)"))
yuuji@49 2338 (paragraph-separate paragraph-start))
yuuji@7 2339 (mark-paragraph)
yuuji@7 2340 (if (not (bobp)) (forward-line 1))
yuuji@482 2341 (YaTeX-uncomment-region-sub "%" nil nil YaTeX-uncomment-once))
yuuji@69 2342 (message "This line is not a comment line.")))))
yuuji@4 2343
yuuji@4 2344 (defun YaTeX-remove-prefix (prefix &optional once)
yuuji@7 2345 "Remove prefix on current line as far as prefix detected. But
yuuji@4 2346 optional argument ONCE makes deletion once."
yuuji@4 2347 (interactive "sPrefix:")
yuuji@4 2348 (beginning-of-line)
yuuji@4 2349 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
yuuji@4 2350 (replace-match "")
yuuji@69 2351 (if once (end-of-line))))
yuuji@3 2352
yuuji@22 2353 (defun YaTeX-kill-some-pairs (predicate gofunc kill-contents)
yuuji@22 2354 "Kill some matching pair.
yuuji@64 2355 This function assumes that pairs occupy whole of each line where they resid."
yuuji@7 2356 (if (not (funcall predicate)) nil
yuuji@64 2357 (let ((b1 (match-beginning 0)) (e1 (match-end 0))
yuuji@64 2358 b2 e2)
yuuji@7 2359 (save-excursion
yuuji@7 2360 (funcall gofunc)
yuuji@64 2361 (funcall predicate) ;get match data
yuuji@64 2362 (if (< (point) e1) ;if currently on begin-line
yuuji@64 2363 (progn
yuuji@64 2364 (setq b2 b1 e2 e1
yuuji@64 2365 b1 (match-beginning 0) e1 (match-end 0))
yuuji@64 2366 (goto-char e2)) ;goto end-line's end
yuuji@64 2367 (setq b2 (match-beginning 0)
yuuji@64 2368 e2 (match-end 0))
yuuji@64 2369 (goto-char e2)) ;now e2 has surely end-line's end
yuuji@64 2370 (skip-chars-forward " \t")
yuuji@64 2371 (and (eolp)
yuuji@64 2372 (not (eobp))
yuuji@64 2373 (setq e2 (1+ (point))))
yuuji@64 2374 (if (not kill-contents)
yuuji@64 2375 (kill-region
yuuji@64 2376 (progn
yuuji@64 2377 (goto-char b2)
yuuji@68 2378 (skip-chars-backward " \t%")
yuuji@64 2379 (if (bolp) (point) b2))
yuuji@64 2380 e2))
yuuji@64 2381 (goto-char b1)
yuuji@68 2382 (skip-chars-backward " \t%")
yuuji@64 2383 (if (not kill-contents)
yuuji@64 2384 (progn
yuuji@64 2385 (kill-append
yuuji@64 2386 (buffer-substring
yuuji@64 2387 (setq b1 (if (bolp) (point) b1))
yuuji@64 2388 (setq e1
yuuji@64 2389 (progn
yuuji@64 2390 (goto-char e1)
yuuji@64 2391 (while (looking-at "{\\| \t")
yuuji@64 2392 (forward-list 1))
yuuji@64 2393 (skip-chars-forward " \t")
yuuji@64 2394 (if (and (eolp) (not (eobp)))
yuuji@64 2395 (1+ (point))
yuuji@64 2396 (point)))))
yuuji@64 2397 t)
yuuji@64 2398 (delete-region b1 e1))
yuuji@64 2399 (kill-region
yuuji@64 2400 (if (bolp) (point) b1)
yuuji@64 2401 e2)))
yuuji@69 2402 t)))
yuuji@5 2403
yuuji@22 2404 (defun YaTeX-kill-section-command (point kill-all)
yuuji@82 2405 "Kill section-type command at POINT leaving its last argument.
yuuji@82 2406 Non-nil for the second argument kill its last argument too."
yuuji@82 2407 (let ((cmd (get 'YaTeX-on-section-command-p 'command))
yuuji@82 2408 (argc (get 'YaTeX-on-section-command-p 'argc))
yuuji@82 2409 beg (end (make-marker)))
yuuji@14 2410 (save-excursion
yuuji@22 2411 (goto-char point)
yuuji@22 2412 (or (looking-at YaTeX-ec-regexp)
yuuji@22 2413 (progn
yuuji@22 2414 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
yuuji@22 2415 (forward-char -1)))
yuuji@22 2416 (setq beg (point))
yuuji@22 2417 (skip-chars-forward "^{")
yuuji@82 2418 (while (> (setq argc (1- argc)) 0)
yuuji@82 2419 (skip-chars-forward "^{")
yuuji@82 2420 (forward-list 1))
yuuji@82 2421 (kill-region beg (point))
yuuji@22 2422 (forward-list 1)
yuuji@22 2423 (set-marker end (point))
yuuji@82 2424 (if kill-all
yuuji@82 2425 (progn
yuuji@82 2426 (kill-append (buffer-substring beg end) nil)
yuuji@82 2427 (delete-region beg end))
yuuji@22 2428 (goto-char beg)
yuuji@82 2429 (kill-append
yuuji@82 2430 (buffer-substring
yuuji@82 2431 (point) (progn (skip-chars-forward "^{" end) (1+ (point))))
yuuji@82 2432 nil)
yuuji@82 2433 (delete-region beg (1+ (point)))
yuuji@22 2434 (goto-char end)
yuuji@68 2435 (set-marker end nil)
yuuji@68 2436 (kill-append (buffer-substring (point) (1- (point))) nil)
yuuji@69 2437 (delete-backward-char 1)))))
yuuji@14 2438
yuuji@22 2439 (defun YaTeX-kill-paren (kill-contents)
yuuji@22 2440 "Kill parentheses leaving its contents.
yuuji@22 2441 But kill its contents if the argument KILL-CONTENTS is non-nil."
yuuji@79 2442 (interactive "P")
yuuji@79 2443 (let (p bsl (backslash-syntax (char-to-string (char-syntax ?\\)))
yuuji@79 2444 (md (match-data)))
yuuji@79 2445 (unwind-protect
yuuji@79 2446 (save-excursion
yuuji@79 2447 (modify-syntax-entry ?\\ " ")
yuuji@79 2448 (if (looking-at "\\s(\\|\\(\\s)\\)")
yuuji@79 2449 (progn
yuuji@79 2450 (if (match-beginning 1)
yuuji@79 2451 (up-list -1))
yuuji@79 2452 (if (and (> (point) (point-min))
yuuji@79 2453 (= (char-after (1- (point))) ?\\ ))
yuuji@79 2454 (setq p (1- (point)) bsl t)
yuuji@79 2455 (setq p (point)))
yuuji@79 2456 (forward-list 1)
yuuji@79 2457 ;(YaTeX-goto-open-paren t)
yuuji@79 2458 (if kill-contents (delete-region p (point))
yuuji@79 2459 (backward-delete-char 1)
yuuji@79 2460 (cond
yuuji@79 2461 ((save-excursion
yuuji@79 2462 (forward-char -2)
yuuji@79 2463 (looking-at (concat YaTeX-ec-regexp "/")))
yuuji@79 2464 (backward-delete-char 2))
yuuji@79 2465 ((= (char-after (1- (point))) ?\\)
yuuji@79 2466 (backward-delete-char 1)))
yuuji@79 2467 (goto-char p)
yuuji@79 2468 (if (looking-at
yuuji@79 2469 (concat "{" YaTeX-ec-regexp
yuuji@79 2470 YaTeX-command-token-regexp "+"
yuuji@79 2471 "\\s +"))
yuuji@79 2472 (delete-region (point) (match-end 0))
yuuji@79 2473 (delete-char 1)
yuuji@79 2474 (if bsl (delete-char 1))))
yuuji@79 2475 t)))
yuuji@79 2476 (modify-syntax-entry ?\\ backslash-syntax)
yuuji@79 2477 (store-match-data md))))
yuuji@14 2478
yuuji@22 2479 (defvar YaTeX-read-environment-history nil "Holds history of environments.")
yuuji@22 2480 (put 'YaTeX-read-environment-history 'no-default t)
yuuji@22 2481 (defun YaTeX-read-environment (prompt &optional predicate must-match initial)
yuuji@22 2482 "Read a LaTeX environment name with completion."
yuuji@49 2483 (YaTeX-sync-local-table 'tmp-env-table)
yuuji@51 2484 (completing-read-with-history
yuuji@51 2485 prompt
yuuji@51 2486 (append tmp-env-table user-env-table env-table)
yuuji@51 2487 predicate must-match initial
yuuji@69 2488 'YaTeX-read-environment-history))
yuuji@22 2489
yuuji@22 2490 (defvar YaTeX-read-section-history nil "Holds history of section-types.")
yuuji@22 2491 (put 'YaTeX-read-section-history 'no-default t)
yuuji@22 2492 (defun YaTeX-read-section (prompt &optional predicate initial)
yuuji@22 2493 "Read a LaTeX section-type command with completion."
yuuji@49 2494 (YaTeX-sync-local-table 'tmp-section-table)
yuuji@51 2495 (let ((minibuffer-completion-table
yuuji@22 2496 (append tmp-section-table user-section-table section-table)))
yuuji@51 2497 (read-from-minibuffer-with-history
yuuji@51 2498 prompt initial YaTeX-section-completion-map nil
yuuji@69 2499 'YaTeX-read-section-history)))
yuuji@22 2500
yuuji@22 2501 (defun YaTeX-read-section-with-overview ()
yuuji@22 2502 "Read sectioning command with overview.
yuuji@119 2503 This function refers a local variable `source-window' in YaTeX-make-section,
yuuji@119 2504 because this function is called with no argument."
yuuji@22 2505 (interactive)
yuuji@52 2506 (require 'yatexsec) ;some case needs this
yuuji@22 2507 (if (> (minibuffer-depth) 1)
yuuji@22 2508 (error "Too many minibuffer levels for overview."))
yuuji@64 2509 (let ((sw (selected-window))
yuuji@64 2510 (minibuffer-max-depth nil) ; for XEmacs20
yuuji@64 2511 (enable-recursive-minibuffers t) sect)
yuuji@22 2512 (unwind-protect
yuuji@22 2513 (progn
yuuji@22 2514 (select-window source-window)
yuuji@22 2515 (setq sect (YaTeX-read-section-in-minibuffer
yuuji@22 2516 "Sectioning(Up=C-p, Down=C-n, Help=?): "
yuuji@22 2517 YaTeX-sectioning-level (YaTeX-section-overview))))
yuuji@22 2518 (select-window sw))
yuuji@72 2519 (YaTeX-minibuffer-erase)
yuuji@22 2520 (insert sect)
yuuji@69 2521 (exit-minibuffer)))
yuuji@22 2522
yuuji@51 2523 (defvar YaTeX-read-fontsize-history nil "Holds history of font designator.")
yuuji@51 2524 (put 'YaTeX-read-fontsize-history 'no-default t)
yuuji@22 2525 (defun YaTeX-read-fontsize (prompt &optional predicate must-match initial)
yuuji@22 2526 "Read a LaTeX font changing command with completion."
yuuji@49 2527 (YaTeX-sync-local-table 'tmp-fontsize-table)
yuuji@51 2528 (completing-read-with-history
yuuji@22 2529 prompt (append tmp-fontsize-table user-fontsize-table fontsize-table)
yuuji@69 2530 predicate must-match initial 'YaTeX-read-fontsize-history))
yuuji@5 2531
yuuji@5 2532 (defun YaTeX-change-environment ()
yuuji@5 2533 "Change the name of environment."
yuuji@5 2534 (interactive)
yuuji@5 2535 (if (not (YaTeX-on-begin-end-p)) nil
yuuji@5 2536 (save-excursion
yuuji@179 2537 (let (p env newenv (m1 (match-beginning 1)) (m2 (match-beginning 2)))
yuuji@165 2538 (setq env (if m1 (YaTeX-buffer-substring m1 (match-end 1))
yuuji@165 2539 (YaTeX-buffer-substring m2 (match-end 2))))
yuuji@11 2540 (goto-char (match-beginning 0))
yuuji@5 2541 (set-mark-command nil)
yuuji@5 2542 (YaTeX-goto-corresponding-environment)
yuuji@5 2543 (setq newenv (YaTeX-read-environment
yuuji@5 2544 (format "Change environment `%s' to: " env)))
yuuji@13 2545 (cond
yuuji@13 2546 ((string= newenv "") (message "Change environment cancelled."))
yuuji@13 2547 ((string= newenv env) (message "No need to change."))
yuuji@13 2548 (t
yuuji@5 2549 (search-forward (concat "{" env) (point-end-of-line) t)
yuuji@68 2550 (replace-match (concat "{" newenv) t)
yuuji@5 2551 (exchange-point-and-mark)
yuuji@5 2552 (search-forward (concat "{" env) (point-end-of-line) t)
yuuji@68 2553 (replace-match (concat "{" newenv) t)))
yuuji@69 2554 t))))
yuuji@5 2555
yuuji@22 2556 (defun YaTeX-change-section ()
yuuji@22 2557 "Change section-type command."
yuuji@5 2558 (interactive)
yuuji@49 2559 (let*((where (YaTeX-on-section-command-p YaTeX-command-token-regexp))
yuuji@70 2560 (p (point)) (cmd (YaTeX-match-string 1))
yuuji@70 2561 (beg (make-marker)) (end (make-marker)) old new)
yuuji@49 2562 (if (null where) nil
yuuji@70 2563 (unwind-protect
yuuji@119 2564 (let ((source-window (selected-window)))
yuuji@70 2565 (cond
yuuji@70 2566 ((equal where 0);;if point is on section command
yuuji@70 2567 (set-marker beg (match-beginning 1))
yuuji@70 2568 (set-marker end (match-end 1))
yuuji@70 2569 (goto-char beg) ;beginning of the command
yuuji@70 2570 (setq new (YaTeX-read-section
yuuji@169 2571 (format "Change `%s' to: " cmd) nil)
yuuji@169 2572 old cmd))
yuuji@49 2573
yuuji@70 2574 ((= where -1);;if point is on a optional parameter
yuuji@70 2575 (set-marker beg (match-beginning 2))
yuuji@70 2576 (skip-chars-forward "^{")
yuuji@70 2577 (set-marker end (point))
yuuji@70 2578 (goto-char p)
yuuji@70 2579 (setq new
yuuji@70 2580 (if (fboundp (intern-soft (concat YaTeX-addin-prefix cmd)))
yuuji@70 2581 (YaTeX-addin cmd)
yuuji@70 2582 (concat "["
yuuji@169 2583 (read-string
yuuji@169 2584 (format "Change `%s' to: "
yuuji@169 2585 (setq old (YaTeX-buffer-substring
yuuji@169 2586 (1+ beg) (1- end)))))
yuuji@70 2587 "]"))))
yuuji@49 2588
yuuji@70 2589 ((> where 0);;if point is in arguments' braces
yuuji@70 2590 (or (looking-at "{")
yuuji@70 2591 (progn (skip-chars-backward "^{") (forward-char -1)))
yuuji@70 2592 (set-marker beg (1+ (point)))
yuuji@70 2593 (forward-list 1)
yuuji@70 2594 (forward-char -1)
yuuji@70 2595 (set-marker end (point))
yuuji@165 2596 (setq old (YaTeX-buffer-substring beg end))
yuuji@70 2597 (goto-char p)
yuuji@70 2598 (if (> (length old) 40)
yuuji@70 2599 (setq old (concat (substring old 0 12) "..."
yuuji@70 2600 (substring old -12))))
yuuji@70 2601 (setq new
yuuji@70 2602 (if (intern-soft (concat "YaTeX::" cmd))
yuuji@70 2603 (funcall (intern-soft (concat "YaTeX::" cmd)) where)
yuuji@70 2604 (read-string (format "Change `%s' to: " old)))))
yuuji@70 2605 ) ;cond
yuuji@169 2606 (if (string= old new)
yuuji@169 2607 nil ;do not replace
yuuji@169 2608 (delete-region beg end)
yuuji@169 2609 (goto-char beg)
yuuji@169 2610 (insert-before-markers new)))
yuuji@70 2611 (set-marker beg nil)
yuuji@70 2612 (set-marker end nil))
yuuji@49 2613 ;;(goto-char (marker-position p))
yuuji@69 2614 new)))
yuuji@49 2615
yuuji@49 2616 (defun YaTeX-change-fontsize ()
yuuji@49 2617 "Change large-type command."
yuuji@49 2618 (let ((lt (append tmp-fontsize-table user-fontsize-table fontsize-table))
yuuji@49 2619 (p (point)) large old new beg end)
yuuji@49 2620 ;;(and (looking-at "}") (up-list -1))
yuuji@49 2621 ;;(and (looking-at "{") (forward-char 1))
yuuji@49 2622 ;;Is above convenient?
yuuji@49 2623 (save-excursion
yuuji@49 2624 (or (looking-at YaTeX-ec-regexp)
yuuji@49 2625 (progn
yuuji@49 2626 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
yuuji@49 2627 (forward-char -1)))
yuuji@49 2628 (cond
yuuji@49 2629 ((and
yuuji@49 2630 (looking-at
yuuji@49 2631 (concat YaTeX-ec-regexp "\\(" YaTeX-TeX-token-regexp "\\)"))
yuuji@49 2632 (< p (match-end 0))
yuuji@49 2633 (assoc (setq old (YaTeX-match-string 1)) lt))
yuuji@49 2634 (goto-char p)
yuuji@49 2635 (setq beg (match-beginning 1) end (match-end 1) ;save match position
yuuji@49 2636 new (completing-read
yuuji@49 2637 (format "Change font/size `%s' to : " old) lt))
yuuji@22 2638 (delete-region beg end)
yuuji@49 2639 (goto-char beg)
yuuji@22 2640 (insert-before-markers new)
yuuji@49 2641 new)
yuuji@49 2642 (t nil)
yuuji@69 2643 ))))
yuuji@22 2644
yuuji@52 2645 (defun YaTeX-change-math-image ()
yuuji@52 2646 "Change with image completion."
yuuji@52 2647 (let (maketitle memberp beg end)
yuuji@52 2648 (if (and (YaTeX-on-maketitle-p)
yuuji@52 2649 (progn
yuuji@52 2650 (setq maketitle (substring (YaTeX-match-string 0) 1))
yuuji@52 2651 (setq memberp (YaTeX-math-member-p maketitle))))
yuuji@291 2652 (let*((last-command-char (string-to-char (car memberp)))
yuuji@291 2653 (last-command-event last-command-char))
yuuji@52 2654 (setq beg (match-beginning 0) end (match-end 0))
yuuji@52 2655 (delete-region beg end)
yuuji@52 2656 (YaTeX-math-insert-sequence t (cdr memberp))))))
yuuji@52 2657
yuuji@22 2658 (defun YaTeX-kill-* (&optional arg)
yuuji@22 2659 "Parse current line and call suitable function.
yuuji@22 2660 Non-nil for ARG kills its contents too."
yuuji@22 2661 (interactive "P")
yuuji@5 2662 (cond
yuuji@5 2663 ((YaTeX-kill-some-pairs 'YaTeX-on-begin-end-p
yuuji@22 2664 'YaTeX-goto-corresponding-environment arg))
yuuji@5 2665 ((YaTeX-kill-some-pairs 'YaTeX-on-BEGIN-END-p
yuuji@22 2666 'YaTeX-goto-corresponding-BEGIN-END arg))
yuuji@32 2667 ((YaTeX-on-section-command-p YaTeX-command-token-regexp);on any command
yuuji@22 2668 (YaTeX-kill-section-command (match-beginning 0) arg))
yuuji@22 2669 ((YaTeX-kill-paren arg))
yuuji@407 2670 ((and (fboundp 'overlays-at)
yuuji@407 2671 (member YaTeX-on-the-fly-overlay (overlays-at (point))))
yuuji@407 2672 (YaTeX-on-the-fly-cancel))
yuuji@69 2673 (t (message "I don't know what to kill."))))
yuuji@5 2674
yuuji@5 2675 (defun YaTeX-change-* ()
yuuji@5 2676 "Parse current line and call suitable function."
yuuji@5 2677 (interactive)
yuuji@5 2678 (cond
yuuji@82 2679 ((YaTeX-change-parentheses))
yuuji@5 2680 ((YaTeX-change-environment))
yuuji@22 2681 ((YaTeX-change-section))
yuuji@49 2682 ((YaTeX-change-fontsize))
yuuji@52 2683 ((YaTeX-change-math-image))
yuuji@69 2684 (t (message "I don't know what to change."))))
yuuji@5 2685
yuuji@7 2686 ;;;
yuuji@48 2687 ;Check availability of add-in functions
yuuji@7 2688 ;;;
yuuji@7 2689 (cond
yuuji@48 2690 ((featurep 'yatexadd) nil) ;Already provided.
yuuji@48 2691 ((progn (load "yatexadd" t) (featurep 'yatexadd)) nil)
yuuji@7 2692 (t (message "YaTeX add-in functions not supplied.")))
yuuji@7 2693
yuuji@5 2694 (defun YaTeX-addin (name)
yuuji@5 2695 "Check availability of addin function and call it if exists."
yuuji@7 2696 (if (and (not (get 'YaTeX-generate 'disabled))
yuuji@57 2697 (intern-soft (concat YaTeX-addin-prefix name))
yuuji@57 2698 (fboundp (intern-soft (concat YaTeX-addin-prefix name))))
yuuji@57 2699 (let ((s (funcall (intern (concat YaTeX-addin-prefix name)))))
yuuji@7 2700 (if (stringp s) s ""))
yuuji@69 2701 "")) ;Add in function is not bound.
yuuji@69 2702
yuuji@7 2703
yuuji@22 2704 (defun YaTeX-on-item-p (&optional point)
yuuji@22 2705 "Return t if POINT (default is (point)) is on \\item."
yuuji@22 2706 (let ((p (or point (point))))
yuuji@22 2707 (save-excursion
yuuji@22 2708 (goto-char p)
yuuji@22 2709 (end-of-line)
yuuji@22 2710 (setq p (point))
yuuji@22 2711 (re-search-backward YaTeX-paragraph-delimiter nil t)
yuuji@69 2712 (re-search-forward YaTeX-item-regexp p t))))
yuuji@22 2713
yuuji@49 2714 (defun YaTeX-in-verb-p (&optional point)
yuuji@49 2715 "Check if POINT is in verb or verb*. Default of POINT is (point)."
yuuji@49 2716 (setq point (or point (point)))
yuuji@7 2717 (save-excursion
yuuji@70 2718 (let ((md (match-data)))
yuuji@70 2719 (goto-char point)
yuuji@70 2720 (unwind-protect
yuuji@70 2721 (if (not (re-search-backward
yuuji@70 2722 (concat YaTeX-ec-regexp
yuuji@70 2723 "\\(" YaTeX-verb-regexp "\\)"
yuuji@70 2724 "\\([^-A-Za-z_*]\\)")
yuuji@70 2725 (point-beginning-of-line) t))
yuuji@70 2726 nil
yuuji@70 2727 (goto-char (match-end 2))
yuuji@70 2728 (skip-chars-forward
yuuji@165 2729 (concat "^" (YaTeX-buffer-substring
yuuji@165 2730 (match-beginning 2) (match-end 2))))
yuuji@70 2731 (and (< (match-beginning 2) point) (< (1- point) (point))))
yuuji@70 2732 (store-match-data md)))))
yuuji@49 2733
yuuji@49 2734 (defun YaTeX-literal-p (&optional point)
yuuji@49 2735 "Check if POINT is in verb or verb* or verbatime environment family.
yuuji@49 2736 Default of POINT is (point)."
yuuji@70 2737 (let ((md (match-data)))
yuuji@70 2738 (unwind-protect
yuuji@70 2739 (cond
yuuji@70 2740 ((equal YaTeX-ec "\\") ;maybe LaTeX
yuuji@70 2741 (save-excursion
yuuji@70 2742 (and point (goto-char point))
yuuji@70 2743 (or (YaTeX-in-verb-p (point))
yuuji@70 2744 (and (not (looking-at "\\\\end{verb"))
yuuji@70 2745 (YaTeX-quick-in-environment-p
yuuji@70 2746 YaTeX-verbatim-environments))))))
yuuji@70 2747 (store-match-data md))))
yuuji@5 2748
yuuji@22 2749 ;; Filling \item
yuuji@46 2750 (defun YaTeX-remove-trailing-comment (start end)
yuuji@46 2751 "Remove trailing comment from START to end."
yuuji@46 2752 (save-excursion
yuuji@60 2753 (let ((trcom (concat YaTeX-comment-prefix "$")))
yuuji@46 2754 (goto-char start)
yuuji@46 2755 (while (re-search-forward trcom end t)
yuuji@54 2756 (if (/= (char-after (1- (match-beginning 0))) ?\\ )
yuuji@69 2757 (replace-match "\\1"))))))
yuuji@5 2758
yuuji@82 2759 (defvar YaTeX-itemize-withlabel-max-indent-depth 8)
yuuji@58 2760 (defun YaTeX-get-item-info (&optional recent thisenv)
yuuji@51 2761 "Return the list of the beginning of \\item and column of its item.
yuuji@53 2762 If it seems to be outside of itemizing environment, just return nil.
yuuji@58 2763 Non-nil for optional argument RECENT refers recent \\item.
yuuji@58 2764 Optional second argument THISENV omits calling YaTeX-inner-environment."
yuuji@22 2765 (save-excursion
yuuji@82 2766 (let* ((p (point)) env e0 c cc md
yuuji@58 2767 (bndry (and (setq env (or thisenv (YaTeX-inner-environment t)))
yuuji@82 2768 (get 'YaTeX-inner-environment 'point))))
yuuji@22 2769 (end-of-line)
yuuji@53 2770 (if (if recent
yuuji@82 2771 (catch 'found
yuuji@82 2772 (while (YaTeX-re-search-active-backward
yuuji@82 2773 YaTeX-item-regexp YaTeX-comment-prefix bndry t)
yuuji@82 2774 (setq md (match-data))
yuuji@82 2775 (YaTeX-inner-environment t)
yuuji@82 2776 (store-match-data md)
yuuji@82 2777 (if (= bndry (get 'YaTeX-inner-environment 'point))
yuuji@82 2778 (throw 'found t))))
yuuji@53 2779 (goto-char bndry)
yuuji@53 2780 (YaTeX-re-search-active-forward
yuuji@53 2781 YaTeX-item-regexp YaTeX-comment-prefix p t))
yuuji@51 2782 (progn
yuuji@53 2783 (goto-char (match-end 0))
yuuji@53 2784 ;(setq c (current-column))
yuuji@58 2785 (if (string-match "desc" env)
yuuji@58 2786 (setq c 6)
yuuji@82 2787 (setq cc (current-column))
yuuji@58 2788 (if (equal (following-char) ?\[) (forward-list 1))
yuuji@82 2789 (if (< (- (current-column) cc)
yuuji@82 2790 YaTeX-itemize-withlabel-max-indent-depth)
yuuji@82 2791 (setq c 0)
yuuji@82 2792 (move-to-column cc)
yuuji@82 2793 (setq c YaTeX-itemize-withlabel-max-indent-depth)))
yuuji@51 2794 (skip-chars-forward " \t" (point-end-of-line))
yuuji@69 2795 (list (point-beginning-of-line) (+ c (current-column))))))))
yuuji@22 2796
yuuji@5 2797 (defun YaTeX-fill-item ()
yuuji@5 2798 "Fill item in itemize environment."
yuuji@5 2799 (interactive)
yuuji@5 2800 (save-excursion
yuuji@51 2801 (let* ((p (point))
yuuji@51 2802 (item-term (concat
yuuji@58 2803 "\\(^[ \t]*$\\)\\|" YaTeX-item-regexp "\\|\\("
yuuji@53 2804 YaTeX-ec-regexp "\\(begin\\|end\\)\\)"))
yuuji@51 2805 ;;This value depends on LaTeX.
yuuji@51 2806 fill-prefix start col
yuuji@53 2807 (info (YaTeX-get-item-info t)))
yuuji@55 2808 (if (null info) nil ;not on \item, do nothing
yuuji@22 2809 (setq start (car info)
yuuji@22 2810 col (car (cdr info)))
yuuji@55 2811 (save-excursion
yuuji@55 2812 (if (re-search-backward "^\\s *$" start t)
yuuji@55 2813 ;;if separated from \item line, isolate this block
yuuji@55 2814 (progn
yuuji@55 2815 (setq start (1+ (match-end 0)))
yuuji@55 2816 (goto-char start)
yuuji@55 2817 (skip-chars-forward " \t")
yuuji@55 2818 (delete-region (point) start) ;is this your favor???
yuuji@55 2819 (indent-to col))))
yuuji@46 2820 (beginning-of-line)
yuuji@46 2821 (if (<= (save-excursion
yuuji@46 2822 (re-search-forward
yuuji@58 2823 (concat "\\\\end{\\|\\\\begin{\\|^[ \t]*$") nil t)
yuuji@46 2824 (match-beginning 0))
yuuji@46 2825 p)
yuuji@51 2826 (progn (message "Not on itemize.") nil)
yuuji@51 2827 (end-of-line)
yuuji@51 2828 (newline)
yuuji@51 2829 (indent-to col)
yuuji@51 2830 (setq fill-prefix
yuuji@165 2831 (YaTeX-buffer-substring (point-beginning-of-line)(point)))
yuuji@51 2832 (beginning-of-line)
yuuji@53 2833 (delete-region (point) (progn (forward-line 1) (point)))
yuuji@51 2834 (re-search-forward item-term nil 1)
yuuji@51 2835 (YaTeX-remove-trailing-comment start (point))
yuuji@51 2836 (beginning-of-line)
yuuji@51 2837 (push-mark (point) t)
yuuji@51 2838 (goto-char start)
yuuji@51 2839 (forward-line 1)
yuuji@51 2840 (while (< (point) (mark))
yuuji@51 2841 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
yuuji@51 2842 (forward-line 1))
yuuji@51 2843 (fill-region-as-paragraph start (mark))
yuuji@51 2844 (if NTT-jTeX
yuuji@51 2845 (while (progn(forward-line -1)(end-of-line) (> (point) start))
yuuji@51 2846 (insert ?%)))
yuuji@69 2847 (pop-mark))))))
yuuji@5 2848
yuuji@51 2849 (defun YaTeX-fill-paragraph (arg)
yuuji@51 2850 "YaTeX adjustment function for fill-paragraph.
yuuji@51 2851 *Protect \\verb from unexpected broken up."
yuuji@51 2852 (interactive "P")
yuuji@51 2853 (cond
yuuji@51 2854 ((not (eq major-mode 'yatex-mode)) (fill-paragraph arg))
yuuji@51 2855 ((YaTeX-quick-in-environment-p YaTeX-fill-inhibit-environments) nil)
yuuji@68 2856 ((YaTeX-in-math-mode-p) nil)
yuuji@51 2857 (t
yuuji@51 2858 (save-excursion
yuuji@82 2859 (let*((verbrex (concat YaTeX-ec-regexp
yuuji@51 2860 "\\(" YaTeX-verb-regexp "\\)" ;match#1
yuuji@51 2861 "\\(.\\).*\\(\\2\\)")) ;match #2 and #3
yuuji@82 2862 (tilderex (concat "\\("
yuuji@82 2863 YaTeX-kanji-regexp "~"
yuuji@82 2864 "\\)" YaTeX-ec-regexp
yuuji@82 2865 "\\|\\("
yuuji@82 2866 "~" YaTeX-kanji-regexp
yuuji@82 2867 "\\)"))
yuuji@82 2868 (p (point)) ii end poslist spacelist lenlist b e n
yuuji@82 2869 (fill-prefix fill-prefix)
yuuji@82 2870 (inenv (or (YaTeX-inner-environment t) "document"))
yuuji@82 2871 (border (get 'YaTeX-inner-environment 'point)))
yuuji@52 2872 (cond
yuuji@52 2873 ((save-excursion (beginning-of-line) ;if point is on the first
yuuji@52 2874 (setq end (point)) ;non-whitespace char
yuuji@52 2875 (skip-chars-forward " \t")
yuuji@52 2876 (equal (point) p))
yuuji@165 2877 (setq fill-prefix (YaTeX-buffer-substring p end)))
yuuji@53 2878 ((and ;;(not YaTeX-emacs-19)
yuuji@82 2879 (string-match YaTeX-itemizing-env-regexp inenv)
yuuji@58 2880 (setq ii (YaTeX-get-item-info)))
yuuji@58 2881 (save-excursion
yuuji@58 2882 (beginning-of-line)
yuuji@58 2883 (indent-to-column (car (cdr ii)))
yuuji@58 2884 (setq fill-prefix
yuuji@165 2885 (YaTeX-buffer-substring (point) (point-beginning-of-line)))
yuuji@58 2886 (delete-region (point) (progn (beginning-of-line) (point))))))
yuuji@82 2887 (cond
yuuji@82 2888 ((string-match "tabular" inenv)
yuuji@82 2889 (let ((b (point-beginning-of-line))
yuuji@82 2890 (e (point-end-of-line)))
yuuji@82 2891 (if (re-search-backward
yuuji@82 2892 "&\\|\\\\\\\\\\|\\\\\\(begin\\|end\\){" border t)
yuuji@82 2893 (setq b (if (match-beginning 1)
yuuji@82 2894 (progn (forward-line 1) (point))
yuuji@82 2895 (point-beginning-of-line))))
yuuji@82 2896 (goto-char p)
yuuji@82 2897 (if (re-search-forward
yuuji@82 2898 "&\\|\\\\\\\\\\|\\\\\\(end\\|begin\\){" nil t)
yuuji@82 2899 (setq e (if (match-beginning 1)
yuuji@82 2900 (progn (forward-line -1)
yuuji@82 2901 (point-end-of-line))
yuuji@82 2902 (match-beginning 0))))
yuuji@82 2903 (set-mark e)
yuuji@82 2904 (goto-char b)))
yuuji@82 2905 (t
yuuji@82 2906 (mark-paragraph)))
yuuji@51 2907 (save-restriction
yuuji@51 2908 (narrow-to-region (region-beginning) (region-end))
yuuji@52 2909 (YaTeX-remove-trailing-comment (point-min) (point-max))
yuuji@82 2910 ;; First, replace spaces in verb to _ temporarily.
yuuji@58 2911 (goto-char (point-min))
yuuji@51 2912 (while (YaTeX-re-search-active-forward
yuuji@58 2913 verbrex YaTeX-comment-prefix (point-max) t)
yuuji@51 2914 (setq end (match-beginning 3))
yuuji@51 2915 (goto-char (match-beginning 2))
yuuji@51 2916 (while (re-search-forward "\\s " end t)
yuuji@51 2917 (setq poslist (cons (make-marker) poslist)
yuuji@82 2918 spacelist (cons (preceding-char) spacelist)
yuuji@82 2919 lenlist (cons 1 lenlist))
yuuji@51 2920 (replace-match "_")
yuuji@51 2921 (set-marker (car poslist) (match-beginning 0))))
yuuji@82 2922 ;; Second, replace "表~\ref{...}" to "\\\ref{...}"
yuuji@82 2923 (goto-char (point-min))
yuuji@82 2924 (while (YaTeX-re-search-active-forward
yuuji@82 2925 tilderex YaTeX-comment-prefix (point-max) t)
yuuji@82 2926 (if (match-beginning 1)
yuuji@82 2927 (setq b (match-beginning 1) e (match-end 1) n 1)
yuuji@82 2928 (setq b (match-beginning 2) e (match-end 2) n 2))
yuuji@82 2929 (setq poslist (cons (make-marker) poslist)
yuuji@82 2930 spacelist (cons (YaTeX-match-string n) spacelist)
yuuji@82 2931 lenlist (cons 2 lenlist))
yuuji@82 2932 (goto-char (match-beginning 0))
yuuji@82 2933 (delete-region (point) e)
yuuji@82 2934 (insert YaTeX-ec YaTeX-ec) ;set-marker should be here
yuuji@82 2935 (set-marker (car poslist) b))
yuuji@58 2936 ;;(fill-paragraph arg)
yuuji@58 2937 (fill-region-as-paragraph (point-min) (point-max) arg)
yuuji@51 2938 (while spacelist
yuuji@68 2939 (goto-char (car poslist))
yuuji@68 2940 (set-marker (car poslist) nil)
yuuji@82 2941 (and (eolp) (skip-chars-forward "\n\t "))
yuuji@82 2942 (delete-char (car lenlist))
yuuji@51 2943 (insert (car spacelist))
yuuji@82 2944 (setq spacelist (cdr spacelist)
yuuji@82 2945 poslist (cdr poslist)
yuuji@82 2946 lenlist (cdr lenlist)))
yuuji@52 2947 (goto-char (point-min))
yuuji@52 2948 (forward-word 1)
yuuji@52 2949 (beginning-of-line)
yuuji@82 2950 (while (re-search-forward "\\\\\\([a-z]*ref\\|cite\\){" nil t)
yuuji@59 2951 (if (< (point-end-of-line)
yuuji@59 2952 (save-excursion (forward-char -1) (forward-list 1) (point)))
yuuji@73 2953 (progn (end-of-line)
yuuji@73 2954 (if (save-excursion
yuuji@73 2955 (backward-word 1)
yuuji@73 2956 (looking-at "[^0-9A-z!-)]"))
yuuji@73 2957 (insert YaTeX-comment-prefix)))))
yuuji@82 2958 ;; Nonbreak space `~'
yuuji@82 2959 (goto-char (point-min))
yuuji@82 2960 (while (YaTeX-re-search-active-forward
yuuji@82 2961 "~\\(\\s *\\)$" YaTeX-comment-prefix (point-max) t)
yuuji@82 2962 (delete-region (match-beginning 1) (match-end 1))
yuuji@82 2963 (insert YaTeX-comment-prefix))
yuuji@59 2964 (goto-char (point-min))
yuuji@73 2965 (if (and NTT-jTeX (looking-at "[ \t]\\|^$"))
yuuji@52 2966 (progn
yuuji@52 2967 (goto-char (point-min))
yuuji@52 2968 (while (not (eobp))
yuuji@52 2969 (end-of-line)
yuuji@52 2970 (or (bolp)
yuuji@52 2971 (save-excursion
yuuji@52 2972 (backward-word 1)
yuuji@73 2973 (looking-at "[0-9A-z!-)]")) ;is not japanese string
yuuji@59 2974 (progn (setq p (point)) (insert YaTeX-comment-prefix)))
yuuji@52 2975 (forward-line 1))
yuuji@52 2976 (goto-char p)
yuuji@61 2977 (if (looking-at "%") (delete-char 1)) ;remove last inserted `%'
yuuji@69 2978 ))))))))
yuuji@51 2979
yuuji@52 2980 (if (fboundp 'YaTeX-saved-indent-new-comment-line) nil
yuuji@52 2981 (fset 'YaTeX-saved-indent-new-comment-line
yuuji@52 2982 (symbol-function 'indent-new-comment-line))
yuuji@52 2983 (fset 'indent-new-comment-line 'YaTeX-indent-new-comment-line))
yuuji@52 2984
yuuji@58 2985 (defun YaTeX-indent-new-comment-line (&optional soft)
yuuji@58 2986 "Tuned `indent-new-comment-line' function for yatex.
yuuji@58 2987 See the documentation of `YaTeX-saved-indent-new-comment-line'."
yuuji@69 2988 (interactive)
yuuji@52 2989 (cond
yuuji@60 2990 ((or (not (memq major-mode '(yatex-mode yahtml-mode)))
yuuji@53 2991 (string-match
yuuji@53 2992 "document"
yuuji@53 2993 (or (and (boundp 'inenv) inenv)
yuuji@53 2994 (or (YaTeX-inner-environment t) "document"))))
yuuji@58 2995 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
yuuji@60 2996 ; ((and (eq major-mode 'yahtml-mode)
yuuji@60 2997 ; (string-match
yuuji@60 2998 ; "^[Pp][Rr][Ee]" (yahtml-inner-environment-but "^[Aa]\\b" t)))
yuuji@60 2999 ; (yahtml-indent-new-commnet-line))
yuuji@61 3000 ((and (eq major-mode 'yatex-mode) ;1997/2/4
yuuji@61 3001 (YaTeX-in-math-mode-p)) nil) ;1996/12/30
yuuji@58 3002 (t (let (fill-prefix)
yuuji@69 3003 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft)))))))
yuuji@51 3004
yuuji@5 3005 (defun YaTeX-fill-* ()
yuuji@5 3006 "Fill paragraph according to its condition."
yuuji@5 3007 (interactive)
yuuji@5 3008 (cond
yuuji@5 3009 ((YaTeX-fill-item))
yuuji@69 3010 ))
yuuji@5 3011
yuuji@22 3012 ;; Accent completion
yuuji@5 3013 (defun YaTeX-read-accent-char (x)
yuuji@5 3014 "Read char in accent braces."
yuuji@5 3015 (let ((c (read-char)))
yuuji@5 3016 (concat
yuuji@5 3017 (if (and (or (= c ?i) (= c ?j))
yuuji@5 3018 (not (string-match (regexp-quote x) "cdb")))
yuuji@5 3019 "\\" "")
yuuji@69 3020 (char-to-string c))))
yuuji@5 3021
yuuji@5 3022 (defun YaTeX-make-accent ()
yuuji@5 3023 "Make accent usage."
yuuji@5 3024 (interactive)
yuuji@5 3025 (message "1:` 2:' 3:^ 4:\" 5:~ 6:= 7:. u v H t c d b")
yuuji@5 3026 (let ((c (read-char))(case-fold-search nil))
yuuji@5 3027 (setq c (cond ((and (> c ?0) (< c ?8))
yuuji@5 3028 (substring "`'^\"~=." (1- (- c ?0)) (- c ?0)))
yuuji@5 3029 ((= c ?h) "H")
yuuji@5 3030 (t (char-to-string c))))
yuuji@5 3031 (if (not (string-match c "`'^\"~=.uvHtcdb")) nil
yuuji@5 3032 (insert "\\" c "{}")
yuuji@5 3033 (backward-char 1)
yuuji@5 3034 (insert (YaTeX-read-accent-char c))
yuuji@5 3035 (if (string= c "t") (insert (YaTeX-read-accent-char c)))
yuuji@69 3036 (forward-char 1))))
yuuji@5 3037
yuuji@359 3038 ;; Field skip in tabular
yuuji@359 3039 (defun YaTeX-forward-field (arg)
yuuji@359 3040 "Move forward to the ARGth next column field of table."
yuuji@359 3041 (interactive "p")
yuuji@359 3042 (if (< arg 0)
yuuji@359 3043 (YaTeX-backward-field (- arg))
yuuji@359 3044 (let ((ep (save-excursion (YaTeX-end-of-environment) (point)))
yuuji@359 3045 (wc (car (YaTeX-array-what-column-internal))))
yuuji@359 3046 (while (>= (setq arg (1- arg)) 0)
yuuji@359 3047 (skip-chars-forward "^&\\\\")
yuuji@359 3048 (while (and (not (eobp))
yuuji@359 3049 (> ep (point))
yuuji@359 3050 (looking-at "\\&\\|\\\\")
yuuji@359 3051 (= wc (car (YaTeX-array-what-column-internal))))
yuuji@362 3052 (skip-chars-forward "&" ep)
yuuji@362 3053 (while (looking-at "[\n\t ]+\\|\\\\\\\\\\|\\\\.line\\>")
yuuji@362 3054 (goto-char (match-end 0))
yuuji@362 3055 ))))))
yuuji@359 3056
yuuji@359 3057 (defun YaTeX-backward-field (arg)
yuuji@359 3058 "Move backward to the ARGth next column field of table."
yuuji@359 3059 (interactive "p")
yuuji@359 3060 (if (< arg 0)
yuuji@359 3061 (YaTeX-forward-field (- arg))
yuuji@359 3062 (let ((bp (save-excursion
yuuji@359 3063 (YaTeX-beginning-of-environment)
yuuji@359 3064 (point-end-of-line)))
yuuji@359 3065 (wc (car (YaTeX-array-what-column-internal))))
yuuji@359 3066 (while (>= (setq arg (1- arg)) 0)
yuuji@359 3067 (skip-chars-backward "^&\\\\" bp)
yuuji@359 3068 (while (and (not (bobp))
yuuji@359 3069 (< bp (point))
yuuji@359 3070 (memq (preceding-char) '(?& ?\\))
yuuji@359 3071 (= wc (car (YaTeX-array-what-column-internal))))
yuuji@359 3072 (skip-chars-backward "&\\\\" bp)
yuuji@359 3073 (skip-chars-backward "\n\t " bp))
yuuji@359 3074 (if (eolp) (skip-chars-forward "^&\\\\"))))))
yuuji@359 3075
yuuji@22 3076 ;; Indentation
yuuji@22 3077 (defun YaTeX-current-indentation ()
yuuji@22 3078 "Return the indentation of current environment."
yuuji@22 3079 (save-excursion
yuuji@53 3080 ;;(beginning-of-line)
yuuji@53 3081 (if (YaTeX-beginning-of-environment t)
yuuji@53 3082 (goto-char (get 'YaTeX-inner-environment 'point))
yuuji@53 3083 (forward-line -1)
yuuji@53 3084 (beginning-of-line)
yuuji@53 3085 (skip-chars-forward " \t"))
yuuji@69 3086 (current-column)))
yuuji@22 3087
yuuji@53 3088 (defun YaTeX-previous-line-indentation ()
yuuji@53 3089 (save-excursion
yuuji@53 3090 (forward-line -1)
yuuji@53 3091 (skip-chars-forward " \t")
yuuji@53 3092 (current-column)))
yuuji@53 3093
yuuji@82 3094 (defvar YaTeX-noindent-env-regexp "verbatim\\*?\\|alltt"
yuuji@82 3095 "*Regexp of environment names that should begin with no indentation.
yuuji@82 3096 All verbatime-like environment name should match with.")
yuuji@22 3097 (defun YaTeX-indent-line ()
yuuji@22 3098 "Indent corrent line referrin current environment."
yuuji@22 3099 (interactive)
yuuji@48 3100 (let ((indent-relative
yuuji@48 3101 (function
yuuji@51 3102 (lambda (&optional additional)
yuuji@48 3103 (YaTeX-reindent
yuuji@51 3104 (+ (YaTeX-current-indentation)
yuuji@51 3105 (or additional 0)
yuuji@51 3106 YaTeX-environment-indent)))))
yuuji@82 3107 sect depth iteminfo (p (point)) pp (peol (point-end-of-line)) begend
yuuji@52 3108 ;;inenv below is sometimes defined in YaTeX-indent-new-comment-line
yuuji@52 3109 (inenv (or (and (boundp 'inenv) inenv) (YaTeX-inner-environment t))))
yuuji@52 3110 ;;(if NTT-jTeX ;;Do you need this section?
yuuji@52 3111 ;; (save-excursion
yuuji@52 3112 ;; (end-of-line)
yuuji@52 3113 ;; (let ((p (point)))
yuuji@52 3114 ;; (forward-line -1)
yuuji@52 3115 ;; (end-of-line)
yuuji@52 3116 ;; (or (= p (point))
yuuji@52 3117 ;; (progn (backward-char (length YaTeX-comment-prefix))
yuuji@52 3118 ;; (not (looking-at (regexp-quote YaTeX-comment-prefix))))
yuuji@52 3119 ;; (progn
yuuji@52 3120 ;; (skip-chars-backward YaTeX-comment-prefix)
yuuji@52 3121 ;; (kill-line))))))
yuuji@52 3122 (or inenv (setq inenv "document")) ;is the default environment
yuuji@48 3123 (cond
yuuji@82 3124 ((and
yuuji@82 3125 (prog1 (YaTeX-on-begin-end-p)
yuuji@82 3126 (setq begend (match-beginning 0)))
yuuji@82 3127 (or (match-beginning 2) ;if \end
yuuji@82 3128 (and (match-beginning 3) ;if \) \]
yuuji@82 3129 (= (char-syntax (char-after (1+ (match-beginning 3)))) ?\)))))
yuuji@70 3130 (YaTeX-reindent
yuuji@70 3131 (save-excursion
yuuji@70 3132 (YaTeX-goto-corresponding-environment)
yuuji@70 3133 (current-column))))
yuuji@82 3134 ;; on the begining of verbatime line, remove all indentation
yuuji@82 3135 ((and begend ;; match-beginning 0 of \begin
yuuji@82 3136 YaTeX-noindent-env-regexp
yuuji@82 3137 (stringp YaTeX-noindent-env-regexp)
yuuji@82 3138 (save-excursion
yuuji@82 3139 (and ;; if the \begin is the first declaration of this line
yuuji@82 3140 (progn (beginning-of-line) (skip-chars-forward " \t")
yuuji@82 3141 (= begend (point)))
yuuji@82 3142 (progn
yuuji@82 3143 (goto-char begend)
yuuji@82 3144 (looking-at
yuuji@82 3145 (concat YaTeX-ec-regexp
yuuji@82 3146 "begin{\\(" YaTeX-noindent-env-regexp "\\)}"))))))
yuuji@82 3147 (save-excursion
yuuji@82 3148 (goto-char begend)
yuuji@82 3149 (delete-region (point) (point-beginning-of-line))))
yuuji@53 3150 ((string-match YaTeX-equation-env-regexp inenv)
yuuji@68 3151 (YaTeX-indent-line-equation)) ;autoload-ed from yatexenv
yuuji@52 3152 (;(YaTeX-in-environment-p '("itemize" "enumerate" "description" "list"))
yuuji@52 3153 (string-match YaTeX-itemizing-env-regexp inenv)
yuuji@52 3154 ;;(YaTeX-on-item-p) ??
yuuji@53 3155 ;;(setq iteminfo (YaTeX-get-item-info t))
yuuji@53 3156 (if (save-excursion
yuuji@51 3157 (beginning-of-line)
yuuji@53 3158 (re-search-forward YaTeX-item-regexp peol t))
yuuji@68 3159 (progn
yuuji@68 3160 (save-excursion
yuuji@68 3161 (goto-char (1+ (match-beginning 0)))
yuuji@68 3162 (setq depth
yuuji@68 3163 (* YaTeX-environment-indent
yuuji@68 3164 (cond
yuuji@68 3165 ((looking-at "subsubsub") 3)
yuuji@68 3166 ((looking-at "subsub") 2)
yuuji@68 3167 ((looking-at "sub") 1)
yuuji@68 3168 (t 0)))))
yuuji@51 3169 (funcall indent-relative depth))
yuuji@82 3170 (YaTeX-reindent (or (car (cdr (YaTeX-get-item-info t inenv)))
yuuji@53 3171 (+ (save-excursion
yuuji@53 3172 (beginning-of-line)
yuuji@53 3173 (YaTeX-current-indentation))
yuuji@52 3174 YaTeX-environment-indent))))
yuuji@48 3175 )
yuuji@49 3176 ((YaTeX-literal-p) ;verbatims
yuuji@48 3177 (tab-to-tab-stop))
yuuji@82 3178 ((string-match "\\(tabular\\|array\\)" inenv) ;1.73
yuuji@359 3179 (let ((n 1) (cc (current-column)) (p (point)))
yuuji@82 3180 (condition-case err
yuuji@82 3181 (save-excursion
yuuji@82 3182 (beginning-of-line)
yuuji@82 3183 (skip-chars-forward "[ \t]")
yuuji@82 3184 ;;(if (looking-at "&") (forward-char 1))
yuuji@82 3185 (require 'yatexenv)
yuuji@82 3186 (setq n (car (YaTeX-array-what-column-internal))))
yuuji@82 3187 (error nil))
yuuji@82 3188 (YaTeX-reindent
yuuji@82 3189 (+ (YaTeX-current-indentation)
yuuji@82 3190 YaTeX-environment-indent
yuuji@359 3191 (* (1- n) YaTeX-tabular-indentation)))
yuuji@359 3192 (and (= cc (current-column))
yuuji@359 3193 (= p (point))
yuuji@359 3194 (equal last-command 'YaTeX-indent-line)
yuuji@359 3195 ;; if NO indent action occured, move to the next column
yuuji@359 3196 (YaTeX-forward-field 1))))
yuuji@52 3197 ((and inenv (not (equal "document" inenv)))
yuuji@48 3198 (funcall indent-relative))
yuuji@53 3199 ((YaTeX-on-section-command-p YaTeX-sectioning-regexp)
yuuji@53 3200 (require 'yatexsec) ;to know YaTeX-sectioning-level
yuuji@68 3201 (setq sect (YaTeX-match-string 1))
yuuji@68 3202 (if (string-match "\\*$" sect)
yuuji@68 3203 (setq sect (substring sect 0 -1)))
yuuji@53 3204 (YaTeX-reindent
yuuji@53 3205 (* (max
yuuji@53 3206 (1- ;I want chapter to have indentation 0
yuuji@68 3207 (or (cdr (assoc sect YaTeX-sectioning-level))
yuuji@53 3208 0))
yuuji@53 3209 0)
yuuji@53 3210 YaTeX-environment-indent)))
yuuji@53 3211 ;;Default movement
yuuji@48 3212 ((and (bolp) fill-prefix) (insert fill-prefix))
yuuji@48 3213 (t (save-excursion
yuuji@48 3214 (beginning-of-line)
yuuji@64 3215 (if fill-prefix
yuuji@64 3216 (progn
yuuji@64 3217 (delete-region (point)
yuuji@64 3218 (progn (skip-chars-forward " \t")
yuuji@64 3219 (point)))
yuuji@64 3220 (insert fill-prefix))
yuuji@64 3221 (skip-chars-forward " \t")
yuuji@82 3222 (if (bobp)
yuuji@82 3223 nil
yuuji@82 3224 (indent-relative-maybe))))
yuuji@52 3225 (skip-chars-forward " \t")))
yuuji@53 3226 ;;if current line is \begin, re-indent \end too
yuuji@53 3227 (if (and (YaTeX-on-begin-end-p) (match-beginning 1))
yuuji@53 3228 (save-excursion
yuuji@53 3229 ;;(beginning-of-line)
yuuji@53 3230 ;;(search-forward "\\begin")
yuuji@53 3231 (goto-char (match-beginning 0))
yuuji@53 3232 (setq depth (current-column))
yuuji@53 3233 (YaTeX-goto-corresponding-environment)
yuuji@53 3234 (YaTeX-reindent depth)))
yuuji@59 3235 (if (or
yuuji@59 3236 (and NTT-jTeX
yuuji@59 3237 (save-excursion (beginning-of-line) (looking-at "[ \t]")))
yuuji@59 3238 (save-excursion
yuuji@59 3239 (beginning-of-line)
yuuji@59 3240 (and
yuuji@82 3241 (not (bobp))
yuuji@82 3242 (progn
yuuji@82 3243 (backward-char 1)
yuuji@82 3244 (re-search-backward
yuuji@82 3245 "\\\\\\(\\(page\\)?ref\\|cite\\){" (point-beginning-of-line) t))
yuuji@59 3246 (goto-char (1- (match-end 0)))
yuuji@59 3247 (> (save-excursion
yuuji@59 3248 (condition-case ()
yuuji@59 3249 (progn (forward-list 1) (point))
yuuji@59 3250 (error (point-max))))
yuuji@59 3251 (point-end-of-line)))))
yuuji@52 3252 (save-excursion
yuuji@52 3253 (end-of-line)
yuuji@52 3254 (let ((p (point)))
yuuji@52 3255 (forward-line -1)
yuuji@52 3256 (end-of-line)
yuuji@52 3257 (or (= p (point))
yuuji@52 3258 (looking-at (regexp-quote YaTeX-comment-prefix))
yuuji@52 3259 (bobp) (bolp)
yuuji@52 3260 (save-excursion
yuuji@52 3261 (backward-word 1)
yuuji@52 3262 (looking-at "\\sw+")) ;is not japanese string
yuuji@69 3263 (insert YaTeX-comment-prefix)))))))
yuuji@22 3264
yuuji@77 3265 (defun YaTeX-comment-line-break (&optional soft)
yuuji@77 3266 "Call comment-indent-new-line and YaTeX-indent-line"
yuuji@77 3267 (comment-indent-new-line soft)
yuuji@77 3268 (YaTeX-indent-line))
yuuji@77 3269
yuuji@70 3270 (defun YaTeX-latex2e-p ()
yuuji@70 3271 (let ((b (current-buffer))
yuuji@70 3272 (ptn (concat YaTeX-ec "documentclass")))
yuuji@70 3273 (unwind-protect
yuuji@70 3274 (or (save-excursion (search-backward ptn nil t))
yuuji@70 3275 (progn
yuuji@70 3276 (YaTeX-visit-main t)
yuuji@70 3277 (save-excursion (search-backward ptn nil t))))
yuuji@70 3278 (set-buffer b))))
yuuji@70 3279
yuuji@7 3280 (provide 'yatex)
yuuji@7 3281 (defvar yatex-mode-load-hook nil
yuuji@7 3282 "*List of functions to be called when yatex.el is loaded.")
yuuji@72 3283 (if (and YaTeX-emacs-19 YaTeX-display-color-p (not (featurep 'yatex19)))
yuuji@55 3284 (load "yatex19"))
yuuji@51 3285 (load "yatexhks" t)
yuuji@51 3286
yuuji@51 3287 ;;-------------------- Final hook jobs --------------------
yuuji@51 3288 (substitute-all-key-definition
yuuji@51 3289 'fill-paragraph 'YaTeX-fill-paragraph YaTeX-mode-map)
yuuji@72 3290 (substitute-all-key-definition
yuuji@73 3291 'kill-buffer 'YaTeX-kill-buffer YaTeX-mode-map)
yuuji@7 3292 (run-hooks 'yatex-mode-load-hook)
yuuji@51 3293
yuuji@51 3294 ;; `History' was moved to ChangeLog
yuuji@0 3295 ;----------------------------- End of yatex.el -----------------------------