Disable syntasic html/tidy checker for a file - vim

Is there a way to disable the html/tidy plugin for syntastic for a certain file?
I have a handlebars template that contain an empty <tbody></tbody> tag as a placeholder, and I keep getting the error
trimming empty <tbody> [html/tidy]
Is there a way to either disable this specific rule, or just disable the html/tidy plugin for this specific file?

Try to put this in your .vimrc
let g:syntastic_html_tidy_ignore_errors=[" proprietary attribute " ,"trimming empty <", "unescaped &" , "lacks \"action", "is not recognized!", "discarding unexpected"]
This solves more things than one but I think it can be helpful. More on this here.

I was running into this with .hbs and .html templating for a node project. Adding this to my .vimrc helped:
let syntastic_mode_map = { 'passive_filetypes': ['html'] }
more options here https://github.com/scrooloose/syntastic/issues/240

Additionally, if you just want to turn warnings off for html tidy:
let g:syntastic_html_tidy_quiet_messages = { "level" : "warnings" }
I have found this is a welcome setting for editing twig templates.
Of course for more info, in vim:
:h syntastic-checkers

Related

vim-airline: how to create a custom tabline formatter so that it contains the current directory?

In vim-airline, how to create a custom tabline formatter so that it contains the current directory? something like: dir/filename or filename (dir). I did google this, but don't find an answer. Thanks a lot.
I found the solution.
In ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/formatters, create the custom formatter, for instance, you can name it as custom_dir_filename.vim which has the following file content:
function! airline#extensions#tabline#formatters#custom_dir_filename#format(bufnr, buffers)
let name = bufname(a:bufnr)
return fnamemodify(name, ':p:h:t') . '/' . fnamemodify(name, ':t')
endfunction
In your .vimrc, add the following:
let g:airline#extensions#tabline#formatter = 'custom_dir_filename'
there is already a similar one provided by airline (i found it by digging at the source code) its called short_path.
So just do
let g:airline#extensions#tabline#formatter = 'short_path'

Is there a way to get ProxyHTMLURLMap to match more than once per tag attribute?

I have a problem that seems to be caused by resources being called with img tags that look like this:
<img
class="alignnone size-full"
title="some title"
src="https://new.url.com/some.jpeg" alt="" width="612" height="408"
srcset="https://new.url.com/some.jpeg 612w, https://old.url.com/some-300x200.jpg 300w"
sizes="(max-width: 612px) 100vw, 612px">
ProxyHTMLURLMap successfully replaces the first URL within the attribute "srcset" but never more than the first.
I don't see anything in the manual that could address this, any help is much appreciated.
I am interested in any open source Linux compatible solutions even if outside Apache.
Thanks!
I found a limited workaround for this issue.
If each ProxyHTMLURLMap can replace only one matched occurrence, we need to add more directives like that.
ProxyHTMLURLMap "https://old.url.com/" "https://new.url.com/" Rl
ProxyHTMLURLMap " https://old.url.com/" " https://new.url.com/" Rl
ProxyHTMLURLMap ", https://old.url.com/" ", https://new.url.com/" Rl
ProxyHTMLURLMap "w, https://old.url.com/" "w, https://new.url.com/" Rl
These four directives can replace up to 4 instances of https://old.url.com
"R" flag is needed to process regular expressions.
"l" flag is needed to avoid stopping after first (second, third) match occurs.
It seems to work for me.

How to use both pman and custom help files in Vim with the viewdoc plugin?

