diff options
| author | Richard M. Stallman | 1994-03-25 18:31:42 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-03-25 18:31:42 +0000 |
| commit | 0e0de659c7e7a38224ea44b7ab8310d727a8b190 (patch) | |
| tree | fa0fdc4d62f1df92594f49797bacd359c9883556 | |
| parent | 32daa216192d20b884095e70e12d82ed5794fbac (diff) | |
| download | emacs-0e0de659c7e7a38224ea44b7ab8310d727a8b190.tar.gz emacs-0e0de659c7e7a38224ea44b7ab8310d727a8b190.zip | |
(gud-gdb-complete-command): New defun to support true
GDB completion in the GUD buffer. Requires assistance from
GDB in the form of the `complete' command.
(gud-gdb-complete-in-progress, gud-gdb-complete-string,
gud-gdb-complete-break, gud-gdb-complete-list,
gud-gdb-complete-filter): New.
(gdb): Bind TAB to gud-gdb-complete-command.
| -rw-r--r-- | lisp/gud.el | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/lisp/gud.el b/lisp/gud.el index 843999c4c31..1234a25485e 100644 --- a/lisp/gud.el +++ b/lisp/gud.el | |||
| @@ -31,7 +31,8 @@ | |||
| 31 | ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com> | 31 | ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com> |
| 32 | ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>, | 32 | ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>, |
| 33 | ;; who also hacked the mode to use comint.el. Shane Hartman <shane@spr.com> | 33 | ;; who also hacked the mode to use comint.el. Shane Hartman <shane@spr.com> |
| 34 | ;; added support for xdb (HPUX debugger). | 34 | ;; added support for xdb (HPUX debugger). Rick Sladkey <jrs@world.std.com> |
| 35 | ;; wrote the GDB command completion code. | ||
| 35 | 36 | ||
| 36 | ;;; Code: | 37 | ;;; Code: |
| 37 | 38 | ||
| @@ -252,10 +253,94 @@ and source-file directory for your debugger." | |||
| 252 | (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") | 253 | (gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).") |
| 253 | (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.") | 254 | (gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.") |
| 254 | 255 | ||
| 256 | (local-set-key "\C-i" 'gud-gdb-complete-command) | ||
| 255 | (setq comint-prompt-regexp "^(.*gdb[+]?) *") | 257 | (setq comint-prompt-regexp "^(.*gdb[+]?) *") |
| 256 | (run-hooks 'gdb-mode-hook) | 258 | (run-hooks 'gdb-mode-hook) |
| 257 | ) | 259 | ) |
| 258 | 260 | ||
| 261 | ;; One of the nice features of GDB is its impressive support for | ||
| 262 | ;; context-sensitive command completion. We preserve that feature | ||
| 263 | ;; in the GUD buffer by using a GDB command designed just for Emacs. | ||
| 264 | |||
| 265 | ;; The completion process filter indicates when it is finished. | ||
| 266 | (defvar gud-gdb-complete-in-progress) | ||
| 267 | |||
| 268 | ;; Since output may arrive in fragments we accumulate partials strings here. | ||
| 269 | (defvar gud-gdb-complete-string) | ||
| 270 | |||
| 271 | ;; We need to know how much of the completion to chop off. | ||
| 272 | (defvar gud-gdb-complete-break) | ||
| 273 | |||
| 274 | ;; The completion list is constructed by the process filter. | ||
| 275 | (defvar gud-gdb-complete-list) | ||
| 276 | |||
| 277 | (defun gud-gdb-complete-command () | ||
| 278 | "Perform completion on the GDB command preceding point. | ||
| 279 | This is implemented using the GDB `complete' command which isn't | ||
| 280 | available with older versions of GDB." | ||
| 281 | (interactive) | ||
| 282 | (let* ((end (point)) | ||
| 283 | (command (save-excursion | ||
| 284 | (beginning-of-line) | ||
| 285 | (and (looking-at comint-prompt-regexp) | ||
| 286 | (goto-char (match-end 0))) | ||
| 287 | (buffer-substring (point) end))) | ||
| 288 | command-word) | ||
| 289 | ;; Find the word break. This match will always succeed. | ||
| 290 | (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command) | ||
| 291 | (setq gud-gdb-complete-break (match-beginning 2) | ||
| 292 | command-word (substring command gud-gdb-complete-break)) | ||
| 293 | (unwind-protect | ||
| 294 | (progn | ||
| 295 | ;; Temporarily install our filter function. | ||
| 296 | (gud-overload-functions | ||
| 297 | '((gud-marker-filter . gud-gdb-complete-filter))) | ||
| 298 | ;; Issue the command to GDB. | ||
| 299 | (gud-basic-call (concat "complete " command)) | ||
| 300 | (setq gud-gdb-complete-in-progress t | ||
| 301 | gud-gdb-complete-string nil | ||
| 302 | gud-gdb-complete-list nil) | ||
| 303 | ;; Slurp the output. | ||
| 304 | (while gud-gdb-complete-in-progress | ||
| 305 | (accept-process-output (get-buffer-process gud-comint-buffer)))) | ||
| 306 | ;; Restore the old filter function. | ||
| 307 | (gud-overload-functions '((gud-marker-filter . gud-gdb-marker-filter)))) | ||
| 308 | ;; Protect against old versions of GDB. | ||
| 309 | (and gud-gdb-complete-list | ||
| 310 | (string-match "^Undefined command: \"complete\"" | ||
| 311 | (car gud-gdb-complete-list)) | ||
| 312 | (error "This version of GDB doesn't support the `complete' command.")) | ||
| 313 | ;; Sort the list like readline. | ||
| 314 | (setq gud-gdb-complete-list | ||
| 315 | (sort gud-gdb-complete-list (function string-lessp))) | ||
| 316 | ;; Remove duplicates. | ||
| 317 | (let ((first gud-gdb-complete-list) | ||
| 318 | (second (cdr gud-gdb-complete-list))) | ||
| 319 | (while second | ||
| 320 | (if (string-equal (car first) (car second)) | ||
| 321 | (setcdr first (setq second (cdr second))) | ||
| 322 | (setq first second | ||
| 323 | second (cdr second))))) | ||
| 324 | ;; Let comint handle the rest. | ||
| 325 | (comint-dynamic-simple-complete command-word gud-gdb-complete-list))) | ||
| 326 | |||
| 327 | ;; The completion process filter is installed temporarily to slurp the | ||
| 328 | ;; output of GDB up to the next prompt and build the completion list. | ||
| 329 | (defun gud-gdb-complete-filter (string) | ||
| 330 | (setq string (concat gud-gdb-complete-string string)) | ||
| 331 | (while (string-match "\n" string) | ||
| 332 | (setq gud-gdb-complete-list | ||
| 333 | (cons (substring string gud-gdb-complete-break (match-beginning 0)) | ||
| 334 | gud-gdb-complete-list)) | ||
| 335 | (setq string (substring string (match-end 0)))) | ||
| 336 | (if (string-match comint-prompt-regexp string) | ||
| 337 | (progn | ||
| 338 | (setq gud-gdb-complete-in-progress nil) | ||
| 339 | string) | ||
| 340 | (progn | ||
| 341 | (setq gud-gdb-complete-string string) | ||
| 342 | ""))) | ||
| 343 | |||
| 259 | 344 | ||
| 260 | ;; ====================================================================== | 345 | ;; ====================================================================== |
| 261 | ;; sdb functions | 346 | ;; sdb functions |