Copy whole object

This commit is contained in:
Jiri Jakes 2026-04-25 15:09:47 +08:00
parent a88e8fe7d6
commit 1900bf0f72
2 changed files with 26 additions and 12 deletions

View file

@ -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"