Index: /cdl-mode/trunk/CDL
===================================================================
--- /cdl-mode/trunk/CDL	(revision 2)
+++ /cdl-mode/trunk/CDL	(revision 2)
@@ -0,0 +1,176 @@
+;;
+;;  TOPPERS Software
+;;      Toyohashi Open Platform for Embedded Real-Time Systems
+;; 
+;;  Copyright (C) 2010 by TAKUYA
+;;              Embedded and Real-Time Systems Laboratory
+;;              Graduate School of Information Science, Nagoya Univ., JAPAN
+;; 
+;;  ãLì ÒÍCÈºÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
+;;  Ai{\tgEFAðüÏµ½àÌðÜÞDÈº¯¶jðgpE¡»Eü
+;;  ÏEÄzziÈºCpÆÄÔj·é±Æð³Åø·éD
+;;  (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
+;;       \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
+;;      XR[hÉÜÜêÄ¢é±ÆD
+;;  (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«é`ÅÄzz·éêÉÍCÄzzÉº¤hL
+gip
+;;      Ò}j
+AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
+;;      Ì³ÛØKèðfÚ·é±ÆD
+;;  (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
+;;      ÆD
+;;    (a) ÄzzÉº¤hL
+gipÒ}j
+AÈÇjÉCãLÌ
+;;        ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
+;;    (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
+;;        ñ·é±ÆD
+;;  (4) {\tgEFAÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶é¢©Èé¹
+;;      Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
+;;      Ü½C{\tgEFAÌ[UÜ½ÍGh[U©çÌ¢©Èé
+;;      RÉîÃ­¿©çàCãLì Ò¨æÑTOPPERSvWFNgð
+;;      ÆÓ·é±ÆD
+;; 
+;;  {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
+;;  æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
+;;  ÉÎ·éK«àÜßÄC¢©ÈéÛØàsíÈ¢DÜ½C{\tgEF
+;;  AÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶½¢©Èé¹QÉÖµÄàC»
+;;  ÌÓCðíÈ¢D
+;; 
+;; 
+auto
+break
+case
+char
+const
+continue
+default
+do
+double
+else
+enum
+extern
+float
+for
+goto
+if
+int
+long
+register
+return
+short
+signed
+sizeof
+static
+struct
+switch
+typedef
+union
+unsigned
+void
+volatile
+while
+;*2
+#define
+#elif
+#else
+#endif
+#error
+#if
+#ifdef
+#ifndef
+#import
+#include
+#line
+#pragma
+#undef
+;*1
+_asm
+__asm
+_based
+__based
+cdecl
+_cdecl
+__cdecl
+_declspec
+__declspec
+dllexport
+dllimport
+_except
+__except
+_fastcall
+__fastcall
+_finally
+__finally
+_inline
+__inline
+_int8
+__int8
+_int16
+__int16
+_int32
+__int32
+_int64
+__int64
+_leave
+__leave
+naked
+_stdcall
+__stdcall
+thread
+_try
+__try
+$END$
+
+;*0
+node
+linkunit
+domain
+class
+signature
+celltype
+composite
+cell
+;*1
+attr
+var
+call
+entry
+FACTORY
+factory
+require
+;*2
+singleton
+active
+C_EXP
+import
+import_C
+write
+allocator
+size_is
+count_is
+omit
+optional
+through
+receive
+send
+context
+inline
+deviate
+
+;*0
+uint8_t
+uint16_t
+uint32_t
+int8_t
+int16_t
+int32_t
+int64_t
+bool_t
+char_t
+double64_t
+float32_t
+true
+false
Index: /cdl-mode/trunk/cdl-mode.l
===================================================================
--- /cdl-mode/trunk/cdl-mode.l	(revision 2)
+++ /cdl-mode/trunk/cdl-mode.l	(revision 2)
@@ -0,0 +1,391 @@
+;;
+;;  TOPPERS Software
+;;      Toyohashi Open Platform for Embedded Real-Time Systems
+;; 
+;;  Copyright (C) 2010 by TAKUYA
+;;              Embedded and Real-Time Systems Laboratory
+;;              Graduate School of Information Science, Nagoya Univ., JAPAN
+;; 
+;;  ãLì ÒÍCÈºÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
+;;  Ai{\tgEFAðüÏµ½àÌðÜÞDÈº¯¶jðgpE¡»Eü
+;;  ÏEÄzziÈºCpÆÄÔj·é±Æð³Åø·éD
+;;  (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
+;;       \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
+;;      XR[hÉÜÜêÄ¢é±ÆD
+;;  (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«é`ÅÄzz·éêÉÍCÄzzÉº¤hL
+gip
+;;      Ò}j
+AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
+;;      Ì³ÛØKèðfÚ·é±ÆD
+;;  (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
+;;      ÆD
+;;    (a) ÄzzÉº¤hL
+gipÒ}j
+AÈÇjÉCãLÌ
+;;        ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
+;;    (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
+;;        ñ·é±ÆD
+;;  (4) {\tgEFAÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶é¢©Èé¹
+;;      Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
+;;      Ü½C{\tgEFAÌ[UÜ½ÍGh[U©çÌ¢©Èé
+;;      RÉîÃ­¿©çàCãLì Ò¨æÑTOPPERSvWFNgð
+;;      ÆÓ·é±ÆD
+;; 
+;;  {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
+;;  æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
+;;  ÉÎ·éK«àÜßÄC¢©ÈéÛØàsíÈ¢DÜ½C{\tgEF
+;;  AÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶½¢©Èé¹QÉÖµÄàC»
+;;  ÌÓCðíÈ¢D
+;; 
+;; 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;  cdl-mode for xyzzy
+;;
+;;
+;;  [hû@D
+;;  1. cdl-mode.l ð site-lisp/ ÌºÉC
+;;     CDL ð etc/ ÌºÉ»ê¼ê¨­D
+;;  2. ºLð .xyzzy ÉÇÁ·éD
+;;  
+;;  (require "cdl-mode")
+;;  (push '("\\.cdl$" . cdl-mode) *auto-mode-alist*)
+;;
+
+(provide "cdl-mode")
+
+(in-package "editor")
+
+(export '(*cdl-mode-hook* cdl-indent-level cdl-continued-statement-offset
+	  cdl-argdecl-indent cdl-brace-offset cdl-brace-imaginary-offset
+	  cdl-label-offset cdl-comment-indent))
+(export '(cdl-mode cdl-indent-line cdl-newline-and-indent cdl-electric-insert
+	  cdl-electric-close indent-cpp-directive
+	  *cdl-keyword-file* *cdl-indent-tabs-mode*
+	  *cdl-tab-always-indent* *cdl-comment-column*
+	  *cdl-comment-c++-style*))
+
+(defvar *cdl-mode-hook* nil)
+
+(unless (boundp 'cdl-indent-level)
+  (setq cdl-indent-level 2)
+  (setq cdl-continued-statement-offset 2)
+  (setq cdl-argdecl-indent 5)
+  (setq cdl-brace-offset 0)
+  (setq cdl-brace-imaginary-offset 0)
+  (setq cdl-label-offset -2)
+  (setq cdl-comment-indent 2))
+
+(defvar *cdl-tab-always-indent* t)
+
+(defvar *cdl-indent-tabs-mode* nil)
+(defvar *cdl-comment-column* nil)
+(defvar *cdl-comment-c++-style* nil)
+
+(defvar *cdl-keyword-hash-table* nil)
+(defvar *cdl-keyword-file* "CDL")
+
+(defvar *cdl-mode-syntax-table* nil)
+(unless *cdl-mode-syntax-table*
+  (setq *cdl-mode-syntax-table* (make-syntax-table))
+  (do ((x #x21 (1+ x)))((>= x #x7f))
+    (let ((c (code-char x)))
+      (unless (alphanumericp c)
+	(set-syntax-punctuation *cdl-mode-syntax-table* c))))
+  (set-syntax-option *cdl-mode-syntax-table*
+		     *syntax-option-c-preprocessor*)
+  (set-syntax-string *cdl-mode-syntax-table* #\")
+  (set-syntax-string *cdl-mode-syntax-table* #\')
+  (set-syntax-escape *cdl-mode-syntax-table* #\\)
+  (set-syntax-symbol *cdl-mode-syntax-table* #\_)
+  (set-syntax-symbol *cdl-mode-syntax-table* #\#)
+  (set-syntax-match *cdl-mode-syntax-table* #\( #\))
+  (set-syntax-match *cdl-mode-syntax-table* #\{ #\})
+  (set-syntax-match *cdl-mode-syntax-table* #\[ #\])
+  (set-syntax-start-multi-comment *cdl-mode-syntax-table* "/*")
+  (set-syntax-end-multi-comment *cdl-mode-syntax-table* "*/")
+  (set-syntax-start-c++-comment *cdl-mode-syntax-table* #\/)
+  (set-syntax-end-c++-comment *cdl-mode-syntax-table* #\LFD))
+
+(defvar *cdl-mode-map* nil)
+(unless *cdl-mode-map*
+  (setq *cdl-mode-map* (make-sparse-keymap))
+  (define-key *cdl-mode-map* #\{ 'cdl-electric-insert)
+  (define-key *cdl-mode-map* #\: 'cdl-electric-insert)
+  (define-key *cdl-mode-map* #\# 'cdl-electric-insert)
+  (define-key *cdl-mode-map* #\} 'cdl-electric-close)
+  (define-key *cdl-mode-map* #\C-h 'backward-delete-char-untabify-or-selection)
+  (define-key *cdl-mode-map* #\TAB 'cdl-indent-line)
+  (define-key *cdl-mode-map* #\C-M-q 'indent-sexp)
+  (define-key *cdl-mode-map* #\RET 'cdl-newline-and-indent))
+
+(defvar *cdl-mode-abbrev-table* nil)
+(unless *cdl-mode-abbrev-table*
+  (define-abbrev-table '*cdl-mode-abbrev-table*))
+
+(defun cdl-indent-line ()
+  (interactive "*")
+  (if (or (not (interactive-p))
+	  *cdl-tab-always-indent*
+	  (save-excursion
+	    (skip-chars-backward " \t")
+	    (bolp)))
+      (case (save-excursion
+	      (goto-bol)
+	      (parse-point-syntax))
+	(:string)
+	(:comment
+	 (let ((column (calc-cdl-comment-indent)))
+	   (when (integerp column)
+	     (smart-indentation column))))
+	(t
+	 (let ((column (calc-c-indent)))
+	   (when (integerp column)
+	     (smart-indentation column)))))
+    (insert "\t"))
+  t)
+
+(defun cdl-newline-and-indent (&optional (arg 1))
+  (interactive "*p")
+  (delete-trailing-spaces)
+  (insert #\LFD arg)
+  (cdl-indent-line))
+
+(defun cdl-electric-insert (&optional (arg 1))
+  (interactive "*p")
+  (unless (prog1
+	      (parse-point-syntax)
+	    (self-insert-command arg))
+    (cdl-indent-line))
+  t)
+
+(defun cdl-electric-close (&optional (arg 1))
+  (interactive "*p")
+  (unless (prog1
+	      (parse-point-syntax)
+	    (self-insert-command arg))
+    (cdl-indent-line))
+  (save-excursion
+    (forward-char -1)
+    (and (goto-matched-parenthesis)
+	 (show-matched-parenthesis)))
+  t)
+
+(defun cpp-indent-to (to)
+  (skip-chars-forward " \t")
+  (when (/= to (current-column))
+    (delete-horizontal-spaces)
+    (indent-to to)))
+
+(defun indent-cpp-directive ()
+  (interactive)
+  (save-excursion
+    (let ((column 1))
+      (goto-char (point-min))
+      (while (scan-buffer "^#" :regexp t)
+	(forward-char 1)
+	(cond ((looking-at "[ \t]*if")
+	       (cpp-indent-to column)
+	       (setq column (1+ column)))
+	      ((looking-at "[ \t]*el\\(se\\|if\\)")
+	       (cpp-indent-to (1- column)))
+	      ((looking-at "[ \t]*endif")
+	       (setq column (1- column))
+	       (when (zerop column)
+		 (error "Unmatched \"#endif\" at line ~d" (current-line-number)))
+	       (cpp-indent-to column))
+	      (t (cpp-indent-to column)
+		 (if (looking-for "define")
+		     (while (and (progn
+				   (goto-eol)
+				   (forward-char -1)
+				   (looking-for "\\"))
+				 (forward-line 1))
+		       (cdl-indent-line))))))
+      (when (/= column 1)
+	(error "Unmatched \"#if\" or \"#ifdef\""))))
+  t)
+
+(defun cdl-comment-indent ()
+  (save-excursion
+    (let ((opoint (point)))
+      (goto-bol)
+      (cond ((looking-at "/\\*\\|//")
+	     0)
+	    (t
+	     (skip-chars-forward " \t")
+	     (cond ((looking-at "}[ \t]*\\($\\|/\\*\\|//\\)")
+		    (+ (current-column) 2))
+		   ((looking-at "#[ \t]*\\(endif\\|else\\)\\>")
+		    (goto-char (match-end 1))
+		    (+ (current-column) 2))
+		   ((or (looking-at "/\\*\\|//")
+			(eolp))
+		    (calc-c-indent))
+		   ((zerop comment-column)
+		    0)
+		   (t
+		    (goto-char opoint)
+		    (skip-chars-backward " \t")
+		    (max (1+ (current-column)) comment-column))))))))
+
+(defvar-local cdl-comment-indent-variable 'cdl-comment-indent)
+
+(defun calc-cdl-comment-indent ()
+  (save-excursion
+    (goto-bol)
+    (skip-chars-forward " \t")
+    (let ((eolp (eolp)))
+      (when (and (or eolp (looking-for "*"))
+		 (scan-buffer "/*" :reverse t))
+	(while (and (eq (parse-point-syntax) ':comment)
+		    (scan-buffer "/*" :reverse t :no-dup t)))
+	(+ (current-column)
+	   (if eolp
+	       (if (symbolp cdl-comment-indent-variable)
+		   (symbol-value cdl-comment-indent-variable)
+		 0)
+	     1))))))
+
+(autoload 'cdl-build-summary-of-functions "cfns" nil)
+(autoload 'cdl-maketags "cfns")
+(pushnew '(cdl-maketags "*.c" "*.cpp" "*.cxx" "*.cc" "*.h" "*.hpp" "*.hxx" "*.inl")
+	 *maketags-list* :key #'car)
+
+(defun cdl-tags-find-target ()
+  (let* ((opoint (point))
+	 (tail (progn
+		 (skip-chars-forward "a-zA-Z0-9_")
+		 (point)))
+	 (name (buffer-substring tail
+				 (progn
+				   (skip-chars-backward "a-zA-Z0-9_")
+				   (when (or (looking-back "::~")
+					     (looking-back "->~")
+					     (looking-back ".~"))
+				     (forward-char -1))
+				   (point))))
+	 class)
+    (cond ((looking-back "::")
+	   (forward-char -2)
+	   (let ((point (point)))
+	     (when (looking-back ">")
+	       (let ((depth 1))
+		 (loop
+		   (forward-char -1)
+		   (skip-chars-backward "^<>")
+		   (cond ((looking-back ">")
+			  (incf depth))
+			 ((looking-back "<")
+			  (decf depth)
+			  (when (zerop depth)
+			    (forward-char -1)
+			    (return)))
+			 (t
+			  (return)))))
+	       (skip-chars-backward " \t\n\f")
+	       (setq point (point)))
+	     (setq class (buffer-substring point
+					   (progn
+					     (skip-chars-backward "a-zA-Z0-9_")
+					     (point))))))
+	  (t
+	   (goto-char tail)
+	   (when (looking-for "::")
+	     (forward-char 2)
+	     (setq class name)
+	     (setq name (buffer-substring
+			 (point)
+			 (progn
+			   (skip-chars-forward "a-zA-Z0-9_")
+			   (point)))))))
+    (goto-char opoint)
+    (values class name '(function structure))))
+
+(defun cdl-tags-find-point-1 (re start reverse structurep lgoal)
+  (let* ((limit (if reverse
+		    (- start *jump-tag-limit*)
+		  (+ start *jump-tag-limit*)))
+	 (goal (progn
+		 (goto-char start)
+		 (while (scan-buffer re :regexp t :limit limit :tail t :reverse reverse)
+		   (let ((opoint (point))
+			 (point0 (match-beginning 0))
+			 (start (match-end 1)))
+		     (unless structurep
+		       (forward-char -1)
+		       (forward-sexp 1 t))
+		     (skip-white-forward)
+		     (unless (looking-for ";")
+		       (return start))
+		     (goto-char (if reverse (1- point0) opoint)))))))
+    (if lgoal
+	(if goal
+	    (if (< (abs (- lgoal start)) (abs (- goal start)))
+		lgoal goal)
+	  lgoal)
+      goal)))
+
+(defun cdl-tags-find-point (class name type point)
+  (let* ((structurep (eq type 'structure))
+	 (re (compile-regexp (if structurep
+				 (concat "\\_<\\(?:struct\\|class\\|interface\\)[ \t\n\f]+\\("
+					 name "\\)\\_>")
+			       (concat "\\_<\\(" name "\\)[ \t\n\f]*("))))
+	 goal)
+    (setq goal (cdl-tags-find-point-1 re point t structurep nil))
+    (setq goal (cdl-tags-find-point-1 re point nil structurep goal))
+    goal))
+
+;; FÃ¯·éL[[hi³K\»j
+
+(defvar *cdl-regexp-keyword-list* nil)
+(setq *cdl-regexp-keyword-list*
+     (compile-regexp-keyword-list
+      '(
+	 ("\\([\[]\\)\\(in\\|out\\|inout\\|oneway\\)\\([\]]\\)" nil (:keyword 2) nil 2 2)
+	)
+      ))
+;	("³K\»" å¶¬¶ÌæÊðµÈ¢H color LøÍÍ Ç±©ç Ç±ÜÅ)
+
+(defun cdl-mode ()
+  (interactive)
+  (kill-all-local-variables)
+  (setq mode-name "CDL")
+  (setq buffer-mode 'cdl-mode)
+  (use-syntax-table *cdl-mode-syntax-table*)
+  (use-keymap *cdl-mode-map*)
+  (make-local-variable 'mode-specific-indent-command)
+  (setq mode-specific-indent-command 'cdl-indent-line)
+  (make-local-variable 'paragraph-start)
+  (setq paragraph-start "^$\\|\f")
+  (make-local-variable 'paragraph-separate)
+  (setq paragraph-separate paragraph-start)
+  (make-local-variable 'indent-tabs-mode)
+  (setq indent-tabs-mode *cdl-indent-tabs-mode*)
+  (make-local-variable 'tags-find-target)
+  (setq tags-find-target #'cdl-tags-find-target)
+  (make-local-variable 'tags-find-point)
+  (setq tags-find-point #'cdl-tags-find-point)
+  (make-local-variable 'build-summary-function)
+  (setq build-summary-function 'cdl-build-summary-of-functions)
+  (and *cdl-keyword-file*
+       (null *cdl-keyword-hash-table*)
+       (setq *cdl-keyword-hash-table*
+	     (load-keyword-file *cdl-keyword-file*)))
+  (when *cdl-keyword-hash-table*
+    (make-local-variable 'keyword-hash-table)
+    (setq keyword-hash-table *cdl-keyword-hash-table*))
+  (setq *local-abbrev-table* *cdl-mode-abbrev-table*)
+  (if *cdl-comment-c++-style*
+      (setq comment-start "// " comment-end "")
+    (setq comment-start "/* " comment-end " */"))
+  (setq comment-start-skip "/\\(\\*+\\|/\\)[ \t]*")
+  (setq comment-indent-function 'cdl-comment-indent)
+  (when *cdl-comment-column*
+    (setq comment-column *cdl-comment-column*))
+  (make-local-variable 'regexp-keyword-list)
+  (setq regexp-keyword-list *cdl-regexp-keyword-list*)
+  (run-hooks '*cdl-mode-hook*))
Index: /tf-mode/trunk/tf
===================================================================
--- /tf-mode/trunk/tf	(revision 2)
+++ /tf-mode/trunk/tf	(revision 2)
@@ -0,0 +1,66 @@
+;;
+;;  TOPPERS Software
+;;      Toyohashi Open Platform for Embedded Real-Time Systems
+;; 
+;;  Copyright (C) 2010 by TAKUYA
+;;              Embedded and Real-Time Systems Laboratory
+;;              Graduate School of Information Science, Nagoya Univ., JAPAN
+;; 
+;;  ãLì ÒÍCÈºÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
+;;  Ai{\tgEFAðüÏµ½àÌðÜÞDÈº¯¶jðgpE¡»Eü
+;;  ÏEÄzziÈºCpÆÄÔj·é±Æð³Åø·éD
+;;  (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
+;;       \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
+;;      XR[hÉÜÜêÄ¢é±ÆD
+;;  (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«é`ÅÄzz·éêÉÍCÄzzÉº¤hL
+gip
+;;      Ò}j
+AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
+;;      Ì³ÛØKèðfÚ·é±ÆD
+;;  (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
+;;      ÆD
+;;    (a) ÄzzÉº¤hL
+gipÒ}j
+AÈÇjÉCãLÌ
+;;        ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
+;;    (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
+;;        ñ·é±ÆD
+;;  (4) {\tgEFAÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶é¢©Èé¹
+;;      Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
+;;      Ü½C{\tgEFAÌ[UÜ½ÍGh[U©çÌ¢©Èé
+;;      RÉîÃ­¿©çàCãLì Ò¨æÑTOPPERSvWFNgð
+;;      ÆÓ·é±ÆD
+;; 
+;;  {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
+;;  æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
+;;  ÉÎ·éK«àÜßÄC¢©ÈéÛØàsíÈ¢DÜ½C{\tgEF
+;;  AÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶½¢©Èé¹QÉÖµÄàC»
+;;  ÌÓCðíÈ¢D
+;; 
+;; 
+;*2b
+LENGTH
+EQ
+ALT
+SORT
+ENVIRON
+VALUE
+CONCAT
+APPEND
+AT
+_
+FORMAT
+FIND
+RANGE
+SYMBOL
+PEEK
+DUMP
+TRACE
+NOOP
+BCOPY
+ESCSTR
+UNESCSTR
+CALL
+LSORT
Index: /tf-mode/trunk/tf-mode.el
===================================================================
--- /tf-mode/trunk/tf-mode.el	(revision 2)
+++ /tf-mode/trunk/tf-mode.el	(revision 2)
@@ -0,0 +1,357 @@
+;;
+;;  TOPPERS Software
+;;      Toyohashi Open Platform for Embedded Real-Time Systems
+;; 
+;;  Copyright (C) 2010 by TAKUYA
+;;              Embedded and Real-Time Systems Laboratory
+;;              Graduate School of Information Science, Nagoya Univ., JAPAN
+;; 
+;;  上記著作権者は，以下の(1)〜(4)の条件を満たす場合に限り，本ソフトウェ
+;;  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+;;  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+;;  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+;;      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+;;      スコード中に含まれていること．
+;;  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+;;      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+;;      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+;;      の無保証規定を掲載すること．
+;;  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+;;      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+;;      と．
+;;    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+;;        作権表示，この利用条件および下記の無保証規定を掲載すること．
+;;    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+;;        報告すること．
+;;  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+;;      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+;;      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+;;      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+;;      免責すること．
+;; 
+;;  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+;;  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+;;  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+;;  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+;;  の責任を負わない．
+;; 
+;; 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;  tf-mode for emacs
+;;
+;; 
+;;  ロード方法．
+;;  下記を .emacs に追加する．
+;;  
+;;  (setq load-path (append '("ファイルの置き場所") load-path))
+;;  (autoload 'tf-mode "tf-mode" nil t)
+;;  (add-hook 'tf-mode-hook '(lambda () (font-lock-mode 1)))
+;;  (setq auto-mode-alist (append '(
+;;		("\\.tf$" . tf-mode)) auto-mode-alist))
+;; 
+
+;; 
+;; 構文テーブル
+;;
+
+(defvar tf-mode-syntax-table nil
+  "Syntax table in use in TF-mode buffers.")
+
+(if tf-mode-syntax-table
+    ()
+  (setq tf-mode-syntax-table (make-syntax-table)))
+
+;;
+;; キーワードの強調表示
+;; 
+
+(defvar tf-font-lock-defaults 
+  (list 'tf-font-lock-keywords
+	t
+	nil
+	nil
+	'beginning-of-line
+	))
+
+(defconst tf-font-lock-keywords
+  (list
+   ;; コメント
+   '("^\$[ \t].*"
+     . font-lock-comment-face)
+   ;; 制御構造
+   '("\\([\$]\\)\\(IF\\|FOREACH\\|JOINEACH\\)\\([ \t]\\)" 
+     . (2 font-lock-keyword-face))
+   '("\\([\$]\\)\\(END\\|ELSE\\)\\([\$]\\)"
+     . (2 font-lock-keyword-face))
+   '("\\([\$]\\)\\(FUNCTION\\|FILE\\|INCLUDE\\)\\([ \t]\\)"
+     . (2 font-lock-builtin-face))
+   '("\\([\$]\\)\\(ERROR\\|WORNING\\)\\([ \t\$]\\)"
+     . (2 font-lock-warning-face))
+   '("\\([\$]\\)\\(SPC\\|TAB\\|NL\\|ARGC\\|ARGV\\|RESULT\\)\\([\$]\\)"
+     . (2 font-lock-string-face))
+   '("\\([\"]\\)\\([^\"]\\)*\\([\"]\\)"
+     . font-lock-string-face)
+   '("\\([\']\\)\\([^\']\\)*\\([\']\\)"
+     . font-lock-string-face)
+   '("\\([ \t!@\$~\+\*^\(=,<>%|-]\\)\\(LENGTH\\|EQ\\|ALT\\|SORT\\|ENVIRON\\|VALUE\\|CONCAT\\|APPEND\\|AT\\|_\\|FORMAT\\|FIND\\|RANGE\\|SYMBOL\\|PEEK\\|DUMP\\|TRACE\\|NOOP\\|BCOPY\\|ESCSTR\\|UNESCSTR\\|CALL\\|LSORT\\)\\([\(]\\)"
+     . (2 font-lock-function-name-face))
+   ))
+
+;;
+;; tfモード特有のキーバインド
+;;
+
+(defvar tf-mode-map
+  (let ((tf-keymap (make-keymap)))
+    ;; タブを押すとtestが呼ばれる。
+    (define-key tf-keymap "\t"  'tf-indent-line)
+    tf-keymap))
+
+
+;;------------------------
+;;
+;;  インデントに関する定義
+;;
+;;------------------------
+
+(defvar *tf-tab-always-indent* t)
+
+(defvar *tf-block-beg-re*
+  "[\$]\\(IF\\|FOREACH\\|JOINEACH\\|FUNCTION\\)[ ]")
+(defvar *tf-block-mid-re*
+  "\$ELSE[\$]")
+(defvar *tf-block-end-re* "\$END[\$]")
+
+(defvar *tf-indent-column* 4)
+
+(defun tf-space-line ()
+  "空行かどうか"
+  (save-excursion
+    (beginning-of-line) ; (goto-bol)
+    (looking-at "\\([ \t]*$\\|^\$[ \t]\\)")))
+
+(defun tf-previous-line ()
+  "空行じゃない行まで戻る"
+  (catch 'tf-previous-line-loop
+    (while (= (forward-line -1) 0)
+      (unless (tf-space-line)
+	(throw 'tf-previous-line-loop t)))))
+
+(defun calc-tf-indent ()
+  "インデントする数を数える"
+  (let ((column 0) (curp (point)))
+    (save-excursion
+      ;前の行を調べる
+      (when (tf-previous-line)
+	(beginning-of-line) ;(goto-bol)
+	(skip-chars-forward " \t")
+	; インデント数
+	(setq column (current-column))
+	;(message-box (format nil "column1: ~D" column))
+	(save-restriction
+	  (narrow-to-region (progn (end-of-line) (point)) ;(goto-eol) (point))
+			    (progn (beginning-of-line) (point))) ;(goto-bol) (point)))
+	  (beginning-of-line)
+	  (skip-chars-forward " \t")
+	  ; 開きものがあればインデント数を増やす
+	  (cond
+	   ((looking-at *tf-block-beg-re*)
+	    (setq column (+ column *tf-indent-column*)))
+	   ((looking-at *tf-block-mid-re*)
+	    (setq column (+ column *tf-indent-column*)))
+	  )
+	)))
+    ;(message-box (format nil "column2: ~D" column))
+    ; 現在の行を調べる
+    (save-excursion
+      (save-restriction
+	(narrow-to-region (progn (end-of-line) (point)) ;(goto-eol) (point))
+			  (progn (beginning-of-line) (point))) ;(goto-bol) (point)))
+	(beginning-of-line) ; (goto-bol)
+	(skip-chars-forward " \t")
+	; 閉じものがあればインデント数を減らす
+	(cond
+	 ((looking-at *tf-block-end-re*)
+	  (setq column (- column *tf-indent-column*)))
+	 ((looking-at *tf-block-mid-re*)
+	  (setq column (- column *tf-indent-column*)))
+	)))
+    column
+  ))
+
+(defun tf-not-comment-line ()
+  (save-excursion
+    (progn
+      (beginning-of-line)
+      (if (looking-at "^\$[ \t]")
+	  nil
+	  t
+	  )
+      )
+    ))
+
+(defun tf-indent-line ()
+  (interactive "*")
+  (if (or (not (interactive-p))
+	  *tf-tab-always-indent*
+	  (save-excursion
+	    (skip-chars-backward " \t")
+	    (bolp)))
+    (if (tf-not-comment-line) ;; コメント行でなければ実行する
+      ; ここを変えただけ
+      (let ((column (calc-tf-indent)))
+	(when (integerp column)
+	  (save-excursion
+	    (beginning-of-line) ;(goto-bol)
+	    (delete-region (point)
+			   (progn
+			     (skip-chars-forward " \t")
+			     (point)))
+	    (indent-to column)))
+	(if (and (bolp) column)
+	    (skip-chars-forward " \t")))
+	 )
+    (insert "\t"))
+  t)
+
+;;
+;; tfモードメイン関数
+;;
+
+(defun tf-mode ()
+  ""
+  (interactive)
+  (kill-all-local-variables)
+  (set-syntax-table tf-mode-syntax-table)
+  (setq case-fold-search nil)
+  (use-local-map tf-mode-map)
+  (setq mode-name "tf")
+  (make-local-variable 'font-lock-defaults)
+  (setq font-lock-defaults tf-font-lock-defaults)
+  (set (make-local-variable 'indent-line-function) 'tf-indent-line)
+  (run-hooks 'tf-mode-hook))
+
+;; -------------------
+;;
+;;  $END$の対応を探す
+;;
+;; -------------------
+
+;; 対応を探すための正規表現
+(defvar *tf-block-keyword* "[\$]\\(IF[ \t]\\|FOREACH[ \t]\\|JOINEACH[ \t]\\|FUNCTION[ \t]\\|END[\$]\\)")
+(defvar *tf-block-tag* 'tf-block)
+
+(defvar tf-block-highlight-face 'highlight)
+
+(defvar tf-block-highlight-overlay nil)
+
+(defun tf-block-get-line-start-pos ()
+  (save-excursion
+    (let ((xor '(lambda (a b) (and (or a b) (not (and a b)))))
+          (point (point))
+          (count 0))
+      (while (and (not (funcall xor (bobp) (eolp)))
+                  (> point (point-min)))
+        (setq point (1- point))
+        (goto-char (1- (point))))
+      ;; delete linefeed of start point.
+      (when (and (eolp) (>= (point-max) (1+ point)))
+        (setq point (1+ point)))
+      point)))
+
+(defun tf-block-get-line-end-pos ()
+  (save-excursion
+    (let ((xor '(lambda (a b) (and (or a b) (not (and a b)))))
+          (point (point)))
+      (while (and (not (funcall xor (eobp) (eolp)))
+                  (>= (point-max) point))
+        (setq point (1+ point))
+        (goto-char (1+ (point))))
+      point)))
+
+;; ハイライトを元に戻す
+(defun tf-block-highlight-done ()
+  (remove-hook 'pre-command-hook 'tf-block-highlight-done)
+  (if tf-block-highlight-overlay
+      (delete-overlay tf-block-highlight-overlay)))
+
+;; ハイライト（オーバレイ）
+(defun tf-block-do-highlight (start end)
+  (if tf-block-highlight-overlay
+      (move-overlay tf-block-highlight-overlay start end)
+    (setq tf-block-highlight-overlay (make-overlay start end)))
+  (overlay-put tf-block-highlight-overlay
+	       'face tf-block-highlight-face)
+  (add-hook 'pre-command-hook 'tf-block-highlight-done))
+
+(defun tf-block-hook ()
+  (progn
+    (if (string-match "tf" mode-name) ;; tf-modeのときだけ
+	(let (now)
+	  (save-excursion
+	    (progn
+	      (setq now (point))
+	      (if (string-match "\$END\$" (buffer-substring (- now 5) (- now 1))) ;; $END$の後ろにカーソル
+		  (progn
+		    (goto-char now)
+		    (do-tf-block) ;; 本体呼び出し
+		    )
+		)
+	      )
+	    )
+	  )
+      )
+    )
+  )
+
+(defun do-tf-block ()
+  (let (from to end_depth line_no line_string tmp_string now)
+    (save-excursion
+      (setq from (point))
+      (backward-char 1)
+      (if t ;(re-search-backward *tf-block-keyword*) ;(scan-buffer *tf-block-keyword* :reverse t :regexp t)
+	  (progn
+	    (setq end_depth 1) ;; $END$の深さ
+	    (while (> end_depth 0) ;; $END$の対応が見つかるまで
+	      (progn
+		(if (re-search-backward *tf-block-keyword* nil t);(scan-buffer *tf-block-keyword* :reverse t :regexp t :no-dup t)
+		    (progn
+		      (setq tmp_string (match-string 0))
+		      (setq now (point))
+		      (beginning-of-line)
+		      (if (not (string-match "^$[ \t]" (buffer-substring (point) (+ (point) 2)))) ;; コメントアウト中かチェック
+			  (progn
+			    (goto-char now)
+			    (if (string-match "[\$]END[\$]" tmp_string) ;; $END$が見つかった
+				 (setq end_depth (+ end_depth 1)) ;; 深さ+1
+			      (progn ;; $END$以外が見つかった
+			  	 (setq end_depth (- end_depth 1)) ;; 深さ-1
+				  ))
+			    )
+			)
+		      )
+		  (setq end_depth -1) ;; $END$の対応がない
+		  )))
+	    (if (= end_depth 0) ;; $END$の対応があった
+		(progn
+		  (let ((slinep 0) (elinep 0))
+		    (save-excursion
+		      (setq slinep (tf-block-get-line-start-pos)
+			    elinep (tf-block-get-line-end-pos)))
+		    ;; display line contents to minibuffer
+		    (message "%d: %s" (1+ (count-lines (point-min) slinep))
+			       (buffer-substring slinep elinep))
+		    ;; do overlay.
+		    (tf-block-do-highlight slinep elinep))
+		  )
+	      (message "ないかもだよ") ;; $END$の対応がなかった
+	      )
+	    )
+	)
+      )
+    )
+  )
+
+
+(add-hook 'post-command-hook 'tf-block-hook) ;; post-command-hookに追加
Index: /tf-mode/trunk/tf-mode.l
===================================================================
--- /tf-mode/trunk/tf-mode.l	(revision 2)
+++ /tf-mode/trunk/tf-mode.l	(revision 2)
@@ -0,0 +1,338 @@
+;;
+;;  TOPPERS Software
+;;      Toyohashi Open Platform for Embedded Real-Time Systems
+;; 
+;;  Copyright (C) 2010 by TAKUYA
+;;              Embedded and Real-Time Systems Laboratory
+;;              Graduate School of Information Science, Nagoya Univ., JAPAN
+;; 
+;;  ãLì ÒÍCÈºÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
+;;  Ai{\tgEFAðüÏµ½àÌðÜÞDÈº¯¶jðgpE¡»Eü
+;;  ÏEÄzziÈºCpÆÄÔj·é±Æð³Åø·éD
+;;  (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
+;;       \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
+;;      XR[hÉÜÜêÄ¢é±ÆD
+;;  (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«é`ÅÄzz·éêÉÍCÄzzÉº¤hL
+gip
+;;      Ò}j
+AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
+;;      Ì³ÛØKèðfÚ·é±ÆD
+;;  (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJ­Ég
+;;      pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
+;;      ÆD
+;;    (a) ÄzzÉº¤hL
+gipÒ}j
+AÈÇjÉCãLÌ
+;;        ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
+;;    (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
+;;        ñ·é±ÆD
+;;  (4) {\tgEFAÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶é¢©Èé¹
+;;      Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
+;;      Ü½C{\tgEFAÌ[UÜ½ÍGh[U©çÌ¢©Èé
+;;      RÉîÃ­¿©çàCãLì Ò¨æÑTOPPERSvWFNgð
+;;      ÆÓ·é±ÆD
+;; 
+;;  {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
+;;  æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
+;;  ÉÎ·éK«àÜßÄC¢©ÈéÛØàsíÈ¢DÜ½C{\tgEF
+;;  AÌpÉæè¼ÚIÜ½ÍÔÚIÉ¶¶½¢©Èé¹QÉÖµÄàC»
+;;  ÌÓCðíÈ¢D
+;; 
+;; 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;  tf-mode for xyzzy
+;;
+;;
+;;  [hû@D
+;;  1. tf-mode.l ð site-lisp/ ÌºÉC
+;;     tf ð etc/ ÌºÉ»ê¼ê¨­D
+;;  2. ºLð .xyzzy ÉÇÁ·éD
+;;  
+;; (require "tf-mode")
+;; (push '("\\.tf$" . tf-mode) *auto-mode-alist*)
+;;
+
+(provide "tf-mode")
+
+(in-package "editor")
+
+(export '(tf-mode
+         *tf-mode-hook* *tf-indent-column*
+	 *tf-tab-always-indent*))
+
+(defvar *tf-mode-hook* nil)
+
+;; (add-hook '*tf-mode-hook* #'(lambda()
+;;   (set-syntax-match (syntax-table) #\( #\))
+;;   (set-syntax-match (syntax-table) #\{ #\})
+;;   (set-syntax-match (syntax-table) #\[ #\])
+;; ))
+
+(defvar *tf-mode-map* nil)
+(unless *tf-mode-map*
+  (setq *tf-mode-map* (make-sparse-keymap))
+  (define-key *tf-mode-map* #\TAB 'tf-indent-line)
+  )
+
+(defvar *tf-mode-syntax-table* nil)
+(unless *tf-mode-syntax-table*
+  (setq *tf-mode-syntax-table* (make-syntax-table)))
+;;  (set-syntax-start-comment *tf-mode-syntax-table* #\$\t t)
+;;  (set-syntax-end-comment *tf-mode-syntax-table* #\LFD nil t))
+
+
+;; etc/tfÌL[[hðQÆ
+
+(defvar *tf-keyword-hash-table* nil)
+(defvar *tf-keyword-file* "tf")
+
+;; FÃ¯·éL[[h
+
+(defvar *tf-regexp-keyword-list* nil)
+(setq *tf-regexp-keyword-list*
+     (compile-regexp-keyword-list
+      '(
+	 ("^\$[ \t].*" nil (:keyword :comment :line) nil nil nil)
+	 ("\\([\$]\\)\\(IF\\|FOREACH\\|JOINEACH\\)\\([ \t]\\)" nil (:keyword 0 :bold) nil 2 nil)
+	 ("\\([\$]\\)\\(END\\|ELSE\\)\\([\$]\\)" nil (:keyword 0 :bold) nil 2 2)
+	 ("\\([\$]\\)\\(FUNCTION\\|FILE\\|INCLUDE\\)\\([ \t]\\)" nil (:keyword 1 :bold) nil 2 nil)
+	 ("\\([\$]\\)\\(ERROR\\|WORNING\\)\\([ \t\$]\\)" nil (:keyword 1 :bold) nil 2 2)
+	 ("\\([\$]\\)\\(SPC\\|TAB\\|NL\\|ARGC\\|ARGV\\|RESULT\\)\\([\$]\\)" nil (:keyword :string :bold) nil 2 2)
+	 ("\\([\"]\\)\\([^\"]\\)*\\([\"]\\)" nil (:keyword :string) nil nil nil)
+	 ("\\([\']\\)\\([^\']\\)*\\([\']\\)" nil (:keyword :string) nil nil nil)
+	)
+      ))
+;	("³K\»" å¶¬¶ÌæÊðµÈ¢H color LøÍÍ Ç±©ç Ç±ÜÅ)
+
+
+;;--------------------------------------------------------------------------
+;;
+;;  CfgÉÖ·éè`
+;;
+;;--------------------------------------------------------------------------
+
+(defvar *tf-tab-always-indent* t)
+
+(defvar *tf-block-beg-re*
+  "[\$]\\(IF\\|FOREACH\\|JOINEACH\\|FUNCTION\\)[ ]")
+(defvar *tf-block-mid-re*
+  "\$ELSE[\$]")
+(defvar *tf-block-end-re* "\$END[\$]")
+
+(defvar *tf-indent-column* 4)
+
+(defun tf-space-line ()
+  "ós©Ç¤©"
+  (save-excursion
+    (goto-bol)
+    (looking-at "\\([ \t]*$\\|^\$[ \t]\\)")))
+
+(defun tf-previous-line ()
+  "ós¶áÈ¢sÜÅßé"
+  (while (forward-line -1)
+    ;(message-box (format nil "=> ~D" (current-line-number)))
+    (unless (tf-space-line)
+	(return-from tf-previous-line t))))
+
+(defun calc-tf-indent ()
+  "Cfg·éð¦é"
+  (let ((column 0) (curp (point)))
+    (save-excursion
+      ;OÌsð²×é
+      (when (tf-previous-line)
+	(goto-bol)
+	(skip-chars-forward " \t")
+	; Cfg
+	(setq column (current-column))
+	;(message-box (format nil "column1: ~D" column))
+	(save-restriction
+	  (narrow-to-region (progn (goto-eol) (point))
+			    (progn (goto-bol) (point)))
+	  (skip-chars-forward " \t")
+	  ; J«àÌª êÎCfgðâ·
+	  (cond
+	   ((looking-at *tf-block-beg-re*)
+	    (setq column (+ column *tf-indent-column*)))
+	   ((looking-at *tf-block-mid-re*)
+	    (setq column (+ column *tf-indent-column*)))
+	  )
+	)))
+    ;(message-box (format nil "column2: ~D" column))
+    ; »ÝÌsð²×é
+    (save-excursion
+      (save-restriction
+	(narrow-to-region (progn (goto-eol) (point))
+			  (progn (goto-bol) (point)))
+	(goto-bol)
+	(skip-chars-forward " \t")
+	; Â¶àÌª êÎCfgð¸ç·
+	(cond
+	 ((looking-at *tf-block-end-re*)
+	  (setq column (- column *tf-indent-column*)))
+	 ((looking-at *tf-block-mid-re*)
+	  (setq column (- column *tf-indent-column*)))
+	)))
+    column
+  ))
+
+(defun tf-not-comment-line ()
+  (save-excursion
+    (progn
+      (beginning-of-line)
+      (if (looking-at "^\$[ \t]")
+	  nil
+	  t
+	  )
+      )
+    ))
+
+(defun tf-indent-line ()
+  (interactive "*")
+  (if (or (not (interactive-p))
+	  *tf-tab-always-indent*
+	  (save-excursion
+	    (skip-chars-backward " \t")
+	    (bolp)))
+    (if (tf-not-comment-line) ;; RgsÅÈ¯êÎÀs·é
+      ; ±±ðÏ¦½¾¯
+      (let ((column (calc-tf-indent)))
+	(when (integerp column)
+	  (save-excursion
+	    (goto-bol)
+	    (delete-region (point)
+			   (progn
+			     (skip-chars-forward " \t")
+			     (point)))
+	    (indent-to column)))
+	(if (and (bolp) column)
+	    (skip-chars-forward " \t")))
+	 )
+    (insert "\t"))
+  t)
+
+;; -------------------------------------------------------------------------
+;;
+;;  tf-mode{Ì
+;;
+;; -------------------------------------------------------------------------
+
+(defun tf-mode ()
+ (interactive)
+ (kill-all-local-variables)
+ (setq buffer-mode 'tf-mode)
+ (setq mode-name "tf")
+ (use-keymap *tf-mode-map*)
+ (make-local-variable 'mode-specific-indent-command)
+ (setq mode-specific-indent-command #'tf-indent-line)
+ (use-syntax-table *tf-mode-syntax-table*)
+ (and *tf-keyword-file*
+    (null *tf-keyword-hash-table*)
+    (setq *tf-keyword-hash-table*
+      (load-keyword-file *tf-keyword-file*)))
+ (when *tf-keyword-hash-table*
+    (make-local-variable 'keyword-hash-table)
+    (setq keyword-hash-table *tf-keyword-hash-table*))
+ (make-local-variable 'regexp-keyword-list)
+ (setq regexp-keyword-list *tf-regexp-keyword-list*)
+ (run-hooks '*tf-mode-hook*))
+
+;; -------------------------------------------------------------------------
+;;
+;;  $END$ÌÎðT·
+;;
+;; -------------------------------------------------------------------------
+
+;; ÎðT·½ßÌ³K\»
+(defvar *tf-block-keyword* "[\$]\\(IF[ \t]\\|FOREACH[ \t]\\|JOINEACH[ \t]\\|FUNCTION[ \t]\\|END[\$]\\)")
+(defvar *tf-block-tag* 'tf-block)
+
+
+(defvar-local *stored-text-attributes* nil)
+
+(defun save-text-attributes (&optional start end)
+  (setq *stored-text-attributes*
+        (list-text-attributes start end)))
+
+(defun restore-text-attributes ()
+  (mapc (lambda (attr) (apply #'set-text-attribute attr))
+        *stored-text-attributes*)
+  (setq *stored-text-attributes* nil))
+
+
+(defun tf-block-pre-hook ()
+  (delete-text-attributes *tf-block-tag*)
+  (restore-text-attributes)
+  )
+
+
+(defun tf-block-hook ()
+  (progn
+    (if (string-match "tf" mode-name) ;; tf-modeÌÆ«¾¯
+	(let (now)
+	  (save-excursion
+	    (progn
+	      (setq now (point))
+	      (if (string-match "\$END\$" (buffer-substring (- now 5) (- now 1))) ;; $END$ÌãëÉJ[\
+		  (progn
+		    (goto-char now)
+		    (save-text-attributes)
+		    (do-tf-block) ;; {ÌÄÑoµ
+		    )
+		)
+	      )
+	    )
+	  )
+      )
+    )
+  )
+
+(defun do-tf-block ()
+  (let (from to end_depth line_no line_string tmp_string now)
+    (save-excursion
+      (setq from (point))
+      (backward-char 1)
+      (if (scan-buffer *tf-block-keyword* :reverse t :regexp t)
+	  (progn
+	    (setq end_depth 1) ;; $END$Ì[³
+	    (while (> end_depth 0) ;; $END$ÌÎª©Â©éÜÅ
+	      (progn
+		(if (scan-buffer *tf-block-keyword* :reverse t :regexp t :no-dup t)
+		    (progn
+		      (setq tmp_string (match-string 0))
+		      (setq now (point))
+		      (beginning-of-line)
+		      (if (not (string-match "^$[ \t]" (buffer-substring (point) (+ (point) 2)))) ;; RgAEg©`FbN
+			  (progn
+			    (goto-char now)
+			    (if (string-match "[\$]END[\$]" tmp_string) ;; $END$ª©Â©Á½
+				 (setq end_depth (+ end_depth 1)) ;; [³+1
+			      (progn ;; $END$ÈOª©Â©Á½
+			  	 (setq end_depth (- end_depth 1)) ;; [³-1
+				  ))
+			    )
+			)
+		      )
+		  (setq end_depth -1) ;; $END$ÌÎªÈ¢
+		  )))
+	    (if (= end_depth 0) ;; $END$ÌÎª Á½
+		(progn
+		  (setq to (point))
+		  (setq line_no (current-line-number))
+		  (end-of-line)
+		  (setq line_string (buffer-substring to (point)))
+		  (message "~d : ~s" line_no line_string) ;; sÔ,sàeð\¦
+		  (set-text-attribute from to *tf-block-tag* :bold t) ;; ÍÜê½ÍÍð­²
+		  )
+	      (message "È¢©à¾æ") ;; $END$ÌÎªÈ©Á½
+	      )
+	    )
+	)
+      )
+    )
+  )
+
+
+(add-hook '*pre-command-hook* 'tf-block-pre-hook) ;; post-command-hookÉÇÁ
+(add-hook '*post-command-hook* 'tf-block-hook) ;; post-command-hookÉÇÁ
