1 ;;; Copyright (C) 2010, 2012, 2014-2015 Rocky Bernstein <rocky@gnu.org>
2 ;;; Debugger location ring
5 ;; This file manages a ring of (recently stopped) positions to allow
6 ;; the programmer to move between them.
12 (require 'load-relative)
13 (require-relative-list '("loc") "realgud-")
15 (declare-function realgud:loc-describe 'realgud-loc)
17 (defcustom realgud-loc-hist-size 20 ; For testing. Should really be larger.
18 "Size of realgud's position history ring"
22 (defstruct realgud-loc-hist
23 "A list of source-code positions recently encountered"
25 (ring (make-ring realgud-loc-hist-size)))
27 (defun realgud:loc-hist-describe(loc-hist)
28 "Format LOC-HIST values inside buffer *Describe*"
29 (switch-to-buffer (get-buffer-create "*Describe*"))
31 (insert "** Source Positions Stopped At\n")
34 (format " - buffer size :: %d\n" realgud-loc-hist-size)
35 (format " - position :: %d\n"
36 (realgud-loc-hist-position loc-hist))))
37 (let ((locs (cddr (realgud-loc-hist-ring loc-hist)))
40 (while (and (< i (length locs)) (setq loc (elt locs i)) (realgud-loc? loc) )
41 (insert (format "*** %d\n" i))
42 (realgud:loc-describe loc)
48 (defun realgud-loc-hist-item-at(loc-hist position)
49 "Get the current item stored at POSITION of the ring
50 component in LOC-HIST"
51 (lexical-let ((ring (realgud-loc-hist-ring loc-hist)))
52 (if (ring-empty-p ring)
54 (ring-ref ring position))))
56 (defun realgud-loc-hist-item(loc-hist)
57 "Get the current item of LOC-HIST at the position previously set"
58 (realgud-loc-hist-item-at
60 (realgud-loc-hist-position loc-hist)))
62 (defun realgud-loc-hist-add(loc-hist loc)
63 "Add FRAME to LOC-HIST"
64 ;; Switching frames shouldn't save a new ring
65 ;; position. Also make sure no position is different.
66 ;; Perhaps duplicates should be controlled by an option.
67 (let* ((ring (realgud-loc-hist-ring loc-hist))
68 (old-loc (realgud-loc-hist-item loc-hist)))
71 (equal (realgud-loc-filename old-loc)
72 (realgud-loc-filename loc))
73 (equal (realgud-loc-line-number old-loc)
74 (realgud-loc-line-number loc))
75 (equal (realgud-loc-column-number old-loc)
76 (realgud-loc-column-number old-loc)))
77 (setf (realgud-loc-hist-position loc-hist) 0)
78 (ring-insert ring loc)
82 (defun realgud-loc-hist-clear(loc-hist)
83 "Clear out all source locations in LOC-HIST"
84 (lexical-let* ((ring (ring-ref (realgud-loc-hist-ring loc-hist)
85 (realgud-loc-hist-position loc-hist)))
87 (setf (realgud-loc-hist-position loc-hist) (- head 1))
88 (while (not (ring-empty-p ring))
91 (defun realgud-loc-hist-index(loc-hist)
92 "Return the ring-index value of LOC-HIST"
94 (ring (realgud-loc-hist-ring loc-hist))
97 (index (mod (+ ringlen head
98 (- (realgud-loc-hist-position loc-hist)))
100 (if (zerop index) ringlen index)
103 (defun realgud-loc-hist-set (loc-hist position)
104 "Set LOC-HIST to POSITION in the stopping history"
105 (setf (realgud-loc-hist-position loc-hist) position))
107 ;; FIXME: add numeric arg?
108 (defun realgud-loc-hist-newer (loc-hist)
109 "Set LOC-HIST position to an newer position."
111 (setf (realgud-loc-hist-position loc-hist)
112 (ring-minus1 (realgud-loc-hist-position loc-hist)
113 (ring-length (realgud-loc-hist-ring loc-hist)))))
115 (defun realgud-loc-hist-newest (loc-hist)
116 "Set LOC-HIST position to the newest position."
117 (setf (realgud-loc-hist-position loc-hist) -1))
119 ;; FIXME: add numeric arg?
120 (defun realgud-loc-hist-older (loc-hist)
121 "Set LOC-HIST position to an older position."
122 (setf (realgud-loc-hist-position loc-hist)
123 (ring-plus1 (realgud-loc-hist-position loc-hist)
124 (ring-length (realgud-loc-hist-ring loc-hist)))))
126 (defun realgud-loc-hist-oldest (loc-hist)
127 "Set LOC-HIST to the oldest stopping point."
128 (lexical-let* ((ring (realgud-loc-hist-ring loc-hist))
130 (setf (realgud-loc-hist-position loc-hist) head)))
132 (provide-me "realgud-")