   )
 )
 
+(defun lkm-is-line-label ()
+  "Returns t if the current line is a label"
+  (setq current-line (thing-at-point 'line))
+  (string-match "^[%A-Za-z][A-Za-z0-9]*:?\\|^[0-9]+:?" current-line))
+
+(defun lkm-validate-line-label ()
+  "Tells you whether or not the current line contains a valid line label"
+  (interactive)
+  (if (lkm-is-line-label)
+      (message "This is a line label"))
+  (if (not (lkm-is-line-label)) 
+      (message "This is not a line label")))
+
+(defun lkm-parent-label-distance ()
+  "Returns the distance from the parent label in number of lines"
+  (setq lkm-distance 0)
+  (save-excursion
+    (while (not (lkm-is-line-label))
+      (forward-line -1)
+      (incf lkm-distance)))  
+  (setq lkm-distance lkm-distance))
+
+(defun lkm-print-parent-label-distance ()
+  "Print the distance from the parent label"
+  (interactive)
+  (message "The distance from the parent label is %d lines" (lkm-parent-label-distance)))
+
+(defun lkm-parent-label-name ()
+  "Returns the name of the parent label"
+  (save-excursion
+    (forward-line (- (lkm-parent-label-distance)))
+    (setq label-line (thing-at-point 'line)))
+  (string-match "^[%A-Za-z][A-Za-z0-9]*:?\\|^[0-9]+:?" label-line)
+  (setq label-line (substring label-line 0 (match-end 0))))
+
+(defun lkm-print-parent-label-name ()
+  "Print the parent label name"
+  (interactive)
+  (message "The parent label is '%s'" (lkm-parent-label-name)))
+
+(defun lkm-current-label-offset-routine ()
+  "Get the current label+offset^routine"
+  (setq pl-label (lkm-parent-label-name))
+  (setq pl-offset (lkm-parent-label-distance))
+  (string-match "^[[:alnum:]]+" (buffer-name))
+  (setq pl-routine (substring (buffer-name) 0 (match-end 0)))
+  (if (not (= pl-offset 0))
+      (setq pl-result (format "%s+%d^%s" pl-label pl-offset pl-routine)))
+  (if (= pl-offset 0)
+      (setq pl-result (format "%s^%s" pl-label pl-routine)))
+  (setq pl-result pl-result))
+
+(defun lkm-print-current-label-offset-routine ()
+  "Print the current label+offset^routine"
+  (interactive)
+  (message (lkm-current-label-offset-routine)))
+
 (defun lkm-gtm-global-lookup (global)
   "Look up a global in GT.M"
   (interactive "sWhat global would you like to look up? ")

  "mumps mode"
  "LorikeeM MUMPS Developer Tools"

  (setq lkm-version "0.99.4")
  (message "LorikeeM MUMPS Developer Tools %s" lkm-version)

  (setq frame-title-format "LorikeeM MUMPS Developer Tools")

  ;;
  ;; set up syntax table entries

  "MUMPS keywords for completion")

;; build the regexps from the lists
(setq mumps-line-label "^[%A-Za-z][A-Za-z0-9]*:?\\|^[0-9]+:?")
(setq mumps-string-error "\\\\\".*")
(setq mumps-unmatched-open-paren "\(.*")
(setq mumps-unmatched-close-paren "\).*")
(defvar mkuf (regexp-opt mumps-keywords-ucase-full 'words))
(defvar mklf (regexp-opt mumps-keywords-lcase-full 'words))
(defvar mkua (regexp-opt mumps-keywords-ucase-abbrev 'words))
