Skip to content
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

offer markdown highlighting in aichat files #83

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Konfekt
Copy link
Contributor

@Konfekt Konfekt commented Mar 8, 2024

Markdown highlighting within aichat files is controlled by a global variable g:aichat_markdown.

The Vim documentation and the syntax file for aichat have been updated. Markdown highlighting is disabled by default when editing .aichat files, but can be enabled by a user variable.

Markdown highlighting within aichat files is controlled by
a global variable `g:aichat_markdown`.

The Vim documentation and the syntax file for aichat have been updated. Markdown
highlighting is disabled by default when editing .aichat files,
but can be enabled by a user variable.
@madox2
Copy link
Owner

madox2 commented Mar 9, 2024

What is the motivation behind this feature? Enabling full markdown got into conflict with the current aichat file highlighting:
image

@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 9, 2024

The output is often markdown with code in codeblock. For highlighting, including codeblocks, just reuse that of markdown.vim and add the vim-ai specificities (for prompt markers).
Is in the screenshot code_syntax_enabled = 1 set ?

@madox2
Copy link
Owner

madox2 commented Mar 9, 2024

Yes, the screenshot is taken with code_syntax_enabled = 1. To problem is that markdown is applied to the whole file, not just to the fenced replies.

@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 9, 2024

Yes. What is the correct syntax highlighting for the user input?

One could explicitly override it, but in practice it is often simple text.

This is just a suggestion that seems more maintainable than the ftplugin/aichat.vim with the added benefit of highlighting the markdown output itself (and not only the code blocks).

@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 9, 2024

Regarding the correct highlighting of the user input, an idea could have been to add code fence markers for the current file type, except for text selected in a comment syntax region. However, in the end, users might rather (ab)use the source code file as a scratchpad for sending text into the chat, so that this assumption is perhaps a bit patronizing.

@madox2
Copy link
Owner

madox2 commented Mar 9, 2024

I am not sure is syntax highlighting of the user input is needed. If you for instance use ChatGPT on web, you cannot use formatting your prompt. And it wouldn't make any difference to the model too. I would say formatting code blocks should be enough but I might be wrong

@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 9, 2024

I am not sure is syntax highlighting of the user input is needed.

I agree with you.
Markdown highlighting was meant to highlight the output, not input, since the output is often markdown.
One can define a user input region to drop syntax highlighting there.

diff --git a/syntax/aichat.vim b/syntax/aichat.vim:
-syntax region myRegion start=/>>>.*$\zs/ end=/\ze<<<.*$/
-highlight default link myRegion Normal
-
@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 10, 2024

User input is now using default highlighting, whereas the output uses built-in markdown highlighting, in particular for the fenced code blocks.
Since (ChatGPT's) output often uses markdown formatting, this (if g:aichat_markdown is set) improves readability and adds highlighting for programming languages not contained in s:filetype_dict in ftplugin/aichat.vim (line 12):

screenshot-2024-03-10-085151
in contrast to
screenshot-2024-03-10_085255

@madox2
Copy link
Owner

madox2 commented Mar 24, 2024

Still having the same issue (see screenshot in the comments above). I think you tried to fix it with >>> <<<, that that' boundary isn't respected in my environment

@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 24, 2024

This is somewhat to be expected, as I had the impression that code_syntax_enabled = 1 replicates what g:markdown_fenced_languages= ['cpp', 'vim', 'sh', 'dosini', 'javascript', 'javascriptreact', 'typescript', 'typescriptreact'] would achieve, and therefore becomes dispensable. But I might be completely wrong, as I rarely used fenced highlighting, and there's a point in making both settings work at the same time?

@madox2
Copy link
Owner

madox2 commented Mar 24, 2024

Yes, I think that this solution is much better and I would like to replace the current highlighting with this one. But first I need to get this working. I have found that there is a conflict with the plugin preservim/vim-markdown that I use, which causes the weird highlighting I posted in the screenshot.

@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 24, 2024

Hard to say from afar, but https://github.com/preservim/vim-markdown/blob/a657e697376909c41475a686eeef7fc7a4972d94/ftplugin/markdown.vim#L789 shows that this also does what the built-in markdown ftplugin tries to achieve, so a careful setup is needed to avoid mutual interference

@Konfekt
Copy link
Contributor Author

Konfekt commented Mar 26, 2024

Maybe this way around the highlighting is more robust?

dargor added a commit to dargor/dotfiles that referenced this pull request Jul 19, 2024
See madox2/vim-ai#83

Signed-off-by: Gabriel Linder <linder.gabriel@gmail.com>
@dargor
Copy link

dargor commented Jul 19, 2024

I came here wanting to do the same thing, thanks for your diff it works flawlessly for me !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants