yatex

annotate yatexlib.el @ 77:1b172d26b55e

Fix auto-fill movement on Emacs21. Fix YaTeX:ref. Support jump/change on AMS-LaTeX's parentheses.
author yuuji
date Thu, 01 May 2003 13:38:27 +0000
parents f41b01fef5d6
children 0734be649cb8
rev   line source
yuuji@23 1 ;;; -*- Emacs-Lisp -*-
yuuji@64 2 ;;; YaTeX and yahtml common libraries, general functions and definitions
yuuji@23 3 ;;; yatexlib.el
yuuji@73 4 ;;; (c )1994-2002 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@77 5 ;;; Last modified Wed Oct 2 23:35:33 2002 on firestorm
yuuji@23 6 ;;; $Id$
yuuji@23 7
yuuji@64 8 ;; General variables
yuuji@64 9 (defvar YaTeX-dos (memq system-type '(ms-dos windows-nt OS/2)))
yuuji@64 10 (defvar YaTeX-emacs-19 (>= (string-to-int emacs-version) 19))
yuuji@64 11 (defvar YaTeX-emacs-20 (>= (string-to-int emacs-version) 20))
yuuji@72 12 (defvar YaTeX-emacs-21 (>= (string-to-int emacs-version) 21))
yuuji@64 13 (defvar YaTeX-user-completion-table
yuuji@64 14 (if YaTeX-dos "~/_yatexrc" "~/.yatexrc")
yuuji@64 15 "*Default filename in which user completion table is saved.")
yuuji@64 16
yuuji@72 17 (defvar YaTeX-display-color-p
yuuji@72 18 (or (and (fboundp 'display-color-p) (display-color-p))
yuuji@72 19 (and (fboundp 'device-class)
yuuji@72 20 (eq 'color (device-class (selected-device))))
yuuji@72 21 window-system) ; falls down lazy check..
yuuji@72 22 "Current display's capability of expressing colors.")
yuuji@72 23
yuuji@64 24 (defvar YaTeX-japan (or (boundp 'NEMACS) (boundp 'MULE) YaTeX-emacs-20)
yuuji@64 25 "Whether yatex mode is running on Japanese environment or not.")
yuuji@64 26
yuuji@70 27 ;; autoload from yahtml.el
yuuji@70 28 (autoload 'yahtml-inner-environment-but "yahtml" "yahtml internal func." t)
yuuji@70 29
yuuji@64 30 (defvar YaTeX-kanji-code-alist
yuuji@64 31 (cond
yuuji@64 32 ((boundp '*junet*)
yuuji@77 33 (list '(0 . *noconv*)
yuuji@77 34 (cons
yuuji@64 35 1
yuuji@64 36 (if YaTeX-dos (if (boundp '*sjis-dos*) *sjis-dos* *sjis*dos)
yuuji@64 37 *sjis*))
yuuji@64 38 '(2 . *junet*) '(3 . *euc-japan*)))
yuuji@64 39 (YaTeX-emacs-20
yuuji@64 40 ;;(cdr-safe(assq 'coding-system (assoc "Japanese" language-info-alist)))
yuuji@77 41 (list '(0 . no-conversion)
yuuji@77 42 (cons
yuuji@64 43 1 (cond (YaTeX-dos 'shift_jis-dos)
yuuji@64 44 ((member 'shift_jis (coding-system-list)) 'shift_jis-unix)
yuuji@64 45 (t 'sjis)))
yuuji@68 46 '(2 . iso-2022-jp-unix)
yuuji@68 47 '(3 . euc-jp-unix))))
yuuji@64 48 "Kanji-code expression translation table.")
yuuji@64 49 (defvar YaTeX-inhibit-prefix-letter nil
yuuji@64 50 "*T for changing key definitions from [prefix] Letter to [prefix] C-Letter.")
yuuji@64 51
yuuji@64 52 (defvar YaTeX-no-begend-shortcut nil
yuuji@64 53 "*T for disabling shortcut of begin-type completion, [prefix] b d, etc.")
yuuji@64 54
yuuji@64 55 (defvar YaTeX-default-pop-window-height 10
yuuji@64 56 "Default typesetting buffer height.
yuuji@64 57 If integer, sets the window-height of typesetting buffer.
yuuji@64 58 If string, sets the percentage of it.
yuuji@64 59 If nil, use default pop-to-buffer.")
yuuji@64 60
yuuji@64 61 (defvar YaTeX-create-file-prefix-g nil
yuuji@64 62 "*Non-nil creates new file when [prefix] g on \\include{foo}.")
yuuji@64 63
yuuji@64 64 (defvar YaTeX-nervous t
yuuji@64 65 "*If you are nervous about maintenance of yatexrc, set this value to T.
yuuji@64 66 And you will have the local dictionary.")
yuuji@64 67
yuuji@72 68 (defvar YaTeX-use-italic-bold (string< "20" emacs-version)
yuuji@72 69 "*Non-nil tries to find italic/bold fontset.
yuuji@72 70 This variable is effective when font-lock is used.
yuuji@72 71 \it, \bf 内部での日本語が□になってしまう場合はこれをnilにして下さい。")
yuuji@72 72
yuuji@64 73 ;----------- work variables ----------------------------------------
yuuji@64 74 (defvar YaTeX-typesetting-mode-map nil
yuuji@69 75 "Keymap used in YaTeX typesetting buffer")
yuuji@69 76
yuuji@64 77 (if YaTeX-typesetting-mode-map nil
yuuji@64 78 (setq YaTeX-typesetting-mode-map (make-keymap))
yuuji@64 79 ;(suppress-keymap YaTeX-typesetting-mode-map t)
yuuji@64 80 (define-key YaTeX-typesetting-mode-map " " 'YaTeX-jump-error-line)
yuuji@64 81 (define-key YaTeX-typesetting-mode-map "\C-m" 'YaTeX-send-string)
yuuji@64 82 (define-key YaTeX-typesetting-mode-map "1" 'delete-other-windows)
yuuji@64 83 (define-key YaTeX-typesetting-mode-map "0" 'delete-window)
yuuji@64 84 (define-key YaTeX-typesetting-mode-map "q" 'delete-window))
yuuji@64 85
yuuji@64 86 (defvar YaTeX-parent-file nil
yuuji@64 87 "*Main LaTeX source file name used when %#! expression doesn't exist.")
yuuji@64 88 (make-variable-buffer-local 'YaTeX-parent-file)
yuuji@64 89
yuuji@64 90 ;---------- Define default key bindings on YaTeX mode map ----------
yuuji@64 91 ;;;###autoload
yuuji@64 92 (defun YaTeX-define-key (key binding &optional map)
yuuji@64 93 "Define key on YaTeX-prefix-map."
yuuji@64 94 (if YaTeX-inhibit-prefix-letter
yuuji@64 95 (let ((c (aref key 0)))
yuuji@64 96 (cond
yuuji@64 97 ((and (>= c ?a) (<= c ?z)) (aset key 0 (1+ (- c ?a))))
yuuji@64 98 ((and (>= c ?A) (<= c ?Z) (numberp YaTeX-inhibit-prefix-letter))
yuuji@64 99 (aset key 0 (1+ (- c ?A))))
yuuji@64 100 (t nil))))
yuuji@64 101 (define-key (or map YaTeX-prefix-map) key binding))
yuuji@64 102
yuuji@64 103 ;;;###autoload
yuuji@64 104 (defun YaTeX-local-table-symbol (symbol)
yuuji@64 105 "Return the lisp symbol which keeps local completion table of SYMBOL."
yuuji@64 106 (intern (concat "YaTeX$"
yuuji@64 107 default-directory
yuuji@64 108 (symbol-name symbol))))
yuuji@64 109
yuuji@64 110 ;;;###autoload
yuuji@64 111 (defun YaTeX-sync-local-table (symbol)
yuuji@64 112 "Synchronize local variable SYMBOL.
yuuji@64 113 Copy its corresponding directory dependent completion table to SYMBOL."
yuuji@64 114 (if (boundp (YaTeX-local-table-symbol symbol))
yuuji@64 115 (set symbol (symbol-value (YaTeX-local-table-symbol symbol)))))
yuuji@64 116
yuuji@64 117 (defvar YaTeX-user-table-is-read nil
yuuji@64 118 "Flag that means whether user completion table has been read or not.")
yuuji@64 119 ;;;###autoload
yuuji@64 120 (defun YaTeX-read-user-completion-table (&optional forcetoread)
yuuji@64 121 "Append user completion table of LaTeX macros"
yuuji@64 122 (let*((user-table (expand-file-name YaTeX-user-completion-table))
yuuji@64 123 (local-table (expand-file-name (file-name-nondirectory user-table)))
yuuji@64 124 var localvar localbuf (curbuf (current-buffer)) sexp)
yuuji@64 125 (if YaTeX-user-table-is-read nil
yuuji@64 126 (message "Loading user completion table")
yuuji@64 127 (if (file-exists-p user-table) (load-file user-table)
yuuji@64 128 (message "Welcome to the field of YaTeX. I'm glad to see you!")))
yuuji@64 129 (setq YaTeX-user-table-is-read t)
yuuji@64 130 (cond
yuuji@64 131 ((file-exists-p local-table)
yuuji@64 132 (set-buffer (setq localbuf (find-file-noselect local-table)))
yuuji@64 133 (widen)
yuuji@64 134 (goto-char (point-min))
yuuji@64 135 (while (re-search-forward "(setq \\([^ ]+\\)" nil t)
yuuji@64 136 (setq var (intern (buffer-substring
yuuji@64 137 (match-beginning 1) (match-end 1)))
yuuji@64 138 localvar (YaTeX-local-table-symbol var))
yuuji@64 139 (goto-char (match-beginning 0))
yuuji@64 140 (setq sexp (buffer-substring (point)
yuuji@64 141 (progn (forward-sexp) (point))))
yuuji@64 142 (set-buffer curbuf)
yuuji@64 143 (or (assq var (buffer-local-variables)) (make-local-variable var))
yuuji@64 144 (eval (read sexp))
yuuji@64 145 (or (and (boundp localvar)
yuuji@64 146 (symbol-value localvar)
yuuji@64 147 (not forcetoread))
yuuji@64 148 (set localvar (symbol-value var)))
yuuji@64 149 (set-buffer localbuf))
yuuji@64 150 (kill-buffer localbuf)))
yuuji@64 151 (set-buffer curbuf)))
yuuji@64 152
yuuji@64 153 ;;;###autoload
yuuji@64 154 (defun YaTeX-reload-dictionary ()
yuuji@64 155 "Reload local dictionary.
yuuji@64 156 Use this function after editing ./.yatexrc."
yuuji@64 157 (interactive)
yuuji@64 158 (let ((YaTeX-user-table-is-read nil))
yuuji@64 159 (YaTeX-read-user-completion-table t)))
yuuji@64 160
yuuji@64 161 ;;;###autoload
yuuji@64 162 (defun YaTeX-lookup-table (word type)
yuuji@64 163 "Lookup WORD in completion table whose type is TYPE.
yuuji@64 164 This function refers the symbol tmp-TYPE-table, user-TYPE-table, TYPE-table.
yuuji@64 165 Typically, TYPE is one of 'env, 'section, 'fontsize, 'singlecmd."
yuuji@64 166 (if (symbolp type) (setq type (symbol-name type)))
yuuji@64 167 (or (assoc word (symbol-value (intern (concat "tmp-" type "-table"))))
yuuji@64 168 (assoc word (symbol-value (intern (concat "user-" type "-table"))))
yuuji@64 169 (assoc word (symbol-value (intern (concat type "-table"))))))
yuuji@64 170
yuuji@64 171 ;;;###autoload
yuuji@64 172 (defun YaTeX-update-table (vallist default-table user-table local-table)
yuuji@64 173 "Update completion table if the car of VALLIST is not in current tables.
yuuji@64 174 Second argument DEFAULT-TABLE is the quoted symbol of default completion
yuuji@64 175 table, third argument USER-TABLE is user table which will be saved in
yuuji@64 176 YaTeX-user-completion-table, fourth argument LOCAL-TABLE should have the
yuuji@64 177 completion which is valid during current Emacs's session. If you
yuuji@64 178 want to make LOCAL-TABLE valid longer span (but restrict in this directory)
yuuji@64 179 create the file in current directory which has the same name with
yuuji@64 180 YaTeX-user-completion-table."
yuuji@64 181 (let ((car-v (car vallist)) key answer
yuuji@64 182 (file (file-name-nondirectory YaTeX-user-completion-table)))
yuuji@64 183 (cond
yuuji@64 184 ((assoc car-v (symbol-value default-table))
yuuji@64 185 nil) ;Nothing to do
yuuji@64 186 ((setq key (assoc car-v (symbol-value user-table)))
yuuji@64 187 (if (equal (cdr vallist) (cdr key)) nil
yuuji@64 188 ;; if association hits, but contents differ.
yuuji@64 189 (message
yuuji@64 190 "%s's attributes turned into %s" (car vallist) (cdr vallist))
yuuji@64 191 (set user-table (delq key (symbol-value user-table)))
yuuji@64 192 (set user-table (cons vallist (symbol-value user-table)))
yuuji@64 193 (YaTeX-update-dictionary
yuuji@64 194 YaTeX-user-completion-table user-table "user")))
yuuji@64 195 ((setq key (assoc car-v (symbol-value local-table)))
yuuji@64 196 (if (equal (cdr vallist) (cdr key)) nil
yuuji@64 197 (message
yuuji@64 198 "%s's attributes turned into %s" (car vallist) (cdr vallist))
yuuji@64 199 (set local-table (delq key (symbol-value local-table)))
yuuji@64 200 (set local-table (cons vallist (symbol-value local-table)))
yuuji@64 201 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
yuuji@64 202 (YaTeX-update-dictionary file local-table)))
yuuji@64 203 ;; All of above cases, there are some completion in tables.
yuuji@64 204 ;; Then update tables.
yuuji@64 205 (t
yuuji@64 206 (if (not YaTeX-nervous)
yuuji@64 207 (setq answer "u")
yuuji@64 208 (message
yuuji@64 209 (cond
yuuji@64 210 (YaTeX-japan
yuuji@68 211 "`%s'の登録先: U)ユーザ辞書 L)ローカル辞書 N)メモリ D)しない")
yuuji@64 212 (t
yuuji@64 213 "Register `%s' into: U)serDic L)ocalDic N)one D)iscard"))
yuuji@64 214 (if (> (length car-v) 23)
yuuji@68 215 (concat (substring car-v 0 10) "..." (substring car-v -9))
yuuji@64 216 car-v))
yuuji@64 217 (setq answer (char-to-string (read-char))))
yuuji@64 218 (cond
yuuji@64 219 ((string-match answer "uy")
yuuji@64 220 (set user-table (cons vallist (symbol-value user-table)))
yuuji@64 221 (YaTeX-update-dictionary YaTeX-user-completion-table user-table "user")
yuuji@64 222 )
yuuji@64 223 ((string-match answer "tl")
yuuji@64 224 (set local-table (cons vallist (symbol-value local-table)))
yuuji@64 225 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
yuuji@64 226 (YaTeX-update-dictionary file local-table))
yuuji@64 227 ((string-match answer "d") nil) ;discard it
yuuji@64 228 (t (set default-table
yuuji@64 229 (cons vallist (symbol-value default-table)))))))))
yuuji@64 230
yuuji@64 231 ;;;###autoload
yuuji@64 232 (defun YaTeX-cplread-with-learning
yuuji@64 233 (prom default-table user-table local-table
yuuji@64 234 &optional pred reqmatch init hsym)
yuuji@64 235 "Completing read with learning.
yuuji@64 236 Do a completing read with prompt PROM. Completion table is what
yuuji@64 237 DEFAULT-TABLE, USER-TABLE, LOCAL table are appended in reverse order.
yuuji@64 238 Note that these tables are passed by the symbol.
yuuji@64 239 Optional arguments PRED, REQMATH and INIT are passed to completing-read
yuuji@64 240 as its arguments PREDICATE, REQUIRE-MATCH and INITIAL-INPUT respectively.
yuuji@64 241 If optional 8th argument HSYM, history symbol, is passed, use it as
yuuji@64 242 history list variable."
yuuji@64 243 (YaTeX-sync-local-table local-table)
yuuji@64 244 (let*((table (append (symbol-value local-table)
yuuji@64 245 (symbol-value user-table)
yuuji@64 246 (symbol-value default-table)))
yuuji@64 247 (word (completing-read-with-history
yuuji@64 248 prom table pred reqmatch init hsym)))
yuuji@64 249 (if (and (string< "" word) (not (assoc word table)))
yuuji@64 250 (YaTeX-update-table (list word) default-table user-table local-table))
yuuji@64 251 word))
yuuji@64 252
yuuji@64 253 ;;;###autoload
yuuji@64 254 (defun YaTeX-update-dictionary (file symbol &optional type)
yuuji@64 255 (let ((local-table-buf (find-file-noselect file))
yuuji@64 256 (name (symbol-name symbol))
yuuji@64 257 (value (symbol-value symbol)))
yuuji@64 258 (save-excursion
yuuji@64 259 (message "Updating %s dictionary..." (or type "local"))
yuuji@64 260 (set-buffer local-table-buf)
yuuji@64 261 (goto-char (point-max))
yuuji@64 262 (search-backward (concat "(setq " name) nil t)
yuuji@64 263 (delete-region (point) (progn (forward-sexp) (point)))
yuuji@64 264 (delete-blank-lines)
yuuji@64 265 (insert "(setq " name " '(\n")
yuuji@64 266 (mapcar '(lambda (s)
yuuji@64 267 (insert (format "%s\n" (prin1-to-string s))))
yuuji@64 268 value)
yuuji@64 269 (insert "))\n\n")
yuuji@64 270 (delete-blank-lines)
yuuji@64 271 (basic-save-buffer)
yuuji@64 272 (kill-buffer local-table-buf)
yuuji@64 273 (message "Updating %s dictionary...Done" (or type "local")))))
yuuji@64 274
yuuji@64 275 ;;;###autoload
yuuji@64 276 (defun YaTeX-define-begend-key-normal (key env &optional map)
yuuji@64 277 "Define short cut YaTeX-make-begin-end key."
yuuji@64 278 (YaTeX-define-key
yuuji@64 279 key
yuuji@64 280 (list 'lambda '(arg) '(interactive "P")
yuuji@64 281 (list 'YaTeX-insert-begin-end env 'arg))
yuuji@64 282 map))
yuuji@64 283
yuuji@64 284 ;;;###autoload
yuuji@64 285 (defun YaTeX-define-begend-region-key (key env &optional map)
yuuji@64 286 "Define short cut YaTeX-make-begin-end-region key."
yuuji@64 287 (YaTeX-define-key key (list 'lambda nil '(interactive)
yuuji@64 288 (list 'YaTeX-insert-begin-end env t)) map))
yuuji@64 289
yuuji@64 290 ;;;###autoload
yuuji@64 291 (defun YaTeX-define-begend-key (key env &optional map)
yuuji@64 292 "Define short cut key for begin type completion both for normal
yuuji@64 293 and region mode. To customize YaTeX, user should use this function."
yuuji@64 294 (YaTeX-define-begend-key-normal key env map)
yuuji@64 295 (if YaTeX-inhibit-prefix-letter nil
yuuji@64 296 (YaTeX-define-begend-region-key
yuuji@64 297 (concat (upcase (substring key 0 1)) (substring key 1)) env)))
yuuji@64 298
yuuji@23 299 ;;;###autoload
yuuji@23 300 (defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func)
yuuji@23 301 "Search STRING which is not commented out by CMNTRX.
yuuji@23 302 Optional arguments after BOUND, ERR, CNT are passed literally to search-forward
yuuji@23 303 or search-backward.
yuuji@23 304 Optional sixth argument FUNC changes search-function."
yuuji@49 305 (let ((sfunc (or func 'search-forward)) found md)
yuuji@23 306 (while (and (prog1
yuuji@23 307 (setq found (funcall sfunc string bound err cnt))
yuuji@23 308 (setq md (match-data)))
yuuji@23 309 (or
yuuji@64 310 (and (eq major-mode 'yatex-mode)
yuuji@64 311 (YaTeX-in-verb-p (match-beginning 0)))
yuuji@23 312 (save-excursion
yuuji@72 313 (goto-char (match-beginning 0))
yuuji@23 314 (beginning-of-line)
yuuji@23 315 (re-search-forward cmntrx (match-beginning 0) t)))))
yuuji@23 316 (store-match-data md)
yuuji@69 317 found))
yuuji@23 318
yuuji@23 319 (defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt)
yuuji@23 320 "Search REGEXP backward which is not commented out by regexp CMNTRX.
yuuji@23 321 See also YaTeX-search-active-forward."
yuuji@69 322 (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward))
yuuji@69 323
yuuji@23 324 (defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt)
yuuji@23 325 "Search STRING backward which is not commented out by regexp CMNTRX.
yuuji@23 326 See also YaTeX-search-active-forward."
yuuji@69 327 (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward))
yuuji@69 328
yuuji@23 329 (defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt)
yuuji@23 330 "Search REGEXP backward which is not commented out by regexp CMNTRX.
yuuji@23 331 See also YaTeX-search-active-forward."
yuuji@69 332 (YaTeX-search-active-forward
yuuji@69 333 regexp cmntrx bound err cnt 're-search-backward))
yuuji@23 334
yuuji@23 335 ;;;###autoload
yuuji@23 336 (defun YaTeX-switch-to-buffer (file &optional setbuf)
yuuji@23 337 "Switch to buffer if buffer exists, find file if not.
yuuji@23 338 Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer."
yuuji@23 339 (interactive "Fswitch to file: ")
yuuji@70 340 (if (bufferp file)
yuuji@70 341 (setq file (buffer-file-name file))
yuuji@70 342 (and (string-match "^[^/].*/" file)
yuuji@70 343 (eq major-mode 'yatex-mode)
yuuji@70 344 YaTeX-search-file-from-top-directory
yuuji@70 345 (save-excursion
yuuji@70 346 (YaTeX-visit-main t)
yuuji@70 347 (setq file (expand-file-name file)))))
yuuji@52 348 (let (buf (hilit-auto-highlight (not setbuf)))
yuuji@52 349 (cond
yuuji@52 350 ((setq buf (get-file-buffer file))
yuuji@52 351 (funcall (if setbuf 'set-buffer 'switch-to-buffer)
yuuji@52 352 (get-file-buffer file))
yuuji@52 353 buf)
yuuji@52 354 ((or YaTeX-create-file-prefix-g (file-exists-p file))
yuuji@52 355 (or ;find-file returns nil but set current-buffer...
yuuji@52 356 (if setbuf (set-buffer (find-file-noselect file))
yuuji@52 357 (find-file file))
yuuji@52 358 (current-buffer)))
yuuji@52 359 (t (message "%s was not found in this directory." file)
yuuji@69 360 nil))))
yuuji@23 361
yuuji@23 362 ;;;###autoload
yuuji@23 363 (defun YaTeX-switch-to-buffer-other-window (file)
yuuji@23 364 "Switch to buffer if buffer exists, find file if not."
yuuji@23 365 (interactive "Fswitch to file: ")
yuuji@70 366 (and (eq major-mode 'yatex-mode)
yuuji@70 367 (stringp file)
yuuji@70 368 (string-match "^[^/].*/" file)
yuuji@70 369 YaTeX-search-file-from-top-directory
yuuji@70 370 (save-excursion
yuuji@70 371 (YaTeX-visit-main t)
yuuji@70 372 (setq file (expand-file-name file))))
yuuji@52 373 (if (bufferp file) (setq file (buffer-file-name file)))
yuuji@52 374 (cond
yuuji@52 375 ((get-file-buffer file)
yuuji@52 376 (switch-to-buffer-other-window (get-file-buffer file))
yuuji@52 377 t)
yuuji@52 378 ((or YaTeX-create-file-prefix-g (file-exists-p file))
yuuji@52 379 (find-file-other-window file) t)
yuuji@52 380 (t (message "%s was not found in this directory." file)
yuuji@69 381 nil)))
yuuji@23 382
yuuji@70 383 (defun YaTeX-get-file-buffer (file)
yuuji@70 384 "Return the FILE's buffer.
yuuji@70 385 Base directory is that of main file or current directory."
yuuji@70 386 (let (dir main (cdir default-directory))
yuuji@70 387 (or (and (eq major-mode 'yatex-mode)
yuuji@70 388 YaTeX-search-file-from-top-directory
yuuji@70 389 (save-excursion
yuuji@70 390 (YaTeX-visit-main t)
yuuji@70 391 (get-file-buffer file)))
yuuji@70 392 (get-file-buffer file))))
yuuji@70 393
yuuji@23 394 (defun YaTeX-replace-format-sub (string format repl)
yuuji@23 395 (let ((beg (or (string-match (concat "^\\(%" format "\\)") string)
yuuji@23 396 (string-match (concat "[^%]\\(%" format "\\)") string)))
yuuji@23 397 (len (length format)))
yuuji@23 398 (if (null beg) string ;no conversion
yuuji@23 399 (concat
yuuji@70 400 (substring string 0 (match-beginning 1)) (or repl "")
yuuji@69 401 (substring string (match-end 1))))))
yuuji@23 402
yuuji@23 403 ;;;###autoload
yuuji@23 404 (defun YaTeX-replace-format (string format repl)
yuuji@23 405 "In STRING, replace first appearance of FORMAT to REPL as if
yuuji@23 406 function `format' does. FORMAT does not contain `%'"
yuuji@23 407 (let ((ans string))
yuuji@23 408 (while (not (string=
yuuji@23 409 ans (setq string (YaTeX-replace-format-sub ans format repl))))
yuuji@23 410 (setq ans string))
yuuji@69 411 string))
yuuji@23 412
yuuji@23 413 ;;;###autoload
yuuji@70 414 (defun YaTeX-replace-formats (string replace-list)
yuuji@70 415 (let ((list replace-list))
yuuji@70 416 (while list
yuuji@70 417 (setq string (YaTeX-replace-format
yuuji@70 418 string (car (car list)) (cdr (car list)))
yuuji@70 419 list (cdr list)))
yuuji@70 420 string))
yuuji@70 421
yuuji@70 422 ;;;###autoload
yuuji@23 423 (defun YaTeX-replace-format-args (string &rest args)
yuuji@23 424 "Translate the argument mark #1, #2, ... #n in the STRING into the
yuuji@23 425 corresponding real arguments ARGS."
yuuji@23 426 (let ((argp 1))
yuuji@23 427 (while args
yuuji@23 428 (setq string
yuuji@23 429 (YaTeX-replace-format string (int-to-string argp) (car args)))
yuuji@23 430 (setq args (cdr args) argp (1+ argp))))
yuuji@69 431 string)
yuuji@23 432
yuuji@23 433 ;;;###autoload
yuuji@23 434 (defun rindex (string char)
yuuji@23 435 (let ((pos (1- (length string)))(index -1))
yuuji@23 436 (while (>= pos 0)
yuuji@23 437 (cond
yuuji@23 438 ((= (aref string pos) char)
yuuji@23 439 (setq index pos) (setq pos -1))
yuuji@23 440 (t (setq pos (1- pos))))
yuuji@23 441 )
yuuji@64 442 index))
yuuji@64 443
yuuji@64 444 ;;;###autoload
yuuji@64 445 (defun point-beginning-of-line ()
yuuji@64 446 (save-excursion (beginning-of-line)(point)))
yuuji@64 447
yuuji@64 448 ;;;###autoload
yuuji@64 449 (defun point-end-of-line ()
yuuji@64 450 (save-excursion (end-of-line)(point)))
yuuji@64 451
yuuji@23 452
yuuji@23 453 ;;;###autoload
yuuji@23 454 (defun YaTeX-showup-buffer (buffer &optional func select)
yuuji@23 455 "Make BUFFER show up in certain window (but current window)
yuuji@23 456 that gives the maximum value by the FUNC. FUNC should take an argument
yuuji@23 457 of its window object. Non-nil for optional third argument SELECT selects
yuuji@49 458 that window. This function never selects minibuffer window."
yuuji@53 459 (or (and (if (and YaTeX-emacs-19 select)
yuuji@47 460 (get-buffer-window buffer t)
yuuji@47 461 (get-buffer-window buffer))
yuuji@47 462 (progn
yuuji@47 463 (if select
yuuji@51 464 (goto-buffer-window buffer))
yuuji@47 465 t))
yuuji@23 466 (let ((window (selected-window))
yuuji@23 467 (wlist (YaTeX-window-list)) win w (x 0))
yuuji@23 468 (cond
yuuji@23 469 ((> (length wlist) 2)
yuuji@23 470 (if func
yuuji@23 471 (while wlist
yuuji@23 472 (setq w (car wlist))
yuuji@23 473 (if (and (not (eq window w))
yuuji@23 474 (> (funcall func w) x))
yuuji@23 475 (setq win w x (funcall func w)))
yuuji@23 476 (setq wlist (cdr wlist)))
yuuji@23 477 (setq win (get-lru-window)))
yuuji@23 478 (select-window win)
yuuji@23 479 (switch-to-buffer buffer)
yuuji@23 480 (or select (select-window window)))
yuuji@23 481 ((= (length wlist) 2)
yuuji@49 482 ;(other-window 1);This does not work properly on Emacs-19
yuuji@49 483 (select-window (get-lru-window))
yuuji@23 484 (switch-to-buffer buffer)
yuuji@23 485 (or select (select-window window)))
yuuji@23 486 (t ;if one-window
yuuji@23 487 (cond
yuuji@47 488 ((and YaTeX-emacs-19 (get-buffer-window buffer t))
yuuji@47 489 nil) ;if found in other frame
yuuji@23 490 (YaTeX-default-pop-window-height
yuuji@51 491 (split-window-calculate-height YaTeX-default-pop-window-height)
yuuji@59 492 ;;(pop-to-buffer buffer) ;damn! emacs-19.30
yuuji@59 493 (select-window (next-window nil 1))
yuuji@59 494 (switch-to-buffer (get-buffer-create buffer))
yuuji@23 495 (or select (select-window window)))
yuuji@23 496 (t nil)))
yuuji@69 497 ))))
yuuji@69 498
yuuji@69 499 (cond
yuuji@69 500 ((fboundp 'screen-height)
yuuji@69 501 (fset 'YaTeX-screen-height 'screen-height)
yuuji@69 502 (fset 'YaTeX-screen-width 'screen-width))
yuuji@69 503 ((fboundp 'frame-height)
yuuji@69 504 (fset 'YaTeX-screen-height 'frame-height)
yuuji@69 505 (fset 'YaTeX-screen-width 'frame-width))
yuuji@69 506 (t (error "I don't know how to run windows.el on this Emacs...")))
yuuji@23 507
yuuji@23 508 ;;;###autoload
yuuji@51 509 (defun split-window-calculate-height (height)
yuuji@51 510 "Split current window wight specified HEIGHT.
yuuji@59 511 If HEIGHT is number, make a new window that has HEIGHT lines.
yuuji@59 512 If HEIGHT is string, make a new window that occupies HEIGT % of screen height.
yuuji@51 513 Otherwise split window conventionally."
yuuji@59 514 (if (one-window-p t)
yuuji@51 515 (split-window
yuuji@51 516 (selected-window)
yuuji@51 517 (max
yuuji@51 518 (min
yuuji@69 519 (- (YaTeX-screen-height)
yuuji@59 520 (if (numberp height)
yuuji@59 521 (+ height 2)
yuuji@69 522 (/ (* (YaTeX-screen-height)
yuuji@59 523 (string-to-int height))
yuuji@51 524 100)))
yuuji@69 525 (- (YaTeX-screen-height) window-min-height 1))
yuuji@69 526 window-min-height))))
yuuji@51 527
yuuji@51 528 ;;;###autoload
yuuji@23 529 (defun YaTeX-window-list ()
yuuji@23 530 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
yuuji@23 531 (while (not (eq curw (setq win (next-window win))))
yuuji@23 532 (or (eq win (minibuffer-window))
yuuji@23 533 (setq wlist (cons win wlist))))
yuuji@69 534 wlist))
yuuji@23 535
yuuji@72 536 (if YaTeX-emacs-21
yuuji@72 537 ;; Emacs-21's next-window returns other frame's window even if called
yuuji@72 538 ;; with argument ALL-FRAMES nil, when called from minibuffer context.
yuuji@72 539 ;; Therefore, check frame identity here.
yuuji@72 540 (defun YaTeX-window-list ()
yuuji@72 541 (let*((curw (selected-window)) (win curw) (wlist (list curw))
yuuji@72 542 (curf (window-frame curw)))
yuuji@72 543 (while (and (not (eq curw (setq win (next-window win))))
yuuji@72 544 (eq curf (window-frame win)))
yuuji@72 545 (or (eq win (minibuffer-window))
yuuji@72 546 (setq wlist (cons win wlist))))
yuuji@72 547 wlist)))
yuuji@72 548
yuuji@23 549 ;;;###autoload
yuuji@23 550 (defun substitute-all-key-definition (olddef newdef keymap)
yuuji@23 551 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
yuuji@23 552 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
yuuji@23 553 where ever it appears."
yuuji@68 554 (if YaTeX-emacs-19
yuuji@68 555 (substitute-key-definition olddef newdef keymap global-map)
yuuji@68 556 (mapcar
yuuji@68 557 (function (lambda (key) (define-key keymap key newdef)))
yuuji@68 558 (where-is-internal olddef keymap))))
yuuji@23 559
yuuji@23 560 ;;;###autoload
yuuji@23 561 (defun YaTeX-match-string (n &optional m)
yuuji@23 562 "Return (buffer-substring (match-beginning n) (match-beginning m))."
yuuji@23 563 (if (match-beginning n)
yuuji@23 564 (buffer-substring (match-beginning n)
yuuji@69 565 (match-end (or m n)))))
yuuji@23 566
yuuji@23 567 ;;;###autoload
yuuji@23 568 (defun YaTeX-minibuffer-complete ()
yuuji@49 569 "Complete in minibuffer.
yuuji@51 570 If the symbol 'delim is bound and is string, its value is assumed to be
yuuji@49 571 the character class of delimiters. Completion will be performed on
yuuji@51 572 the last field separated by those delimiters.
yuuji@51 573 If the symbol 'quick is bound and is 't, when the try-completion results
yuuji@51 574 in t, exit minibuffer immediately."
yuuji@23 575 (interactive)
yuuji@72 576 (save-restriction
yuuji@72 577 (narrow-to-region
yuuji@72 578 (if (fboundp 'field-beginning) (field-beginning (point-max)) (point-min))
yuuji@72 579 (point-max))
yuuji@72 580 (let ((md (match-data)) beg word compl
yuuji@72 581 (quick (and (boundp 'quick) (eq quick t)))
yuuji@72 582 (displist ;function to display completion-list
yuuji@72 583 (function
yuuji@72 584 (lambda ()
yuuji@72 585 (with-output-to-temp-buffer "*Completions*"
yuuji@72 586 (display-completion-list
yuuji@72 587 (all-completions word minibuffer-completion-table)))))))
yuuji@72 588 (setq beg (if (and (boundp 'delim) (stringp delim))
yuuji@72 589 (save-excursion
yuuji@72 590 (skip-chars-backward (concat "^" delim))
yuuji@72 591 (point))
yuuji@72 592 (point-min))
yuuji@72 593 word (buffer-substring beg (point-max))
yuuji@72 594 compl (try-completion word minibuffer-completion-table))
yuuji@72 595 (cond
yuuji@72 596 ((eq compl t)
yuuji@72 597 (if quick (exit-minibuffer)
yuuji@72 598 (let ((p (point)) (max (point-max)))
yuuji@72 599 (unwind-protect
yuuji@72 600 (progn
yuuji@72 601 (goto-char max)
yuuji@72 602 (insert " [Sole completion]")
yuuji@72 603 (goto-char p)
yuuji@72 604 (sit-for 1))
yuuji@72 605 (delete-region max (point-max))
yuuji@72 606 (goto-char p)))))
yuuji@72 607 ((eq compl nil)
yuuji@72 608 (ding)
yuuji@72 609 (save-excursion
yuuji@72 610 (let (p)
yuuji@72 611 (unwind-protect
yuuji@72 612 (progn
yuuji@72 613 (goto-char (setq p (point-max)))
yuuji@72 614 (insert " [No match]")
yuuji@72 615 (goto-char p)
yuuji@72 616 (sit-for 2))
yuuji@72 617 (delete-region p (point-max))))))
yuuji@72 618 ((string= compl word)
yuuji@72 619 (funcall displist))
yuuji@72 620 (t (delete-region beg (point-max))
yuuji@72 621 (insert compl)
yuuji@72 622 (if quick
yuuji@72 623 (if (eq (try-completion compl minibuffer-completion-table) t)
yuuji@72 624 (exit-minibuffer)
yuuji@72 625 (funcall displist)))))
yuuji@72 626 (store-match-data md))))
yuuji@23 627
yuuji@51 628 (defun YaTeX-minibuffer-quick-complete ()
yuuji@51 629 "Set 'quick to 't and call YaTeX-minibuffer-complete.
yuuji@51 630 See documentation of YaTeX-minibuffer-complete."
yuuji@51 631 (interactive)
yuuji@51 632 (let ((quick t))
yuuji@51 633 (self-insert-command 1)
yuuji@51 634 (YaTeX-minibuffer-complete)))
yuuji@51 635
yuuji@51 636 (defun foreach-buffers (pattern job)
yuuji@51 637 "For each buffer which matches with PATTERN, do JOB."
yuuji@51 638 (let ((list (buffer-list)))
yuuji@51 639 (save-excursion
yuuji@51 640 (while list
yuuji@51 641 (set-buffer (car list))
yuuji@51 642 (if (or (and (stringp pattern)
yuuji@51 643 (buffer-file-name)
yuuji@51 644 (string-match pattern (buffer-file-name)))
yuuji@51 645 (and (symbolp pattern) major-mode (eq major-mode pattern)))
yuuji@51 646 (eval job))
yuuji@69 647 (setq list (cdr list))))))
yuuji@51 648
yuuji@51 649 (defun goto-buffer-window (buffer)
yuuji@51 650 "Select window which is bound to BUFFER.
yuuji@51 651 If no such window exist, switch to buffer BUFFER."
yuuji@52 652 (interactive "BGoto buffer: ")
yuuji@51 653 (if (stringp buffer)
yuuji@51 654 (setq buffer (or (get-file-buffer buffer) (get-buffer buffer))))
yuuji@51 655 (if (get-buffer buffer)
yuuji@51 656 (cond
yuuji@51 657 ((get-buffer-window buffer)
yuuji@51 658 (select-window (get-buffer-window buffer)))
yuuji@51 659 ((and YaTeX-emacs-19 (get-buffer-window buffer t))
yuuji@51 660 (let*((win (get-buffer-window buffer t))
yuuji@51 661 (frame (window-frame win)))
yuuji@51 662 (select-frame frame)
yuuji@51 663 (raise-frame frame)
yuuji@51 664 (focus-frame frame)
yuuji@51 665 (select-window win)
yuuji@51 666 (set-mouse-position frame 0 0)
yuuji@51 667 (and (featurep 'windows) (fboundp 'win:adjust-window)
yuuji@51 668 (win:adjust-window))))
yuuji@54 669 ((and (featurep 'windows) (fboundp 'win:get-buffer-window)
yuuji@56 670 (let ((w (win:get-buffer-window buffer)))
yuuji@56 671 (and w (win:switch-window w))))
yuuji@54 672 (select-window (get-buffer-window buffer)))
yuuji@69 673 (t (switch-to-buffer buffer)))))
yuuji@51 674
yuuji@51 675 ;; Here starts the functions which support gmhist-vs-Emacs19 compatible
yuuji@51 676 ;; reading with history.
yuuji@51 677 ;;;###autoload
yuuji@51 678 (defun completing-read-with-history
yuuji@51 679 (prompt table &optional predicate must-match initial hsym)
yuuji@51 680 "Completing read with general history: gmhist, Emacs-19."
yuuji@51 681 (let ((minibuffer-history
yuuji@51 682 (or (symbol-value hsym)
yuuji@51 683 (and (boundp 'minibuffer-history) minibuffer-history)))
yuuji@51 684 (minibuffer-history-symbol (or hsym 'minibuffer-history)))
yuuji@51 685 (prog1
yuuji@51 686 (if (fboundp 'completing-read-with-history-in)
yuuji@51 687 (completing-read-with-history-in
yuuji@51 688 minibuffer-history-symbol prompt table predicate must-match initial)
yuuji@51 689 (completing-read prompt table predicate must-match initial))
yuuji@51 690 (if (and YaTeX-emacs-19 hsym) (set hsym minibuffer-history)))))
yuuji@51 691
yuuji@51 692 ;;;###autoload
yuuji@51 693 (defun read-from-minibuffer-with-history (prompt &optional init map read hsym)
yuuji@51 694 "Read from minibuffer with general history: gmhist, Emacs-19."
yuuji@51 695 (cond
yuuji@51 696 (YaTeX-emacs-19
yuuji@51 697 (read-from-minibuffer prompt init map read hsym))
yuuji@51 698 (t
yuuji@51 699 (let ((minibuffer-history-symbol hsym))
yuuji@51 700 (read-from-minibuffer prompt init map read)))))
yuuji@51 701
yuuji@51 702 ;;;###autoload
yuuji@51 703 (defun read-string-with-history (prompt &optional init hsym)
yuuji@51 704 "Read string with history: gmhist(Emacs-18) and Emacs-19."
yuuji@51 705 (cond
yuuji@51 706 (YaTeX-emacs-19
yuuji@51 707 (read-from-minibuffer prompt init minibuffer-local-map nil hsym))
yuuji@51 708 ((featurep 'gmhist-mh)
yuuji@51 709 (read-with-history-in hsym prompt init))
yuuji@51 710 (t (read-string prompt init))))
yuuji@23 711
yuuji@69 712 ;;;###autoload
yuuji@69 713 (fset 'YaTeX-rassoc
yuuji@69 714 (if (and nil (fboundp 'rassoc) (subrp (symbol-function 'rassoc)))
yuuji@69 715 (symbol-function 'rassoc)
yuuji@70 716 (function
yuuji@70 717 (lambda (key list)
yuuji@70 718 (let ((l list))
yuuji@70 719 (catch 'found
yuuji@70 720 (while l
yuuji@70 721 (if (equal key (cdr (car l)))
yuuji@70 722 (throw 'found (car l)))
yuuji@70 723 (setq l (cdr l)))))))))
yuuji@70 724
yuuji@70 725 (defun YaTeX-insert-file-contents (file visit &optional beg end)
yuuji@70 726 (cond
yuuji@72 727 ((and (string< "19" emacs-version) (not (featurep 'xemacs)))
yuuji@70 728 (insert-file-contents file visit beg end))
yuuji@77 729 ((string-match "unix\\|linux" (symbol-name system-type))
yuuji@70 730 (let ((default-process-coding-system
yuuji@72 731 (and (boundp '*noconv*) (list '*noconv*)))
yuuji@72 732 (file-coding-system (and (boundp '*noconv*) '*noconv*))
yuuji@70 733 kanji-fileio-code
yuuji@70 734 (default-process-kanji-code 0))
yuuji@70 735 (call-process shell-file-name file (current-buffer) nil
yuuji@70 736 (or (and (boundp 'shell-command-option)
yuuji@70 737 shell-command-option)
yuuji@70 738 "-c")
yuuji@77 739 (format "dd bs=1 count=%d | tail -c +%d" end beg))))
yuuji@70 740 (t (insert-file-contents file))))
yuuji@70 741
yuuji@70 742 (defun YaTeX-split-string (str &optional sep null)
yuuji@70 743 "Split string STR by every occurrence of SEP(regexp).
yuuji@70 744 If the optional second argument SEP is nil, it defaults to \"[ \f\t\n\r\v]+\".
yuuji@70 745 Do not include null string by default. Non-nil for optional third argument
yuuji@70 746 NULL includes null string in a list."
yuuji@70 747 (let ((sep (or sep "[ \f\t\n\r\v]+"))
yuuji@70 748 list m)
yuuji@70 749 (while str
yuuji@70 750 (if (setq m (string-match sep str))
yuuji@70 751 (progn
yuuji@70 752 (if (or (> m 0) null)
yuuji@70 753 (setq list (cons (substring str 0 m) list)))
yuuji@70 754 (setq str (substring str (match-end 0))))
yuuji@70 755 (if (or null (string< "" str))
yuuji@70 756 (setq list (cons str list)))
yuuji@70 757 (setq str nil)))
yuuji@70 758 (nreverse list)))
yuuji@69 759
yuuji@73 760 ;;;###autoload
yuuji@73 761 (defun YaTeX-delete1 (elt list)
yuuji@73 762 "Delete"
yuuji@73 763 (let (e)
yuuji@73 764 (while (setq e (YaTeX-member elt list))
yuuji@73 765 (setq list (delq (car e) list))))
yuuji@73 766 list)
yuuji@73 767 (if (fboundp 'delete)
yuuji@73 768 (fset 'YaTeX-delete (symbol-function 'delete))
yuuji@73 769 (fset 'YaTeX-delete (symbol-function 'YaTeX-delete1)))
yuuji@73 770
yuuji@73 771 (defun YaTeX-member1 (elt list)
yuuji@73 772 (catch 'found
yuuji@73 773 (while list
yuuji@73 774 (if (equal elt (car list))
yuuji@73 775 (throw 'found list))
yuuji@73 776 (setq list (cdr list)))))
yuuji@73 777
yuuji@73 778 (if (and (fboundp 'member) (subrp (symbol-function 'member)))
yuuji@73 779 (fset 'YaTeX-member (symbol-function 'member))
yuuji@73 780 (fset 'YaTeX-member (symbol-function 'YaTeX-member1)))
yuuji@73 781
yuuji@53 782 ;;;
yuuji@53 783 ;; Interface function for windows.el
yuuji@53 784 ;;;
yuuji@53 785 ;;;###autoload
yuuji@53 786 (defun YaTeX-switch-to-window ()
yuuji@53 787 "Switch to windows.el's window decided by last pressed key."
yuuji@53 788 (interactive)
yuuji@53 789 (or (featurep 'windows) (error "Why don't you use `windows.el'?"))
yuuji@53 790 (win-switch-to-window 1 (- last-command-char win:base-key)))
yuuji@53 791
yuuji@64 792 ;;;###autoload
yuuji@64 793 (defun YaTeX-reindent (col)
yuuji@64 794 "Remove current indentation and reindento to COL column."
yuuji@64 795 (save-excursion
yuuji@64 796 (beginning-of-line)
yuuji@64 797 (skip-chars-forward " \t")
yuuji@64 798 (if (/= col (current-column))
yuuji@64 799 (progn
yuuji@64 800 (delete-region (point) (progn (beginning-of-line) (point)))
yuuji@64 801 (indent-to col))))
yuuji@64 802 (skip-chars-forward " \t" (point-end-of-line)))
yuuji@64 803
yuuji@64 804 (defun YaTeX-inner-environment (&optional quick)
yuuji@64 805 "Return current inner-most environment.
yuuji@64 806 Non-nil for optional argument QUICK restricts search bound to most
yuuji@64 807 recent sectioning command. Matching point is stored to property 'point
yuuji@64 808 of 'YaTeX-inner-environment, which can be referred by
yuuji@64 809 (get 'YaTeX-inner-environment 'point)."
yuuji@73 810 (put 'YaTeX-inner-environment 'point (point-min))
yuuji@73 811 (put 'YaTeX-inner-environment 'indent 0)
yuuji@64 812 (let*((nest 0)
yuuji@64 813 (beg (YaTeX-replace-format-args
yuuji@64 814 (regexp-quote YaTeX-struct-begin)
yuuji@64 815 ;YaTeX-struct-begin ;=== TENTATIVE!! ==
yuuji@64 816 YaTeX-struct-name-regexp
yuuji@64 817 (if (eq major-mode 'yahtml-mode) "\\s *.*" "")
yuuji@64 818 ""))
yuuji@64 819 (end (YaTeX-replace-format-args
yuuji@64 820 (regexp-quote YaTeX-struct-end)
yuuji@64 821 YaTeX-struct-name-regexp "" ""))
yuuji@64 822 (begend (concat "\\(" beg "\\)\\|\\(" end "\\)"))
yuuji@64 823 bound m0
yuuji@64 824 (htmlp (eq major-mode 'yahtml-mode))
yuuji@64 825 (open
yuuji@64 826 (concat "^" (or (cdr (assq major-mode '((yahtml-mode . "<")))) "{")))
yuuji@64 827 (close
yuuji@64 828 (concat "^"
yuuji@64 829 (or (cdr(assq major-mode '((yahtml-mode . "\n\t >")))) "}"))))
yuuji@64 830 (save-excursion
yuuji@64 831 (if quick
yuuji@64 832 (setq bound
yuuji@64 833 (save-excursion
yuuji@64 834 (if htmlp
yuuji@64 835 ;;(re-search-backward YaTeX-sectioning-regexp nil 1)
yuuji@73 836 ;;(goto-char (point-min)) ;Is this enough? 97/6/26
yuuji@73 837 (re-search-backward yahtml-indentation-boundary nil 1)
yuuji@64 838 (YaTeX-re-search-active-backward
yuuji@64 839 (concat YaTeX-ec-regexp
yuuji@64 840 "\\(" YaTeX-sectioning-regexp "\\)\\*?{")
yuuji@64 841 YaTeX-comment-prefix nil 1))
yuuji@64 842 (or (bobp) (end-of-line))
yuuji@64 843 (point))))
yuuji@64 844 (if (catch 'begin
yuuji@64 845 (if (and (numberp bound) (< (point) bound)) (throw 'begin nil))
yuuji@64 846 (while (YaTeX-re-search-active-backward
yuuji@64 847 begend YaTeX-comment-prefix bound t)
yuuji@64 848 (setq m0 (match-beginning 0))
yuuji@64 849 (if (looking-at end) ;;(match-beginning 2)
yuuji@64 850 (setq nest (1+ nest))
yuuji@64 851 (setq nest (1- nest)))
yuuji@64 852 (if (< nest 0)
yuuji@64 853 (progn
yuuji@64 854 (put 'YaTeX-inner-environment 'point m0)
yuuji@64 855 (goto-char m0)
yuuji@64 856 (put 'YaTeX-inner-environment 'indent (current-column))
yuuji@64 857 (throw 'begin t)))))
yuuji@64 858 (buffer-substring
yuuji@64 859 (progn (skip-chars-forward open) (1+ (point)))
yuuji@69 860 (progn (skip-chars-forward close) (point)))))))
yuuji@64 861
yuuji@73 862 (defun YaTeX-goto-corresponding-environment (&optional allow-mismatch noerr)
yuuji@73 863 "Go to corresponding begin/end enclosure.
yuuji@73 864 Optional argument ALLOW-MISMATCH allows mismatch open/clese. Use this
yuuji@73 865 for \left(, \right).
yuuji@73 866 Optional third argument NOERR causes no error for unballanced environment."
yuuji@73 867 (interactive)
yuuji@73 868 (if (not (YaTeX-on-begin-end-p)) nil
yuuji@73 869 (let ((p (match-end 0)) b0 b1 env (nest 0) regexp re-s (op (point))
yuuji@73 870 (m0 (match-beginning 0)) ;whole matching
yuuji@73 871 (m1 (match-beginning 1)) ;environment in \begin{}
yuuji@73 872 (m2 (match-beginning 2)) ;environment in \end{}
yuuji@73 873 (m3 (match-beginning 3))) ;environment in \[ \] \( \)
yuuji@73 874 ;(setq env (regexp-quote (buffer-substring p (match-beginning 0))))
yuuji@73 875 (if (cond
yuuji@73 876 (m1 ;if begin{xxx}
yuuji@73 877 (setq env
yuuji@73 878 (if allow-mismatch YaTeX-struct-name-regexp
yuuji@73 879 (regexp-quote (buffer-substring m1 (match-end 1)))))
yuuji@73 880 ; (setq regexp (concat "\\(\\\\end{" env "}\\)\\|"
yuuji@73 881 ; "\\(\\\\begin{" env "}\\)"))
yuuji@73 882 (setq regexp
yuuji@73 883 (concat
yuuji@73 884 "\\("
yuuji@73 885 (YaTeX-replace-format-args
yuuji@73 886 (regexp-quote YaTeX-struct-end) env "" "")
yuuji@73 887 "\\)\\|\\("
yuuji@73 888 (YaTeX-replace-format-args
yuuji@73 889 (regexp-quote YaTeX-struct-begin) env "" "")
yuuji@73 890 "\\)"))
yuuji@73 891 (setq re-s 're-search-forward))
yuuji@73 892 (m2 ;if end{xxx}
yuuji@73 893 (setq env
yuuji@73 894 (if allow-mismatch YaTeX-struct-name-regexp
yuuji@73 895 (regexp-quote (buffer-substring m2 (match-end 2)))))
yuuji@73 896 ; (setq regexp (concat "\\(\\\\begin{" env "}\\)\\|"
yuuji@73 897 ; "\\(\\\\end{" env "}\\)"))
yuuji@73 898 (setq regexp
yuuji@73 899 (concat
yuuji@73 900 "\\("
yuuji@73 901 (YaTeX-replace-format-args
yuuji@73 902 (regexp-quote YaTeX-struct-begin) env "" "")
yuuji@73 903 "\\)\\|\\("
yuuji@73 904 (YaTeX-replace-format-args
yuuji@73 905 (regexp-quote YaTeX-struct-end) env "" "")
yuuji@73 906 "\\)"))
yuuji@73 907 (setq re-s 're-search-backward))
yuuji@73 908 (m3 ;math environment
yuuji@73 909 (setq env (char-after (1+ m3))
yuuji@73 910 regexp (format "\\(%s%s\\)\\|\\(%s%s\\)"
yuuji@73 911 YaTeX-ec-regexp
yuuji@73 912 (regexp-quote
yuuji@73 913 (cdr (assq env '((?( . ")") (?) . "(")
yuuji@73 914 (?[ . "]") (?] . "[")))))
yuuji@73 915 YaTeX-ec-regexp
yuuji@73 916 (regexp-quote (char-to-string env)))
yuuji@73 917 re-s (if (memq env '(?\( ?\[))
yuuji@73 918 're-search-forward
yuuji@73 919 're-search-backward)))
yuuji@73 920 (t (if noerr nil (error "Corresponding environment not found."))))
yuuji@73 921 (progn
yuuji@73 922 (while (and (>= nest 0) (funcall re-s regexp nil t))
yuuji@73 923 (setq b0 (match-beginning 0) b1 (match-beginning 1))
yuuji@73 924 (if (or (equal b0 m0)
yuuji@73 925 (YaTeX-literal-p b0))
yuuji@73 926 nil
yuuji@73 927 (setq nest (if (equal b0 b1)
yuuji@73 928 (1- nest) (1+ nest)))))
yuuji@73 929 (if (< nest 0)
yuuji@73 930 (goto-char (match-beginning 0)) ;found.
yuuji@73 931 (goto-char op)
yuuji@73 932 (funcall
yuuji@73 933 (if noerr 'message 'error)
yuuji@73 934 "Corresponding environment `%s' not found." env)
yuuji@73 935 (sit-for 1)
yuuji@73 936 nil))))))
yuuji@73 937
yuuji@64 938 (defun YaTeX-end-environment ()
yuuji@64 939 "Close opening environment"
yuuji@64 940 (interactive)
yuuji@64 941 (let ((env (YaTeX-inner-environment)))
yuuji@64 942 (if (not env) (error "No premature environment")
yuuji@64 943 (save-excursion
yuuji@64 944 (if (YaTeX-search-active-forward
yuuji@64 945 (YaTeX-replace-format-args YaTeX-struct-end env "" "")
yuuji@64 946 YaTeX-comment-prefix nil t)
yuuji@64 947 (if (y-or-n-p
yuuji@64 948 (concat "Environment `" env
yuuji@64 949 "' may be already closed. Force close?"))
yuuji@64 950 nil
yuuji@64 951 (error "end environment aborted."))))
yuuji@64 952 (message "") ;Erase (y or n) message.
yuuji@64 953 (YaTeX-insert-struc 'end env)
yuuji@64 954 (save-excursion
yuuji@64 955 (goto-char (or (get 'YaTeX-inner-environment 'point) (match-end 0)))
yuuji@64 956 (if (pos-visible-in-window-p)
yuuji@64 957 (sit-for (if YaTeX-dos 2 1))
yuuji@64 958 (message "Matches with %s at line %d"
yuuji@64 959 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
yuuji@69 960 (count-lines (point-min) (point))))))))
yuuji@64 961
yuuji@70 962 (defun YaTeX-beginning-of-environment (&optional limit-search-bound end)
yuuji@70 963 "Goto the beginning of the current environment.
yuuji@70 964 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound to
yuuji@70 965 most recent sectioning command. Non-nil for optional third argument END
yuuji@70 966 goes to end of environment."
yuuji@70 967 (interactive)
yuuji@70 968 (let ((op (point)))
yuuji@70 969 (if (YaTeX-inner-environment limit-search-bound)
yuuji@70 970 (progn
yuuji@70 971 (goto-char (get 'YaTeX-inner-environment 'point))
yuuji@70 972 (and end (YaTeX-goto-corresponding-environment))
yuuji@70 973 (if (interactive-p) (push-mark op))
yuuji@70 974 t))))
yuuji@70 975
yuuji@70 976 (defun YaTeX-end-of-environment (&optional limit-search-bound)
yuuji@70 977 "Goto the end of the current environment.
yuuji@70 978 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound
yuuji@70 979 to most recent sectioning command."
yuuji@70 980 (interactive)
yuuji@70 981 (YaTeX-beginning-of-environment limit-search-bound t))
yuuji@70 982
yuuji@70 983 (defun YaTeX-mark-environment ()
yuuji@70 984 "Mark current position and move point to end of environment."
yuuji@70 985 (interactive)
yuuji@70 986 (let ((curp (point)))
yuuji@70 987 (if (and (YaTeX-on-begin-end-p) (match-beginning 1)) ;if on \\begin
yuuji@70 988 (forward-line 1)
yuuji@70 989 (beginning-of-line))
yuuji@70 990 (if (not (YaTeX-end-of-environment)) ;arg1 turns to match-beginning 1
yuuji@70 991 (progn
yuuji@70 992 (goto-char curp)
yuuji@70 993 (error "Cannot found the end of current environment."))
yuuji@70 994 (YaTeX-goto-corresponding-environment)
yuuji@70 995 (beginning-of-line) ;for confirmation
yuuji@70 996 (if (< curp (point))
yuuji@70 997 (progn
yuuji@70 998 (message "Mark this environment?(y or n): ")
yuuji@70 999 (if (= (read-char) ?y) nil
yuuji@70 1000 (goto-char curp)
yuuji@70 1001 (error "Abort. Please call again at more proper position."))))
yuuji@70 1002 (set-mark-command nil)
yuuji@70 1003 (YaTeX-goto-corresponding-environment)
yuuji@70 1004 (end-of-line)
yuuji@70 1005 (if (eobp) nil (forward-char 1)))))
yuuji@70 1006
yuuji@72 1007 (defun YaTeX-kill-buffer (buffer)
yuuji@72 1008 "Make effort to show parent buffer after kill."
yuuji@72 1009 (interactive "bKill buffer: ")
yuuji@72 1010 (or (get-buffer buffer)
yuuji@72 1011 (error "No such buffer %s" buffer))
yuuji@72 1012 (let ((pf YaTeX-parent-file))
yuuji@72 1013 (kill-buffer buffer)
yuuji@72 1014 (and pf
yuuji@72 1015 (get-file-buffer pf)
yuuji@72 1016 (switch-to-buffer (get-file-buffer pf)))))
yuuji@70 1017
yuuji@64 1018 ;;;VER2
yuuji@64 1019 (defun YaTeX-insert-struc (what env)
yuuji@64 1020 (cond
yuuji@64 1021 ((eq what 'begin)
yuuji@64 1022 (insert (YaTeX-replace-format-args
yuuji@64 1023 YaTeX-struct-begin env (YaTeX-addin env))))
yuuji@64 1024 ((eq what 'end)
yuuji@64 1025 (insert (YaTeX-replace-format-args YaTeX-struct-end env)))
yuuji@69 1026 (t nil)))
yuuji@64 1027
yuuji@64 1028 ;;; Function for menu support
yuuji@64 1029 (defun YaTeX-define-menu (keymap bindlist)
yuuji@64 1030 "Define KEYMAP(symbol)'s menu-bindings according to BINDLIST.
yuuji@64 1031 KEYMAP should be a quoted symbol of newly allocated keymap.
yuuji@64 1032 BINDLIST consists of binding list. Each element is as follows.
yuuji@64 1033
yuuji@64 1034 '(menusymbol DOC_String . contents)
yuuji@64 1035
yuuji@64 1036 CONTENTS is one of lambda-form, interactive function, or other keymap.
yuuji@64 1037 See yatex19.el for example."
yuuji@64 1038 (cond
yuuji@64 1039 ((featurep 'xemacs)
yuuji@64 1040 (let (name)
yuuji@64 1041 (if (keymapp (symbol-value keymap))
yuuji@64 1042 (progn
yuuji@64 1043 (setq name (keymap-name (symbol-value keymap)))
yuuji@64 1044 (set keymap nil))
yuuji@64 1045 (setq name (car (symbol-value keymap)))
yuuji@64 1046 (set keymap (cdr (symbol-value keymap))))
yuuji@64 1047 (mapcar
yuuji@64 1048 (function
yuuji@64 1049 (lambda (bind)
yuuji@64 1050 (setq bind (cdr bind))
yuuji@64 1051 (if (eq (car-safe (cdr bind)) 'lambda)
yuuji@64 1052 (setcar (cdr bind) 'progn))
yuuji@64 1053 (if (stringp (car-safe (cdr bind)))
yuuji@64 1054 (set keymap
yuuji@64 1055 (cons (cdr bind) (symbol-value keymap)))
yuuji@64 1056 (set keymap
yuuji@64 1057 (cons (vector (car bind) (cdr bind) t)
yuuji@64 1058 (symbol-value keymap))))))
yuuji@64 1059 bindlist)
yuuji@64 1060 (set keymap (cons name (symbol-value keymap)))))
yuuji@64 1061 (t
yuuji@64 1062 (mapcar
yuuji@64 1063 (function
yuuji@64 1064 (lambda (bind)
yuuji@64 1065 (define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
yuuji@64 1066 bindlist))))
yuuji@64 1067
yuuji@72 1068 ;;;
yuuji@72 1069 ;; Emacs 21 compensational wrapper
yuuji@72 1070 ;;;
yuuji@72 1071 (defun YaTeX-minibuffer-begin ()
yuuji@72 1072 (if (fboundp 'field-beginning)
yuuji@72 1073 (field-beginning (point-max))
yuuji@72 1074 (point-min)))
yuuji@72 1075
yuuji@72 1076 (defun YaTeX-minibuffer-end ()
yuuji@72 1077 (if (fboundp 'field-end)
yuuji@72 1078 (field-end (point-max))
yuuji@72 1079 (point-max)))
yuuji@72 1080
yuuji@72 1081 (defun YaTeX-minibuffer-string ()
yuuji@72 1082 (buffer-substring (YaTeX-minibuffer-begin) (YaTeX-minibuffer-end)))
yuuji@72 1083
yuuji@72 1084 (defun YaTeX-minibuffer-erase ()
yuuji@72 1085 (if (eq (selected-window) (minibuffer-window))
yuuji@72 1086 (if (fboundp 'delete-field) (delete-field) (erase-buffer))))
yuuji@72 1087
yuuji@72 1088 ;;;
yuuji@72 1089 ;; hilit19 vs. font-lock
yuuji@72 1090 ;;;
yuuji@72 1091 (defun YaTeX-convert-pattern-hilit2fontlock (h19pa)
yuuji@72 1092 "Convert hilit19's H19PA patterns alist to font-lock's one.
yuuji@72 1093 This function is a makeshift for YaTeX and yahtml."
yuuji@72 1094 (let ((ignorecase (not (null (car h19pa))))
yuuji@72 1095 (palist (cdr h19pa))
yuuji@72 1096 flpa i newface
yuuji@72 1097 (mapping
yuuji@72 1098 '((bold . YaTeX-font-lock-bold-face)
yuuji@72 1099 (italic . YaTeX-font-lock-italic-face)
yuuji@73 1100 (defun . font-lock-function-name-face)
yuuji@73 1101 (define . font-lock-variable-name-face)
yuuji@72 1102 (keyword . font-lock-keyword-face)
yuuji@72 1103 (decl . YaTeX-font-lock-declaration-face)
yuuji@72 1104 (label . YaTeX-font-lock-label-face)
yuuji@72 1105 (crossref . YaTeX-font-lock-crossref-face)
yuuji@72 1106 (include . YaTeX-font-lock-include-face)
yuuji@72 1107 (formula . YaTeX-font-lock-formula-face)
yuuji@72 1108 (string . ignore) (comment . ignore)
yuuji@72 1109 )))
yuuji@72 1110 (while (setq i (car palist))
yuuji@72 1111 (setq newface (nth 2 i)
yuuji@72 1112 newface (or (cdr (assq newface mapping)) newface))
yuuji@72 1113 (cond
yuuji@72 1114 ((eq newface 'ignore) nil) ;no translation
yuuji@72 1115 ((stringp (car i)) ;hiliting by regexp
yuuji@72 1116 (setq flpa
yuuji@72 1117 (cons
yuuji@72 1118 (if (numberp (car (cdr i)))
yuuji@72 1119 (list (car i) ;regexp
yuuji@72 1120 (car (cdr i)) ;matching group number
yuuji@73 1121 newface nil) ;'keep) ;keep is hilit19 taste
yuuji@72 1122 (list
yuuji@72 1123 (concat
yuuji@72 1124 (car i) ;original regexp and..
yuuji@72 1125 ;;"[^"
yuuji@72 1126 ;;(regexp-quote (substring (car (cdr i)) 0 1))
yuuji@72 1127 ;;"]+" ;for shortest match
yuuji@72 1128 ".*"
yuuji@72 1129 (car (cdr i)))
yuuji@73 1130 0 (list 'quote newface) nil)) ;;'keep))
yuuji@72 1131 flpa)))
yuuji@72 1132 ((and (symbolp (car i)) (fboundp (car i)))
yuuji@72 1133 (setq flpa
yuuji@72 1134 (cons
yuuji@72 1135 (list (car (cdr i)) ;regexp
yuuji@72 1136 (list
yuuji@72 1137 (list
yuuji@72 1138 'lambda (list 'dummy)
yuuji@72 1139 '(goto-char (match-beginning 0))
yuuji@72 1140 '(remove-text-properties
yuuji@73 1141 (point) (min (point-max) (1+ (point)))
yuuji@72 1142 '(face nil font-lock-multiline nil))
yuuji@72 1143 (list
yuuji@72 1144 'let (list '(e (match-end 0))
yuuji@72 1145 (list 'm (list (car i) (car (cdr i)))))
yuuji@72 1146 (list
yuuji@72 1147 'if 'm
yuuji@72 1148 (list
yuuji@72 1149 'YaTeX-font-lock-fillin
yuuji@72 1150 (list 'car 'm)
yuuji@72 1151 (list 'cdr 'm)
yuuji@72 1152 (list 'quote 'face)
yuuji@72 1153 (list 'quote 'font-lock)
yuuji@72 1154 (list 'quote newface))
yuuji@72 1155 '(goto-char e)
yuuji@72 1156 ))
yuuji@72 1157 nil) ;retun nil to cheat font-lock
yuuji@72 1158 nil nil)) ;pre-match, post-match both nil
yuuji@72 1159 flpa))))
yuuji@72 1160 (setq palist (cdr palist)));while
yuuji@72 1161 (if (featurep 'xemacsp)
yuuji@72 1162 (nreverse flpa)
yuuji@72 1163 flpa)))
yuuji@72 1164
yuuji@73 1165 (if (and (boundp 'YaTeX-use-font-lock)
yuuji@73 1166 YaTeX-use-font-lock)
yuuji@73 1167 (require 'font-lock))
yuuji@73 1168
yuuji@72 1169 (cond
yuuji@73 1170 ((and (featurep 'font-lock) (fboundp 'defface))
yuuji@72 1171 ;; In each defface, '(class static-color) is for Emacs-21 -nw
yuuji@72 1172 ;; '(class tty) is for XEmacs-21 -nw
yuuji@72 1173 (defface YaTeX-font-lock-label-face
yuuji@72 1174 '((((class static-color)) (:foreground "yellow" :underline t))
yuuji@72 1175 (((type tty)) (:foreground "yellow" :underline t))
yuuji@72 1176 (((class color) (background dark)) (:foreground "pink" :underline t))
yuuji@72 1177 (((class color) (background light)) (:foreground "red" :underline t))
yuuji@72 1178 (t (:bold t :underline t)))
yuuji@72 1179 "Font Lock mode face used to highlight labels."
yuuji@72 1180 :group 'font-lock-faces)
yuuji@72 1181 (defvar YaTeX-font-lock-label-face 'YaTeX-font-lock-label-face)
yuuji@72 1182
yuuji@72 1183 (defface YaTeX-font-lock-declaration-face
yuuji@72 1184 '((((class color) (background dark)) (:foreground "cyan"))
yuuji@72 1185 (((class color) (background light)) (:foreground "RoyalBlue"))
yuuji@72 1186 (t (:bold t :underline t)))
yuuji@72 1187 "Font Lock mode face used to highlight some declarations."
yuuji@72 1188 :group 'font-lock-faces)
yuuji@72 1189 (defvar YaTeX-font-lock-declaration-face 'YaTeX-font-lock-declaration-face)
yuuji@72 1190
yuuji@72 1191 (defface YaTeX-font-lock-include-face
yuuji@72 1192 '((((class color) (background dark)) (:foreground "Plum1"))
yuuji@72 1193 (((class color) (background light)) (:foreground "purple"))
yuuji@72 1194 (t (:bold t :underline t)))
yuuji@72 1195 "Font Lock mode face used to highlight expression for including."
yuuji@72 1196 :group 'font-lock-faces)
yuuji@72 1197 (defvar YaTeX-font-lock-include-face 'YaTeX-font-lock-include-face)
yuuji@72 1198
yuuji@72 1199 (defface YaTeX-font-lock-formula-face
yuuji@72 1200 '((((class static-color)) (:bold t))
yuuji@72 1201 (((type tty)) (:bold t))
yuuji@72 1202 (((class color) (background dark)) (:foreground "khaki" :bold t))
yuuji@72 1203 (((class color) (background light)) (:foreground "Goldenrod"))
yuuji@72 1204 (t (:bold t :underline t)))
yuuji@72 1205 "Font Lock mode face used to highlight formula."
yuuji@72 1206 :group 'font-lock-faces)
yuuji@72 1207 (defvar YaTeX-font-lock-formula-face 'YaTeX-font-lock-formula-face)
yuuji@72 1208
yuuji@72 1209 (defface YaTeX-font-lock-crossref-face
yuuji@72 1210 '((((class color) (background dark)) (:foreground "lightgoldenrod"))
yuuji@72 1211 (((class color) (background light)) (:foreground "DarkGoldenrod"))
yuuji@72 1212 (t (:bold t :underline t)))
yuuji@72 1213 "Font Lock mode face used to highlight cress references."
yuuji@72 1214 :group 'font-lock-faces)
yuuji@72 1215 (defvar YaTeX-font-lock-crossref-face 'YaTeX-font-lock-crossref-face)
yuuji@72 1216
yuuji@72 1217 (defface YaTeX-font-lock-bold-face
yuuji@72 1218 '((t (:bold t)))
yuuji@72 1219 "Font Lock mode face used to express bold itself."
yuuji@72 1220 :group 'font-lock-faces)
yuuji@72 1221 (defvar YaTeX-font-lock-bold-face 'YaTeX-font-lock-bold-face)
yuuji@72 1222
yuuji@72 1223 (defface YaTeX-font-lock-italic-face
yuuji@72 1224 '((t (:italic t)))
yuuji@72 1225 "Font Lock mode face used to express italic itself."
yuuji@72 1226 :group 'font-lock-faces)
yuuji@72 1227 (defvar YaTeX-font-lock-italic-face 'YaTeX-font-lock-italic-face)
yuuji@72 1228
yuuji@72 1229 ;; Make sure the 'YaTeX-font-lock-{italic,bold}-face is bound with
yuuji@72 1230 ;; italic/bold fontsets
yuuji@72 1231 (if (and (fboundp 'fontset-list) YaTeX-use-italic-bold)
yuuji@73 1232 (let ((flist (fontset-list)) fnt italic bold
yuuji@73 1233 (df (or (and (fboundp 'face-font-name) (face-font-name 'default))
yuuji@73 1234 (face-font 'default)
yuuji@73 1235 (face-font 'italic)
yuuji@73 1236 (face-font 'bold)
yuuji@73 1237 "giveup!"))
yuuji@73 1238 sz medium-i bold-r)
yuuji@73 1239 (string-match
yuuji@73 1240 "^-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-\\(\\([0-9]+\\)\\)" df)
yuuji@73 1241 (setq sz (or (match-string 1 df) "16"))
yuuji@73 1242 (setq medium-i (format "-medium-i-[^-]+--%s" sz)
yuuji@73 1243 bold-r (format "-bold-r-[^-]+--%s" sz))
yuuji@72 1244 (while flist
yuuji@72 1245 (setq fnt (car flist))
yuuji@72 1246 (condition-case err
yuuji@72 1247 (cond
yuuji@73 1248 ((and (string-match medium-i fnt)
yuuji@73 1249 (null italic))
yuuji@72 1250 (set-face-font 'YaTeX-font-lock-italic-face (setq italic fnt)))
yuuji@73 1251 ((and (string-match bold-r fnt) (null bold))
yuuji@72 1252 (set-face-font 'YaTeX-font-lock-bold-face (setq bold fnt))))
yuuji@72 1253 (error nil))
yuuji@72 1254 (setq flist (cdr flist)))))
yuuji@72 1255
yuuji@72 1256 ;;Borrowed from XEmacs's font-lock.el
yuuji@72 1257 (defsubst YaTeX-font-lock-fillin (start end setprop markprop value &optional object)
yuuji@72 1258 "Fill in one property of the text from START to END.
yuuji@72 1259 Arguments PROP and VALUE specify the property and value to put where none are
yuuji@72 1260 already in place. Therefore existing property values are not overwritten.
yuuji@72 1261 Optional argument OBJECT is the string or buffer containing the text."
yuuji@72 1262 (let ((start (text-property-any start end markprop nil object)) next
yuuji@72 1263 (putfunc (if (fboundp 'put-nonduplicable-text-property)
yuuji@72 1264 'put-nonduplicable-text-property
yuuji@72 1265 'put-text-property)))
yuuji@72 1266 (if (eq putfunc 'put-text-property)
yuuji@72 1267 (setq markprop setprop))
yuuji@72 1268 (while start
yuuji@72 1269 (setq next (next-single-property-change start markprop object end))
yuuji@72 1270 (funcall putfunc start next setprop value object)
yuuji@72 1271 (funcall putfunc start next markprop value object)
yuuji@72 1272 (setq start (text-property-any next end markprop nil object)))))
yuuji@72 1273
yuuji@72 1274 (defun YaTeX-warning-font-lock (mode)
yuuji@72 1275 (let ((sw (selected-window)))
yuuji@72 1276 ;;(pop-to-buffer (format " *%s warning*" mode))
yuuji@72 1277 ;;(erase-buffer)
yuuji@72 1278 (momentary-string-display
yuuji@72 1279 (cond
yuuji@72 1280 (YaTeX-japan
yuuji@72 1281 (concat mode " は、既に font-lock に対応しました。\n"
yuuji@72 1282 "~/.emacs などにある\n"
yuuji@72 1283 "\t(put 'yatex-mode 'font-lock-keywords 'tex-mode)\n"
yuuji@72 1284 "\t(put 'yahtml-mode 'font-lock-keywords 'html-mode)\n"
yuuji@72 1285 "などの間に合わせの記述はもはや不要です。"))
yuuji@72 1286 (t
yuuji@72 1287 (concat mode " now supports the font-lock by itself.\n"
yuuji@72 1288 "So you can remove the descriptions such as\n"
yuuji@72 1289 "\t(put 'yatex-mode 'font-lock-keywords 'tex-mode)\n"
yuuji@72 1290 "\t(put 'yahtml-mode 'font-lock-keywords 'html-mode)\n"
yuuji@72 1291 "in your ~/.emacs file. Thank you."))) (point))
yuuji@72 1292 (select-window sw)))
yuuji@72 1293 ))
yuuji@72 1294
yuuji@64 1295
yuuji@68 1296 ;;;
yuuji@68 1297 ;; Functions for the Installation time
yuuji@68 1298 ;;;
yuuji@64 1299
yuuji@58 1300 (defun bcf-and-exit ()
yuuji@58 1301 "Byte compile rest of argument and kill-emacs."
yuuji@58 1302 (if command-line-args-left
yuuji@68 1303 (let ((load-path (cons "." load-path)))
yuuji@68 1304 (and (fboundp 'set-language-environment)
yuuji@68 1305 (featurep 'mule)
yuuji@68 1306 (set-language-environment "Japanese"))
yuuji@58 1307 (mapcar 'byte-compile-file command-line-args-left)
yuuji@58 1308 (kill-emacs))))
yuuji@64 1309
yuuji@23 1310 (provide 'yatexlib)
yuuji@72 1311 ; Local variables:
yuuji@72 1312 ; fill-prefix: ";;; "
yuuji@72 1313 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@72 1314 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@72 1315 ; buffer-file-coding-system: sjis
yuuji@72 1316 ; End: