comparison yatex.el @ 186:61996cd55816 dev

Ensure point-entered/point-left hook should not run continuously.
author yuuji@gentei.org
date Thu, 01 Dec 2011 23:02:36 +0900
parents 85e57c4b27a2
children 2f91947a43a1
comparison
equal deleted inserted replaced
185:85e57c4b27a2 186:61996cd55816
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; Yet Another tex-mode for emacs - //–ì’¹// 2 ;;; Yet Another tex-mode for emacs - //–ì’¹//
3 ;;; yatex.el rev. 1.74.5 3 ;;; yatex.el rev. 1.74.5
4 ;;; (c)1991-2011 by HIROSE Yuuji.[yuuji@yatex.org] 4 ;;; (c)1991-2011 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Wed Nov 30 14:22:06 2011 on duke 5 ;;; Last modified Thu Dec 1 23:00:13 2011 on firestorm
6 ;;; $Id$ 6 ;;; $Id$
7 ;;; The latest version of this software is always available at; 7 ;;; The latest version of this software is always available at;
8 ;;; http://www.yatex.org/ 8 ;;; http://www.yatex.org/
9 9
10 (require 'comment) 10 (require 'comment)
1255 )))) 1255 ))))
1256 1256
1257 (defun YaTeX-jmode () 1257 (defun YaTeX-jmode ()
1258 (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*) 1258 (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1259 (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*) 1259 (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1260 (and (boundp 'skk-mode) skk-mode) 1260 (and (boundp 'skk-mode) skk-mode (not skk-latin-mode))
1261 (and (boundp 'default-input-method) default-input-method 1261 (and (boundp 'default-input-method) default-input-method
1262 current-input-method))) 1262 current-input-method)))
1263 1263
1264 (defun YaTeX-jmode-off () 1264 (defun YaTeX-jmode-off ()
1265 (if (cond 1265 (if (cond
1267 (canna-toggle-japanese-mode) t) 1267 (canna-toggle-japanese-mode) t)
1268 ((and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*) 1268 ((and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1269 (egg:toggle-egg-mode-on-off) t) 1269 (egg:toggle-egg-mode-on-off) t)
1270 ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode) 1270 ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode)
1271 (cond 1271 (cond
1272 ((fboundp 'skk-latin-mode) (skk-latin-mode t)) 1272 ((fboundp 'skk-latin-mode)
1273 (or (and (boundp 'skk-henkan-mode) skk-henkan-mode)
1274 (and (boundp 'skk-henkan-on)
1275 (or skk-henkan-mode skk-henkan-active))
1276 (and (boundp 'j-henkan-on)
1277 (or j-henkan-on j-henkan-active))
1278 ;; Deactivate jmode if henkan-mode is not running.
1279 ;; Suggested by tt.tetsuo.tsukamoto.
1280 (progn
1281 (put 'YaTeX-jmode-on 'skkkata skk-katakana)
1282 (skk-latin-mode t))))
1273 ((fboundp 'skk-mode-off) (skk-mode-off)) 1283 ((fboundp 'skk-mode-off) (skk-mode-off))
1274 (t (j-mode-off))) 1284 (t (j-mode-off)))
1275 t) 1285 t)
1276 ((and (fboundp 'toggle-input-method) current-input-method) 1286 ((and (fboundp 'toggle-input-method) current-input-method)
1277 (toggle-input-method) t) 1287 (toggle-input-method) t)
1284 (if (not canna:*japanese-mode*) (canna-toggle-japanese-mode))) 1294 (if (not canna:*japanese-mode*) (canna-toggle-japanese-mode)))
1285 ((boundp 'egg:*mode-on*) 1295 ((boundp 'egg:*mode-on*)
1286 (and (not egg:*mode-on*) (not egg:*input-mode*) 1296 (and (not egg:*mode-on*) (not egg:*input-mode*)
1287 (egg:toggle-egg-mode-on-off))) 1297 (egg:toggle-egg-mode-on-off)))
1288 ((and (fboundp 'skk-mode) (boundp 'skk-mode)) 1298 ((and (fboundp 'skk-mode) (boundp 'skk-mode))
1289 (if (not skk-mode) (skk-mode 1))) 1299 (if (get 'YaTeX-jmode-on 'skkkata)
1300 (skk-j-mode-on t)
1301 (skk-mode 1))
1302 (put 'YaTeX-jmode-on 'skkkata nil))
1290 ((fboundp 'toggle-input-method) 1303 ((fboundp 'toggle-input-method)
1291 (if (not current-input-method) (toggle-input-method))) 1304 (if (not current-input-method) (toggle-input-method)))
1292 ((and (fboundp 'fep-force-on) (fep-force-on))))) 1305 ((and (fboundp 'fep-force-on) (fep-force-on)))))
1293 1306
1294 (defun YaTeX-jmode-back () 1307 (defun YaTeX-jmode-back ()
1440 ; (backward-char 1)) 1453 ; (backward-char 1))
1441 (t (YaTeX-self-insert arg)))) 1454 (t (YaTeX-self-insert arg))))
1442 1455
1443 (defun YaTeX-jmode-hook (old new) 1456 (defun YaTeX-jmode-hook (old new)
1444 "A hook controling jmode on/off." 1457 "A hook controling jmode on/off."
1458 ;; This function is called via point-entered/leave hook, so that
1459 ;; codes in it is evaluated on such emacsen as having text-properties.
1445 (let ((inhibit-point-motion-hooks t) 1460 (let ((inhibit-point-motion-hooks t)
1446 (oldp (plist-get (text-properties-at old) 'point-left)) 1461 (oldp (plist-get (text-properties-at old) 'point-left))
1447 (newp (plist-get (text-properties-at new) 'point-left)) 1462 (newp (plist-get (text-properties-at new) 'point-left))
1448 (lnew (plist-get (text-properties-at new) 'last-new)) 1463 (lnew (plist-get (text-properties-at new) 'last-new))
1449 (bmp (buffer-modified-p)) ;(endc ?x) 1464 (mjmode (plist-get (text-properties-at new) 'mjmode))
1465 (bmp (buffer-modified-p))
1450 (jm (YaTeX-jmode)) b e) 1466 (jm (YaTeX-jmode)) b e)
1451 ;;(if (eq 'YaTeX-jmode-hook newp)
1452 ;; (setq endc (char-after (next-single-property-change new 'point-left))))
1453 ;;(message "n[%c]=%s o[%c]=%s end=[%c] jm=%s"
1454 ;; (char-after new) newp (char-after old) oldp endc jm)
1455 (unwind-protect 1467 (unwind-protect
1456 (cond 1468 (cond
1457 ((eq lnew new) nil) ;Do nothing if continuous entry 1469 ((eq lnew new) nil) ;Do nothing if continuous entry
1458 ((and (not (eq newp 'YaTeX-jmode-hook)) 1470 ((and (not (eq newp 'YaTeX-jmode-hook))
1459 (eq oldp 'YaTeX-jmode-hook)) 1471 (eq oldp 'YaTeX-jmode-hook)
1472 (plist-get (text-properties-at old) 'entered))
1460 ;; leave 1473 ;; leave
1461 (remove-text-properties 1474 (remove-text-properties
1462 (1+ (or (previous-single-property-change old 'point-left) 1475 (setq b (1+ (or (previous-single-property-change old 'point-left)
1463 (1- (point)))) 1476 (1- (point)))))
1464 (1- (or (next-single-property-change old 'point-left) 1477 (setq e (1- (or (next-single-property-change old 'point-left)
1465 (1+ (point)))) 1478 (1+ (point)))))
1466 (list 'last-new nil)) 1479 (list 'last-new nil 'entered nil))
1480 (add-text-properties b e (list 'mjmode jm))
1481 (if (boundp 'skk-katakana)
1482 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
1467 (if (plist-get (text-properties-at old) 'jmode) 1483 (if (plist-get (text-properties-at old) 'jmode)
1468 (YaTeX-jmode-on))) 1484 (YaTeX-jmode-on)))
1469 ((and (not (eq oldp 'YaTeX-jmode-hook)) 1485 ((and (not (eq oldp 'YaTeX-jmode-hook))
1470 (eq newp 'YaTeX-jmode-hook)) 1486 (eq newp 'YaTeX-jmode-hook)
1487 (not (plist-get (text-properties-at new) 'entered)))
1471 ;; enter 1488 ;; enter
1472 (add-text-properties 1489 (add-text-properties
1473 (1+ (or (previous-single-property-change new 'point-left) 1490 (1+ (or (previous-single-property-change new 'point-left)
1474 (1- (point)))) 1491 (1- (point))))
1475 (1- (or (next-single-property-change new 'point-left) 1492 (1- (or (next-single-property-change new 'point-left)
1476 (1+ (point)))) 1493 (1+ (point))))
1477 (list 'jmode jm 'last-new new)) 1494 (list 'jmode jm 'last-new new 'entered t))
1478 (YaTeX-jmode-off))) 1495 (if (boundp 'skk-katakana) ;care for skk katakana mode
1496 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
1497 (if mjmode (YaTeX-jmode-on) (YaTeX-jmode-off))))
1479 ;;unwind job 1498 ;;unwind job
1480 (set-buffer-modified-p bmp)))) 1499 (set-buffer-modified-p bmp))))
1481 1500
1482 (defun YaTeX-insert-dollar () 1501 (defun YaTeX-insert-dollar ()
1483 (interactive) 1502 (interactive)
1493 (1- (point)) (1+ (point)) 1512 (1- (point)) (1+ (point))
1494 (list 'point-left 'YaTeX-jmode-hook 1513 (list 'point-left 'YaTeX-jmode-hook
1495 'point-entered 'YaTeX-jmode-hook 1514 'point-entered 'YaTeX-jmode-hook
1496 'front-sticky t 1515 'front-sticky t
1497 'rear-nonsticky t 1516 'rear-nonsticky t
1517 'mjmode nil
1498 'jmode (YaTeX-jmode)))) 1518 'jmode (YaTeX-jmode))))
1499 (YaTeX-jmode-off) 1519 (YaTeX-jmode-off)
1500 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1)))) 1520 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1))))
1501 1521
1502 (defun YaTeX-insert-dollars-region (beg end) 1522 (defun YaTeX-insert-dollars-region (beg end)

yatex.org