yatex

annotate yatex.el @ 422:5e7b06dcab9c

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