Skip to content

Commit

Permalink
Merge branch 'tag-finder'
Browse files Browse the repository at this point in the history
* tag-finder:
  Prepare tag-finder branch for merging into master
  Made it use vim's 'tags' variable to tag filename lookup
  Made it such that filenames in the tag list are optional
  Moved some functions around
  Added first version of tag plugin

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information
wincent committed Feb 21, 2012
2 parents 10ed0d9 + 57bc791 commit 93a5839
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .mailmap
@@ -1 +1,3 @@
Noon Silk <noonsilk@gmail.com> Noon Silk <noonsilk@gmail.com>
Noon Silk <noonsilk@gmail.com> Noon Silk <superhappyfun@gmail.com>
Sung Pae <sung@metablu.com> guns <sung@metablu.com>
18 changes: 17 additions & 1 deletion doc/command-t.txt
Expand Up @@ -340,6 +340,12 @@ COMMANDS *command-t-commands*
can persist across Vim sessions (see Vim's |jumplist|
documentation for more info).

*:CommandTTag*
|:CommandTTag| Brings up the Command-T window tags window, which can
be used to select from the tags, if any, returned by
Vim's |taglist()| function. See Vim's |tag| documentation
for general info on tags.

*:CommandTFlush*
|:CommandTFlush|Instructs the plug-in to flush its path cache, causing
the directory to be rescanned for new or deleted paths
Expand Down Expand Up @@ -488,6 +494,12 @@ Following is a list of all available options:
you want the best match to appear in a fixed location on the screen
but still be near the prompt at the bottom.

*g:CommandTTagIncludeFilenames*
|g:CommandTTagIncludeFilenames| boolean (default: 0)

When this setting is off (the default) the matches in the |:CommandTTag|
listing do not include filenames.

As well as the basic options listed above, there are a number of settings that
can be used to override the default key mappings used by Command-T. For
example, to set <C-x> as the mapping for cancelling (dismissing) the Command-T
Expand Down Expand Up @@ -589,6 +601,7 @@ order):
Marian Schubert
Matthew Todd
Mike Lundy
Noon Silk
Scott Bronson
Steven Moazami
Sung Pae
Expand Down Expand Up @@ -645,7 +658,7 @@ PayPal to win@wincent.com:

LICENSE *command-t-license*

Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
Copyright 2010-2012 Wincent Colaiuta. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand All @@ -670,6 +683,9 @@ POSSIBILITY OF SUCH DAMAGE.

HISTORY *command-t-history*

1.4 (not yet released)
- added |:CommandTTag| command (patches from Noon Silk)

1.3.1 (18 December 2011)

- fix jumplist navigation under Ruby 1.9.x (patch from Woody Peterson)
Expand Down
11 changes: 10 additions & 1 deletion plugin/command-t.vim
@@ -1,5 +1,5 @@
" command-t.vim
" Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
" Copyright 2010-2012 Wincent Colaiuta. All rights reserved.
"
" Redistribution and use in source and binary forms, with or without
" modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -29,6 +29,7 @@ let g:command_t_loaded = 1

command CommandTBuffer call <SID>CommandTShowBufferFinder()
command CommandTJump call <SID>CommandTShowJumpFinder()
command CommandTTag call <SID>CommandTShowTagFinder()
command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
command CommandTFlush call <SID>CommandTFlush()

Expand Down Expand Up @@ -71,6 +72,14 @@ function s:CommandTShowJumpFinder()
endif
endfunction

function s:CommandTShowTagFinder()
if has('ruby')
ruby $command_t.show_tag_finder
else
call s:CommandTRubyWarning()
endif
endfunction

function s:CommandTFlush()
if has('ruby')
ruby $command_t.flush
Expand Down
28 changes: 16 additions & 12 deletions ruby/command-t/controller.rb
@@ -1,4 +1,4 @@
# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
# Copyright 2010-2012 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand All @@ -24,6 +24,7 @@
require 'command-t/finder/buffer_finder'
require 'command-t/finder/jump_finder'
require 'command-t/finder/file_finder'
require 'command-t/finder/tag_finder'
require 'command-t/match_window'
require 'command-t/prompt'
require 'command-t/vim/path_utilities'
Expand All @@ -48,6 +49,12 @@ def show_jump_finder
show
end

def show_tag_finder
@path = VIM::pwd
@active_finder = tag_finder
show
end

def show_file_finder
# optional parameter will be desired starting directory, or ""
@path = File.expand_path(::VIM::evaluate('a:arg'), VIM::pwd)
Expand Down Expand Up @@ -75,6 +82,7 @@ def hide
def flush
@max_height = nil
@file_finder = nil
@tag_finder = nil
end

def handle_key
Expand Down Expand Up @@ -200,13 +208,6 @@ def get_list_or_string name
end
end

