yatex

annotate yatexlib.el @ 70:44e3a5e1e883

Fix makefile for Windows Brush up label completion \cite completion Support much more about LaTeX2e --- [yahtml] English Info (By Jun Ohya) Automatic pixel size detection for <img src="..."> Aware global-class of css definition & for char-entity reference
author yuuji
date Sun, 09 Apr 2000 03:37:47 +0000
parents 807c1e7e68b7
children 0aaebd07dad0
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@70 4 ;;; (c )1994-2000 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@70 5 ;;; Last modified Sun Apr 9 12:36:25 2000 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@64 12 (defvar YaTeX-user-completion-table
yuuji@64 13 (if YaTeX-dos "~/_yatexrc" "~/.yatexrc")
yuuji@64 14 "*Default filename in which user completion table is saved.")
yuuji@64 15
yuuji@64 16 (defvar YaTeX-japan (or (boundp 'NEMACS) (boundp 'MULE) YaTeX-emacs-20)
yuuji@64 17 "Whether yatex mode is running on Japanese environment or not.")
yuuji@64 18
yuuji@70 19 ;; autoload from yahtml.el
yuuji@70 20 (autoload 'yahtml-inner-environment-but "yahtml" "yahtml internal func." t)
yuuji@70 21
yuuji@64 22 (defvar YaTeX-kanji-code-alist
yuuji@64 23 (cond
yuuji@64 24 ((boundp '*junet*)
yuuji@64 25 (list (cons
yuuji@64 26 1
yuuji@64 27 (if YaTeX-dos (if (boundp '*sjis-dos*) *sjis-dos* *sjis*dos)
yuuji@64 28 *sjis*))
yuuji@64 29 '(2 . *junet*) '(3 . *euc-japan*)))
yuuji@64 30 (YaTeX-emacs-20
yuuji@64 31 ;;(cdr-safe(assq 'coding-system (assoc "Japanese" language-info-alist)))
yuuji@64 32 (list (cons
yuuji@64 33 1 (cond (YaTeX-dos 'shift_jis-dos)
yuuji@64 34 ((member 'shift_jis (coding-system-list)) 'shift_jis-unix)
yuuji@64 35 (t 'sjis)))
yuuji@68 36 '(2 . iso-2022-jp-unix)
yuuji@68 37 '(3 . euc-jp-unix))))
yuuji@64 38 "Kanji-code expression translation table.")
yuuji@64 39 (defvar YaTeX-inhibit-prefix-letter nil
yuuji@64 40 "*T for changing key definitions from [prefix] Letter to [prefix] C-Letter.")
yuuji@64 41
yuuji@64 42 (defvar YaTeX-no-begend-shortcut nil
yuuji@64 43 "*T for disabling shortcut of begin-type completion, [prefix] b d, etc.")
yuuji@64 44
yuuji@64 45 (defvar YaTeX-default-pop-window-height 10
yuuji@64 46 "Default typesetting buffer height.
yuuji@64 47 If integer, sets the window-height of typesetting buffer.
yuuji@64 48 If string, sets the percentage of it.
yuuji@64 49 If nil, use default pop-to-buffer.")
yuuji@64 50
yuuji@64 51 (defvar YaTeX-create-file-prefix-g nil
yuuji@64 52 "*Non-nil creates new file when [prefix] g on \\include{foo}.")
yuuji@64 53
yuuji@64 54 (defvar YaTeX-nervous t
yuuji@64 55 "*If you are nervous about maintenance of yatexrc, set this value to T.
yuuji@64 56 And you will have the local dictionary.")
yuuji@64 57
yuuji@64 58 ;----------- work variables ----------------------------------------
yuuji@64 59 (defvar YaTeX-typesetting-mode-map nil
yuuji@69 60 "Keymap used in YaTeX typesetting buffer")
yuuji@69 61
yuuji@64 62 (if YaTeX-typesetting-mode-map nil
yuuji@64 63 (setq YaTeX-typesetting-mode-map (make-keymap))
yuuji@64 64 ;(suppress-keymap YaTeX-typesetting-mode-map t)
yuuji@64 65 (define-key YaTeX-typesetting-mode-map " " 'YaTeX-jump-error-line)
yuuji@64 66 (define-key YaTeX-typesetting-mode-map "\C-m" 'YaTeX-send-string)
yuuji@64 67 (define-key YaTeX-typesetting-mode-map "1" 'delete-other-windows)
yuuji@64 68 (define-key YaTeX-typesetting-mode-map "0" 'delete-window)
yuuji@64 69 (define-key YaTeX-typesetting-mode-map "q" 'delete-window))
yuuji@64 70
yuuji@64 71 (defvar YaTeX-parent-file nil
yuuji@64 72 "*Main LaTeX source file name used when %#! expression doesn't exist.")
yuuji@64 73 (make-variable-buffer-local 'YaTeX-parent-file)
yuuji@64 74
yuuji@64 75 ;---------- Define default key bindings on YaTeX mode map ----------
yuuji@64 76 ;;;###autoload
yuuji@64 77 (defun YaTeX-define-key (key binding &optional map)
yuuji@64 78 "Define key on YaTeX-prefix-map."
yuuji@64 79 (if YaTeX-inhibit-prefix-letter
yuuji@64 80 (let ((c (aref key 0)))
yuuji@64 81 (cond
yuuji@64 82 ((and (>= c ?a) (<= c ?z)) (aset key 0 (1+ (- c ?a))))
yuuji@64 83 ((and (>= c ?A) (<= c ?Z) (numberp YaTeX-inhibit-prefix-letter))
yuuji@64 84 (aset key 0 (1+ (- c ?A))))
yuuji@64 85 (t nil))))
yuuji@64 86 (define-key (or map YaTeX-prefix-map) key binding))
yuuji@64 87
yuuji@64 88 ;;;###autoload
yuuji@64 89 (defun YaTeX-local-table-symbol (symbol)
yuuji@64 90 "Return the lisp symbol which keeps local completion table of SYMBOL."
yuuji@64 91 (intern (concat "YaTeX$"
yuuji@64 92 default-directory
yuuji@64 93 (symbol-name symbol))))
yuuji@64 94
yuuji@64 95 ;;;###autoload
yuuji@64 96 (defun YaTeX-sync-local-table (symbol)
yuuji@64 97 "Synchronize local variable SYMBOL.
yuuji@64 98 Copy its corresponding directory dependent completion table to SYMBOL."
yuuji@64 99 (if (boundp (YaTeX-local-table-symbol symbol))
yuuji@64 100 (set symbol (symbol-value (YaTeX-local-table-symbol symbol)))))
yuuji@64 101
yuuji@64 102 (defvar YaTeX-user-table-is-read nil
yuuji@64 103 "Flag that means whether user completion table has been read or not.")
yuuji@64 104 ;;;###autoload
yuuji@64 105 (defun YaTeX-read-user-completion-table (&optional forcetoread)
yuuji@64 106 "Append user completion table of LaTeX macros"
yuuji@64 107 (let*((user-table (expand-file-name YaTeX-user-completion-table))
yuuji@64 108 (local-table (expand-file-name (file-name-nondirectory user-table)))
yuuji@64 109 var localvar localbuf (curbuf (current-buffer)) sexp)
yuuji@64 110 (if YaTeX-user-table-is-read nil
yuuji@64 111 (message "Loading user completion table")
yuuji@64 112 (if (file-exists-p user-table) (load-file user-table)
yuuji@64 113 (message "Welcome to the field of YaTeX. I'm glad to see you!")))
yuuji@64 114 (setq YaTeX-user-table-is-read t)
yuuji@64 115 (cond
yuuji@64 116 ((file-exists-p local-table)
yuuji@64 117 (set-buffer (setq localbuf (find-file-noselect local-table)))
yuuji@64 118 (widen)
yuuji@64 119 (goto-char (point-min))
yuuji@64 120 (while (re-search-forward "(setq \\([^ ]+\\)" nil t)
yuuji@64 121 (setq var (intern (buffer-substring
yuuji@64 122 (match-beginning 1) (match-end 1)))
yuuji@64 123 localvar (YaTeX-local-table-symbol var))
yuuji@64 124 (goto-char (match-beginning 0))
yuuji@64 125 (setq sexp (buffer-substring (point)
yuuji@64 126 (progn (forward-sexp) (point))))
yuuji@64 127 (set-buffer curbuf)
yuuji@64 128 (or (assq var (buffer-local-variables)) (make-local-variable var))
yuuji@64 129 (eval (read sexp))
yuuji@64 130 (or (and (boundp localvar)
yuuji@64 131 (symbol-value localvar)
yuuji@64 132 (not forcetoread))
yuuji@64 133 (set localvar (symbol-value var)))
yuuji@64 134 (set-buffer localbuf))
yuuji@64 135 (kill-buffer localbuf)))
yuuji@64 136 (set-buffer curbuf)))
yuuji@64 137
yuuji@64 138 ;;;###autoload
yuuji@64 139 (defun YaTeX-reload-dictionary ()
yuuji@64 140 "Reload local dictionary.
yuuji@64 141 Use this function after editing ./.yatexrc."
yuuji@64 142 (interactive)
yuuji@64 143 (let ((YaTeX-user-table-is-read nil))
yuuji@64 144 (YaTeX-read-user-completion-table t)))
yuuji@64 145
yuuji@64 146 ;;;###autoload
yuuji@64 147 (defun YaTeX-lookup-table (word type)
yuuji@64 148 "Lookup WORD in completion table whose type is TYPE.
yuuji@64 149 This function refers the symbol tmp-TYPE-table, user-TYPE-table, TYPE-table.
yuuji@64 150 Typically, TYPE is one of 'env, 'section, 'fontsize, 'singlecmd."
yuuji@64 151 (if (symbolp type) (setq type (symbol-name type)))
yuuji@64 152 (or (assoc word (symbol-value (intern (concat "tmp-" type "-table"))))
yuuji@64 153 (assoc word (symbol-value (intern (concat "user-" type "-table"))))
yuuji@64 154 (assoc word (symbol-value (intern (concat type "-table"))))))
yuuji@64 155
yuuji@64 156 ;;;###autoload
yuuji@64 157 (defun YaTeX-update-table (vallist default-table user-table local-table)
yuuji@64 158 "Update completion table if the car of VALLIST is not in current tables.
yuuji@64 159 Second argument DEFAULT-TABLE is the quoted symbol of default completion
yuuji@64 160 table, third argument USER-TABLE is user table which will be saved in
yuuji@64 161 YaTeX-user-completion-table, fourth argument LOCAL-TABLE should have the
yuuji@64 162 completion which is valid during current Emacs's session. If you
yuuji@64 163 want to make LOCAL-TABLE valid longer span (but restrict in this directory)
yuuji@64 164 create the file in current directory which has the same name with
yuuji@64 165 YaTeX-user-completion-table."
yuuji@64 166 (let ((car-v (car vallist)) key answer
yuuji@64 167 (file (file-name-nondirectory YaTeX-user-completion-table)))
yuuji@64 168 (cond
yuuji@64 169 ((assoc car-v (symbol-value default-table))
yuuji@64 170 nil) ;Nothing to do
yuuji@64 171 ((setq key (assoc car-v (symbol-value user-table)))
yuuji@64 172 (if (equal (cdr vallist) (cdr key)) nil
yuuji@64 173 ;; if association hits, but contents differ.
yuuji@64 174 (message
yuuji@64 175 "%s's attributes turned into %s" (car vallist) (cdr vallist))
yuuji@64 176 (set user-table (delq key (symbol-value user-table)))
yuuji@64 177 (set user-table (cons vallist (symbol-value user-table)))
yuuji@64 178 (YaTeX-update-dictionary
yuuji@64 179 YaTeX-user-completion-table user-table "user")))
yuuji@64 180 ((setq key (assoc car-v (symbol-value local-table)))
yuuji@64 181 (if (equal (cdr vallist) (cdr key)) nil
yuuji@64 182 (message
yuuji@64 183 "%s's attributes turned into %s" (car vallist) (cdr vallist))
yuuji@64 184 (set local-table (delq key (symbol-value local-table)))
yuuji@64 185 (set local-table (cons vallist (symbol-value local-table)))
yuuji@64 186 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
yuuji@64 187 (YaTeX-update-dictionary file local-table)))
yuuji@64 188 ;; All of above cases, there are some completion in tables.
yuuji@64 189 ;; Then update tables.
yuuji@64 190 (t
yuuji@64 191 (if (not YaTeX-nervous)
yuuji@64 192 (setq answer "u")
yuuji@64 193 (message
yuuji@64 194 (cond
yuuji@64 195 (YaTeX-japan
yuuji@68 196 "`%s'の登録先: U)ユーザ辞書 L)ローカル辞書 N)メモリ D)しない")
yuuji@64 197 (t
yuuji@64 198 "Register `%s' into: U)serDic L)ocalDic N)one D)iscard"))
yuuji@64 199 (if (> (length car-v) 23)
yuuji@68 200 (concat (substring car-v 0 10) "..." (substring car-v -9))
yuuji@64 201 car-v))
yuuji@64 202 (setq answer (char-to-string (read-char))))
yuuji@64 203 (cond
yuuji@64 204 ((string-match answer "uy")
yuuji@64 205 (set user-table (cons vallist (symbol-value user-table)))
yuuji@64 206 (YaTeX-update-dictionary YaTeX-user-completion-table user-table "user")
yuuji@64 207 )
yuuji@64 208 ((string-match answer "tl")
yuuji@64 209 (set local-table (cons vallist (symbol-value local-table)))
yuuji@64 210 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
yuuji@64 211 (YaTeX-update-dictionary file local-table))
yuuji@64 212 ((string-match answer "d") nil) ;discard it
yuuji@64 213 (t (set default-table
yuuji@64 214 (cons vallist (symbol-value default-table)))))))))
yuuji@64 215
yuuji@64 216 ;;;###autoload
yuuji@64 217 (defun YaTeX-cplread-with-learning
yuuji@64 218 (prom default-table user-table local-table
yuuji@64 219 &optional pred reqmatch init hsym)
yuuji@64 220 "Completing read with learning.
yuuji@64 221 Do a completing read with prompt PROM. Completion table is what
yuuji@64 222 DEFAULT-TABLE, USER-TABLE, LOCAL table are appended in reverse order.
yuuji@64 223 Note that these tables are passed by the symbol.
yuuji@64 224 Optional arguments PRED, REQMATH and INIT are passed to completing-read
yuuji@64 225 as its arguments PREDICATE, REQUIRE-MATCH and INITIAL-INPUT respectively.
yuuji@64 226 If optional 8th argument HSYM, history symbol, is passed, use it as
yuuji@64 227 history list variable."
yuuji@64 228 (YaTeX-sync-local-table local-table)
yuuji@64 229 (let*((table (append (symbol-value local-table)
yuuji@64 230 (symbol-value user-table)
yuuji@64 231 (symbol-value default-table)))
yuuji@64 232 (word (completing-read-with-history
yuuji@64 233 prom table pred reqmatch init hsym)))
yuuji@64 234 (if (and (string< "" word) (not (assoc word table)))
yuuji@64 235 (YaTeX-update-table (list word) default-table user-table local-table))
yuuji@64 236 word))
yuuji@64 237
yuuji@64 238 ;;;###autoload
yuuji@64 239 (defun YaTeX-update-dictionary (file symbol &optional type)
yuuji@64 240 (let ((local-table-buf (find-file-noselect file))
yuuji@64 241 (name (symbol-name symbol))
yuuji@64 242 (value (symbol-value symbol)))
yuuji@64 243 (save-excursion
yuuji@64 244 (message "Updating %s dictionary..." (or type "local"))
yuuji@64 245 (set-buffer local-table-buf)
yuuji@64 246 (goto-char (point-max))
yuuji@64 247 (search-backward (concat "(setq " name) nil t)
yuuji@64 248 (delete-region (point) (progn (forward-sexp) (point)))
yuuji@64 249 (delete-blank-lines)
yuuji@64 250 (insert "(setq " name " '(\n")
yuuji@64 251 (mapcar '(lambda (s)
yuuji@64 252 (insert (format "%s\n" (prin1-to-string s))))
yuuji@64 253 value)
yuuji@64 254 (insert "))\n\n")
yuuji@64 255 (delete-blank-lines)
yuuji@64 256 (basic-save-buffer)
yuuji@64 257 (kill-buffer local-table-buf)
yuuji@64 258 (message "Updating %s dictionary...Done" (or type "local")))))
yuuji@64 259
yuuji@64 260 ;;;###autoload
yuuji@64 261 (defun YaTeX-define-begend-key-normal (key env &optional map)
yuuji@64 262 "Define short cut YaTeX-make-begin-end key."
yuuji@64 263 (YaTeX-define-key
yuuji@64 264 key
yuuji@64 265 (list 'lambda '(arg) '(interactive "P")
yuuji@64 266 (list 'YaTeX-insert-begin-end env 'arg))
yuuji@64 267 map))
yuuji@64 268
yuuji@64 269 ;;;###autoload
yuuji@64 270 (defun YaTeX-define-begend-region-key (key env &optional map)
yuuji@64 271 "Define short cut YaTeX-make-begin-end-region key."
yuuji@64 272 (YaTeX-define-key key (list 'lambda nil '(interactive)
yuuji@64 273 (list 'YaTeX-insert-begin-end env t)) map))
yuuji@64 274
yuuji@64 275 ;;;###autoload
yuuji@64 276 (defun YaTeX-define-begend-key (key env &optional map)
yuuji@64 277 "Define short cut key for begin type completion both for normal
yuuji@64 278 and region mode. To customize YaTeX, user should use this function."
yuuji@64 279 (YaTeX-define-begend-key-normal key env map)
yuuji@64 280 (if YaTeX-inhibit-prefix-letter nil
yuuji@64 281 (YaTeX-define-begend-region-key
yuuji@64 282 (concat (upcase (substring key 0 1)) (substring key 1)) env)))
yuuji@64 283
yuuji@23 284 ;;;###autoload
yuuji@23 285 (defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func)
yuuji@23 286 "Search STRING which is not commented out by CMNTRX.
yuuji@23 287 Optional arguments after BOUND, ERR, CNT are passed literally to search-forward
yuuji@23 288 or search-backward.
yuuji@23 289 Optional sixth argument FUNC changes search-function."
yuuji@49 290 (let ((sfunc (or func 'search-forward)) found md)
yuuji@23 291 (while (and (prog1
yuuji@23 292 (setq found (funcall sfunc string bound err cnt))
yuuji@23 293 (setq md (match-data)))
yuuji@23 294 (or
yuuji@64 295 (and (eq major-mode 'yatex-mode)
yuuji@64 296 (YaTeX-in-verb-p (match-beginning 0)))
yuuji@23 297 (save-excursion
yuuji@23 298 (beginning-of-line)
yuuji@23 299 (re-search-forward cmntrx (match-beginning 0) t)))))
yuuji@23 300 (store-match-data md)
yuuji@69 301 found))
yuuji@23 302
yuuji@23 303 (defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt)
yuuji@23 304 "Search REGEXP backward which is not commented out by regexp CMNTRX.
yuuji@23 305 See also YaTeX-search-active-forward."
yuuji@69 306 (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward))
yuuji@69 307
yuuji@23 308 (defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt)
yuuji@23 309 "Search STRING backward which is not commented out by regexp CMNTRX.
yuuji@23 310 See also YaTeX-search-active-forward."
yuuji@69 311 (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward))
yuuji@69 312
yuuji@23 313 (defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt)
yuuji@23 314 "Search REGEXP backward which is not commented out by regexp CMNTRX.
yuuji@23 315 See also YaTeX-search-active-forward."
yuuji@69 316 (YaTeX-search-active-forward
yuuji@69 317 regexp cmntrx bound err cnt 're-search-backward))
yuuji@23 318
yuuji@23 319 ;;;###autoload
yuuji@23 320 (defun YaTeX-switch-to-buffer (file &optional setbuf)
yuuji@23 321 "Switch to buffer if buffer exists, find file if not.
yuuji@23 322 Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer."
yuuji@23 323 (interactive "Fswitch to file: ")
yuuji@70 324 (if (bufferp file)
yuuji@70 325 (setq file (buffer-file-name file))
yuuji@70 326 (and (string-match "^[^/].*/" file)
yuuji@70 327 (eq major-mode 'yatex-mode)
yuuji@70 328 YaTeX-search-file-from-top-directory
yuuji@70 329 (save-excursion
yuuji@70 330 (YaTeX-visit-main t)
yuuji@70 331 (setq file (expand-file-name file)))))
yuuji@52 332 (let (buf (hilit-auto-highlight (not setbuf)))
yuuji@52 333 (cond
yuuji@52 334 ((setq buf (get-file-buffer file))
yuuji@52 335 (funcall (if setbuf 'set-buffer 'switch-to-buffer)
yuuji@52 336 (get-file-buffer file))
yuuji@52 337 buf)
yuuji@52 338 ((or YaTeX-create-file-prefix-g (file-exists-p file))
yuuji@52 339 (or ;find-file returns nil but set current-buffer...
yuuji@52 340 (if setbuf (set-buffer (find-file-noselect file))
yuuji@52 341 (find-file file))
yuuji@52 342 (current-buffer)))
yuuji@52 343 (t (message "%s was not found in this directory." file)
yuuji@69 344 nil))))
yuuji@23 345
yuuji@23 346 ;;;###autoload
yuuji@23 347 (defun YaTeX-switch-to-buffer-other-window (file)
yuuji@23 348 "Switch to buffer if buffer exists, find file if not."
yuuji@23 349 (interactive "Fswitch to file: ")
yuuji@70 350 (and (eq major-mode 'yatex-mode)
yuuji@70 351 (stringp file)
yuuji@70 352 (string-match "^[^/].*/" file)
yuuji@70 353 YaTeX-search-file-from-top-directory
yuuji@70 354 (save-excursion
yuuji@70 355 (YaTeX-visit-main t)
yuuji@70 356 (setq file (expand-file-name file))))
yuuji@52 357 (if (bufferp file) (setq file (buffer-file-name file)))
yuuji@52 358 (cond
yuuji@52 359 ((get-file-buffer file)
yuuji@52 360 (switch-to-buffer-other-window (get-file-buffer file))
yuuji@52 361 t)
yuuji@52 362 ((or YaTeX-create-file-prefix-g (file-exists-p file))
yuuji@52 363 (find-file-other-window file) t)
yuuji@52 364 (t (message "%s was not found in this directory." file)
yuuji@69 365 nil)))
yuuji@23 366
yuuji@70 367 (defun YaTeX-get-file-buffer (file)
yuuji@70 368 "Return the FILE's buffer.
yuuji@70 369 Base directory is that of main file or current directory."
yuuji@70 370 (let (dir main (cdir default-directory))
yuuji@70 371 (or (and (eq major-mode 'yatex-mode)
yuuji@70 372 YaTeX-search-file-from-top-directory
yuuji@70 373 (save-excursion
yuuji@70 374 (YaTeX-visit-main t)
yuuji@70 375 (get-file-buffer file)))
yuuji@70 376 (get-file-buffer file))))
yuuji@70 377
yuuji@23 378 (defun YaTeX-replace-format-sub (string format repl)
yuuji@23 379 (let ((beg (or (string-match (concat "^\\(%" format "\\)") string)
yuuji@23 380 (string-match (concat "[^%]\\(%" format "\\)") string)))
yuuji@23 381 (len (length format)))
yuuji@23 382 (if (null beg) string ;no conversion
yuuji@23 383 (concat
yuuji@70 384 (substring string 0 (match-beginning 1)) (or repl "")
yuuji@69 385 (substring string (match-end 1))))))
yuuji@23 386
yuuji@23 387 ;;;###autoload
yuuji@23 388 (defun YaTeX-replace-format (string format repl)
yuuji@23 389 "In STRING, replace first appearance of FORMAT to REPL as if
yuuji@23 390 function `format' does. FORMAT does not contain `%'"
yuuji@23 391 (let ((ans string))
yuuji@23 392 (while (not (string=
yuuji@23 393 ans (setq string (YaTeX-replace-format-sub ans format repl))))
yuuji@23 394 (setq ans string))
yuuji@69 395 string))
yuuji@23 396
yuuji@23 397 ;;;###autoload
yuuji@70 398 (defun YaTeX-replace-formats (string replace-list)
yuuji@70 399 (let ((list replace-list))
yuuji@70 400 (while list
yuuji@70 401 (setq string (YaTeX-replace-format
yuuji@70 402 string (car (car list)) (cdr (car list)))
yuuji@70 403 list (cdr list)))
yuuji@70 404 string))
yuuji@70 405
yuuji@70 406 ;;;###autoload
yuuji@23 407 (defun YaTeX-replace-format-args (string &rest args)
yuuji@23 408 "Translate the argument mark #1, #2, ... #n in the STRING into the
yuuji@23 409 corresponding real arguments ARGS."
yuuji@23 410 (let ((argp 1))
yuuji@23 411 (while args
yuuji@23 412 (setq string
yuuji@23 413 (YaTeX-replace-format string (int-to-string argp) (car args)))
yuuji@23 414 (setq args (cdr args) argp (1+ argp))))
yuuji@69 415 string)
yuuji@23 416
yuuji@23 417 ;;;###autoload
yuuji@23 418 (defun rindex (string char)
yuuji@23 419 (let ((pos (1- (length string)))(index -1))
yuuji@23 420 (while (>= pos 0)
yuuji@23 421 (cond
yuuji@23 422 ((= (aref string pos) char)
yuuji@23 423 (setq index pos) (setq pos -1))
yuuji@23 424 (t (setq pos (1- pos))))
yuuji@23 425 )
yuuji@64 426 index))
yuuji@64 427
yuuji@64 428 ;;;###autoload
yuuji@64 429 (defun point-beginning-of-line ()
yuuji@64 430 (save-excursion (beginning-of-line)(point)))
yuuji@64 431
yuuji@64 432 ;;;###autoload
yuuji@64 433 (defun point-end-of-line ()
yuuji@64 434 (save-excursion (end-of-line)(point)))
yuuji@64 435
yuuji@23 436
yuuji@23 437 ;;;###autoload
yuuji@23 438 (defun YaTeX-showup-buffer (buffer &optional func select)
yuuji@23 439 "Make BUFFER show up in certain window (but current window)
yuuji@23 440 that gives the maximum value by the FUNC. FUNC should take an argument
yuuji@23 441 of its window object. Non-nil for optional third argument SELECT selects
yuuji@49 442 that window. This function never selects minibuffer window."
yuuji@53 443 (or (and (if (and YaTeX-emacs-19 select)
yuuji@47 444 (get-buffer-window buffer t)
yuuji@47 445 (get-buffer-window buffer))
yuuji@47 446 (progn
yuuji@47 447 (if select
yuuji@51 448 (goto-buffer-window buffer))
yuuji@47 449 t))
yuuji@23 450 (let ((window (selected-window))
yuuji@23 451 (wlist (YaTeX-window-list)) win w (x 0))
yuuji@23 452 (cond
yuuji@23 453 ((> (length wlist) 2)
yuuji@23 454 (if func
yuuji@23 455 (while wlist
yuuji@23 456 (setq w (car wlist))
yuuji@23 457 (if (and (not (eq window w))
yuuji@23 458 (> (funcall func w) x))
yuuji@23 459 (setq win w x (funcall func w)))
yuuji@23 460 (setq wlist (cdr wlist)))
yuuji@23 461 (setq win (get-lru-window)))
yuuji@23 462 (select-window win)
yuuji@23 463 (switch-to-buffer buffer)
yuuji@23 464 (or select (select-window window)))
yuuji@23 465 ((= (length wlist) 2)
yuuji@49 466 ;(other-window 1);This does not work properly on Emacs-19
yuuji@49 467 (select-window (get-lru-window))
yuuji@23 468 (switch-to-buffer buffer)
yuuji@23 469 (or select (select-window window)))
yuuji@23 470 (t ;if one-window
yuuji@23 471 (cond
yuuji@47 472 ((and YaTeX-emacs-19 (get-buffer-window buffer t))
yuuji@47 473 nil) ;if found in other frame
yuuji@23 474 (YaTeX-default-pop-window-height
yuuji@51 475 (split-window-calculate-height YaTeX-default-pop-window-height)
yuuji@59 476 ;;(pop-to-buffer buffer) ;damn! emacs-19.30
yuuji@59 477 (select-window (next-window nil 1))
yuuji@59 478 (switch-to-buffer (get-buffer-create buffer))
yuuji@23 479 (or select (select-window window)))
yuuji@23 480 (t nil)))
yuuji@69 481 ))))
yuuji@69 482
yuuji@69 483 (cond
yuuji@69 484 ((fboundp 'screen-height)
yuuji@69 485 (fset 'YaTeX-screen-height 'screen-height)
yuuji@69 486 (fset 'YaTeX-screen-width 'screen-width))
yuuji@69 487 ((fboundp 'frame-height)
yuuji@69 488 (fset 'YaTeX-screen-height 'frame-height)
yuuji@69 489 (fset 'YaTeX-screen-width 'frame-width))
yuuji@69 490 (t (error "I don't know how to run windows.el on this Emacs...")))
yuuji@23 491
yuuji@23 492 ;;;###autoload
yuuji@51 493 (defun split-window-calculate-height (height)
yuuji@51 494 "Split current window wight specified HEIGHT.
yuuji@59 495 If HEIGHT is number, make a new window that has HEIGHT lines.
yuuji@59 496 If HEIGHT is string, make a new window that occupies HEIGT % of screen height.
yuuji@51 497 Otherwise split window conventionally."
yuuji@59 498 (if (one-window-p t)
yuuji@51 499 (split-window
yuuji@51 500 (selected-window)
yuuji@51 501 (max
yuuji@51 502 (min
yuuji@69 503 (- (YaTeX-screen-height)
yuuji@59 504 (if (numberp height)
yuuji@59 505 (+ height 2)
yuuji@69 506 (/ (* (YaTeX-screen-height)
yuuji@59 507 (string-to-int height))
yuuji@51 508 100)))
yuuji@69 509 (- (YaTeX-screen-height) window-min-height 1))
yuuji@69 510 window-min-height))))
yuuji@51 511
yuuji@51 512 ;;;###autoload
yuuji@23 513 (defun YaTeX-window-list ()
yuuji@23 514 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
yuuji@23 515 (while (not (eq curw (setq win (next-window win))))
yuuji@23 516 (or (eq win (minibuffer-window))
yuuji@23 517 (setq wlist (cons win wlist))))
yuuji@69 518 wlist))
yuuji@23 519
yuuji@23 520 ;;;###autoload
yuuji@23 521 (defun substitute-all-key-definition (olddef newdef keymap)
yuuji@23 522 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
yuuji@23 523 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
yuuji@23 524 where ever it appears."
yuuji@68 525 (if YaTeX-emacs-19
yuuji@68 526 (substitute-key-definition olddef newdef keymap global-map)
yuuji@68 527 (mapcar
yuuji@68 528 (function (lambda (key) (define-key keymap key newdef)))
yuuji@68 529 (where-is-internal olddef keymap))))
yuuji@23 530
yuuji@23 531 ;;;###autoload
yuuji@23 532 (defun YaTeX-match-string (n &optional m)
yuuji@23 533 "Return (buffer-substring (match-beginning n) (match-beginning m))."
yuuji@23 534 (if (match-beginning n)
yuuji@23 535 (buffer-substring (match-beginning n)
yuuji@69 536 (match-end (or m n)))))
yuuji@23 537
yuuji@23 538 ;;;###autoload
yuuji@23 539 (defun YaTeX-minibuffer-complete ()
yuuji@49 540 "Complete in minibuffer.
yuuji@51 541 If the symbol 'delim is bound and is string, its value is assumed to be
yuuji@49 542 the character class of delimiters. Completion will be performed on
yuuji@51 543 the last field separated by those delimiters.
yuuji@51 544 If the symbol 'quick is bound and is 't, when the try-completion results
yuuji@51 545 in t, exit minibuffer immediately."
yuuji@23 546 (interactive)
yuuji@51 547 (let ((md (match-data)) beg word compl
yuuji@51 548 (quick (and (boundp 'quick) (eq quick t)))
yuuji@51 549 (displist ;function to display completion-list
yuuji@51 550 (function
yuuji@51 551 (lambda ()
yuuji@51 552 (with-output-to-temp-buffer "*Completions*"
yuuji@51 553 (display-completion-list
yuuji@51 554 (all-completions word minibuffer-completion-table)))))))
yuuji@49 555 (setq beg (if (and (boundp 'delim) (stringp delim))
yuuji@23 556 (save-excursion
yuuji@23 557 (skip-chars-backward (concat "^" delim))
yuuji@49 558 (point))
yuuji@23 559 (point-min))
yuuji@23 560 word (buffer-substring beg (point-max))
yuuji@23 561 compl (try-completion word minibuffer-completion-table))
yuuji@23 562 (cond
yuuji@49 563 ((eq compl t)
yuuji@51 564 (if quick (exit-minibuffer)
yuuji@51 565 (let ((p (point)) (max (point-max)))
yuuji@51 566 (unwind-protect
yuuji@51 567 (progn
yuuji@51 568 (goto-char max)
yuuji@51 569 (insert " [Sole completion]")
yuuji@51 570 (goto-char p)
yuuji@51 571 (sit-for 1))
yuuji@51 572 (delete-region max (point-max))
yuuji@51 573 (goto-char p)))))
yuuji@23 574 ((eq compl nil)
yuuji@23 575 (ding)
yuuji@23 576 (save-excursion
yuuji@23 577 (let (p)
yuuji@51 578 (unwind-protect
yuuji@51 579 (progn
yuuji@51 580 (goto-char (setq p (point-max)))
yuuji@51 581 (insert " [No match]")
yuuji@51 582 (goto-char p)
yuuji@51 583 (sit-for 2))
yuuji@51 584 (delete-region p (point-max))))))
yuuji@23 585 ((string= compl word)
yuuji@51 586 (funcall displist))
yuuji@23 587 (t (delete-region beg (point-max))
yuuji@51 588 (insert compl)
yuuji@51 589 (if quick
yuuji@51 590 (if (eq (try-completion compl minibuffer-completion-table) t)
yuuji@51 591 (exit-minibuffer)
yuuji@51 592 (funcall displist)))))
yuuji@69 593 (store-match-data md)))
yuuji@23 594
yuuji@51 595 (defun YaTeX-minibuffer-quick-complete ()
yuuji@51 596 "Set 'quick to 't and call YaTeX-minibuffer-complete.
yuuji@51 597 See documentation of YaTeX-minibuffer-complete."
yuuji@51 598 (interactive)
yuuji@51 599 (let ((quick t))
yuuji@51 600 (self-insert-command 1)
yuuji@51 601 (YaTeX-minibuffer-complete)))
yuuji@51 602
yuuji@51 603 (defun foreach-buffers (pattern job)
yuuji@51 604 "For each buffer which matches with PATTERN, do JOB."
yuuji@51 605 (let ((list (buffer-list)))
yuuji@51 606 (save-excursion
yuuji@51 607 (while list
yuuji@51 608 (set-buffer (car list))
yuuji@51 609 (if (or (and (stringp pattern)
yuuji@51 610 (buffer-file-name)
yuuji@51 611 (string-match pattern (buffer-file-name)))
yuuji@51 612 (and (symbolp pattern) major-mode (eq major-mode pattern)))
yuuji@51 613 (eval job))
yuuji@69 614 (setq list (cdr list))))))
yuuji@51 615
yuuji@51 616 (defun goto-buffer-window (buffer)
yuuji@51 617 "Select window which is bound to BUFFER.
yuuji@51 618 If no such window exist, switch to buffer BUFFER."
yuuji@52 619 (interactive "BGoto buffer: ")
yuuji@51 620 (if (stringp buffer)
yuuji@51 621 (setq buffer (or (get-file-buffer buffer) (get-buffer buffer))))
yuuji@51 622 (if (get-buffer buffer)
yuuji@51 623 (cond
yuuji@51 624 ((get-buffer-window buffer)
yuuji@51 625 (select-window (get-buffer-window buffer)))
yuuji@51 626 ((and YaTeX-emacs-19 (get-buffer-window buffer t))
yuuji@51 627 (let*((win (get-buffer-window buffer t))
yuuji@51 628 (frame (window-frame win)))
yuuji@51 629 (select-frame frame)
yuuji@51 630 (raise-frame frame)
yuuji@51 631 (focus-frame frame)
yuuji@51 632 (select-window win)
yuuji@51 633 (set-mouse-position frame 0 0)
yuuji@51 634 (and (featurep 'windows) (fboundp 'win:adjust-window)
yuuji@51 635 (win:adjust-window))))
yuuji@54 636 ((and (featurep 'windows) (fboundp 'win:get-buffer-window)
yuuji@56 637 (let ((w (win:get-buffer-window buffer)))
yuuji@56 638 (and w (win:switch-window w))))
yuuji@54 639 (select-window (get-buffer-window buffer)))
yuuji@69 640 (t (switch-to-buffer buffer)))))
yuuji@51 641
yuuji@51 642 ;; Here starts the functions which support gmhist-vs-Emacs19 compatible
yuuji@51 643 ;; reading with history.
yuuji@51 644 ;;;###autoload
yuuji@51 645 (defun completing-read-with-history
yuuji@51 646 (prompt table &optional predicate must-match initial hsym)
yuuji@51 647 "Completing read with general history: gmhist, Emacs-19."
yuuji@51 648 (let ((minibuffer-history
yuuji@51 649 (or (symbol-value hsym)
yuuji@51 650 (and (boundp 'minibuffer-history) minibuffer-history)))
yuuji@51 651 (minibuffer-history-symbol (or hsym 'minibuffer-history)))
yuuji@51 652 (prog1
yuuji@51 653 (if (fboundp 'completing-read-with-history-in)
yuuji@51 654 (completing-read-with-history-in
yuuji@51 655 minibuffer-history-symbol prompt table predicate must-match initial)
yuuji@51 656 (completing-read prompt table predicate must-match initial))
yuuji@51 657 (if (and YaTeX-emacs-19 hsym) (set hsym minibuffer-history)))))
yuuji@51 658
yuuji@51 659 ;;;###autoload
yuuji@51 660 (defun read-from-minibuffer-with-history (prompt &optional init map read hsym)
yuuji@51 661 "Read from minibuffer with general history: gmhist, Emacs-19."
yuuji@51 662 (cond
yuuji@51 663 (YaTeX-emacs-19
yuuji@51 664 (read-from-minibuffer prompt init map read hsym))
yuuji@51 665 (t
yuuji@51 666 (let ((minibuffer-history-symbol hsym))
yuuji@51 667 (read-from-minibuffer prompt init map read)))))
yuuji@51 668
yuuji@51 669 ;;;###autoload
yuuji@51 670 (defun read-string-with-history (prompt &optional init hsym)
yuuji@51 671 "Read string with history: gmhist(Emacs-18) and Emacs-19."
yuuji@51 672 (cond
yuuji@51 673 (YaTeX-emacs-19
yuuji@51 674 (read-from-minibuffer prompt init minibuffer-local-map nil hsym))
yuuji@51 675 ((featurep 'gmhist-mh)
yuuji@51 676 (read-with-history-in hsym prompt init))
yuuji@51 677 (t (read-string prompt init))))
yuuji@23 678
yuuji@69 679 ;;;###autoload
yuuji@69 680 (fset 'YaTeX-rassoc
yuuji@69 681 (if (and nil (fboundp 'rassoc) (subrp (symbol-function 'rassoc)))
yuuji@69 682 (symbol-function 'rassoc)
yuuji@70 683 (function
yuuji@70 684 (lambda (key list)
yuuji@70 685 (let ((l list))
yuuji@70 686 (catch 'found
yuuji@70 687 (while l
yuuji@70 688 (if (equal key (cdr (car l)))
yuuji@70 689 (throw 'found (car l)))
yuuji@70 690 (setq l (cdr l)))))))))
yuuji@70 691
yuuji@70 692 (defun YaTeX-insert-file-contents (file visit &optional beg end)
yuuji@70 693 (cond
yuuji@70 694 ((string< "19" emacs-version)
yuuji@70 695 (insert-file-contents file visit beg end))
yuuji@70 696 ((string-match "unix" (symbol-name system-type))
yuuji@70 697 (let ((default-process-coding-system
yuuji@70 698 (and (boundp '*noconv*) (list *noconv*)))
yuuji@70 699 file-coding-system (and (boundp '*noconv*) *noconv*)
yuuji@70 700 kanji-fileio-code
yuuji@70 701 (default-process-kanji-code 0))
yuuji@70 702 (call-process shell-file-name file (current-buffer) nil
yuuji@70 703 (or (and (boundp 'shell-command-option)
yuuji@70 704 shell-command-option)
yuuji@70 705 "-c")
yuuji@70 706 (format "head -c %d | tail -c +%d" end beg))))
yuuji@70 707 (t (insert-file-contents file))))
yuuji@70 708
yuuji@70 709 (defun YaTeX-split-string (str &optional sep null)
yuuji@70 710 "Split string STR by every occurrence of SEP(regexp).
yuuji@70 711 If the optional second argument SEP is nil, it defaults to \"[ \f\t\n\r\v]+\".
yuuji@70 712 Do not include null string by default. Non-nil for optional third argument
yuuji@70 713 NULL includes null string in a list."
yuuji@70 714 (let ((sep (or sep "[ \f\t\n\r\v]+"))
yuuji@70 715 list m)
yuuji@70 716 (while str
yuuji@70 717 (if (setq m (string-match sep str))
yuuji@70 718 (progn
yuuji@70 719 (if (or (> m 0) null)
yuuji@70 720 (setq list (cons (substring str 0 m) list)))
yuuji@70 721 (setq str (substring str (match-end 0))))
yuuji@70 722 (if (or null (string< "" str))
yuuji@70 723 (setq list (cons str list)))
yuuji@70 724 (setq str nil)))
yuuji@70 725 (nreverse list)))
yuuji@69 726
yuuji@53 727 ;;;
yuuji@53 728 ;; Interface function for windows.el
yuuji@53 729 ;;;
yuuji@53 730 ;;;###autoload
yuuji@53 731 (defun YaTeX-switch-to-window ()
yuuji@53 732 "Switch to windows.el's window decided by last pressed key."
yuuji@53 733 (interactive)
yuuji@53 734 (or (featurep 'windows) (error "Why don't you use `windows.el'?"))
yuuji@53 735 (win-switch-to-window 1 (- last-command-char win:base-key)))
yuuji@53 736
yuuji@64 737 ;;;###autoload
yuuji@64 738 (defun YaTeX-reindent (col)
yuuji@64 739 "Remove current indentation and reindento to COL column."
yuuji@64 740 (save-excursion
yuuji@64 741 (beginning-of-line)
yuuji@64 742 (skip-chars-forward " \t")
yuuji@64 743 (if (/= col (current-column))
yuuji@64 744 (progn
yuuji@64 745 (delete-region (point) (progn (beginning-of-line) (point)))
yuuji@64 746 (indent-to col))))
yuuji@64 747 (skip-chars-forward " \t" (point-end-of-line)))
yuuji@64 748
yuuji@64 749 (defun YaTeX-inner-environment (&optional quick)
yuuji@64 750 "Return current inner-most environment.
yuuji@64 751 Non-nil for optional argument QUICK restricts search bound to most
yuuji@64 752 recent sectioning command. Matching point is stored to property 'point
yuuji@64 753 of 'YaTeX-inner-environment, which can be referred by
yuuji@64 754 (get 'YaTeX-inner-environment 'point)."
yuuji@64 755 (let*((nest 0)
yuuji@64 756 (beg (YaTeX-replace-format-args
yuuji@64 757 (regexp-quote YaTeX-struct-begin)
yuuji@64 758 ;YaTeX-struct-begin ;=== TENTATIVE!! ==
yuuji@64 759 YaTeX-struct-name-regexp
yuuji@64 760 (if (eq major-mode 'yahtml-mode) "\\s *.*" "")
yuuji@64 761 ""))
yuuji@64 762 (end (YaTeX-replace-format-args
yuuji@64 763 (regexp-quote YaTeX-struct-end)
yuuji@64 764 YaTeX-struct-name-regexp "" ""))
yuuji@64 765 (begend (concat "\\(" beg "\\)\\|\\(" end "\\)"))
yuuji@64 766 bound m0
yuuji@64 767 (htmlp (eq major-mode 'yahtml-mode))
yuuji@64 768 (open
yuuji@64 769 (concat "^" (or (cdr (assq major-mode '((yahtml-mode . "<")))) "{")))
yuuji@64 770 (close
yuuji@64 771 (concat "^"
yuuji@64 772 (or (cdr(assq major-mode '((yahtml-mode . "\n\t >")))) "}"))))
yuuji@64 773 (save-excursion
yuuji@64 774 (if quick
yuuji@64 775 (setq bound
yuuji@64 776 (save-excursion
yuuji@64 777 (if htmlp
yuuji@64 778 ;;(re-search-backward YaTeX-sectioning-regexp nil 1)
yuuji@64 779 (goto-char (point-min)) ;Is this enough? 97/6/26
yuuji@64 780 (YaTeX-re-search-active-backward
yuuji@64 781 (concat YaTeX-ec-regexp
yuuji@64 782 "\\(" YaTeX-sectioning-regexp "\\)\\*?{")
yuuji@64 783 YaTeX-comment-prefix nil 1))
yuuji@64 784 (or (bobp) (end-of-line))
yuuji@64 785 (point))))
yuuji@64 786 (if (catch 'begin
yuuji@64 787 (if (and (numberp bound) (< (point) bound)) (throw 'begin nil))
yuuji@64 788 (while (YaTeX-re-search-active-backward
yuuji@64 789 begend YaTeX-comment-prefix bound t)
yuuji@64 790 (setq m0 (match-beginning 0))
yuuji@64 791 (if (looking-at end) ;;(match-beginning 2)
yuuji@64 792 (setq nest (1+ nest))
yuuji@64 793 (setq nest (1- nest)))
yuuji@64 794 (if (< nest 0)
yuuji@64 795 (progn
yuuji@64 796 (put 'YaTeX-inner-environment 'point m0)
yuuji@64 797 (goto-char m0)
yuuji@64 798 (put 'YaTeX-inner-environment 'indent (current-column))
yuuji@64 799 (throw 'begin t)))))
yuuji@64 800 (buffer-substring
yuuji@64 801 (progn (skip-chars-forward open) (1+ (point)))
yuuji@69 802 (progn (skip-chars-forward close) (point)))))))
yuuji@64 803
yuuji@64 804 (defun YaTeX-end-environment ()
yuuji@64 805 "Close opening environment"
yuuji@64 806 (interactive)
yuuji@64 807 (let ((env (YaTeX-inner-environment)))
yuuji@64 808 (if (not env) (error "No premature environment")
yuuji@64 809 (save-excursion
yuuji@64 810 (if (YaTeX-search-active-forward
yuuji@64 811 (YaTeX-replace-format-args YaTeX-struct-end env "" "")
yuuji@64 812 YaTeX-comment-prefix nil t)
yuuji@64 813 (if (y-or-n-p
yuuji@64 814 (concat "Environment `" env
yuuji@64 815 "' may be already closed. Force close?"))
yuuji@64 816 nil
yuuji@64 817 (error "end environment aborted."))))
yuuji@64 818 (message "") ;Erase (y or n) message.
yuuji@64 819 (YaTeX-insert-struc 'end env)
yuuji@64 820 (save-excursion
yuuji@64 821 (goto-char (or (get 'YaTeX-inner-environment 'point) (match-end 0)))
yuuji@64 822 (if (pos-visible-in-window-p)
yuuji@64 823 (sit-for (if YaTeX-dos 2 1))
yuuji@64 824 (message "Matches with %s at line %d"
yuuji@64 825 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
yuuji@69 826 (count-lines (point-min) (point))))))))
yuuji@64 827
yuuji@70 828 (defun YaTeX-beginning-of-environment (&optional limit-search-bound end)
yuuji@70 829 "Goto the beginning of the current environment.
yuuji@70 830 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound to
yuuji@70 831 most recent sectioning command. Non-nil for optional third argument END
yuuji@70 832 goes to end of environment."
yuuji@70 833 (interactive)
yuuji@70 834 (let ((op (point)))
yuuji@70 835 (if (YaTeX-inner-environment limit-search-bound)
yuuji@70 836 (progn
yuuji@70 837 (goto-char (get 'YaTeX-inner-environment 'point))
yuuji@70 838 (and end (YaTeX-goto-corresponding-environment))
yuuji@70 839 (if (interactive-p) (push-mark op))
yuuji@70 840 t))))
yuuji@70 841
yuuji@70 842 (defun YaTeX-end-of-environment (&optional limit-search-bound)
yuuji@70 843 "Goto the end of the current environment.
yuuji@70 844 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound
yuuji@70 845 to most recent sectioning command."
yuuji@70 846 (interactive)
yuuji@70 847 (YaTeX-beginning-of-environment limit-search-bound t))
yuuji@70 848
yuuji@70 849 (defun YaTeX-mark-environment ()
yuuji@70 850 "Mark current position and move point to end of environment."
yuuji@70 851 (interactive)
yuuji@70 852 (let ((curp (point)))
yuuji@70 853 (if (and (YaTeX-on-begin-end-p) (match-beginning 1)) ;if on \\begin
yuuji@70 854 (forward-line 1)
yuuji@70 855 (beginning-of-line))
yuuji@70 856 (if (not (YaTeX-end-of-environment)) ;arg1 turns to match-beginning 1
yuuji@70 857 (progn
yuuji@70 858 (goto-char curp)
yuuji@70 859 (error "Cannot found the end of current environment."))
yuuji@70 860 (YaTeX-goto-corresponding-environment)
yuuji@70 861 (beginning-of-line) ;for confirmation
yuuji@70 862 (if (< curp (point))
yuuji@70 863 (progn
yuuji@70 864 (message "Mark this environment?(y or n): ")
yuuji@70 865 (if (= (read-char) ?y) nil
yuuji@70 866 (goto-char curp)
yuuji@70 867 (error "Abort. Please call again at more proper position."))))
yuuji@70 868 (set-mark-command nil)
yuuji@70 869 (YaTeX-goto-corresponding-environment)
yuuji@70 870 (end-of-line)
yuuji@70 871 (if (eobp) nil (forward-char 1)))))
yuuji@70 872
yuuji@70 873
yuuji@64 874 ;;;VER2
yuuji@64 875 (defun YaTeX-insert-struc (what env)
yuuji@64 876 (cond
yuuji@64 877 ((eq what 'begin)
yuuji@64 878 (insert (YaTeX-replace-format-args
yuuji@64 879 YaTeX-struct-begin env (YaTeX-addin env))))
yuuji@64 880 ((eq what 'end)
yuuji@64 881 (insert (YaTeX-replace-format-args YaTeX-struct-end env)))
yuuji@69 882 (t nil)))
yuuji@64 883
yuuji@64 884 ;;; Function for menu support
yuuji@64 885 (defun YaTeX-define-menu (keymap bindlist)
yuuji@64 886 "Define KEYMAP(symbol)'s menu-bindings according to BINDLIST.
yuuji@64 887 KEYMAP should be a quoted symbol of newly allocated keymap.
yuuji@64 888 BINDLIST consists of binding list. Each element is as follows.
yuuji@64 889
yuuji@64 890 '(menusymbol DOC_String . contents)
yuuji@64 891
yuuji@64 892 CONTENTS is one of lambda-form, interactive function, or other keymap.
yuuji@64 893 See yatex19.el for example."
yuuji@64 894 (cond
yuuji@64 895 ((featurep 'xemacs)
yuuji@64 896 (let (name)
yuuji@64 897 (if (keymapp (symbol-value keymap))
yuuji@64 898 (progn
yuuji@64 899 (setq name (keymap-name (symbol-value keymap)))
yuuji@64 900 (set keymap nil))
yuuji@64 901 (setq name (car (symbol-value keymap)))
yuuji@64 902 (set keymap (cdr (symbol-value keymap))))
yuuji@64 903 (mapcar
yuuji@64 904 (function
yuuji@64 905 (lambda (bind)
yuuji@64 906 (setq bind (cdr bind))
yuuji@64 907 (if (eq (car-safe (cdr bind)) 'lambda)
yuuji@64 908 (setcar (cdr bind) 'progn))
yuuji@64 909 (if (stringp (car-safe (cdr bind)))
yuuji@64 910 (set keymap
yuuji@64 911 (cons (cdr bind) (symbol-value keymap)))
yuuji@64 912 (set keymap
yuuji@64 913 (cons (vector (car bind) (cdr bind) t)
yuuji@64 914 (symbol-value keymap))))))
yuuji@64 915 bindlist)
yuuji@64 916 (set keymap (cons name (symbol-value keymap)))))
yuuji@64 917 (t
yuuji@64 918 (mapcar
yuuji@64 919 (function
yuuji@64 920 (lambda (bind)
yuuji@64 921 (define-key (symbol-value keymap) (vector (car bind)) (cdr bind))))
yuuji@64 922 bindlist))))
yuuji@64 923
yuuji@64 924
yuuji@68 925 ;;;
yuuji@68 926 ;; Functions for the Installation time
yuuji@68 927 ;;;
yuuji@64 928
yuuji@58 929 (defun bcf-and-exit ()
yuuji@58 930 "Byte compile rest of argument and kill-emacs."
yuuji@58 931 (if command-line-args-left
yuuji@68 932 (let ((load-path (cons "." load-path)))
yuuji@68 933 (and (fboundp 'set-language-environment)
yuuji@68 934 (featurep 'mule)
yuuji@68 935 (set-language-environment "Japanese"))
yuuji@58 936 (mapcar 'byte-compile-file command-line-args-left)
yuuji@58 937 (kill-emacs))))
yuuji@64 938
yuuji@23 939 (provide 'yatexlib)