diff lisp/egg/egg.el @ 140:585fb297b004 r20-2b4

Import from CVS: tag r20-2b4
author cvs
date Mon, 13 Aug 2007 09:32:43 +0200
parents 6608ceec7cf8
children 1856695b1fa9
line wrap: on
line diff
--- a/lisp/egg/egg.el	Mon Aug 13 09:31:48 2007 +0200
+++ b/lisp/egg/egg.el	Mon Aug 13 09:32:43 2007 +0200
@@ -2082,6 +2082,8 @@
 (make-variable-buffer-local 'egg:*in-fence-mode*)
 (set-default 'egg:*in-fence-mode* nil)
 
+(defvar egg:fence-buffer nil "Buffer fence is active in")
+
 ;;(load-library "its-dump/roma-kana")         ;;;(define-its-mode "roma-kana"        " a$B$"(B")
 ;;(load-library "its-dump/roma-kata")         ;;;(define-its-mode "roma-kata"        " a$B%"(B")
 ;;(load-library "its-dump/downcase")          ;;;(define-its-mode "downcase"         " a a")
@@ -2564,7 +2566,8 @@
   ;; XEmacs change:
 ;  (buffer-disable-undo (current-buffer))
   (undo-boundary)
-  (setq egg:*in-fence-mode* t)
+  (setq egg:*in-fence-mode* t
+	egg:fence-buffer (current-buffer))
   (egg:mode-line-display)
   ;;;(setq egg:*global-map-backup* (current-global-map))
   (setq egg:*local-map-backup*  (current-local-map))
@@ -2580,6 +2583,7 @@
   (set-marker egg:*region-end* egg:*region-start*)
   (egg:fence-face-on)
   (goto-char egg:*region-start*)
+  (add-hook 'pre-command-hook 'fence-pre-command-hook)
   )
 
 (defun henkan-fence-region-or-single-space ()
@@ -2688,6 +2692,7 @@
 (defun egg:quit-egg-mode ()
   ;;;(use-global-map egg:*global-map-backup*)
   (use-local-map egg:*local-map-backup*)
+  (remove-hook 'pre-command-hook 'fence-pre-command-hook)
   (setq egg:*in-fence-mode* nil)
   (egg:mode-line-display)
   (if overwrite-mode
@@ -2724,6 +2729,36 @@
 (if (boundp 'mouse-track-cleanup-hook)
     (add-hook 'mouse-track-cleanup-hook 'fence-mouse-protect))
 
+(defun fence-pre-command-hook ()
+  ;; cribbed off of isearch-mode
+  ;;
+  ;; For use as the value of `pre-command-hook' when fence is active.
+  ;; If the command about to be executed is not ours,
+  ;; kill the fence before that command is executed.
+  ;;
+  (cond ((not (eq (current-buffer) egg:fence-buffer))
+	 ;; If the buffer (likely meaning "frame") has changed, bail.
+	 ;; This can also happen if a proc filter has popped up another
+	 ;; buffer, which is arguably a bad thing for it to have done,
+	 ;; but the way in which egg would have hosed you in that
+	 ;; case is unarguably even worse.
+	 (save-excursion
+	   (set-buffer egg:fence-buffer)
+	   (its:reset-input)
+	   (fence-cancel-input)))
+	((not (and this-command
+		   (symbolp this-command)
+		   (get this-command 'egg-fence-command)))
+	 (its:reset-input)
+	 (fence-cancel-input))
+	(t
+	 (if (or (not (pos-visible-in-window-safe
+		       (marker-position egg:*region-start*)))
+		 (not (pos-visible-in-window-safe
+		       (marker-position egg:*region-end*))))
+	     (recenter))))
+  )
+
 (defun egg-lang-switch-callback ()
   "Do whatever processing is necessary when the language-environment changes."
   (if egg:*in-fence-mode*
@@ -2732,7 +2767,8 @@
 	(fence-cancel-input)))
   (let ((func (get current-language-environment 'set-egg-environ)))
     (if (not (null func))
-      (funcall func))))
+      (funcall func)))
+  (egg:mode-line-display))
 
 (defun fence-mode-help-command ()
   "Display documentation for fence-mode."
@@ -2787,6 +2823,118 @@
 (define-key fence-mode-map [right] 'fence-forward-char)
 (define-key fence-mode-map [left] 'fence-backward-char)
 
+(put 'fence-self-insert-command 'egg-fence-command t)
+(put 'fence-hiragana 'egg-fence-command t)
+(put 'fence-katakana 'egg-fence-command t)
+(put 'fence-hankaku 'egg-fence-command t)
+(put 'fence-zenkaku 'egg-fence-command t)
+(put 'its:select-hiragana 'egg-fence-command t)
+(put 'its:select-katakana 'egg-fence-command t)
+(put 'its:select-downcase 'egg-fence-command t)
+(put 'its:select-upcase 'egg-fence-command t)
+(put 'its:select-zenkaku-downcase 'egg-fence-command t)
+(put 'its:select-zenkaku-upcase 'egg-fence-command t)
+(put 'its:minibuffer-completion-help 'egg-fence-command t)
+(put 'henkan-fence-region-or-single-space 'egg-fence-command t)
+(put 'henkan-fence-region 'egg-fence-command t)
+(put 'fence-beginning-of-line 'egg-fence-command t)
+(put 'fence-backward-char 'egg-fence-command t)
+(put 'fence-cancel-input 'egg-fence-command t)
+(put 'fence-delete-char 'egg-fence-command t)
+(put 'fence-end-of-line 'egg-fence-command t)
+(put 'fence-forward-char 'egg-fence-command t)
+(put 'fence-cancel-input 'egg-fence-command t)
+(put 'fence-mode-help-command 'egg-fence-command t)
+(put 'fence-kill-line 'egg-fence-command t)
+(put 'fence-exit-mode 'egg-fence-command t)
+(put 'fence-exit-mode 'egg-fence-command t)
+(put 'fence-exit-mode 'egg-fence-command t)
+(put 'its:select-previous-mode 'egg-fence-command t)
+(put 'fence-transpose-chars 'egg-fence-command t)
+(put 'eval-expression 'egg-fence-command t)
+(put 'fence-toggle-egg-mode 'egg-fence-command t)
+(put 'jis-code-input 'egg-fence-command t)
+(put 'fence-backward-delete-char 'egg-fence-command t)
+(put 'fence-backward-delete-char 'egg-fence-command t)
+(put 'fence-backward-delete-char 'egg-fence-command t)
+(put 'fence-forward-char 'egg-fence-command t)
+(put 'fence-backward-char 'egg-fence-command t)
+(put 'hiragana-region 'egg-fence-command t)
+(put 'hiragana-paragraph 'egg-fence-command t)
+(put 'hiragana-sentance 'egg-fence-command t)
+(put 'katakana-region 'egg-fence-command t)
+(put 'katakana-paragraph 'egg-fence-command t)
+(put 'katakana-sentance 'egg-fence-command t)
+(put 'hankaku-region 'egg-fence-command t)
+(put 'hankaku-paragraph 'egg-fence-command t)
+(put 'hankaku-sentance 'egg-fence-command t)
+(put 'hankaku-word 'egg-fence-command t)
+(put 'zenkaku-region 'egg-fence-command t)
+(put 'zenkaku-paragraph 'egg-fence-command t)
+(put 'zenkaku-sentance 'egg-fence-command t)
+(put 'zenkaku-word 'egg-fence-command t)
+(put 'roma-kana-region 'egg-fence-command t)
+(put 'roma-kana-paragraph 'egg-fence-command t)
+(put 'roma-kana-sentance 'egg-fence-command t)
+(put 'roma-kana-word 'egg-fence-command t)
+(put 'roma-kanji-region 'egg-fence-command t)
+(put 'roma-kanji-paragraph 'egg-fence-command t)
+(put 'roma-kanji-sentance 'egg-fence-command t)
+(put 'roma-kanji-word 'egg-fence-command t)
+(put 'its:select-mode 'egg-fence-command t)
+(put 'its:select-mode-from-menu 'egg-fence-command t)
+(put 'its:next-mode 'egg-fence-command t)
+(put 'its:previous-mode 'egg-fence-command t)
+(put 'its:select-hiragana 'egg-fence-command t)
+(put 'its:select-katakana 'egg-fence-command t)
+(put 'its:select-downcase 'egg-fence-command t)
+(put 'its:select-upcase   'egg-fence-command t)
+(put 'its:select-zenkaku-downcase 'egg-fence-command t)
+(put 'its:select-zenkaku-upcase   'egg-fence-command t)
+(put 'its:select-mode-temporally 'egg-fence-command t)
+(put 'its:select-previous-mode 'egg-fence-command t)
+(put 'fence-toggle-egg-mode 'egg-fence-command t)
+(put 'fence-transpose-chars 'egg-fence-command t)
+(put 'henkan-region 'egg-fence-command t)
+(put 'henkan-paragraph 'egg-fence-command t)
+(put 'henkan-sentance 'egg-fence-command t)
+(put 'henkan-word 'egg-fence-command t)
+(put 'henkan-kakutei 'egg-fence-command t)
+(put 'gyaku-henkan-region 'egg-fence-command t)
+(put 'gyaku-henkan-sentance 'egg-fence-command t)
+(put 'gyaku-henkan-word 'egg-fence-command t)
+(put 'gyaku-henkan-kakutei 'egg-fence-command t)
+(put 'henkan-kakutei-first-char 'egg-fence-command t)
+(put 'henkan-kakutei-before-point 'egg-fence-command t)
+(put 'sai-henkan 'egg-fence-command t)
+(put 'henkan-forward-bunsetu 'egg-fence-command t)
+(put 'henkan-backward-bunsetu 'egg-fence-command t)
+(put 'henkan-first-bunsetu 'egg-fence-command t)
+(put 'henkan-last-bunsetu 'egg-fence-command t)
+(put 'henkan-hiragana 'egg-fence-command t)
+(put 'henkan-katakana 'egg-fence-command t)
+(put 'henkan-next-kouho 'egg-fence-command t)
+(put 'henkan-next-kouho-dai 'egg-fence-command t)
+(put 'henkan-next-kouho-sho 'egg-fence-command t)
+(put 'henkan-previous-kouho 'egg-fence-command t)
+(put 'henkan-previous-kouho-dai 'egg-fence-command t)
+(put 'henkan-previous-kouho-sho 'egg-fence-command t)
+(put 'henkan-bunsetu-chijime-dai 'egg-fence-command t)
+(put 'henkan-bunsetu-chijime-sho 'egg-fence-command t)
+(put 'henkan-bunsetu-nobasi-dai 'egg-fence-command t)
+(put 'henkan-bunsetu-nobasi-sho 'egg-fence-command t)
+(put 'henkan-saishou-bunsetu 'egg-fence-command t)
+(put 'henkan-saichou-bunsetu 'egg-fence-command t)
+(put 'henkan-quit 'egg-fence-command t)
+(put 'henkan-select-kouho-dai 'egg-fence-command t)
+(put 'henkan-select-kouho-sho 'egg-fence-command t)
+(put 'henkan-word-off 'egg-fence-command t)
+(put 'henkan-kakutei-and-self-insert 'egg-fence-command t)
+(put 'henkan-help-command 'egg-fence-command t)
+(put 'toroku-region 'egg-fence-command t)
+(put 'toroku-henkan-mode 'egg-fence-command t)
+(put 'recenter 'egg-fence-command t)
+
 
 ;;;----------------------------------------------------------------------
 ;;;