Squashed 'vim/bundle/yaml/' content from commit 20bc37c02
git-subtree-dir: vim/bundle/yaml git-subtree-split: 20bc37c02a648959362388b4933653ab3c304645main
commit
a086d20325
@ -0,0 +1,41 @@
|
|||||||
|
# Vim syntax files
|
||||||
|
# Language: YAML
|
||||||
|
# Author: Igor Vergeichik <iverg@mail.ru>
|
||||||
|
# Author: Nikolai Weibull <now@bitwi.se>
|
||||||
|
# Sponsor: Tom Sawyer <transami@transami.net>
|
||||||
|
# Sponsor: Ingy döt Net <ingy@ingy.net>
|
||||||
|
|
||||||
|
YAML.VIM and YAML collection sorting scripts:
|
||||||
|
|
||||||
|
INSTALLATION:
|
||||||
|
- Put syntax/yaml.vim in vim's syntax folder (/usr/share/vim/syntax on my system)
|
||||||
|
- Add the .yaml/.yml extensions to the filetype.vim file: |
|
||||||
|
" Yaml
|
||||||
|
au BufNewFile,BufRead *.yaml,*.yml setf yaml
|
||||||
|
- If you want add a new enty to the syntax menu:
|
||||||
|
an 50.110.370 &Syntax.WXYZ.Yaml :cal SetSyn("yaml")<CR>
|
||||||
|
- Put yamlsort.rb and yamlsort.vim into ~/.vim/scripts directory.
|
||||||
|
|
||||||
|
SORT USE:
|
||||||
|
- Type vim command: |
|
||||||
|
:source ~/.vim/scripts/yamlsort.vim
|
||||||
|
- Then: >
|
||||||
|
<F4> is mapped to sort YAML collections in direct order,
|
||||||
|
and <F5> in reversed order.
|
||||||
|
|
||||||
|
NOTES:
|
||||||
|
- If you want change key mapping of sorting rules edit yamlsort.vim
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
- Work with short notation of collections and mappings ({}, [])
|
||||||
|
- Support sorting of multiline values
|
||||||
|
|
||||||
|
Changelog:
|
||||||
|
2010-02-19:
|
||||||
|
- Merge Nikolai Weibull's rendition of yaml.vim (thanks to Phill Baker).
|
||||||
|
2002-06-09:
|
||||||
|
- Key field can contain any number of spaces before column.
|
||||||
|
- >
|
||||||
|
If any record of collection does not key field (i.e field which
|
||||||
|
value is used in sorting), it is placed to the end of collection.
|
||||||
|
|
@ -0,0 +1,126 @@
|
|||||||
|
" Vim syntax file
|
||||||
|
" Language: YAML (YAML Ain't Markup Language)
|
||||||
|
" Author: Igor Vergeichik <iverg@mail.ru>
|
||||||
|
" Author: Nikolai Weibull <now@bitwi.se>
|
||||||
|
" Sponsor: Tom Sawyer <transfire@gmail.com>
|
||||||
|
" Version: 2.0
|
||||||
|
"
|
||||||
|
|
||||||
|
if version < 600
|
||||||
|
syntax clear
|
||||||
|
elseif exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
syntax clear
|
||||||
|
|
||||||
|
if exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:cpo_save = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
|
syn keyword yamlTodo contained TODO FIXME XXX NOTE
|
||||||
|
|
||||||
|
syn region yamlDocumentHeader start='---' end='$' contains=yamlDirective
|
||||||
|
syn match yamlDocumentEnd '\.\.\.'
|
||||||
|
syn match yamlDirective contained '%[^:]\+:.\+'
|
||||||
|
|
||||||
|
syn region yamlComment display oneline start='\%(^\|\s\)#' end='$'
|
||||||
|
\ contains=yamlTodo,@Spell
|
||||||
|
"syn region yamlMapping start="\w+:\s*\w+" end="$"
|
||||||
|
\ contains=yamlKey,yamlValue
|
||||||
|
syn match yamlNodeProperty "!\%(![^\\^% ]\+\|[^!][^:/ ]*\)"
|
||||||
|
syn match yamlAnchor "&.\+"
|
||||||
|
syn match yamlAlias "\*.\+"
|
||||||
|
syn match yamlDelimiter "[-,:]\(\s\|\n\)"
|
||||||
|
syn match yamlBlock "[\[\]\{\}>|]"
|
||||||
|
syn match yamlOperator '[?+-]'
|
||||||
|
syn match yamlKey '\(\.\|\w\)\+\(\s\+\(\.\|\w\)\+\)*\ze\s*:\(\s\|\n\)'
|
||||||
|
syn match yamlScalar '\(\(|\|>\)\s*\n*\r*\)\@<=\(\s\+\).*\n*\r*\(\(\3\).*\n\)*'
|
||||||
|
|
||||||
|
" Predefined data types
|
||||||
|
|
||||||
|
" Yaml Integer type
|
||||||
|
syn match yamlInteger display "[-+]\?\(0\|[1-9][0-9,]*\)"
|
||||||
|
syn match yamlInteger display "[-+]\?0[xX][0-9a-fA-F,]\+"
|
||||||
|
|
||||||
|
" floating point number
|
||||||
|
syn match yamlFloating display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=\>"
|
||||||
|
syn match yamlFloating display "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
|
||||||
|
syn match yamlFloating display "\<\d\+e[-+]\=\d\+[fl]\=\>"
|
||||||
|
syn match yamlFloating display "\(([+-]\?inf)\)\|\((NaN)\)"
|
||||||
|
" TODO: sexagecimal and fixed (20:30.15 and 1,230.15)
|
||||||
|
syn match yamlNumber display
|
||||||
|
\ '\<[+-]\=\d\+\%(\.\d\+\%([eE][+-]\=\d\+\)\=\)\='
|
||||||
|
syn match yamlNumber display '0\o\+'
|
||||||
|
syn match yamlNumber display '0x\x\+'
|
||||||
|
syn match yamlNumber display '([+-]\=[iI]nf)'
|
||||||
|
|
||||||
|
" Boolean
|
||||||
|
syn keyword yamlBoolean true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF
|
||||||
|
syn match yamlBoolean ":.*\zs\W[+-]\(\W\|$\)"
|
||||||
|
|
||||||
|
syn match yamlConstant '\<[~yn]\>'
|
||||||
|
|
||||||
|
" Null
|
||||||
|
syn keyword yamlNull null Null NULL nil Nil NIL
|
||||||
|
syn match yamlNull "\W[~]\(\W\|$\)"
|
||||||
|
|
||||||
|
syn match yamlTime "\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\?Z"
|
||||||
|
syn match yamlTime "\d\d\d\d-\d\d-\d\dt\d\d:\d\d:\d\d.\d\d-\d\d:\d\d"
|
||||||
|
syn match yamlTime "\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d.\d\d\s-\d\d:\d\d"
|
||||||
|
syn match yamlTimestamp '\d\d\d\d-\%(1[0-2]\|\d\)-\%(3[0-2]\|2\d\|1\d\|\d\)\%( \%([01]\d\|2[0-3]\):[0-5]\d:[0-5]\d.\d\d [+-]\%([01]\d\|2[0-3]\):[0-5]\d\|t\%([01]\d\|2[0-3]\):[0-5]\d:[0-5]\d.\d\d[+-]\%([01]\d\|2[0-3]\):[0-5]\d\|T\%([01]\d\|2[0-3]\):[0-5]\d:[0-5]\d.\dZ\)\='
|
||||||
|
|
||||||
|
" Single and double quoted scalars
|
||||||
|
syn region yamlString start="'" end="'" skip="\\'"
|
||||||
|
\ contains=yamlSingleEscape
|
||||||
|
syn region yamlString start='"' end='"' skip='\\"'
|
||||||
|
\ contains=yamlEscape
|
||||||
|
|
||||||
|
" Escaped symbols
|
||||||
|
" every charater preceeded with slash is escaped one
|
||||||
|
syn match yamlEscape "\\."
|
||||||
|
" 2,4 and 8-digit escapes
|
||||||
|
syn match yamlEscape "\\\(x\x\{2\}\|u\x\{4\}\|U\x\{8\}\)"
|
||||||
|
syn match yamlEscape contained display +\\[\\"abefnrtv^0_ NLP]+
|
||||||
|
syn match yamlEscape contained display '\\x\x\{2}'
|
||||||
|
syn match yamlEscape contained display '\\u\x\{4}'
|
||||||
|
syn match yamlEscape contained display '\\U\x\{8}'
|
||||||
|
" TODO: how do we get 0x85, 0x2028, and 0x2029 into this?
|
||||||
|
syn match yamlEscape display '\\\%(\r\n\|[\r\n]\)'
|
||||||
|
syn match yamlSingleEscape contained display +''+
|
||||||
|
|
||||||
|
syn match yamlKey "\w\+\ze\s*:\(\s\|\n\)"
|
||||||
|
syn match yamlType "![^\s]\+\s\@="
|
||||||
|
|
||||||
|
hi link yamlKey Identifier
|
||||||
|
hi link yamlType Type
|
||||||
|
hi link yamlInteger Number
|
||||||
|
hi link yamlFloating Float
|
||||||
|
hi link yamlNumber Number
|
||||||
|
hi link yamlEscape Special
|
||||||
|
hi link yamlSingleEscape SpecialChar
|
||||||
|
hi link yamlComment Comment
|
||||||
|
hi link yamlBlock Operator
|
||||||
|
hi link yamlDelimiter Delimiter
|
||||||
|
hi link yamlString String
|
||||||
|
hi link yamlBoolean Boolean
|
||||||
|
hi link yamlNull Boolean
|
||||||
|
hi link yamlTime String
|
||||||
|
hi link yamlTodo Todo
|
||||||
|
hi link yamlDocumentHeader PreProc
|
||||||
|
hi link yamlDocumentEnd PreProc
|
||||||
|
hi link yamlDirective Keyword
|
||||||
|
hi link yamlNodeProperty Type
|
||||||
|
hi link yamlAnchor Type
|
||||||
|
hi link yamlAlias Type
|
||||||
|
hi link yamlOperator Operator
|
||||||
|
hi link yamlScalar String
|
||||||
|
hi link yamlConstant Constant
|
||||||
|
hi link yamlTimestamp Number
|
||||||
|
|
||||||
|
let b:current_syntax = "yaml"
|
||||||
|
|
||||||
|
let &cpo = s:cpo_save
|
||||||
|
unlet s:cpo_save
|
@ -0,0 +1,112 @@
|
|||||||
|
# This is a script for vim-ruby for sorting collections
|
||||||
|
#
|
||||||
|
# Author: Igor Vergeichik <iverg@mail.ru>
|
||||||
|
# Sponsor: Tom Sawyer <transami@transami.net>
|
||||||
|
# Copyright (c) 2002 Tom Saywer
|
||||||
|
|
||||||
|
class YCollection
|
||||||
|
def initialize(rule)
|
||||||
|
@buffer=VIM::Buffer.current
|
||||||
|
@window=VIM::Window.current
|
||||||
|
@lnum = @window.cursor[0]
|
||||||
|
@key=@buffer[@lnum].scan(/^([^:]+[^\s])\s*:/)
|
||||||
|
# Find collection bounds
|
||||||
|
r = bounds
|
||||||
|
# If collection found - resort it
|
||||||
|
replace(r, resort((parse r), rule)) if r[1]>0
|
||||||
|
end
|
||||||
|
|
||||||
|
# Detect bounds of YAML collection
|
||||||
|
# Input: no
|
||||||
|
# Output: Array - range of detected collection
|
||||||
|
def bounds
|
||||||
|
lnum = @lnum
|
||||||
|
# If line begins with a dash - this is one of collection items
|
||||||
|
if @buffer[lnum]=~/\s*-/
|
||||||
|
coll_bounds(lnum)
|
||||||
|
else
|
||||||
|
# otherwise we need to find parent item
|
||||||
|
ind = VIM::evaluate("indent(#{lnum})").to_i
|
||||||
|
while lnum>0
|
||||||
|
if VIM::evaluate("indent(#{lnum})").to_i<ind
|
||||||
|
return coll_bounds(lnum)
|
||||||
|
else lnum=lnum-1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# No parent item found - no collection detected
|
||||||
|
[0, 0]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Detect bounds of YAML collection
|
||||||
|
# Called only for line which is a item of collection
|
||||||
|
# Input: line number
|
||||||
|
# Output: Array - range of detected collection
|
||||||
|
def coll_bounds(lnum)
|
||||||
|
ind = VIM::evaluate("indent(#{lnum})").to_i
|
||||||
|
start = fin = lnum
|
||||||
|
# Detect beginning of collection
|
||||||
|
ln = lnum - 1
|
||||||
|
while ln>0
|
||||||
|
curr_ind = VIM::evaluate("indent(#{ln})").to_i
|
||||||
|
break if curr_ind<ind || (curr_ind==ind && @buffer[ln]!~/\s*-/)
|
||||||
|
start = ln
|
||||||
|
ln = ln - 1
|
||||||
|
end
|
||||||
|
# Detect end of collection
|
||||||
|
ln = lnum + 1
|
||||||
|
while ln<=@buffer.count
|
||||||
|
curr_ind = VIM::evaluate("indent(#{ln})").to_i
|
||||||
|
break if curr_ind<ind || (curr_ind==ind && @buffer[ln]!~/\s*-/)
|
||||||
|
fin = ln
|
||||||
|
ln = ln + 1
|
||||||
|
end
|
||||||
|
[start,fin]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Parse data in YAML collection to separate collection's items
|
||||||
|
# Input: range of lines of collection in document
|
||||||
|
# Output: Array, each element is weight and Array of lines
|
||||||
|
def parse(range)
|
||||||
|
idx = -1
|
||||||
|
data = Array.new
|
||||||
|
ind = VIM::evaluate("indent(#{range[0]})").to_i
|
||||||
|
range[0].upto(range[1]) do |x|
|
||||||
|
if VIM::evaluate("indent(#{x})").to_i==ind
|
||||||
|
idx = idx+1
|
||||||
|
data[idx]=Array.new
|
||||||
|
data[idx][0]=Array.new
|
||||||
|
data[idx][1]=@buffer[x].scan(/\s*(.*)\s*$/) if @key.empty?
|
||||||
|
end
|
||||||
|
data[idx][1]=@buffer[x].scan(/:(.*)$/) if @buffer[x]=~/^#{@key}\s*:/
|
||||||
|
data[idx][0].push @buffer[x]
|
||||||
|
end
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sort collection.
|
||||||
|
# Input: parsed collection, sorting rule (lambda)
|
||||||
|
# Output: Sorted array of collection's lines
|
||||||
|
def resort(data, rule)
|
||||||
|
lines = Array.new
|
||||||
|
data.sort { |a,b|
|
||||||
|
if a[1].nil?
|
||||||
|
1
|
||||||
|
elsif b[1].nil?
|
||||||
|
-1
|
||||||
|
else
|
||||||
|
rule.call(a[1], b[1])
|
||||||
|
end
|
||||||
|
}.each { |x| x[0].each { |y| lines.push y }}
|
||||||
|
lines
|
||||||
|
end
|
||||||
|
|
||||||
|
# Replace lines of collection in document with sorted lines
|
||||||
|
def replace(range, lines)
|
||||||
|
range[0].upto(range[1]) {|x| @buffer[x] = lines[x-range[0]] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Init collection
|
||||||
|
#YCollection.new lambda {|a,b| b<=>a}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
" Vim script for vim-ruby for sorting yaml collections
|
||||||
|
" Requires: yamlsort.rb
|
||||||
|
" Author: Igor Vergeichik <iverg@mail.ru>
|
||||||
|
" Sponsor: Tom Sawyer <transami@transami.net>
|
||||||
|
" Copyright (c) 2002 Tom Saywer
|
||||||
|
|
||||||
|
ruby load '~/.vim/scripts/yamlsort.rb'
|
||||||
|
|
||||||
|
" Direct sort
|
||||||
|
function! YamlSort()
|
||||||
|
ruby YCollection.new lambda{|a,b| a<=>b}
|
||||||
|
endfunction
|
||||||
|
" Reverse sort
|
||||||
|
function! YamlRSort()
|
||||||
|
ruby YCollection.new lambda{|a,b| b<=>a}
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
map <F4> :call YamlSort()<CR>
|
||||||
|
map <F5> :call YamlRSort()<CR>
|
Loading…
Reference in New Issue