Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 118 lines (98 sloc) 4.487 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
;;; rdebug-locring.el --- Ruby debugger location ring

;; Copyright (C) 2008, 2009 Rocky Bernstein (rocky@gnu.org)
;; Copyright (C) 2008 Anders Lindgren

;; $Id: rdebug-locring.el 917 2009-03-31 09:49:37Z rockyb $

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; This file manages a ring of (recently stopped) positions to allow
;; the programmer to move back and forth between them.

;;; Code:

(defvar rdebug-source-location-ring nil
  "Ring of the last `rdebug-source-location-ring-size' positions we've stopped aft.")

(defvar rdebug-source-location-ring-index -1
  "Position in `rdebug-source-location-ring' of where we are.")

(defun rdebug-locring-add (frame location-history-ring)
  "Add FRAME to LOCATION-HISTORY-RING if we are on the top frame and have a frame to add."
  ;; Switching frames shouldn't save a new ring
  ;; position. Also make sure no position is different.
  ;; Perhaps duplicates should be controlled by an option.
  (unless (and (not (ring-empty-p location-history-ring))
(equal (ring-ref location-history-ring
(ring-length location-history-ring)) frame))
    (ring-insert-at-beginning location-history-ring frame)))

(defun rdebug-locring-clear ()
  "Clear out all source locations in `Go to the source location of the first stopping point."
  (interactive)
  (setq rdebug-source-location-ring-index -1)
  (while (not (ring-empty-p rdebug-source-location-ring))
    (ring-remove rdebug-source-location-ring)))

(defun rdebug-locring-goto (ring-position)
  "Go the source position RING-POSITION in the stopping history."
  (interactive "NSource location ring position (0 is oldest): ")
  (with-current-buffer gud-comint-buffer
    (setq rdebug-source-location-ring-index ring-position)
    (let* ((frame (ring-ref rdebug-source-location-ring ring-position))
(file (car frame))
(line (cdr frame)))
      (when file
(rdebug-display-line file line)
(message (format "%d %s:%d" rdebug-source-location-ring-index
file line))))))
    
(defun rdebug-locring-newer ()
  "Cycle through source location stopping history to get the next newer (more recently visited) location."
  (interactive)
  (with-current-buffer gud-comint-buffer
    (if (equal (+ 1 rdebug-source-location-ring-index)
(ring-length rdebug-source-location-ring))
(progn
(message "At newest - Will set to wrap to oldest.")
(setq rdebug-source-location-ring-index -1))
      ;; else
      (rdebug-locring-goto
       (if (> rdebug-source-location-ring-index
(ring-length rdebug-source-location-ring))
0
;; else
(ring-plus1 rdebug-source-location-ring-index
(ring-length rdebug-source-location-ring)))))))

(defun rdebug-locring-newest ()
  "Go to the source location of the first stopping point."
  (interactive)
  (rdebug-locring-goto (- (ring-length rdebug-source-location-ring) 1)))
  
(defun rdebug-locring-older ()
  "Cycle through source location stopping history to get the next older (least recently visited) location."
  (interactive)
  (with-current-buffer gud-comint-buffer
    (if (equal rdebug-source-location-ring-index 0)
(progn
(message "At oldest - Will set to wrap to newest.")
(setq rdebug-source-location-ring-index
(+ 1 (ring-length rdebug-source-location-ring))))
      ;; else
      (rdebug-locring-goto
       (if (or (not rdebug-source-location-ring-index)
(< rdebug-source-location-ring-index 0))
0
;; else
(ring-minus1 rdebug-source-location-ring-index
(ring-length rdebug-source-location-ring)))))))

(defun rdebug-locring-oldest ()
  "Go to the oldest source position location."
  (interactive)
  (ring-ref rdebug-source-location-ring 0))

(provide 'rdebug-locring)

;;; Local variables:
;;; eval:(put 'rdebug-debug-enter 'lisp-indent-hook 1)
;;; End:

;;; rdebug-locring.el ends here
Something went wrong with that request. Please try again.