                       ))
 ;; ----------------
 
-(defvar two-mode-update 0)
+(defvar two-mode-update nil)
 (defvar two-mode-mode-idle-timer nil)
 (defvar two-mode-bool nil)
 (defvar two-mode-mode-delay (/ (float 1) (float 8)))

;; multiple modes, so I suppose that 'two-mode-mode' isn't strictly
;; accurate anymore.

;; configure these:
(defvar default-mode (list "SGML" 'sgml-mode))
(defvar second-modes (list

          (run-hooks 'two-mode-switch-hook))
      (if (eq font-lock-mode t)
          (font-lock-fontify-buffer))
      (if (fboundp 'turn-on-font-lock-if-enabled)
          (turn-on-font-lock-if-enabled)
        (turn-on-font-lock-if-desired)))))

(defun two-mode-mode-update-mode ()
  (when (and two-mode-bool two-mode-update)
    (setq two-mode-update 0)
    (let ((mode-list second-modes)
          (to-mode (car default-mode))
          (func (cadr default-mode)))
      (while mode-list
        (let ((mode (car mode-list))
              (lm -1)
              (rm -1))
          (save-excursion
            (if (search-backward (cadr mode) nil t)
                (setq lm (point))))
          (save-excursion
            (if (search-backward (car (cddr mode)) nil t)
                (setq rm (point))))
          (if (and (not (and (= lm -1) (= rm -1))) (>= lm rm))
              (progn
                (setq mode-list nil)
                (setq to-mode (car mode))
                (setq func (car (cdr (cddr mode)))))
            (setq mode-list (cdr mode-list)))))
      (two-mode-change-mode to-mode func))))

(defun two-mode-mode ()
  "Turn on two-mode-mode"
  (interactive)
  (setq two-mode-update t)
  (two-mode-mode-setup)
  (two-mode-mode-update-mode)
  (if two-mode-hook
     (run-hooks 'two-mode-hook)))

