diff --git a/custom.el b/custom.el index 4d48980..d96e9f2 100644 --- a/custom.el +++ b/custom.el @@ -9,9 +9,9 @@ dockerfile-mode dumb-jump dumber-jump emacs-lldb exec-path-from-shell flycheck fsharp-mode haskell-mode haskell-ts-mode helm htmlize idris-mode marginalia - markdown-ts-mode multiple-cursors orderless org-mode - parinfer-rust-mode realgud-lldb rg sly terraform-mode - tree-sitter-langs vertico visual-fill-column + markdown-ts-mode multiple-cursors odin-mode orderless + org-mode parinfer-rust-mode realgud-lldb rg sly + terraform-mode tree-sitter-langs vertico visual-fill-column yasnippet-snippets zig-mode)) '(safe-local-variable-directories '("/Users/grant/programming/project/edit/")) '(safe-local-variable-values diff --git a/init.el b/init.el index a5d3be5..edb8124 100644 --- a/init.el +++ b/init.el @@ -11,6 +11,8 @@ ; If startup times are slow ; (setq use-package-verbose t) +(add-to-list 'load-path (concat (file-name-parent-directory user-init-file) "local-lisp/")) + (use-package emacs) (setq tab-bar-show nil) (setq inhibit-startup-message t) @@ -384,5 +386,8 @@ (use-package dockerfile-mode) -(load-file (concat (file-name-parent-directory user-init-file) "odin-mode.el")) -(load-file (concat (file-name-parent-directory user-init-file) "codex.el")) +(use-package odin-mode + :ensure nil) + +(use-package codex + :ensure nil) diff --git a/codex.el b/local-lisp/codex.el similarity index 93% rename from codex.el rename to local-lisp/codex.el index 769ecd0..eef430d 100644 --- a/codex.el +++ b/local-lisp/codex.el @@ -16,6 +16,8 @@ ;; {"type":"item.completed","item":{"id":"item_1","type":"agent_message","text":"Hi! How can I help?"}} ;; {"type":"turn.completed","usage":{"input_tokens":4050,"cached_input_tokens":3712,"output_tokens":13}} +;;; Code: + (require 'json) (require 'cl-lib) (require 'subr-x) @@ -44,6 +46,27 @@ :type 'string :group 'codex) +(defcustom codex-provider nil + "Custom codex provider to use. +Note on Copilot: +In order for copilot integration to work, you need a section in your +~/.codex/config.toml like this: +[model_providers.github-copilot] +name = \"Github Copilot\" +base_url = \"https://api.githubcopilot.com\" +env_key = \"GITHUB_COPILOT_TOKEN\" +wire_api = \"chat\" +http_headers = { + Copilot-Integration-Id = \"vscode-chat\" +}" + :type 'string + :group 'codex) + +(defcustom codex-model nil + "Model for Codex to use." + :type 'string + :group 'codex) + (defcustom codex-skip-git-repo-check t "Whether to pass --skip-git-repo-check to Codex." :type 'boolean @@ -71,17 +94,6 @@ :group 'codex) (defvar codex--session-id nil) -(defvar codex--use-copilot nil - "In order for copilot integration to work, you need a section in your -~/.codex/config.toml like this: -[model_providers.github-copilot] -name = \"Github Copilot\" -base_url = \"https://api.githubcopilot.com\" -env_key = \"GITHUB_COPILOT_TOKEN\" -wire_api = \"chat\" -http_headers = { - Copilot-Integration-Id = \"vscode-chat\" -}") (defvar codex-mode-map (let ((map (make-sparse-keymap))) @@ -95,6 +107,7 @@ http_headers = { ("^User:$" . 'codex-user-prompt-face) ("^Codex:$" . 'codex-assistant-prompt-face))) +;;;###autoload (define-derived-mode codex-mode fundamental-mode "Codex" "Major mode for chatting with Codex." (setq-local buffer-read-only nil) @@ -224,12 +237,14 @@ http_headers = { (message "Using session %s" codex--session-id) (list "resume" codex--session-id)))) (skip (and codex-skip-git-repo-check (list "--skip-git-repo-check"))) - (copilot (and codex--use-copilot (list "-c" "model_provider=github-copilot" "-m" "claude-haiku-4.5"))) - (command (append (list codex-command "exec") resume skip copilot (list "--json" prompt)))) + (provider (and codex-provider (list "-c" (concat "model_provider=" codex-provider)))) + (model (and codex-model (list "-m" codex-model))) + (command (append (list codex-command "exec") resume skip provider model (list "--json" prompt)))) command)))) (set-process-sentinel proc (lambda (p event) + (message event) (when (string= event "finished\n") (with-current-buffer (process-buffer p) (thread-first @@ -238,7 +253,10 @@ http_headers = { codex--format-response codex--write-to-chat) (codex--ensure-session-in-sessions-file prompt) - (kill-buffer))))))) + (kill-buffer))) + (when (string-prefix-p "exited abnormally" event) + (with-current-buffer (process-buffer p) + (error (buffer-string)))))))) (defun codex--get-current-user-prompt () (with-codex-buffer @@ -317,3 +335,8 @@ http_headers = { tup)) sessions))) (codex--write-sessions-file new-sessions))) + +(provide 'codex) + + +;;; codex.el ends here diff --git a/odin-mode.el b/local-lisp/odin-mode.el similarity index 100% rename from odin-mode.el rename to local-lisp/odin-mode.el