aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-20 12:25:57 -0400
committerCraig Jennings <c@cjennings.net>2026-06-20 12:25:57 -0400
commit098d3a0dc2fbeeb296433be68f980708e1670dc3 (patch)
treef2583ccb18ed30cd415948214f7108e3a59536b5 /modules
parent55ca0d6f157e34372fe21539551bee797056d906 (diff)
downloaddotemacs-098d3a0dc2fbeeb296433be68f980708e1670dc3.tar.gz
dotemacs-098d3a0dc2fbeeb296433be68f980708e1670dc3.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.el24
1 files changed, 16 insertions, 8 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el
index 20bf6ec88..97af1296d 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."