Commit b5b8e7de authored by Stefan Monnier's avatar Stefan Monnier
Browse files

* lisp/progmodes/gud.el (gud-gdb): Use completion-at-point instead of

gud-gdb-complete-command.
(gud-gdb-completions): New function, from gud-gdb-complete-command.
(gud-gdb-completion-at-point): New function.
(gud-gdb-completions): Remove.
parent 7990b61a
2011-04-15 Stefan Monnier <monnier@iro.umontreal.ca>
* progmodes/gud.el (gud-gdb): Use completion-at-point instead of
gud-gdb-complete-command.
(gud-gdb-completions): New function, from gud-gdb-complete-command.
(gud-gdb-completion-at-point): New function.
(gud-gdb-completions): Remove.
2011-04-14 Michael Albinus <michael.albinus@gmx.de> 2011-04-14 Michael Albinus <michael.albinus@gmx.de>
* net/tramp-sh.el (tramp-sh-handle-file-attributes): Handle the * net/tramp-sh.el (tramp-sh-handle-file-attributes): Handle the
......
...@@ -767,7 +767,9 @@ directory and source-file directory for your debugger." ...@@ -767,7 +767,9 @@ directory and source-file directory for your debugger."
(gud-def gud-until "until %l" "\C-u" "Continue to current line.") (gud-def gud-until "until %l" "\C-u" "Continue to current line.")
(gud-def gud-run "run" nil "Run the program.") (gud-def gud-run "run" nil "Run the program.")
(local-set-key "\C-i" 'gud-gdb-complete-command) (add-hook 'completion-at-point-functions #'gud-gdb-completion-at-point
nil 'local)
(local-set-key "\C-i" 'completion-at-point)
(setq comint-prompt-regexp "^(.*gdb[+]?) *") (setq comint-prompt-regexp "^(.*gdb[+]?) *")
(setq paragraph-start comint-prompt-regexp) (setq paragraph-start comint-prompt-regexp)
(setq gdb-first-prompt t) (setq gdb-first-prompt t)
...@@ -791,26 +793,28 @@ directory and source-file directory for your debugger." ...@@ -791,26 +793,28 @@ directory and source-file directory for your debugger."
;; The completion list is constructed by the process filter. ;; The completion list is constructed by the process filter.
(defvar gud-gdb-fetched-lines) (defvar gud-gdb-fetched-lines)
(defun gud-gdb-complete-command (&optional command a b) (defun gud-gdb-completions (context command)
"Perform completion on the GDB command preceding point. "Completion table for GDB commands.
This is implemented using the GDB `complete' command which isn't COMMAND is the prefix for which we seek completion.
available with older versions of GDB." CONTEXT is the text before COMMAND on the line."
(interactive) (let* ((start (- (point) (field-beginning)))
(if command (complete-list
;; Used by gud-watch in mini-buffer. (gud-gdb-run-command-fetch-lines (concat "complete " context command)
(setq command (concat "p " command))
;; Used in GUD buffer.
(let ((end (point)))
(setq command (buffer-substring (comint-line-beginning-position) end))))
(let* ((command-word
;; Find the word break. This match will always succeed.
(and (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
(substring command (match-beginning 2))))
(complete-list
(gud-gdb-run-command-fetch-lines (concat "complete " command)
(current-buffer) (current-buffer)
;; From string-match above. ;; From string-match above.
(match-beginning 2)))) (length context))))
;; `gud-gdb-run-command-fetch-lines' has some nasty side-effects on the
;; buffer (via `gud-delete-prompt-marker'): it removes the prompt and then
;; re-adds it later, thus messing up markers and overlays along the way.
;; This is a problem for completion-in-region which uses an overlay to
;; create a field.
;; So we restore completion-in-region's field if needed.
;; FIXME: change gud-gdb-run-command-fetch-lines so it doesn't modify the
;; buffer at all.
(when (/= start (- (point) (field-beginning)))
(dolist (ol (overlays-at (1- (point))))
(when (eq (overlay-get ol 'field) 'completion)
(move-overlay ol (- (point) start) (overlay-end ol)))))
;; Protect against old versions of GDB. ;; Protect against old versions of GDB.
(and complete-list (and complete-list
(string-match "^Undefined command: \"complete\"" (car complete-list)) (string-match "^Undefined command: \"complete\"" (car complete-list))
...@@ -836,8 +840,27 @@ available with older versions of GDB." ...@@ -836,8 +840,27 @@ available with older versions of GDB."
pos (match-end 0))) pos (match-end 0)))
(and (= (mod count 2) 1) (and (= (mod count 2) 1)
(setq complete-list (list (concat str "'")))))) (setq complete-list (list (concat str "'"))))))
;; Let comint handle the rest. complete-list))
(comint-dynamic-simple-complete command-word complete-list)))
(defun gud-gdb-completion-at-point ()
"Return the data to complete the GDB command before point."
(let ((end (point))
(start
(save-excursion
(skip-chars-backward "^ " (comint-line-beginning-position))
(point))))
(list start end
(completion-table-dynamic
(apply-partially #'gud-gdb-completions
(buffer-substring (comint-line-beginning-position)
start))))))
;; (defun gud-gdb-complete-command ()
;; "Perform completion on the GDB command preceding point.
;; This is implemented using the GDB `complete' command which isn't
;; available with older versions of GDB."
;; (interactive)
;; (apply #'completion-in-region (gud-gdb-completion-at-point)))
;; The completion process filter is installed temporarily to slurp the ;; The completion process filter is installed temporarily to slurp the
;; output of GDB up to the next prompt and build the completion list. ;; output of GDB up to the next prompt and build the completion list.
...@@ -3061,6 +3084,7 @@ class of the file (using s to separate nested class ids)." ...@@ -3061,6 +3084,7 @@ class of the file (using s to separate nested class ids)."
;; syntactic information chain and collect any 'inclass ;; syntactic information chain and collect any 'inclass
;; symbols until 'topmost-intro is reached to find out if ;; symbols until 'topmost-intro is reached to find out if
;; point is within a nested class ;; point is within a nested class
;; FIXME: Yuck!!! cc-mode should provide a function instead.
(if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode")) (if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode"))
(with-current-buffer fbuffer (with-current-buffer fbuffer
(let ((nclass) (syntax)) (let ((nclass) (syntax))
...@@ -3457,14 +3481,14 @@ This function must return nil if it doesn't handle EVENT." ...@@ -3457,14 +3481,14 @@ This function must return nil if it doesn't handle EVENT."
so they have been disabled.")) so they have been disabled."))
(unless (null cmd) ; CMD can be nil if unknown debugger (unless (null cmd) ; CMD can be nil if unknown debugger
(if (eq gud-minor-mode 'gdbmi) (if (eq gud-minor-mode 'gdbmi)
(if gdb-macro-info (if gdb-macro-info
(gdb-input (gdb-input
(list (concat (list (concat
"server macro expand " expr "\n") "server macro expand " expr "\n")
`(lambda () (gdb-tooltip-print-1 ,expr)))) `(lambda () (gdb-tooltip-print-1 ,expr))))
(gdb-input (gdb-input
(list (concat cmd "\n") (list (concat cmd "\n")
`(lambda () (gdb-tooltip-print ,expr))))) `(lambda () (gdb-tooltip-print ,expr)))))
(setq gud-tooltip-original-filter (process-filter process)) (setq gud-tooltip-original-filter (process-filter process))
(set-process-filter process 'gud-tooltip-process-output) (set-process-filter process 'gud-tooltip-process-output)
(gud-basic-call cmd)) (gud-basic-call cmd))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment