Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

ftdetect for minisnip and expanding a command name in the syntax file #3

Closed
wants to merge 2 commits into from
Closed

Conversation

gowther-zoho
Copy link

There are two things in this request:

  1. This creates a filetype detection scripts based on the globally defined g:minisnip_dir variable. So wherever that is set (default or by user) all the files in that directory are given the filetype of minisnip. Allowing for other things out of the box like the syntax file automatically working etc.

  2. For the syntax/minisnip.vim file: I have expanded "exe" to "execute". I don't really like the short names. They are convenient for the immediate but long term it is easier to grok the long name of the internal vim commands.

adding filetype detection for the minisnip directory
I don't like using "shortnames" for vim commands. It's easier to read and understand later if the full name for the command is used.
" get the snippets directory
let snippet_dir = expand(g:minisnip_dir) . "*"

execute 'autocmd BufRead,BufNewFile ' . snippet_dir . ' set filetype=minisnip'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error detected while processing /home/joe/.config/nvim/plugged/vim-minisnip/ftdetect/minisnip.vim:
line   11:
E121: Undefined variable: g:minisnip_dir
E116: Invalid arguments for function expand
E15: Invalid expression: expand(g:minisnip_dir) . "**/*"
line   13:
E121: Undefined variable: snippet_dir
E15: Invalid expression: 'autocmd BufRead,BufNewFile ' . snippet_dir . ' set filetype=minisnip'
Press ENTER or type command to continue

Sadly I'm not sure why this is happening.
If I do :echo expand(g:minisnip_dir) it comes through correctly as /home/joe/.vim/minisnip which is correct (though I do have it symlinked to ~/joe/programs/configs/nvim/snippets but that shouldn't matter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure either. I will investigate. It works as is on macOS. I have to add the g:minisnip_dir on Windows. I am only using vim/gvim to test. I see you are using nvim so hopefully that doesn't deviate here too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to rewrite minisnips to use an actually directory path and file name extension (e.g. .minisnip) then maybe this is a moot effort? If you think that change will take you a while, I will try and find this answer out.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't planned on changing it any time soon. I'm more focused on writing a deoplete source for it. I develop very casually...heh...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows at work, I have to explicitly set g:minisnip_home because my $HOME is a network drive but Vim is installed under C:. Not sure how to get around that. I was hoping just put the package in place and everything works.

Try:

" get the snippets directory
"let snippet_dir = expand(g:minisnip_dir) . "*"

"execute 'autocmd BufRead,BufNewFile ' . snippet_dir . ' set filetype=minisnip'
execute "autocmd BufRead,BufNewFile /" g:minisnip_dir . '*' "/ set filetype=minisnip"

Still looking but maybe just put the syntax one in place with an addition to the docs to say if you want syntax highlighting while editing your snippets do:

autocmd BufRead,BufNewFile /path/to/snippets set filetype=minisnip

Copy link

@arp242 arp242 Nov 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why g:minisnip_dir isn't working, but in #5 I changed the documentation for this to:

autocmd BufRead,BufNewFile */minisnip/_* setlocal filetype=minisnip

This way you don't need to specify the full path, it will work multiple directories, and it is still unlikely to be triggered accidentally.

In addition to this:

  • It would be better to wrap this in an augroup; this way people can easily delete this, for example. See this page for a explanation.

  • It probably also be better to use setlocal. I think that for filetype= it's always buffer-local, but I can never remember for which settings this is. This makes it clearer, and less prone for an accidental set in case someone adds something later on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good points I think.

@gowther-zoho
Copy link
Author

Okay then, I will work out the fix for this. :)

@gowther-zoho
Copy link
Author

Try the following:

let snippet_dir = g:minisnip_dir . "*"

Maybe it is the expand portion that is messing things up. This still works for me on macOS. I will try it on Windows tomorrow at work.

@joereynolds
Copy link
Owner

Changing that still seems to be an issue, I'll take a look at it later hopefully :)

@arp242 arp242 mentioned this pull request Dec 7, 2017
joereynolds pushed a commit that referenced this pull request Dec 7, 2017
* Add ftdetect

Fixes #3

* Add "for syntax highlighting"

Also add modeline to help file; almost all help files have this, and it
makes editing them a lot easier imho.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants