]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/realgud/common/cmds.el
Add 'packages/realgud/' from commit 'd811316e6a0f4eeee8a1347f504c196c86baa2cb'
[gnu-emacs-elpa] / packages / realgud / realgud / common / cmds.el
1 ;;; Copyright (C) 2010-2011, 2013-2015 Rocky Bernstein <rocky@gnu.org>
2 (require 'load-relative)
3 (require-relative-list '("send" "core") "realgud-")
4 (require-relative-list '("buffer/command") "realgud-buffer-")
5 (require-relative-list '("buffer/source") "realgud-buffer-")
6
7 (declare-function buffer-killed? 'helper)
8 (declare-function realgud-cmdbuf-info-in-srcbuf?= 'realgud-buffer-command)
9 (declare-function realgud-cmdbuf? 'realgud-buffer-command)
10 (declare-function realgud-command 'realgud-cmd)
11 (declare-function realgud-get-cmdbuf 'realgud-buffer-helper)
12 (declare-function realgud-get-command 'realgud-buffer-command)
13 (declare-function realgud-get-bpnum-from-line-num 'realgud-buffer-source)
14
15 (declare-function realgud:terminate 'realgud-core)
16 (declare-function realgud:terminate-srcbuf 'realdgud-core)
17
18 (defun realgud:cmd-remap(arg cmd-name default-cmd-template key
19 &optional no-record? frame-switch?
20 realgud-prompts?)
21 "Run debugger command CMD-NAME using DEFAULT-CMD-TEMPLATE
22 if none has been set in the command hash. If key is given we'll set
23 a shortcut for that key."
24 (let ((buffer (current-buffer))
25 (cmdbuf (realgud-get-cmdbuf))
26 (cmd-hash)
27 (cmd)
28 )
29 (with-current-buffer-safe cmdbuf
30 (realgud-cmdbuf-info-in-srcbuf?= (not (realgud-cmdbuf? buffer)))
31 (setq cmd-hash (realgud-cmdbuf-info-cmd-hash realgud-cmdbuf-info))
32 (unless (and cmd-hash (setq cmd (gethash cmd-name cmd-hash)))
33 (setq cmd default-cmd-template))
34 )
35 (realgud-command cmd arg no-record? frame-switch? realgud-prompts?)
36 ;; FIXME: Figure out how to update the position if the source
37 ;; buffer is displayed.
38 ;; (if frame-switch?
39 ;; (let* ((src-buffer (realgud-get-srcbuf-from-cmdbuf cmdbuf))
40 ;; (src-window (get-buffer-window src-buffer))
41 ;; ))
42 ;; (with-selected-window src-window
43 ;; (message "recentering...")
44 ;; (realgud-recenter-arrow)
45 ;; ))
46 )
47 ;; FIXME: this is a one-time thing. Put in caller.
48 (if key
49 (local-set-key (format "\C-c%s" key)
50 (intern (format "realgud:cmd-%s" cmd-name)))
51 )
52 )
53
54 (defun realgud:cmd-backtrace(arg)
55 "Show the current call stack"
56 (interactive "p")
57 (realgud:cmd-remap arg "backtrace" "backtrace" "T")
58 )
59
60 (defun realgud:cmd-break(arg)
61 "Set a breakpoint at the current line"
62 (interactive "p")
63 (realgud:cmd-remap arg "break" "break %X:%l" "b"))
64
65 (defun realgud:cmd-clear(line-num)
66 "Delete breakpoint at the current line"
67 (interactive "p")
68 (realgud:cmd-remap line-num "clear" "clear %l" "X"))
69
70 (defun realgud:cmd-continue(&optional arg)
71 "Continue execution."
72 (interactive "MContinue args: ")
73 (realgud:cmd-remap arg "continue" "continue" "c")
74 )
75
76 (defun realgud:cmd-delete(&optional arg)
77 "Delete breakpoint by number."
78 (interactive "pBreakpoint number: ")
79 (let* ((line-num (line-number-at-pos))
80 (arg (realgud-get-bpnum-from-line-num line-num)))
81 (if arg
82 (realgud:cmd-remap arg "delete" "delete %p" "D")
83 (message "Can't find breakpoint at line %d" line-num))
84 )
85 )
86
87 (defun realgud:cmd-disable(&optional arg)
88 "Disable breakpoint."
89 (interactive "NBreakpoint number: ")
90 (realgud:cmd-remap arg "disable" "disable %p" "-")
91 )
92
93 (defun realgud:cmd-enable(&optional arg)
94 "Enable breakpoint."
95 (interactive "NBreakpoint number: ")
96 (realgud:cmd-remap arg "enable" "enable %p" "+")
97 )
98
99 (defun realgud:cmd-eval(arg)
100 "Exaluate an expression."
101 (interactive "MEval expesssion: ")
102 (realgud:cmd-remap arg "eval" "eval %s" "e")
103 )
104
105 (defun realgud:cmd-eval-region(start end)
106 (interactive "r")
107 (let ((text (buffer-substring-no-properties start end)))
108 (realgud:cmd-remap text "eval" "eval %s" "e")
109 )
110 )
111
112 (defun realgud:cmd-finish(&optional arg)
113 "Run until the completion of the current stack frame.
114
115 This command is often referred to as 'step out' as opposed to
116 'step over' or 'step into'.
117 "
118 (interactive "p")
119 (realgud:cmd-remap arg "finish" "finish" ".")
120 )
121
122 (defun realgud:cmd-frame(arg)
123 "Change the current frame number to the value of the numeric argument.
124 If no argument specified use 0 or the most recent frame."
125 (interactive "p")
126 (realgud:cmd-remap arg "frame" "frame %p" "f" t t)
127 )
128
129 (defun realgud:cmd-kill(arg)
130 "kill debugger process"
131 (interactive "p")
132 (realgud:cmd-remap arg "kill" "kill" "k" nil nil 't)
133 )
134
135 (defun realgud:cmd-newer-frame(&optional arg)
136 "Move the current frame to a newer (more recent) frame.
137 With a numeric argument move that many levels forward."
138 (interactive "p")
139 (realgud:cmd-remap arg "down" "down %p" "<" t t)
140 )
141
142 (defun realgud:cmd-next(&optional arg)
143 "Step one source line at current call level.
144
145 With a numeric argument, step that many times. This command is
146 often referred to as 'step through' as opposed to 'step into' or
147 'step out'.
148
149 The definition of 'next' is debugger specific so, see the
150 debugger documentation for a more complete definition of what is
151 getting stepped."
152 (interactive "p")
153 (realgud:cmd-remap arg "next" "next %p" "n")
154 )
155
156 (defun realgud:cmd-next-no-arg(&optional arg)
157 "Step one source line at current call level.
158
159 The definition of 'next' is debugger specific so, see the
160 debugger documentation for a more complete definition of what is
161 getting stepped."
162 (interactive)
163 (realgud:cmd-remap nil "next" "next" "n")
164 )
165
166 (defun realgud:cmd-older-frame(&optional arg)
167 "Move the current frame to an older (less recent) frame.
168 With a numeric argument move that many levels back."
169 (interactive "p")
170 (realgud:cmd-remap arg "up" "up %p" ">" t t)
171 )
172
173 (defun realgud:cmd-restart(&optional arg)
174 "Restart execution."
175 (interactive "MRestart args: ")
176 (realgud:cmd-remap arg "restart" "run" "R" 't nil 't)
177 )
178
179 (defun realgud:cmd-shell(&optional arg)
180 "Restart execution."
181 (interactive "p")
182 (realgud:cmd-remap arg "shell" "shell" "S")
183 )
184
185 (defun realgud:cmd-step(&optional arg)
186 "Step one source line.
187
188 With a numeric argument, step that many times.
189 This command is often referred to as 'step into' as opposed to
190 'step over' or 'step out'.
191
192 The definition of 'step' is debugger specific so, see the
193 debugger documentation for a more complete definition of what is
194 getting stepped."
195 (interactive "p")
196 (realgud:cmd-remap arg "step" "step %p" "s")
197 )
198
199 (defun realgud:cmd-step-no-arg()
200 "Step one source line.
201
202 The definition of 'step' is debugger specific so, see the
203 debugger documentation for a more complete definition of what is
204 getting stepped."
205 (interactive)
206 (realgud:cmd-remap nil "step" "step" "s")
207 )
208
209 (defun realgud:cmd-terminate (&optional arg)
210 "Gently terminate source and command buffers without possibly
211 issuing a command to the underlying debuger. Use this if the
212 underlying debugger has died or you want to get out of all
213 shortkey modes in the source window and possibly restart
214 debugging after editing source."
215 (interactive "p")
216 (realgud:terminate (current-buffer))
217 )
218
219 (defun realgud:cmd-until(&optional arg)
220 "Run until the completion of the current stack frame.
221
222 Continue until the current line. In some cases this is really
223 two commands - setting a temporary breakpoint on the line and
224 continuing execution."
225 (interactive "p")
226 (realgud:cmd-remap arg "until" "until" "u")
227 )
228
229 (defun realgud:cmd-quit (&optional arg)
230 "Gently terminate execution of the debugged program."
231 (interactive "p")
232 (let ((buffer (current-buffer))
233 (cmdbuf (realgud-get-cmdbuf))
234 (cmd-hash)
235 (cmd)
236 )
237 (if cmdbuf
238 (progn
239 (with-current-buffer cmdbuf
240 (realgud-cmdbuf-info-in-srcbuf?= (not (realgud-cmdbuf? buffer)))
241 (setq cmd-hash (realgud-cmdbuf-info-cmd-hash realgud-cmdbuf-info))
242 (unless (and cmd-hash (setq cmd (gethash "quit" cmd-hash)))
243 (setq cmd "quit"))
244 )
245 (realgud-command cmd arg 't)
246 (if cmdbuf (realgud:terminate cmdbuf))
247 )
248 ; else
249 (realgud:terminate-srcbuf buffer)
250 )
251 )
252 )
253
254 (local-set-key "\C-cq" 'realgud:cmd-quit)
255
256 (provide-me "realgud-")