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.

168 lines
6.4 KiB

  1. ;; Copyright (C) 2015-2016, 2018-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. ;; Stock Python debugger pdb
  14. (eval-when-compile (require 'cl-lib)) ;For setf.
  15. (require 'load-relative)
  16. (require-relative-list '("../../common/regexp"
  17. "../../common/loc"
  18. "../../common/init")
  19. "realgud-")
  20. (require-relative-list '("../../lang/python") "realgud-lang-")
  21. (defvar realgud-pat-hash)
  22. (declare-function make-realgud-loc-pat 'realgud-regexp)
  23. (defvar realgud:pdb-pat-hash (make-hash-table :test 'equal)
  24. "Hash key is the what kind of pattern we want to match:
  25. backtrace, prompt, etc. The values of a hash entry is a
  26. realgud-loc-pat struct")
  27. (declare-function make-realgud-loc "realgud-loc" (a b c d e f))
  28. ;; -------------------------------------------------------------------
  29. ;; User-definable variables
  30. ;;
  31. ;; Regular expression that describes a pdb location generally shown
  32. ;; before a command prompt.
  33. ;;
  34. ;; Program-location lines look like this:
  35. ;; > /usr/bin/zonetab2pot.py(15)<module>()
  36. ;; or MS Windows:
  37. ;; > c:\\mydirectory\\gcd.py(10)<module>
  38. (setf (gethash "loc" realgud:pdb-pat-hash)
  39. (make-realgud-loc-pat
  40. :regexp "^> \\(\\(?:[a-zA-Z]:\\)?[-a-zA-Z0-9_/.\\\\ ]+\\)(\\([0-9]+\\))"
  41. :file-group 1
  42. :line-group 2))
  43. ;; An initial list of regexps that don't generally have files
  44. ;; associated with them and therefore we should not try to find file
  45. ;; associations for them. This list is used to seed a field of the
  46. ;; same name in the cmd-info structure inside a command buffer. A user
  47. ;; may add additional files to the command-buffer's re-ignore-list.
  48. (setf (gethash "ignore-re-file-list" realgud:pdb-pat-hash)
  49. (list realgud-python-ignore-file-re))
  50. (setf (gethash "prompt" realgud:pdb-pat-hash)
  51. (make-realgud-loc-pat
  52. :regexp "^[(]+Pdb[)]+ "
  53. ))
  54. ;; realgud-loc-pat that describes a Python backtrace line.
  55. (setf (gethash "lang-backtrace" realgud:pdb-pat-hash)
  56. realgud-python-backtrace-loc-pat)
  57. (setf (gethash "debugger-backtrace" realgud:pdb-pat-hash)
  58. realgud:python-trepan-backtrace-pat)
  59. ;; realgud-loc-pat that describes a line a Python "info break" line.
  60. ;; For example:
  61. ;; 1 breakpoint keep y at /usr/local/bin/trepan3k:7
  62. (setf (gethash "debugger-breakpoint" realgud:pdb-pat-hash)
  63. (make-realgud-loc-pat
  64. :regexp (format "^%s[ \t]+\\(breakpoint\\)[ \t]+\\(keep\\|del\\)[ \t]+\\(yes\\|no\\)[ \t]+.*at \\(.+\\):%s"
  65. realgud:regexp-captured-num realgud:regexp-captured-num)
  66. :num 1
  67. :text-group 2 ;; misnamed Is "breakpoint" or "watchpoint"
  68. :string 3 ;; misnamed. Is "keep" or "del"
  69. :file-group 5
  70. :line-group 6))
  71. ;; realgud-loc-pat that describes location in a pytest error
  72. (setf (gethash "pytest-error" realgud:pdb-pat-hash)
  73. realgud-pytest-error-loc-pat)
  74. ;; realgud-loc-pat that describes location in a flake8 message
  75. (setf (gethash "flake8-msg" realgud:pdb-pat-hash)
  76. realgud-flake8-msg-loc-pat)
  77. ;; Regular expression that describes a "breakpoint set" line. For example:
  78. ;; Breakpoint 1 at /usr/bin/pdb:7
  79. (setf (gethash "brkpt-set" realgud:pdb-pat-hash)
  80. (make-realgud-loc-pat
  81. :regexp "^Breakpoint \\([0-9]+\\) at[ \t\n]+\\(.+\\):\\([0-9]+\\)\\(\n\\|$\\)"
  82. :num 1
  83. :file-group 2
  84. :line-group 3))
  85. ;; realgud-loc-pat that describes a "delete breakpoint" line
  86. ;; Python 3 includes a file name and line number; Python 2 doesn't
  87. (setf (gethash "brkpt-del" realgud:pdb-pat-hash)
  88. (make-realgud-loc-pat
  89. :regexp "^Deleted breakpoint \\([0-9]+\\)"
  90. :num 1))
  91. (setf (gethash "font-lock-keywords" realgud:pdb-pat-hash)
  92. '(
  93. ;; The frame number and first type name, if present.
  94. ("^\\(->\\|##\\)\\([0-9]+\\) \\(<module>\\)? *\\([a-zA-Z_][a-zA-Z0-9_]*\\)(\\(.+\\))?"
  95. (2 realgud-backtrace-number-face)
  96. (4 font-lock-function-name-face nil t)) ; t means optional.
  97. ;; Parameter sequence, E.g. gcd(a=3, b=5)
  98. ;; ^^^^^^^^^
  99. ("(\\(.+\\))"
  100. (1 font-lock-variable-name-face))
  101. ;; File name. E.g file '/test/gcd.py'
  102. ;; ------^^^^^^^^^^^^-
  103. ("[ \t]+file '\\([^ ]+*\\)'"
  104. (1 realgud-file-name-face))
  105. ;; Line number. E.g. at line 28
  106. ;; ---------^^
  107. ("[ \t]+at line \\([0-9]+\\)$"
  108. (1 realgud-line-number-face))
  109. ;; Function name.
  110. ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\.\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  111. (1 font-lock-type-face)
  112. (2 font-lock-function-name-face))
  113. ;; (pdb-frames-match-current-line
  114. ;; (0 pdb-frames-current-frame-face append))
  115. ))
  116. (setf (gethash "font-lock-breakpoint-keywords" realgud:pdb-pat-hash)
  117. realgud:python-debugger-font-lock-breakpoint-keywords)
  118. (defvar realgud:pdb-command-hash (make-hash-table :test 'equal)
  119. "Hash key is command name like 'finish' and the value is
  120. the pdb command to use, like 'return'")
  121. (setf (gethash "pdb" realgud-command-hash) realgud:pdb-command-hash)
  122. ;; Mappings between PDB-specific names and GUD names
  123. (setf (gethash "finish" realgud:pdb-command-hash) "return")
  124. (setf (gethash "kill" realgud:pdb-command-hash) "quit")
  125. (setf (gethash "backtrace" realgud:pdb-command-hash) "where")
  126. ;; Clear in Python does both the usual “delete” and “clear”
  127. (setf (gethash "delete" realgud:pdb-command-hash) "clear %p")
  128. (setf (gethash "clear" realgud:pdb-command-hash) "clear %X:%l")
  129. ;; Use ‘!’ instead of ‘p’, since ‘p’ only works for expressions, not statements
  130. (setf (gethash "eval" realgud:pdb-command-hash) "!%s")
  131. (setf (gethash "info-breakpoints" realgud:pdb-command-hash) "break")
  132. ;; Unsupported features:
  133. (setf (gethash "shell" realgud:pdb-command-hash) "*not-implemented*")
  134. (setf (gethash "frame" realgud:pdb-command-hash) "*not-implemented*")
  135. (setf (gethash "pdb" realgud-pat-hash) realgud:pdb-pat-hash)
  136. (provide-me "realgud:pdb-")