Why isn't vim-snipmate UltiSnips for Django not working? - django

I'm running Vim 8.0.124 and I've installed the vim-snipmate plugin to use in my Python and Django development. I followed the instructions by creating a .vimrc file that contains the following:
# ~/.vimrc
set nocompatible " Required by Vundle
filetype off " Required by Vundle
" Begin Vundle settings ==========================================================
"
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
# Optional
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
call vundle#end()
filetype plugin indent on
"
" End Vundle settings ==========================================================
" SnipMate
autocmd FileType python set ft=python.django
autocmd FileType html set ft=htmldjango.html
" UltiSnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:UltiSnipsEditSplit="vertical"
Installing vim-snipmate includes the creation of these four files:
~/.vim/bundle/vim-snippets/snippets/django.snippets
~/.vim/bundle/vim-snippets/snippets/htmldjango.snippets
~/.vim/bundle/vim-snippets/UltiSnips/django.snippets
~/.vim/bundle/vim-snippets/UltiSnips/htmldjango.snippets
I have two questions. First, why are the UltiSnip Django snippets not working? The snippets in snippets/django.snippets work but those in the UltiSnips django.snippets file don't. If I open a file test.py and type "fdate" where fdate should expand into a Django DateField, nothing happens (other than a tab is entered). Initially, when the UltiSnips weren't working, I went to its Github page and read the instructions which seemed to indicate I should add the SirVer plugin so I did. Even then, then don't seem to work. I should add that what you see above is my entire .vimrc file. Also, I created a completely new ~/.vim directory which only contains the Vundle and vim-snipmate bundles so there shouldn't be any other conflicts.
My second less important question is, when I view any of these snippet files, most of the lines are folded. Is there any way I can configure Vim so that when I open any of these .snippet files, all the folds will be open? They would be easier to search that way.

