 
 ;;; CODE FOR SPECWARE-MODE 
 
-(defun sl-indent-level (&optional indent)
+(defun sw:indent-level (&optional indent)
    "Allow the user to change the block indentation level. Numeric prefix 
 accepted in lieu of prompting."
    (interactive "NIndentation level: ")
-   (setq sl-indent-level indent))
-
-(defun sl-pipe-indent (&optional indent)
+   (setq sw:indent-level indent))
+
+(defun sw:pipe-indent (&optional indent)
   "Allow to change pipe indentation level (usually negative). Numeric prefix
 accepted in lieu of prompting."
    (interactive "NPipe Indentation level: ")
-   (setq sl-pipe-indent indent))
-
-(defun sl-case-indent (&optional of)
-  "Toggle sl-case-indent. Prefix means set it to nil."
+   (setq sw:pipe-indent indent))
+
+(defun sw:case-indent (&optional of)
+  "Toggle sw:case-indent. Prefix means set it to nil."
   (interactive "P")
-  (setq sl-case-indent (and (not of) (not sl-case-indent)))
-  (if sl-case-indent (message "%s" "true") (message "%s" nil)))
-
-(defun sl-nested-if-indent (&optional of)
-  "Toggle sl-nested-if-indent. Prefix means set it to nil."
+  (setq sw:case-indent (and (not of) (not sw:case-indent)))
+  (if sw:case-indent (message "%s" "true") (message "%s" nil)))
+
+(defun sw:nested-if-indent (&optional of)
+  "Toggle sw:nested-if-indent. Prefix means set it to nil."
   (interactive "P")
-  (setq sl-nested-if-indent (and (not of) (not sl-nested-if-indent)))
-  (if sl-nested-if-indent (message "%s" "true") (message "%s" nil)))
-
-(defun sl-type-of-indent (&optional of)
-  "Toggle sl-type-of-indent. Prefix means set it to nil."
+  (setq sw:nested-if-indent (and (not of) (not sw:nested-if-indent)))
+  (if sw:nested-if-indent (message "%s" "true") (message "%s" nil)))
+
+(defun sw:type-of-indent (&optional of)
+  "Toggle sw:type-of-indent. Prefix means set it to nil."
   (interactive "P")
-  (setq sl-type-of-indent (and (not of) (not sl-type-of-indent)))
-  (if sl-type-of-indent (message "%s" "true") (message "%s" nil)))
-
-(defun sl-electric-semi-mode (&optional of)
-  "Toggle sl-electric-semi-mode. Prefix means set it to nil."
+  (setq sw:type-of-indent (and (not of) (not sw:type-of-indent)))
+  (if sw:type-of-indent (message "%s" "true") (message "%s" nil)))
+
+(defun sw:electric-semi-mode (&optional of)
+  "Toggle sw:electric-semi-mode. Prefix means set it to nil."
   (interactive "P")
-  (setq sl-electric-semi-mode (and (not of) (not sl-electric-semi-mode)))
+  (setq sw:electric-semi-mode (and (not of) (not sw:electric-semi-mode)))
   (message "%s" (concat "Electric semi mode is " 
-                   (if sl-electric-semi-mode "on" "off"))))
+                   (if sw:electric-semi-mode "on" "off"))))
 
 (defun insert-circle-s () (interactive) (insert ""))
 (defun insert-open-quote () (interactive) (insert ""))

                              (not (zerop (% numb 2))))
                         t nil)))))))))

(defun sl-skip-block ()
  (let ((case-fold-search nil))
    (sl-backward-sexp)
    (if (looking-at "end\\b")
        (progn
          (goto-char (sl-find-match-backward "end" "\\bend\\b"
                                              sl-end-starters-reg))
          (skip-chars-backward "\n\t "))
      ;; Here we will need to skip backward past if-then-else
      ;; and case-of expression. Please - tell me how !!
      )))

(defun sl-find-match-backward (unquoted-this this match &optional start)
  (save-excursion
    (let ((case-fold-search nil)
          (level 1)
          (pattern (concat this "\\|" match)))
      (if start (goto-char start))
      (while (not (zerop level))
        (if (sl-re-search-backward pattern)
            (setq level (cond
                         ((looking-at this) (1+ level))
                         ((looking-at match) (1- level))))


;;; BINDINGS: should be common to the source and process modes...

(defun install-sw-keybindings (map)
  ;; Text-formatting commands:
  (define-key map "\C-c\C-m" 'sw:insert-form)
  (define-key map "\M-|"     'sw:electric-pipe)
  (define-key map "\;"       'sw:electric-semi)
  (define-key map "\M-\t"    'sw:back-to-outer-indent)
  (define-key map "\C-j"     'newline-and-indent)
  (define-key map "\177"     'backward-delete-char-untabify)
  (define-key map [backspace] 'backward-delete-char-untabify)
  (define-key map "\C-\M-\q" 'sw:indent-sexp)
  (define-key map "\C-\M-\\" 'sw:indent-region)
  (define-key map "\t"       'sw:indent-line) ; ...except this one

  (define-key map "\M-."     'specware-meta-point)
  (define-key map "\M-,"     'continue-specware-meta-point)
  (define-key map "\C-c\C-p"    'process-specware-file)
  (define-key map "\C-cl"    'sw:switch-to-lisp)
  (define-key map "\M-*"     'sw:switch-to-lisp)
  (define-key map "\C-?"     'backward-delete-char-untabify)
