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