     (,factor--regex-type-definition 2 'factor-font-lock-type-definition)
     (,factor--regex-symbol-definition 2 'factor-font-lock-symbol-definition)
     (,factor--regex-using-line 1 'factor-font-lock-vocabulary-name)
-    (,factor--regex-use-line 1 'factor-font-lock-vocabulary-name)))
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; factor-mode commands
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(require 'comint)
-
-(defvar factor-binary "~/factor/factor")
-(defvar factor-image "~/factor/factor.image")
+    (,factor--regex-use-line 1 'factor-font-lock-vocabulary-name))
+  "Font lock keywords definition for Factor mode.")
+
++
+;;; Factor mode syntax:
+
+(defvar factor-mode-syntax-table nil
+  "Syntax table used while in Factor mode.")
+
+(if factor-mode-syntax-table
+    ()
+  (let ((i 0))
+    (setq factor-mode-syntax-table (make-syntax-table))
+
+    ;; Default is atom-constituent
+    (while (< i 256)
+      (modify-syntax-entry i "_   " factor-mode-syntax-table)
+      (setq i (1+ i)))
+
+    ;; Word components.
+    (setq i ?0)
+    (while (<= i ?9)
+      (modify-syntax-entry i "w   " factor-mode-syntax-table)
+      (setq i (1+ i)))
+    (setq i ?A)
+    (while (<= i ?Z)
+      (modify-syntax-entry i "w   " factor-mode-syntax-table)
+      (setq i (1+ i)))
+    (setq i ?a)
+    (while (<= i ?z)
+      (modify-syntax-entry i "w   " factor-mode-syntax-table)
+      (setq i (1+ i)))
+
+    ;; Whitespace
+    (modify-syntax-entry ?\t " " factor-mode-syntax-table)
+    (modify-syntax-entry ?\n ">" factor-mode-syntax-table)
+    (modify-syntax-entry ?\f " " factor-mode-syntax-table)
+    (modify-syntax-entry ?\r " " factor-mode-syntax-table)
+    (modify-syntax-entry ?  " " factor-mode-syntax-table)
+
+    (modify-syntax-entry ?\[ "(]  " factor-mode-syntax-table)
+    (modify-syntax-entry ?\] ")[  " factor-mode-syntax-table)
+    (modify-syntax-entry ?{ "(}  " factor-mode-syntax-table)
+    (modify-syntax-entry ?} "){  " factor-mode-syntax-table)
+
+    (modify-syntax-entry ?\( "()" factor-mode-syntax-table)
+    (modify-syntax-entry ?\) ")(" factor-mode-syntax-table)
+    (modify-syntax-entry ?\" "\"    " factor-mode-syntax-table)))
+
++
+;;; Factor mode commands:
 
 (defun factor-telnet-to-port (port)
   (interactive "nPort: ")


(add-to-list 'auto-mode-alist '("\\.factor\\'" . factor-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; factor-listener-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-derived-mode factor-listener-mode comint-mode "Factor Listener")


  (beginning-of-line)
  (insert "! "))

(defvar factor-mode-map (make-sparse-keymap)
  "Key map used by Factor mode.")

(define-key factor-mode-map "\C-c\C-f" 'factor-run-file)
(define-key factor-mode-map "\C-c\C-r" 'factor-send-region)
