From 1ecf55c3177a73aa24a62358bec3406aa3f84b5c Mon Sep 17 00:00:00 2001 From: Zelong Kuang Date: Sun, 14 Dec 2025 23:46:29 +1100 Subject: [PATCH] Python support --- init.el | 3 ++- lisp/init-cc.el | 13 +++++++------ lisp/init-completion.el | 21 +++++++++++++++++++-- lisp/init-lsp.el | 12 +++++++++--- lisp/init-python.el | 31 +++++++++++++++++++++++++++++++ recentf | 15 +++++++++------ 6 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 lisp/init-python.el diff --git a/init.el b/init.el index 397e7fe..195d6a8 100644 --- a/init.el +++ b/init.el @@ -32,9 +32,10 @@ (require 'init-llm) - +(require 'init-lsp) (require 'init-coding) (require 'init-org) (require 'init-tex) (require 'init-typst) (require 'init-cc) +(require 'init-python) diff --git a/lisp/init-cc.el b/lisp/init-cc.el index e4f8967..98caca0 100644 --- a/lisp/init-cc.el +++ b/lisp/init-cc.el @@ -2,13 +2,14 @@ (use-package cc-mode :ensure nil - :init (setq-default c-basic-offset 4)) + :init (setq-default c-basic-offset 2)) (when (treesit-available-p) (use-package c-ts-mode + :ensure nil :functions centaur-treesit-available-p :init - (setq c-ts-mode-indent-offset 4) + (setq c-ts-mode-indent-offset 2) (when (boundp 'major-mode-remap-alist) (add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode)) @@ -16,10 +17,10 @@ (add-to-list 'major-mode-remap-alist '(c-or-c++-mode . c-or-c++-ts-mode))))) -(use-package eglot - :hook (c-mode . eglot-ensure) - :hook (c++-mode . eglot-ensure) - :config +(with-eval-after-load 'eglot + (add-hook 'c-ts-mode-hook #'eglot-ensure) + (add-hook 'c++-ts-mode-hook #'eglot-ensure) (add-to-list 'eglot-server-programs '((c++-mode c-mode) "clangd"))) + (provide 'init-cc) diff --git a/lisp/init-completion.el b/lisp/init-completion.el index fddbc4f..eba004f 100644 --- a/lisp/init-completion.el +++ b/lisp/init-completion.el @@ -32,9 +32,9 @@ ;; Optionally use the `orderless' completion style. (use-package orderless :custom - (completion-styles '(orderless basic)) + (completion-styles '(orderless partial-completion basic)) (completion-category-defaults nil) - (completion-category-overrides '((file (styles basic partial-completion)))) + (completion-category-overrides nil) (orderless-component-separator #'orderless-escapable-split-on-space)) ;; Support Pinyin @@ -149,6 +149,23 @@ ;; setting is useful beyond Corfu. (read-extended-command-predicate #'command-completion-default-include-p)) +(use-package cape + :init + ;; Add `completion-at-point-functions', used by `completion-at-point'. + (add-to-list 'completion-at-point-functions #'cape-dabbrev) + (add-to-list 'completion-at-point-functions #'cape-file) + ;;(add-to-list 'completion-at-point-functions #'cape-history) + ;;(add-to-list 'completion-at-point-functions #'cape-keyword) + ;;(add-to-list 'completion-at-point-functions #'cape-tex) + ;;(add-to-list 'completion-at-point-functions #'cape-sgml) + ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345) + ;;(add-to-list 'completion-at-point-functions #'cape-abbrev) + ;;(add-to-list 'completion-at-point-functions #'cape-ispell) + ;;(add-to-list 'completion-at-point-functions #'cape-dict) + ;;(add-to-list 'completion-at-point-functions #'cape-symbol) + ;;(add-to-list 'completion-at-point-functions #'cape-line) + ) + (provide 'init-completion) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/lisp/init-lsp.el b/lisp/init-lsp.el index a337c7d..6594639 100644 --- a/lisp/init-lsp.el +++ b/lisp/init-lsp.el @@ -12,12 +12,18 @@ eglot-send-changes-idle-time 0.5)) (use-package eglot-booster - :after eglot - :config (eglot-booster-mode)) + :ensure (eglot-booster :type git :host nil :repo "https://github.com/jdtsmith/eglot-booster") + :after eglot + :config (eglot-booster-mode)) (use-package consult-eglot :after consult eglot :bind (:map eglot-mode-map - ("C-M-." . consult-eglot-symbols))) + ("C-M-." . consult-eglot-symbols)) + :config + (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster)) + +(with-eval-after-load 'eglot + (setq completion-category-defaults nil)) (provide 'init-lsp) diff --git a/lisp/init-python.el b/lisp/init-python.el new file mode 100644 index 0000000..2faa45d --- /dev/null +++ b/lisp/init-python.el @@ -0,0 +1,31 @@ +;; -*- lexical-binding: t; -*- + +;; Python Mode +;; Install: pip install pyflakes autopep8 +(use-package python + :ensure nil + :functions exec-path-from-shell-copy-env + :hook (inferior-python-mode . (lambda () + (process-query-on-exit-flag + (get-process "Python")))) + :init + ;; Disable readline based native completion + (setq python-shell-completion-native-enable nil) + :config + (add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode)) + ;; Default to Python 3. Prefer the versioned Python binaries since some + ;; systems stupidly make the unversioned one point at Python 2. + (when (and (executable-find "python3") + (string= python-shell-interpreter "python")) + (setq python-shell-interpreter "python3")) + + ;; Env vars + (with-eval-after-load 'exec-path-from-shell + (exec-path-from-shell-copy-env "PYTHONPATH"))) + +(with-eval-after-load 'eglot + (add-hook 'python-ts-mode-hook #'eglot-ensure) + (add-to-list 'eglot-server-programs '((python-mode python-ts-mode) . ("pyright-langserver" "--stdio")))) + + +(provide 'init-python) diff --git a/recentf b/recentf index 5b4b9ed..825693f 100644 --- a/recentf +++ b/recentf @@ -1,11 +1,16 @@ -;;; Automatically generated by ‘recentf’ on Sun Dec 14 23:02:01 2025 -*- mode: emacs-lisp; lexical-binding: t -*- +;;; Automatically generated by ‘recentf’ on Sun Dec 14 23:44:36 2025 -*- mode: emacs-lisp; lexical-binding: t -*- (setq recentf-list '( - "~/.emacs.d/lisp/init-cc.el" - "~/programming/leetcode/2.c" - "~/.emacs.d/lisp/init-lsp.el" + "~/.emacs.d/lisp/a.py" + "~/.emacs.d/lisp/init-python.el" "~/.emacs.d/init.el" + "~/.emacs.d/lisp/init-completion.el" + "~/.emacs.d/lisp/init-lsp.el" + "~/.emacs.d/lisp/init-cc.el" + "~/programming/leetcode/test.cpp" + "~/programming/leetcode/2.c" + "~/.emacs.d/.gitignore" "~/.emacs.d/lisp/init-better-default.el" "~/.emacs.d/url/cookies" "~/.config/fish/config.fish" @@ -16,11 +21,9 @@ "~/.emacs.d/lisp/init-typst.el" "~/build-emacs-for-macos/builds/Emacs.app/Contents/Resources/lisp/loaddefs.el.gz" "~/.config/emacs_bak/doom/config.org" - "~/.emacs.d/.gitignore" "~/.emacs.d/lisp/init-org.el" "~/org/roam/20251212003211-presentation_of_group.org" "~/.emacs.d/lisp/init-tex.el" - "~/.emacs.d/lisp/init-completion.el" "~/.emacs.d/lisp/init-edit.el" "~/org/roam/20251117171745-emacs.org" "~/.emacs.d/lisp/init-ui.el"