Skip to content

Commit

Permalink
Closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszkorecki committed Mar 6, 2012
1 parent b2a4db6 commit 65a2e1b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 22 deletions.
38 changes: 16 additions & 22 deletions lib/CoffeeTags.rb
Expand Up @@ -3,6 +3,7 @@
require "CoffeeTags/parser"
require "CoffeeTags/formatter"
require 'optparse'
require 'erb'

class Object
def blank?
Expand All @@ -21,41 +22,30 @@ module Coffeetags

class Utils
def self.tagbar_conf include_vars
<<-CONF
" Add this type definition to your vimrc
" coffeetags --vim-conf >> <PATH TO YOUR VIMRC>
" if you want your tags to include vars/objects do:
" coffeetags --vim-conf --include-vars
let g:tagbar_type_coffee = {
\\ 'kinds' : [
\\ 'f:functions',
\\ 'o:object'
\\ ],
\\ 'kind2scope' : {
\\ 'f' : 'object',
\\ 'o' : 'object'
\\},
\\ 'sro' : ".",
\\ 'ctagsbin' : 'coffeetags',
\\ 'ctagsargs' : '#{include_vars ? "--include-vars" : "" } ',
\\}
CONF
include_vars_opt = include_vars ? "--include-vars" : ''

tmpl_file = File.read(File.expand_path("../../vim/tagbar-coffee.vim.erb", __FILE__))
tmpl = ERB.new(tmpl_file)

tmpl.result(binding)
end

def self.option_parser args
args << '-h' if args.empty?
options = {}
optparse = OptionParser.new do |opts|

opts.banner = (<<-BAN
#{NAME} #{Coffeetags::VERSION}
by #{AUTHOR} ( #{URL} )
Usage:
coffeetags [OPTIONS] <list of files>
CoffeeTags + TagBar + Vim ---> https://gist.github.com/1935512
BAN
).gsub(/^\s*/,'')

opts.on('-i', '--include-vars', "Include variables in generated tags") do |o|

opts.on('--include-vars', "Include variables in generated tags") do |o|
options[:include_vars] = true
end

Expand All @@ -68,10 +58,14 @@ def self.option_parser args
options[:recur] = true
end

opts.on('--vim-conf', 'Generate TagBar config (more info https://gist.github.com/1935512 )') do
puts tagbar_conf options[:include_vars]
exit
end

opts.on('-v', '--version', 'Current version') do
puts Coffeetags::VERSION
exit

end

opts.on('-h','--help','HALP') do
Expand Down
40 changes: 40 additions & 0 deletions tagbar-info.markdown
@@ -0,0 +1,40 @@
# How to use CoffeeTags with [TagBar ](https://github.com/majutsushi/tagbar)

## Config types

CoffeeTags can work in 2 modes:

- tags only for functions (default)
- tags for functions and objects containing them

Second mode is activated by adding --include-vars to command line arguments

# CoffeeTags + TagBar + Vim

## Config in vimrc

You can add the config to your .vimrc (making sure that the old one is removed)
by:

coffeetags --vim-conf >> ~/.vimrc

or (for 2nd mode)

coffeetags --include-vars --vim-conf >> ~/.vimrc


## Config as a filetype plugin

You can generate a special filetype plugin and tagbar will use that
automatically.

This option is preferable if you want to keep your vimrc short.

coffeetags --vim-conf > ~/vim/ftplugin/coffee/tagbar-coffee.vim
coffeetags [--include-vars] --vim-conf > ~/vim/ftplugin/coffee/tagbar-coffee.vim

or if you're using pathogen

coffeetags [--include-vars] --vim-conf > ~/vim/bundle/coffeetags/ftplugin/coffee/tagbar-coffee.vim
coffeetags --vim-conf > ~/vim/bundle/coffeetags/ftplugin/coffee/tagbar-coffee.vim

15 changes: 15 additions & 0 deletions vim/tagbar-coffee.vim.erb
@@ -0,0 +1,15 @@
if executable('coffeetags')
let g:tagbar_type_coffee = {
\ 'ctagsbin' : 'coffeetags',
\ 'ctagsargs' : '<%= include_vars_opt %>',
\ 'kinds' : [
\ 'f:functions',
\ 'o:object',
\ ],
\ 'sro' : ".",
\ 'kind2scope' : {
\ 'f' : 'object',
\ 'o' : 'object',
\ }
\ }
endif

0 comments on commit 65a2e1b

Please sign in to comment.