# Backslash-escape space, \, |, %, #, "
def sanitize_path_string str
# for details on escaping command-line mode arguments see: :h :
# (that is, help on ":") in the Vim documentation.
str.gsub(/[ \\|%#"]/, '\\\\\0')
end

def default_open_command
if !get_bool('&hidden') && get_bool('&modified')
'sp'
Expand Down Expand Up @@ -237,11 +238,9 @@ def ensure_appropriate_window_selection

def open_selection selection, options = {}
command = options[:command] || default_open_command
selection = File.expand_path selection, @path
selection = relative_path_under_working_directory selection
selection = sanitize_path_string selection

ensure_appropriate_window_selection
::VIM::command "silent #{command} #{selection}"
@active_finder.open_selection command, selection, options
end

def map key, function, param = nil
Expand Down Expand Up @@ -326,5 +325,10 @@ def file_finder
def jump_finder
@jump_finder ||= CommandT::JumpFinder.new
end

def tag_finder
@tag_finder ||= CommandT::TagFinder.new \
:include_filenames => get_bool('g:CommandTTagIncludeFilenames')
end
end # class Controller
end # module commandT
22 changes: 21 additions & 1 deletion ruby/command-t/finder.rb
@@ -1,4 +1,4 @@
# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
# Copyright 2010-2012 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand All @@ -22,6 +22,7 @@
# POSSIBILITY OF SUCH DAMAGE.

require 'command-t/ext' # CommandT::Matcher
require 'command-t/vim/path_utilities'

module CommandT
# Encapsulates a Scanner instance (which builds up a list of available files
Expand All @@ -31,6 +32,8 @@ module CommandT
# Specialized subclasses use different kinds of scanners adapted for
# different kinds of search (files, buffers).
class Finder
include VIM::PathUtilities

def initialize path = Dir.pwd, options = {}
raise RuntimeError, 'Subclass responsibility'
end
Expand All @@ -45,8 +48,25 @@ def flush
@scanner.flush
end

def open_selection command, selection, options = {}
selection = File.expand_path selection, @path
selection = relative_path_under_working_directory selection
selection = sanitize_path_string selection

::VIM::command "silent #{command} #{selection}"
end

def path= path
@scanner.path = path
end

private

# Backslash-escape space, \, |, %, #, "
def sanitize_path_string str
# for details on escaping command-line mode arguments see: :h :
# (that is, help on ":") in the Vim documentation.
str.gsub(/[ \\|%#"]/, '\\\\\0')
end
end # class Finder
end # CommandT
44 changes: 44 additions & 0 deletions ruby/command-t/finder/tag_finder.rb
@@ -0,0 +1,44 @@
# Copyright 2011-2012 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

require 'command-t/ext' # CommandT::Matcher
require 'command-t/scanner/tag_scanner'
require 'command-t/finder'

module CommandT
class TagFinder < Finder
def initialize options = {}
@scanner = TagScanner.new options
@matcher = Matcher.new @scanner, :always_show_dot_files => true
end

def open_selection command, selection, options = {}
if @scanner.include_filenames
selection = selection[0, selection.index(':')]
end

# open the tag and center the screen on it
::VIM::command "silent! tag #{selection} | :normal zz"
end
end # class TagFinder
end # module CommandT
1 change: 1 addition & 0 deletions ruby/command-t/scanner/jump_scanner.rb
Expand Up @@ -37,6 +37,7 @@ def paths
filenames = jumps_with_filename[1..-2].map do |line|
relative_path_under_working_directory line.split[3]
end

filenames.sort.uniq
end

Expand Down
49 changes: 49 additions & 0 deletions ruby/command-t/scanner/tag_scanner.rb
@@ -0,0 +1,49 @@
# Copyright 2011-2012 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

require 'command-t/vim'
require 'command-t/scanner'

module CommandT
class TagScanner < Scanner
attr_reader :include_filenames

def initialize options = {}
@include_filenames = options[:include_filenames] || false
end

def paths
taglist.map do |tag|
path = tag['name']
path << ":#{tag['filename']}" if @include_filenames
path
end.uniq.sort
end

private

def taglist
::VIM::evaluate 'taglist(".")'
end
end # class TagScanner
end # module CommandT
2 changes: 1 addition & 1 deletion ruby/command-t/stub.rb
Expand Up @@ -27,7 +27,7 @@ class Stub
'Please see INSTALLATION and TROUBLE-SHOOTING in the help',
'For more information type: :help command-t']

[:flush, :show_buffer_finder, :show_file_finder].each do |method|
[:flush, :show_buffer_finder, :show_file_finder, :show_tag_finder].each do |method|
define_method(method.to_sym) { warn *@@load_error }
end

Expand Down

0 comments on commit 93a5839

Please sign in to comment.