-
Notifications
You must be signed in to change notification settings - Fork 10
ftdetect for minisnip and expanding a command name in the syntax file #3
Conversation
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' |
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.
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.
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 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.
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.
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.
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 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...
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.
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
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 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 forfiletype=
it's always buffer-local, but I can never remember for which settings this is. This makes it clearer, and less prone for an accidentalset
in case someone adds something later on.
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.
All good points I think.
Okay then, I will work out the fix for this. :) |
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. |
Changing that still seems to be an issue, I'll take a look at it later hopefully :) |
* 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.
There are two things in this request:
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.
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.