(require 'gud)
(provide 'rubydb)
(defvar gud-rubydb-history nil)
(defun gud-rubydb-massage-args (file args)
(cons "-I" (cons "." (cons "-r" (cons "debug" (cons file args))))))
(defvar gud-rubydb-marker-acc "")
(defun gud-rubydb-marker-filter (string)
(save-match-data
(setq gud-marker-acc (concat gud-marker-acc string))
(let ((output ""))
(while (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
gud-marker-acc)
(setq
gud-last-frame
(cons (substring gud-marker-acc (match-beginning 1) (match-end 1))
(string-to-int (substring gud-marker-acc
(match-beginning 2)
(match-end 2))))
output (concat output
(substring gud-marker-acc 0 (match-beginning 0)))
gud-marker-acc (substring gud-marker-acc (match-end 0))))
(if (string-match "\032.*\\'" gud-marker-acc)
(progn
(setq output (concat output (substring gud-marker-acc
0 (match-beginning 0))))
(setq gud-marker-acc
(substring gud-marker-acc (match-beginning 0))))
(setq output (concat output gud-marker-acc)
gud-marker-acc ""))
output)))
(defun gud-rubydb-find-file (f)
(find-file-noselect f))
(defvar rubydb-command-name "ruby"
"File name for executing ruby.")
(defun rubydb (command-line)
"Run rubydb on program FILE in buffer *gud-FILE*.
The directory containing FILE becomes the initial working directory
and source-file directory for your debugger."
(interactive
(list (read-from-minibuffer "Run rubydb (like this): "
(if (consp gud-rubydb-history)
(car gud-rubydb-history)
(concat rubydb-command-name " "))
nil nil
'(gud-rubydb-history . 1))))
(gud-overload-functions '((gud-massage-args . gud-rubydb-massage-args)
(gud-marker-filter . gud-rubydb-marker-filter)
(gud-find-file . gud-rubydb-find-file)
))
(gud-common-init command-line)
(gud-def gud-break "b %l" "\C-b" "Set breakpoint at current line.")
(gud-def gud-step "s" "\C-s" "Step one source line with display.")
(gud-def gud-next "n" "\C-n" "Step one line (skip functions).")
(gud-def gud-cont "c" "\C-r" "Continue with display.")
(gud-def gud-finish "finish" "\C-f" "Finish executing current function.")
(gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
(gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
(gud-def gud-print "p %e" "\C-p" "Evaluate ruby expression at point.")
(setq comint-prompt-regexp "^(rdb:-) ")
(setq paragraph-start comint-prompt-regexp)
(run-hooks 'rubydb-mode-hook)
)