 This includes a 'Debugger' menu and special key bindings when the
 debugger is active."
   (rdebug-debugger-support-minor-mode 1))
+
+
+;; -- Minor mode for source buffers, makes buffer read-only and bind short keys
+
+(defvar rdebug-local-short-key-mode-map
+  (let ((map (make-sparse-keymap)))
+    (rdebug-populate-secondary-buffer-map-plain map)
+    map)
+  "Keymap used in `rdebug-local-short-key-mode'.")
+
+
+;; Implementation node: This is the mode that does all the work, it's
+;; local to the buffer that is affected.
+(define-minor-mode rdebug-local-short-key-mode
+  "Minor mode with short keys for source buffers for the `rdebug' debugger.
+The buffer is read-only when the minor mode is active.
+
+Please use the global `rdebug-short-key-mode' to automatically
+activate this mode when the `rdebug' debugger is used.
+
+\\{rdebug-local-short-key-mode-map}"
+  :group 'rdebug
+  :global nil
+  :init-value nil
+  :keymap rdebug-local-short-key-mode-map
+  (if rdebug-local-short-key-mode
+      (setq buffer-read-only t)
+    (setq buffer-read-only nil)))
+
+
+;; Implementation note: This is the user-level command. It only
+;; controls if `rdebug-local-short-key-mode' should be activated or
+;; not.
+(define-minor-mode rdebug-short-key-mode
+  "When enabled, short keys can be used in source buffers in `rdebug'."
+  :group 'rdebug
+  :global t
+  :init-value nil
+  (rdebug-short-key-mode-maybe-activate))
+
+
+(defun rdebug-short-key-mode-maybe-activate ()
+  (if rdebug-short-key-mode
+      (rdebug-local-short-key-mode-on)
+    (rdebug-local-short-key-mode-off)))
+
+
+(defun rdebug-local-short-key-mode-off ()
+  "Turn off `rdebug-local-short-key-mode' in all buffers."
+  (rdebug-debug-enter "rdebug-local-short-key-mode-off"
+    (save-current-buffer
+      (dolist (buf (buffer-list))
+        (set-buffer buf)
+        (if rdebug-local-short-key-mode
+            (rdebug-local-short-key-mode -1))))))
+
+
+(defun rdebug-local-short-key-mode-on ()
+  "Turn on `rdebug-local-short-key-mode' in the current debugger frame."
+  (rdebug-debug-enter "rdebug-local-short-key-mode-off"
+    (save-current-buffer
+      (if gud-comint-buffer
+          (set-buffer gud-comint-buffer))
+      (let ((frame (or gud-last-frame
+                       gud-last-last-frame)))
+        (if (and frame
+                 rdebug-short-key-mode)
+            (ignore-errors
+              ;; `gud-find-file' calls `error' if it doesn't find the file.
+              (let ((buffer (gud-find-file (car frame))))
+                (save-current-buffer
+                  (set-buffer buffer)
+                  (rdebug-local-short-key-mode 1)))))))))
 
 
 ;; -- The `rdebug' command and support functions.

    (rdebug-populate-secondary-buffer-map map)

    ;; --------------------
    ;; The "Watch window" submeny.
    (let ((submenu (make-sparse-keymap)))
      (define-key-after map [menu-bar debugger watch]
        (cons "Watch window" submenu)

      ;; an arbitrary window.
      (if gud-last-frame
          (rdebug-pick-source-window))

      (rdebug-local-short-key-mode-on)

      ;; Does the remaining text look like it might end with the
      ;; beginning of another marker?  If it does, then keep it in
