From 811b18bdbd6002f3a8aaa1b85cc25eea70a05934 Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Fri, 22 Apr 2022 00:20:05 +0800 Subject: Add config of python (emacs) --- .emacs.d/init.el | 2 ++ .emacs.d/lisp/init-c.el | 2 ++ .emacs.d/lisp/init-eglot.el | 3 +++ .emacs.d/lisp/init-go.el | 5 +++-- .emacs.d/lisp/init-python.el | 20 ++++++++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .emacs.d/lisp/init-c.el create mode 100644 .emacs.d/lisp/init-python.el (limited to '.emacs.d') diff --git a/.emacs.d/init.el b/.emacs.d/init.el index a0ba982..0dcedfb 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -28,6 +28,8 @@ (require 'init-org) (require 'init-lang) (require 'init-go) +(require 'init-python) +(require 'init-c) (require 'init-eglot) (require 'init-racket) (require 'init-deft) diff --git a/.emacs.d/lisp/init-c.el b/.emacs.d/lisp/init-c.el new file mode 100644 index 0000000..020ca56 --- /dev/null +++ b/.emacs.d/lisp/init-c.el @@ -0,0 +1,2 @@ +;; TODO +(provide 'init-c) diff --git a/.emacs.d/lisp/init-eglot.el b/.emacs.d/lisp/init-eglot.el index 5409958..311c5d3 100644 --- a/.emacs.d/lisp/init-eglot.el +++ b/.emacs.d/lisp/init-eglot.el @@ -1,3 +1,6 @@ +(when (gx/maybe-require-package 'eglot) + (autoload #'eglot-ensure "eglot" nil t)) + (defun gx/eglot-format-before-save () (add-hook 'before-save-hook #'eglot-format nil t)) diff --git a/.emacs.d/lisp/init-go.el b/.emacs.d/lisp/init-go.el index f0a6b84..3a224fb 100644 --- a/.emacs.d/lisp/init-go.el +++ b/.emacs.d/lisp/init-go.el @@ -1,4 +1,5 @@ (when (gx/maybe-require-package 'go-mode) + (autoload #'go-mode "go-mode" nil t) (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))) (add-hook 'go-mode-hook (lambda () (setq tab-width 4))) @@ -6,8 +7,8 @@ (gx/maybe-require-package 'go-dlv) (when (gx/maybe-require-package 'eglot) - (add-hook 'go-mode-hook #'eglot-ensure) (add-hook 'go-mode-hook #'gx/eglot-format-before-save) - (add-hook 'go-mode-hook #'gx/eglot-code-action-organize-imports-before-save)) + (add-hook 'go-mode-hook #'gx/eglot-code-action-organize-imports-before-save) + (add-hook 'go-mode-hook #'eglot-ensure)) (provide 'init-go) diff --git a/.emacs.d/lisp/init-python.el b/.emacs.d/lisp/init-python.el new file mode 100644 index 0000000..646251f --- /dev/null +++ b/.emacs.d/lisp/init-python.el @@ -0,0 +1,20 @@ +(when (gx/maybe-require-package 'eglot) + (add-hook 'python-mode-hook #'eglot-ensure)) + +;; TODO Check if the venv-directory exists. +;; Raise error message if it doesn't. +(defun gx/python-load-venv () + "" + (setenv "WORKON_HOME" (projectile-project-root)) + (let* ((project-root (projectile-project-root)) + (venv-directory "venv")) + (setenv "WORKON_HOME" project-root) + (pyvenv-workon venv-directory))) + + +(when (gx/maybe-require-package 'pyvenv) + (autoload #'pyvenv-activate "pyvenv" nil t) + (autoload #'pyvenv-workon "pyvenv" nil t) + (add-hook 'python-mode-hook #'gx/python-load-venv)) + +(provide 'init-python) -- cgit v1.2.3