diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-20 12:25:57 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-20 12:25:57 -0400 |
| commit | f704ca0fb844155908121680f1ad12201b46761c (patch) | |
| tree | ab7fb9d9707d098f715861e9a38584ed2575048c /modules | |
| parent | 4f3bc95173b5e90a926310b8b5bb0a6049b826eb (diff) | |
| download | dotemacs-f704ca0fb844155908121680f1ad12201b46761c.tar.gz dotemacs-f704ca0fb844155908121680f1ad12201b46761c.zip | |
refactor(ai-config): extract gptel model-apply step, drop dead branch
cj/gptel-change-model applied the selection inline (scope dispatch + message) and re-checked (stringp model) on a value already interned to a symbol. Extract cj/--gptel-apply-model-selection (scope backend model backend-name), which sets the vars globally or buffer-locally and returns the message; the dead stringp branch is gone. Adds direct coverage of both scopes.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/ai-config.el | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el index 20bf6ec8..97af1296 100644 --- a/modules/ai-config.el +++ b/modules/ai-config.el @@ -233,6 +233,20 @@ Returns a string like \"Anthropic - Claude: claude-opus-4-7\"." (or backend-name "AI") (cj/gptel--model-to-string current-model)))) +(defun cj/--gptel-apply-model-selection (scope backend model backend-name) + "Set gptel BACKEND and MODEL, globally or buffer-locally per SCOPE. +SCOPE is \"global\" or \"buffer\"; any non-\"global\" value is buffer-local. +MODEL is a symbol. BACKEND-NAME is the display name for the confirmation. +Returns the confirmation message string." + (if (string= scope "global") + (progn + (setq gptel-backend backend) + (setq gptel-model model) + (format "Changed to %s model: %s (global)" backend-name model)) + (setq-local gptel-backend backend) + (setq-local gptel-model model) + (format "Changed to %s model: %s (buffer-local)" backend-name model))) + ;; Backend/model switching commands (defun cj/gptel-change-model () "Change the GPTel backend and select a model from that backend. @@ -257,14 +271,8 @@ necessary. Prompt for whether to apply the selection globally or buffer-locally. (backend (nth 1 model-info)) (model (intern (nth 2 model-info))) (backend-name (nth 3 model-info))) - (if (string= scope "global") - (progn - (setq gptel-backend backend) - (setq gptel-model model) - (message "Changed to %s model: %s (global)" backend-name model)) - (setq-local gptel-backend backend) - (setq-local gptel-model (if (stringp model) (intern model) model)) - (message "Changed to %s model: %s (buffer-local)" backend-name model))))) + (message "%s" (cj/--gptel-apply-model-selection + scope backend model backend-name))))) (defun cj/gptel-switch-backend () "Switch the GPTel backend and then choose one of its models." |
