Skip to content
This repository
Newer
Older
100644 175 lines (142 sloc) 6.443 kb
0768eb09 » mark-moseley
2009-07-21 SVN RubyForge pull
1 ;;; rdebug-watch.el --- Ruby debugger (short and simple) key bindings
2 ;;; and minor mode.
3
4 ;; Copyright (C) 2008 Rocky Bernstein (rocky@gnu.org)
5 ;; Copyright (C) 2008 Anders Lindgren
6
7 ;; $Id: rdebug-shortkey.el 807 2008-04-08 19:55:37Z andersl $
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;; This file contains code which add short simple key bindings to buffers
27 ;; which are part of an part of an rdebug session. It also handles
28 ;; minor mode setting of these buffers.
29
30 ;;; Code:
31 ;; -------------------------------------------------------------------
32 ;; Source short key mode.
33 ;;
34 ;; When this minor mode is active and the debugger is running, the
35 ;; source window displaying the current debugger frame is marked as
36 ;; read-only and the short keys of the secondary windows can be used,
37 ;; for example, you can use the space-bar to single-step the program.
38
39 ;; Implementation note:
40 ;;
41 ;; This is presented to the user as one global minor mode. However,
42 ;; under the surface the real work is done by another, non-global,
43 ;; minor mode named "local short key mode". This is activated and
44 ;; deactivated appropriately by the Rdebug filter functions.
45
46 ;; Implementation note: This is the user-level command. It only
47 ;; controls if `rdebug-internal-short-key-mode' should be activated or
48 ;; not.
49
50 (require 'rdebug-source)
51
52 (define-minor-mode rdebug-short-key-mode
53 "When enabled, short keys can be used in source buffers in `rdebug'."
54 :group 'rdebug
55 :global t
56 :init-value nil
57 ;; Unless the debugger is running, activating this doesn't do
58 ;; anything.
59 (if (featurep 'rdebug-core)
60 (with-no-warnings
61 (rdebug-short-key-mode-maybe-activate))))
62
63 (defvar rdebug-internal-short-key-mode-map
64 (let ((map (make-sparse-keymap)))
65 (define-key map "b" 'gud-break)
66 (define-key map "t" 'rdebug-toggle-source-breakpoint-enabled)
67 (define-key map [insert] 'rdebug-short-key-mode)
68 ;;(define-key map "p" 'gud-print)
69 (rdebug-populate-secondary-buffer-map-plain map)
70 map)
71 "Keymap used in `rdebug-internal-short-key-mode'.")
72
73 (defvar rdebug-original-read-only nil
74 "The value `buffer-read-only' should be restored to after short key mode.")
75
76 ;; `define-minor-mode' does not set if the mode was on or off prior to being called.
77 (defvar rdebug-internal-short-key-mode-previous-state nil
78 "Used to determine when 'rdebug-internal-short-key-mode' changed state.")
79
80 ;; Implementation note: This is the mode that does all the work, it's
81 ;; local to the buffer that is affected.
82 (define-minor-mode rdebug-internal-short-key-mode
83 "Minor mode with short keys for source buffers for the `rdebug' debugger.
84 The buffer is read-only when the minor mode is active.
85
86 Note that this is for internal use only, please use the global
87 mode `rdebug-short-key-mode'.
88
89 \\{rdebug-internal-short-key-mode-map}"
90 :group 'rdebug
91 :global nil
92 :init-value nil
93 :lighter " ShortKeys"
94 :keymap rdebug-internal-short-key-mode-map
95 (make-local-variable 'rdebug-original-read-only)
96 (make-local-variable 'rdebug-internal-short-key-mode-previous-state)
97 ;; Ensure action only is performed when the state actually is toggled.
98 (unless (eq rdebug-internal-short-key-mode-previous-state
99 rdebug-internal-short-key-mode)
100 (if rdebug-internal-short-key-mode
101 ;; Mode is being turned on.
102 (progn
103 (setq rdebug-original-read-only buffer-read-only)
104 (setq buffer-read-only t))
105 ;; Mode is being turned off.
106 (setq buffer-read-only rdebug-original-read-only))
107 ;; Save the current state, so we can determine when the state is
108 ;; toggled in the future.
109 (setq rdebug-internal-short-key-mode-previous-state
110 rdebug-internal-short-key-mode)))
111
112 (defun rdebug-buffer-killed-p (buffer)
113 "Return t if BUFFER is killed."
114 (not (buffer-name buffer)))
115
116 (defun rdebug-internal-short-key-mode-on ()
117 "Turn on `rdebug-internal-short-key-mode' in the current debugger frame."
118 (rdebug-debug-enter "rdebug-internal-short-key-mode-on"
119 (save-current-buffer
120 (if (and gud-comint-buffer
121 (not (rdebug-buffer-killed-p gud-comint-buffer)))
122 (set-buffer gud-comint-buffer))
123 (let ((frame (or gud-last-frame
124 gud-last-last-frame)))
125 (if (and frame
126 rdebug-short-key-mode)
127 (ignore-errors
128 ;; `gud-find-file' calls `error' if it doesn't find the file.
129 (let ((buffer (gud-find-file (car frame))))
130 (save-current-buffer
131 (set-buffer buffer)
132 ;; Make gud-comint-buffer local
133 (if gud-comint-buffer
134 (make-local-variable 'gud-comint-buffer))
135 (rdebug-internal-short-key-mode 1)))))))))
136
137
138 (defun rdebug-turn-on-short-key-mode ()
139 "Turn on `rdebug-short-key-mode'.
140
141 This function is designed to be used in a user hook, for example:
142
143 (add-hook 'rdebug-mode-hook 'rdebug-turn-on-short-key-mode)"
144 (interactive)
145 (rdebug-short-key-mode 1))
146
147
148 (defun rdebug-turn-off-short-key-mode ()
149 "Turn off `rdebug-short-key-mode'."
150 (interactive)
151 (rdebug-short-key-mode -1))
152
153
154 (defun rdebug-short-key-mode-maybe-activate ()
155 (if rdebug-short-key-mode
156 (rdebug-internal-short-key-mode-on)
157 (rdebug-internal-short-key-mode-off)))
158
159
160 (defun rdebug-internal-short-key-mode-off ()
161 "Turn off `rdebug-internal-short-key-mode' in all buffers."
162 (rdebug-debug-enter "rdebug-internal-short-key-mode-off"
163 (save-current-buffer
164 (dolist (buf (buffer-list))
165 (set-buffer buf)
166 (when rdebug-internal-short-key-mode
167 (rdebug-internal-short-key-mode -1))))))
168
169 (provide 'rdebug-shortkey)
170
171 ;;; Local variables:
172 ;;; eval:(put 'rdebug-debug-enter 'lisp-indent-hook 1)
173 ;;; End:
174
175 ;;; rdebug-shortkey.el ends here
Something went wrong with that request. Please try again.