From 1900bf0f72f6864371b34ae87e4245be8629bf94 Mon Sep 17 00:00:00 2001 From: Jiri Jakes Date: Sat, 25 Apr 2026 15:09:47 +0800 Subject: [PATCH] Copy whole object --- nano-gpt-status.el | 19 +++++++++++++------ ppq-status.el | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/nano-gpt-status.el b/nano-gpt-status.el index 94dfd1c..ab48683 100644 --- a/nano-gpt-status.el +++ b/nano-gpt-status.el @@ -285,16 +285,23 @@ (let ((map (make-sparse-keymap))) (set-keymap-parent map tabulated-list-mode-map) (define-key map "q" #'nano-gpt-quit) - (define-key map "w" #'nano-gpt-models-copy-id) + (define-key map "w" #'nano-gpt-models-copy-nix-entry) map)) -(defun nano-gpt-models-copy-id () - "Copy the ID of the current model to clipboard." +(defun nano-gpt-models-copy-nix-entry () + "Copy the current model as a Nix attribute set to clipboard." (interactive) (when tabulated-list-entries - (let* ((entry (tabulated-list-get-entry)) - (id (aref entry 1))) - (kill-new id) + (let* ((id (tabulated-list-get-id)) + (model (seq-find (lambda (m) (equal (nano-gpt--aget m 'id) id)) + nano-gpt--models-data)) + (name (nano-gpt--aget model 'name)) + (pricing (nano-gpt--aget model 'pricing)) + (input-price (or (nano-gpt--aget pricing 'prompt) 0)) + (output-price (or (nano-gpt--aget pricing 'completion) 0)) + (nix-str (format " \"%s\" = {\n name = \"%s\";\n cost = [%s %s];\n };" + id name (or input-price 0) (or output-price 0)))) + (kill-new nix-str) (message "Copied: %s" id)))) (define-derived-mode nano-gpt-models-mode tabulated-list-mode "Models" diff --git a/ppq-status.el b/ppq-status.el index 13b72b7..855eede 100644 --- a/ppq-status.el +++ b/ppq-status.el @@ -373,16 +373,23 @@ PROJECT-NAME is the display name for the project." (let ((map (make-sparse-keymap))) (set-keymap-parent map tabulated-list-mode-map) (define-key map "q" #'ppq-quit) - (define-key map "w" #'ppq-models-copy-id) + (define-key map "w" #'ppq-models-copy-nix-entry) map)) -(defun ppq-models-copy-id () - "Copy the ID of the current model to clipboard." +(defun ppq-models-copy-nix-entry () + "Copy the current model as a Nix attribute set to clipboard." (interactive) (when tabulated-list-entries - (let* ((entry (tabulated-list-get-entry)) - (id (aref entry 1))) - (kill-new id) + (let* ((id (tabulated-list-get-id)) + (model (seq-find (lambda (m) (equal (ppq--aget m 'id) id)) + ppq--models-data)) + (name (ppq--aget model 'name)) + (pricing (ppq--aget model 'pricing)) + (input-price (or (ppq--aget pricing 'input_per_1M_tokens) 0)) + (output-price (or (ppq--aget pricing 'output_per_1M_tokens) 0)) + (nix-str (format " \"%s\" = {\n name = \"%s\";\n cost = [%s %s];\n };" + id name (or input-price 0) (or output-price 0)))) + (kill-new nix-str) (message "Copied: %s" id)))) (defun ppq--format-created-at (epoch-ms)