yatex

annotate yatex.el @ 68:0eb6997bee16

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