template.nvim icon indicating copy to clipboard operation
template.nvim copied to clipboard

Trying to fix the parsing of .tex and .txt file extensions when parsing templates

Open Chifiwang opened this issue 1 year ago • 3 comments

I was trying to create a template for some latex and noticed that it wouldn't parse. The other option of .tpl removed my lsp and syntax highlighting, so I wanted to see why it wouldn't parse

From what I saw, within the function temp.get_temp.list() the call to vim.filetype.match({ filename = name }) will not match .tex and .txt file extensions by design (see https://www.reddit.com/r/neovim/comments/1cb4kty/vimfiletypematch_returns_nil/) for why.

Because of this, templates in latex .tex, and also incidentally .txt files, will not parse requiring you to use .tpl files with a header comment of ;; tex to be read properly.

To fix this I reimplemented the functionality of vim.filetype.match and adjusted the code according to the new function's api.

If you have time feel free to review and adjust the code as needed or contact me if I made a mistake in understanding when adjusting the code.

Thank you for your time.

Chifiwang avatar Aug 29 '24 02:08 Chifiwang

I noticed that when pasting multiple versions of the template into one file there was a nil exception so I added a guarding if statement to mitigate that. It looks as though the output is correct none the less

Chifiwang avatar Aug 29 '24 03:08 Chifiwang

thanks I think we need a test here

glepnir avatar Aug 29 '24 05:08 glepnir

No problem!

Chifiwang avatar Aug 29 '24 14:08 Chifiwang