aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/gud.el82
1 files changed, 53 insertions, 29 deletions
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 47cbdf19ed2..e81f4ca949b 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -767,7 +767,9 @@ directory and source-file directory for your debugger."
767 (gud-def gud-until "until %l" "\C-u" "Continue to current line.") 767 (gud-def gud-until "until %l" "\C-u" "Continue to current line.")
768 (gud-def gud-run "run" nil "Run the program.") 768 (gud-def gud-run "run" nil "Run the program.")
769 769
770 (local-set-key "\C-i" 'gud-gdb-complete-command) 770 (add-hook 'completion-at-point-functions #'gud-gdb-completion-at-point
771 nil 'local)
772 (local-set-key "\C-i" 'completion-at-point)
771 (setq comint-prompt-regexp "^(.*gdb[+]?) *") 773 (setq comint-prompt-regexp "^(.*gdb[+]?) *")
772 (setq paragraph-start comint-prompt-regexp) 774 (setq paragraph-start comint-prompt-regexp)
773 (setq gdb-first-prompt t) 775 (setq gdb-first-prompt t)
@@ -791,26 +793,28 @@ directory and source-file directory for your debugger."
791;; The completion list is constructed by the process filter. 793;; The completion list is constructed by the process filter.
792(defvar gud-gdb-fetched-lines) 794(defvar gud-gdb-fetched-lines)
793 795
794(defun gud-gdb-complete-command (&optional command a b) 796(defun gud-gdb-completions (context command)
795 "Perform completion on the GDB command preceding point. 797 "Completion table for GDB commands.
796This is implemented using the GDB `complete' command which isn't 798COMMAND is the prefix for which we seek completion.
797available with older versions of GDB." 799CONTEXT is the text before COMMAND on the line."
798 (interactive) 800 (let* ((start (- (point) (field-beginning)))
799 (if command 801 (complete-list
800 ;; Used by gud-watch in mini-buffer. 802 (gud-gdb-run-command-fetch-lines (concat "complete " context command)
801 (setq command (concat "p " command))
802 ;; Used in GUD buffer.
803 (let ((end (point)))
804 (setq command (buffer-substring (comint-line-beginning-position) end))))
805 (let* ((command-word
806 ;; Find the word break. This match will always succeed.
807 (and (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
808 (substring command (match-beginning 2))))
809 (complete-list
810 (gud-gdb-run-command-fetch-lines (concat "complete " command)
811 (current-buffer) 803 (current-buffer)
812 ;; From string-match above. 804 ;; From string-match above.
813 (match-beginning 2)))) 805 (length context))))
806 ;; `gud-gdb-run-command-fetch-lines' has some nasty side-effects on the
807 ;; buffer (via `gud-delete-prompt-marker'): it removes the prompt and then
808 ;; re-adds it later, thus messing up markers and overlays along the way.
809 ;; This is a problem for completion-in-region which uses an overlay to
810 ;; create a field.
811 ;; So we restore completion-in-region's field if needed.
812 ;; FIXME: change gud-gdb-run-command-fetch-lines so it doesn't modify the
813 ;; buffer at all.
814 (when (/= start (- (point) (field-beginning)))
815 (dolist (ol (overlays-at (1- (point))))
816 (when (eq (overlay-get ol 'field) 'completion)
817 (move-overlay ol (- (point) start) (overlay-end ol)))))
814 ;; Protect against old versions of GDB. 818 ;; Protect against old versions of GDB.
815 (and complete-list 819 (and complete-list
816 (string-match "^Undefined command: \"complete\"" (car complete-list)) 820 (string-match "^Undefined command: \"complete\"" (car complete-list))
@@ -836,8 +840,27 @@ available with older versions of GDB."
836 pos (match-end 0))) 840 pos (match-end 0)))
837 (and (= (mod count 2) 1) 841 (and (= (mod count 2) 1)
838 (setq complete-list (list (concat str "'")))))) 842 (setq complete-list (list (concat str "'"))))))
839 ;; Let comint handle the rest. 843 complete-list))
840 (comint-dynamic-simple-complete command-word complete-list))) 844
845(defun gud-gdb-completion-at-point ()
846 "Return the data to complete the GDB command before point."
847 (let ((end (point))
848 (start
849 (save-excursion
850 (skip-chars-backward "^ " (comint-line-beginning-position))
851 (point))))
852 (list start end
853 (completion-table-dynamic
854 (apply-partially #'gud-gdb-completions
855 (buffer-substring (comint-line-beginning-position)
856 start))))))
857
858;; (defun gud-gdb-complete-command ()
859;; "Perform completion on the GDB command preceding point.
860;; This is implemented using the GDB `complete' command which isn't
861;; available with older versions of GDB."
862;; (interactive)
863;; (apply #'completion-in-region (gud-gdb-completion-at-point)))
841 864
842;; The completion process filter is installed temporarily to slurp the 865;; The completion process filter is installed temporarily to slurp the
843;; output of GDB up to the next prompt and build the completion list. 866;; 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 ;; syntactic information chain and collect any 'inclass 3084 ;; syntactic information chain and collect any 'inclass
3062 ;; symbols until 'topmost-intro is reached to find out if 3085 ;; symbols until 'topmost-intro is reached to find out if
3063 ;; point is within a nested class 3086 ;; point is within a nested class
3087 ;; FIXME: Yuck!!! cc-mode should provide a function instead.
3064 (if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode")) 3088 (if (and fbuffer (equal (symbol-file 'java-mode) "cc-mode"))
3065 (with-current-buffer fbuffer 3089 (with-current-buffer fbuffer
3066 (let ((nclass) (syntax)) 3090 (let ((nclass) (syntax))
@@ -3457,14 +3481,14 @@ This function must return nil if it doesn't handle EVENT."
3457so they have been disabled.")) 3481so they have been disabled."))
3458 (unless (null cmd) ; CMD can be nil if unknown debugger 3482 (unless (null cmd) ; CMD can be nil if unknown debugger
3459 (if (eq gud-minor-mode 'gdbmi) 3483 (if (eq gud-minor-mode 'gdbmi)
3460 (if gdb-macro-info 3484 (if gdb-macro-info
3461 (gdb-input 3485 (gdb-input
3462 (list (concat 3486 (list (concat
3463 "server macro expand " expr "\n") 3487 "server macro expand " expr "\n")
3464 `(lambda () (gdb-tooltip-print-1 ,expr)))) 3488 `(lambda () (gdb-tooltip-print-1 ,expr))))
3465 (gdb-input 3489 (gdb-input
3466 (list (concat cmd "\n") 3490 (list (concat cmd "\n")
3467 `(lambda () (gdb-tooltip-print ,expr))))) 3491 `(lambda () (gdb-tooltip-print ,expr)))))
3468 (setq gud-tooltip-original-filter (process-filter process)) 3492 (setq gud-tooltip-original-filter (process-filter process))
3469 (set-process-filter process 'gud-tooltip-process-output) 3493 (set-process-filter process 'gud-tooltip-process-output)
3470 (gud-basic-call cmd)) 3494 (gud-basic-call cmd))