use local vars
authorRobin Krens <robin@robinkrens.nl>
Thu, 2 Jan 2025 14:32:54 +0000 (15:32 +0100)
committerRobin Krens <robin@robinkrens.nl>
Thu, 2 Jan 2025 14:32:54 +0000 (15:32 +0100)
claudy.vim

index 2b8fe1e..ab39d57 100644 (file)
@@ -52,27 +52,30 @@ function! ClaudyRefactor(user_prompt)
     
     let l:start_line = line("'<")
     let l:end_line = line("'>")
-    let selected_text = a:user_prompt . shellescape(join(getline(l:start_line, l:end_line)))
+    let l:selected_text = a:user_prompt . shellescape(join(getline(l:start_line, l:end_line)))
 
-    let system_prompt = "reply with one C function (do not implement other functions) code should be able to copied right into an editor, no explaining text"
+    let l:system_prompt = "detect programming language, reply with one function (do not implement other functions) code should be able to copied right into an editor, no explaining text, start always with ```c and end with ```"
 
     " Prepare the JSON payload
-    let json_data = {
+    let l:json_data = {
         \ 'model': 'claude-3-5-sonnet-20241022',
         \ 'max_tokens': 1024,
-       \ 'system': system_prompt,
+       \ 'system': l:system_prompt,
         \ 'messages': [
         \   {
         \     'role': 'user',
-        \     'content': selected_text
+        \     'content': l:selected_text
         \   }
         \ ]
     \ }
 
-    let refactored_code = ClaudyRequest(json_data)
+    let l:refactored_code = ClaudyRequest(l:json_data)
     vnew
-    put =refactored_code
+    setlocal syntax=c
+    setlocal buftype=nofile
+    put =l:refactored_code
 endfunction
 
 vnoremap <leader>c :<c-u>call ClaudyRefactor()
 vnoremap <leader>i :<c-u>call ClaudyImplement()
+vnoremap <leader>b :<c-u>call ClaudyTest()