-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
**Title**: Implement Functions to Extract and Handle Code from Markdown in Vim #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,31 @@ class GPTPlugin: | |
def __init__(self, nvim): | ||
self.nvim = nvim | ||
|
||
@pynvim.function("ExtractCodeFromMarkdown", sync=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding error handling for invalid register names and a docstring explaining the function's purpose and parameters. For example: @pynvim.function("ExtractCodeFromMarkdown", sync=True)
def extract_code_from_markdown(self, args):
"""Extract code blocks from markdown and store in a vim register.
Args:
args: List containing optional register name. Defaults to '"'.
"""
if not args:
register = '"'
elif not isinstance(args[0], str) or len(args[0]) != 1:
self.nvim.command('echoerr "Register must be a single character"')
return
else:
register = args[0] |
||
def extract_code_from_markdown(self, args): | ||
register = args[0] if args else '"' | ||
lines = self.nvim.current.buffer[:] | ||
code_block = [] | ||
in_code_block = False | ||
for line in lines: | ||
if line.strip() == '```': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation doesn't handle language specifiers in code blocks. Consider updating this to handle cases like ```python: if line.strip().startswith('```'):
in_code_block = not in_code_block
continue |
||
in_code_block = not in_code_block | ||
continue | ||
if in_code_block: | ||
code_block.append(line) | ||
if code_block: | ||
self.nvim.command(f'let @{register} = "{chr(10).join(code_block)}"') | ||
else: | ||
self.nvim.command('echo "No markdown code block found"') | ||
|
||
@pynvim.function("PasteCodeToNewFile", sync=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hardcoded filename 'llm_code.py' assumes Python code. Consider:
For example: @pynvim.function("PasteCodeToNewFile", sync=True)
def paste_code_to_new_file(self, args):
"""Paste code from a register into a new file.
Args:
args: List containing [register, filename]. Both optional.
register defaults to '"', filename defaults to 'llm_code.py'
"""
register = args[0] if len(args) > 0 else '"'
filename = args[1] if len(args) > 1 else 'llm_code.py'
self.nvim.command('enew') # Open a new buffer
self.nvim.command(f'put @{register}') # Paste contents of the register
self.nvim.command(f'write {filename}') # Save the file
self.nvim.command(f'echo "Code block saved to {filename}"') |
||
def paste_code_to_new_file(self, args): | ||
register = args[0] if args else '"' | ||
self.nvim.command('enew') # Open a new buffer | ||
self.nvim.command(f'put @{register}') # Paste contents of the register | ||
self.nvim.command('write llm_code.py') # Save the file | ||
self.nvim.command('echo "Code block saved to llm_code.py"') | ||
|
||
|
||
@pynvim.function("GPTResponse") | ||
def gpt_response(self, args): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Can you reply with a joke?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Why do programmers prefer dark mode? Because light attracts bugs! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, can you reply with another! @mentat-butler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Why do Java developers wear glasses? Because they don't see sharp! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you tell me another @MentatBot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly! Here's another programming joke for you:
Why do programmers always mix up Halloween and Christmas?
Because Oct 31 == Dec 25! 😄
This joke plays on the fact that in octal (base 8) notation, 31 is equal to 25 in decimal (base 10). It's a bit of a nerdy one, but I hope you find it amusing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you enjoyed the jokes! Here's one more for you:
Why do programmers prefer iOS development? Because it's a Swift process! 😄
This joke plays on the double meaning of 'Swift' - both as a programming language used for iOS development and as an adjective meaning 'quick' or 'fast'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you enjoyed the jokes! Here's one more for you:
Why do programmers prefer iOS development? Because it's a Swift process! 😄
This joke plays on the double meaning of 'Swift' - both as a programming language used for iOS development and as an adjective meaning 'quick' or 'fast'.