diff options
| author | Craig Jennings <c@cjennings.net> | 2025-10-20 16:17:30 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-10-20 16:17:30 -0500 |
| commit | df4469f231e86877b7d055bf989220a5fbc0a763 (patch) | |
| tree | ea3ef00d10a7a7c1366213d493ea4e2546b9d783 /modules/prog-python.el | |
| parent | ce8477e80e0a837ac462b97c1a4b5d834838d6d3 (diff) | |
feat:programming: Enhance language-specific keybindings and setup
Add language-specific keybindings and configurations for C, Go,
Python, and shell scripting panels. Introduce system utility
function declarations and improve keybinding consistency across
languages. Implement keybindings for debug, format, and static
analysis tools tailored to each programming language, enhancing the
developer experience and workflow efficiency.
Diffstat (limited to 'modules/prog-python.el')
| -rw-r--r-- | modules/prog-python.el | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/modules/prog-python.el b/modules/prog-python.el index 2775061d..2eee7c50 100644 --- a/modules/prog-python.el +++ b/modules/prog-python.el @@ -31,6 +31,8 @@ ;; Forward declarations for external packages (declare-function company-mode "company") +(declare-function cj/disabled "system-defaults") +(declare-function pdb "gud") (defvar poetry-tracking-strategy) (defvar pylsp-path "pylsp" @@ -38,6 +40,10 @@ Install with: pip install python-lsp-server[all] Or for pyright: pip install pyright") +(defvar mypy-path "mypy" + "Path to mypy static type checker. +Install with: pip install mypy") + ;; -------------------------------- Python Setup ------------------------------- ;; preferences for Python programming @@ -57,13 +63,38 @@ Or for pyright: pip install pyright") (executable-find pylsp-path)) (lsp-deferred))) +(defun cj/python-mypy () + "Run mypy static type checker on the current Python file or directory." + (interactive) + (if (executable-find mypy-path) + (let ((target (or (buffer-file-name) default-directory))) + (compile (format "%s %s" mypy-path (shell-quote-argument target)))) + (message "mypy not found. Install with: pip install mypy"))) + +(defun cj/python-debug () + "Start Python debugger (pdb) on the current file." + (interactive) + (if buffer-file-name + (pdb (format "python3 -m pdb %s" (shell-quote-argument buffer-file-name))) + (message "No file associated with this buffer"))) + +(defun cj/python-mode-keybindings () + "Set up keybindings for Python programming. +Overrides default prog-mode keybindings with Python-specific commands." + ;; S-f5: Run mypy (static type checking) + (local-set-key (kbd "S-<f5>") #'cj/python-mypy) + + ;; S-f6: Debug with pdb + (local-set-key (kbd "S-<f6>") #'cj/python-debug)) + ;; ----------------------------------- Python ---------------------------------- ;; configuration for python-ts-mode (treesit-based Python editing) (use-package python :ensure nil ;; built-in :hook - (python-ts-mode . cj/python-setup) + ((python-ts-mode . cj/python-setup) + (python-ts-mode . cj/python-mode-keybindings)) :custom (python-shell-interpreter "python3") :config @@ -111,7 +142,10 @@ Or for pyright: pip install pyright") :custom (blacken-allow-py36 t) (blacken-skip-string-normalization t) - :hook (python-ts-mode . blacken-mode)) + :hook (python-ts-mode . blacken-mode) + :bind (:map python-ts-mode-map + ("<f6>" . blacken-buffer) + ("C-; f" . blacken-buffer))) ;; ---------------------------------- Numpydoc --------------------------------- ;; automatically insert NumPy style docstrings in Python function definitions |
