~willvaughn/.emacs.d

8ae8017c66b3b8a175a1f040c596ab633220e13a — William Vaughn 2 months ago 5e1fdc9
add a function for starting a django shell
1 files changed, 17 insertions(+), 0 deletions(-)

M lisp/wv-python.el
M lisp/wv-python.el => lisp/wv-python.el +17 -0
@@ 1,9 1,26 @@
;;; lisp/wv-python.el -*- lexical-binding: t; -*-

;;; Set this in a .dir-locals.el
;;; ((nil . ((wv-python/django-managepy-path . "/path/to/your/project/manage.py"))))
(defvar wv-python/django-managepy-path nil
  "Path to current project's manage.py file.")

(defun wv-python/django-shell ()
  (interactive)
  (if (not wv-python/django-managepy-path)
      (message "Variable 'wv-python/django-managepy-path' not set. Please configure it in .dir-locals.el.")
    (let ((default-directory (file-name-directory wv-python/django-managepy-path))
          (python-shell-interpreter wv-python/django-managepy-path)
          (python-shell-interpreter-args "shell"))
      (run-python (python-shell-calculate-command) nil t))))

(use-package python
  :hook
  ((python-mode . tree-sitter-mode)
   (python-mode . tree-sitter-hl-mode))
  :bind
  (:map python-mode-map
   ("C-c M-p" . wv-python/django-shell))
  :config
  (setq-default eglot-workspace-configuration
                '(:pylsp