(require 'gud)
(provide 'rdebug)
(defvar gud-rdebug-history nil)
(if (fboundp 'gud-overload-functions)
(defun gud-rdebug-massage-args (file args)
(cons file args))
(defun gud-rdebug-massage-args (file args)
args))
(defvar gud-rdebug-marker-acc "")
(make-variable-buffer-local 'gud-rdebug-marker-acc)
(defun gud-rdebug-marker-filter (string)
(setq gud-rdebug-marker-acc (concat gud-rdebug-marker-acc string))
(let ((output ""))
(while (string-match "\\([^:\n]*\\):\\([0-9]+\\):.*\n"
gud-rdebug-marker-acc)
(setq
gud-last-frame
(cons (substring gud-rdebug-marker-acc (match-beginning 1) (match-end 1))
(string-to-int (substring gud-rdebug-marker-acc
(match-beginning 2)
(match-end 2))))
output (concat output
(substring gud-rdebug-marker-acc 0 (match-beginning 0)))
gud-rdebug-marker-acc (substring gud-rdebug-marker-acc (match-end 0))))
(setq output (concat output gud-rdebug-marker-acc)
gud-rdebug-marker-acc "")
output))
(defun gud-rdebug-find-file (f)
(save-excursion
(let ((buf (find-file-noselect f)))
(set-buffer buf)
buf)))
(defvar rdebug-command-name "rdebug"
"File name for executing rdebug.")
(defun rdebug (command-line)
"Run rdebug 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 rdebug (like this): "
(if (consp gud-rdebug-history)
(car gud-rdebug-history)
(concat rdebug-command-name " "))
nil nil
'(gud-rdebug-history . 1))))
(if (not (fboundp 'gud-overload-functions))
(gud-common-init command-line 'gud-rdebug-massage-args
'gud-rdebug-marker-filter 'gud-rdebug-find-file)
(gud-overload-functions '((gud-massage-args . gud-rdebug-massage-args)
(gud-marker-filter . gud-rdebug-marker-filter)
(gud-find-file . gud-rdebug-find-file)))
(gud-common-init command-line rdebug-command-name))
(gud-def gud-break "break %d%f:%l" "\C-b" "Set breakpoint at current line in current file.")
(gud-def gud-step "step" "\C-s" "Step one source line with display.")
(gud-def gud-next "next" "\C-n" "Step one line (skip functions).")
(gud-def gud-cont "cont" "\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:-) ")
(if (boundp 'comint-last-output-start)
(set-marker comint-last-output-start (point)))
(set (make-local-variable 'paragraph-start) comint-prompt-regexp)
(run-hooks 'rdebug-mode-hook)
)