yatex

annotate yatexenv.el @ 23:b00c74813e56

Change the YaTeX-math-mode's prefix from `,' to `;'. Add YaTeX-apropos, YaTeX-what-column, YaTeX-beginning-of-environment, YaTeX-end-of-environment. Add variables YaTeX-default-pop-window-height, YaTeX-close-paren-always, YaTeX-no-begend-shortcut, YaTeX-auto-math-mode. Remove Greek letters from maketitle-type. Make YaTeX-inner-environment two times faster and more reliable. C-u for [prefix] k kills contents too. Fix the detection of the range of section-type commands when nested. Add \end{ completion. Add YaTeX-generate-simple. Refine documents(using Texinfo). %#REQUIRE for sub-preambles.
author yuuji
date Thu, 07 Jul 1994 16:37:05 +0000
parents
children 459e1eca4e10
rev   line source
yuuji@23 1 ;;; -*- Emacs-Lisp -*-
yuuji@23 2 ;;; YaTeX environment-specific functions.
yuuji@23 3 ;;; yatexenv.el
yuuji@23 4 ;;; (c ) 1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@23 5 ;;; Last modified Fri Jul 8 00:48:40 1994 on figaro
yuuji@23 6 ;;; $Id$
yuuji@23 7
yuuji@23 8 ;;;
yuuji@23 9 ;; Functions for tabular environment
yuuji@23 10 ;;;
yuuji@23 11
yuuji@23 12 ;; Showing the matching column of tabular environment.
yuuji@23 13 (defun YaTeX-array-what-column ()
yuuji@23 14 "Show matching columne title of array environment.
yuuji@23 15 When calling from a program, make sure to be in array/tabular environment."
yuuji@23 16 (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&") (n 0)
yuuji@23 17 (firsterr "This line might be the first row."))
yuuji@23 18 (save-excursion
yuuji@23 19 (YaTeX-beginning-of-environment)
yuuji@23 20 (search-forward "{" p) (up-list 1)
yuuji@23 21 (search-forward "{" p) (up-list 1)
yuuji@23 22 ;;(re-search-forward andptn p)
yuuji@23 23 (while (progn (search-forward "&" p)
yuuji@23 24 (equal (char-after (1- (match-beginning 0))) ?\\ )))
yuuji@23 25 (setq beg (1- (point))) ;beg is the point of the first &
yuuji@23 26 (or (re-search-forward nlptn p t)
yuuji@23 27 (error firsterr))
yuuji@23 28 (setq eot (point)) ;eot is the point of the first \\
yuuji@23 29 (goto-char p)
yuuji@23 30 (or (re-search-backward nlptn beg t)
yuuji@23 31 (error firsterr))
yuuji@23 32 (setq bor (point)) ;bor is the beginning of this row.
yuuji@23 33 (while (< (1- (point)) p)
yuuji@23 34 (if (equal (following-char) ?&)
yuuji@23 35 (forward-char 1)
yuuji@23 36 (re-search-forward andptn nil 1))
yuuji@23 37 (setq n (1+ n))) ;Check current column number
yuuji@23 38 (goto-char p)
yuuji@23 39 (cond ;Start searching \multicolumn{N}
yuuji@23 40 ((> n 1)
yuuji@23 41 (re-search-backward andptn) ;Sure to find!
yuuji@23 42 (while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t)
yuuji@23 43 (setq n (+ n (string-to-int
yuuji@23 44 (buffer-substring (match-beginning 1)
yuuji@23 45 (match-end 1)))
yuuji@23 46 -1)))))
yuuji@23 47 (message "%s" n)
yuuji@23 48 (goto-char (1- beg))
yuuji@23 49 (cond
yuuji@23 50 ((= n 1) (message "Here is the FIRST column!"))
yuuji@23 51 (t (while (> n 1)
yuuji@23 52 (or (re-search-forward andptn p nil)
yuuji@23 53 (error "This column exceeds the limit."))
yuuji@23 54 (setq n (1- n)))
yuuji@23 55 (skip-chars-forward "\\s ")
yuuji@23 56 (message
yuuji@23 57 "Here is the column of: %s"
yuuji@23 58 (buffer-substring
yuuji@23 59 (point)
yuuji@23 60 (progn
yuuji@23 61 (re-search-forward (concat andptn "\\|" nlptn) eot)
yuuji@23 62 (goto-char (match-beginning 0))
yuuji@23 63 (if (looking-at andptn)
yuuji@23 64 (forward-char 1))
yuuji@23 65 (skip-chars-backward "\\s ")
yuuji@23 66 (point))))))))
yuuji@23 67 )
yuuji@23 68
yuuji@23 69 ;;;###autoload
yuuji@23 70 (defun YaTeX-what-column ()
yuuji@23 71 "Show which kind of column the current position is belonging to."
yuuji@23 72 (interactive)
yuuji@23 73 (cond
yuuji@23 74 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*"))
yuuji@23 75 (YaTeX-array-what-column))
yuuji@23 76 (t (message "Not in array/tabuar environment.")))
yuuji@23 77 )
yuuji@23 78
yuuji@23 79 ;;;
yuuji@23 80 ;; Functions for tabbing environment
yuuji@23 81 ;;;
yuuji@23 82 (defun YaTeX-intelligent-newline-tabbing ()
yuuji@23 83 "Check the number of \\= in the first line and insert that many \\>."
yuuji@23 84 (let ((p (point)) begenv tabcount)
yuuji@23 85 (save-excursion
yuuji@23 86 (YaTeX-beginning-of-environment)
yuuji@23 87 (setq begenv (point-end-of-line))
yuuji@23 88 (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t)
yuuji@23 89 (progn
yuuji@23 90 (setq tabcount 0)
yuuji@23 91 (while (> (point) begenv)
yuuji@23 92 (if (search-backward "\\=" begenv 1)
yuuji@23 93 (setq tabcount (1+ tabcount)))))))
yuuji@23 94 (YaTeX-indent-line)
yuuji@23 95 (if tabcount
yuuji@23 96 (progn
yuuji@23 97 (save-excursion
yuuji@23 98 (while (> tabcount 0)
yuuji@23 99 (insert "\\>\t")
yuuji@23 100 (setq tabcount (1- tabcount))))
yuuji@23 101 (forward-char 2))
yuuji@23 102 (insert "\\=")))
yuuji@23 103 )
yuuji@23 104
yuuji@23 105 ;;;
yuuji@23 106 ;; Functions for itemize/enumerate/list environments
yuuji@23 107 ;;;
yuuji@23 108
yuuji@23 109 (defun YaTeX-indent-for-item ()
yuuji@23 110 (let (col (p (point)) begenv)
yuuji@23 111 (save-excursion
yuuji@23 112 (YaTeX-beginning-of-environment t)
yuuji@23 113 (setq begenv (point-end-of-line))
yuuji@23 114 (goto-char p)
yuuji@23 115 (if (YaTeX-search-active-backward "\\item" YaTeX-comment-prefix begenv t)
yuuji@23 116 (setq col (current-column))))
yuuji@23 117 (if col (indent-to col) (YaTeX-indent-line)))
yuuji@23 118 )
yuuji@23 119
yuuji@23 120 (defvar YaTeX-item-for-insert "\\item ")
yuuji@23 121 (defun YaTeX-intelligent-newline-itemize ()
yuuji@23 122 "Insert '\\item '."
yuuji@23 123 (YaTeX-indent-for-item)
yuuji@23 124 (insert YaTeX-item-for-insert)
yuuji@23 125 )
yuuji@23 126 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
yuuji@23 127 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
yuuji@23 128
yuuji@23 129 (defun YaTeX-intelligent-newline-description ()
yuuji@23 130 (YaTeX-indent-for-item)
yuuji@23 131 (insert "\\item[] ")
yuuji@23 132 (forward-char -2)
yuuji@23 133 )
yuuji@23 134
yuuji@23 135
yuuji@23 136 ;;;
yuuji@23 137 ;; Intelligent newline
yuuji@23 138 ;;;
yuuji@23 139 ;;;###autoload
yuuji@23 140 (defun YaTeX-intelligent-newline (arg)
yuuji@23 141 "Insert newline and environment-specific entry.
yuuji@23 142 `\\item' for some itemizing environment,
yuuji@23 143 `\\> \\> \\' for tabbing environemnt,
yuuji@23 144 `& & \\ \hline' for tabular environment."
yuuji@23 145 (interactive "P")
yuuji@23 146 (let*((env (YaTeX-inner-environment))
yuuji@23 147 func)
yuuji@23 148 (if arg (setq env (YaTeX-read-environment "For what environment? ")))
yuuji@23 149 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env)))
yuuji@23 150 (end-of-line)
yuuji@23 151 (newline)
yuuji@23 152 (if (and env func (fboundp func))
yuuji@23 153 (funcall func)))
yuuji@23 154 )