Did you try with ":setfiletype htmldjango" ? or ":selfiletype django" (https://www.vim.org/scripts/script.php?script_id=1487)

Take a look in the docs, especially under section 4.1.1 How snippets are loaded UltiSnips-how-snippets-are-loaded
I had similar issue, I've created separate directory for snippets, at $HOME/UltiSnips. There I've created directory python, where I've moved files python.snippet and django.snippet. Similarly, you may create directories for another languages and use snippets for another frameworks.
From the docs:
UltiSnips iterates
over the snippet definition directories looking for files with names of the
following patterns: ft.snippets, ft_.snippets, or ft/, where "ft" is the
'filetype' of the current document and "*" is a shell-like wildcard matching
any string including the empty string.

Related

Using custom fonts on shinyapps.io

I would like to use a custom font in my shiny app (on plots) on shinyapps.io. I have my Roboto-Regular.ttf in the ./www/ directory. And this is the upper portion of my app.R file:
dir.create('~/.fonts')
system("chmod +x ./www/Roboto-Regular.ttf")
system("cp ./www/Roboto-Regular.ttf ~/.fonts/")
system('fc-cache -f -v ~/.fonts/')
system('fc-match Roboto')
library(ggplot2)
library(shiny)
library(shinythemes)
library(extrafont)
font_import(pattern="Roboto",prompt=FALSE)
loadfonts()
print(fonts())
Upon deploying the app, I end up with an error that looks like this:
Registering fonts with R
Scanning ttf files in /usr/share/fonts/, ~/.fonts/ ...
Extracting .afm files from .ttf files...
/home/shiny/.fonts/Roboto-Regular.ttfWarning in gzfile(dest, "w") :
cannot open compressed file '/opt/R/3.5.1/lib/R/library/extrafontdb/metrics/Roboto-Regular.afm.gz', probable reason 'Permission denied'
Error in value[[3L]](cond) : cannot open the connection
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
Does anyone see what might be wrong?
After a bit of struggle I found an even simpler solution that works on shinyapps.io:
Here we go:
Place custom font in www directory: e.g. IndieFlower.ttf from here
Follow the steps from here
This leads to the following upper part of the app.R file:
dir.create('~/.fonts')
file.copy("www/IndieFlower.ttf", "~/.fonts")
system('fc-cache -f ~/.fonts')
Since Linux looks into the .fonts directory to search fonts, you don't need the extrafont package, but you can directly use those fonts like:
ggplot(mapping=aes(x=seq(1,10,.1), y=seq(1,10,.1))) +
geom_line(position="jitter", color="red", size=2) + theme_bw() +
theme(text=element_text(size = 16, family = "IndieFlower"))
This is the answer I received from RStudio regarding this. I haven't tested this out myself.
Hi,
Our developer was able to advise this is due to a possibly unfortunate design choice made when they created extrafont and the associated extrafontdb package. The extrafont font database is stored in the extrafontdb package directory -- that's essentially all that the extrafontdb package is used for.
This means that the extrafontdb directory needs to be user-writable. If the user installs the package, this will work fine, but if root installs the package (as is the case on shinyapps.io), then it won't work.
One potential workaround is to install the extrafontdb package to library that is in subdirectory of the app.
To do it: create an r-lib/ subdir, and download the extrafontdb source package there:
dir.create('r-lib')
download.file('https://cran.r-project.org/src/contrib/extrafontdb_1.0.tar.gz','r-lib/extrafontdb_1.0.tar.gz')
When deployed, the app will include this r-lib/ subdirectory and the extrafontdb source package.
Then, at the top of the app, install the extrafontdb package from the source package, into the r-lib directory.
.libPaths(c('r-lib', .libPaths()))
install.packages('r-lib/extrafontdb_1.0.tar.gz',type = 'source',repos = NULL)
They deployed an app on shinyapps.io that does the extrafontdb installation, and it works fine. The libpath is set so so that install.packages() will install from the provided source package to the r-lib/ subdirectory of the app.
Please let us know if you're able to implement the above or have any additional questions.
Thanks,
Adding an alternative answer to symbolrush's answer which I found did not work. Here was the code I used initially:
# Add fonts to shiny linux server
if (Sys.info()[['sysname']] == 'Linux') {
dir.create('~/.fonts')
fonts = c(
"www/IBMPlexSans-Regular.ttf",
"www/IBMPlexSans-Bold.ttf",
"www/IBMPlexSans-Medium.ttf"
)
file.copy(fonts, "~/.fonts")
system('fc-cache -f ~/.fonts')
}
# Load fonts and set theme
font_paths("fonts")
font_add("IBMPlexSans", regular = "IBMPlexSans-Regular.ttf")
font_add("IBMPlexSans-Bold", regular = "IBMPlexSans-Bold.ttf")
font_add("IBMPlexSans-Medium", regular = "IBMPlexSans-Medium.ttf")
showtext_auto()
The bizarre thing is that the first instance of the app on shinyapps.io worked, including the custom fonts. However when the app went to sleep and was opened a second time, I get this error in the log:
Error in value[[3L]](cond) : font file not found for 'regular' type
I was never able to debug why this was the case, but I tried a simpler solution that has worked perfectly so far. I moved my fonts to a /font folder in the app folder (I don't think using the /www folder is necessary) and added the /font folder using path_folder():
library(showtext)
# Load fonts and set theme
font_paths("fonts")
font_add("IBMPlexSans", regular = "IBMPlexSans-Regular.ttf")
font_add("IBMPlexSans-Bold", regular = "IBMPlexSans-Bold.ttf")
font_add("IBMPlexSans-Medium", regular = "IBMPlexSans-Medium.ttf")
showtext_auto()
I hope this helps anyone who is having problems with their app not running after the first instance, as I could not find the same situation anywhere on stackoverflow.

How to apply syntax file for vim?

I've read vim manual pages and also bunch of tutorials and managed to set up my C++ environment in vim, but to apply a syntax file is probably a science fiction.
I downloaded a 'cpp.vim' which is a syntax file, now how do I apply that file so my code start shining??
I tried to place a file into following directories:
~/.vim/after/syntax/
~/.vim/syntax
/usr/share/vim/vim73/syntax
(but under different name, so not replacing old file)
none of that work, and anyway if I place a file into $VIMRUNTIME/syntax under some crazy name, then how do i apply it into vim?
Here is my .vimrc setting:
"
" vim settings
"
set t_Co=256
set nocompatible
set laststatus=2
"set ruler
"set ballooneval
"set balloondelay=400
"set balloonexpr=""
filetype off
"
" vundle settings and plugins
"
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"Vundle Plugin manager
Plugin 'gmarik/Vundle.vim' "vundle plugin manager
"Core plugins
Plugin 'ervandew/supertab' "completition with tab
Plugin 'scrooloose/syntastic' "error checking
Plugin 'vim-scripts/OmniCppComplete' "auto complete
"Plugin 'octol/vim-cpp-enhanced-highlight' "syntax highlighting
Plugin 'vim-scripts/Cpp11-Syntax-Support'
Plugin 'bling/vim-airline' "statusline and tabline
"Sipet plugins
Plugin 'MarcWeber/vim-addon-mw-utils' "required by snipmate
Plugin 'tomtom/tlib_vim' "required by snipmate
Plugin 'garbas/vim-snipmate' "insert snipets
Plugin 'honza/vim-snippets' "optional snipets
Plugin 'vim-scripts/a.vim' "Switching between source and header file
Plugin 'chazy/cscope_maps' "Allows searching code
Plugin 'vim-scripts/argtextobj.vim' "Text-object like motion for arguments
Plugin 'wincent/Command-T' "Fast file navigation
Plugin 'vim-scripts/taglist.vim' "Source code browser (requires exuberant-ctags > apt-get install)
Plugin 'ddollar/nerdcommenter' "wrangle your code comments, regardless of filetype
Plugin 'scrooloose/nerdtree' "explore your filesystem and to open files and directories
Plugin 'tpope/vim-unimpaired' "provides a lot of useful mappings
Plugin 'majutsushi/tagbar' "browsing the tags of source code files
Plugin 'chrisbra/NrrwRgn' "focussing on a region and making the rest inaccessible
Plugin 'vim-scripts/ZoomWin' "zoom into a window and out again
Plugin 'terryma/vim-multiple-cursors'
Plugin 'jeetsukumaran/vim-buffergator' "listing,navigating, and selecting buffers for edit
Plugin 'bronson/vim-trailing-whitespace' "causes all trailing whitespace to be highlighted in red
Plugin 'mileszs/ack.vim' "uses ack to search inside the current directory for a pattern
Plugin 'myusuf3/numbers.vim' "intelligently toggling line numbers
Plugin 'Lokaltog/vim-easymotion' "provides a much simpler way to use some motions in vim
call vundle#end()
filetype plugin indent on
"
" ariline options
"
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
"
" syntastic settings
"
let g:syntastic_enable_signs = 1
let g:syntastic_cpp_checkers = ['gcc']
let g:syntastic_auto_jump = 1
let g:syntastic_enable_balloons = 1
let g:syntastic_cpp_compiler = 'g++'
let g:syntastic_cpp_compiler_options = '-std=c++11'
let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_auto_refresh_includes = 1
let g:syntastic_always_populate_loc_list = 1
syntax on
colorscheme slate
... etc
other options are plugins and plugin settings..
The Question is simple, how do I apply a syntax file ??
All you need to do is make sure the filetype is loaded properly. So if the syntax file is called cpp.vim make sure set ft? returns cpp. You should place it in $HOME/.vim/syntax. It should get loaded automatically. Assuming filetype on and syntax on is set.
The only way to make sure the syntax file isn't loaded properly is to use :scriptnames. Make sure the file isn't listed if it is your problem is something different then what you have described.
Ok, I managed to get things work :)
I downloaded two syntax files, one of which does do the job by highlighting the code and other which for some unknown reason does not.
The fact that I have Vundle installed as a plugin manager there was no need to place a syntax file anywhere because that part handles Vundle it self...
All I had to do is is to remove the syntax file that does not work. and also make several tests to see the difference between default syntax highlighting and custom with file.
to enable syntax highlighting only one option is needed placed anywhere in the .vimrc file:
syntax on
or
syntax enable
difference between these two is that 'on' switch does search for first cpp file it find inside $VIMRUNTIME directory while enable switch searches in .vim directory too.
more info about that here
To make syntax highlighting more 'nice' I also downloaded color schemes which makes code much more readable.
And if you just want to know how to apply that piece of file here is how:
Download it with Vundle and place this at the end of your .vimrc file:
colorscheme molokai
Where molokai is the name of colorscheme downloaded with Vundle :D
YES!!!
thanks you FDinoff for trying to help! you were right about :scriptnames which actually helped me to figure out that my file isn't loaded ;)

Vim YouCompleteMe configuration

i just installed YouCompleteMe for Vim through vundle. It works, but it shows only the words contained in the current file. I want to use it to develop c++ programs, how can i configure it to show autocompletion from c++ headers file in /usr/include for example? Thanks a lot.
You need to navigate to ~/.vim/bundles/YouCompleteMe and run the installation script with --clang-completer, so do ./install.sh --clang-completer. After it finishes you should have support for C like languages.
You may also need to place let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' in your ~/.vimrc.
I have installed with pathogen. I tried the above instructions with ./install.sh --clang-complete. After this, it did not work, and I indeed had to add the path. But it was different than in another reply here, namely
let g:ycm_global_ycm_extra_conf = '.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
so there is an extra "third_party/ycmd" in the path.
While the suggestions here might work in the beginning, I am not sure it's the proper way to go. According to YCM developer, whenever you start a project, you need a new .ycm_extra_conf.py file
From https://valloric.github.io/YouCompleteMe/#ubuntu-linux-x64-super-quick-installation
YCM looks for a .ycm_extra_conf.py file in the directory of the opened file or in any directory above it in the hierarchy (recursively); when the file is found, it is loaded (only once!) as a Python module. YCM calls a FlagsForFile method in that module which should provide it with the information necessary to compile the current file. You can also provide a path to a global .ycm_extra_conf.py file, which will be used as a fallback. To prevent the execution of malicious code from a file you didn't write YCM will ask you once per .ycm_extra_conf.py if it is safe to load. This can be disabled and you can white-/blacklist files. See the Options section for more details.
While you might only need to modify the compile flags from the vanilla .ycm_extra_conf.py, I feel it is advisable to create a new file for every project you start.
Everything that the folks here have said is correct. I just want to add that as of 2017, the "install.sh" script is deprecated. Now, you have to use the install.py script instead by typing
./install.py --clang-completer
Also, in your .vimrc file, instead of ".vim/bundle/blahblahblah", you'll need to add a "~/" in front of the address by adding:
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py"
to your .vimrc file, to give it an absolute path from the Home directory so that Vim can find the ".ycm_extra_conf.py" file. Otherwise, you might experience some funny behavior.
I just wanted to add if you don't want to manually define a config file there is this neat little repository that will auto generate it. https://github.com/rdnetto/YCM-Generator

Sublime Text 2 FileTemplates plugin doesn't work

I want to use "FileTemplates" plugin in Sublime Text 2. I installed it with Package Controller, but when I use "Create file from template" and select something, nothing happens! It doesn't even create a file.
How can I make it work? Any ideas?
You need to find you current user's packages folder. Here you will find where the FileTemplates package has been installed. On my Windows system it is %APPDATA%\Roaming\Sublime Text 2\Packages\FileTemplates. You may also get to this folder from the Preferences menu by selecting Browse Packages...
Inside this folder there is a Templates folder. Inside this folder you will find the pre-canned file templates. You may create your own by copying and pasting the existing files to create the templates you like. You will need to create a .file-template file in the FileTemplates folder. This file is an xml file which tells sublime where to find the actual template and what parameters to the file creation the user may pass into the template. For instance $name is the parameter that the user is prompted for which will be used to name the file created from the template. Hope this helps.

Excluding a single project file from an SVN repository

I have a django project that I have been working on as a solo developer, and have been using TortoiseSVN to keep the code managed in a repository on a work server. I work on this on a local installation of django etc.
There is now a second person who will be working on this project, and the possibility of working on some other PCs.
Now, there should, for the time being, only be one development version (branch?) of this project, but the configuration file (settings.py) will need to be different on each computer that is being used. I want to create one local version of this file on each PC which should not need to be changed again.
How can I set the repository (preferably within TortoiseSVN) to exclude this one file? E.g. the repository should not include settings.py. When a checkout occurs, it should update all files in the local folder but not change/remove the local copy of settings.py. When a commit occurs, settings.py should be ignored and not uploaded.
At the moment settings.py is overwritten/updated as per any other file in the project folder/repository.
Any nudges in the right direction would be useful - I'm new to SVN generally and would like to know if this is something that's going to need detailed understanding of branching or if there is a simpler way.
Thanks
In TortoiseSVN, when you try to commit your files, in the file list dialog, right click the file and look for the Ignore option. You can ignore by complete filename or extension.
If the file is already in the repository, and you want to remove it from there and ignore it, you can simply right-click the file and in the TortoiseSVN menu look for the 'Delete and add to ignore list' option.
You'll be looking for the svn:ignore property, which tells subversion to not version files matching a pattern or patterns you specify.
There's some guidance on using it with TortoiseSVN at:
http://arcware.net/tortoisesvn-global-ignore-pattern-vs-svn-ignore/
These should help:
I have a file in my project that every developer must change, but I don't want those local mods to ever be committed. How can I make 'svn commit' ignore the file?
Excluding Items from the Commit List
The typical solution is to do what bgever said and ignore the settings file itself, and then commit a file with example values, something like settings.py.example. That file should only be updated when you add or remove settings. When deploying, you'd copy that to settings.py and edit the values.