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.

229 lines
8.2 KiB

  1. ;; Copyright (C) 2011, 2014-2016 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. ;;; Common Python constants and regular expressions.
  14. (require 'load-relative)
  15. (require-relative-list '("../common/regexp" "../common/loc" "../common/track")
  16. "realgud-")
  17. (declare-function realgud-goto-line-for-pt 'realgud-track)
  18. (declare-function make-realgud-loc-pat 'realgud-regexp)
  19. (defconst realgud-python-backtrace-loc-pat
  20. (make-realgud-loc-pat
  21. :regexp "^[ \t]+File \"\\(.+\\)\", line \\([0-9]+\\)"
  22. :file-group 1
  23. :line-group 2)
  24. "A realgud-loc-pat struct that describes a Python backtrace (or
  25. traceback) line." )
  26. ;; Regular expression that pseudo-files in caller. For example:
  27. ;; <string>
  28. (defconst realgud-python-ignore-file-re "<string>"
  29. "Regular expression that pseudo-files of caller()")
  30. (defun realgud-python-populate-command-keys (&optional map)
  31. "Bind the debugger function key layout used by many debuggers.
  32. \\{realgud-example-map-standard}"
  33. (define-key map (kbd "C-c !b") 'realgud:goto-debugger-backtrace-line)
  34. (define-key map (kbd "C-c !!") 'realgud:goto-lang-backtrace-line)
  35. (define-key map (kbd "C-c !e") 'realgud:pytest-goto-errmsg-line)
  36. (define-key map (kbd "C-c !8") 'realgud:flake8-goto-msg-line)
  37. )
  38. ;; Things common to the trepan Python debuggers
  39. (defconst realgud:python-trepan-frame-start-regexp
  40. "\\(?:^\\|\n\\)\\(->\\|##\\)")
  41. (defconst realgud:python-trepan-frame-num-regexp
  42. "\\([0-9]+\\)")
  43. ;; Regular expression that describes a trepan2/3k location generally shown
  44. ;; before a command prompt.
  45. ;;
  46. ;; For example:
  47. ;; (/usr/bin/zonetab2pot.py:15 @10): <module>
  48. ;; (/usr/bin/zonetab2pot.py:15 remapped <string>): <module>
  49. ;; or MS Windows:
  50. ;; (c:\\mydirectory\\gcd.py:10): <module>
  51. (defconst realgud:python-trepan-loc-pat
  52. (make-realgud-loc-pat
  53. :regexp "^(\\(\\(?:[a-zA-Z]:\\)?[-a-zA-Z0-9_/.\\\\ ]+\\):\\([0-9]+\\)\\(?: @[0-9]+\\)?\\(?: remapped .*?\\)?): \\(?:<module>\\)?\\(?:\n.. [0-9]+ \\(.*?\\)\n\\)?"
  54. :file-group 1
  55. :line-group 2
  56. :text-group 3
  57. :ignore-file-re realgud-python-ignore-file-re)
  58. "A realgud-loc-pat struct that describes a Python trepan
  59. location line." )
  60. ;; Regular expression that describes a trepan2/3k backtrace line.
  61. ;; For example:
  62. ;; ->0 get_distribution(dist='trepan==0.3.9')
  63. ;; called from file '/python2.7/dist-packages/pkg_res.py' at line 341
  64. ;; ##1 load_entry_point(dist='tr=0.3.9', group='console_scripts', name='tr')
  65. ;; called from file '/python2.7/dist-packages/pkg_res.py' at line 351
  66. ;; ##2 <module> exec()
  67. (defconst realgud:python-trepan-backtrace-pat
  68. (make-realgud-loc-pat
  69. :regexp (concat
  70. realgud:python-trepan-frame-start-regexp
  71. realgud:python-trepan-frame-num-regexp "[ ]"
  72. "\\(?:.*?)\\)\\(?:[\n\t ]+?\\)"
  73. "\\(?:called from file \\)?'\\([^:]+?\\)' at line \\([0-9]+\\)")
  74. :num 2
  75. :file-group 3
  76. :line-group 4
  77. ))
  78. ;; FIXME breakpoints aren't locations. It should be a different structure
  79. ;; realgud-loc that describes a trepan2/3k "info breakpoints" line.
  80. ;; For example:
  81. ;; 1 breakpoint keep y at /home/rocky/.pyenv/versions/3.7.2/lib/python3.7/importlib/_bootstrap.py:1019
  82. ;; 2 breakpoint keep y at /home/rocky/.pyenv/versions/3.7.2/lib/python3.7/importlib/_bootstrap.py:1023
  83. ;; 3 breakpoint keep y at /home/rocky/.pyenv/versions/3.7.2/lib/python3.7/importlib/_bootstrap.py:1
  84. (defconst realgud-python-breakpoint-pat
  85. (make-realgud-loc-pat
  86. :regexp (format "^%s[ \t]+\\(breakpoint\\)[ \t]+\\(keep\\|del\\)[ \t]+\\([yn]\\)[ \t]+.*at \\(.+\\):%s"
  87. realgud:regexp-captured-num realgud:regexp-captured-num)
  88. :num 1
  89. :text-group 2 ;; misnamed Is "breakpoint" or "watchpoint"
  90. :string 3 ;; misnamed. Is "keep" or "del"
  91. :file-group 5
  92. :line-group 6)
  93. "A realgud-loc-pat struct that describes a Python breakpoint." )
  94. ;; Regular expression that describes a "breakpoint set" line
  95. (defconst realgud:python-trepan-brkpt-set-pat
  96. (make-realgud-loc-pat
  97. :regexp "^Breakpoint \\([0-9]+\\) set at line \\([0-9]+\\)[ \t\n]+of file[ \t\n]+\\(.+\\)\\(\n\\|$\\)"
  98. :num 1
  99. :file-group 3
  100. :line-group 2))
  101. ;; Regular expression that describes a debugger "delete" (breakpoint) response.
  102. (defconst realgud:python-trepan-brkpt-del-pat
  103. (make-realgud-loc-pat
  104. :regexp "^Deleted breakpoint \\([0-9]+\\)\n"
  105. :num 1))
  106. ;; Regular expression that describes a debugger "disable" (breakpoint) response.
  107. ;; For example:
  108. ;; Breakpoint entry 4 disabled.
  109. (defconst realgud:python-trepan-brkpt-disable-pat
  110. (make-realgud-loc-pat
  111. :regexp (format "^Breakpoint %s disabled"
  112. realgud:regexp-captured-num)
  113. :num 1))
  114. ;; Regular expression that describes a debugger "enable" (breakpoint) response.
  115. ;; For example:
  116. ;; Breakpoint entry 4 enabled.
  117. (defconst realgud:python-trepan-brkpt-enable-pat
  118. (make-realgud-loc-pat
  119. :regexp (format "^Breakpoint %s enabled"
  120. realgud:regexp-captured-num)
  121. :num 1))
  122. (defconst realgud:python-debugger-font-lock-keywords
  123. '(
  124. ;; The frame number and first type name, if present.
  125. ("^\\(->\\|##\\)\\([0-9]+\\) \\(<module>\\)? *\\([a-zA-Z_][a-zA-Z0-9_]*\\)(\\(.+\\))?"
  126. (2 realgud-backtrace-number-face)
  127. (4 font-lock-function-name-face nil t)) ; t means optional.
  128. ;; Parameter sequence, E.g. gcd(a=3, b=5)
  129. ;; ^^^^^^^^^
  130. ("(\\(.+\\))"
  131. (1 font-lock-variable-name-face))
  132. ;; File name. E.g file '/test/gcd.py'
  133. ;; ------^^^^^^^^^^^^-
  134. ("[ \t]+file '\\([^ ]+*\\)'"
  135. (1 realgud-file-name-face))
  136. ;; Line number. E.g. at line 28
  137. ;; ---------^^
  138. ("[ \t]+at line \\([0-9]+\\)$"
  139. (1 realgud-line-number-face))
  140. ;; Function name.
  141. ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\.\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
  142. (1 font-lock-type-face)
  143. (2 font-lock-function-name-face))
  144. ;; (trepan2-frames-match-current-line
  145. ;; (0 trepan2-frames-current-frame-face append))
  146. ))
  147. (defconst realgud:python-debugger-font-lock-breakpoint-keywords
  148. '(
  149. ;; The breakpoint number, type and disposition
  150. ;; 1 breakpoint keep y at /home/rocky/.pyenv/versions/3.7.2/bin/trepan3k:6
  151. ;; ^ ^^^^^^^^^^ ^^^^
  152. ("^\\([0-9]+\\)[ \t]+\\(breakpoint\\)[ \t]+\\(keep\\|del\\)"
  153. (1 realgud-breakpoint-number-face)
  154. (2 font-lock-function-name-face nil t) ; t means optional.
  155. (3 font-lock-function-name-face nil t)) ; t means optional.
  156. ;; 1 breakpoint keep y at /home/rocky/.pyenv/versions/3.7.2/bin/trepan3k:6
  157. ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^
  158. ("[ \t]+at \\(.+*\\):\\([0-9]+\\)"
  159. (1 realgud-file-name-face)
  160. (2 realgud-line-number-face))
  161. ))
  162. (defconst realgud-pytest-error-loc-pat
  163. (make-realgud-loc-pat
  164. :regexp "^\\(.*\\):\\([0-9]+\\): in "
  165. :file-group 1
  166. :line-group 2)
  167. "A realgud-loc-pat struct that describes a Pytest error line"
  168. )
  169. ;; FIXME: there is probably a less redundant way to do the following
  170. ;; FNS.
  171. (defun realgud:pytest-goto-errmsg-line (pt)
  172. "Display the location mentioned by the pytest error at PT."
  173. (interactive "d")
  174. (realgud-goto-line-for-pt pt "pytest-error"))
  175. (defconst realgud-flake8-msg-loc-pat
  176. (make-realgud-loc-pat
  177. :regexp "^\\(.*\\):\\([0-9]+\\):\\([0-9]+\\): [EFWCN]\\([0-9]+\\) "
  178. :file-group 1
  179. :line-group 2
  180. :char-offset-group 3
  181. )
  182. "A realgud-loc-pat struct that describes a flake8 warning or error line"
  183. )
  184. ;; FIXME: there is probably a less redundant way to do the following
  185. ;; FNS.
  186. (defun realgud:flake8-goto-msg-line (pt)
  187. "Display the location mentioned by the flake8 warning or error."
  188. (interactive "d")
  189. (realgud-goto-line-for-pt pt "flake8-msg"))
  190. (provide-me "realgud-lang-")