Skip to content

Commit

Permalink
Prepare tag-finder branch for merging into master
Browse files Browse the repository at this point in the history
This commit prepare's the tag-finder contributed by Noon Silk for
merging into master. Changes made:

  - Add Noon to the .mailmap file, as his commits use two distinct email
    addresses
  - flesh out the CommandTTag documentation
  - add documentation for the g:CommandTTagIncludeFilenames setting,
    which itself was renamed from underscore-style to CamelCase for
    consistency with the other settings
  - added Noon to the AUTHORS section in the documentation
  - updated copyright year ranges in touched files
  - remove default setting of g:command_t_tag_include_filenames
    preference from the main plug-in file, for consistency with other
    settings (where defaults are handled when initializing Finders and
    Scanners)
  - get rid of the controller's @tag_finder instance when the user runs
    CommandTFlush; this means that you can change the value of
    g:CommandTTagIncludeFilenames and force Command-T to use the new
    setting without having to alter the setting in your ~/.vimrc and
    restart Vim
  - removed commented-out code
  - removed or fixed whitespace-damaged files (trailing whitespace and
    incorrect indentation)
  - changed TagFinder#open_selection to extract tag portion of the
    selection without calling #split (guard against unnecessary work in
    pathological case that filename contains colons)
  - open tags using `silent!` rather than `silent` (suppresses "E432:
    Tags file not sorted" warning for non-sorted tags files)
  - removed unneeded inclusion of VIM::PathUtilities in TagScanner
  - use Vim's `taglist()` function to get tags rather than opening and
    parsing tags files directly (insulate Command-T from differences in
    the different tag file formats that Vim supports)

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information
wincent committed Feb 21, 2012
1 parent 02916e4 commit 57bc791
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -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: 15 additions & 3 deletions doc/command-t.txt
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ COMMANDS *command-t-commands*
documentation for more info).

*:CommandTTag*
|:CommandTTag| Brings up a Command-T window for tags (see Vim's |tag|
documentation for more info).
|: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
Expand Down Expand Up @@ -492,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 @@ -593,6 +601,7 @@ order):
Marian Schubert
Matthew Todd
Mike Lundy
Noon Silk
Scott Bronson
Steven Moazami
Sung Pae
Expand Down Expand Up @@ -649,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 @@ -674,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
7 changes: 1 addition & 6 deletions plugin/command-t.vim
Original file line number Diff line number Diff line change
@@ -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 All @@ -26,7 +26,6 @@ if exists("g:command_t_loaded")
finish
endif
let g:command_t_loaded = 1
let g:command_t_tag_include_filenames = 0

command CommandTBuffer call <SID>CommandTShowBufferFinder()
command CommandTJump call <SID>CommandTShowJumpFinder()
Expand All @@ -42,10 +41,6 @@ if !hasmapto(':CommandTBuffer<CR>')
silent! nnoremap <unique> <silent> <Leader>b :CommandTBuffer<CR>
endif

if !hasmapto(':CommandTTag<CR>')
silent! nnoremap <unique> <silent> <Leader>f :CommandTTag<CR>
endif

function s:CommandTRubyWarning()
echohl WarningMsg
echo "command-t.vim requires Vim to be compiled with Ruby support"
Expand Down
11 changes: 4 additions & 7 deletions ruby/command-t/controller.rb
Original file line number Diff line number Diff line change
@@ -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 Down Expand Up @@ -82,6 +82,7 @@ def hide
def flush
@max_height = nil
@file_finder = nil
@tag_finder = nil
end

def handle_key
Expand Down Expand Up @@ -238,11 +239,6 @@ def ensure_appropriate_window_selection
def open_selection selection, options = {}
command = options[:command] || default_open_command

# The following has been moved to 'finder.rb'
# selection = File.expand_path selection, @path
# selection = relative_path_under_working_directory selection
# selection = sanitize_path_string selection

ensure_appropriate_window_selection
@active_finder.open_selection command, selection, options
end
Expand Down Expand Up @@ -331,7 +327,8 @@ def jump_finder
end

def tag_finder
@tag_finder ||= CommandT::TagFinder.new
@tag_finder ||= CommandT::TagFinder.new \
:include_filenames => get_bool('g:CommandTTagIncludeFilenames')
end
end # class Controller
end # module commandT
19 changes: 8 additions & 11 deletions ruby/command-t/finder.rb
Original file line number Diff line number Diff line change
@@ -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 Down Expand Up @@ -49,22 +49,19 @@ def flush
end

def open_selection command, selection, options = {}
# Default implementation, children can re-implement this at their leisure.

selection = File.expand_path selection, @path
selection = relative_path_under_working_directory selection
selection = sanitize_path_string selection

::VIM::command "silent #{command} #{selection}"
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 :
Expand Down
19 changes: 9 additions & 10 deletions ruby/command-t/finder/tag_finder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2011 Wincent Colaiuta. All rights reserved.
# 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:
Expand Down Expand Up @@ -27,19 +27,18 @@

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

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

# Opens the tag and centers the screen on it.
::VIM::command "silent tag #{tagname} | :normal zz"
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
44 changes: 14 additions & 30 deletions ruby/command-t/scanner/tag_scanner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2011 Wincent Colaiuta. All rights reserved.
# 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:
Expand All @@ -22,44 +22,28 @@
# POSSIBILITY OF SUCH DAMAGE.

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

module CommandT
class TagScanner < Scanner
include VIM::PathUtilities
attr_reader :include_filenames

def paths
tokens = Array.new

tag_filenames.each { |tagfile|
if FileTest.exist?(tagfile)
File.open(tagfile).each { |line|
# Don't want comments
data = line.split if line.match(/^[^!]/)

if data
if include_filenames
identifier = data[0] + ":" + data[1]
else
identifier = data[0]
end
tokens.push identifier
end
}
end
}

tokens.sort.uniq
def initialize options = {}
@include_filenames = options[:include_filenames] || false
end

def tag_filenames
tags = VIM::capture("silent set tags?")
tags = tags[5,tags.length].split(',')
def paths
taglist.map do |tag|
path = tag['name']
path << ":#{tag['filename']}" if @include_filenames
path
end.uniq.sort
end

def include_filenames
::VIM::evaluate("g:command_t_tag_include_filenames").to_i != 0
private

def taglist
::VIM::evaluate 'taglist(".")'
end
end # class TagScanner
end # module CommandT

0 comments on commit 57bc791

Please sign in to comment.