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.

577 lines
22 KiB

  1. ;; Copyright (C) 2015-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. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; process-command buffer things
  14. (require 'load-relative)
  15. (require 'json)
  16. (require-relative-list
  17. '("../fringe" "../loc" "../lochist" "../regexp") "realgud-")
  18. (require-relative-list '("info") "realgud-buffer-")
  19. (declare-function realgud-get-cmdbuf 'realgud-buffer-helper)
  20. (eval-when-compile
  21. (byte-compile-disable-warning 'cl-functions)
  22. ;; Somehow disabling cl-functions causes the erroneous message:
  23. ;; Warning: the function `reduce' might not be defined at runtime.
  24. ;; FIXME: isolate, fix and/or report back to Emacs developers a bug
  25. (byte-compile-disable-warning 'unresolved)
  26. (defvar realgud-cmdbuf-info)
  27. )
  28. (require 'cl-lib)
  29. (when (< emacs-major-version 26)
  30. (defun make-mutex(&rest name)
  31. ;; Stub for Emacs that doesn't have mutex
  32. ))
  33. (defface debugger-running
  34. '((((class color) (min-colors 16) (background light))
  35. (:foreground "Green4" :weight bold))
  36. (((class color) (min-colors 88) (background dark))
  37. (:foreground "Green1" :weight bold))
  38. (((class color) (min-colors 16) (background dark))
  39. (:foreground "Green" :weight bold))
  40. (((class color)) (:foreground "green" :weight bold))
  41. (t (:weight bold)))
  42. "Face used to highlight debugger run information."
  43. :group 'realgud
  44. :version "25.1")
  45. (defface debugger-not-running
  46. '((t :inherit font-lock-warning-face))
  47. "Face used when debugger or process is not running."
  48. :group 'realgud
  49. :version "25.1")
  50. (cl-defstruct realgud-cmdbuf-info
  51. "The debugger object/structure specific to a process buffer."
  52. debugger-name ;; Name of debugger
  53. base-variable-name ;; prefix used in variables pertinent to this
  54. ;; debugger sometimes it is the same as the debugger
  55. ;; and sometimes it is different
  56. cmd-args ;; Command-line invocation arguments
  57. frame-switch? ;; Should the selected window be the source buffer or
  58. ;; command buffer?
  59. in-srcbuf? ;; If true, selected window should be the source buffer.
  60. ;; Otherwise, the command buffer?
  61. last-input-end ;; point where input last ended. Set from
  62. ;; comint-last-input-end
  63. prior-prompt-regexp ;; regular expression prompt (e.g.
  64. ;; comint-prompt-regexp) *before* setting
  65. ;; loc-regexp
  66. no-record? ;; Should we update the location history?
  67. in-debugger? ;; True if we think we are in a debugger
  68. src-shortkey? ;; Are source buffers in realgud-short-key mode?
  69. regexp-hash ;; hash table of regular expressions appropriate for
  70. ;; this debugger. Eventually loc-regexp, file-group
  71. ;; and line-group below will removed and stored here.
  72. srcbuf-list ;; list of source buffers we have stopped at
  73. source-path ;; last source-code path we've seen
  74. bt-buf ;; backtrace buffer if it exists
  75. brkpt-buf ;; breakpoint buffer if it exists
  76. bp-list ;; list of breakpoints
  77. divert-output? ;; Output is part of a conversation between front-end
  78. ;; debugger.
  79. cmd-hash ;; Allows us to remap command names like
  80. ;; quit => quit!
  81. callback-loc-fn ;; If we need, as in the case of Java, to do
  82. ;; special handling to map output to a file
  83. ;; location, this is set to that special
  84. ;; function
  85. callback-eval-filter ;; If set, this function strip extraneous output
  86. ;; when evaluating an expression. For example,
  87. ;; some trepan debuggers expression values prefaced with:
  88. ;; $DB::D[0] =
  89. ;; FIXME: REMOVE THIS and use regexp-hash
  90. loc-regexp ;; Location regular expression string
  91. file-group
  92. line-group
  93. alt-file-group
  94. alt-line-group
  95. text-group
  96. ;; A list (or sequence) of regular expression strings of file names
  97. ;; that we should ignore.
  98. ;;
  99. ;; For example in Python debuggers it often starts out "<string>...", while
  100. ;; in Ruby and Perl it often starts out "(eval ...".
  101. ;;
  102. ;; However in this list could be individual files that one encounters in the
  103. ;; course of debugging. For example:
  104. ;; - in nodejs "internal/module.js" or more generally internal/.*\.js.
  105. ;; - in C ../sysdeps/x86_64/multiarch/strchr-avx2.S or or more generally .*/sysdeps/.*
  106. ;; and so on.
  107. ;;
  108. ;; A list of regular expression. When one in the list matches a source
  109. ;; location, we ignore that file. Of course, the regular expression could
  110. ;; be a specific file name. Various programming languages have names
  111. ;; that might not be real. For example, in Python or Ruby when you compile
  112. ;; a or evaluate string you provide a name in the call, and often times
  113. ;; this isn't the real name of a file. It is often something like "exec" or
  114. ;; "<string>", or "<eval>". Each of the debuggers has the opportunity to seed the
  115. ;; the ignore list.
  116. ignore-re-file-list
  117. ;; A property list which maps the name as seen in the location to a path that we
  118. ;; can do a "find-file" on
  119. filename-remap-alist
  120. ;; A mutex to ensure that two threads doing things in the same debug
  121. ;; session simultaneously
  122. mutex
  123. loc-hist ;; ring of locations seen in the course of execution
  124. ;; see realgud-lochist
  125. starting-directory ;; directory where initial debug command was issued.
  126. ;; this can be used to resolve relative file names
  127. )
  128. (make-variable-buffer-local 'realgud-cmdbuf-info)
  129. (make-variable-buffer-local 'realgud-last-output-start)
  130. (defalias 'realgud-cmdbuf-info? 'realgud-cmdbuf-info-p)
  131. ;; FIXME: figure out how to put in a loop.
  132. (realgud-struct-field-setter "realgud-cmdbuf-info" "bp-list")
  133. (realgud-struct-field-setter "realgud-cmdbuf-info" "bt-buf")
  134. (realgud-struct-field-setter "realgud-cmdbuf-info" "brkpt-buf")
  135. (realgud-struct-field-setter "realgud-cmdbuf-info" "cmd-args")
  136. (realgud-struct-field-setter "realgud-cmdbuf-info" "last-input-end")
  137. (realgud-struct-field-setter "realgud-cmdbuf-info" "divert-output?")
  138. (realgud-struct-field-setter "realgud-cmdbuf-info" "frame-switch?")
  139. (realgud-struct-field-setter "realgud-cmdbuf-info" "in-srcbuf?")
  140. (realgud-struct-field-setter "realgud-cmdbuf-info" "no-record?")
  141. (realgud-struct-field-setter "realgud-cmdbuf-info" "prior-prompt-regexp")
  142. (realgud-struct-field-setter "realgud-cmdbuf-info" "src-shortkey?")
  143. (realgud-struct-field-setter "realgud-cmdbuf-info" "source-path")
  144. (realgud-struct-field-setter "realgud-cmdbuf-info" "in-debugger?")
  145. (realgud-struct-field-setter "realgud-cmdbuf-info" "callback-loc-fn")
  146. (realgud-struct-field-setter "realgud-cmdbuf-info" "callback-eval-filter")
  147. (realgud-struct-field-setter "realgud-cmdbuf-info" "starting-directory")
  148. (realgud-struct-field-setter "realgud-cmdbuf-info" "ignore-re-file-list")
  149. ;; (realgud-struct-field-setter "realgud-cmdbuf-info" "filename-remap-alist")
  150. (defun realgud-cmdbuf-filename-remap-alist= (value &optional buffer)
  151. (setq buffer (realgud-get-cmdbuf buffer))
  152. (setf (realgud-cmdbuf-info-filename-remap-alist realgud-cmdbuf-info) value))
  153. (defun realgud:cmdbuf-follow-buffer(event)
  154. (interactive "e")
  155. (let* ((pos (posn-point (event-end event)))
  156. (buffer (get-text-property pos 'buffer)))
  157. (find-file-other-window (buffer-file-name buffer))))
  158. (defun realgud:cmdbuf-buffers-describe (info)
  159. (let* ((buffer-list (realgud-cmdbuf-info-srcbuf-list info))
  160. (debugger-name (realgud-cmdbuf-info-debugger-name info))
  161. (file-remap-name (intern (format "realgud:%s-file-remap" debugger-name)))
  162. (file-remap (and (boundp file-remap-name) (eval file-remap-name)))
  163. (filename)
  164. (remapped-filename)
  165. )
  166. (insert "* Source Buffers Seen (srcbuf-list)\n")
  167. (dolist (buffer buffer-list)
  168. (insert " - ")
  169. (put-text-property
  170. (insert-text-button
  171. (setq filename (buffer-name buffer))
  172. 'action 'realgud:cmdbuf-follow-buffer
  173. 'help-echo "mouse-2: visit this file")
  174. (point)
  175. 'buffer buffer)
  176. (when (setq remapped-filename (and file-remap (gethash filename file-remap)))
  177. (insert (format "\tremapped to: %s" remapped-filename)))
  178. (insert "\n")
  179. )))
  180. ;; FIXME: this is a cheat. We are inserting
  181. ;; and afterwards inserting ""
  182. (defun realgud:cmdbuf-bp-list-describe (info)
  183. (let ((bp-list (realgud-cmdbuf-info-bp-list info))
  184. ;; For reasons I don't understand bp-list has duplicates
  185. (bp-nums nil))
  186. (cond (bp-list
  187. (insert "* Breakpoint list (bp-list)\n")
  188. (dolist (loc bp-list "")
  189. (let ((bp-num (realgud-loc-num loc)))
  190. (when (and bp-num (not (cl-member bp-num bp-nums)))
  191. (insert (format "** Breakpoint %d\n" bp-num))
  192. (realgud:org-mode-append-loc loc)
  193. (setq bp-nums (cl-adjoin bp-num bp-nums))
  194. ))))
  195. ;; Since we are inserting, the below in fact
  196. ;; inserts nothing. The string return is
  197. ;; aspirational for when this is fixed
  198. (t "\n")
  199. )))
  200. (defun realgud:org-mode-encode (header object)
  201. "Return an org-mode representation of OBJECT as an org-mode string."
  202. (format "%s%s" header
  203. (cond ((not object) "nil\n")
  204. ((stringp object) (format "%s\n" object))
  205. ((keywordp object) (json-encode-string
  206. (substring (symbol-name object) 1)))
  207. ((symbolp object) (json-encode-string
  208. (symbol-name object)))
  209. ((numberp object) (json-encode-number object))
  210. ((arrayp object) (json-encode-array object))
  211. ((hash-table-p object) (realgud:org-mode-encode-htable object))
  212. ;; ((listp object) (realgud:org-mode-encodelist object))
  213. (t (signal 'error (list object))))))
  214. (defun realgud:org-mode-encode-htable (hash-table)
  215. "Return an org-mode representation of HASH-TABLE as a s."
  216. (format "%s"
  217. (json-join
  218. (sort (realgud:org-mode-encode-htable-1 hash-table)
  219. 'string<) "")))
  220. (defun realgud:org-mode-encode-htable-1 (hash-table)
  221. "Return an org-mode representation of HASH-TABLE as a s."
  222. (let (r)
  223. (maphash
  224. (lambda (k v)
  225. (push (format
  226. " - %s\t::\t%s" k (realgud:org-mode-encode v ""))
  227. r))
  228. hash-table)
  229. r))
  230. (defun realgud:cmdbuf-info-describe (&optional buffer)
  231. "Display realgud-cmdcbuf-info fields of BUFFER.
  232. BUFFER is either a debugger command or source buffer. If BUFFER is not given
  233. the current buffer is used as a starting point.
  234. Information is put in an internal buffer called *Describe Debugger Session*."
  235. (interactive "")
  236. (setq buffer (realgud-get-cmdbuf buffer))
  237. (if buffer
  238. (with-current-buffer buffer
  239. (let ((info realgud-cmdbuf-info)
  240. (cmdbuf-name (buffer-name)))
  241. (if info
  242. (progn
  243. (switch-to-buffer (get-buffer-create "*Describe Debugger Session*"))
  244. (setq buffer-read-only 'nil)
  245. (delete-region (point-min) (point-max))
  246. ;;(insert "#+OPTIONS: H:2 num:nil toc:t \\n:nil ::t |:t ^:nil -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc\n")
  247. (insert (format "#+TITLE: Debugger info for %s
  248. This is based on an org-mode buffer. Hit tab to expand/contract sections.
  249. \n"
  250. cmdbuf-name))
  251. (insert "* General Information (realgud-cmdbuf-info)\n")
  252. ;; (insert "* General Information (")
  253. ;; (insert-text-button
  254. ;; "realgud-cmdbuf-info"
  255. ;; ;; FIXME figure out how to set buffer to cmdbuf so we get cmdbuf value
  256. ;; 'action (lambda(button) (describe-variable 'realgud-cmdbuf-info))
  257. ;; 'help-echo "mouse-2: help-on-variable")
  258. ;; (insert ")\n")
  259. (mapc 'insert
  260. (list
  261. (format " - Debugger name ::\t%s\n"
  262. (realgud-cmdbuf-info-debugger-name info))
  263. (format " - Command-line args ::\t%s\n"
  264. (json-encode (realgud-cmdbuf-info-cmd-args info)))
  265. (format " - Starting directory ::\t%s\n"
  266. (realgud-cmdbuf-info-starting-directory info))
  267. (format " - Current source-code path ::\t[[%s]]\n"
  268. (realgud-cmdbuf-info-source-path info))
  269. (format " - Selected window should contain source? :: %s\n"
  270. (realgud-cmdbuf-info-in-srcbuf? info))
  271. (format " - Last input end ::\t%s\n"
  272. (realgud-cmdbuf-info-last-input-end info))
  273. (format " - Source should go into short-key mode? :: %s\n"
  274. (realgud-cmdbuf-info-src-shortkey? info))
  275. (format " - In debugger? ::\t%s\n"
  276. (realgud-cmdbuf-info-in-debugger? info))
  277. (format " - Ignore file regexps ::\t%s\n"
  278. (realgud-cmdbuf-info-ignore-re-file-list info))
  279. (format " - remapped file names ::\t%s\n"
  280. (realgud-cmdbuf-info-filename-remap-alist info))
  281. (realgud:org-mode-encode "\n** Remap table for debugger commands\n"
  282. (realgud-cmdbuf-info-cmd-hash info))
  283. ;; (realgud:org-mode-encode "\n** Backtrace buffer"
  284. ;; (realgud-cmdbuf-info-bt-buf info))
  285. ;; (format " - Backtrace buffer ::\t%s\n"
  286. ;; (realgud-cmdbuf-info-bt-buf info))
  287. ))
  288. (insert "\n")
  289. (realgud:cmdbuf-bp-list-describe info)
  290. (insert "\n")
  291. (realgud:cmdbuf-buffers-describe info)
  292. (insert "\n")
  293. (realgud:loc-hist-describe (realgud-cmdbuf-info-loc-hist info))
  294. (insert "
  295. #+STARTUP: overview
  296. #+STARTUP: content
  297. #+STARTUP: showall
  298. #+STARTUP: showeverything
  299. ")
  300. (goto-char (point-min))
  301. (realgud:info-mode)
  302. )
  303. (message "realgud-cmdbuf-info is nil")
  304. )
  305. ))
  306. (message "Buffer %s is not a debugger source or command buffer; nothing done."
  307. (or buffer (current-buffer)))
  308. )
  309. )
  310. (defun realgud-cmdbuf? (&optional buffer)
  311. "Return true if BUFFER is a debugger command buffer."
  312. (with-current-buffer-safe
  313. (or buffer (current-buffer))
  314. (realgud-cmdbuf-info-set?)))
  315. (defun realgud-cmdbuf-info-set? ()
  316. "Return true if realgud-cmdbuf-info is set."
  317. (and (boundp 'realgud-cmdbuf-info)
  318. realgud-cmdbuf-info
  319. (realgud-cmdbuf-info? realgud-cmdbuf-info)))
  320. (defun realgud-cmdbuf-toggle-in-debugger? (&optional buffer)
  321. "Toggle state of whether we think we are in the debugger or not"
  322. (interactive "")
  323. (setq buffer (realgud-get-cmdbuf buffer))
  324. (if buffer
  325. (with-current-buffer buffer
  326. (realgud-cmdbuf-info-in-debugger?=
  327. (not (realgud-sget 'cmdbuf-info 'in-debugger?)))
  328. (message "Command buffer is in debugger?: %s\n"
  329. (realgud-cmdbuf-info-in-debugger? realgud-cmdbuf-info))
  330. (realgud-cmdbuf-mode-line-update)
  331. )
  332. (message "Buffer %s is not a debugger buffer; nothing done."
  333. (or buffer (current-buffer)))
  334. )
  335. )
  336. (defun realgud-cmdbuf-stay-in-source-toggle (&optional buffer)
  337. "Toggle state of whether we should stay in source code or not"
  338. (interactive "")
  339. (setq buffer (realgud-get-cmdbuf buffer))
  340. (if buffer
  341. (with-current-buffer buffer
  342. (realgud-cmdbuf-info-in-srcbuf?=
  343. (not (realgud-sget 'cmdbuf-info 'in-srcbuf?)))
  344. (message "Selected window should contain source?: %s\n"
  345. (realgud-cmdbuf-info-in-srcbuf? realgud-cmdbuf-info))
  346. )
  347. (message "Buffer %s is not a debugger buffer; nothing done."
  348. (or buffer (current-buffer)))
  349. )
  350. )
  351. (defun realgud-cmdbuf-add-srcbuf(srcbuf &optional cmdbuf)
  352. "Add SRCBUF to srcbuf-list field of INFO unless it is already included."
  353. (setq cmdbuf (or cmdbuf (current-buffer)))
  354. (if (realgud-cmdbuf? cmdbuf)
  355. (with-current-buffer-safe cmdbuf
  356. (unless (memq srcbuf (realgud-cmdbuf-info-srcbuf-list realgud-cmdbuf-info))
  357. (setf (realgud-cmdbuf-info-srcbuf-list realgud-cmdbuf-info)
  358. (cons srcbuf (realgud-cmdbuf-info-srcbuf-list realgud-cmdbuf-info))))
  359. )
  360. )
  361. )
  362. (defun realgud-cmdbuf-set-shortkey(&optional cmdbuf unset)
  363. (interactive "")
  364. (setq cmdbuf (or cmdbuf (current-buffer)))
  365. (if (realgud-cmdbuf? cmdbuf)
  366. (with-current-buffer-safe cmdbuf
  367. (setf (realgud-cmdbuf-info-src-shortkey? realgud-cmdbuf-info) (not unset))
  368. (message "Set source to shortkey is now %s" (not unset))
  369. ))
  370. )
  371. (defun realgud-cmdbuf-command-string(cmd-buffer)
  372. "Get the command string invocation for this command buffer"
  373. (cond
  374. ((realgud-cmdbuf? cmd-buffer)
  375. (with-current-buffer cmd-buffer
  376. (let*
  377. ((cmd-args (realgud-sget 'cmdbuf-info 'cmd-args))
  378. (result (car cmd-args)))
  379. (and cmd-args
  380. (cl-reduce (lambda(result x)
  381. (setq result (concat result " " x)))
  382. cmd-args)))))
  383. (t nil)))
  384. ;; FIXME cmd-hash should not be optional. And while I am at it, remove
  385. ;; parameters loc-regexp, file-group, and line-group which can be found
  386. ;; inside pat-hash
  387. ;;
  388. ;; To do this however we need to fix up the caller
  389. ;; realgud:track-set-debugger by changing realgud-pat-hash to store a hash
  390. ;; rather than the loc, file, and line fields; those fields then get
  391. ;; removed.
  392. (defun realgud-cmdbuf-init
  393. (cmd-buf debugger-name regexp-hash &optional cmd-hash base-variable-name
  394. starting-directory)
  395. "Initialize CMD-BUF for a working with a debugger.
  396. DEBUGGER-NAME is the name of the debugger; REGEXP-HASH are debugger-specific
  397. values set in the debugger's init.el."
  398. (with-current-buffer-safe cmd-buf
  399. (let ((realgud-loc-pat (gethash "loc" regexp-hash))
  400. (font-lock-keywords)
  401. (font-lock-breakpoint-keywords)
  402. )
  403. (setq realgud-cmdbuf-info
  404. (make-realgud-cmdbuf-info
  405. :debugger-name debugger-name
  406. :base-variable-name (or base-variable-name debugger-name)
  407. :cmd-args nil
  408. :frame-switch? nil
  409. :in-srcbuf? nil
  410. :last-input-end (point-max)
  411. :prior-prompt-regexp nil
  412. :no-record? nil
  413. :in-debugger? nil
  414. :src-shortkey? t
  415. :regexp-hash regexp-hash
  416. :srcbuf-list nil
  417. :bt-buf nil
  418. :brkpt-buf nil
  419. :bp-list nil
  420. :divert-output? nil
  421. :cmd-hash cmd-hash
  422. :callback-loc-fn (gethash "loc-callback-fn" regexp-hash)
  423. :callback-eval-filter (gethash "callback-eval-filter"
  424. regexp-hash)
  425. :loc-regexp (realgud-sget 'loc-pat 'regexp)
  426. :file-group (realgud-sget 'loc-pat 'file-group)
  427. :line-group (realgud-sget 'loc-pat 'line-group)
  428. :alt-file-group (realgud-sget 'loc-pat 'alt-file-group)
  429. :alt-line-group (realgud-sget 'loc-pat 'alt-line-group)
  430. :text-group (realgud-sget 'loc-pat 'text-group)
  431. :ignore-re-file-list (gethash "ignore-re-file-list" regexp-hash)
  432. :filename-remap-alist nil
  433. :mutex (make-mutex (buffer-name))
  434. :loc-hist (make-realgud-loc-hist)
  435. :starting-directory starting-directory
  436. ))
  437. (setq font-lock-keywords (realgud-cmdbuf-pat "font-lock-keywords"))
  438. (if font-lock-keywords
  439. (set (make-local-variable 'font-lock-defaults)
  440. (list font-lock-keywords)))
  441. (setq font-lock-breakpoint-keywords (realgud-cmdbuf-pat "font-lock-breakpoint-keywords"))
  442. (if font-lock-breakpoint-keywords
  443. (set (make-local-variable 'font-lock-breakpoint-keywords)
  444. (list font-lock-breakpoint-keywords)))
  445. )
  446. (put 'realgud-cmdbuf-info 'variable-documentation
  447. "Debugger object for a process buffer."))
  448. )
  449. (defun realgud-cmdbuf-reset (cmd-buf)
  450. "nil out variable realgud-cmdbuf-info in CMD-BUF"
  451. (with-current-buffer-safe cmd-buf
  452. (setq realgud-cmdbuf-info nil)
  453. ))
  454. (defun realgud-cmdbuf-debugger-name (&optional cmd-buf)
  455. "Return the debugger name recorded in the debugger command-process buffer."
  456. (with-current-buffer-safe (or cmd-buf (current-buffer))
  457. (if (realgud-cmdbuf?)
  458. (realgud-sget 'cmdbuf-info 'debugger-name)
  459. nil))
  460. )
  461. (defun realgud-cmdbuf-mutex (&optional cmd-buf)
  462. "Return the mutex for the current command buffer"
  463. (with-current-buffer-safe (or cmd-buf (current-buffer))
  464. (if (realgud-cmdbuf?)
  465. (realgud-sget 'cmdbuf-info 'mutex)
  466. nil))
  467. )
  468. (defun realgud-cmdbuf-filename-remap-alist (&optional cmd-buf)
  469. "Return the file-remap alist the current command buffer"
  470. (with-current-buffer-safe (or cmd-buf (current-buffer))
  471. (if (realgud-cmdbuf?)
  472. (realgud-sget 'cmdbuf-info 'filename-remap-alist)
  473. nil))
  474. )
  475. (defun realgud-cmdbuf-pat(key)
  476. "Extract regexp stored under KEY in a realgud-cmdbuf via realgud-cmdbuf-info"
  477. (if (realgud-cmdbuf?)
  478. (let*
  479. ((debugger-name (realgud-cmdbuf-debugger-name))
  480. (regexp-hash (gethash debugger-name realgud-pat-hash))
  481. (loc-pat (gethash key regexp-hash)))
  482. loc-pat)
  483. nil))
  484. (defun realgud-cmdbuf-loc-hist(cmd-buf)
  485. "Return the history ring of locations that a debugger
  486. command-process buffer has stored."
  487. (with-current-buffer-safe cmd-buf
  488. (realgud-sget 'cmdbuf-info 'loc-hist))
  489. )
  490. (defun realgud-cmdbuf-ignore-re-file-list(cmd-buf)
  491. (with-current-buffer-safe cmd-buf
  492. (realgud-sget 'cmdbuf-info 'ignore-re-file-list))
  493. )
  494. (defun realgud-cmdbuf-src-marker(cmd-buf)
  495. "Return a marker to current source location stored in the history ring."
  496. (with-current-buffer cmd-buf
  497. (let* ((loc (realgud-loc-hist-item (realgud-cmdbuf-loc-hist cmd-buf))))
  498. (and loc (realgud-loc-marker loc)))))
  499. (defun realgud-cmdbuf-mode-line-update (&optional opt-cmdbuf)
  500. "Force update of command buffer to include process status"
  501. (let ((cmdbuf (realgud-get-cmdbuf opt-cmdbuf))
  502. (debug-status)
  503. (status)
  504. (cmd-process)
  505. )
  506. (if (and cmdbuf (buffer-name cmdbuf))
  507. (with-current-buffer cmdbuf
  508. (setq cmd-process (get-buffer-process cmdbuf))
  509. (setq debug-status
  510. (if (realgud-sget 'cmdbuf-info 'in-debugger?)
  511. " debugger"
  512. ""))
  513. (setq status
  514. (if cmd-process
  515. (list (propertize
  516. (format ":%s%s"
  517. (process-status cmd-process) debug-status)
  518. 'face 'realgud-debugger-running))
  519. (list (propertize ":not running" 'face
  520. 'realgud-debugger-not-running))
  521. ))
  522. (setq mode-line-process status)
  523. ;; Force mode line redisplay soon.
  524. (force-mode-line-update))
  525. ))
  526. )
  527. (provide-me "realgud-buffer-")