Created
September 2, 2017 17:30
-
-
Save henrik/d56cd7a4279205e23bed8ce7f4ecd791 to your computer and use it in GitHub Desktop.
WIP: Vim highlight private section of Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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