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.

135 lines
5.1 KiB

  1. ;; Copyright (C) 2015-2017, 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. ;; `pdb' Main interface to pdb via Emacs
  14. (require 'python) ; for python-shell-interpreter
  15. (require 'load-relative)
  16. (require-relative-list '("core" "track-mode") "realgud:pdb-")
  17. (require-relative-list '("../../common/run") "realgud:")
  18. (require-relative-list '("core" "track-mode") "realgud:pdb-")
  19. ;; This is needed, or at least the docstring part of it is needed to
  20. ;; get the customization menu to work in Emacs 24.
  21. (defgroup realgud:pdb nil
  22. "The realgud interface to the Python pdb debugger"
  23. :group 'realgud
  24. :version "25.13")
  25. ;; -------------------------------------------------------------------
  26. ;; User-definable variables
  27. ;;
  28. (defcustom realgud:pdb-command-name
  29. "python -m pdb"
  30. "File name for executing the stock Python debugger and command options.
  31. This should be an executable on your path, or an absolute file name."
  32. :type 'string
  33. :group 'realgud:pdb)
  34. ;; -------------------------------------------------------------------
  35. ;; The end.
  36. ;;
  37. (declare-function pdb-track-mode 'realgud:pdb-track)
  38. (declare-function pdb-query-cmdline 'realgud:pdb-core)
  39. (declare-function pdb-parse-cmd-args 'realgud:pdb-core)
  40. (declare-function realgud:run-debugger 'realgud:run)
  41. (declare-function realgud:run-process 'realgud:core)
  42. (declare-function realgud:flatten 'realgud-utils)
  43. ;;;###autoload
  44. (defun realgud:pdb (&optional opt-cmd-line no-reset)
  45. "Invoke the pdb Python debugger and start the Emacs user interface.
  46. String OPT-CMD-LINE specifies how to run pdb. You will be prompted
  47. for a command line is one isn't supplied.
  48. OPT-COMMAND-LINE is treated like a shell string; arguments are
  49. tokenized by `split-string-and-unquote'. The tokenized string is
  50. parsed by `pdb-parse-cmd-args' and path elements found by that
  51. are expanded using `realgud:expand-file-name-if-exists'.
  52. Normally, command buffers are reused when the same debugger is
  53. reinvoked inside a command buffer with a similar command. If we
  54. discover that the buffer has prior command-buffer information and
  55. NO-RESET is nil, then that information which may point into other
  56. buffers and source buffers which may contain marks and fringe or
  57. marginal icons is reset. See `loc-changes-clear-buffer' to clear
  58. fringe and marginal icons.
  59. "
  60. (interactive)
  61. (realgud:run-debugger "pdb" 'pdb-query-cmdline
  62. 'pdb-parse-cmd-args
  63. 'realgud:pdb-minibuffer-history
  64. opt-cmd-line no-reset)
  65. )
  66. ;;;###autoload
  67. (defun realgud:pdb-remote (&optional opt-cmd-line no-reset)
  68. "Invoke the pdb Python debugger and start the Emacs user interface.
  69. String OPT-CMD-LINE specifies how to run pdb. You will be prompted
  70. for a command line is one isn't supplied.
  71. OPT-COMMAND-LINE is treated like a shell string; arguments are
  72. tokenized by `split-string-and-unquote'. The tokenized string is
  73. parsed by `pdb-parse-remote-cmd-args' and path elements found by that
  74. are expanded using `realgud:expand-file-name-if-exists'.
  75. Normally, command buffers are reused when the same debugger is
  76. reinvoked inside a command buffer with a similar command. If we
  77. discover that the buffer has prior command-buffer information and
  78. NO-RESET is nil, then that information which may point into other
  79. buffers and source buffers which may contain marks and fringe or
  80. marginal icons is reset. See `loc-changes-clear-buffer' to clear
  81. fringe and marginal icons.
  82. "
  83. (interactive)
  84. (realgud:run-debugger "pdb" 'pdb-remote-query-cmdline
  85. 'pdb-parse-remote-cmd-args
  86. 'realgud:pdb-remote-minibuffer-history
  87. opt-cmd-line no-reset "remote-pdb")
  88. )
  89. ;;;###autoload
  90. (defun realgud:pdb-delayed ()
  91. "This is like `pdb', but assumes inside the program to be debugged, you
  92. have a call to the debugger somewhere, e.g. 'from trepan.api import debug; debug()'.
  93. Therefore we invoke python rather than the debugger initially.
  94. "
  95. (interactive)
  96. (let* ((initial-debugger python-shell-interpreter)
  97. (actual-debugger "pdb")
  98. (cmd-str (pdb-query-cmdline initial-debugger))
  99. (cmd-args (split-string-and-unquote cmd-str))
  100. ;; XXX: python gets registered as the interpreter rather than
  101. ;; a debugger, and the debugger position (nth 1) is missing:
  102. ;; the script-args takes its place.
  103. (parsed-args (pdb-parse-cmd-args cmd-args))
  104. (script-args (nth 1 parsed-args))
  105. (script-name (car script-args))
  106. (parsed-cmd-args
  107. (cl-remove-if 'nil (realgud:flatten parsed-args))))
  108. (realgud:run-process actual-debugger script-name parsed-cmd-args
  109. 'realgud:pdb-minibuffer-history)))
  110. (realgud-deferred-invoke-setup "pdb")
  111. (provide-me "realgud-")