Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.7 KiB

  1. ;; Copyright (C) 2010, 2012, 2014-2016, 2019 Free Software Foundation, Inc
  2. ;; Author: Rocky Bernstein <rocky@gnu.org>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;;; Debugger location ring
  12. ;;; Commentary:
  13. ;; This file manages a ring of (recently stopped) positions to allow
  14. ;; the programmer to move between them.
  15. ;;; Code:
  16. (eval-when-compile (require 'cl-lib))
  17. (require 'ring)
  18. (require 'org)
  19. (require 'load-relative)
  20. (require-relative-list '("loc") "realgud-")
  21. (declare-function realgud:loc-describe 'realgud-loc)
  22. (defcustom realgud-loc-hist-size 20 ; For testing. Should really be larger.
  23. "Size of realgud's position history ring"
  24. :type 'integer
  25. :group 'realgud)
  26. (cl-defstruct realgud-loc-hist
  27. "A list of source-code positions recently encountered"
  28. (position -1)
  29. (ring (make-ring realgud-loc-hist-size)))
  30. (defun realgud:loc-hist-describe(loc-hist)
  31. "Format LOC-HIST values inside buffer *Describe Debugger Session*"
  32. (switch-to-buffer (get-buffer-create "*Describe Debugger Session*"))
  33. (org-mode)
  34. (insert "** Source Positions Stopped at (loc-hist)\n")
  35. (mapc 'insert
  36. (list
  37. (format " - buffer size :: %d\n" realgud-loc-hist-size)
  38. (format " - position :: %d\n"
  39. (realgud-loc-hist-position loc-hist))))
  40. (let ((locs (cddr (realgud-loc-hist-ring loc-hist)))
  41. (loc)
  42. (i 0))
  43. (while (and (< i (length locs)) (setq loc (elt locs i)) (realgud-loc? loc) )
  44. (insert (format "*** %d\n" i))
  45. (realgud:loc-describe loc)
  46. (setq i (1+ i))
  47. )
  48. )
  49. )
  50. (defun realgud-loc-hist-item-at(loc-hist position)
  51. "Get the current item stored at POSITION of the ring
  52. component in LOC-HIST"
  53. (let ((ring (realgud-loc-hist-ring loc-hist)))
  54. (unless (ring-empty-p ring)
  55. (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
  59. loc-hist
  60. (realgud-loc-hist-position loc-hist)))
  61. (defun realgud-loc-hist-add(loc-hist loc)
  62. "Add FRAME to LOC-HIST"
  63. ;; Switching frames shouldn't save a new ring
  64. ;; position. Also make sure no position is different.
  65. ;; Perhaps duplicates should be controlled by an option.
  66. (let* ((ring (realgud-loc-hist-ring loc-hist))
  67. (old-loc (realgud-loc-hist-item loc-hist)))
  68. (unless (and
  69. old-loc
  70. (equal (realgud-loc-filename old-loc)
  71. (realgud-loc-filename loc))
  72. (equal (realgud-loc-line-number old-loc)
  73. (realgud-loc-line-number loc))
  74. (equal (realgud-loc-column-number old-loc)
  75. (realgud-loc-column-number old-loc)))
  76. (setf (realgud-loc-hist-position loc-hist) 0)
  77. (ring-insert ring loc)
  78. )
  79. ))
  80. (defun realgud-loc-hist-clear(loc-hist)
  81. "Clear out all source locations in LOC-HIST"
  82. (let* ((ring (ring-ref (realgud-loc-hist-ring loc-hist)
  83. (realgud-loc-hist-position loc-hist)))
  84. (head (car ring)))
  85. (setf (realgud-loc-hist-position loc-hist) (- head 1))
  86. (while (not (ring-empty-p ring))
  87. (ring-remove ring))))
  88. (defun realgud-loc-hist-index(loc-hist)
  89. "Return the ring-index value of LOC-HIST"
  90. (let* (
  91. (ring (realgud-loc-hist-ring loc-hist))
  92. (head (car ring))
  93. (ringlen (cadr ring))
  94. (index (mod (+ ringlen head
  95. (- (realgud-loc-hist-position loc-hist)))
  96. ringlen)))
  97. (if (zerop index) ringlen index)
  98. ))
  99. (defun realgud-loc-hist-set (loc-hist position)
  100. "Set LOC-HIST to POSITION in the stopping history"
  101. (setf (realgud-loc-hist-position loc-hist) position))
  102. ;; FIXME: add numeric arg?
  103. (defun realgud-loc-hist-newer (loc-hist)
  104. "Set LOC-HIST position to an newer position."
  105. (setf (realgud-loc-hist-position loc-hist)
  106. (ring-minus1 (realgud-loc-hist-position loc-hist)
  107. (ring-length (realgud-loc-hist-ring loc-hist)))))
  108. (defun realgud-loc-hist-newest (loc-hist)
  109. "Set LOC-HIST position to the newest position."
  110. (setf (realgud-loc-hist-position loc-hist) -1))
  111. ;; FIXME: add numeric arg?
  112. (defun realgud-loc-hist-older (loc-hist)
  113. "Set LOC-HIST position to an older position."
  114. (setf (realgud-loc-hist-position loc-hist)
  115. (ring-plus1 (realgud-loc-hist-position loc-hist)
  116. (ring-length (realgud-loc-hist-ring loc-hist)))))
  117. (defun realgud-loc-hist-oldest (loc-hist)
  118. "Set LOC-HIST to the oldest stopping point."
  119. (let* ((ring (realgud-loc-hist-ring loc-hist))
  120. (head (car ring)))
  121. (setf (realgud-loc-hist-position loc-hist) head)))
  122. (provide-me "realgud-")