1 ;;; Copyright (C) 2013-2014 Rocky Bernstein <rocky@gnu.org>
2 (eval-when-compile (require 'cl))
4 (require 'load-relative)
5 (require-relative-list '("../../common/track" "../../common/lang"
6 "../../common/core") "realgud-")
7 (require-relative-list '("init") "realgud:gub-")
9 (declare-function realgud-query-cmdline 'realgud-core)
10 (declare-function realgud-suggest-invocation 'realgud-core)
11 (declare-function realgud-lang-mode? 'realgud-lang)
13 ;; FIXME: I think the following could be generalized and moved to
14 ;; realgud-... probably via a macro.
15 (defvar realgud:gub-minibuffer-history nil
16 "minibuffer history list for the command `gub'.")
18 (easy-mmode-defmap gub-minibuffer-local-map
19 '(("\C-i" . comint-dynamic-complete-filename))
20 "Keymap for minibuffer prompting of gud startup command."
21 :inherit minibuffer-local-map)
23 ;; FIXME: I think this code and the keymaps and history
24 ;; variable chould be generalized, perhaps via a macro.
25 (defun gub-query-cmdline (&optional opt-debugger)
26 (realgud-query-cmdline
27 'gub-suggest-invocation
28 gub-minibuffer-local-map
29 'realgud:gub-minibuffer-history
32 (defun gub-parse-cmd-args (orig-args)
33 "Parse command line ARGS for the name of script to debug and its args.
35 ARGS should contain a tokenized list of the command line to run.
37 We return the a list containing
39 - the command processor (e.g. gub.sh) and it's arguments if any - a list of strings
40 For example for the following input
41 \'./gub.sh --gub=\"-I\" -- ./gcd.go a b\'
44 (gub (\"-gub=-I\") (./gcd.rb a b))
46 NOTE: the above should have each item listed in quotes.
51 (interp-regexp ".*\\(^gub\.sh\\|tortoise\\)$")
56 (go-prog-and-args '())
61 (list gub-name gub-args go-prog-and-args)
64 (when (string-match interp-regexp
65 (file-name-nondirectory (car args)))
66 (setq gub-name (pop args))
71 (let ((arg (pop args)))
73 ((string-match "^-[-]?gub=" arg)
74 (setq gub-args (nconc gub-args (list arg))))
76 ((string-match "^-run" arg)
77 (setq gub-args (nconc gub-args (list arg))))
79 ((string-match "^-interp=SS" arg)
80 (setq gub-args (nconc gub-args (list arg))))
82 ((equal arg "--")) ;; Ignore
84 ;; Anything else add to gub-args
85 ('t (setq go-prog-and-args (nconc go-prog-and-args (list arg))))
87 (list gub-name gub-args go-prog-and-args)
90 (defconst realgud:gub-auto-suffix-regexp
95 (defun gub-suggest-file-priority(filename)
99 (if (realgud-lang-mode? filename "go")
101 (if (string-match realgud:gub-auto-suffix-regexp filename)
109 ;; To silence Warning: reference to free variable
110 (defvar realgud:gub-command-name)
112 (defun gub-suggest-invocation (debugger-name)
113 "Suggest a command invocation via `realgud-suggest-invocaton'"
114 (realgud-suggest-invocation realgud:gub-command-name
115 realgud:gub-minibuffer-history
118 ;; Convert a command line as would be typed normally to run a script
119 ;; into one that invokes an Emacs-enabled debugging session.
120 ;; "--debugger" in inserted as the first switch.
122 (defun realgud:gub-massage-args (command-line)
123 (let* ((new-args (list "--debugger"))
124 (args (split-string-and-unquote command-line))
128 (setq new-args (cons (car args) new-args))
129 (setq args (cdr args)))))
131 ;; Pass all switches and -e scripts through.
133 (string-match "^-" (car args))
134 (not (equal "-" (car args)))
135 (not (equal "--" (car args))))
139 (string-match "^-" (car args)))
140 (error "Can't use stdin as the script to debug"))
141 ;; This is the program name.
152 "Gub cleanup - remove debugger's internal buffers (frame,
155 ;; (gub-breakpoint-remove-all-icons)
156 (dolist (buffer (buffer-list))
157 (when (string-match "\\*gub-[a-z]+\\*" (buffer-name buffer))
158 (let ((w (get-buffer-window buffer)))
161 (kill-buffer buffer))))
163 ;; (defun gub-reset-keymaps()
164 ;; "This unbinds the special debugger keys of the source buffers."
166 ;; (setcdr (assq 'gub-debugger-support-minor-mode minor-mode-map-alist)
167 ;; gub-debugger-support-minor-mode-map-when-deactive))
170 (defun realgud:gub-customize ()
171 "Use `customize' to edit the settings of the `gub' debugger."
173 (customize-group 'realgud:gub))
175 (provide-me "realgud:gub-")