commit 379f40eec33fc8e0e22139bc16ad566aa0a5079a Author: Wong Ding Feng Date: Sun Jul 20 22:51:50 2025 +0800 update diff --git a/config.el b/config.el new file mode 100644 index 0000000..6853d4b --- /dev/null +++ b/config.el @@ -0,0 +1,320 @@ +;;; $DOOMDIR/config.el -*- lexical-binding: t; -*- + +(setq doom-theme 'doom-one) + +(setq display-line-numbers-type t) + +(setq org-directory "~/org/") + +(defun load-if-exists (f) + (if (file-exists-p (expand-file-name f)) + (load-file (expand-file-name f)))) + +(load-if-exists "~/.config/doom/secrets.el") + +(after! epa-file + (setq epa-file-encrypt-to "dingfengwong@gmail.com")) + +(after! auth-source + (setq auth-sources '("~/.authinfo.gpg"))) + +(setq epa-file-cache-passphrase-for-symmetric-encryption t) + +(use-package! super-save + :config + (super-save-mode +1) + (setq super-save-auto-save-when-idle t) + (setq super-save-idle-duration 1)) + + +;; Search bindings for consult-line +(map! + :n "C-s" (lambda () (interactive) (consult-line (thing-at-point 'symbol))) + :n "M-S" #'consult-line + :n "C-S-s" #'consult-line-multi) + +(after! lsp-ui + (setq lsp-ui-doc-include-signature t ;; Show method signatures in docs + lsp-ui-sideline-show-symbol t ;; Show symbols in the sideline + lsp-ui-doc-show-with-cursor t ;; Show docs when cursor is on symbol + lsp-ui-doc-max-height 30 ;; Increase doc height to show more info + lsp-ui-sideline-show-hover t ;; Show hover information in sideline + lsp-ui-doc-enable t ;; Enable documentation + lsp-signature-auto-activate t ;; Show signature help automatically + lsp-signature-render-documentation t)) ;; Include docs in signature help + +(after! eldoc + (setq eldoc-echo-area-use-multiline-p t + eldoc-echo-area-prefer-doc-buffer t)) + +(use-package! corfu-popupinfo + :after corfu + :hook (corfu-mode . corfu-popupinfo-mode) + :custom + (corfu-popupinfo-delay '(0.25 . 0.1)) ; Faster popup display + (corfu-popupinfo-hide nil) ; Don't hide automatically + ) + +;; Configure Corfu for richer display +(after! corfu + (setq corfu-auto t ; Enable auto completion + corfu-auto-prefix 2 ; Complete after 2 characters + corfu-preview-current t ; Preview current candidate + corfu-show-documentation t ; Show documentation in popup + corfu-doc-max-height 20 ; Max height for doc popup + corfu-doc-delay 0.2 ; Faster doc popup + corfu-quit-no-match t) ; Quit if no match + + ;; Show more detailed annotations + (setq corfu-show-annotations t + corfu-annotate-max-width 50)) + +;; If using LSP, configure to show more details +(after! lsp-mode + (setq lsp-completion-show-detail t ; Show method signatures + lsp-completion-show-kind t ; Show completion item kind + lsp-completion-show-label-description t ; Show more details in label + )) + +(after! lsp-haskell + (setq lsp-haskell-plugin-fourmolu-config-path "fourmolu -o -XImportQualifiedPost -o -XOverloadedStrings -o -XTypeApplications -o -XScopedTypeVariables -o -XGADTs -o -XDataKinds -o -XTypeFamilies -o -XFlexibleContexts -o -XFlexibleInstances -o -XMultiParamTypeClasses -o -XRankNTypes -o -XExistentialQuantification") + ) + + +(defun +org--restart-mode-h () + "Restart `org-mode', but only once." + (remove-hook 'doom-switch-buffer-hook #'+org--restart-mode-h + 'local) + (delq! (current-buffer) org-agenda-new-buffers) + (let ((file buffer-file-name) + (old-buffer (current-buffer)) + (inhibit-redisplay t) + new-buffer) + (kill-buffer) + (setq new-buffer (find-file file)) + (unless (buffer-live-p old-buffer) + (make-indirect-buffer new-buffer old-buffer 'clone)))) + +(defun +org--restart-mode-h () + "Restart `org-mode', but only once." + (remove-hook 'doom-switch-buffer-hook #'+org--restart-mode-h + 'local) + (delq! (current-buffer) org-agenda-new-buffers) + (let ((file buffer-file-name) + (inhibit-redisplay t)) + (kill-buffer) + (find-file file))) +(defun +org--restart-mode-h () + "Restart `org-mode', but only once." + (remove-hook 'doom-switch-buffer-hook #'+org--restart-mode-h 'local) + (quiet! (org-mode-restart)) + (delq! (current-buffer) org-agenda-new-buffers) + (run-hooks 'find-file-hook)) + +(add-hook! 'org-agenda-finalize-hook + (defun +org-exclude-agenda-buffers-from-workspace-h () + "Don't associate temporary agenda buffers with current workspace." + (when (and org-agenda-new-buffers + (bound-and-true-p persp-mode) + (not org-agenda-sticky)) + (let (persp-autokill-buffer-on-remove) + (persp-remove-buffer org-agenda-new-buffers + (get-current-persp) + nil))))) + + +(use-package org + :defer t + :config + (defalias '+org--restart-mode-h #'ignore)) + +(advice-add #'org-capture :around + (lambda (fun &rest args) + (letf! ((#'+org--restart-mode-h #'ignore)) + (apply fun args)))) + +;;(use-package! org-roam +;; :after org +;; :config +;; :init +;; (setq org-roam-directory "~/org/roam") ; No file-truename needed in Doom +;; :config +;; (advice-remove 'org-roam-db-query '+org-roam-try-init-db-a) +;; (org-roam-db-autosync-mode) +;; (setq org-roam-completion-everywhere t)) + + ; (use-package! org-roam + ; :custom + ; (org-roam-directory "~/org/roam") + ; (org-roam-completion-everywhere t) + ; (org-roam-capture-templates + ; '(("d" "default" plain + ; "%?" + ; :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" + ; "#+title: ${title}\n") + ; :unnarrowed t) + ; ("r" "reference" plain + ; "%?" + ; :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" + ; "#+title: ${title}\n#+filetags: :reference:\n") + ; :unnarrowed t) + ; ("p" "project" plain + ; "\n* Goals\n\n%?\n\n* Tasks\n\n* Notes\n\n" + ; :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" + ; "#+title: ${title}\n#+filetags: :project:\n") + ; :unnarrowed t))) + ; :config + ; (org-roam-setup) + ; ;; If using org-roam-protocol + ; (require 'org-roam-protocol)) + +(after! org + (require 'org-re-reveal) + (setq org-re-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js") + (setq org-re-reveal-theme "white") + (setq org-re-reveal-transition "slide")) + +(after! org + (require 'org-tempo) + (add-to-list 'org-structure-template-alist '("n" . "notes"))) + +(use-package! anki-editor + :after org + :config + (setq anki-editor-create-decks t) + :bind (:map org-mode-map + ("C-c a" . anki-editor-push-notes))) + +(use-package! org-anki + :after org + :config + (setq org-anki-default-deck "Default") + :bind (:map org-mode-map + ("C-c n" . org-anki-sync-entry))) + +(setq-default show-trailing-whitespace t) + +(use-package! bnf-mode + :mode "\\.bnf\\'" + :config + ;; Optional: Add any custom configuration here + (setq bnf-mode-hook + (lambda () + ;; Enable line numbers + (display-line-numbers-mode) + ;; Enable auto-pairing of angle brackets + (modify-syntax-entry ?< "(>" bnf-mode-syntax-table) + (modify-syntax-entry ?> ")<" bnf-mode-syntax-table)))) + +(use-package! ebnf-mode + :mode "\\.ebnf\\'" + :config + ;; Optional customizations: + (setq ebnf-mode-indent-offset 4) ; Default is 8 spaces + (setq ebnf-mode-indent-by-production t) ; Align with the '=' in productions + (setq ebnf-mode-comment-char ?\;) ; Use ; for comments + (setq ebnf-mode-eop-char ?\.)) ; Use . for end of production + +(use-package! nix-mode + :mode "\\.nix\\'" + :config + ;; Function to check if we're in a nixpkgs repository + (defun in-nixpkgs-repo-p () + (when-let ((root (or (locate-dominating-file default-directory ".git") + (vc-root-dir)))) + (or (string-match-p "/nixpkgs/?$" root) + (file-exists-p (expand-file-name "pkgs/top-level/all-packages.nix" root)) + (file-exists-p (expand-file-name ".nixpkgs-version.json" root))))) + + ;; Set up format-all-mode to use our custom formatter selection + (set-formatter! 'nixfmt + '("nixfmt") + :modes '(nix-mode)) + + (set-formatter! 'alejandra + '("alejandra" "--quiet") + :modes '(nix-mode)) + + ;; Add hooks to handle all formatting scenarios + (add-hook! 'nix-mode-hook + ;; Disable LSP formatting + (setq-local +format-with-lsp nil) + + ;; Set formatter for format-all-mode (+format/buffer) + (setq-local +format-with + (if (in-nixpkgs-repo-p) + 'nixfmt + 'alejandra)) + + ;; Handle format-on-save + (when (bound-and-true-p format-all-mode) + (format-all-mode -1)) + (add-hook! 'before-save-hook :local + (when (eq major-mode 'nix-mode) + (if (in-nixpkgs-repo-p) + (format-all-buffer 'nixfmt) + (format-all-buffer 'alejandra)))) + + ;; Override lsp-format-buffer + (advice-add 'lsp-format-buffer :around + (lambda (orig-fun &rest args) + (if (eq major-mode 'nix-mode) + (if (in-nixpkgs-repo-p) + (format-all-buffer 'nixfmt) + (format-all-buffer 'alejandra)) + (apply orig-fun args)))))) + +;; Enable format-on-save globally if desired +(setq +format-on-save-enabled-modes '(nix-mode)) + +(use-package! llvm-ts-mode + :mode "\\.ll\\'" ; LLVM IR files + :mode "\\.td\\'" ; TableGen files + :hook (llvm-ts-mode . tree-sitter-mode)) + +(after! tree-sitter + (add-to-list 'tree-sitter-major-mode-language-alist '(llvm-ts-mode . llvm))) + +(after! lsp-clangd + (setq lsp-clients-clangd-executable "clangd") + (setq lsp-clients--clangd-default-executable "clangd") + (setq lsp-clangd-binary-path "clangd")) + +(after! org + (use-package! ob-mermaid + :config + (setq ob-mermaid-cli-path "mmdc")) ; Adjust path if needed + + ;; Add mermaid to org-babel languages + (org-babel-do-load-languages + 'org-babel-load-languages + (append org-babel-load-languages + '((mermaid . t))))) + +(after! org + (setq-default org-download-image-dir "./images") + + (defun my/org-download-image-dir-setup () + "Create and set org-download-image-dir relative to current org file." + (let* ((current-file-dir (file-name-directory (buffer-file-name))) + (image-dir (expand-file-name "images" current-file-dir))) + (make-directory image-dir t) + (setq-local org-download-image-dir image-dir))) + + (add-hook 'org-mode-hook #'my/org-download-image-dir-setup) + (setq org-download-link-format "[[file:%s]]\n") + (setq org-download-timestamp "%Y%m%d-%H%M%S_") + (setq org-download-screenshot-method "maim -s %s") + ) + +(setq gptel-model 'mixtral-8x7b-32768 + gptel-backend + (gptel-make-openai "OpenRouter" ;Any name you want + :host "openrouter.ai" + :endpoint "/api/v1/chat/completions" + :stream t + :key "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" ;can be a function that returns the key + :models '(google/gemini-2.5-flash-preview-05-20 + google/gemini-2.5-flash-preview-05-20:thinking + anthropic/claude-sonnet-4 + ))) diff --git a/init.el b/init.el new file mode 100644 index 0000000..57b463e --- /dev/null +++ b/init.el @@ -0,0 +1,210 @@ +;;; init.el -*- lexical-binding: t; -*- + +;; This file controls what Doom modules are enabled and what order they load +;; in. Remember to run 'doom sync' after modifying it! + +;; NOTE Press 'SPC h d h' (or 'C-h d h' for non-vim users) to access Doom's +;; documentation. There you'll find a link to Doom's Module Index where all +;; of our modules are listed, including what flags they support. + +;; NOTE Move your cursor over a module's name (or its flags) and press 'K' (or +;; 'C-c c k' for non-vim users) to view its documentation. This works on +;; flags as well (those symbols that start with a plus). +;; +;; Alternatively, press 'gd' (or 'C-c c d') on a module to browse its +;; directory (for easy access to its source code). + +(doom! :input + ;;bidi ; (tfel ot) thgir etirw uoy gnipleh + ;;chinese + ;;japanese + ;;layout ; auie,ctsrnm is the superior home row + + :completion + ;;company ; the ultimate code completion backend + (corfu +orderless) ; complete with cap(f), cape and a flying feather! + ;;helm ; the *other* search engine for love and life + ;;ido ; the other *other* search engine... + ;;ivy ; a search engine for love and life + vertico ; the search engine of the future + + :ui + deft ; notational velocity for Emacs + doom ; what makes DOOM look the way it does + doom-dashboard ; a nifty splash screen for Emacs + ;;doom-quit ; DOOM quit-message prompts when you quit Emacs + ;;(emoji +unicode) ; 🙂 + hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW + indent-guides ; highlighted indent columns + ;;ligatures ; ligatures and symbols to make your code pretty again + ;;minimap ; show a map of the code on the side + modeline ; snazzy, Atom-inspired modeline, plus API + ;;nav-flash ; blink cursor line after big motions + ;;neotree ; a project drawer, like NERDTree for vim + ophints ; highlight the region an operation acts on + (popup +defaults) ; tame sudden yet inevitable temporary windows + ;;tabs ; a tab bar for Emacs + treemacs ; a project drawer, like neotree but cooler + ;;unicode ; extended unicode support for various languages + (vc-gutter +pretty) ; vcs diff in the fringe + vi-tilde-fringe ; fringe tildes to mark beyond EOB + window-select ; visually switch windows + workspaces ; tab emulation, persistence & separate workspaces + zen ; distraction-free coding or writing + + :editor + (evil +everywhere); come to the dark side, we have cookies + file-templates ; auto-snippets for empty files + fold ; (nigh) universal code folding + (format +onsave) ; automated prettiness + ;;god ; run Emacs commands without modifier keys + ;;lispy ; vim for lisp, for people who don't like vim + multiple-cursors ; editing in many places at once + ;;objed ; text object editing for the innocent + ;;parinfer ; turn lisp into python, sort of + ;;rotate-text ; cycle region at point between text candidates + snippets ; my elves. They type so I don't have to + ;;word-wrap ; soft wrapping with language-aware indent + + :emacs + dired ; making dired pretty [functional] + electric ; smarter, keyword-based electric-indent + ;;eww ; the internet is gross + ibuffer ; interactive buffer management + undo ; persistent, smarter undo for your inevitable mistakes + vc ; version-control and Emacs, sitting in a tree + + :term + eshell ; the elisp shell that works everywhere + ;;shell ; simple shell REPL for Emacs + ;;term ; basic terminal emulator for Emacs + ;;vterm ; the best terminal emulation in Emacs + + :checkers + syntax ; tasing you for every semicolon you forget + (spell +flyspell) ; tasing you for misspelling mispelling + grammar ; tasing grammar mistake every you make + + :tools + ;;ansible + ;;biblio ; Writes a PhD for you (citation needed) + collab ; buffers with friends + debugger ; FIXME stepping through code, to help you add bugs + direnv + docker + editorconfig ; let someone else argue about tabs vs spaces + ;;ein ; tame Jupyter notebooks with emacs + (eval +overlay) ; run code, run (also, repls) + lookup ; navigate your code and its documentation + (lsp +peek) ; M-x vscode + magit ; a g porcelain for Emacs + make ; run make tasks from Emacs + pass ; password manager for nerds + pdf ; pdf enhancements + ;;prodigy ; FIXME managing external services & code builders + ;;terraform ; infrastructure as code + ;;tmux ; an API for interacting with tmux + tree-sitter ; syntax and parsing, sitting in a tree... + ;;upload ; map local to remote projects via ssh/ftp + + :os + (:if (featurep :system 'macos) macos) ; improve compatibility with macOS + tty ; improve the terminal Emacs experience + + :lang + ;;agda ; types of types of types of types... + ;;beancount ; mind the GAAP + (cc +lsp) ; C > C++ == 1 + ;;clojure ; java with a lisp + ;;common-lisp ; if you've seen one lisp, you've seen them all + ;;coq ; proofs-as-programs + ;;crystal ; ruby at the speed of c + ;;csharp ; unity, .NET, and mono shenanigans + data ; config/data formats + ;;(dart +flutter) ; paint ui and not much else + ;;dhall + ;;elixir ; erlang done right + ;;elm ; care for a cup of TEA? + emacs-lisp ; drown in parentheses + ;;erlang ; an elegant language for a more civilized age + ;;ess ; emacs speaks statistics + ;;factor + ;;faust ; dsp, but you get to keep your soul + ;;fortran ; in FORTRAN, GOD is REAL (unless declared INTEGER) + ;;fsharp ; ML stands for Microsoft's Language + ;;fstar ; (dependent) types and (monadic) effects and Z3 + ;;gdscript ; the language you waited for + (go +lsp) ; the hipster dialect + (graphql +lsp) ; Give queries a REST + (haskell +lsp +tree-sitter) ; a language that's lazier than I am + ;;hy ; readability of scheme w/ speed of python + ;;idris ; a language you can depend on + json ; At least it ain't XML + (java +lsp) ; the poster child for carpal tunnel syndrome + javascript ; all(hope(abandon(ye(who(enter(here)))))) + ;;julia ; a better, faster MATLAB + ;;kotlin ; a better, slicker Java(Script) + ;;latex ; writing papers in Emacs has never been so fun + ;;lean ; for folks with too much to prove + ;;ledger ; be audit you can be + ;;lua ; one-based indices? one-based indices + markdown ; writing docs for people to ignore + ;;nim ; python + lisp at the speed of c + nix ; I hereby declare "nix geht mehr!" + ;;ocaml ; an objective camel + (org +brain + +contacts + +crypt + +dragndrop + +gnuplot + +hugo + +journal + +jupyter + +link + +noter + +pandoc + +passwords + +pomodoro + +present + +pretty + +priorities + +roam2 + ) ; organize your plain life in plain text + ;;php ; perl's insecure younger brother + plantuml ; diagrams for confusing people more + graphviz ; diagrams for confusing yourself even more + ;;purescript ; javascript, but functional + (python +lsp +pyright) ; beautiful is better than ugly + ;;qt ; the 'cutest' gui framework ever + ;;racket ; a DSL for DSLs + ;;raku ; the artist formerly known as perl6 + ;;rest ; Emacs as a REST client + ;;rst ; ReST in peace + ;;(ruby +rails) ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"} + (rust +lsp) ; Fe2O3.unwrap().unwrap().unwrap().unwrap() + ;;scala ; java, but good + ;;(scheme +guile) ; a fully conniving family of lisps + sh ; she sells {ba,z,fi}sh shells on the C xor + ;;sml + ;;solidity ; do you need a blockchain? No. + ;;swift ; who asked for emoji variables? + ;;terra ; Earth and Moon in alignment for performance. + web ; the tubes + yaml ; JSON, but readable + zig ; C, but simpler + + :email + (mu4e +org +gmail) + ;;notmuch + ;;(wanderlust +gmail) + + :app + ;;calendar + ;;emms + ;;everywhere ; *leave* Emacs!? You must be joking + ;;irc ; how neckbeards socialize + ;;(rss +org) ; emacs as an RSS reader + + :config + ;;literate + (default +bindings +smartparens)) diff --git a/packages.el b/packages.el new file mode 100644 index 0000000..756d372 --- /dev/null +++ b/packages.el @@ -0,0 +1,31 @@ +;; -*- no-byte-compile: t; -*- +;;; $DOOMDIR/packages.el + +(package! super-save) + +(package! gptel) + +(package! org-re-reveal) + +(package! copilot + :recipe (:host github :repo "copilot-emacs/copilot.el" :files ("*.el"))) + +(package! anki-editor + :recipe (:host github :repo "anki-editor/anki-editor")) + +(package! org-anki + :recipe (:host github :repo "eyeinsky/org-anki")) + +(package! bnf-mode + :recipe (:host github + :repo "sergeyklay/bnf-mode" + :files ("*.el"))) + +(package! ebnf-mode :recipe (:host github :repo "nverno/ebnf-mode")) + +(package! llvm-ts-mode + :recipe (:host github :repo "nverno/llvm-ts-mode")) + +(package! tree-sitter-langs) + +(package! ob-mermaid)