yatex

annotate yatex.el @ 64:36a48185b95a

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