1 ;;; Copyright (C) 2010-2011, 2014-2015 Rocky Bernstein <rocky@gnu.org>
2 ;; `rdebug' Main interface to rdebug via Emacs
3 (require 'load-relative)
4 (require-relative-list '("../../common/helper"
5 "../../common/track") "realgud-")
6 (require-relative-list '("core" "track-mode") "realgud-rdebug-")
7 ;; This is needed, or at least the docstring part of it is needed to
8 ;; get the customization menu to work in Emacs 24.
9 (defgroup realgud:rdebug nil
10 "The realgud interface to the Ruby debugger, rdebug"
14 (declare-function rdebug-query-cmdline 'realgud-rdebug-core)
15 (declare-function rdebug-parse-cmd-args 'realgud-rdebug-core)
16 (declare-function realgud:run-debugger 'realgud:run)
18 ;; -------------------------------------------------------------------
19 ;; User definable variables
22 (defcustom realgud:rdebug-command-name
25 "File name for executing the Ruby debugger and command options.
26 This should be an executable on your path, or an absolute file name."
28 :group 'realgud:rdebug)
30 (declare-function rdebug-track-mode (bool))
32 ;; -------------------------------------------------------------------
36 (defun rdebug-get-script-name (args)
37 "Parse command line ARGS.
39 ARGS is a list of strings containing the rdebug command name. We
40 return a list containing the script name, and whether the
41 annotate option was set is returned.
43 Initially annotate should be set to nil. Argument ARGS contains
44 a tokenized list of the command line."
45 ;; Parse the following:
47 ;; [ruby ruby-options] rdebug rdebug-options script-name script-options
51 ;; Strip of optional "ruby" or "ruby182" etc.
52 (when (string-match "^ruby[0-9]*$"
53 (file-name-sans-extension
54 (file-name-nondirectory (car args))))
57 (string-match "^-" (car args)))
58 (if (member (car args) '("-e" "-r" "-I" "-C" "-F" "-K"))
61 ;; Remove "rdebug" from "rdebug --rdebug-options script
64 ;; Skip to the first non-option argument.
67 (let ((arg (pop args)))
69 ;; Annotation or emacs option with level number.
70 ((or (member arg '("--annotate" "-A"))
71 (equal arg "--emacs"))
74 ;; Combined annotation and level option.
75 ((string-match "^--annotate=[0-9]" arg)
77 ;; Options with arguments.
78 ((member arg '("-h" "--host" "-p" "--port"
79 "-I" "--include" "-r" "--require"))
81 ((string-match "^-" arg)
86 (list name annotate-p)))))
90 (defun realgud:rdebug (&optional opt-cmd-line no-reset)
91 "Invoke the rdebug Ruby debugger and start the Emacs user interface.
93 String OPT-CMD-LINE is treated like a shell string; arguments are
94 tokenized by `split-string-and-unquote'. The tokenized string is
95 parsed by `trepan8-parse-cmd-args' and path elements found by that
96 are expanded using `realgud:expand-file-name-if-exists'.
98 Normally, command buffers are reused when the same debugger is
99 reinvoked inside a command buffer with a similar command. If we
100 discover that the buffer has prior command-buffer information and
101 NO-RESET is nil, then that information which may point into other
102 buffers and source buffers which may contain marks and fringe or
103 marginal icons is reset. See `loc-changes-clear-buffer' to clear
104 fringe and marginal icons.
107 (realgud:run-debugger "rdebug" 'rdebug-query-cmdline
108 'rdebug-parse-cmd-args
109 'realgud:rdebug-minibuffer-history
110 opt-cmd-line no-reset)
114 (defalias 'rdebug 'realgud:rdebug)
115 (provide-me "realgud-")