4 ;; ======================================================================
7 ;;; History of argument lists passed to rubydb.
8 (defvar gud-rubydb-history nil
)
10 (defun gud-rubydb-massage-args (file args
)
11 (cons "-I" (cons "." (cons "-r" (cons "debug" (cons file args
))))))
13 ;; There's no guarantee that Emacs will hand the filter the entire
14 ;; marker at once; it could be broken up across several strings. We
15 ;; might even receive a big chunk with several markers in it. If we
16 ;; receive a chunk of text which looks like it might contain the
17 ;; beginning of a marker, we save it here between calls to the
19 (defvar gud-rubydb-marker-acc
"")
21 (defun gud-rubydb-marker-filter (string)
23 (setq gud-marker-acc
(concat gud-marker-acc string
))
26 ;; Process all the complete markers in this chunk.
27 (while (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
31 ;; Extract the frame position from the marker.
33 (cons (substring gud-marker-acc
(match-beginning 1) (match-end 1))
34 (string-to-int (substring gud-marker-acc
38 ;; Append any text before the marker to the output we're going
39 ;; to return - we don't include the marker in this text.
41 (substring gud-marker-acc
0 (match-beginning 0)))
43 ;; Set the accumulator to the remaining text.
44 gud-marker-acc
(substring gud-marker-acc
(match-end 0))))
46 ;; Does the remaining text look like it might end with the
47 ;; beginning of another marker? If it does, then keep it in
48 ;; gud-marker-acc until we receive the rest of it. Since we
49 ;; know the full marker regexp above failed, it's pretty simple to
50 ;; test for marker starts.
51 (if (string-match "\032.*\\'" gud-marker-acc
)
53 ;; Everything before the potential marker start can be output.
54 (setq output
(concat output
(substring gud-marker-acc
55 0 (match-beginning 0))))
57 ;; Everything after, we save, to combine with later input.
59 (substring gud-marker-acc
(match-beginning 0))))
61 (setq output
(concat output gud-marker-acc
)
66 (defun gud-rubydb-find-file (f)
67 (find-file-noselect f
))
69 (defvar rubydb-command-name
"ruby"
70 "File name for executing ruby.")
73 (defun rubydb (command-line)
74 "Run rubydb on program FILE in buffer *gud-FILE*.
75 The directory containing FILE becomes the initial working directory
76 and source-file directory for your debugger."
78 (list (read-from-minibuffer "Run rubydb (like this): "
79 (if (consp gud-rubydb-history
)
80 (car gud-rubydb-history
)
81 (concat rubydb-command-name
" "))
83 '(gud-rubydb-history .
1))))
85 (gud-overload-functions '((gud-massage-args . gud-rubydb-massage-args
)
86 (gud-marker-filter . gud-rubydb-marker-filter
)
87 (gud-find-file . gud-rubydb-find-file
)
89 (gud-common-init command-line
)
91 (gud-def gud-break
"b %l" "\C-b" "Set breakpoint at current line.")
92 ; (gud-def gud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
93 (gud-def gud-step
"s" "\C-s" "Step one source line with display.")
94 (gud-def gud-next
"n" "\C-n" "Step one line (skip functions).")
95 (gud-def gud-cont
"c" "\C-r" "Continue with display.")
96 (gud-def gud-finish
"finish" "\C-f" "Finish executing current function.")
97 (gud-def gud-up
"up %p" "<" "Up N stack frames (numeric arg).")
98 (gud-def gud-down
"down %p" ">" "Down N stack frames (numeric arg).")
99 (gud-def gud-print
"p %e" "\C-p" "Evaluate ruby expression at point.")
101 (setq comint-prompt-regexp
"^(rdb:-) ")
102 (setq paragraph-start comint-prompt-regexp
)
103 (run-hooks 'rubydb-mode-hook
)