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.

225 lines
7.1 KiB

  1. ;; Copyright (C) 2010, 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. (require 'load-relative)
  12. (require-relative-list '("helper") "realgud-")
  13. (require-relative-list '("buffer/helper") "realgud-buffer-")
  14. (declare-function realgud:backtrace-init 'realgud-buffer-helper)
  15. (declare-function realgud:breakpoint-init 'realgud-buffer-helper)
  16. (declare-function realgud-get-backtrace-buf 'realgud-buffer-helper)
  17. (declare-function realgud-get-breakpoint-buf 'realgud-buffer-helper)
  18. (declare-function realgud-get-cmdbuf 'realgud-buffer-helper)
  19. (declare-function realgud-get-srcbuf 'realgud-buffer-helper)
  20. (declare-function buffer-killed? 'realgud-helper)
  21. (declare-function one-window-p(bool))
  22. (defun realgud-window-update-position (buffer marker)
  23. "Update BUFFER to position specified with MARKER.
  24. We assume MARKER points inside BUFFER"
  25. (with-current-buffer buffer
  26. (goto-char marker)
  27. (let ((window (get-buffer-window buffer)))
  28. (if window (set-window-point window marker))
  29. )))
  30. (defun realgud-window-src ( &optional opt-buffer )
  31. "Make sure the source buffer is displayed in a window
  32. We don't care if the command buffer is also displayed.
  33. See also `realgud-window-src-undisturb-cmd'"
  34. (let* ((buffer (or opt-buffer (current-buffer)))
  35. (src-buffer (realgud-get-srcbuf buffer))
  36. (src-window (get-buffer-window src-buffer 'visible))
  37. (window (selected-window)))
  38. (if src-buffer
  39. (unless (and src-window (not (window-minibuffer-p)))
  40. (set-window-buffer window src-buffer))
  41. )
  42. ))
  43. (defun realgud-window-src-undisturb-cmd ( &optional opt-buffer )
  44. "Make sure the source buffers is displayed in windows without
  45. disturbing the command window if it is also displayed. Returns
  46. the command window
  47. See also `realgud-window-src'."
  48. (interactive)
  49. (let* ((buffer (or opt-buffer (current-buffer)))
  50. (src-buffer (realgud-get-srcbuf buffer))
  51. (src-window (get-buffer-window src-buffer))
  52. (cmd-buffer (realgud-get-cmdbuf buffer))
  53. (cmd-window (get-buffer-window cmd-buffer))
  54. (window (selected-window))
  55. )
  56. (if src-buffer
  57. (unless src-window
  58. (setq src-window
  59. (if (eq window cmd-window)
  60. ;; FIXME: generalize what to do here.
  61. (if (one-window-p 't)
  62. (split-window)
  63. (next-window window 'no-minibuf))
  64. window))
  65. (set-window-buffer src-window src-buffer))
  66. )
  67. (select-window src-window)
  68. cmd-window)
  69. )
  70. (defun realgud-window-cmd-undisturb-src ( &optional opt-buffer switch?)
  71. "Make sure the command buffer is displayed in windows without
  72. disturbing the command window if it is also displayed. Returns
  73. the source window."
  74. (interactive)
  75. (let* ((buffer (or opt-buffer (current-buffer)))
  76. (src-buffer (realgud-get-srcbuf buffer))
  77. (src-window (get-buffer-window src-buffer))
  78. (cmd-buffer (realgud-get-cmdbuf buffer))
  79. (cmd-window (get-buffer-window cmd-buffer))
  80. (window (selected-window))
  81. )
  82. (when cmd-buffer
  83. (unless cmd-window
  84. (setq cmd-window
  85. (if (eq window src-window)
  86. ;; FIXME: generalize what to do here.
  87. (if (one-window-p 't)
  88. (split-window)
  89. (next-window window 'no-minibuf))
  90. window))
  91. (set-window-buffer cmd-window cmd-buffer)
  92. )
  93. (if switch?
  94. (and (select-window cmd-window)
  95. (switch-to-buffer cmd-buffer)))
  96. )
  97. (select-window cmd-window)
  98. src-window)
  99. )
  100. (defun realgud:window-bt-undisturb-src ( &optional opt-buffer switch?)
  101. "Make sure the backtrace buffer is displayed in windows without
  102. disturbing the source window if it is also displayed. Returns
  103. the source window
  104. See also `realgud-window-src'"
  105. (interactive)
  106. (let* ((buffer (or opt-buffer (current-buffer)))
  107. (src-buffer (realgud-get-srcbuf buffer))
  108. (src-window (get-buffer-window src-buffer))
  109. (cmd-buffer (realgud-get-cmdbuf buffer))
  110. (cmd-window (get-buffer-window cmd-buffer))
  111. (bt-buffer (realgud-get-backtrace-buf cmd-buffer))
  112. (bt-window (get-buffer-window bt-buffer))
  113. (window (selected-window))
  114. )
  115. (when cmd-buffer
  116. (unless bt-window
  117. (setq bt-window
  118. (if (eq window src-window)
  119. ;; FIXME: generalize what to do here.
  120. (if (one-window-p 't)
  121. (split-window)
  122. (next-window window 'no-minibuf))
  123. window))
  124. (set-window-buffer bt-window bt-buffer)
  125. )
  126. (if switch?
  127. (and (select-window bt-window)
  128. (switch-to-buffer bt-buffer)))
  129. )
  130. src-window)
  131. )
  132. (defun realgud:window-brkpt-undisturb-src ( &optional opt-buffer switch?)
  133. "Make sure the backtrace buffer is displayed in windows without
  134. disturbing the source window if it is also displayed. Returns
  135. the source window
  136. See also `realgud-window-src'"
  137. (interactive)
  138. (let* ((buffer (or opt-buffer (current-buffer)))
  139. (src-buffer (realgud-get-srcbuf buffer))
  140. (src-window (get-buffer-window src-buffer))
  141. (cmd-buffer (realgud-get-cmdbuf buffer))
  142. (cmd-window (get-buffer-window cmd-buffer))
  143. (brkpt-buffer (realgud-get-breakpoint-buf cmd-buffer))
  144. (brkpt-window (get-buffer-window brkpt-buffer))
  145. (window (selected-window))
  146. )
  147. (when cmd-buffer
  148. (unless brkpt-window
  149. (setq brkpt-window
  150. (if (eq window src-window)
  151. ;; FIXME: generalize what to do here.
  152. (if (one-window-p 't)
  153. (split-window)
  154. (next-window window 'no-minibuf))
  155. window))
  156. (set-window-buffer brkpt-window brkpt-buffer)
  157. )
  158. (if switch?
  159. (and (select-window brkpt-window)
  160. (switch-to-buffer brkpt-buffer)))
  161. )
  162. src-window)
  163. )
  164. (defun realgud:window-bt()
  165. "Refresh backtrace information and display that in a buffer"
  166. (interactive)
  167. (with-current-buffer-safe (realgud-get-cmdbuf)
  168. (realgud:backtrace-init)
  169. (realgud:window-bt-undisturb-src)
  170. )
  171. )
  172. (defun realgud:window-brkpt()
  173. "Refresh breakpoint information and display that in a buffer"
  174. (interactive)
  175. (with-current-buffer-safe (realgud-get-cmdbuf)
  176. (realgud:breakpoint-init)
  177. (realgud:window-brkpt-undisturb-src)
  178. )
  179. )
  180. ;; (defun realgud-window-src-and-cmd ( &optional opt-buffer )
  181. ;; "Make sure the source buffers is displayed in windows without
  182. ;; disturbing the command window if it is also displayed. Returns
  183. ;; the command window
  184. ;; See also `realgud-window-src-window'"
  185. ;; (interactive)
  186. ;; (let* ((buffer (or opt-buffer (current-buffer)))
  187. ;; (src-buffer (realgud-get-srcbuf buffer))
  188. ;; (src-window (get-buffer-window src-buffer))
  189. ;; (cmd-buffer (realgud-get-cmdbuf buffer))
  190. ;; (cmd-window (get-buffer-window cmd-buffer))
  191. ;; (window (selected-window))
  192. ;; )
  193. ;; (if src-buffer
  194. ;; (unless src-window
  195. ;; (setq src-window
  196. ;; (if (eq window cmd-window)
  197. ;; (if (one-window-p 't) (split-window) (next-window window))
  198. ;; window))
  199. ;; (set-window-buffer src-window src-buffer))
  200. ;; )
  201. ;; cmd-window)
  202. ;; )
  203. (provide-me "realgud-")