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.

227 lines
8.8 KiB

  1. ;; Copyright (C) 2010-2015, 2017 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. (require 'load-relative)
  14. (require-relative-list '("cmds" "custom" "eval" "helper" "key" "lochist" "loc"
  15. "menu")
  16. "realgud-")
  17. (require-relative-list '("buffer/command" "buffer/helper" "buffer/source")
  18. "realgud-buffer-")
  19. (eval-when-compile
  20. (defvar realgud:tool-bar-map) ;; Fully defined in track-mode
  21. )
  22. (declare-function realgud-cmds--mouse-add-remove-bp 'realgud-cmds)
  23. (declare-function realgud-cmdbuf? 'realgud-buffer-command)
  24. (declare-function realgud:debugger-name-transform 'realgud-helper)
  25. (declare-function realgud-get-cmdbuf 'realgud-buffer-helper)
  26. (declare-function realgud:follow-mark 'realgud-follow)
  27. (declare-function realgud-loc-hist-item-at 'realgud-lochist)
  28. (declare-function realgud-cmdbuf-loc-hist 'realgud-command)
  29. (declare-function realgud-populate-debugger-menu 'realgud-menu)
  30. (declare-function realgud-populate-common-keys 'realgud-key)
  31. (declare-function realgud-populate-src-buffer-map-plain 'realgud-key)
  32. (declare-function realgud-srcbuf-info-short-key?=, 'realgud-source)
  33. (declare-function realgud-srcbuf-info-was-read-only?= 'realgud-source)
  34. (declare-function realgud-srcbuf-info-prev-local-map= 'realgud-source)
  35. (declare-function realgud-srcbuf? 'realgud-buffer-source)
  36. (declare-function realgud--ensure-attached 'realgud-buffer-source)
  37. (declare-function realgud-srcbuf-info-set? 'realgud-buffer-source)
  38. ;; (defvar realgud::tool-bar-map) ;; fully defined in track-mode.el
  39. (defvar realgud:shortkey-mode-map
  40. (let ((map (make-sparse-keymap)))
  41. (suppress-keymap map)
  42. (realgud-populate-debugger-menu map)
  43. (realgud-populate-common-keys map)
  44. (realgud-populate-src-buffer-map-plain map)
  45. (define-key map "1" 'realgud-goto-arrow1)
  46. (define-key map "2" 'realgud-goto-arrow2)
  47. (define-key map "3" 'realgud-goto-arrow3)
  48. (define-key map "4" 'realgud:goto-loc-hist-4)
  49. (define-key map "5" 'realgud:goto-loc-hist-5)
  50. (define-key map "6" 'realgud:goto-loc-hist-6)
  51. (define-key map "7" 'realgud:goto-loc-hist-7)
  52. (define-key map "8" 'realgud:goto-loc-hist-8)
  53. (define-key map "9" 'realgud:goto-loc-hist-9)
  54. (define-key map "b" 'realgud:cmd-break)
  55. (define-key map "j" 'realgud:cmd-jump)
  56. (define-key map "c" 'realgud:cmd-continue)
  57. (define-key map "e" 'realgud:cmd-eval-dwim)
  58. (define-key map "E" 'realgud:cmd-eval-at-point)
  59. (define-key map "U" 'realgud:cmd-until)
  60. (define-key map "h" 'realgud:cmd-until-here)
  61. (define-key map [mouse-2] 'realgud:tooltip-eval)
  62. (define-key map [left-fringe mouse-1] #'realgud-cmds--mouse-add-remove-bp)
  63. (define-key map [left-margin mouse-1] #'realgud-cmds--mouse-add-remove-bp)
  64. ;; FIXME: these can go to a common routine
  65. (define-key map "<" 'realgud:cmd-newer-frame)
  66. (define-key map ">" 'realgud:cmd-older-frame)
  67. (define-key map "d" 'realgud:cmd-newer-frame)
  68. (define-key map "u" 'realgud:cmd-older-frame)
  69. (define-key map "l" 'realgud-recenter-arrow)
  70. (define-key map "C" 'realgud-window-cmd-undisturb-src)
  71. (define-key map "I" 'realgud:cmdbuf-info-describe)
  72. (define-key map "S" 'realgud-window-src-undisturb-cmd)
  73. (define-key map "R" 'realgud:cmd-restart)
  74. (define-key map "!" 'realgud:cmd-shell)
  75. (define-key map [insert] 'realgud-short-key-mode)
  76. (define-key map [(control x)(control q)] 'realgud-short-key-mode)
  77. map)
  78. "Keymap used in `realgud-short-key-mode'.")
  79. ;; Implementation note: This is the mode that does all the work, it's
  80. ;; local to the buffer that is affected.
  81. (define-minor-mode realgud-short-key-mode
  82. "Minor mode with short keys for source buffers for the `realgud' debugger.
  83. If `realgud-srcbuf-lock' is set, the buffer is read-only when the
  84. minor mode is active.
  85. \\{realgud:shortkey-mode-map}"
  86. :group 'realgud
  87. :global nil
  88. :init-value nil
  89. :lighter " ShortKeys"
  90. :keymap realgud:shortkey-mode-map
  91. ;; executed on activation/deactivation:
  92. (realgud-short-key-mode-setup realgud-short-key-mode))
  93. (defun realgud-get-short-key-mode-map (cmdbuf)
  94. (when (realgud-cmdbuf? cmdbuf)
  95. (with-current-buffer cmdbuf
  96. (let* ((info realgud-cmdbuf-info)
  97. (debugger-name (realgud-cmdbuf-info-debugger-name info))
  98. (base-variable-name
  99. (or (gethash debugger-name realgud:variable-basename-hash)
  100. debugger-name))
  101. (keymap-symbol
  102. (intern
  103. (replace-regexp-in-string
  104. "\\." ""
  105. (concat base-variable-name "-short-key-mode-map"))))
  106. (keymap (eval keymap-symbol))
  107. )
  108. (cond ((keymapp keymap) keymap)
  109. ('t nil))
  110. ))
  111. ))
  112. (defun realgud-short-key-mode-setup (mode-on?)
  113. "Set up or tear down `realgud-short-key-mode'.
  114. MODE-ON? is a boolean indicating whether the mode should be
  115. turned on or off."
  116. (setq realgud-short-key-mode mode-on?)
  117. ;; When enabling, try to find a command buffer to attach to.
  118. (when (and realgud-short-key-mode (not (realgud--ensure-attached)))
  119. (setq realgud-short-key-mode nil))
  120. ;; Now apply mode change
  121. (cond
  122. ;; Mode was just enabled
  123. (realgud-short-key-mode
  124. ;; Record info to restore it when disabling
  125. (unless (equal (realgud-sget 'srcbuf-info 'short-key?) realgud-short-key-mode)
  126. (realgud-srcbuf-info-prev-local-map= (current-local-map))
  127. (realgud-srcbuf-info-was-read-only?= buffer-read-only))
  128. ;; Apply local map
  129. (let ((keymap (realgud-get-short-key-mode-map (realgud-get-cmdbuf))))
  130. (when keymap (use-local-map keymap)))
  131. ;; Finish setting up
  132. (set (make-local-variable 'tool-bar-map) realgud:tool-bar-map)
  133. (local-set-key [m-insert] #'realgud-short-key-mode)
  134. (setq buffer-read-only realgud-srcbuf-lock)
  135. (run-mode-hooks 'realgud-short-key-mode-hook))
  136. ;; Mode was just disabled
  137. (t
  138. (kill-local-variable 'tool-bar-map)
  139. (when (realgud-srcbuf-info-set?)
  140. ;; Restore previous state
  141. (use-local-map (realgud-sget 'srcbuf-info 'prev-local-map))
  142. (setq buffer-read-only (realgud-sget 'srcbuf-info 'was-read-only?)))))
  143. ;; Record state
  144. (when (realgud-srcbuf-info-set?)
  145. (realgud-srcbuf-info-short-key?= realgud-short-key-mode)))
  146. (defun realgud-short-key-mode-off ()
  147. "Turn off `realgud-short-key-mode' in all buffers."
  148. (interactive)
  149. (save-excursion
  150. (dolist (buf (buffer-list))
  151. (set-buffer buf)
  152. (when realgud-short-key-mode
  153. (realgud-short-key-mode -1)))))
  154. (defun realgud-populate-src-buffer-map (map)
  155. "Bind all common keys and menu used in src buffers.
  156. This includes the keys bound to `realgud-key-prefix' (typically C-x
  157. C-a)."
  158. (realgud-populate-src-buffer-map-plain map)
  159. (realgud-populate-common-keys map)
  160. (let ((prefix-map (make-sparse-keymap)))
  161. (realgud-populate-debugger-menu map)
  162. (realgud-populate-src-buffer-map-plain prefix-map)
  163. (define-key map realgud-key-prefix prefix-map)))
  164. (defun realgud:goto-loc-hist(num)
  165. "Go to position nth from the newest position."
  166. (let ((cmdbuf (realgud-get-cmdbuf)))
  167. (if cmdbuf
  168. (let* ((loc-hist (realgud-cmdbuf-loc-hist cmdbuf))
  169. (loc (realgud-loc-hist-item-at loc-hist (- num)))
  170. (loc-marker (realgud-loc-marker loc)))
  171. (realgud:follow-mark loc-marker))
  172. ;; else
  173. (message "No command buffer associated with this buffer")
  174. )))
  175. (defun realgud:goto-loc-hist-4 ()
  176. "Go to position 4th from the newest position."
  177. (interactive)
  178. (realgud:goto-loc-hist 4))
  179. (defun realgud:goto-loc-hist-5 ()
  180. "Go to position 5th from the newest position."
  181. (interactive)
  182. (realgud:goto-loc-hist 5))
  183. (defun realgud:goto-loc-hist-6 ()
  184. "Go to position 6th from the newest position."
  185. (interactive)
  186. (realgud:goto-loc-hist 6))
  187. (defun realgud:goto-loc-hist-7 ()
  188. "Go to position 7th from the newest position."
  189. (interactive)
  190. (realgud:goto-loc-hist 7))
  191. (defun realgud:goto-loc-hist-8 ()
  192. "Go to position 8th from the newest position."
  193. (interactive)
  194. (realgud:goto-loc-hist 8))
  195. (defun realgud:goto-loc-hist-9 ()
  196. "Go to position 9th from the newest position."
  197. (interactive)
  198. (realgud:goto-loc-hist 9))
  199. (provide-me "realgud-")