1 ;;; Copyright (C) 2010-2015 Rocky Bernstein <rocky@gnu.org>
2 (require 'load-relative)
3 (require-relative-list '("custom" "helper" "key" "lochist" "loc" "menu")
5 (require-relative-list '("buffer/command" "buffer/helper" "buffer/source")
9 (defvar realgud:tool-bar-map) ;; Fully defined in track-mode
13 (declare-function realgud-cmdbuf? 'realgud-buffer-command)
14 (declare-function realgud:debugger-name-transform 'realgud-helper)
15 (declare-function realgud-get-cmdbuf 'realgud-buffer-helper)
16 (declare-function realgud:loc-follow 'realgud-loc)
17 (declare-function realgud-loc-hist-item-at 'realgud-lochist)
18 (declare-function realgud-cmdbuf-loc-hist 'realgud-command)
19 (declare-function realgud-populate-debugger-menu 'realgud-menu)
20 (declare-function realgud-populate-common-keys 'realgud-key)
21 (declare-function realgud-populate-src-buffer-map-plain 'realgud-key)
22 (declare-function realgud-srcbuf-info-short-key?=, 'realgud-source)
23 (declare-function realgud-srcbuf-info-was-read-only?= 'realgud-source)
24 (declare-function realgud-srcbuf? 'realgud-buffer-source)
26 ;; (defvar realgud::tool-bar-map) ;; fully defined in track-mode.el
28 (defvar realgud:shortkey-mode-map
29 (let ((map (make-sparse-keymap)))
31 (realgud-populate-debugger-menu map)
32 (realgud-populate-common-keys map)
33 (realgud-populate-src-buffer-map-plain map)
34 (define-key map "1" 'realgud-goto-arrow1)
35 (define-key map "2" 'realgud-goto-arrow2)
36 (define-key map "3" 'realgud-goto-arrow3)
37 (define-key map "4" 'realgud:goto-loc-hist-4)
38 (define-key map "5" 'realgud:goto-loc-hist-5)
39 (define-key map "6" 'realgud:goto-loc-hist-6)
40 (define-key map "7" 'realgud:goto-loc-hist-7)
41 (define-key map "8" 'realgud:goto-loc-hist-8)
42 (define-key map "9" 'realgud:goto-loc-hist-9)
43 (define-key map "b" 'realgud:cmd-break)
44 (define-key map "c" 'realgud:cmd-continue)
45 (define-key map "e" 'realgud:cmd-eval-region)
46 (define-key map "U" 'realgud:cmd-until)
48 ;; FIXME: these can go to a common routine
49 (define-key map "<" 'realgud:cmd-newer-frame)
50 (define-key map ">" 'realgud:cmd-older-frame)
51 (define-key map "d" 'realgud:cmd-newer-frame)
52 (define-key map "u" 'realgud:cmd-older-frame)
53 (define-key map "l" 'realgud-recenter-arrow)
54 (define-key map "C" 'realgud-window-cmd-undisturb-src)
55 (define-key map "I" 'realgud:cmdbuf-info-describe)
56 (define-key map "S" 'realgud-window-src-undisturb-cmd)
58 (define-key map "R" 'realgud:cmd-restart)
59 (define-key map "!" 'realgud:cmd-shell)
60 (define-key map [insert] 'realgud-short-key-mode)
61 (define-key map [(control x)(control q)] 'realgud-short-key-mode)
63 "Keymap used in `realgud-short-key-mode'.")
65 ;; Implementation note: This is the mode that does all the work, it's
66 ;; local to the buffer that is affected.
67 (define-minor-mode realgud-short-key-mode
68 "Minor mode with short keys for source buffers for the `dbgr' debugger.
69 The buffer is read-only when the minor mode is active.
71 \\{realgud:shortkey-mode-map}"
76 :keymap realgud:shortkey-mode-map
77 ;; executed on activation/deactivation:
78 (realgud-short-key-mode-setup realgud-short-key-mode))
80 (defun realgud-get-short-key-mode-map (cmdbuf)
81 (when (realgud-cmdbuf? cmdbuf)
82 (with-current-buffer cmdbuf
83 (let* ((info realgud-cmdbuf-info)
85 (realgud:debugger-name-transform
86 (realgud-cmdbuf-info-debugger-name info)))
89 (replace-regexp-in-string
91 (concat debugger-name "-short-key-mode-map"))))
92 (keymap (eval keymap-symbol))
94 (cond ((keymapp keymap) keymap)
99 (defun realgud-short-key-mode-setup (mode-on?)
100 "Called when entering or leaving `realgud-short-key-mode'. Variable
101 MODE-ON? a boolean which specifies if we are going into or out of this mode."
102 (if (realgud-srcbuf?)
103 (let* ((cmdbuf (realgud-get-cmdbuf))
104 (shortkey-keymap (realgud-get-short-key-mode-map cmdbuf))
107 ;; If there's a shortkey keymap that is custom
108 ;; for this debugger mode, use it.
109 (when shortkey-keymap
112 (set (make-local-variable 'tool-bar-map) realgud:tool-bar-map)
113 (use-local-map shortkey-keymap))
115 (kill-local-variable 'realgud:tool-bar-map)
119 ;; Ensure action only is performed when the state actually is toggled.
120 ;; or when not read-only
121 (when (or (not buffer-read-only)
122 (not (eq (realgud-sget 'srcbuf-info 'short-key?) mode-on?)))
123 ;; Save the current state, so we can determine when the
124 ;; state is toggled in the future.
125 (when (not (eq (realgud-sget 'srcbuf-info 'short-key?) mode-on?))
126 (realgud-srcbuf-info-short-key?= mode-on?)
127 (setq realgud-short-key-mode mode-on?)
129 ;; mode is being turned on.
131 (realgud-srcbuf-info-was-read-only?= buffer-read-only)
133 ;; If there's a shortkey keymap that is custom
134 ;; for this debugger mode, use it.
135 (if shortkey-keymap (use-local-map shortkey-keymap))
137 (local-set-key [m-insert] 'realgud-short-key-mode)
138 (when realgud-srcbuf-lock (setq buffer-read-only t))
139 (run-mode-hooks 'realgud-short-key-mode-hook))
140 ;; mode is being turned off: restore read-only state.
141 (setq buffer-read-only
142 (realgud-sget 'srcbuf-info 'was-read-only?))))
143 ;; (with-current-buffer-safe cmdbuf
144 ;; (realgud-cmdbuf-info-src-shortkey?= mode-on?)
145 ;; (realgud-cmdbuf-info-in-srcbuf?= mode-on?)
149 (setq realgud-short-key-mode nil)
150 (error "buffer %s does not seem to be attached to a debugger"
153 (defun realgud-short-key-mode-off ()
154 "Turn off `realgud-short-key-mode' in all buffers."
157 (dolist (buf (buffer-list))
159 (when realgud-short-key-mode
160 (realgud-short-key-mode-setup 0)))))
162 (defun realgud-populate-src-buffer-map (map)
163 "Bind all common keys and menu used in the dbgr src buffers.
164 This includes the keys bound to `realgud-key-prefix' (typically C-x
166 (realgud-populate-src-buffer-map-plain map)
167 (realgud-populate-common-keys map)
168 (let ((prefix-map (make-sparse-keymap)))
169 (realgud-populate-debugger-menu map)
170 (realgud-populate-src-buffer-map-plain prefix-map)
171 (define-key map realgud-key-prefix prefix-map)))
173 (defun realgud:goto-loc-hist(num)
174 "Go to position nth from the newest position."
175 (let ((cmdbuf (realgud-get-cmdbuf)))
177 (let* ((loc-hist (realgud-cmdbuf-loc-hist cmdbuf))
178 (loc (realgud-loc-hist-item-at loc-hist (- num)))
179 (loc-marker (realgud-loc-marker loc)))
180 (realgud:loc-follow loc-marker))
182 (message "No command buffer associated with this buffer")
186 (defun realgud:goto-loc-hist-4 ()
187 "Go to position 4th from the newest position."
189 (realgud:goto-loc-hist 4))
191 (defun realgud:goto-loc-hist-5 ()
192 "Go to position 5th from the newest position."
194 (realgud:goto-loc-hist 5))
196 (defun realgud:goto-loc-hist-6 ()
198 (realgud:goto-loc-hist 6))
200 (defun realgud:goto-loc-hist-7 ()
201 "Go to position 7th from the newest position."
203 (realgud:goto-loc-hist 7))
205 (defun realgud:goto-loc-hist-8 ()
206 "Go to position 8th from the newest position."
208 (realgud:goto-loc-hist 8))
210 (defun realgud:goto-loc-hist-9 ()
211 "Go to position 9th from the newest position."
213 (realgud:goto-loc-hist 9))
215 (provide-me "realgud-")