yatex

annotate yatex.el @ 69:807c1e7e68b7

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