yatex

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