dkellner-python.el 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ;; dkellner-python.el --- Python-specific configuration
  2. ;;
  3. ;; This mainly enables and configures Elpy:
  4. ;; https://elpy.readthedocs.io/en/latest/index.html
  5. (use-package elpy
  6. :config
  7. (elpy-enable)
  8. ;; Disable highlight-indentation-mode, because I don't like it.
  9. (delete 'elpy-module-highlight-indentation elpy-modules))
  10. (defun dkellner/elpy-test-tox-runner (top file module test)
  11. "Test the project using Tox.
  12. At the moment this just runs `tox` in the project-root and is not able to run a
  13. single test at point."
  14. (interactive (elpy-test-at-point))
  15. (apply #'elpy-test-run
  16. top
  17. "tox"
  18. ()))
  19. (put 'dkellner/elpy-test-tox-runner 'elpy-test-runner-p t)
  20. ;; The following is not mature and well-tested yet, but first results are
  21. ;; pleasing. When running a test we try to detect "(Pdb)" in the process'
  22. ;; output - if we do, we change the mode to `dkellner/pdb-mode' which enables
  23. ;; us to interact with the debugger.
  24. ;;
  25. ;; TODO: Move point to the end of the buffer (that is, after "(Pdb) ")
  26. (define-derived-mode dkellner/pdb-mode comint-mode "Pdb"
  27. "Major mode for interacting with the Python debugger `Pdb'."
  28. (setq buffer-read-only nil)
  29. (local-set-key (kbd "C-c g") 'recompile))
  30. (defun dkellner/watch-for-pdb (start end length)
  31. "Runs `pdb-mode' when the string \"(Pdb)\" is detected.
  32. This function should be added to `after-change-functions'."
  33. (save-excursion
  34. (goto-char start)
  35. (if (search-forward "(Pdb)" end t)
  36. (dkellner/pdb-mode))))
  37. (defun dkellner/setup-watch-for-pdb ()
  38. "Adds `dkellner/watch-for-pdb' to `after-change-functions' (buffer-local)."
  39. (add-hook 'after-change-functions 'dkellner/watch-for-pdb t t))
  40. (add-hook 'compilation-mode-hook 'dkellner/setup-watch-for-pdb)
  41. (provide 'dkellner-python)