]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/realgud/debugger/rdebug/rdebug.el
Add 'packages/realgud/' from commit 'd811316e6a0f4eeee8a1347f504c196c86baa2cb'
[gnu-emacs-elpa] / packages / realgud / realgud / debugger / rdebug / rdebug.el
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"
11 :group 'realgud
12 :version "24.1")
13
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)
17
18 ;; -------------------------------------------------------------------
19 ;; User definable variables
20 ;;
21
22 (defcustom realgud:rdebug-command-name
23 ;;"rdebug --emacs 3"
24 "rdebug"
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."
27 :type 'string
28 :group 'realgud:rdebug)
29
30 (declare-function rdebug-track-mode (bool))
31
32 ;; -------------------------------------------------------------------
33 ;; The end.
34 ;;
35
36 (defun rdebug-get-script-name (args)
37 "Parse command line ARGS.
38
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.
42
43 Initially annotate should be set to nil. Argument ARGS contains
44 a tokenized list of the command line."
45 ;; Parse the following:
46 ;;
47 ;; [ruby ruby-options] rdebug rdebug-options script-name script-options
48 (and args
49 (let ((name nil)
50 (annotate-p nil))
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))))
55 (pop args)
56 (while (and args
57 (string-match "^-" (car args)))
58 (if (member (car args) '("-e" "-r" "-I" "-C" "-F" "-K"))
59 (pop args))
60 (pop args)))
61 ;; Remove "rdebug" from "rdebug --rdebug-options script
62 ;; --script-options"
63 (pop args)
64 ;; Skip to the first non-option argument.
65 (while (and args
66 (not name))
67 (let ((arg (pop args)))
68 (cond
69 ;; Annotation or emacs option with level number.
70 ((or (member arg '("--annotate" "-A"))
71 (equal arg "--emacs"))
72 (setq annotate-p t)
73 (pop args))
74 ;; Combined annotation and level option.
75 ((string-match "^--annotate=[0-9]" arg)
76 (setq annotate-p t))
77 ;; Options with arguments.
78 ((member arg '("-h" "--host" "-p" "--port"
79 "-I" "--include" "-r" "--require"))
80 (pop args))
81 ((string-match "^-" arg)
82 nil)
83 (t
84 (setq name arg)))))
85 (and name
86 (list name annotate-p)))))
87
88
89 ;;;###autoload
90 (defun realgud:rdebug (&optional opt-cmd-line no-reset)
91 "Invoke the rdebug Ruby debugger and start the Emacs user interface.
92
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'.
97
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.
105 "
106 (interactive)
107 (realgud:run-debugger "rdebug" 'rdebug-query-cmdline
108 'rdebug-parse-cmd-args
109 'realgud:rdebug-minibuffer-history
110 opt-cmd-line no-reset)
111 )
112
113
114 (defalias 'rdebug 'realgud:rdebug)
115 (provide-me "realgud-")