Compare commits

..

3 commits

Author SHA1 Message Date
d36c62080b [feat] add cond-let marco 2024-07-07 20:06:15 +08:00
20eba0d77d [feat] add trace-python=virtualenv func 2024-07-06 22:12:45 +08:00
54c44551e8 [package] remove python-poetry 2024-07-06 21:47:49 +08:00
2 changed files with 39 additions and 1 deletions

View file

@ -229,6 +229,19 @@
'org-babel-load-languages 'org-babel-load-languages
'((restclient . t))) '((restclient . t)))
#+end_src #+end_src
*
** cond-let
终于知道为什么没人想写这个宏了,括号是真得多啊。
#+begin_src emacs-lisp
(defmacro cond-let (forms)
(declare (debug t))
(if forms
`(let* ,(setq varlist (internal--build-bindings (caar forms)))
(if-let ,(car (last varlist))
,(cadar forms)
(cond-let ,(cdr forms))))))
#+end_src
* 杂项 * 杂项
=cnfonts= 是一个可以分别设置中英文字体的 bk ,方便对其表格。 =cnfonts= 是一个可以分别设置中英文字体的 bk ,方便对其表格。
@ -577,3 +590,29 @@
(add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode) (add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode)
(add-hook 'cider-repl-mode-hook 'enable-paredit-mode)) (add-hook 'cider-repl-mode-hook 'enable-paredit-mode))
#+end_src #+end_src
* Python
自动切换虚拟环境, poetry 包可能在处理远端机器的项目可能会有问题所以从那边抠出来放到这里。
#+begin_src emacs-lisp
(defvar poetry-venv-list '()
"List of known poetry virtualenvs.")
(defun my/track-python-virtualenv (&optional _)
(interactive)
(when (and buffer-file-name
(string= nil (file-remote-p default-directory)))
(cond ((locate-dominating-file default-directory "pyproject.toml")
(if-let ((poetry-current-project-venv (cdr (assq '(locate-dominating-file default-directory "pyproject.toml") poetry-venv-list))))
(when (not (equal python-shell-virtualenv-path poetry-current-project-venv))
(pyvenv-activate poetry-current-project-venv))
(let ((poetry-project-path (locate-dominating-file default-directory "pyproject.toml"))
(poetry-venv-path (s-trim (shell-command-to-string "env -u VIRTUAL_ENV poetry env info -p"))))
(pyvenv-activate poetry-venv-path)
(add-to-list 'poetry-venv-list (cons poetry-project-path poetry-venv-path)))))
((locate-dominating-file default-directory ".venv")
(pyvenv-activate (concat (locate-dominating-file default-directory ".venv") ".venv")))
(t (pyvenv-deactivate)))))
(add-to-list 'window-buffer-change-functions 'my/track-python-virtualenv)
#+end_src

View file

@ -169,7 +169,6 @@
(python (python
+lsp +lsp
+pyright +pyright
+poetry
+tree-sitter) ; beautiful is better than ugly +tree-sitter) ; beautiful is better than ugly
;;qt ; the 'cutest' gui framework ever ;;qt ; the 'cutest' gui framework ever
;;racket ; a DSL for DSLs ;;racket ; a DSL for DSLs