 
 ;;; Factor mode indentation:
 
-(defvar factor-indent-width factor-default-indent-width
-  "Indentation width in factor buffers. A local variable.")
-
-(make-variable-buffer-local 'factor-indent-width)
+(make-variable-buffer-local
+ (defvar factor-indent-width factor-default-indent-width
+   "Indentation width in factor buffers. A local variable."))
 
 (defconst factor--regexp-word-start
   (let ((sws '("" ":" "TUPLE" "MACRO" "MACRO:" "M")))

            (setq iw (current-indentation))))))
    iw))

(defun factor--brackets-depth ()
  "Returns number of brackets, not closed on previous lines."
  (syntax-ppss-depth
   (save-excursion
     (syntax-ppss (line-beginning-position)))))

(defun factor--calculate-indentation ()
  "Calculate Factor indentation for line at point."
  (let ((not-indented t)
        (cur-indent 0))
    (save-excursion
      (beginning-of-line)
      (if (bobp)
          (setq cur-indent 0)
        (save-excursion
          (while not-indented
            ;; Check that we are inside open brackets
            (save-excursion
              (let ((cur-depth (factor--brackets-depth)))
                (forward-line -1)
                (setq cur-indent (+ (current-indentation)
                                    (* factor-indent-width
                                       (- cur-depth (factor--brackets-depth)))))
                (setq not-indented nil)))
            (forward-line -1)
              ;; Check that we are after the end of previous word
              (if (looking-at ".*;[ \t]*$")
                  (progn
                    (setq cur-indent (- (current-indentation) factor-indent-width))
                    (setq not-indented nil))
                ;; Check that we are after the start of word
                (if (looking-at factor--regexp-word-start)
                    (progn
                      (message "inword")
                      (setq cur-indent (+ (current-indentation) factor-indent-width))
                      (setq not-indented nil))
                  (if (bobp)
                      (setq not-indented nil))))))))
    cur-indent))

(defun factor-indent-line ()
  "Indent current line as Factor code"

  (factor-listener-mode))

(defun factor-refresh-all ()
  "Reload source files and documentation for all loaded
vocabularies which have been modified on disk."
  (interactive)
  (comint-send-string "*factor*" "refresh-all\n"))

