 
  
-;; rdebugtrack functions
-(defun rdebug-rdebugtrack-toggle-stack-tracking (arg)
+;; rdebugtrack 
+(defcustom rdebugrack-mode-text " rdebug"
+  "*String to display in the mode line when rdebugtrack mode is active.
+
+\(When the string is not empty, make sure that it has a leading space.)"
+  :tag "rdebug mode text"                ; To separate it from `global-...'
+  :group 'rdebug
+  :type 'string)
+
+(define-minor-mode rdebugtrack-mode ()
+  "Minor mode for tracking ruby debugging inside a process shell."
+  :init-value nil
+  ;; The indicator for the mode line.
+  :lighter rdebugtrack-mode-text
+  ;; The minor mode bindings.
+  :keymap
+  '(("\C-cg" . 'rdebug-goto-traceback-line)
+    ("\C-cG" . 'rdebug-goto-dollarbang-traceback-line))
+  :global nil
+  :group 'rdebug
+  (rdebugtrack-toggle-stack-tracking 1)
+  (setq rdebugtrack-is-tracking-p t)
+  (local-set-key "\C-cg" 'rdebug-goto-traceback-line)
+  (local-set-key "\C-cG" 'rdebug-goto-dollarbang-traceback-line)
+  (add-hook 'comint-output-filter-functions 'rdebugtrack-track-stack-file)
+  (run-mode-hooks 'rdebugtrack-mode-hook))
+
+
+(defun rdebugtrack-toggle-stack-tracking (arg)
   (interactive "P")
   (if (not (get-buffer-process (current-buffer)))
-      (error "No process associated with buffer '%s'" (current-buffer)))
-  ;; missing or 0 is toggle, >0 turn on, <0 turn off
-  (if (or (not arg)
-	  (zerop (setq arg (prefix-numeric-value arg))))
-      (setq rdebug-rdebugtrack-do-tracking-p (not rdebug-rdebugtrack-do-tracking-p))
-    (setq rdebug-rdebugtrack-do-tracking-p (> arg 0)))
-  (message "%sabled rdebug's rdebugtrack"
-           (if rdebug-rdebugtrack-do-tracking-p "En" "Dis")))
-
-(defun turn-on-rdebugtrack ()
+      (message "No process associated with buffer '%s'" (current-buffer))
+    ;else
+    ;; missing or 0 is toggle, >0 turn on, <0 turn off
+    (if (or (not arg)
+	    (zerop (setq arg (prefix-numeric-value arg))))
+	(setq rdebugtrack-do-tracking-p (not rdebugtrack-do-tracking-p))
+      (setq rdebugtrack-do-tracking-p (> arg 0)))
+    (message "%sabled rdebug's rdebugtrack"
+	     (if rdebugtrack-do-tracking-p "En" "Dis")))
+  )
+
+(defun turn-on-rdebugtrack-mode ()
+  "Turn on rdebugtrack mode.
+
+This function is designed to be added to hooks, for example:
+  (add-hook 'comint-mode-hook 'turn-on-rdebugtrack-mode)"
   (interactive)
-  (rdebug-rdebugtrack-toggle-stack-tracking 1)
-  (setq rdebug-rdebugtrack-is-tracking-p t)
-  (local-set-key "\C-cg" 'rdebug-goto-traceback-line)
-  (local-set-key "\C-cG" 'rdebug-goto-dollarbang-traceback-line)
-  (add-hook 'comint-output-filter-functions 'rdebug-rdebugtrack-track-stack-file)
-  ; remove other py-pdbtrack if which gets in the way
-  (remove-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
-  (remove-hook 'comint-output-filter-functions 'py-pydbtrack-track-stack-file)
-  (remove-hook 'comint-output-filter-functions 'bashdb-bashdbtrack-track-stack-file)
+  (rdebugtrack-mode 1)
 )
 
 (defun turn-off-rdebugtrack ()
   (interactive)
-  (rdebug-rdebugtrack-toggle-stack-tracking 0)
-  (setq rdebug-rdebugtrack-is-tracking-p nil)
+  (setq rdebugtrack-is-tracking-p nil)
+  (rdebugtrack-toggle-stack-tracking 0)
   (remove-hook 'comint-output-filter-functions 
-	       'rdebug-rdebugtrack-track-stack-file) )
+	       'rdebugtrack-track-stack-file))
 
 ;; Add a designator to the minor mode strings if we are tracking
-(or (assq 'rdebug-rdebugtrack-minor-mode-string minor-mode-alist)
+(or (assq 'rdebugtrack-minor-mode-string minor-mode-alist)
     (add-to-list 'minor-mode-alist 
-		 '(rdebug-rdebugtrack-is-tracking-p
-		   rdebug-rdebugtrack-minor-mode-string)))
+		 '(rdebugtrack-is-tracking-p
+		   rdebugtrack-minor-mode-string)))
 ;; rdebugtrack
 
 ;;-----------------------------------------------------------------------------

  "\n")

;; rdebugtrack constants
(defconst rdebug-rdebugtrack-stack-entry-regexp
      "^(\\([-a-zA-Z0-9_/.]*\\):\\([0-9]+\\)):[ \t]?\\(.*\n\\)"
  "Regular expression rdebugtrack uses to find a stack trace entry.")

(defconst rdebug-rdebugtrack-input-prompt "\n(+rdb:\\([0-9]+\\|post-mortem\\))+ *"
  "Regular expression rdebugtrack uses to recognize a rdebug prompt.")

(defconst rdebug-rdebugtrack-track-range 10000
  "Max number of characters from end of buffer to search for stack entry.")

(defun gud-rdebug-massage-args (file args)

	)))
    )

(defun rdebugtrack-get-source-buffer (block-str)
  "Return line number and buffer of code indicated by block-str's traceback 
text.

