yatex

annotate yatex.el @ 79:0734be649cb8

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