blob: 1d48a6fb178781245c723f09887ff392757382ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
1
;;; Code:
(use-package python
:ensure t)
(use-package eglot
:ensure t
:config
(add-to-list 'eglot-server-programs '(python-mode . ("pylsp")))
:hook
((python-mode . eglot-ensure)))
(use-package pyvenv
:ensure t
:config
(pyvenv-mode t)
;; Set correct Python interpreter
(setq pyvenv-post-activate-hooks
(list (lambda ()
(setq python-shell-interpreter (concat pyvenv-virtual-env "bin/python3")))))
(setq pyvenv-post-deactivate-hooks
(list (lambda ()
(setq python-shell-interpreter "python3")))))
(defun python-args-to-google-docstring (text &optional make-fields)
"Return a reST docstring format for the python arguments in yas-text."
(let* ((indent (concat "\n" (make-string (current-column) 32)))
(args (python-split-args text))
(nr 0)
(formatted-args
(mapconcat
(lambda (x)
(concat " " (nth 0 x)
(if make-fields (format " ${%d:arg%d}" (cl-incf nr) nr))
(if (nth 1 x) (concat " \(default " (nth 1 x) "\)"))))
args
indent)))
(unless (string= formatted-args "")
(concat
(mapconcat 'identity
(list "" "Args:" formatted-args)
indent)
"\n"))))
(setq python-indent-guess-indent-offset nil)
(defun mk/python/remove_unused ()
"Removes unused imports"
(interactive)
(setq command (concat "autoflake --in-place --remove-unused-variables " buffer-file-name))
(shell-command command)
;; Reload the modified file
(revert-buffer t t)
)
(provide 'python-custom)
;;; python-custom.el ends here
|