When editing PHP files I want to use help files from two sources:
vim help files in /etc/vim/bundle/yii-api-vim/doc/ from here.
PHP man pages with pman
If there's no help available from the help files it should try pman.
The viewdoc plugin's help claims that
You can have several documentation sources for same file type, and choose which one should be used on-the-fly.
But it does not explain, how to do this. The only feature that comes close are handlers for a specific filetype, like ViewDoc_{filetype}(topic, filetype, synid, have_context). But I don't know how to implement such a function.
Open questions to me are:
How can I check inside that function if a *.txt file exists in my specific directory?
What should I return to let viewdoc open such a help file if it exists?
What should I return to let viewdoc open a pman page for a ordinary PHP function?
It would be helpful to see an example for such a function.
I'm not an expert on vim scripting, so this may not be an ideal solution, but this is what worked for me.
First create a custom viewdoc handler in the viewdoc_pman.vim file (which can be found in the ~/.vim/bundle/viewdoc/plugin/ directory if you are using the recommended pathogen installation).
function ViewDoc_pman_custom(topic, filetype, synid, ctx)
let l:tagpath = '/etc/vim/bundle/yii-api-vim/doc/tags'
let l:shell = printf('grep %s %s', shellescape(a:topic,1), l:tagpath)
let l:output = system(l:shell)
if !v:shell_error
return g:ViewDoc_help(a:topic, a:filetype, a:synid, a:ctx)
else
let l:ViewDoc_pman_old = function('ViewDoc_pman')
return l:ViewDoc_pman_old(a:topic, a:filetype, a:synid, a:ctx)
endif
endfunction
This function uses grep to look for the specified topic string in the yii-api-vim tags file. If it finds it there, it just forwards the command to the default ViewDoc_help handler (this is assuming you've already installed the yii-api-vim documentation so that it works correctly with the standard help).
If grep doesn't find anything, then it falls back to calling the old php handler in the ViewDoc_pman function. Note that we can't just call g:ViewDoc_pman directly since that is a variable that we are about to overwrite. We need to get a handle to the old function using function('ViewDoc_pman') and call that instead.
Finally, you need to find these two lines:
let g:ViewDoc_pman = function('ViewDoc_pman')
let g:ViewDoc_php = function('ViewDoc_pman')
And replace them with these two:
let g:ViewDoc_pman = function('ViewDoc_pman_custom')
let g:ViewDoc_php = function('ViewDoc_pman_custom')
This forces all php documentation queries to be forwarded to our new custom handler rather than the old ViewDoc_pman function.
If you prefer not to edit the viewdoc_pman.vim file, you can put the viewdoc handler in your .vimrc file instead. Then to set the g:ViewDoc_pman and g:ViewDoc_php variables, you'll need to add the following lines:
autocmd VimEnter * let g:ViewDoc_pman = function('ViewDoc_pman_custom')
autocmd VimEnter * let g:ViewDoc_php = function('ViewDoc_pman_custom')
The autocmd VimEnter forces the assignments to happen after all plugins have been loaded, otherwise those variables would just be overwritten by the plugin and your custom handler would never be called.

Defining scope for custom Sublime Text 2 snippets

While trying to write my own snippets for Sublime Text 2, I ran into the following two problems:
Finding scope keys. I figured out that I can look through my packages one by one and find references to a declared "scope" property. For example in ~/Library/Application Support/Sublime Text 2/Packages/JavaScript/Comments.tmPreferences (a file in my HTML package) there's these two lines:
<key>scope</key>
<string>source.js</string>
So if I want my current snippet to work on javascript files, I define my scope like:
<scope>source.js</scope>
I'm assuming all these scope keys are defined on-the-fly based on what Packages I have installed. Does Sublime Text build a list anywhere that I can more easily reference? Perusing through a bunch of package files seems overly tedious.
Defining multiple scope properties. This I've figured out, and the following line allows my snippet to work in both HTML and JavaScript files.
<scope>text.html, source.js</scope>
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee
CSS: source.css
D: source.d
Diff: source.diff
Erlang: source.erlang
Go: source.go
GraphViz: source.dot
Groovy: source.groovy
Haskell: source.haskell
HTML: text.html(.basic)
JSP: text.html.jsp
Java: source.java
Java Properties: source.java-props
Java Doc: text.html.javadoc
JSON: source.json
Javascript: source.js
BibTex: source.bibtex
Latex Log: text.log.latex
Latex Memoir: text.tex.latex.memoir
Latex: text.tex.latex
LESS: source.css.less
TeX: text.tex
Lisp: source.lisp
Lua: source.lua
MakeFile: source.makefile
Markdown: text.html.markdown
Multi Markdown: text.html.markdown.multimarkdown
Matlab: source.matlab
Objective-C: source.objc
Objective-C++: source.objc++
OCaml campl4: source.camlp4.ocaml
OCaml: source.ocaml
OCamllex: source.ocamllex
Perl: source.perl
PHP: source.php
Regular Expression(python): source.regexp.python
Python: source.python
R Console: source.r-console
R: source.r
Ruby on Rails: source.ruby.rails
Ruby HAML: text.haml
SQL(Ruby): source.sql.ruby
Regular Expression: source.regexp
RestructuredText: text.restructuredtext
Ruby: source.ruby
SASS: source.sass
Scala: source.scala
Shell Script: source.shell
SQL: source.sql
Stylus: source.stylus
TCL: source.tcl
HTML(TCL): text.html.tcl
Plain text: text.plain
Textile: text.html.textile
XML: text.xml
XSL: text.xml.xsl
YAML: source.yaml
If anything is missing, add it in this gist https://gist.github.com/4705378.
View Current Scope of Cursor Position
Place your cursor in the file where you wish to know the scope.
Use this keyboard-shortcut:
Windows: ctrl+shift+alt+p
Mac: ctrl+shift+p
The current scope will be displayed in the left side of the status bar on Windows, or in a popup window on Mac.
Use these as the <scope> key in your foo.sublime-snippet file.
The returned scopes are listed generic to specific. Choose the scope(s) which best "scoped" the snippet to where it should be available to tab trigger.
There's a package called Scope Hunter, by Isaac Muse, which is really helpful for this.
It can show you the scope under any cursor in a document, which I've found really helpful when debugging my own snippets. Sometimes it's very detailed; a sample scope from my frontmost document:
Scope: text.tex.latex
meta.function.environment.list.latex
meta.function.environment.general.latex
meta.function.environment.math.latex
string.other.math.block.environment.latex
meta.group.braces.tex
meta.space-after-command.latex
(Wrapped for ease of reading)
I wouldn't have been able to find that if I spent a week picking SL2 apart, but this package gets it in seconds. Highly recommended.
This level of detail also means that you can define snippets in a very granular way, if you want. For example, the meta.function.environment.list.latex corresponds broadly to lists in LaTeX, so I have a snippet that inserts a new \item when I press super+enter in a list environment, but nobody else. I can target snippets much more effectively than with blind guesswork.
The source code is in Github, or you can install it through Package Control.
Actually, you can use the Ctrl+Alt+Shift+P (without using Scope Hunter) and it will show you the scope on the bottom bar on the left side right after the Col/Line information. It's pretty small print but it's there.
To answer, #1, look in the syntax's .tmLanguage file, look for the key: scopeName. This is what the syntax uses for the snippet's scope value.
For example, an excerpt from nathos / sass-textmate-bundle
<key>scopeName</key>
<string>source.sass</string>
So you would use source.sass in your snippet.
Here is more info on defining a syntax

How can I syntax highlight a custom self closing script tag in vim?

I know that normal script tags can't self close, and I know less of vimscript than I might. I have been working with a custom XML templating language quite similar to HTML, and have been using the HTML mode along with the file ~/.vim/after/syntax/html.vim:
syn region javaScript start=+<is:PageComponents:Script[^>]*>+ keepend end=+</is:PageComponents:Script>+me=s-1 contains=#htmlJavaScript,htmlCssStyleComment,htmlScriptTag,#htmlPreproc
syn region htmlScriptTag contained start=+<is:PageComponents:Script+ end=+>+ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent
The problem that I am experiencing is "spillover" of the highlighting region until the end of the file or the next closing script tag.
I have attempted changing start to: +<is:PageComponents:Script[^>]*\(\\\)\#<!>+, and +<is:PageComponents:Script[^>]*[^\\]>+, neither of which make a difference. As far as I understand regexes, the negative lookbehind should have been an ideal solution, and the one character match should have forced the greedy star to back off one character, resulting in failure. Replacing the * with \{-} for ungreedy behavior has the same result. What am I missing?
In case it's relevant, I'm running vim in Cygwin's mintty (type is xterm-256color), shell is bash, color scheme is solarized.
Edit: Adding sample of our markup language
<is:PageComponents:Template title="Page Title" controller="controller">
<is:PageComponents:Script src="/path/jsfile.js" />
<is:PageComponents:Style src="cssfile.css" />
<is:Containers:Box label="Box Label">
<is:DataGridComponents:DataGrid id="data_grid_id" data_provider="data_provider" keep_state="true">
<is:DataGridComponents:DataGridHeader />
<is:DataGridComponents:Columns strip_placeholders="false" id="%%id%%_row">
<is:DataGridComponents:Column header_title="Links Header">
<span class="popup-link popup-link-type1" id="type1_%%id%%">Type 1</span> |
<span class="popup-link popup-link-type2" id="type2_%%id%%">Type 2</span>
</is:DataGridComponents:Column>
<is:DataGridComponents:Column header_title="Data1">%%data1%%</is:DataGridComponents:Column>
<is:DataGridComponents:Column header_title="Data2">%%data2%%</is:DataGridComponents:Column>
</is:DataGridComponents:Columns>
<is:DataGridComponents:DataGridFooter>
<is:DataGridComponents:Pager id="pager_id" data_provider="pager_data_provider" for_component="data_grid_id" />
<is:Containers:Box id="footer_box_id" data_provider="footer_box_data_provider">Text: %%data%%</is:containers:box>
</is:DataGridComponents:DataGridFooter>
</is:DataGridComponents:DataGrid>
</is:Containers:Box>
<is:PageComponents:Script location="onready">
{literal}
// Insert literal JavaScript code here for the page
{/literal}
</is:PageComponents:Script>
{include file="path/file1.tpl"}
{include file="path/file2.tpl"}
</is:PageComponents:Template>
Both of my patterns worked correctly when I switched to using / instead of \ in my match.
The corrected patterns are:
+<is:PageComponents:Script[^>]*\(/\)\#<!>+ and
+<is:PageComponents:Script[^>]*[^/]>+.

Resources