 (defun sw:re-search-backward (regexpr)
   (let ((case-fold-search nil) (found t))
     (if (re-search-backward regexpr nil t)
-        (save-match-data
+        (progn
           (condition-case ()
               (while (sw:inside-comment-or-string-p)
                 (re-search-backward regexpr))
             (error (setq found nil)))
+          (when found
+            (re-search-forward regexpr nil t)
+            (re-search-backward regexpr nil t))
           found)
       nil)))
 

  (unless (sw:re-search-backward sw:basic-unit-intro-regexp)
    (goto-char (point-min))
    (sw:re-search-forward "^\\sw")      ; Find any non-comment word
  (beginning-of-line))
    (beginning-of-line))

(defun sw:end-of-unit ()
  (interactive "")
  (forward-char 1)
  (unless (sw:re-search-forward sw:basic-unit-intro-regexp)
    (goto-char (point-max)))
  (beginning-of-line)
  (forward-char -1)
  (sw:re-search-backward "\\sw")	; Find any non-comment word
  (beginning-of-line)
  (forward-line 1))

(defun sw:next-unit ()
  (interactive "")
  (forward-char 1)
  (unless (sw:re-search-forward sw:basic-unit-intro-regexp)
    (goto-char (point-max)))
  (beginning-of-line))


		"theorem"
		"type")))

(defvar sw:whitespace "\\(\n\\|\\s-\\)")

(defvar sw:basic-unit-intro-regexp "^\\(\\sw+\\)\\(\n\\|\\s-\\)*=\\s-*")

(defvar sw:definition-intro-sexp
  (concat "\\s-*\\(" sw:definition-introducing-words "\\)\\>"))
