yatex

annotate yatex.el @ 61:b9f753846b6b

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