   (easy-menu-add specware-mode-menu)
   (if specware-use-x-symbol
       (x-symbol-mode t))
-  (if specware-use-hide-show
-      (hs-minor-mode t))
+  (when specware-use-hide-show
+    (hs-minor-mode t)
+    (setq hs-marker-begin-regexp "\\s-*%{{{")
+    (setq hs-marker-end-regexp "\\s-*%}}}"))
   (run-hooks 'specware-mode-hook))           ; Run the hook
 
 (defvar specware-mode-abbrev-table nil "*Specware mode abbrev table (default nil)")

  ;; white-space.
  ;; 
  ;;(make-local-variable 'parse-sexp-ignore-comments)
  ;;(setq parse-sexp-ignore-comments t)
  )

(defun specware-font-lock-fontify-region-function (beg end &optional loudvar)

		       (progn (beginning-of-line))
		     (end-of-buffer))
		   (forward-comment -100)) ; Go backward until non-comment found
	  (if (looking-at hs-marker-begin-regexp)
	      (sw:scan-matching-patterns "%{{{" "\\(%{{{\\|%}}}\\)")
	    (if (looking-at "(\\*")
		(sw:scan-matching-patterns "(\\*" "\\((\\*\\|\\*)\\)")
	      (let ((parse-sexp-ignore-comments t))
		(forward-sexp n)))))))))

(defun sw:scan-matching-patterns (beg beg-end)
  (let ((beg-marker (re-search-forward beg nil t)))
    (if (null beg-marker)
	(warn "No region marker")
      (sw:scan-to-end-matching-patterns beg beg-end))))

(defun sw:scan-to-end-matching-patterns (beg beg-end)
  (let ((next-marker (re-search-forward beg-end nil t)))
    (if (null next-marker)
	(warn "Unmatched marker")
      (progn (goto-char (match-beginning 0))
	     (if (looking-at beg)
		 (progn (sw:scan-matching-patterns beg beg-end)
			(sw:scan-to-end-matching-patterns beg beg-end))
	       (goto-char (match-end 0)))))))

(defun sw:adjust-begin (n)
  (point))
