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

Extend to other markup languages #56

Merged
merged 3 commits into from
Sep 27, 2021
Merged

Extend to other markup languages #56

merged 3 commits into from
Sep 27, 2021

Conversation

krisgry
Copy link
Contributor

@krisgry krisgry commented Aug 21, 2021

I finally got around to create a suggestion based on #42

This makes the plugin call the possibly-user-defined function g:PasteImageFunction instead of doing Markdown-specific inserts.
The old behaviour has been separated into the MarkdownPasteImage function, which I have set g:PasteImageFunction to default to.

I've also included two example paste functions: one for latex and another that just pastes the path of the image (in case you just want to save the image and have its path). These are defined within the plugin (which I think makes sense for common languages), put can also be defined by the user in vimrc.

I tagged this as WIP since it is my first vimscript PR, and I have some questions and comments:

  • is the way I set the default value for PasteImageFunction ok?
  • the if in front of the call to the PasteImageFunction was seemingly needed because call() is a function
  • I was unsuccessful in my attepts at setting PasteImageFunction based on the filetype (autocmd), but I'm hoping that someone can give some pointers :) For now I have just set the PastImageFunction manually. Here is what I tried This now magically works. Probably had a problem with my vim settings
autocmd FileType markdown,tex nmap <buffer><silent> <leader>p :call mdip#MarkdownClipboardImage()<CR>
autocmd FileType markdown let g:PasteImageFunction = 'g:MarkdownPasteImage'
autocmd FileType tex let g:PasteImageFunction = 'g:LatexPasteImage'

Looking forward to hearing what you think!

Kristoffer Gryte added 2 commits August 21, 2021 21:18
Add description for extending to other filetypes
@krisgry krisgry changed the title WIP: Extend to other markup languages Extend to other markup languages Sep 26, 2021
@krisgry
Copy link
Contributor Author

krisgry commented Sep 26, 2021

Added a description to README, including a list of supported filetypes/languages. It seemed like a good idea to allow for PRs on this, but that is of course entirely up to you @ferrine 😄

@ferrine ferrine merged commit c0aa411 into img-paste-devs:master Sep 27, 2021
@ferrine
Copy link
Collaborator

ferrine commented Sep 27, 2021

thanks, looks good

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.

2 participants