Skip to content

Instantly share code, notes, and snippets.

@henrik
Created September 2, 2017 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/d56cd7a4279205e23bed8ce7f4ecd791 to your computer and use it in GitHub Desktop.
Save henrik/d56cd7a4279205e23bed8ce7f4ecd791 to your computer and use it in GitHub Desktop.
WIP: Vim highlight private section of Ruby
function! Snake()
ruby << EOF
b = Vim::Buffer.current
line_count = b.length
indexed_lines = line_count.times.map { |i| [ i, b[i + 1] ] }
matches = indexed_lines.select { |i, line| line.match(/^\s+private$/) }
matches.each { |priv_i, priv_text|
re = /^#{priv_text.sub(" private", "end")}$/
end_i, _ = indexed_lines[priv_i..-1].find { |i, line| line.match(re) }
from_line = priv_i + 1
to_line = end_i + 1
p [ from_line, to_line ]
Vim::command %{call matchadd('Error', '\\%>#{from_line}l\\%<#{to_line}l.*')}
}
EOF
endfunction
command! Snake :call Snake()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment