]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/realgud/debugger/trepanx/core.el
Add 'packages/realgud/' from commit 'd811316e6a0f4eeee8a1347f504c196c86baa2cb'
[gnu-emacs-elpa] / packages / realgud / realgud / debugger / trepanx / core.el
1 ;;; Copyright (C) 2010, 2014 Rocky Bernstein <rocky@gnu.org>
2 (eval-when-compile (require 'cl))
3
4 (require 'load-relative)
5
6 (require-relative-list '("../../common/track"
7 "../../common/core"
8 "../../common/lang")
9 "realgud-")
10 (require-relative-list '("init") "realgud:trepanx-")
11
12 (declare-function realgud-parse-command-arg 'realgud-core)
13 (declare-function realgud-query-cmdline 'realgud-core)
14 (declare-function realgud-suggest-invocation 'realgud-core)
15
16 ;; FIXME: I think the following could be generalized and moved to
17 ;; realgud-... probably via a macro.
18 (defvar realgud:trepanx-minibuffer-history nil
19 "minibuffer history list for the command `realgud:trepanx'.")
20
21 (easy-mmode-defmap trepanx-minibuffer-local-map
22 '(("\C-i" . comint-dynamic-complete-filename))
23 "Keymap for minibuffer prompting of gud startup command."
24 :inherit minibuffer-local-map)
25
26 ;; FIXME: I think this code and the keymaps and history
27 ;; variable chould be generalized, perhaps via a macro.
28 (defun trepanx-query-cmdline (&optional opt-debugger)
29 (realgud-query-cmdline
30 'trepanx-suggest-invocation
31 trepanx-minibuffer-local-map
32 'realgud:trepanx-minibuffer-history
33 opt-debugger))
34
35 (defun trepanx-parse-cmd-args (orig-args)
36 "Parse command line ARGS for the annotate level and name of script to debug.
37
38 ARGS should contain a tokenized list of the command line to run.
39
40 We return the a list containing
41 - the command processor (e.g. ruby) and it's arguments if any - a list of strings
42 - the name of the debugger given (e.g. trepanx) and its arguments - a list of strings
43 - the script name and its arguments - list of strings
44 - whether the annotate or emacs option was given ('-A', '--annotate' or '--emacs) - a boolean
45
46 For example for the following input
47 (map 'list 'symbol-name
48 '(ruby1.9 -W -C /tmp trepanx --emacs ./gcd.rb a b))
49
50 we might return:
51 ((ruby1.9 -W -C) (trepanx --emacs) (./gcd.rb a b) 't)
52
53 NOTE: the above should have each item listed in quotes.
54 "
55
56 ;; Parse the following kind of pattern:
57 ;; [ruby ruby-options] trepanx trepanx-options script-name script-options
58 (let (
59 (args orig-args)
60 (pair) ;; temp return from
61 (ruby-opt-two-args '("0" "C" "e" "E" "F" "i"))
62 ;; Ruby doesn't have mandatory 2-arg options in our sense,
63 ;; since the two args can be run together, e.g. "-C/tmp" or "-C /tmp"
64 ;;
65 (ruby-two-args '())
66 ;; One dash is added automatically to the below, so
67 ;; h is really -h and -host is really --host.
68 (trepanx-two-args '("h" "-host" "p" "-port"
69 "I" "-include" "-r" "-require"))
70 (trepanx-opt-two-args '())
71
72 ;; Things returned
73 (script-name nil)
74 (debugger-name nil)
75 (interpreter-args '())
76 (debugger-args '())
77 (script-args '())
78 (annotate-p nil))
79
80 (if (not (and args))
81 ;; Got nothing: return '(nil, nil)
82 (list interpreter-args debugger-args script-args annotate-p)
83 ;; else
84 ;; Strip off optional "ruby" or "ruby182" etc.
85 (when (string-match "^ruby[-0-9]*$"
86 (file-name-sans-extension
87 (file-name-nondirectory (car args))))
88 (setq interpreter-args (list (pop args)))
89
90 ;; Strip off Ruby-specific options
91 (while (and args
92 (string-match "^-" (car args)))
93 (setq pair (realgud-parse-command-arg
94 args ruby-two-args ruby-opt-two-args))
95 (nconc interpreter-args (car pair))
96 (setq args (cadr pair))))
97
98 ;; Remove "trepanx" from "trepanx --trepanx-options script
99 ;; --script-options"
100 (setq debugger-name (file-name-sans-extension
101 (file-name-nondirectory (car args))))
102 (unless (string-match "^trepanx$" debugger-name)
103 (message
104 "Expecting debugger name `%s' to be `trepanx'"
105 debugger-name))
106 (setq debugger-args (list (pop args)))
107
108 ;; Skip to the first non-option argument.
109 (while (and args (not script-name))
110 (let ((arg (car args)))
111 (cond
112 ;; Annotation or emacs option with level number.
113 ((or (member arg '("--annotate" "-A"))
114 (equal arg "--emacs"))
115 (setq annotate-p t)
116 (nconc debugger-args (list (pop args))))
117 ;; Combined annotation and level option.
118 ((string-match "^--annotate=[0-9]" arg)
119 (nconc debugger-args (list (pop args)) )
120 (setq annotate-p t))
121 ;; Options with arguments.
122 ((string-match "^-" arg)
123 (setq pair (realgud-parse-command-arg
124 args trepanx-two-args trepanx-opt-two-args))
125 (nconc debugger-args (car pair))
126 (setq args (cadr pair)))
127 ;; Anything else must be the script to debug.
128 (t (setq script-name arg)
129 (setq script-args args))
130 )))
131 (list interpreter-args debugger-args script-args annotate-p))))
132
133 ;; To silence Warning: reference to free variable
134 (defvar realgud:trepanx-command-name)
135
136 (defun trepanx-suggest-invocation (debugger-name)
137 "Suggest a trepanx command invocation via `realgud-suggest-invocaton'"
138 (realgud-suggest-invocation realgud:trepanx-command-name
139 realgud:trepanx-minibuffer-history
140 "ruby" "\\.rb$" "trepanx"))
141
142 (defun trepanx-reset ()
143 "Trepanx cleanup - remove debugger's internal buffers (frame,
144 breakpoints, etc.)."
145 (interactive)
146 ;; (trepanx-breakpoint-remove-all-icons)
147 (dolist (buffer (buffer-list))
148 (when (string-match "\\*trepanx-[a-z]+\\*" (buffer-name buffer))
149 (let ((w (get-buffer-window buffer)))
150 (when w
151 (delete-window w)))
152 (kill-buffer buffer))))
153
154 ;; (defun trepanx-reset-keymaps()
155 ;; "This unbinds the special debugger keys of the source buffers."
156 ;; (interactive)
157 ;; (setcdr (assq 'trepanx-debugger-support-minor-mode minor-mode-map-alist)
158 ;; trepanx-debugger-support-minor-mode-map-when-deactive))
159
160
161 (defun realgud:trepanx-customize ()
162 "Use `customize' to edit the settings of the `trepanx' debugger."
163 (interactive)
164 (customize-group 'realgud:trepanx))
165
166 (provide-me "realgud:trepanx-")