From: Ben Beltran Date: Mon, 8 Oct 2012 16:44:10 +0000 (-0500) Subject: Add vim again :) X-Git-Url: https://git.r.bdr.sh/rbdr/dotfiles/commitdiff_plain/0d23b6e515a01a5782532351821ebfa11f3d6cf2?ds=sidebyside;hp=--cc Add vim again :) --- 0d23b6e515a01a5782532351821ebfa11f3d6cf2 diff --git a/vim/.VimballRecord b/vim/.VimballRecord new file mode 100644 index 0000000..058155c --- /dev/null +++ b/vim/.VimballRecord @@ -0,0 +1,4 @@ +command-t-1.3.1.vba: call delete('/Users/benbeltran/.vim/ruby/command-t/controller.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/extconf.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/finder/buffer_finder.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/finder/file_finder.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/finder/jump_finder.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/finder.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/match_window.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/prompt.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/scanner/buffer_scanner.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/scanner/file_scanner.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/scanner/jump_scanner.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/scanner.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/settings.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/stub.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/vim/path_utilities.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/vim/screen.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/vim/window.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/vim.rb')|call delete('/Users/benbeltran/.vim/ruby/command-t/ext.c')|call delete('/Users/benbeltran/.vim/ruby/command-t/match.c')|call delete('/Users/benbeltran/.vim/ruby/command-t/matcher.c')|call delete('/Users/benbeltran/.vim/ruby/command-t/ext.h')|call delete('/Users/benbeltran/.vim/ruby/command-t/match.h')|call delete('/Users/benbeltran/.vim/ruby/command-t/matcher.h')|call delete('/Users/benbeltran/.vim/ruby/command-t/ruby_compat.h')|call delete('/Users/benbeltran/.vim/ruby/command-t/depend')|call delete('/Users/benbeltran/.vim/doc/command-t.txt')|call delete('/Users/benbeltran/.vim/plugin/command-t.vim') +supertab.vba: call delete('/Users/benbeltran/.vim/doc/supertab.txt')|call delete('/Users/benbeltran/.vim/plugin/supertab.vim') +tagbar.vmb: call delete('/Users/benbeltran/.vim/autoload/tagbar.vim')|call delete('/Users/benbeltran/.vim/doc/tagbar.txt')|call delete('/Users/benbeltran/.vim/plugin/tagbar.vim')|call delete('/Users/benbeltran/.vim/syntax/tagbar.vim') +delimitMate-2.6.vba: call delete('/Users/benbeltran/.vim/plugin/delimitMate.vim')|call delete('/Users/benbeltran/.vim/autoload/delimitMate.vim')|call delete('/Users/benbeltran/.vim/doc/delimitMate.txt') diff --git a/vim/.netrwhist b/vim/.netrwhist new file mode 100644 index 0000000..ac734e4 --- /dev/null +++ b/vim/.netrwhist @@ -0,0 +1,4 @@ +let g:netrw_dirhistmax =10 +let g:netrw_dirhist_cnt =2 +let g:netrw_dirhist_1='/Users/benbeltran/.newsbeuter' +let g:netrw_dirhist_2='/Users/benbeltran/.vim' diff --git a/vim/CHANGELOG b/vim/CHANGELOG new file mode 100644 index 0000000..040e0e8 --- /dev/null +++ b/vim/CHANGELOG @@ -0,0 +1,18 @@ +2010-12-29 wycats + + * FEATURE: Opening with an explicit directory starts on NERDTree + * FEATURE: If you close the last window before NERDTree, close NERDTree + * EXTERNAL: Block insert mode in NERDTree [wycats/nerdtree] + * FEATURE: Add a Mkdir NERDTree/Command-T aware alias + +2010-12-28 wycats + + * TAG: 0.9.0 + * BUGFIX: Interaction bug between NERDTree and ZoomWin + * BUGFIX: Arrow keys not working in xterm [akatz] + * FEATURE: SearchFold + * FEATURE: Refresh NERDTree and CommandT on refocus + * FEATURE: triggers ZoomWin + * FEATURE: JSLint plugin + * FEATURE: Improved, more modern-looking NERDTree + * FEATURE: irblack theme (now default) diff --git a/vim/README.markdown b/vim/README.markdown new file mode 100644 index 0000000..96b3193 --- /dev/null +++ b/vim/README.markdown @@ -0,0 +1,303 @@ +# Janus: Carlhuda's vim Distribution + +This is a basic distribution of vim plugins and tools intended to be run +on top of the latest MacVIM snapshot. + +We (Carl and Yehuda) both use this distribution for our own use, and +welcome patches and contributions to help make it an effective way to +get started with vim and then use it productively for years to come. + +At present, we are still learning to use vim ourselves, so you should +anticipate a period of rapid development while we get a handle on the +best tools for the job. So far, we have mostly integrated existing +plugins and tools, and we anticipate to continue doing so while also +writing our own plugins as appropriate. + +In general, you can expect that the tools we use work well together and +that we have given careful thought to the experience of using MacVIM +with the tools in question. If you run into an issue using it, please +report an issue to the issue tracker. + +## Pre-requisites + +Janus is built primarily for [MacVim](http://code.google.com/p/macvim/) on OSX. +Download it [here](https://github.com/b4winckler/macvim/downloads). + +Alternatively, you can use Janus with the bundled console `vim` installation on +OSX (via Terminal), or with any other `vim` or `gvim` installation. + +Linux users can install `gvim` for an experience identical to MacVim. +On Debian/Ubuntu, simply `apt-get install vim-gnome`. For remote +servers, install console vim with `apt-get install vim-nox`. + +On a fresh Ubuntu install you also have to install the packages `rake` and `ruby-dev` +before running the install script and `exuberant-ctags` for ctags +support. + +## Installation + +0. `for i in ~/.vim ~/.vimrc ~/.gvimrc; do [ -e $i ] && mv $i $i.old; + done` +1. `git clone git://github.com/carlhuda/janus.git ~/.vim` +2. `cd ~/.vim` +3. `rake` + +or + + `curl https://raw.github.com/carlhuda/janus/master/bootstrap.sh -o - | sh` + +## Customization + +Create `~/.vimrc.local` and `~/.gvimrc.local` for any local +customizations. + +For example, to override the default color schemes: + + echo color desert > ~/.vimrc.local + echo color molokai > ~/.gvimrc.local + +If you want to add additional Vim plugins you can do so by adding a +`~/.janus.rake` like so: + + vim_plugin_task "zencoding", "git://github.com/mattn/zencoding-vim.git" + vim_plugin_task "minibufexpl", "git://github.com/fholgado/minibufexpl.vim.git" + +If you do not wish to use one of the plugins Janus provides out of the +box you can have it skipped using the `skip_vim_plugin` method in +`~/.janus.rake`: + + skip_vim_plugin "color-sampler" + +**Note**: Skipping the plugin will only apply to installation. It won't +remove configurations or mappings Janus might have added for it. + +## Updating to the latest version + +To update to the latest version of the distribution, just run `rake` +again inside your `~/.vim` directory. + +# Intro to VIM + +Here's some tips if you've never used VIM before: + +## Tutorials + +* Type `vimtutor` into a shell to go through a brief interactive + tutorial inside VIM. +* Read the slides at [VIM: Walking Without Crutches](http://walking-without-crutches.heroku.com/#1). +* Watch the screencasts at [vimcasts.org](http://vimcasts.org/) +* Watch Derek Wyatt's energetic tutorial videos at [his site](http://www.derekwyatt.org/vim/vim-tutorial-videos/) +* Read wycats' perspective on learning vim at + [Everyone who tried to convince me to use vim was wrong](http://yehudakatz.com/2010/07/29/everyone-who-tried-to-convince-me-to-use-vim-was-wrong/) +* Read this and other answers to a question about vim at StackOverflow: + [Your problem with Vim is that you don't grok vi](http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118) + +## Modes + +* VIM has two modes: + * insert mode- stuff you type is added to the buffer + * normal mode- keys you hit are interpretted as commands +* To enter insert mode, hit `i` +* To exit insert mode, hit `` + +## Useful commands + +* Use `:q` to exit vim +* Certain commands are prefixed with a `` key, which maps to `\` + by default. Use `let mapleader = ","` to change this. +* Keyboard [cheat sheet](http://walking-without-crutches.heroku.com/image/images/vi-vim-cheat-sheet.png). + +# Features + +This vim distribution includes a number of packages built by others. + +## Base Customizations + +Janus ships with a number of basic customizations for vim: + +* Line numbers +* Ruler (line and column numbers) +* No wrap (turn off per-buffer via set :wrap) +* Soft 2-space tabs, and default hard tabs to 2 spaces +* Show tailing whitespace as `.` +* Make searching highlighted, incremental, and case insensitive unless a + capital letter is used +* Always show a status line +* Allow backspacing over everything (identations, eol, and start + characters) in insert mode +* `e` expands to `:e {directory of current file}/` (open in the + current buffer) +* `tr` expands to `:te {directory of current file}/` (open in a + new MacVIM tab) +* `` inserts the directory of the current file into a command + +## "Project Drawer" aka [NERDTree](http://github.com/wycats/nerdtree) + +NERDTree is a file explorer plugin that provides "project drawer" +functionality to your vim projects. You can learn more about it with +:help NERDTree. + +**Customizations**: Janus adds a number of customizations to the core +NERDTree: + +* Use `n` to toggle NERDTree +* Ignore `*.rbc` and `*~` files +* Automatically activate NERDTree when MacVIM opens and make the + original buffer the active one +* Provide alternative :e, :cd, :rm and :touch abbreviations which also + refresh NERDTree when done (when NERDTree is open) +* When opening vim with vim /path, open the left NERDTree to that + directory, set the vim pwd, and clear the right buffer +* Disallow `:e`ing files into the NERDTree buffer +* In general, assume that there is a single NERDTree buffer on the left + and one or more editing buffers on the right + +## [Ack.vim](http://github.com/mileszs/ack.vim) + + +Ack.vim uses ack to search inside the current directory for a pattern. +You can learn more about it with :help Ack + +**Customizations**: Janus rebinds command-shift-f (``) to bring up +`:Ack `. + +## [Align](http://github.com/tsaleh/vim-align) + +Align lets you align statements on their equal signs, make comment +boxes, align comments, align declarations, etc. + +* `:5,10Align =>` to align lines 5-10 on `=>`'s + +## [Command-T](https://wincent.com/products/command-t) + +Command-T provides a mechanism for searching for a file inside the +current working directory. It behaves similarly to command-t in +Textmate. + +**Customizations**: Janus rebinds command-t (``) to bring up this +plugin. It defaults to `t`. + +## [ConqueTerm](http://code.google.com/p/conque/) + +ConqueTerm embeds a basic terminal inside a vim buffer. The terminal has +an insert mode in which you can type commands, tab complete and use the +terminal like normal. You can also escape out of insert mode to use +other vim commands on the buffer, like yank and paste. + +**Customizations**: Janus binds command-e (``) to bring up +`:ConqueTerm bash --login` in the current buffer. + +**Note**: To get colors working, you might have to `export TERM=xterm` +and use `ls -G` or `gls --color` + +## [indent\_object](http://github.com/michaeljsmith/vim-indent-object) + +Indent object creates a "text object" that is relative to the current +ident. Text objects work inside of visual mode, and with `c` (change), +`d` (delete) and `y` (yank). For instance, try going into a method in +normal mode, and type `v ii`. Then repeat `ii`. + +**Note**: indent\_object seems a bit busted. It would also be nice if +there was a text object for Ruby `class` and `def` blocks. + +## [surround](http://github.com/tpope/vim-surround) + +Surround allows you to modify "surroundings" around the current text. +For instance, if the cursor was inside `"foo bar"`, you could type +`cs"'` to convert the text to `'foo bar'`. + +There's a lot more; check it out at `:help surround` + +## [NERDCommenter](http://github.com/ddollar/nerdcommenter) + +NERDCommenter allows you to wrangle your code comments, regardless of +filetype. View `:help NERDCommenter` for all the details. + +**Customizations**: Janus binds command-/ (``) to toggle comments. + +## [SuperTab](http://github.com/ervandew/supertab) + +In insert mode, start typing something and hit `` to tab-complete +based on the current context. + +## ctags + +Janus includes the [TagList](http://github.com/vim-scripts/taglist.vim) +plugin, which binds `:Tlist` to an overview panel that lists all ctags +for easy navigation. + +**Customizations**: Janus binds `rt` to the ctags command to +update tags. + +**Note**: For full language support, run `brew install ctags` to install +exuberant-ctags. + +**Tip**: Check out `:help ctags` for information about VIM's built-in +ctag support. Tag navigation creates a stack which can traversed via +`Ctrl-]` (to find the source of a token) and `Ctrl-T` (to jump back up +one level). + +## Git Support ([Fugitive](http://github.com/tpope/vim-fugitive)) + +Fugitive adds pervasive git support to git directories in vim. For more +information, use `:help fugitive` + +Use `:Gstatus` to view `git status` and type `-` on any file to stage or +unstage it. Type `p` on a file to enter `git add -p` and stage specific +hunks in the file. + +Use `:Gdiff` on an open file to see what changes have been made to that +file + +## [Gist-vim](http://github.com/mattn/gist-vim) + +Nice [gist integration](https://github.com/mattn/gist-vim) by mattn. +Requires exporting your `GITHUB_TOKEN` and `GITHUB_USER` as environment +variables or setup your [GitHub token config](http://help.github.com/git-email-settings/). + +Try `:Gist`, `:Gist -p` and visual blocks. + +## [ZoomWin](http://github.com/vim-scripts/ZoomWin) + +When working with split windows, ZoomWin lets you zoom into a window and +out again using `Ctrl-W o` + +**Customizations**: Janus binds `` to `:ZoomWin` + +## Additional Syntaxes + +Janus ships with a few additional syntaxes: + +* Markdown (bound to \*.markdown, \*.md, and \*.mk) +* Mustache (bound to \*.mustache) +* Arduino (bound to \*.pde) +* Haml (bound to \*.haml) +* Sass (bound to \*.sass) +* SCSS (bound to \*.scss) +* An improved JavaScript syntax (bound to \*.js) +* Map Gemfile, Rakefile, Vagrantfile and Thorfile to Ruby +* Git commits (set your `EDITOR` to `mvim -f`) + +## Color schemes + +Janus includes the vim color sampler pack, which includes [over 100 +popular color themes](http://www.vi-improved.org/color_sampler_pack/): + +* jellybeans +* matrix +* railscasts2 +* tango +* vibrantink +* vividchalk +* wombat +* xoria256 + +Use `:color vibrantink` to switch to a color scheme. + +Janus also has a few customized versions of popular themes: + +* jellybeans+ +* molokai +* railscasts+ +* vwilight + diff --git a/vim/Rakefile b/vim/Rakefile new file mode 100644 index 0000000..d2c938d --- /dev/null +++ b/vim/Rakefile @@ -0,0 +1,247 @@ +module VIM + Dirs = %w[ after autoload doc plugin ruby snippets syntax ftdetect ftplugin colors indent ] +end + +directory "tmp" +VIM::Dirs.each do |dir| + directory(dir) +end + +def vim_plugin_task(name, repo=nil) + cwd = File.expand_path("../", __FILE__) + dir = File.expand_path("tmp/#{name}") + subdirs = VIM::Dirs + + namespace(name) do + if repo + file dir => "tmp" do + if repo =~ /git$/ + sh "git clone #{repo} #{dir}" + + elsif repo =~ /download_script/ + if filename = `curl --silent --head #{repo} | grep attachment`[/filename=(.+)/,1] + filename.strip! + sh "curl #{repo} > tmp/#{filename}" + else + raise ArgumentError, 'unable to determine script type' + end + + elsif repo =~ /(tar|gz|vba|zip)$/ + filename = File.basename(repo) + sh "curl #{repo} > tmp/#{filename}" + + else + raise ArgumentError, 'unrecognized source url for plugin' + end + + case filename + when /zip$/ + sh "unzip -o tmp/#{filename} -d #{dir}" + + when /tar\.gz$/ + dirname = File.basename(filename, '.tar.gz') + + sh "tar zxvf tmp/#{filename}" + sh "mv #{dirname} #{dir}" + + when /vba(\.gz)?$/ + if filename =~ /gz$/ + sh "gunzip -f tmp/#{filename}" + filename = File.basename(filename, '.gz') + end + + # TODO: move this into the install task + mkdir_p dir + lines = File.readlines("tmp/#{filename}") + current = lines.shift until current =~ /finish$/ # find finish line + + while current = lines.shift + # first line is the filename (possibly followed by garbage) + # some vimballs use win32 style path separators + path = current[/^(.+?)(\t\[{3}\d)?$/, 1].gsub '\\', '/' + + # then the size of the payload in lines + current = lines.shift + num_lines = current[/^(\d+)$/, 1].to_i + + # the data itself + data = lines.slice!(0, num_lines).join + + # install the data + Dir.chdir dir do + mkdir_p File.dirname(path) + File.open(path, 'w'){ |f| f.write(data) } + end + end + end + end + + task :pull => dir do + if repo =~ /git$/ + Dir.chdir dir do + sh "git pull" + end + end + end + + task :install => [:pull] + subdirs do + Dir.chdir dir do + if File.exists?("Rakefile") and `rake -T` =~ /^rake install/ + sh "rake install" + elsif File.exists?("install.sh") + sh "sh install.sh" + else + subdirs.each do |subdir| + if File.exists?(subdir) + sh "cp -RfL #{subdir}/* #{cwd}/#{subdir}/" + end + end + end + end + + yield if block_given? + end + else + task :install => subdirs do + yield if block_given? + end + end + end + + desc "Install #{name} plugin" + task name do + puts + puts "*" * 40 + puts "*#{"Installing #{name}".center(38)}*" + puts "*" * 40 + puts + Rake::Task["#{name}:install"].invoke + end + task :default => name +end + +def skip_vim_plugin(name) + Rake::Task[:default].prerequisites.delete(name) +end + +vim_plugin_task "ack.vim", "git://github.com/mileszs/ack.vim.git" +vim_plugin_task "color-sampler", "git://github.com/vim-scripts/Color-Sampler-Pack.git" +vim_plugin_task "conque", "http://conque.googlecode.com/files/conque_1.1.tar.gz" +vim_plugin_task "fugitive", "git://github.com/tpope/vim-fugitive.git" +vim_plugin_task "git", "git://github.com/tpope/vim-git.git" +vim_plugin_task "haml", "git://github.com/tpope/vim-haml.git" +vim_plugin_task "indent_object", "git://github.com/michaeljsmith/vim-indent-object.git" +vim_plugin_task "javascript", "git://github.com/pangloss/vim-javascript.git" +vim_plugin_task "nerdtree", "git://github.com/wycats/nerdtree.git" +vim_plugin_task "nerdcommenter", "git://github.com/ddollar/nerdcommenter.git" +vim_plugin_task "surround", "git://github.com/tpope/vim-surround.git" +vim_plugin_task "taglist", "git://github.com/vim-scripts/taglist.vim.git" +vim_plugin_task "vividchalk", "git://github.com/tpope/vim-vividchalk.git" +vim_plugin_task "solarized", "git://github.com/altercation/vim-colors-solarized.git" +vim_plugin_task "supertab", "git://github.com/ervandew/supertab.git" +vim_plugin_task "cucumber", "git://github.com/tpope/vim-cucumber.git" +vim_plugin_task "textile", "git://github.com/timcharper/textile.vim.git" +vim_plugin_task "rails", "git://github.com/tpope/vim-rails.git" +vim_plugin_task "rspec", "git://github.com/taq/vim-rspec.git" +vim_plugin_task "zoomwin", "git://github.com/vim-scripts/ZoomWin.git" +vim_plugin_task "snipmate", "git://github.com/msanders/snipmate.vim.git" +vim_plugin_task "markdown", "git://github.com/tpope/vim-markdown.git" +vim_plugin_task "align", "git://github.com/tsaleh/vim-align.git" +vim_plugin_task "unimpaired", "git://github.com/tpope/vim-unimpaired.git" +vim_plugin_task "searchfold", "git://github.com/vim-scripts/searchfold.vim.git" +vim_plugin_task "endwise", "git://github.com/tpope/vim-endwise.git" +vim_plugin_task "irblack", "git://github.com/wgibbs/vim-irblack.git" +vim_plugin_task "vim-coffee-script","git://github.com/kchmck/vim-coffee-script.git" +vim_plugin_task "syntastic", "git://github.com/scrooloose/syntastic.git" +vim_plugin_task "puppet", "git://github.com/ajf/puppet-vim.git" +vim_plugin_task "scala", "git://github.com/bdd/vim-scala.git" +vim_plugin_task "gist-vim", "git://github.com/mattn/gist-vim.git" + +#vim_plugin_task "hammer", "git://github.com/robgleeson/hammer.vim.git" do +# sh "gem install github-markup redcarpet" +#end + +vim_plugin_task "janus_themes" do + # custom version of railscasts theme + File.open(File.expand_path("../colors/railscasts+.vim", __FILE__), "w") do |file| + file.puts <<-VIM.gsub(/^ +/, "").gsub("", " ") + runtime colors/railscasts.vim + let g:colors_name = "railscasts+" + + set fillchars=vert:\\ + set fillchars=stl:\\ + set fillchars=stlnc:\\ + hi StatusLine guibg=#cccccc guifg=#000000 + hi VertSplit guibg=#dddddd + VIM + end + + # custom version of jellybeans theme + File.open(File.expand_path("../colors/jellybeans+.vim", __FILE__), "w") do |file| + file.puts <<-VIM.gsub(/^ /, "") + runtime colors/jellybeans.vim + let g:colors_name = "jellybeans+" + + hi VertSplit guibg=#888888 + hi StatusLine guibg=#cccccc guifg=#000000 + hi StatusLineNC guibg=#888888 guifg=#000000 + VIM + end +end + +vim_plugin_task "molokai" do + sh "curl https://raw.github.com/mrtazz/molokai.vim/master/colors/molokai.vim > colors/molokai.vim" +end +vim_plugin_task "mustache" do + sh "curl https://raw.github.com/defunkt/mustache/master/contrib/mustache.vim > syntax/mustache.vim" + File.open(File.expand_path('../ftdetect/mustache.vim', __FILE__), 'w') do |file| + file << "au BufNewFile,BufRead *.mustache setf mustache" + end +end +vim_plugin_task "arduino","git://github.com/vim-scripts/Arduino-syntax-file.git" do + File.open(File.expand_path('../ftdetect/arduino.vim', __FILE__), 'w') do |file| + file << "au BufNewFile,BufRead *.pde setf arduino" + end +end +vim_plugin_task "vwilight" do + sh "curl https://raw.github.com/gist/796172/724c7ca237a7f6b8d857c4ac2991cfe5ffb18087 > colors/vwilight.vim" +end + +if File.exists?(janus = File.expand_path("~/.janus.rake")) + puts "Loading your custom rake file" + import(janus) +end + +desc "Update the documentation" +task :update_docs do + puts "Updating VIM Documentation..." + system "vim -e -s <<-EOF\n:helptags ~/.vim/doc\n:quit\nEOF" +end + +desc "link vimrc to ~/.vimrc" +task :link_vimrc do + %w[ vimrc gvimrc ].each do |file| + dest = File.expand_path("~/.#{file}") + unless File.exist?(dest) + ln_s(File.expand_path("../#{file}", __FILE__), dest) + end + end +end + +task :clean do + system "git clean -dfx" +end + +desc "Pull the latest" +task :pull do + system "git pull" +end + +task :default => [ + :update_docs, + :link_vimrc +] + +desc "Clear out all build artifacts and rebuild the latest Janus" +task :upgrade => [:clean, :pull, :default] + diff --git a/vim/after/plugin/snipMate.vim b/vim/after/plugin/snipMate.vim new file mode 100644 index 0000000..bdbe199 --- /dev/null +++ b/vim/after/plugin/snipMate.vim @@ -0,0 +1,40 @@ +" These are the mappings for snipMate.vim. Putting it here ensures that it +" will be mapped after other plugins such as supertab.vim. +if !exists('loaded_snips') || exists('s:did_snips_mappings') + finish +endif +let s:did_snips_mappings = 1 + +" This is put here in the 'after' directory in order for snipMate to override +" other plugin mappings (e.g., supertab). +" +" You can safely adjust these mappings to your preferences (as explained in +" :help snipMate-remap). +ino =TriggerSnippet() +snor i=TriggerSnippet() +ino =BackwardsSnippet() +snor i=BackwardsSnippet() +ino =ShowAvailableSnips() + +" The default mappings for these are annoying & sometimes break snipMate. +" You can change them back if you want, I've put them here for convenience. +snor b +snor a +snor bi +snor ' b' +snor ` b` +snor % b% +snor U bU +snor ^ b^ +snor \ b\ +snor b + +" By default load snippets in snippets_dir +if empty(snippets_dir) + finish +endif + +call GetSnippets(snippets_dir, '_') " Get global snippets + +au FileType * if &ft != 'help' | call GetSnippets(snippets_dir, &ft) | endif +" vim:noet:sw=4:ts=4:ft=vim diff --git a/vim/after/syntax/html.vim b/vim/after/syntax/html.vim new file mode 100644 index 0000000..63ebaec --- /dev/null +++ b/vim/after/syntax/html.vim @@ -0,0 +1,10 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +" Syntax highlighting for text/coffeescript script tags +syn include @htmlCoffeeScript syntax/coffee.vim +syn region coffeeScript start=++me=s-1 keepend +\ contains=@htmlCoffeeScript,htmlScriptTag,@htmlPreproc diff --git a/vim/autoload/.DS_Store b/vim/autoload/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/vim/autoload/.DS_Store differ diff --git a/vim/autoload/Align.vim b/vim/autoload/Align.vim new file mode 100644 index 0000000..bce3542 --- /dev/null +++ b/vim/autoload/Align.vim @@ -0,0 +1,1029 @@ +" Align: tool to align multiple fields based on one or more separators +" Author: Charles E. Campbell, Jr. +" Date: Mar 03, 2009 +" Version: 35 +" GetLatestVimScripts: 294 1 :AutoInstall: Align.vim +" GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim +" Copyright: Copyright (C) 1999-2007 Charles E. Campbell, Jr. {{{1 +" Permission is hereby granted to use and distribute this code, +" with or without modifications, provided that this copyright +" notice is copied with it. Like anything else that's free, +" Align.vim is provided *as is* and comes with no warranty +" of any kind, either expressed or implied. By using this +" plugin, you agree that in no event will the copyright +" holder be liable for any damages resulting from the use +" of this software. +" +" Romans 1:16,17a : For I am not ashamed of the gospel of Christ, for it is {{{1 +" the power of God for salvation for everyone who believes; for the Jew first, +" and also for the Greek. For in it is revealed God's righteousness from +" faith to faith. + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if exists("g:loaded_Align") || &cp + finish +endif +let g:loaded_Align = "v35" +if v:version < 700 + echohl WarningMsg + echo "***warning*** this version of Align needs vim 7.0" + echohl Normal + finish +endif +let s:keepcpo= &cpo +set cpo&vim +"DechoTabOn + +" --------------------------------------------------------------------- +" Debugging Support: {{{1 +"if !exists("g:loaded_Decho") | runtime plugin/Decho.vim | endif + +" --------------------------------------------------------------------- +" Options: {{{1 +if !exists("g:Align_xstrlen") + if &enc == "latin1" || $LANG == "en_US.UTF-8" || !has("multi_byte") + let g:Align_xstrlen= 0 + else + let g:Align_xstrlen= 1 + endif +endif + +" --------------------------------------------------------------------- +" Align#AlignCtrl: enter alignment patterns here {{{1 +" +" Styles = all alignment-break patterns are equivalent +" C cycle through alignment-break pattern(s) +" l left-justified alignment +" r right-justified alignment +" c center alignment +" - skip separator, treat as part of field +" : treat rest of line as field +" + repeat previous [lrc] style +" < left justify separators +" > right justify separators +" | center separators +" +" Builds = s:AlignPat s:AlignCtrl s:AlignPatQty +" C s:AlignPat s:AlignCtrl s:AlignPatQty +" p s:AlignPrePad +" P s:AlignPostPad +" w s:AlignLeadKeep +" W s:AlignLeadKeep +" I s:AlignLeadKeep +" l s:AlignStyle +" r s:AlignStyle +" - s:AlignStyle +" + s:AlignStyle +" : s:AlignStyle +" c s:AlignStyle +" g s:AlignGPat +" v s:AlignVPat +" < s:AlignSep +" > s:AlignSep +" | s:AlignSep +fun! Align#AlignCtrl(...) + +" call Dfunc("AlignCtrl(...) a:0=".a:0) + + " save options that will be changed + let keep_search = @/ + let keep_ic = &ic + + " turn ignorecase off + set noic + + " clear visual mode so that old visual-mode selections don't + " get applied to new invocations of Align(). + if v:version < 602 + if !exists("s:Align_gavemsg") + let s:Align_gavemsg= 1 + echomsg "Align needs at least Vim version 6.2 to clear visual-mode selection" + endif + elseif exists("s:dovisclear") +" call Decho("clearing visual mode a:0=".a:0." a:1<".a:1.">") + let clearvmode= visualmode(1) + endif + + " set up a list akin to an argument list + if a:0 > 0 + let A= s:QArgSplitter(a:1) + else + let A=[0] + endif + + if A[0] > 0 + let style = A[1] + + " Check for bad separator patterns (zero-length matches) + " (but zero-length patterns for g/v is ok) + if style !~# '[gv]' + let ipat= 2 + while ipat <= A[0] + if "" =~ A[ipat] + echoerr "AlignCtrl: separator<".A[ipat]."> matches zero-length string" + let &ic= keep_ic +" call Dret("AlignCtrl") + return + endif + let ipat= ipat + 1 + endwhile + endif + endif + +" call Decho("AlignCtrl() A[0]=".A[0]) + if !exists("s:AlignStyle") + let s:AlignStyle= "l" + endif + if !exists("s:AlignPrePad") + let s:AlignPrePad= 0 + endif + if !exists("s:AlignPostPad") + let s:AlignPostPad= 0 + endif + if !exists("s:AlignLeadKeep") + let s:AlignLeadKeep= 'w' + endif + + if A[0] == 0 + " ---------------------- + " List current selection + " ---------------------- + if !exists("s:AlignPatQty") + let s:AlignPatQty= 0 + endif + echo "AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep +" call Decho("AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep) + if exists("s:AlignGPat") && !exists("s:AlignVPat") + echo "AlignGPat<".s:AlignGPat.">" + elseif !exists("s:AlignGPat") && exists("s:AlignVPat") + echo "AlignVPat<".s:AlignVPat.">" + elseif exists("s:AlignGPat") && exists("s:AlignVPat") + echo "AlignGPat<".s:AlignGPat."> AlignVPat<".s:AlignVPat.">" + endif + let ipat= 1 + while ipat <= s:AlignPatQty + echo "Pat".ipat."<".s:AlignPat_{ipat}.">" +" call Decho("Pat".ipat."<".s:AlignPat_{ipat}.">") + let ipat= ipat + 1 + endwhile + + else + " ---------------------------------- + " Process alignment control settings + " ---------------------------------- +" call Decho("process the alignctrl settings") +" call Decho("style<".style.">") + + if style ==? "default" + " Default: preserve initial leading whitespace, left-justified, + " alignment on '=', one space padding on both sides + if exists("s:AlignCtrlStackQty") + " clear AlignCtrl stack + while s:AlignCtrlStackQty > 0 + call Align#AlignPop() + endwhile + unlet s:AlignCtrlStackQty + endif + " Set AlignCtrl to its default value + call Align#AlignCtrl("Ilp1P1=<",'=') + call Align#AlignCtrl("g") + call Align#AlignCtrl("v") + let s:dovisclear = 1 + let &ic = keep_ic + let @/ = keep_search +" call Dret("AlignCtrl") + return + endif + + if style =~# 'm' + " map support: Do an AlignPush now and the next call to Align() + " will do an AlignPop at exit +" call Decho("style case m: do AlignPush") + call Align#AlignPush() + let s:DoAlignPop= 1 + endif + + " = : record a list of alignment patterns that are equivalent + if style =~# "=" +" call Decho("style case =: record list of equiv alignment patterns") + let s:AlignCtrl = '=' + if A[0] >= 2 + let s:AlignPatQty= 1 + let s:AlignPat_1 = A[2] + let ipat = 3 + while ipat <= A[0] + let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat] + let ipat = ipat + 1 + endwhile + let s:AlignPat_1= '\('.s:AlignPat_1.'\)' +" call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">") + endif + + "c : cycle through alignment pattern(s) + elseif style =~# 'C' +" call Decho("style case C: cycle through alignment pattern(s)") + let s:AlignCtrl = 'C' + if A[0] >= 2 + let s:AlignPatQty= A[0] - 1 + let ipat = 1 + while ipat < A[0] + let s:AlignPat_{ipat}= A[ipat+1] +" call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">") + let ipat= ipat + 1 + endwhile + endif + endif + + if style =~# 'p' + let s:AlignPrePad= substitute(style,'^.*p\(\d\+\).*$','\1','') +" call Decho("style case p".s:AlignPrePad.": pre-separator padding") + if s:AlignPrePad == "" + echoerr "AlignCtrl: 'p' needs to be followed by a numeric argument' + let @/ = keep_search + let &ic= keep_ic +" call Dret("AlignCtrl") + return + endif + endif + + if style =~# 'P' + let s:AlignPostPad= substitute(style,'^.*P\(\d\+\).*$','\1','') +" call Decho("style case P".s:AlignPostPad.": post-separator padding") + if s:AlignPostPad == "" + echoerr "AlignCtrl: 'P' needs to be followed by a numeric argument' + let @/ = keep_search + let &ic= keep_ic +" call Dret("AlignCtrl") + return + endif + endif + + if style =~# 'w' +" call Decho("style case w: ignore leading whitespace") + let s:AlignLeadKeep= 'w' + elseif style =~# 'W' +" call Decho("style case w: keep leading whitespace") + let s:AlignLeadKeep= 'W' + elseif style =~# 'I' +" call Decho("style case w: retain initial leading whitespace") + let s:AlignLeadKeep= 'I' + endif + + if style =~# 'g' + " first list item is a "g" selector pattern +" call Decho("style case g: global selector pattern") + if A[0] < 2 + if exists("s:AlignGPat") + unlet s:AlignGPat +" call Decho("unlet s:AlignGPat") + endif + else + let s:AlignGPat= A[2] +" call Decho("s:AlignGPat<".s:AlignGPat.">") + endif + elseif style =~# 'v' + " first list item is a "v" selector pattern +" call Decho("style case v: global selector anti-pattern") + if A[0] < 2 + if exists("s:AlignVPat") + unlet s:AlignVPat +" call Decho("unlet s:AlignVPat") + endif + else + let s:AlignVPat= A[2] +" call Decho("s:AlignVPat<".s:AlignVPat.">") + endif + endif + + "[-lrc+:] : set up s:AlignStyle + if style =~# '[-lrc+:]' +" call Decho("style case [-lrc+:]: field justification") + let s:AlignStyle= substitute(style,'[^-lrc:+]','','g') +" call Decho("AlignStyle<".s:AlignStyle.">") + endif + + "[<>|] : set up s:AlignSep + if style =~# '[<>|]' +" call Decho("style case [-lrc+:]: separator justification") + let s:AlignSep= substitute(style,'[^<>|]','','g') +" call Decho("AlignSep ".s:AlignSep) + endif + endif + + " sanity + if !exists("s:AlignCtrl") + let s:AlignCtrl= '=' + endif + + " restore search and options + let @/ = keep_search + let &ic= keep_ic + +" call Dret("AlignCtrl ".s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle) + return s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle +endfun + +" --------------------------------------------------------------------- +" s:MakeSpace: returns a string with spacecnt blanks {{{1 +fun! s:MakeSpace(spacecnt) +" call Dfunc("MakeSpace(spacecnt=".a:spacecnt.")") + let str = "" + let spacecnt = a:spacecnt + while spacecnt > 0 + let str = str . " " + let spacecnt = spacecnt - 1 + endwhile +" call Dret("MakeSpace <".str.">") + return str +endfun + +" --------------------------------------------------------------------- +" Align#Align: align selected text based on alignment pattern(s) {{{1 +fun! Align#Align(hasctrl,...) range +" call Dfunc("Align#Align(hasctrl=".a:hasctrl.",...) a:0=".a:0) + + " sanity checks + if string(a:hasctrl) != "0" && string(a:hasctrl) != "1" + echohl Error|echo 'usage: Align#Align(hasctrl<'.a:hasctrl.'> (should be 0 or 1),"separator(s)" (you have '.a:0.') )'|echohl None +" call Dret("Align#Align") + return + endif + if exists("s:AlignStyle") && s:AlignStyle == ":" + echohl Error |echo '(Align#Align) your AlignStyle is ":", which implies "do-no-alignment"!'|echohl None +" call Dret("Align#Align") + return + endif + + " set up a list akin to an argument list + if a:0 > 0 + let A= s:QArgSplitter(a:1) + else + let A=[0] + endif + + " if :Align! was used, then the first argument is (should be!) an AlignCtrl string + " Note that any alignment control set this way will be temporary. + let hasctrl= a:hasctrl +" call Decho("hasctrl=".hasctrl) + if a:hasctrl && A[0] >= 1 +" call Decho("Align! : using A[1]<".A[1]."> for AlignCtrl") + if A[1] =~ '[gv]' + let hasctrl= hasctrl + 1 + call Align#AlignCtrl('m') + call Align#AlignCtrl(A[1],A[2]) +" call Decho("Align! : also using A[2]<".A[2]."> for AlignCtrl") + elseif A[1] !~ 'm' + call Align#AlignCtrl(A[1]."m") + else + call Align#AlignCtrl(A[1]) + endif + endif + + " Check for bad separator patterns (zero-length matches) + let ipat= 1 + hasctrl + while ipat <= A[0] + if "" =~ A[ipat] + echoerr "Align: separator<".A[ipat]."> matches zero-length string" +" call Dret("Align#Align") + return + endif + let ipat= ipat + 1 + endwhile + + " record current search pattern for subsequent restoration + let keep_search= @/ + let keep_ic = &ic + let keep_report= &report + set noic report=10000 + + if A[0] > hasctrl + " Align will accept a list of separator regexps +" call Decho("A[0]=".A[0].": accepting list of separator regexp") + + if s:AlignCtrl =~# "=" + "= : consider all separators to be equivalent +" call Decho("AlignCtrl: record list of equivalent alignment patterns") + let s:AlignCtrl = '=' + let s:AlignPat_1 = A[1 + hasctrl] + let s:AlignPatQty= 1 + let ipat = 2 + hasctrl + while ipat <= A[0] + let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat] + let ipat = ipat + 1 + endwhile + let s:AlignPat_1= '\('.s:AlignPat_1.'\)' +" call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">") + + elseif s:AlignCtrl =~# 'C' + "c : cycle through alignment pattern(s) +" call Decho("AlignCtrl: cycle through alignment pattern(s)") + let s:AlignCtrl = 'C' + let s:AlignPatQty= A[0] - hasctrl + let ipat = 1 + while ipat <= s:AlignPatQty + let s:AlignPat_{ipat}= A[(ipat + hasctrl)] +" call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">") + let ipat= ipat + 1 + endwhile + endif + endif + + " Initialize so that begline + " is greater than the line's string length -> ragged right. + " Have to be careful about visualmode() -- it returns the last visual + " mode used whether or not it was used currently. + let begcol = virtcol("'<")-1 + let endcol = virtcol("'>")-1 + if begcol > endcol + let begcol = virtcol("'>")-1 + let endcol = virtcol("'<")-1 + endif +" call Decho("begcol=".begcol." endcol=".endcol) + let begline = a:firstline + let endline = a:lastline + if begline > endline + let begline = a:lastline + let endline = a:firstline + endif +" call Decho("begline=".begline." endline=".endline) + let fieldcnt = 0 + if (begline == line("'>") && endline == line("'<")) || (begline == line("'<") && endline == line("'>")) + let vmode= visualmode() +" call Decho("vmode=".vmode) + if vmode == "\" + if exists("g:Align_xstrlen") && g:Align_xstrlen + let ragged = ( col("'>") > s:Strlen(getline("'>")) || col("'<") > s:Strlen(getline("'<")) ) + else + let ragged = ( col("'>") > strlen(getline("'>")) || col("'<") > strlen(getline("'<")) ) + endif + else + let ragged= 1 + endif + else + let ragged= 1 + endif + if ragged + let begcol= 0 + endif +" call Decho("lines[".begline.",".endline."] col[".begcol.",".endcol."] ragged=".ragged." AlignCtrl<".s:AlignCtrl.">") + + " Keep user options + let etkeep = &l:et + let pastekeep= &l:paste + setlocal et paste + + " convert selected range of lines to use spaces instead of tabs + " but if first line's initial white spaces are to be retained + " then use 'em + if begcol <= 0 && s:AlignLeadKeep == 'I' + " retain first leading whitespace for all subsequent lines + let bgntxt= substitute(getline(begline),'^\(\s*\).\{-}$','\1','') +" call Decho("retaining 1st leading whitespace: bgntxt<".bgntxt.">") + set noet + endif + exe begline.",".endline."ret" + + " Execute two passes + " First pass: collect alignment data (max field sizes) + " Second pass: perform alignment + let pass= 1 + while pass <= 2 +" call Decho(" ") +" call Decho("---- Pass ".pass.": ----") + + let line= begline + while line <= endline + " Process each line + let txt = getline(line) +" call Decho(" ") +" call Decho("Pass".pass.": Line ".line." <".txt.">") + + " AlignGPat support: allows a selector pattern (akin to g/selector/cmd ) + if exists("s:AlignGPat") +" call Decho("Pass".pass.": AlignGPat<".s:AlignGPat.">") + if match(txt,s:AlignGPat) == -1 +" call Decho("Pass".pass.": skipping") + let line= line + 1 + continue + endif + endif + + " AlignVPat support: allows a selector pattern (akin to v/selector/cmd ) + if exists("s:AlignVPat") +" call Decho("Pass".pass.": AlignVPat<".s:AlignVPat.">") + if match(txt,s:AlignVPat) != -1 +" call Decho("Pass".pass.": skipping") + let line= line + 1 + continue + endif + endif + + " Always skip blank lines + if match(txt,'^\s*$') != -1 +" call Decho("Pass".pass.": skipping") + let line= line + 1 + continue + endif + + " Extract visual-block selected text (init bgntxt, endtxt) + if exists("g:Align_xstrlen") && g:Align_xstrlen + let txtlen= s:Strlen(txt) + else + let txtlen= strlen(txt) + endif + if begcol > 0 + " Record text to left of selected area + let bgntxt= strpart(txt,0,begcol) +" call Decho("Pass".pass.": record text to left: bgntxt<".bgntxt.">") + elseif s:AlignLeadKeep == 'W' + let bgntxt= substitute(txt,'^\(\s*\).\{-}$','\1','') +" call Decho("Pass".pass.": retaining all leading ws: bgntxt<".bgntxt.">") + elseif s:AlignLeadKeep == 'w' || !exists("bgntxt") + " No beginning text + let bgntxt= "" +" call Decho("Pass".pass.": no beginning text") + endif + if ragged + let endtxt= "" + else + " Elide any text lying outside selected columnar region + let endtxt= strpart(txt,endcol+1,txtlen-endcol) + let txt = strpart(txt,begcol,endcol-begcol+1) + endif +" call Decho(" ") +" call Decho("Pass".pass.": bgntxt<".bgntxt.">") +" call Decho("Pass".pass.": txt<". txt .">") +" call Decho("Pass".pass.": endtxt<".endtxt.">") + if !exists("s:AlignPat_{1}") + echohl Error|echo "no separators specified!"|echohl None +" call Dret("Align#Align") + return + endif + + " Initialize for both passes + let seppat = s:AlignPat_{1} + let ifield = 1 + let ipat = 1 + let bgnfield = 0 + let endfield = 0 + let alignstyle = s:AlignStyle + let doend = 1 + let newtxt = "" + let alignprepad = s:AlignPrePad + let alignpostpad= s:AlignPostPad + let alignsep = s:AlignSep + let alignophold = " " + let alignop = "l" +" call Decho("Pass".pass.": initial alignstyle<".alignstyle."> seppat<".seppat.">") + + " Process each field on the line + while doend > 0 + + " C-style: cycle through pattern(s) + if s:AlignCtrl == 'C' && doend == 1 + let seppat = s:AlignPat_{ipat} +" call Decho("Pass".pass.": processing field: AlignCtrl=".s:AlignCtrl." ipat=".ipat." seppat<".seppat.">") + let ipat = ipat + 1 + if ipat > s:AlignPatQty + let ipat = 1 + endif + endif + + " cyclic alignment/justification operator handling + let alignophold = alignop + let alignop = strpart(alignstyle,0,1) + if alignop == '+' || doend == 2 + let alignop= alignophold + else + let alignstyle = strpart(alignstyle,1).strpart(alignstyle,0,1) + let alignopnxt = strpart(alignstyle,0,1) + if alignop == ':' + let seppat = '$' + let doend = 2 +" call Decho("Pass".pass.": alignop<:> case: setting seppat<$> doend==2") + endif + endif + + " cylic separator alignment specification handling + let alignsepop= strpart(alignsep,0,1) + let alignsep = strpart(alignsep,1).alignsepop + + " mark end-of-field and the subsequent end-of-separator. + " Extend field if alignop is '-' + let endfield = match(txt,seppat,bgnfield) + let sepfield = matchend(txt,seppat,bgnfield) + let skipfield= sepfield +" call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield) + while alignop == '-' && endfield != -1 + let endfield = match(txt,seppat,skipfield) + let sepfield = matchend(txt,seppat,skipfield) + let skipfield = sepfield + let alignop = strpart(alignstyle,0,1) + let alignstyle= strpart(alignstyle,1).strpart(alignstyle,0,1) +" call Decho("Pass".pass.": extend field: endfield<".strpart(txt,bgnfield,endfield-bgnfield)."> alignop<".alignop."> alignstyle<".alignstyle.">") + endwhile + let seplen= sepfield - endfield +" call Decho("Pass".pass.": seplen=[sepfield=".sepfield."] - [endfield=".endfield."]=".seplen) + + if endfield != -1 + if pass == 1 + " --------------------------------------------------------------------- + " Pass 1: Update FieldSize to max +" call Decho("Pass".pass.": before lead/trail remove: field<".strpart(txt,bgnfield,endfield-bgnfield).">") + let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','') + if s:AlignLeadKeep == 'W' + let field = bgntxt.field + let bgntxt= "" + endif + if exists("g:Align_xstrlen") && g:Align_xstrlen + let fieldlen = s:Strlen(field) + else + let fieldlen = strlen(field) + endif + let sFieldSize = "FieldSize_".ifield + if !exists(sFieldSize) + let FieldSize_{ifield}= fieldlen +" call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">") + elseif fieldlen > FieldSize_{ifield} + let FieldSize_{ifield}= fieldlen +" call Decho("Pass".pass.": oset FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">") + endif + let sSepSize= "SepSize_".ifield + if !exists(sSepSize) + let SepSize_{ifield}= seplen +" call Decho(" set SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">") + elseif seplen > SepSize_{ifield} + let SepSize_{ifield}= seplen +" call Decho("Pass".pass.": oset SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">") + endif + + else + " --------------------------------------------------------------------- + " Pass 2: Perform Alignment + let prepad = strpart(alignprepad,0,1) + let postpad = strpart(alignpostpad,0,1) + let alignprepad = strpart(alignprepad,1).strpart(alignprepad,0,1) + let alignpostpad = strpart(alignpostpad,1).strpart(alignpostpad,0,1) + let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','') + if s:AlignLeadKeep == 'W' + let field = bgntxt.field + let bgntxt= "" + endif + if doend == 2 + let prepad = 0 + let postpad= 0 + endif + if exists("g:Align_xstrlen") && g:Align_xstrlen + let fieldlen = s:Strlen(field) + else + let fieldlen = strlen(field) + endif + let sep = s:MakeSpace(prepad).strpart(txt,endfield,sepfield-endfield).s:MakeSpace(postpad) + if seplen < SepSize_{ifield} + if alignsepop == "<" + " left-justify separators + let sep = sep.s:MakeSpace(SepSize_{ifield}-seplen) + elseif alignsepop == ">" + " right-justify separators + let sep = s:MakeSpace(SepSize_{ifield}-seplen).sep + else + " center-justify separators + let sepleft = (SepSize_{ifield} - seplen)/2 + let sepright = SepSize_{ifield} - seplen - sepleft + let sep = s:MakeSpace(sepleft).sep.s:MakeSpace(sepright) + endif + endif + let spaces = FieldSize_{ifield} - fieldlen +" call Decho("Pass".pass.": Field #".ifield."<".field."> spaces=".spaces." be[".bgnfield.",".endfield."] pad=".prepad.','.postpad." FS_".ifield."<".FieldSize_{ifield}."> sep<".sep."> ragged=".ragged." doend=".doend." alignop<".alignop.">") + + " Perform alignment according to alignment style justification + if spaces > 0 + if alignop == 'c' + " center the field + let spaceleft = spaces/2 + let spaceright= FieldSize_{ifield} - spaceleft - fieldlen + let newtxt = newtxt.s:MakeSpace(spaceleft).field.s:MakeSpace(spaceright).sep + elseif alignop == 'r' + " right justify the field + let newtxt= newtxt.s:MakeSpace(spaces).field.sep + elseif ragged && doend == 2 + " left justify rightmost field (no trailing blanks needed) + let newtxt= newtxt.field + else + " left justfiy the field + let newtxt= newtxt.field.s:MakeSpace(spaces).sep + endif + elseif ragged && doend == 2 + " field at maximum field size and no trailing blanks needed + let newtxt= newtxt.field + else + " field is at maximum field size already + let newtxt= newtxt.field.sep + endif +" call Decho("Pass".pass.": newtxt<".newtxt.">") + endif " pass 1/2 + + " bgnfield indexes to end of separator at right of current field + " Update field counter + let bgnfield= sepfield + let ifield = ifield + 1 + if doend == 2 + let doend= 0 + endif + " handle end-of-text as end-of-field + elseif doend == 1 + let seppat = '$' + let doend = 2 + else + let doend = 0 + endif " endfield != -1 + endwhile " doend loop (as well as regularly separated fields) + + if pass == 2 + " Write altered line to buffer +" call Decho("Pass".pass.": bgntxt<".bgntxt."> line=".line) +" call Decho("Pass".pass.": newtxt<".newtxt.">") +" call Decho("Pass".pass.": endtxt<".endtxt.">") + call setline(line,bgntxt.newtxt.endtxt) + endif + + let line = line + 1 + endwhile " line loop + + let pass= pass + 1 + endwhile " pass loop +" call Decho("end of two pass loop") + + " Restore user options + let &l:et = etkeep + let &l:paste = pastekeep + + if exists("s:DoAlignPop") + " AlignCtrl Map support + call Align#AlignPop() + unlet s:DoAlignPop + endif + + " restore current search pattern + let @/ = keep_search + let &ic = keep_ic + let &report = keep_report + +" call Dret("Align#Align") + return +endfun + +" --------------------------------------------------------------------- +" Align#AlignPush: this command/function pushes an alignment control string onto a stack {{{1 +fun! Align#AlignPush() +" call Dfunc("AlignPush()") + + " initialize the stack + if !exists("s:AlignCtrlStackQty") + let s:AlignCtrlStackQty= 1 + else + let s:AlignCtrlStackQty= s:AlignCtrlStackQty + 1 + endif + + " construct an AlignCtrlStack entry + if !exists("s:AlignSep") + let s:AlignSep= '' + endif + let s:AlignCtrlStack_{s:AlignCtrlStackQty}= s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle.s:AlignSep +" call Decho("AlignPush: AlignCtrlStack_".s:AlignCtrlStackQty."<".s:AlignCtrlStack_{s:AlignCtrlStackQty}.">") + + " push [GV] patterns onto their own stack + if exists("s:AlignGPat") + let s:AlignGPat_{s:AlignCtrlStackQty}= s:AlignGPat + else + let s:AlignGPat_{s:AlignCtrlStackQty}= "" + endif + if exists("s:AlignVPat") + let s:AlignVPat_{s:AlignCtrlStackQty}= s:AlignVPat + else + let s:AlignVPat_{s:AlignCtrlStackQty}= "" + endif + +" call Dret("AlignPush") +endfun + +" --------------------------------------------------------------------- +" Align#AlignPop: this command/function pops an alignment pattern from a stack {{{1 +" and into the AlignCtrl variables. +fun! Align#AlignPop() +" call Dfunc("Align#AlignPop()") + + " sanity checks + if !exists("s:AlignCtrlStackQty") + echoerr "AlignPush needs to be used prior to AlignPop" +" call Dret("Align#AlignPop <> : AlignPush needs to have been called first") + return "" + endif + if s:AlignCtrlStackQty <= 0 + unlet s:AlignCtrlStackQty + echoerr "AlignPush needs to be used prior to AlignPop" +" call Dret("Align#AlignPop <> : AlignPop needs to have been called first") + return "" + endif + + " pop top of AlignCtrlStack and pass value to AlignCtrl + let retval=s:AlignCtrlStack_{s:AlignCtrlStackQty} + unlet s:AlignCtrlStack_{s:AlignCtrlStackQty} + call Align#AlignCtrl(retval) + + " pop G pattern stack + if s:AlignGPat_{s:AlignCtrlStackQty} != "" + call Align#AlignCtrl('g',s:AlignGPat_{s:AlignCtrlStackQty}) + else + call Align#AlignCtrl('g') + endif + unlet s:AlignGPat_{s:AlignCtrlStackQty} + + " pop V pattern stack + if s:AlignVPat_{s:AlignCtrlStackQty} != "" + call Align#AlignCtrl('v',s:AlignVPat_{s:AlignCtrlStackQty}) + else + call Align#AlignCtrl('v') + endif + + unlet s:AlignVPat_{s:AlignCtrlStackQty} + let s:AlignCtrlStackQty= s:AlignCtrlStackQty - 1 + +" call Dret("Align#AlignPop <".retval."> : AlignCtrlStackQty=".s:AlignCtrlStackQty) + return retval +endfun + +" --------------------------------------------------------------------- +" Align#AlignReplaceQuotedSpaces: {{{1 +fun! Align#AlignReplaceQuotedSpaces() +" call Dfunc("AlignReplaceQuotedSpaces()") + + let l:line = getline(line(".")) + if exists("g:Align_xstrlen") && g:Align_xstrlen + let l:linelen = s:Strlen(l:line) + else + let l:linelen = strlen(l:line) + endif + let l:startingPos = 0 + let l:startQuotePos = 0 + let l:endQuotePos = 0 + let l:spacePos = 0 + let l:quoteRe = '\\\@, is needed. {{{1 +" However, doesn't split at all, so this function returns a list +" of arguments which has been: +" * split at whitespace +" * unless inside "..."s. One may escape characters with a backslash inside double quotes. +" along with a leading length-of-list. +" +" Examples: %Align "\"" will align on "s +" %Align " " will align on spaces +" +" The resulting list: qarglist[0] corresponds to a:0 +" qarglist[i] corresponds to a:{i} +fun! s:QArgSplitter(qarg) +" call Dfunc("s:QArgSplitter(qarg<".a:qarg.">)") + + if a:qarg =~ '".*"' + " handle "..." args, which may include whitespace + let qarglist = [] + let args = a:qarg +" call Decho("handle quoted arguments: args<".args.">") + while args != "" + let iarg = 0 + let arglen = strlen(args) +" call Decho("args[".iarg."]<".args[iarg]."> arglen=".arglen) + " find index to first not-escaped '"' + while args[iarg] != '"' && iarg < arglen + if args[iarg] == '\' + let args= strpart(args,1) + endif + let iarg= iarg + 1 + endwhile +" call Decho("args<".args."> iarg=".iarg." arglen=".arglen) + + if iarg > 0 + " handle left of quote or remaining section +" call Decho("handle left of quote or remaining section") + if args[iarg] == '"' + let qarglist= qarglist + split(strpart(args,0,iarg-1)) + else + let qarglist= qarglist + split(strpart(args,0,iarg)) + endif + let args = strpart(args,iarg) + let arglen = strlen(args) + + elseif iarg < arglen && args[0] == '"' + " handle "quoted" section +" call Decho("handle quoted section") + let iarg= 1 + while args[iarg] != '"' && iarg < arglen + if args[iarg] == '\' + let args= strpart(args,1) + endif + let iarg= iarg + 1 + endwhile +" call Decho("args<".args."> iarg=".iarg." arglen=".arglen) + if args[iarg] == '"' + call add(qarglist,strpart(args,1,iarg-1)) + let args= strpart(args,iarg+1) + else + let qarglist = qarglist + split(args) + let args = "" + endif + endif +" call Decho("qarglist".string(qarglist)." iarg=".iarg." args<".args.">") + endwhile + + else + " split at all whitespace + let qarglist= split(a:qarg) + endif + + let qarglistlen= len(qarglist) + let qarglist = insert(qarglist,qarglistlen) +" call Dret("s:QArgSplitter ".string(qarglist)) + return qarglist +endfun + +" --------------------------------------------------------------------- +" s:Strlen: this function returns the length of a string, even if its {{{1 +" using two-byte etc characters. +" Currently, its only used if g:Align_xstrlen is set to a +" nonzero value. Solution from Nicolai Weibull, vim docs +" (:help strlen()), Tony Mechelynck, and my own invention. +fun! s:Strlen(x) +" call Dfunc("s:Strlen(x<".a:x.">") + if g:Align_xstrlen == 1 + " number of codepoints (Latin a + combining circumflex is two codepoints) + " (comment from TM, solution from NW) + let ret= strlen(substitute(a:x,'.','c','g')) + + elseif g:Align_xstrlen == 2 + " number of spacing codepoints (Latin a + combining circumflex is one spacing + " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.) + " (comment from TM, solution from TM) + let ret=strlen(substitute(a:x, '.\Z', 'x', 'g')) + + elseif g:Align_xstrlen == 3 + " virtual length (counting, for instance, tabs as anything between 1 and + " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately + " preceded by lam, one otherwise, etc.) + " (comment from TM, solution from me) + let modkeep= &l:mod + exe "norm! o\" + call setline(line("."),a:x) + let ret= virtcol("$") - 1 + d + let &l:mod= modkeep + + else + " at least give a decent default + ret= strlen(a:x) + endif +" call Dret("s:Strlen ".ret) + return ret +endfun + +" --------------------------------------------------------------------- +" Set up default values: {{{1 +"call Decho("-- Begin AlignCtrl Initialization --") +call Align#AlignCtrl("default") +"call Decho("-- End AlignCtrl Initialization --") + +" --------------------------------------------------------------------- +" Restore: {{{1 +let &cpo= s:keepcpo +unlet s:keepcpo +" vim: ts=4 fdm=marker diff --git a/vim/autoload/AlignMaps.vim b/vim/autoload/AlignMaps.vim new file mode 100644 index 0000000..ace2de8 --- /dev/null +++ b/vim/autoload/AlignMaps.vim @@ -0,0 +1,330 @@ +" AlignMaps.vim : support functions for AlignMaps +" Author: Charles E. Campbell, Jr. +" Date: Mar 03, 2009 +" Version: 41 +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_AlignMaps") + finish +endif +let g:loaded_AlignMaps= "v41" +let s:keepcpo = &cpo +set cpo&vim + +" ===================================================================== +" Functions: {{{1 + +" --------------------------------------------------------------------- +" AlignMaps#WrapperStart: {{{2 +fun! AlignMaps#WrapperStart(vis) range +" call Dfunc("AlignMaps#WrapperStart(vis=".a:vis.")") + + if a:vis + norm! ' + endif + + if line("'y") == 0 || line("'z") == 0 || !exists("s:alignmaps_wrapcnt") || s:alignmaps_wrapcnt <= 0 +" call Decho("wrapper initialization") + let s:alignmaps_wrapcnt = 1 + let s:alignmaps_keepgd = &gdefault + let s:alignmaps_keepsearch = @/ + let s:alignmaps_keepch = &ch + let s:alignmaps_keepmy = SaveMark("'y") + let s:alignmaps_keepmz = SaveMark("'z") + let s:alignmaps_posn = SaveWinPosn(0) + " set up fencepost blank lines + put ='' + norm! mz'a + put! ='' + ky + let s:alignmaps_zline = line("'z") + exe "'y,'zs/@/\177/ge" + else +" call Decho("embedded wrapper") + let s:alignmaps_wrapcnt = s:alignmaps_wrapcnt + 1 + norm! 'yjma'zk + endif + + " change some settings to align-standard values + set nogd + set ch=2 + AlignPush + norm! 'zk +" call Dret("AlignMaps#WrapperStart : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) +endfun + +" --------------------------------------------------------------------- +" AlignMaps#WrapperEnd: {{{2 +fun! AlignMaps#WrapperEnd() range +" call Dfunc("AlignMaps#WrapperEnd() alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) + + " remove trailing white space introduced by whatever in the modification zone + 'y,'zs/ \+$//e + + " restore AlignCtrl settings + AlignPop + + let s:alignmaps_wrapcnt= s:alignmaps_wrapcnt - 1 + if s:alignmaps_wrapcnt <= 0 + " initial wrapper ending + exe "'y,'zs/\177/@/ge" + + " if the 'z line hasn't moved, then go ahead and restore window position + let zstationary= s:alignmaps_zline == line("'z") + + " remove fencepost blank lines. + " restore 'a + norm! 'yjmakdd'zdd + + " restore original 'y, 'z, and window positioning + call RestoreMark(s:alignmaps_keepmy) + call RestoreMark(s:alignmaps_keepmz) + if zstationary > 0 + call RestoreWinPosn(s:alignmaps_posn) +" call Decho("restored window positioning") + endif + + " restoration of options + let &gd= s:alignmaps_keepgd + let &ch= s:alignmaps_keepch + let @/ = s:alignmaps_keepsearch + + " remove script variables + unlet s:alignmaps_keepch + unlet s:alignmaps_keepsearch + unlet s:alignmaps_keepmy + unlet s:alignmaps_keepmz + unlet s:alignmaps_keepgd + unlet s:alignmaps_posn + endif + +" call Dret("AlignMaps#WrapperEnd : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) +endfun + +" --------------------------------------------------------------------- +" AlignMaps#StdAlign: some semi-standard align calls {{{2 +fun! AlignMaps#StdAlign(mode) range +" call Dfunc("AlignMaps#StdAlign(mode=".a:mode.")") + if a:mode == 1 + " align on @ +" call Decho("align on @") + AlignCtrl mIp1P1=l @ + 'a,.Align + elseif a:mode == 2 + " align on @, retaining all initial white space on each line +" call Decho("align on @, retaining all initial white space on each line") + AlignCtrl mWp1P1=l @ + 'a,.Align + elseif a:mode == 3 + " like mode 2, but ignore /* */-style comments +" call Decho("like mode 2, but ignore /* */-style comments") + AlignCtrl v ^\s*/[/*] + AlignCtrl mWp1P1=l @ + 'a,.Align + else + echoerr "(AlignMaps) AlignMaps#StdAlign doesn't support mode#".a:mode + endif +" call Dret("AlignMaps#StdAlign") +endfun + +" --------------------------------------------------------------------- +" AlignMaps#CharJoiner: joins lines which end in the given character (spaces {{{2 +" at end are ignored) +fun! AlignMaps#CharJoiner(chr) +" call Dfunc("AlignMaps#CharJoiner(chr=".a:chr.")") + let aline = line("'a") + let rep = line(".") - aline + while rep > 0 + norm! 'a + while match(getline(aline),a:chr . "\s*$") != -1 && rep >= 0 + " while = at end-of-line, delete it and join with next + norm! 'a$ + j! + let rep = rep - 1 + endwhile + " update rep(eat) count + let rep = rep - 1 + if rep <= 0 + " terminate loop if at end-of-block + break + endif + " prepare for next line + norm! jma + let aline = line("'a") + endwhile +" call Dret("AlignMaps#CharJoiner") +endfun + +" --------------------------------------------------------------------- +" AlignMaps#Equals: supports \t= and \T= {{{2 +fun! AlignMaps#Equals() range +" call Dfunc("AlignMaps#Equals()") + 'a,'zs/\s\+\([*/+\-%|&\~^]\==\)/ \1/e + 'a,'zs@ \+\([*/+\-%|&\~^]\)=@\1=@ge + 'a,'zs/==/\="\\"/ge + 'a,'zs/\([!<>:]\)=/\=submatch(1)."\"/ge + norm g'zk + AlignCtrl mIp1P1=l = + AlignCtrl g = + 'a,'z-1Align + 'a,'z-1s@\([*/+\-%|&\~^!=]\)\( \+\)=@\2\1=@ge + 'a,'z-1s/\( \+\);/;\1/ge + if &ft == "c" || &ft == "cpp" +" call Decho("exception for ".&ft) + 'a,'z-1v/^\s*\/[*/]/s/\/[*/]/@&@/e + 'a,'z-1v/^\s*\/[*/]/s/\*\//@&/e + if exists("g:mapleader") + exe "norm 'zk" + call AlignMaps#StdAlign(1) + else + exe "norm 'zk" + call AlignMaps#StdAlign(1) + endif + 'y,'zs/^\(\s*\) @/\1/e + endif + 'a,'z-1s/\%x0f/=/ge + 'y,'zs/ @//eg +" call Dret("AlignMaps#Equals") +endfun + +" --------------------------------------------------------------------- +" AlignMaps#Afnc: useful for splitting one-line function beginnings {{{2 +" into one line per argument format +fun! AlignMaps#Afnc() +" call Dfunc("AlignMaps#Afnc()") + + " keep display quiet + let chkeep = &ch + let gdkeep = &gd + let vekeep = &ve + set ch=2 nogd ve= + + " will use marks y,z ; save current values + let mykeep = SaveMark("'y") + let mzkeep = SaveMark("'z") + + " Find beginning of function -- be careful to skip over comments + let cmmntid = synIDtrans(hlID("Comment")) + let stringid = synIDtrans(hlID("String")) + exe "norm! ]]" + while search(")","bW") != 0 +" call Decho("line=".line(".")." col=".col(".")) + let parenid= synIDtrans(synID(line("."),col("."),1)) + if parenid != cmmntid && parenid != stringid + break + endif + endwhile + norm! %my + s/(\s*\(\S\)/(\r \1/e + exe "norm! `y%" + s/)\s*\(\/[*/]\)/)\r\1/e + exe "norm! `y%mz" + 'y,'zs/\s\+$//e + 'y,'zs/^\s\+//e + 'y+1,'zs/^/ / + + " insert newline after every comma only one parenthesis deep + sil! exe "norm! `y\h" + let parens = 1 + let cmmnt = 0 + let cmmntline= -1 + while parens >= 1 +" call Decho("parens=".parens." @a=".@a) + exe 'norm! ma "ay`a ' + if @a == "(" + let parens= parens + 1 + elseif @a == ")" + let parens= parens - 1 + + " comment bypass: /* ... */ or //... + elseif cmmnt == 0 && @a == '/' + let cmmnt= 1 + elseif cmmnt == 1 + if @a == '/' + let cmmnt = 2 " //... + let cmmntline= line(".") + elseif @a == '*' + let cmmnt= 3 " /*... + else + let cmmnt= 0 + endif + elseif cmmnt == 2 && line(".") != cmmntline + let cmmnt = 0 + let cmmntline= -1 + elseif cmmnt == 3 && @a == '*' + let cmmnt= 4 + elseif cmmnt == 4 + if @a == '/' + let cmmnt= 0 " ...*/ + elseif @a != '*' + let cmmnt= 3 + endif + + elseif @a == "," && parens == 1 && cmmnt == 0 + exe "norm! i\\" + endif + endwhile + norm! `y%mz% + sil! 'y,'zg/^\s*$/d + + " perform substitutes to mark fields for Align + sil! 'y+1,'zv/^\//s/^\s\+\(\S\)/ \1/e + sil! 'y+1,'zv/^\//s/\(\S\)\s\+/\1 /eg + sil! 'y+1,'zv/^\//s/\* \+/*/ge + sil! 'y+1,'zv/^\//s/\w\zs\s*\*/ */ge + " func + " ws <- declaration -> <-ptr -> <-var-> <-[array][] -> <-glop-> <-end-> + sil! 'y+1,'zv/^\//s/^\s*\(\(\K\k*\s*\)\+\)\s\+\([(*]*\)\s*\(\K\k*\)\s*\(\(\[.\{-}]\)*\)\s*\(.\{-}\)\=\s*\([,)]\)\s*$/ \1@#\3@\4\5@\7\8/e + sil! 'y+1,'z+1g/^\s*\/[*/]/norm! kJ + sil! 'y+1,'z+1s%/[*/]%@&@%ge + sil! 'y+1,'z+1s%*/%@&%ge + AlignCtrl mIp0P0=l @ + sil! 'y+1,'zAlign + sil! 'y,'zs%@\(/[*/]\)@%\t\1 %e + sil! 'y,'zs%@\*/% */%e + sil! 'y,'zs/@\([,)]\)/\1/ + sil! 'y,'zs/@/ / + AlignCtrl mIlrp0P0= # @ + sil! 'y+1,'zAlign + sil! 'y+1,'zs/#/ / + sil! 'y+1,'zs/@// + sil! 'y+1,'zs/\(\s\+\)\([,)]\)/\2\1/e + + " Restore + call RestoreMark(mykeep) + call RestoreMark(mzkeep) + let &ch= chkeep + let &gd= gdkeep + let &ve= vekeep + +" call Dret("AlignMaps#Afnc") +endfun + +" --------------------------------------------------------------------- +" AlignMaps#FixMultiDec: converts a type arg,arg,arg; line to multiple lines {{{2 +fun! AlignMaps#FixMultiDec() +" call Dfunc("AlignMaps#FixMultiDec()") + + " save register x + let xkeep = @x + let curline = getline(".") +" call Decho("curline<".curline.">") + + " Get the type. I'm assuming one type per line (ie. int x; double y; on one line will not be handled properly) + let @x=substitute(curline,'^\(\s*[a-zA-Z_ \t][a-zA-Z0-9_ \t]*\)\s\+[(*]*\h.*$','\1','') +" call Decho("@x<".@x.">") + + " transform line + exe 's/,/;\r'.@x.' /ge' + + "restore register x + let @x= xkeep + +" call Dret("AlignMaps#FixMultiDec : my=".line("'y")." mz=".line("'z")) +endfun + +" --------------------------------------------------------------------- +" Restore: {{{1 +let &cpo= s:keepcpo +unlet s:keepcpo +" vim: ts=4 fdm=marker diff --git a/vim/autoload/EasyMotion.vim b/vim/autoload/EasyMotion.vim new file mode 100755 index 0000000..7c79dd8 --- /dev/null +++ b/vim/autoload/EasyMotion.vim @@ -0,0 +1,573 @@ +" EasyMotion - Vim motions on speed! +" +" Author: Kim Silkebækken +" Source repository: https://github.com/Lokaltog/vim-easymotion + +" Default configuration functions {{{ + function! EasyMotion#InitOptions(options) " {{{ + for [key, value] in items(a:options) + if ! exists('g:EasyMotion_' . key) + exec 'let g:EasyMotion_' . key . ' = ' . string(value) + endif + endfor + endfunction " }}} + function! EasyMotion#InitHL(group, colors) " {{{ + let group_default = a:group . 'Default' + + " Prepare highlighting variables + let guihl = printf('guibg=%s guifg=%s gui=%s', a:colors.gui[0], a:colors.gui[1], a:colors.gui[2]) + if !exists('g:CSApprox_loaded') + let ctermhl = &t_Co == 256 + \ ? printf('ctermbg=%s ctermfg=%s cterm=%s', a:colors.cterm256[0], a:colors.cterm256[1], a:colors.cterm256[2]) + \ : printf('ctermbg=%s ctermfg=%s cterm=%s', a:colors.cterm[0], a:colors.cterm[1], a:colors.cterm[2]) + else + let ctermhl = '' + endif + + " Create default highlighting group + execute printf('hi default %s %s %s', group_default, guihl, ctermhl) + + " Check if the hl group exists + if hlexists(a:group) + redir => hlstatus | exec 'silent hi ' . a:group | redir END + + " Return if the group isn't cleared + if hlstatus !~ 'cleared' + return + endif + endif + + " No colors are defined for this group, link to defaults + execute printf('hi default link %s %s', a:group, group_default) + endfunction " }}} + function! EasyMotion#InitMappings(motions) "{{{ + for motion in keys(a:motions) + call EasyMotion#InitOptions({ 'mapping_' . motion : g:EasyMotion_leader_key . motion }) + endfor + + if g:EasyMotion_do_mapping + for [motion, fn] in items(a:motions) + if empty(g:EasyMotion_mapping_{motion}) + continue + endif + + silent exec 'nnoremap ' . g:EasyMotion_mapping_{motion} . ' :call EasyMotion#' . fn.name . '(0, ' . fn.dir . ')' + silent exec 'onoremap ' . g:EasyMotion_mapping_{motion} . ' :call EasyMotion#' . fn.name . '(0, ' . fn.dir . ')' + silent exec 'vnoremap ' . g:EasyMotion_mapping_{motion} . ' :call EasyMotion#' . fn.name . '(1, ' . fn.dir . ')' + endfor + endif + endfunction "}}} +" }}} +" Motion functions {{{ + function! EasyMotion#F(visualmode, direction) " {{{ + let char = s:GetSearchChar(a:visualmode) + + if empty(char) + return + endif + + let re = '\C' . escape(char, '.$^~') + + call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1)) + endfunction " }}} + function! EasyMotion#T(visualmode, direction) " {{{ + let char = s:GetSearchChar(a:visualmode) + + if empty(char) + return + endif + + if a:direction == 1 + let re = '\C' . escape(char, '.$^~') . '\zs.' + else + let re = '\C.' . escape(char, '.$^~') + endif + + call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1)) + endfunction " }}} + function! EasyMotion#WB(visualmode, direction) " {{{ + call s:EasyMotion('\(\<.\|^$\)', a:direction, a:visualmode ? visualmode() : '', '') + endfunction " }}} + function! EasyMotion#WBW(visualmode, direction) " {{{ + call s:EasyMotion('\(\(^\|\s\)\@<=\S\|^$\)', a:direction, a:visualmode ? visualmode() : '', '') + endfunction " }}} + function! EasyMotion#E(visualmode, direction) " {{{ + call s:EasyMotion('\(.\>\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1)) + endfunction " }}} + function! EasyMotion#EW(visualmode, direction) " {{{ + call s:EasyMotion('\(\S\(\s\|$\)\|^$\)', a:direction, a:visualmode ? visualmode() : '', mode(1)) + endfunction " }}} + function! EasyMotion#JK(visualmode, direction) " {{{ + call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', '') + endfunction " }}} + function! EasyMotion#Search(visualmode, direction) " {{{ + call s:EasyMotion(@/, a:direction, a:visualmode ? visualmode() : '', '') + endfunction " }}} +" }}} +" Helper functions {{{ + function! s:Message(message) " {{{ + echo 'EasyMotion: ' . a:message + endfunction " }}} + function! s:Prompt(message) " {{{ + echohl Question + echo a:message . ': ' + echohl None + endfunction " }}} + function! s:VarReset(var, ...) " {{{ + if ! exists('s:var_reset') + let s:var_reset = {} + endif + + let buf = bufname("") + + if a:0 == 0 && has_key(s:var_reset, a:var) + " Reset var to original value + call setbufvar(buf, a:var, s:var_reset[a:var]) + elseif a:0 == 1 + let new_value = a:0 == 1 ? a:1 : '' + + " Store original value + let s:var_reset[a:var] = getbufvar(buf, a:var) + + " Set new var value + call setbufvar(buf, a:var, new_value) + endif + endfunction " }}} + function! s:SetLines(lines, key) " {{{ + try + " Try to join changes with previous undo block + undojoin + catch + endtry + + for [line_num, line] in a:lines + call setline(line_num, line[a:key]) + endfor + endfunction " }}} + function! s:GetChar() " {{{ + let char = getchar() + + if char == 27 + " Escape key pressed + redraw + + call s:Message('Cancelled') + + return '' + endif + + return nr2char(char) + endfunction " }}} + function! s:GetSearchChar(visualmode) " {{{ + call s:Prompt('Search for character') + + let char = s:GetChar() + + " Check that we have an input char + if empty(char) + " Restore selection + if ! empty(a:visualmode) + silent exec 'normal! gv' + endif + + return '' + endif + + return char + endfunction " }}} +" }}} +" Grouping algorithms {{{ + let s:grouping_algorithms = { + \ 1: 'SCTree' + \ , 2: 'Original' + \ } + " Single-key/closest target priority tree {{{ + " This algorithm tries to assign one-key jumps to all the targets closest to the cursor. + " It works recursively and will work correctly with as few keys as two. + function! s:GroupingAlgorithmSCTree(targets, keys) + " Prepare variables for working + let targets_len = len(a:targets) + let keys_len = len(a:keys) + + let groups = {} + + let keys = reverse(copy(a:keys)) + + " Semi-recursively count targets {{{ + " We need to know exactly how many child nodes (targets) this branch will have + " in order to pass the correct amount of targets to the recursive function. + + " Prepare sorted target count list {{{ + " This is horrible, I know. But dicts aren't sorted in vim, so we need to + " work around that. That is done by having one sorted list with key counts, + " and a dict which connects the key with the keys_count list. + + let keys_count = [] + let keys_count_keys = {} + + let i = 0 + for key in keys + call add(keys_count, 0) + + let keys_count_keys[key] = i + + let i += 1 + endfor + " }}} + + let targets_left = targets_len + let level = 0 + let i = 0 + + while targets_left > 0 + " Calculate the amount of child nodes based on the current level + let childs_len = (level == 0 ? 1 : (keys_len - 1) ) + + for key in keys + " Add child node count to the keys_count array + let keys_count[keys_count_keys[key]] += childs_len + + " Subtract the child node count + let targets_left -= childs_len + + if targets_left <= 0 + " Subtract the targets left if we added too many too + " many child nodes to the key count + let keys_count[keys_count_keys[key]] += targets_left + + break + endif + + let i += 1 + endfor + + let level += 1 + endwhile + " }}} + " Create group tree {{{ + let i = 0 + let key = 0 + + call reverse(keys_count) + + for key_count in keys_count + if key_count > 1 + " We need to create a subgroup + " Recurse one level deeper + let groups[a:keys[key]] = s:GroupingAlgorithmSCTree(a:targets[i : i + key_count - 1], a:keys) + elseif key_count == 1 + " Assign single target key + let groups[a:keys[key]] = a:targets[i] + else + " No target + continue + endif + + let key += 1 + let i += key_count + endfor + " }}} + + " Finally! + return groups + endfunction + " }}} + " Original {{{ + function! s:GroupingAlgorithmOriginal(targets, keys) + " Split targets into groups (1 level) + let targets_len = len(a:targets) + let keys_len = len(a:keys) + + let groups = {} + + let i = 0 + let root_group = 0 + try + while root_group < targets_len + let groups[a:keys[root_group]] = {} + + for key in a:keys + let groups[a:keys[root_group]][key] = a:targets[i] + + let i += 1 + endfor + + let root_group += 1 + endwhile + catch | endtry + + " Flatten the group array + if len(groups) == 1 + let groups = groups[a:keys[0]] + endif + + return groups + endfunction + " }}} + " Coord/key dictionary creation {{{ + function! s:CreateCoordKeyDict(groups, ...) + " Dict structure: + " 1,2 : a + " 2,3 : b + let sort_list = [] + let coord_keys = {} + let group_key = a:0 == 1 ? a:1 : '' + + for [key, item] in items(a:groups) + let key = ( ! empty(group_key) ? group_key : key) + + if type(item) == 3 + " Destination coords + + " The key needs to be zero-padded in order to + " sort correctly + let dict_key = printf('%05d,%05d', item[0], item[1]) + let coord_keys[dict_key] = key + + " We need a sorting list to loop correctly in + " PromptUser, dicts are unsorted + call add(sort_list, dict_key) + else + " Item is a dict (has children) + let coord_key_dict = s:CreateCoordKeyDict(item, key) + + " Make sure to extend both the sort list and the + " coord key dict + call extend(sort_list, coord_key_dict[0]) + call extend(coord_keys, coord_key_dict[1]) + endif + + unlet item + endfor + + return [sort_list, coord_keys] + endfunction + " }}} +" }}} +" Core functions {{{ + function! s:PromptUser(groups) "{{{ + " If only one possible match, jump directly to it {{{ + let group_values = values(a:groups) + + if len(group_values) == 1 + redraw + + return group_values[0] + endif + " }}} + " Prepare marker lines {{{ + let lines = {} + let hl_coords = [] + let coord_key_dict = s:CreateCoordKeyDict(a:groups) + + for dict_key in sort(coord_key_dict[0]) + let target_key = coord_key_dict[1][dict_key] + let [line_num, col_num] = split(dict_key, ',') + + let line_num = str2nr(line_num) + let col_num = str2nr(col_num) + + " Add original line and marker line + if ! has_key(lines, line_num) + let current_line = getline(line_num) + + let lines[line_num] = { 'orig': current_line, 'marker': current_line, 'mb_compensation': 0 } + endif + + " Compensate for byte difference between marker + " character and target character + " + " This has to be done in order to match the correct + " column; \%c matches the byte column and not display + " column. + let target_char_len = strlen(matchstr(lines[line_num]['marker'], '\%' . col_num . 'c.')) + let target_key_len = strlen(target_key) + + " Solve multibyte issues by matching the byte column + " number instead of the visual column + let col_num -= lines[line_num]['mb_compensation'] + + if strlen(lines[line_num]['marker']) > 0 + " Substitute marker character if line length > 0 + let lines[line_num]['marker'] = substitute(lines[line_num]['marker'], '\%' . col_num . 'c.', target_key, '') + else + " Set the line to the marker character if the line is empty + let lines[line_num]['marker'] = target_key + endif + + " Add highlighting coordinates + call add(hl_coords, '\%' . line_num . 'l\%' . col_num . 'c') + + " Add marker/target lenght difference for multibyte + " compensation + let lines[line_num]['mb_compensation'] += (target_char_len - target_key_len) + endfor + + let lines_items = items(lines) + " }}} + " Highlight targets {{{ + let target_hl_id = matchadd(g:EasyMotion_hl_group_target, join(hl_coords, '\|'), 1) + " }}} + + try + " Set lines with markers + call s:SetLines(lines_items, 'marker') + + redraw + + " Get target character {{{ + call s:Prompt('Target key') + + let char = s:GetChar() + " }}} + finally + " Restore original lines + call s:SetLines(lines_items, 'orig') + + " Un-highlight targets {{{ + if exists('target_hl_id') + call matchdelete(target_hl_id) + endif + " }}} + + redraw + endtry + + " Check if we have an input char {{{ + if empty(char) + throw 'Cancelled' + endif + " }}} + " Check if the input char is valid {{{ + if ! has_key(a:groups, char) + throw 'Invalid target' + endif + " }}} + + let target = a:groups[char] + + if type(target) == 3 + " Return target coordinates + return target + else + " Prompt for new target character + return s:PromptUser(target) + endif + endfunction "}}} + function! s:EasyMotion(regexp, direction, visualmode, mode) " {{{ + let orig_pos = [line('.'), col('.')] + let targets = [] + + try + " Reset properties {{{ + call s:VarReset('&scrolloff', 0) + call s:VarReset('&modified', 0) + call s:VarReset('&modifiable', 1) + call s:VarReset('&readonly', 0) + call s:VarReset('&spell', 0) + call s:VarReset('&virtualedit', '') + " }}} + " Find motion targets {{{ + let search_direction = (a:direction == 1 ? 'b' : '') + let search_stopline = line(a:direction == 1 ? 'w0' : 'w$') + + while 1 + let pos = searchpos(a:regexp, search_direction, search_stopline) + + " Reached end of search range + if pos == [0, 0] + break + endif + + " Skip folded lines + if foldclosed(pos[0]) != -1 + continue + endif + + call add(targets, pos) + endwhile + + let targets_len = len(targets) + if targets_len == 0 + throw 'No matches' + endif + " }}} + + let GroupingFn = function('s:GroupingAlgorithm' . s:grouping_algorithms[g:EasyMotion_grouping]) + let groups = GroupingFn(targets, split(g:EasyMotion_keys, '\zs')) + + " Shade inactive source {{{ + if g:EasyMotion_do_shade + let shade_hl_pos = '\%' . orig_pos[0] . 'l\%'. orig_pos[1] .'c' + + if a:direction == 1 + " Backward + let shade_hl_re = '\%'. line('w0') .'l\_.*' . shade_hl_pos + else + " Forward + let shade_hl_re = shade_hl_pos . '\_.*\%'. line('w$') .'l' + endif + + let shade_hl_id = matchadd(g:EasyMotion_hl_group_shade, shade_hl_re, 0) + endif + " }}} + + " Prompt user for target group/character + let coords = s:PromptUser(groups) + + " Update selection {{{ + if ! empty(a:visualmode) + keepjumps call cursor(orig_pos[0], orig_pos[1]) + + exec 'normal! ' . a:visualmode + endif + " }}} + " Handle operator-pending mode {{{ + if a:mode == 'no' + " This mode requires that we eat one more + " character to the right if we're using + " a forward motion + if a:direction != 1 + let coords[1] += 1 + endif + endif + " }}} + + " Update cursor position + call cursor(orig_pos[0], orig_pos[1]) + mark ' + call cursor(coords[0], coords[1]) + + call s:Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']') + catch + redraw + + " Show exception message + call s:Message(v:exception) + + " Restore original cursor position/selection {{{ + if ! empty(a:visualmode) + silent exec 'normal! gv' + else + keepjumps call cursor(orig_pos[0], orig_pos[1]) + endif + " }}} + finally + " Restore properties {{{ + call s:VarReset('&scrolloff') + call s:VarReset('&modified') + call s:VarReset('&modifiable') + call s:VarReset('&readonly') + call s:VarReset('&spell') + call s:VarReset('&virtualedit') + " }}} + " Remove shading {{{ + if g:EasyMotion_do_shade && exists('shade_hl_id') + call matchdelete(shade_hl_id) + endif + " }}} + endtry + endfunction " }}} +" }}} + +" vim: fdm=marker:noet:ts=4:sw=4:sts=4 diff --git a/vim/autoload/ZoomWin.vim b/vim/autoload/ZoomWin.vim new file mode 100644 index 0000000..d2d993f --- /dev/null +++ b/vim/autoload/ZoomWin.vim @@ -0,0 +1,380 @@ +" ZoomWin: Brief-like ability to zoom into/out-of a window +" Author: Charles Campbell +" original version by Ron Aaron +" Date: Jan 26, 2009 +" Version: 23 +" History: see :help zoomwin-history {{{1 +" GetLatestVimScripts: 508 1 :AutoInstall: ZoomWin.vim + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_ZoomWin") + finish +endif +if v:version < 702 + echohl WarningMsg + echo "***warning*** this version of ZoomWin needs vim 7.2" + echohl Normal + finish +endif +let s:keepcpo = &cpo +let g:loaded_ZoomWin = "v23" +set cpo&vim +"DechoTabOn + +" ===================================================================== +" Functions: {{{1 + +" --------------------------------------------------------------------- +" ZoomWin#ZoomWin: toggles between a single-window and a multi-window layout {{{2 +" The original version was by Ron Aaron. +fun! ZoomWin#ZoomWin() +" let g:decho_hide= 1 "Decho +" call Dfunc("ZoomWin#ZoomWin() winbufnr(2)=".winbufnr(2)) + + " if the vim doesn't have +mksession, only a partial zoom is available {{{3 + if !has("mksession") + if !exists("s:partialzoom") + echomsg "missing the +mksession feature; only a partial zoom is available" + let s:partialzoom= 0 + endif + if v:version < 630 + echoerr "***sorry*** you need an updated vim, preferably with +mksession" + elseif s:partialzoom + " partial zoom out + let s:partialzoom= 0 + exe s:winrestore + else + " partial zoom in + let s:partialzoom= 1 + let s:winrestore = winrestcmd() + res + endif +" call Dret("ZoomWin#ZoomWin : partialzoom=".s:partialzoom) + return + endif + + " Close certain windows {{{3 + call s:ZoomWinPreserve(0) + + " save options. Force window minimum height/width to be >= 1 {{{3 + let keep_hidden = &hidden + let keep_write = &write + + if v:version < 603 + if &wmh == 0 || &wmw == 0 + let keep_wmh = &wmh + let keep_wmw = &wmw + silent! set wmh=1 wmw=1 + endif + endif + set hidden write + + if winbufnr(2) == -1 + " there's only one window - restore to multiple-windows mode {{{3 +" call Decho("there's only one window - restore to multiple windows") + + if exists("s:sessionfile") && filereadable(s:sessionfile) + " save position in current one-window-only +" call Decho("save position in current one-window-only in sponly") + let sponly = s:SavePosn(0) + let s:origline = line(".") + let s:origcol = virtcol(".") + + " source session file to restore window layout + let ei_keep= &ei + set ei=all + exe 'silent! so '.fnameescape(s:sessionfile) +" Decho("@@<".@@.">") + let v:this_session= s:sesskeep + + if exists("s:savedposn1") + " restore windows' positioning and buffers +" call Decho("restore windows, positions, buffers") + windo call s:RestorePosn(s:savedposn{winnr()})|unlet s:savedposn{winnr()} + call s:GotoWinNum(s:winkeep) + unlet s:winkeep + endif + + if line(".") != s:origline || virtcol(".") != s:origcol + " If the cursor hasn't moved from the original position, + " then let the position remain what it was in the original + " multi-window layout. +" call Decho("restore position using sponly") + call s:RestorePosn(sponly) + endif + + " delete session file and variable holding its name +" call Decho("delete session file") + call delete(s:sessionfile) + unlet s:sessionfile + let &ei=ei_keep + endif + + else " there's more than one window - go to only-one-window mode {{{3 +" call Decho("there's multiple windows - goto one-window-only") + + let s:winkeep = winnr() + let s:sesskeep = v:this_session + + " doesn't work with the command line window (normal mode q:) + if &bt == "nofile" && expand("%") == (v:version < 702 ? 'command-line' : '[Command Line]') + echoerr "***error*** ZoomWin#ZoomWin doesn't work with the ".expand("%")." window" +" call Dret("ZoomWin#ZoomWin : ".expand('%')." window error") + return + endif +" call Decho("1: @@<".@@.">") + + " disable all events (autocmds) +" call Decho("disable events") + let ei_keep= &ei + set ei=all +" call Decho("2: @@<".@@.">") + + " save window positioning commands +" call Decho("save window positioning commands") + windo let s:savedposn{winnr()}= s:SavePosn(1) + call s:GotoWinNum(s:winkeep) + + " set up name of session file +" call Decho("3: @@<".@@.">") + let s:sessionfile= tempname() +" call Decho("4: @@<".@@.">") + + " save session +" call Decho("save session") + let ssop_keep = &ssop + let &ssop = 'blank,help,winsize,folds,globals,localoptions,options' +" call Decho("5: @@<".@@.">") + exe 'mksession! '.fnameescape(s:sessionfile) +" call Decho("6: @@<".@@.">") + let keepyy= @@ + let keepy0= @0 + let keepy1= @1 + let keepy2= @2 + let keepy3= @3 + let keepy4= @4 + let keepy5= @5 + let keepy6= @6 + let keepy7= @7 + let keepy8= @8 + let keepy9= @9 + set lz ei=all bh= + if v:version >= 700 + try + exe "keepalt keepmarks new! ".fnameescape(s:sessionfile) + catch /^Vim\%((\a\+)\)\=:E/ + echoerr "Too many windows" + silent! call delete(s:sessionfile) + unlet s:sessionfile +" call Dret("ZoomWin#ZoomWin : too many windows") + return + endtry + silent! keepjumps keepmarks v/wincmd\|split\|resize/d + keepalt w! + keepalt bw! + else + exe "new! ".fnameescape(s:sessionfile) + v/wincmd\|split\|resize/d + w! + bw! + endif + let @@= keepyy + let @0= keepy0 + let @1= keepy1 + let @2= keepy2 + let @3= keepy3 + let @4= keepy4 + let @5= keepy5 + let @6= keepy6 + let @7= keepy7 + let @8= keepy8 + let @9= keepy9 + call histdel('search', -1) + let @/ = histget('search', -1) +" call Decho("7: @@<".@@.">") + + " restore user's session options and restore event handling +" call Decho("restore user session options and event handling") + set nolz + let &ssop = ssop_keep + silent! only! +" call Decho("8: @@<".@@.">") + let &ei = ei_keep + echomsg expand("%") +" call Decho("9: @@<".@@.">") + endif + + " restore user option settings {{{3 +" call Decho("restore user option settings") + let &hidden= keep_hidden + let &write = keep_write + if v:version < 603 + if exists("keep_wmw") + let &wmh= keep_wmh + let &wmw= keep_wmw + endif + endif + + " Re-open certain windows {{{3 + call s:ZoomWinPreserve(1) + +" call Dret("ZoomWin#ZoomWin") +endfun + +" --------------------------------------------------------------------- +" SavePosn: this function sets up a savedposn variable that {{{2 +" has the commands necessary to restore the view +" of the current window. +fun! s:SavePosn(savewinhoriz) +" call Dfunc("SavePosn(savewinhoriz=".a:savewinhoriz.") file<".expand("%").">") + let swline = line(".") + if swline == 1 && getline(1) == "" + " empty buffer + let savedposn= "silent b ".winbufnr(0) +" call Dret("SavePosn savedposn<".savedposn.">") + return savedposn + endif + let swcol = col(".") + let swwline = winline()-1 + let swwcol = virtcol(".") - wincol() + let savedposn = "silent b ".winbufnr(0)."|".swline."|silent norm! z\" + if swwline > 0 + let savedposn= savedposn.":silent norm! ".swwline."\\:silent norm! zs\" + endif + let savedposn= savedposn.":silent call cursor(".swline.",".swcol.")\" + + if a:savewinhoriz + if swwcol > 0 + let savedposn= savedposn.":silent norm! ".swwcol."zl\" + endif + + " handle certain special settings for the multi-window savedposn call + " bufhidden buftype buflisted + let settings= "" + if &bh != "" + let settings="bh=".&bh + setlocal bh=hide + endif + if !&bl + let settings= settings." nobl" + setlocal bl + endif + if &bt != "" + let settings= settings." bt=".&bt + setlocal bt= + endif + if settings != "" + let savedposn= savedposn.":setlocal ".settings."\" + endif + + endif +" call Dret("SavePosn savedposn<".savedposn.">") + return savedposn +endfun + +" --------------------------------------------------------------------- +" s:RestorePosn: this function restores noname and scratch windows {{{2 +fun! s:RestorePosn(savedposn) +" call Dfunc("RestorePosn(savedposn<".a:savedposn.">) file<".expand("%").">") + if &scb + setlocal noscb + exe a:savedposn + setlocal scb + else + exe a:savedposn + endif +" call Dret("RestorePosn") +endfun + +" --------------------------------------------------------------------- +" CleanupSessionFile: if you exit Vim before cleaning up the {{{2 +" supposed-to-be temporary session file +fun! ZoomWin#CleanupSessionFile() +" call Dfunc("ZoomWin#CleanupSessionFile()") + if exists("s:sessionfile") && filereadable(s:sessionfile) +" call Decho("sessionfile exists and is readable; deleting it") + silent! call delete(s:sessionfile) + unlet s:sessionfile + endif +" call Dret("ZoomWin#CleanupSessionFile") +endfun + +" --------------------------------------------------------------------- +" GotoWinNum: this function puts cursor into specified window {{{2 +fun! s:GotoWinNum(winnum) +" call Dfunc("GotoWinNum(winnum=".a:winnum.") winnr=".winnr()) + if a:winnum != winnr() + exe a:winnum."wincmd w" + endif +" call Dret("GotoWinNum") +endfun + + +" --------------------------------------------------------------------- +" ZoomWinPreserve: This function, largely written by David Fishburn, {{{2 +" allows ZoomWin to "preserve" certain windows: +" +" TagList, by Yegappan Lakshmanan +" http://vim.sourceforge.net/scripts/script.php?script_id=273 +" +" WinManager, by Srinath Avadhanula +" http://vim.sourceforge.net/scripts/script.php?script_id=95 +" +" It does so by closing the associated window upon entry to ZoomWin +" and re-opening it upon exit by using commands provided by the +" utilities themselves. +fun! s:ZoomWinPreserve(open) +" call Dfunc("ZoomWinPreserve(open=".a:open.")") + + if a:open == 0 + + " Close Taglist + if exists('g:zoomwin_preserve_taglist') && exists('g:loaded_taglist') + " If taglist window is open then close it. + let s:taglist_winnum = bufwinnr(g:TagList_title) + if s:taglist_winnum != -1 + " Close the window + exec "silent! Tlist" + endif + endif + + " Close Winmanager + if exists('g:zoomwin_preserve_winmanager') && exists('g:loaded_winmanager') + " If the winmanager window is open then close it. + let s:is_winmgr_vis = IsWinManagerVisible() + if s:is_winmgr_vis == 1 + exec "WMClose" + endif + endif + + else + + " Re-open Taglist + if exists('g:zoomwin_preserve_taglist') && exists('g:loaded_taglist') + " If taglist window was open, open it again + if s:taglist_winnum != -1 + exec "silent! Tlist" + endif + endif + + " Re-Open Winmanager + if exists('g:zoomwin_preserve_winmanager') && exists('g:loaded_winmanager') + " If the winmanager window is open then close it. + if s:is_winmgr_vis == 1 + exec "WManager" + endif + endif + endif + +" call Dret("ZoomWinPreserve") +endfun + +" ===================================================================== +" Restore: {{{1 +let &cpo= s:keepcpo +unlet s:keepcpo + +" --------------------------------------------------------------------- +" Modelines: {{{1 +" vim: ts=4 fdm=marker diff --git a/vim/autoload/conque_term.vim b/vim/autoload/conque_term.vim new file mode 100644 index 0000000..2780c7d --- /dev/null +++ b/vim/autoload/conque_term.vim @@ -0,0 +1,1590 @@ +" FILE: plugin/conque_term.vim {{{ +" +" AUTHOR: Nico Raffo +" MODIFIED: 2010-05-27 +" VERSION: 1.1, for Vim 7.0 +" LICENSE: +" Conque - pty interaction in Vim +" Copyright (C) 2009-2010 Nico Raffo +" +" MIT License +" +" Permission is hereby granted, free of charge, to any person obtaining a copy +" of this software and associated documentation files (the "Software"), to deal +" in the Software without restriction, including without limitation the rights +" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +" copies of the Software, and to permit persons to whom the Software is +" furnished to do so, subject to the following conditions: +" +" The above copyright notice and this permission notice shall be included in +" all copies or substantial portions of the Software. +" +" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +" THE SOFTWARE. +" }}} + + +" ********************************************************************************************************** +" **** VIM FUNCTIONS *************************************************************************************** +" ********************************************************************************************************** + +" launch conque +function! conque_term#open(...) "{{{ + let command = get(a:000, 0, '') + let hooks = get(a:000, 1, []) + + " bare minimum validation + if has('python') != 1 + echohl WarningMsg | echomsg "Conque requires the Python interface to be installed" | echohl None + return 0 + endif + if empty(command) + echohl WarningMsg | echomsg "No command found" | echohl None + return 0 + else + let l:cargs = split(command, '\s') + if !executable(l:cargs[0]) + echohl WarningMsg | echomsg "Not an executable: " . l:cargs[0] | echohl None + return 0 + endif + endif + + " set buffer window options + let g:ConqueTerm_BufName = substitute(command, ' ', '\\ ', 'g') . "\\ -\\ " . g:ConqueTerm_Idx + call conque_term#set_buffer_settings(command, hooks) + let b:ConqueTerm_Var = 'ConqueTerm_' . g:ConqueTerm_Idx + let g:ConqueTerm_Var = 'ConqueTerm_' . g:ConqueTerm_Idx + let g:ConqueTerm_Idx += 1 + + " open command + try + let l:config = '{"color":' . string(g:ConqueTerm_Color) . ',"TERM":"' . g:ConqueTerm_TERM . '"}' + execute 'python ' . b:ConqueTerm_Var . ' = Conque()' + execute "python " . b:ConqueTerm_Var . ".open('" . conque_term#python_escape(command) . "', " . l:config . ")" + catch + echohl WarningMsg | echomsg "Unable to open command: " . command | echohl None + return 0 + endtry + + " set buffer mappings and auto commands + call conque_term#set_mappings('start') + + startinsert! + return 1 +endfunction "}}} + +" set buffer options +function! conque_term#set_buffer_settings(command, pre_hooks) "{{{ + + " optional hooks to execute, e.g. 'split' + for h in a:pre_hooks + sil exe h + endfor + sil exe "edit " . g:ConqueTerm_BufName + + " buffer settings + setlocal nocompatible " conque won't work in compatible mode + setlocal nopaste " conque won't work in paste mode + setlocal buftype=nofile " this buffer is not a file, you can't save it + setlocal nonumber " hide line numbers + setlocal foldcolumn=0 " reasonable left margin + setlocal nowrap " default to no wrap (esp with MySQL) + setlocal noswapfile " don't bother creating a .swp file + setlocal updatetime=50 " trigger cursorhold event after 50ms / XXX - global + setlocal scrolloff=0 " don't use buffer lines. it makes the 'clear' command not work as expected + setlocal sidescrolloff=0 " don't use buffer lines. it makes the 'clear' command not work as expected + setlocal sidescroll=1 " don't use buffer lines. it makes the 'clear' command not work as expected + setlocal foldmethod=manual " don't fold on {{{}}} and stuff + setlocal bufhidden=hide " when buffer is no longer displayed, don't wipe it out + setfiletype conque_term " useful + sil exe "setlocal syntax=" . g:ConqueTerm_Syntax + +endfunction " }}} + +" set key mappings and auto commands +function! conque_term#set_mappings(action) "{{{ + + " set action + if a:action == 'toggle' + if exists('b:conque_on') && b:conque_on == 1 + let l:action = 'stop' + echohl WarningMsg | echomsg "Terminal is paused" | echohl None + else + let l:action = 'start' + echohl WarningMsg | echomsg "Terminal is resumed" | echohl None + endif + else + let l:action = a:action + endif + + " if mappings are being removed, add 'un' + let map_modifier = 'nore' + if l:action == 'stop' + let map_modifier = 'un' + endif + + " remove all auto commands + if l:action == 'stop' + execute 'autocmd! ' . b:ConqueTerm_Var + + else + execute 'augroup ' . b:ConqueTerm_Var + + " handle unexpected closing of shell, passes HUP to parent and all child processes + execute 'autocmd ' . b:ConqueTerm_Var . ' BufUnload python ' . b:ConqueTerm_Var . '.proc.signal(1)' + + " check for resized/scrolled buffer when entering buffer + execute 'autocmd ' . b:ConqueTerm_Var . ' BufEnter python ' . b:ConqueTerm_Var . '.update_window_size()' + execute 'autocmd ' . b:ConqueTerm_Var . ' VimResized python ' . b:ConqueTerm_Var . '.update_window_size()' + + " set/reset updatetime on entering/exiting buffer + autocmd BufEnter set updatetime=50 + autocmd BufLeave set updatetime=2000 + + " check for resized/scrolled buffer when entering insert mode + " XXX - messed up since we enter insert mode at each updatetime + "execute 'autocmd InsertEnter python ' . b:ConqueTerm_Var . '.screen.align()' + + " read more output when this isn't the current buffer + if g:ConqueTerm_ReadUnfocused == 1 + execute 'autocmd ' . b:ConqueTerm_Var . ' CursorHold * call conque_term#read_all()' + endif + + " poll for more output + sil execute 'autocmd ' . b:ConqueTerm_Var . ' CursorHoldI python ' . b:ConqueTerm_Var . '.auto_read()' + endif + + " use F22 key to get more input + if l:action == 'start' + sil exe 'i' . map_modifier . 'map "\\"' + sil exe 'i' . map_modifier . 'map "\\"' + else + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + endif + + " map ASCII 1-31 + for c in range(1, 31) + " + if c == 27 + continue + endif + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(' . c . '))' + else + sil exe 'i' . map_modifier . 'map ' + endif + endfor + if l:action == 'start' + sil exe 'n' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(3))' + else + sil exe 'n' . map_modifier . 'map ' + endif + + " leave insert mode + if !exists('g:ConqueTerm_EscKey') || g:ConqueTerm_EscKey == '' + " use to send to terminal + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(27))' + else + sil exe 'i' . map_modifier . 'map ' + endif + else + " use to send to terminal + if l:action == 'start' + sil exe 'i' . map_modifier . 'map ' . g:ConqueTerm_EscKey . ' ' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(27))' + else + sil exe 'i' . map_modifier . 'map ' . g:ConqueTerm_EscKey + sil exe 'i' . map_modifier . 'map ' + endif + endif + + " Map in insert mode + if exists('g:ConqueTerm_CWInsert') && g:ConqueTerm_CWInsert == 1 + inoremap j j + inoremap k k + inoremap h h + inoremap l l + inoremap w w + endif + + " map ASCII 33-127 + for i in range(33, 127) + " + if i == 124 + if l:action == 'start' + sil exe "i" . map_modifier . "map :python " . b:ConqueTerm_Var . ".write(chr(124))" + else + sil exe "i" . map_modifier . "map " + endif + continue + endif + if l:action == 'start' + sil exe "i" . map_modifier . "map " . nr2char(i) . " :python " . b:ConqueTerm_Var . ".write(chr(" . i . "))" + else + sil exe "i" . map_modifier . "map " . nr2char(i) + endif + endfor + + " map ASCII 128-255 + for i in range(128, 255) + if l:action == 'start' + sil exe "i" . map_modifier . "map " . nr2char(i) . " :python " . b:ConqueTerm_Var . ".write('" . nr2char(i) . "')" + else + sil exe "i" . map_modifier . "map " . nr2char(i) + endif + endfor + + " Special cases + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u0008")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(" ")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[A")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[B")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[C")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[D")' + else + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + endif + + " send selected text into conque + if l:action == 'start' + sil exe 'v' . map_modifier . 'map :call conque_term#send_selected(visualmode())' + else + sil exe 'v' . map_modifier . 'map ' + endif + + " remap paste keys + if l:action == 'start' + sil exe 'n' . map_modifier . 'map p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + sil exe 'n' . map_modifier . 'map P :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + sil exe 'n' . map_modifier . 'map ]p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + sil exe 'n' . map_modifier . 'map [p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + else + sil exe 'n' . map_modifier . 'map p' + sil exe 'n' . map_modifier . 'map P' + sil exe 'n' . map_modifier . 'map ]p' + sil exe 'n' . map_modifier . 'map [p' + endif + if has('gui_running') + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . ".write(vim.eval('@+'))a" + else + sil exe 'i' . map_modifier . 'map ' + endif + endif + + " disable other normal mode keys which insert text + if l:action == 'start' + sil exe 'n' . map_modifier . 'map r :echo "Replace mode disabled in shell."' + sil exe 'n' . map_modifier . 'map R :echo "Replace mode disabled in shell."' + sil exe 'n' . map_modifier . 'map c :echo "Change mode disabled in shell."' + sil exe 'n' . map_modifier . 'map C :echo "Change mode disabled in shell."' + sil exe 'n' . map_modifier . 'map s :echo "Change mode disabled in shell."' + sil exe 'n' . map_modifier . 'map S :echo "Change mode disabled in shell."' + else + sil exe 'n' . map_modifier . 'map r' + sil exe 'n' . map_modifier . 'map R' + sil exe 'n' . map_modifier . 'map c' + sil exe 'n' . map_modifier . 'map C' + sil exe 'n' . map_modifier . 'map s' + sil exe 'n' . map_modifier . 'map S' + endif + + " set conque as on or off + if l:action == 'start' + let b:conque_on = 1 + else + let b:conque_on = 0 + endif + + " map command to start stop the shell + if a:action == 'start' + nnoremap :call conque_term#set_mappings('toggle') + endif + +endfunction " }}} + + +" send selected text from another buffer +function! conque_term#send_selected(type) "{{{ + let reg_save = @@ + + " save user's sb settings + let sb_save = &switchbuf + set switchbuf=usetab + + " yank current selection + sil exe "normal! `<" . a:type . "`>y" + + " format yanked text + let @@ = substitute(@@, '^[\r\n]*', '', '') + let @@ = substitute(@@, '[\r\n]*$', '', '') + + " execute yanked text + sil exe ":sb " . g:ConqueTerm_BufName + sil exe 'python ' . g:ConqueTerm_Var . '.paste_selection()' + + " reset original values + let @@ = reg_save + sil exe 'set switchbuf=' . sb_save + + " scroll buffer left + startinsert! + normal 0zH +endfunction "}}} + +" read from all known conque buffers +function! conque_term#read_all() "{{{ + " don't run this if we're in a conque buffer + if exists('b:ConqueTerm_Var') + return + endif + + try + for i in range(1, g:ConqueTerm_Idx - 1) + execute 'python ConqueTerm_' . string(i) . '.read(1)' + endfor + catch + " probably a deleted buffer + endtry + + " restart updatetime + call feedkeys("f\e") +endfunction "}}} + +" util function to add enough \s to pass a string to python +function! conque_term#python_escape(input) "{{{ + let l:cleaned = a:input + let l:cleaned = substitute(l:cleaned, '\\', '\\\\', 'g') + let l:cleaned = substitute(l:cleaned, '\n', '\\n', 'g') + let l:cleaned = substitute(l:cleaned, '\r', '\\r', 'g') + let l:cleaned = substitute(l:cleaned, "'", "\\\\'", 'g') + return l:cleaned +endfunction "}}} + +" ********************************************************************************************************** +" **** PYTHON ********************************************************************************************** +" ********************************************************************************************************** + +if has('python') + +python << EOF + +import vim, re, time, math + +# CONFIG CONSTANTS {{{ + +CONQUE_CTL = { + 7:'bel', # bell + 8:'bs', # backspace + 9:'tab', # tab + 10:'nl', # new line + 13:'cr' # carriage return +} +# 11 : 'vt', # vertical tab +# 12 : 'ff', # form feed +# 14 : 'so', # shift out +# 15 : 'si' # shift in + +# Escape sequences +CONQUE_ESCAPE = { + 'm':'font', + 'J':'clear_screen', + 'K':'clear_line', + '@':'add_spaces', + 'A':'cursor_up', + 'B':'cursor_down', + 'C':'cursor_right', + 'D':'cursor_left', + 'G':'cursor_to_column', + 'H':'cursor', + 'P':'delete_chars', + 'f':'cursor', + 'g':'tab_clear', + 'r':'set_coords', + 'h':'set', + 'l':'reset' +} +# 'L':'insert_lines', +# 'M':'delete_lines', +# 'd':'cusor_vpos', + +# Alternate escape sequences, no [ +CONQUE_ESCAPE_PLAIN = { + 'D':'scroll_up', + 'E':'next_line', + 'H':'set_tab', + 'M':'scroll_down' +} +# 'N':'single_shift_2', +# 'O':'single_shift_3', +# '=':'alternate_keypad', +# '>':'numeric_keypad', +# '7':'save_cursor', +# '8':'restore_cursor', + +# Uber alternate escape sequences, with # or ? +CONQUE_ESCAPE_QUESTION = { + '1h':'new_line_mode', + '3h':'132_cols', + '4h':'smooth_scrolling', + '5h':'reverse_video', + '6h':'relative_origin', + '7h':'set_auto_wrap', + '8h':'set_auto_repeat', + '9h':'set_interlacing_mode', + '1l':'set_cursor_key', + '2l':'set_vt52', + '3l':'80_cols', + '4l':'set_jump_scrolling', + '5l':'normal_video', + '6l':'absolute_origin', + '7l':'reset_auto_wrap', + '8l':'reset_auto_repeat', + '9l':'reset_interlacing_mode' +} + +CONQUE_ESCAPE_HASH = { + '8':'screen_alignment_test' +} +# '3':'double_height_top', +# '4':'double_height_bottom', +# '5':'single_height_single_width', +# '6':'single_height_double_width', + +# Font codes {{{ +CONQUE_FONT = { + 0: {'description':'Normal (default)', 'attributes': {'cterm':'NONE','ctermfg':'NONE','ctermbg':'NONE','gui':'NONE','guifg':'NONE','guibg':'NONE'}, 'normal':True}, + 1: {'description':'Bold', 'attributes': {'cterm':'BOLD','gui':'BOLD'}, 'normal':False}, + 4: {'description':'Underlined', 'attributes': {'cterm':'UNDERLINE','gui':'UNDERLINE'}, 'normal':False}, + 5: {'description':'Blink (appears as Bold)', 'attributes': {'cterm':'BOLD','gui':'BOLD'}, 'normal':False}, + 7: {'description':'Inverse', 'attributes': {'cterm':'REVERSE','gui':'REVERSE'}, 'normal':False}, + 8: {'description':'Invisible (hidden)', 'attributes': {'ctermfg':'0','ctermbg':'0','guifg':'#000000','guibg':'#000000'}, 'normal':False}, + 22: {'description':'Normal (neither bold nor faint)', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 24: {'description':'Not underlined', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 25: {'description':'Steady (not blinking)', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 27: {'description':'Positive (not inverse)', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 28: {'description':'Visible (not hidden)', 'attributes': {'ctermfg':'NONE','ctermbg':'NONE','guifg':'NONE','guibg':'NONE'}, 'normal':True}, + 30: {'description':'Set foreground color to Black', 'attributes': {'ctermfg':'16','guifg':'#000000'}, 'normal':False}, + 31: {'description':'Set foreground color to Red', 'attributes': {'ctermfg':'1','guifg':'#ff0000'}, 'normal':False}, + 32: {'description':'Set foreground color to Green', 'attributes': {'ctermfg':'2','guifg':'#00ff00'}, 'normal':False}, + 33: {'description':'Set foreground color to Yellow', 'attributes': {'ctermfg':'3','guifg':'#ffff00'}, 'normal':False}, + 34: {'description':'Set foreground color to Blue', 'attributes': {'ctermfg':'4','guifg':'#0000ff'}, 'normal':False}, + 35: {'description':'Set foreground color to Magenta', 'attributes': {'ctermfg':'5','guifg':'#990099'}, 'normal':False}, + 36: {'description':'Set foreground color to Cyan', 'attributes': {'ctermfg':'6','guifg':'#009999'}, 'normal':False}, + 37: {'description':'Set foreground color to White', 'attributes': {'ctermfg':'7','guifg':'#ffffff'}, 'normal':False}, + 39: {'description':'Set foreground color to default (original)', 'attributes': {'ctermfg':'NONE','guifg':'NONE'}, 'normal':True}, + 40: {'description':'Set background color to Black', 'attributes': {'ctermbg':'16','guibg':'#000000'}, 'normal':False}, + 41: {'description':'Set background color to Red', 'attributes': {'ctermbg':'1','guibg':'#ff0000'}, 'normal':False}, + 42: {'description':'Set background color to Green', 'attributes': {'ctermbg':'2','guibg':'#00ff00'}, 'normal':False}, + 43: {'description':'Set background color to Yellow', 'attributes': {'ctermbg':'3','guibg':'#ffff00'}, 'normal':False}, + 44: {'description':'Set background color to Blue', 'attributes': {'ctermbg':'4','guibg':'#0000ff'}, 'normal':False}, + 45: {'description':'Set background color to Magenta', 'attributes': {'ctermbg':'5','guibg':'#990099'}, 'normal':False}, + 46: {'description':'Set background color to Cyan', 'attributes': {'ctermbg':'6','guibg':'#009999'}, 'normal':False}, + 47: {'description':'Set background color to White', 'attributes': {'ctermbg':'7','guibg':'#ffffff'}, 'normal':False}, + 49: {'description':'Set background color to default (original).', 'attributes': {'ctermbg':'NONE','guibg':'NONE'}, 'normal':True}, + 90: {'description':'Set foreground color to Black', 'attributes': {'ctermfg':'8','guifg':'#000000'}, 'normal':False}, + 91: {'description':'Set foreground color to Red', 'attributes': {'ctermfg':'9','guifg':'#ff0000'}, 'normal':False}, + 92: {'description':'Set foreground color to Green', 'attributes': {'ctermfg':'10','guifg':'#00ff00'}, 'normal':False}, + 93: {'description':'Set foreground color to Yellow', 'attributes': {'ctermfg':'11','guifg':'#ffff00'}, 'normal':False}, + 94: {'description':'Set foreground color to Blue', 'attributes': {'ctermfg':'12','guifg':'#0000ff'}, 'normal':False}, + 95: {'description':'Set foreground color to Magenta', 'attributes': {'ctermfg':'13','guifg':'#990099'}, 'normal':False}, + 96: {'description':'Set foreground color to Cyan', 'attributes': {'ctermfg':'14','guifg':'#009999'}, 'normal':False}, + 97: {'description':'Set foreground color to White', 'attributes': {'ctermfg':'15','guifg':'#ffffff'}, 'normal':False}, + 100: {'description':'Set background color to Black', 'attributes': {'ctermbg':'8','guibg':'#000000'}, 'normal':False}, + 101: {'description':'Set background color to Red', 'attributes': {'ctermbg':'9','guibg':'#ff0000'}, 'normal':False}, + 102: {'description':'Set background color to Green', 'attributes': {'ctermbg':'10','guibg':'#00ff00'}, 'normal':False}, + 103: {'description':'Set background color to Yellow', 'attributes': {'ctermbg':'11','guibg':'#ffff00'}, 'normal':False}, + 104: {'description':'Set background color to Blue', 'attributes': {'ctermbg':'12','guibg':'#0000ff'}, 'normal':False}, + 105: {'description':'Set background color to Magenta', 'attributes': {'ctermbg':'13','guibg':'#990099'}, 'normal':False}, + 106: {'description':'Set background color to Cyan', 'attributes': {'ctermbg':'14','guibg':'#009999'}, 'normal':False}, + 107: {'description':'Set background color to White', 'attributes': {'ctermbg':'15','guibg':'#ffffff'}, 'normal':False} +} +# }}} + +# regular expression matching (almost) all control sequences +CONQUE_SEQ_REGEX = re.compile(ur"(\u001b\[?\??#?[0-9;]*[a-zA-Z@]|\u001b\][0-9];.*?\u0007|[\u0007-\u000f])", re.UNICODE) +CONQUE_SEQ_REGEX_CTL = re.compile(ur"^[\u0007-\u000f]$", re.UNICODE) +CONQUE_SEQ_REGEX_CSI = re.compile(ur"^\u001b\[", re.UNICODE) +CONQUE_SEQ_REGEX_TITLE = re.compile(ur"^\u001b\]", re.UNICODE) +CONQUE_SEQ_REGEX_HASH = re.compile(ur"^\u001b#", re.UNICODE) +CONQUE_SEQ_REGEX_ESC = re.compile(ur"^\u001b", re.UNICODE) + +# match table output +CONQUE_TABLE_OUTPUT = re.compile("^\s*\|\s.*\s\|\s*$|^\s*\+[=+-]+\+\s*$") + +# }}} + +################################################################################################### +class Conque: + + # CLASS PROPERTIES {{{ + + # screen object + screen = None + + # subprocess object + proc = None + + # terminal dimensions and scrolling region + columns = 80 # same as $COLUMNS + lines = 24 # same as $LINES + working_columns = 80 # can be changed by CSI ? 3 l/h + working_lines = 24 # can be changed by CSI r + + # top/bottom of the scroll region + top = 1 # relative to top of screen + bottom = 24 # relative to top of screen + + # cursor position + l = 1 # current cursor line + c = 1 # current cursor column + + # autowrap mode + autowrap = True + + # absolute coordinate mode + absolute_coords = True + + # tabstop positions + tabstops = [] + + # enable colors + enable_colors = True + + # color changes + color_changes = {} + + # color history + color_history = {} + + # don't wrap table output + unwrap_tables = True + + # wrap CUF/CUB around line breaks + wrap_cursor = False + + # }}} + + # constructor + def __init__(self): # {{{ + self.screen = ConqueScreen() + # }}} + + # start program and initialize this instance + def open(self, command, options): # {{{ + + # int vars + self.columns = vim.current.window.width + self.lines = vim.current.window.height + self.working_columns = vim.current.window.width + self.working_lines = vim.current.window.height + self.bottom = vim.current.window.height + + # init color + self.enable_colors = options['color'] + + # init tabstops + self.init_tabstops() + + # open command + self.proc = ConqueSubprocess() + self.proc.open(command, { 'TERM' : options['TERM'], 'CONQUE' : '1', 'LINES' : str(self.lines), 'COLUMNS' : str(self.columns)}) + # }}} + + # write to pty + def write(self, input): # {{{ + + + # check if window size has changed + self.update_window_size() + + # write and read + self.proc.write(input) + self.read(1) + # }}} + + # read from pty, and update buffer + def read(self, timeout = 1): # {{{ + # read from subprocess + output = self.proc.read(timeout) + # and strip null chars + output = output.replace(chr(0), '') + + if output == '': + return + + + + + + chunks = CONQUE_SEQ_REGEX.split(output) + + + + + + # don't go through all the csi regex if length is one (no matches) + if len(chunks) == 1: + + self.plain_text(chunks[0]) + + else: + for s in chunks: + if s == '': + continue + + + + + + + # Check for control character match {{{ + if CONQUE_SEQ_REGEX_CTL.match(s[0]): + + nr = ord(s[0]) + if nr in CONQUE_CTL: + getattr(self, 'ctl_' + CONQUE_CTL[nr])() + else: + + pass + # }}} + + # check for escape sequence match {{{ + elif CONQUE_SEQ_REGEX_CSI.match(s): + + if s[-1] in CONQUE_ESCAPE: + csi = self.parse_csi(s[2:]) + + getattr(self, 'csi_' + CONQUE_ESCAPE[s[-1]])(csi) + else: + + pass + # }}} + + # check for title match {{{ + elif CONQUE_SEQ_REGEX_TITLE.match(s): + + self.change_title(s[2], s[4:-1]) + # }}} + + # check for hash match {{{ + elif CONQUE_SEQ_REGEX_HASH.match(s): + + if s[-1] in CONQUE_ESCAPE_HASH: + getattr(self, 'hash_' + CONQUE_ESCAPE_HASH[s[-1]])() + else: + + pass + # }}} + + # check for other escape match {{{ + elif CONQUE_SEQ_REGEX_ESC.match(s): + + if s[-1] in CONQUE_ESCAPE_PLAIN: + getattr(self, 'esc_' + CONQUE_ESCAPE_PLAIN[s[-1]])() + else: + + pass + # }}} + + # else process plain text {{{ + else: + self.plain_text(s) + # }}} + + # set cursor position + self.screen.set_cursor(self.l, self.c) + + vim.command('redraw') + + + # }}} + + # for polling + def auto_read(self): # {{{ + self.read(1) + if self.c == 1: + vim.command('call feedkeys("\", "t")') + else: + vim.command('call feedkeys("\", "t")') + self.screen.set_cursor(self.l, self.c) + # }}} + + ############################################################################################### + # Plain text # {{{ + + def plain_text(self, input): + + current_line = self.screen[self.l] + + if len(current_line) < self.working_columns: + current_line = current_line + ' ' * (self.c - len(current_line)) + + # if line is wider than screen + if self.c + len(input) - 1 > self.working_columns: + # Table formatting hack + if self.unwrap_tables and CONQUE_TABLE_OUTPUT.match(input): + self.screen[self.l] = current_line[ : self.c - 1] + input + current_line[ self.c + len(input) - 1 : ] + self.apply_color(self.c, self.c + len(input)) + self.c += len(input) + return + + diff = self.c + len(input) - self.working_columns - 1 + # if autowrap is enabled + if self.autowrap: + self.screen[self.l] = current_line[ : self.c - 1] + input[ : -1 * diff ] + self.apply_color(self.c, self.working_columns) + self.ctl_nl() + self.ctl_cr() + remaining = input[ -1 * diff : ] + + self.plain_text(remaining) + else: + self.screen[self.l] = current_line[ : self.c - 1] + input[ : -1 * diff - 1 ] + input[-1] + self.apply_color(self.c, self.working_columns) + self.c = self.working_columns + + # no autowrap + else: + self.screen[self.l] = current_line[ : self.c - 1] + input + current_line[ self.c + len(input) - 1 : ] + self.apply_color(self.c, self.c + len(input)) + self.c += len(input) + + def apply_color(self, start, end): + + + # stop here if coloration is disabled + if not self.enable_colors: + return + + real_line = self.screen.get_real_line(self.l) + + # check for previous overlapping coloration + + to_del = [] + if self.color_history.has_key(real_line): + for i in range(len(self.color_history[real_line])): + syn = self.color_history[real_line][i] + + if syn['start'] >= start and syn['start'] < end: + + vim.command('syn clear ' + syn['name']) + to_del.append(i) + # outside + if syn['end'] > end: + + self.exec_highlight(real_line, end, syn['end'], syn['highlight']) + elif syn['end'] > start and syn['end'] <= end: + + vim.command('syn clear ' + syn['name']) + to_del.append(i) + # outside + if syn['start'] < start: + + self.exec_highlight(real_line, syn['start'], start, syn['highlight']) + + if len(to_del) > 0: + to_del.reverse() + for di in to_del: + del self.color_history[real_line][di] + + # if there are no new colors + if len(self.color_changes) == 0: + return + + highlight = '' + for attr in self.color_changes.keys(): + highlight = highlight + ' ' + attr + '=' + self.color_changes[attr] + + # execute the highlight + self.exec_highlight(real_line, start, end, highlight) + + def exec_highlight(self, real_line, start, end, highlight): + unique_key = str(self.proc.pid) + + syntax_name = 'EscapeSequenceAt_' + unique_key + '_' + str(self.l) + '_' + str(start) + '_' + str(len(self.color_history) + 1) + syntax_options = ' contains=ALLBUT,ConqueString,MySQLString,MySQLKeyword oneline' + syntax_region = 'syntax match ' + syntax_name + ' /\%' + str(real_line) + 'l\%>' + str(start - 1) + 'c.*\%<' + str(end + 1) + 'c/' + syntax_options + syntax_highlight = 'highlight ' + syntax_name + highlight + + vim.command(syntax_region) + vim.command(syntax_highlight) + + # add syntax name to history + if not self.color_history.has_key(real_line): + self.color_history[real_line] = [] + + self.color_history[real_line].append({'name':syntax_name, 'start':start, 'end':end, 'highlight':highlight}) + + # }}} + + ############################################################################################### + # Control functions {{{ + + def ctl_nl(self): + # if we're in a scrolling region, scroll instead of moving cursor down + if self.lines != self.working_lines and self.l == self.bottom: + del self.screen[self.top] + self.screen.insert(self.bottom, '') + elif self.l == self.bottom: + self.screen.append('') + else: + self.l += 1 + + self.color_changes = {} + + def ctl_cr(self): + self.c = 1 + + self.color_changes = {} + + def ctl_bs(self): + if self.c > 1: + self.c += -1 + + def ctl_bel(self): + print 'BELL' + + def ctl_tab(self): + # default tabstop location + ts = self.working_columns + + # check set tabstops + for i in range(self.c, len(self.tabstops)): + if self.tabstops[i]: + ts = i + 1 + break + + + + self.c = ts + + # }}} + + ############################################################################################### + # CSI functions {{{ + + def csi_font(self, csi): # {{{ + if not self.enable_colors: + return + + # defaults to 0 + if len(csi['vals']) == 0: + csi['vals'] = [0] + + # 256 xterm color foreground + if len(csi['vals']) == 3 and csi['vals'][0] == 38 and csi['vals'][1] == 5: + self.color_changes['ctermfg'] = str(csi['vals'][2]) + self.color_changes['guifg'] = '#' + self.xterm_to_rgb(csi['vals'][2]) + + # 256 xterm color background + elif len(csi['vals']) == 3 and csi['vals'][0] == 48 and csi['vals'][1] == 5: + self.color_changes['ctermbg'] = str(csi['vals'][2]) + self.color_changes['guibg'] = '#' + self.xterm_to_rgb(csi['vals'][2]) + + # 16 colors + else: + for val in csi['vals']: + if CONQUE_FONT.has_key(val): + + # ignore starting normal colors + if CONQUE_FONT[val]['normal'] and len(self.color_changes) == 0: + + continue + # clear color changes + elif CONQUE_FONT[val]['normal']: + + self.color_changes = {} + # save these color attributes for next plain_text() call + else: + + for attr in CONQUE_FONT[val]['attributes'].keys(): + if self.color_changes.has_key(attr) and (attr == 'cterm' or attr == 'gui'): + self.color_changes[attr] += ',' + CONQUE_FONT[val]['attributes'][attr] + else: + self.color_changes[attr] = CONQUE_FONT[val]['attributes'][attr] + # }}} + + def csi_clear_line(self, csi): # {{{ + + + # this escape defaults to 0 + if len(csi['vals']) == 0: + csi['val'] = 0 + + + + + # 0 means cursor right + if csi['val'] == 0: + self.screen[self.l] = self.screen[self.l][0 : self.c - 1] + + # 1 means cursor left + elif csi['val'] == 1: + self.screen[self.l] = ' ' * (self.c) + self.screen[self.l][self.c : ] + + # clear entire line + elif csi['val'] == 2: + self.screen[self.l] = '' + + # clear colors + if csi['val'] == 2 or (csi['val'] == 0 and self.c == 1): + real_line = self.screen.get_real_line(self.l) + if self.color_history.has_key(real_line): + for syn in self.color_history[real_line]: + vim.command('syn clear ' + syn['name']) + + + + # }}} + + def csi_cursor_right(self, csi): # {{{ + # we use 1 even if escape explicitly specifies 0 + if csi['val'] == 0: + csi['val'] = 1 + + + + + if self.wrap_cursor and self.c + csi['val'] > self.working_columns: + self.l += int(math.floor( (self.c + csi['val']) / self.working_columns )) + self.c = (self.c + csi['val']) % self.working_columns + return + + self.c = self.bound(self.c + csi['val'], 1, self.working_columns) + # }}} + + def csi_cursor_left(self, csi): # {{{ + # we use 1 even if escape explicitly specifies 0 + if csi['val'] == 0: + csi['val'] = 1 + + if self.wrap_cursor and csi['val'] >= self.c: + self.l += int(math.floor( (self.c - csi['val']) / self.working_columns )) + self.c = self.working_columns - (csi['val'] - self.c) % self.working_columns + return + + self.c = self.bound(self.c - csi['val'], 1, self.working_columns) + # }}} + + def csi_cursor_to_column(self, csi): # {{{ + self.c = self.bound(csi['val'], 1, self.working_columns) + # }}} + + def csi_cursor_up(self, csi): # {{{ + self.l = self.bound(self.l - csi['val'], self.top, self.bottom) + + self.color_changes = {} + # }}} + + def csi_cursor_down(self, csi): # {{{ + self.l = self.bound(self.l + csi['val'], self.top, self.bottom) + + self.color_changes = {} + # }}} + + def csi_clear_screen(self, csi): # {{{ + # default to 0 + if len(csi['vals']) == 0: + csi['val'] = 0 + + # 2 == clear entire screen + if csi['val'] == 2: + self.l = 1 + self.c = 1 + self.screen.clear() + + # 0 == clear down + elif csi['val'] == 0: + for l in range(self.bound(self.l + 1, 1, self.lines), self.lines + 1): + self.screen[l] = '' + + # clear end of current line + self.csi_clear_line(self.parse_csi('K')) + + # 1 == clear up + elif csi['val'] == 1: + for l in range(1, self.bound(self.l, 1, self.lines + 1)): + self.screen[l] = '' + + # clear beginning of current line + self.csi_clear_line(self.parse_csi('1K')) + + # clear coloration + if csi['val'] == 2 or csi['val'] == 0: + real_line = self.screen.get_real_line(self.l) + for line in self.color_history.keys(): + if line >= real_line: + for syn in self.color_history[line]: + vim.command('syn clear ' + syn['name']) + + self.color_changes = {} + # }}} + + def csi_delete_chars(self, csi): # {{{ + self.screen[self.l] = self.screen[self.l][ : self.c ] + self.screen[self.l][ self.c + csi['val'] : ] + # }}} + + def csi_add_spaces(self, csi): # {{{ + self.screen[self.l] = self.screen[self.l][ : self.c - 1] + ' ' * csi['val'] + self.screen[self.l][self.c : ] + # }}} + + def csi_cursor(self, csi): # {{{ + if len(csi['vals']) == 2: + new_line = csi['vals'][0] + new_col = csi['vals'][1] + else: + new_line = 1 + new_col = 1 + + if self.absolute_coords: + self.l = self.bound(new_line, 1, self.lines) + else: + self.l = self.bound(self.top + new_line - 1, self.top, self.bottom) + + self.c = self.bound(new_col, 1, self.working_columns) + if self.c > len(self.screen[self.l]): + self.screen[self.l] = self.screen[self.l] + ' ' * (self.c - len(self.screen[self.l])) + + # }}} + + def csi_set_coords(self, csi): # {{{ + if len(csi['vals']) == 2: + new_start = csi['vals'][0] + new_end = csi['vals'][1] + else: + new_start = 1 + new_end = vim.current.window.height + + self.top = new_start + self.bottom = new_end + self.working_lines = new_end - new_start + 1 + + # if cursor is outside scrolling region, reset it + if self.l < self.top: + self.l = self.top + elif self.l > self.bottom: + self.l = self.bottom + + self.color_changes = {} + # }}} + + def csi_tab_clear(self, csi): # {{{ + # this escape defaults to 0 + if len(csi['vals']) == 0: + csi['val'] = 0 + + + + if csi['val'] == 0: + self.tabstops[self.c - 1] = False + elif csi['val'] == 3: + for i in range(0, self.columns + 1): + self.tabstops[i] = False + # }}} + + def csi_set(self, csi): # {{{ + # 132 cols + if csi['val'] == 3: + self.csi_clear_screen(self.parse_csi('2J')) + self.working_columns = 132 + + # relative_origin + elif csi['val'] == 6: + self.absolute_coords = False + + # set auto wrap + elif csi['val'] == 7: + self.autowrap = True + + + self.color_changes = {} + # }}} + + def csi_reset(self, csi): # {{{ + # 80 cols + if csi['val'] == 3: + self.csi_clear_screen(self.parse_csi('2J')) + self.working_columns = 80 + + # absolute origin + elif csi['val'] == 6: + self.absolute_coords = True + + # reset auto wrap + elif csi['val'] == 7: + self.autowrap = False + + + self.color_changes = {} + # }}} + + # }}} + + ############################################################################################### + # ESC functions {{{ + + def esc_scroll_up(self): # {{{ + self.ctl_nl() + + self.color_changes = {} + # }}} + + def esc_next_line(self): # {{{ + self.ctl_nl() + self.c = 1 + # }}} + + def esc_set_tab(self): # {{{ + + if self.c <= len(self.tabstops): + self.tabstops[self.c - 1] = True + # }}} + + def esc_scroll_down(self): # {{{ + if self.l == self.top: + del self.screen[self.bottom] + self.screen.insert(self.top, '') + else: + self.l += -1 + + self.color_changes = {} + # }}} + + # }}} + + ############################################################################################### + # HASH functions {{{ + + def hash_screen_alignment_test(self): # {{{ + self.csi_clear_screen(self.parse_csi('2J')) + self.working_lines = self.lines + for l in range(1, self.lines + 1): + self.screen[l] = 'E' * self.working_columns + # }}} + + # }}} + + ############################################################################################### + # Random stuff {{{ + + def change_title(self, key, val): + + + if key == '0' or key == '2': + + vim.command('setlocal statusline=' + re.escape(val)) + + def paste(self): + self.write(vim.eval('@@')) + self.read(50) + + def paste_selection(self): + self.write(vim.eval('@@')) + + def update_window_size(self): + # resize if needed + if vim.current.window.width != self.columns or vim.current.window.height != self.lines: + + # reset all window size attributes to default + self.columns = vim.current.window.width + self.lines = vim.current.window.height + self.working_columns = vim.current.window.width + self.working_lines = vim.current.window.height + self.bottom = vim.current.window.height + + # reset screen object attributes + self.l = self.screen.reset_size(self.l) + + # reset tabstops + self.init_tabstops() + + + + # signal process that screen size has changed + self.proc.window_resize(self.lines, self.columns) + + def init_tabstops(self): + for i in range(0, self.columns + 1): + if i % 8 == 0: + self.tabstops.append(True) + else: + self.tabstops.append(False) + + # }}} + + ############################################################################################### + # Utility {{{ + + def parse_csi(self, s): # {{{ + attr = { 'key' : s[-1], 'flag' : '', 'val' : 1, 'vals' : [] } + + if len(s) == 1: + return attr + + full = s[0:-1] + + if full[0] == '?': + full = full[1:] + attr['flag'] = '?' + + if full != '': + vals = full.split(';') + for val in vals: + + val = re.sub("\D", "", val) + + if val != '': + attr['vals'].append(int(val)) + + if len(attr['vals']) == 1: + attr['val'] = int(attr['vals'][0]) + + return attr + # }}} + + def bound(self, val, min, max): # {{{ + if val > max: + return max + + if val < min: + return min + + return val + # }}} + + def xterm_to_rgb(self, color_code): # {{{ + if color_code < 16: + ascii_colors = ['000000', 'CD0000', '00CD00', 'CDCD00', '0000EE', 'CD00CD', '00CDCD', 'E5E5E5', + '7F7F7F', 'FF0000', '00FF00', 'FFFF00', '5C5CFF', 'FF00FF', '00FFFF', 'FFFFFF'] + return ascii_colors[color_code] + + elif color_code < 232: + cc = int(color_code) - 16 + + p1 = "%02x" % (math.floor(cc / 36) * (255/5)) + p2 = "%02x" % (math.floor((cc % 36) / 6) * (255/5)) + p3 = "%02x" % (math.floor(cc % 6) * (255/5)) + + return p1 + p2 + p3 + else: + grey_tone = "%02x" % math.floor((255/24) * (color_code - 232)) + return grey_tone + grey_tone + grey_tone + # }}} + + # }}} + + +import os, signal, pty, tty, select, fcntl, termios, struct + +################################################################################################### +class ConqueSubprocess: + + # process id + pid = 0 + + # stdout+stderr file descriptor + fd = None + + # constructor + def __init__(self): # {{{ + self.pid = 0 + # }}} + + # create the pty or whatever (whatever == windows) + def open(self, command, env = {}): # {{{ + command_arr = command.split() + executable = command_arr[0] + args = command_arr + + try: + self.pid, self.fd = pty.fork() + + except: + pass + + + # child proc, replace with command after altering terminal attributes + if self.pid == 0: + + # set requested environment variables + for k in env.keys(): + os.environ[k] = env[k] + + # set some attributes + try: + attrs = tty.tcgetattr(1) + attrs[0] = attrs[0] ^ tty.IGNBRK + attrs[0] = attrs[0] | tty.BRKINT | tty.IXANY | tty.IMAXBEL + attrs[2] = attrs[2] | tty.HUPCL + attrs[3] = attrs[3] | tty.ICANON | tty.ECHO | tty.ISIG | tty.ECHOKE + attrs[6][tty.VMIN] = 1 + attrs[6][tty.VTIME] = 0 + tty.tcsetattr(1, tty.TCSANOW, attrs) + except: + pass + + os.execvp(executable, args) + + # else master, do nothing + else: + pass + + # }}} + + # read from pty + # XXX - select.poll() doesn't work in OS X!!!!!!! + def read(self, timeout = 1): # {{{ + + output = '' + read_timeout = float(timeout) / 1000 + + try: + # what, no do/while? + while 1: + s_read, s_write, s_error = select.select( [ self.fd ], [], [], read_timeout) + + lines = '' + for s_fd in s_read: + try: + lines = os.read( self.fd, 32 ) + except: + pass + output = output + lines + + if lines == '': + break + except: + pass + + return output + # }}} + + # I guess this one's not bad + def write(self, input): # {{{ + try: + os.write(self.fd, input) + except: + pass + # }}} + + # signal process + def signal(self, signum): # {{{ + try: + os.kill(self.pid, signum) + except: + pass + # }}} + + # get process status + def get_status(self): #{{{ + + p_status = True + + try: + if os.waitpid( self.pid, os.WNOHANG )[0]: + p_status = False + except: + p_status = False + + return p_status + + # }}} + + # update window size in kernel, then send SIGWINCH to fg process + def window_resize(self, lines, columns): # {{{ + try: + fcntl.ioctl(self.fd, termios.TIOCSWINSZ, struct.pack("HHHH", lines, columns, 0, 0)) + os.kill(self.pid, signal.SIGWINCH) + except: + pass + + # }}} + + +################################################################################################### +# ConqueScreen is an extention of the vim.current.buffer object +# It restricts the working indices of the buffer object to the scroll region which pty is expecting +# It also uses 1-based indexes, to match escape sequence commands +# +# E.g.: +# s = ConqueScreen() +# ... +# s[5] = 'Set 5th line in terminal to this line' +# s.append('Add new line to terminal') +# s[5] = 'Since previous append() command scrolled the terminal down, this is a different line than first cb[5] call' +# + +import vim + +class ConqueScreen(object): + + # CLASS PROPERTIES {{{ + + # the buffer + buffer = None + + # screen and scrolling regions + screen_top = 1 + + # screen width + screen_width = 80 + screen_height = 80 + + # }}} + + def __init__(self): # {{{ + self.buffer = vim.current.buffer + + self.screen_top = 1 + self.screen_width = vim.current.window.width + self.screen_height = vim.current.window.height + # }}} + + ############################################################################################### + # List overload {{{ + def __len__(self): # {{{ + return len(self.buffer) + # }}} + + def __getitem__(self, key): # {{{ + real_line = self.get_real_idx(key) + + # if line is past buffer end, add lines to buffer + if real_line >= len(self.buffer): + for i in range(len(self.buffer), real_line + 1): + self.append(' ' * self.screen_width) + + return self.buffer[ real_line ] + # }}} + + def __setitem__(self, key, value): # {{{ + real_line = self.get_real_idx(key) + + # if line is past end of screen, append + if real_line == len(self.buffer): + self.buffer.append(value) + else: + self.buffer[ real_line ] = value + # }}} + + def __delitem__(self, key): # {{{ + del self.buffer[ self.screen_top + key - 2 ] + # }}} + + def append(self, value): # {{{ + if len(self.buffer) > self.screen_top + self.screen_height - 1: + self.buffer[len(self.buffer) - 1] = value + else: + self.buffer.append(value) + + if len(self.buffer) > self.screen_top + self.screen_height - 1: + self.screen_top += 1 + if vim.current.buffer.number == self.buffer.number: + vim.command('normal G') + # }}} + + def insert(self, line, value): # {{{ + + l = self.screen_top + line - 2 + self.buffer[l:l] = [ value ] + + # }}} + # }}} + + ############################################################################################### + # Util {{{ + def get_top(self): # {{{ + return self.screen_top + # }}} + + def get_real_idx(self, line): # {{{ + return (self.screen_top + line - 2) + # }}} + + def get_real_line(self, line): # {{{ + return (self.screen_top + line - 1) + # }}} + + def set_screen_width(self, width): # {{{ + self.screen_width = width + # }}} + + # }}} + + ############################################################################################### + def clear(self): # {{{ + self.buffer.append(' ') + vim.command('normal Gzt') + self.screen_top = len(self.buffer) + # }}} + + def set_cursor(self, line, column): # {{{ + # figure out line + real_line = self.screen_top + line - 1 + if real_line > len(self.buffer): + for l in range(len(self.buffer) - 1, real_line): + self.buffer.append('') + + # figure out column + real_column = column + if len(self.buffer[real_line - 1]) < real_column: + self.buffer[real_line - 1] = self.buffer[real_line - 1] + ' ' * (real_column - len(self.buffer[real_line - 1])) + + # python version is occasionally grumpy + try: + vim.current.window.cursor = (real_line, real_column - 1) + except: + vim.command('call cursor(' + str(real_line) + ', ' + str(real_column) + ')') + # }}} + + def reset_size(self, line): # {{{ + + + + + # save cursor line number + real_line = self.screen_top + line + + # reset screen size + self.screen_width = vim.current.window.width + self.screen_height = vim.current.window.height + self.screen_top = len(self.buffer) - vim.current.window.height + 1 + if self.screen_top < 1: + self.screen_top = 1 + + + # align bottom of buffer to bottom of screen + vim.command('normal ' + str(self.screen_height) + 'kG') + + # return new relative line number + return (real_line - self.screen_top) + # }}} + + def scroll_to_bottom(self): # {{{ + vim.current.window.cursor = (len(self.buffer) - 1, 1) + # }}} + + def align(self): # {{{ + # align bottom of buffer to bottom of screen + vim.command('normal ' + str(self.screen_height) + 'kG') + # }}} + + +EOF + +endif + diff --git a/vim/autoload/delimitMate.vim b/vim/autoload/delimitMate.vim new file mode 100644 index 0000000..bd10975 --- /dev/null +++ b/vim/autoload/delimitMate.vim @@ -0,0 +1,586 @@ +" File: autoload/delimitMate.vim +" Version: 2.6 +" Modified: 2011-01-14 +" Description: This plugin provides auto-completion for quotes, parens, etc. +" Maintainer: Israel Chauca F. +" Manual: Read ":help delimitMate". +" ============================================================================ + +" Utilities {{{ + +let delimitMate_loaded = 1 + +function! delimitMate#ShouldJump() "{{{ + " Returns 1 if the next character is a closing delimiter. + let col = col('.') + let lcol = col('$') + let char = getline('.')[col - 1] + + " Closing delimiter on the right. + for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list + if char == cdel + return 1 + endif + endfor + + " Closing delimiter with space expansion. + let nchar = getline('.')[col] + if b:_l_delimitMate_expand_space && char == " " + for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list + if nchar == cdel + return 1 + endif + endfor + endif + + " Closing delimiter with CR expansion. + let uchar = getline(line('.') + 1)[0] + if b:_l_delimitMate_expand_cr && char == "" + for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list + if uchar == cdel + return 1 + endif + endfor + endif + + return 0 +endfunction "}}} + +function! delimitMate#IsEmptyPair(str) "{{{ + for pair in b:_l_delimitMate_matchpairs_list + if a:str == join( split( pair, ':' ),'' ) + return 1 + endif + endfor + for quote in b:_l_delimitMate_quotes_list + if a:str == quote . quote + return 1 + endif + endfor + return 0 +endfunction "}}} + +function! delimitMate#IsCRExpansion() " {{{ + let nchar = getline(line('.')-1)[-1:] + let schar = getline(line('.')+1)[:0] + let isEmpty = getline('.') == "" + if index(b:_l_delimitMate_left_delims, nchar) > -1 && + \ index(b:_l_delimitMate_left_delims, nchar) == index(b:_l_delimitMate_right_delims, schar) && + \ isEmpty + return 1 + elseif index(b:_l_delimitMate_quotes_list, nchar) > -1 && + \ index(b:_l_delimitMate_quotes_list, nchar) == index(b:_l_delimitMate_quotes_list, schar) && + \ isEmpty + return 1 + else + return 0 + endif +endfunction " }}} delimitMate#IsCRExpansion() + +function! delimitMate#IsSpaceExpansion() " {{{ + let line = getline('.') + let col = col('.')-2 + if col > 0 + let pchar = line[col - 1] + let nchar = line[col + 2] + let isSpaces = (line[col] == line[col+1] && line[col] == " ") + + if index(b:_l_delimitMate_left_delims, pchar) > -1 && + \ index(b:_l_delimitMate_left_delims, pchar) == index(b:_l_delimitMate_right_delims, nchar) && + \ isSpaces + return 1 + elseif index(b:_l_delimitMate_quotes_list, pchar) > -1 && + \ index(b:_l_delimitMate_quotes_list, pchar) == index(b:_l_delimitMate_quotes_list, nchar) && + \ isSpaces + return 1 + endif + endif + return 0 +endfunction " }}} IsSpaceExpansion() + +function! delimitMate#WithinEmptyPair() "{{{ + let cur = strpart( getline('.'), col('.')-2, 2 ) + return delimitMate#IsEmptyPair( cur ) +endfunction "}}} + +function! delimitMate#WriteBefore(str) "{{{ + let len = len(a:str) + let line = getline('.') + let col = col('.')-2 + if col < 0 + call setline('.',line[(col+len+1):]) + else + call setline('.',line[:(col)].line[(col+len+1):]) + endif + return a:str +endfunction " }}} + +function! delimitMate#WriteAfter(str) "{{{ + let len = len(a:str) + let line = getline('.') + let col = col('.')-2 + if (col) < 0 + call setline('.',a:str.line) + else + call setline('.',line[:(col)].a:str.line[(col+len):]) + endif + return '' +endfunction " }}} + +function! delimitMate#GetSyntaxRegion(line, col) "{{{ + return synIDattr(synIDtrans(synID(a:line, a:col, 1)), 'name') +endfunction " }}} + +function! delimitMate#GetCurrentSyntaxRegion() "{{{ + let col = col('.') + if col == col('$') + let col = col - 1 + endif + return delimitMate#GetSyntaxRegion(line('.'), col) +endfunction " }}} + +function! delimitMate#GetCurrentSyntaxRegionIf(char) "{{{ + let col = col('.') + let origin_line = getline('.') + let changed_line = strpart(origin_line, 0, col - 1) . a:char . strpart(origin_line, col - 1) + call setline('.', changed_line) + let region = delimitMate#GetSyntaxRegion(line('.'), col) + call setline('.', origin_line) + return region +endfunction "}}} + +function! delimitMate#IsForbidden(char) "{{{ + if b:_l_delimitMate_excluded_regions_enabled == 0 + return 0 + endif + "let result = index(b:_l_delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0 + if index(b:_l_delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0 + "echom "Forbidden 1!" + return 1 + endif + let region = delimitMate#GetCurrentSyntaxRegionIf(a:char) + "let result = index(b:_l_delimitMate_excluded_regions_list, region) >= 0 + "return result || region == 'Comment' + "echom "Forbidden 2!" + return index(b:_l_delimitMate_excluded_regions_list, region) >= 0 +endfunction "}}} + +function! delimitMate#FlushBuffer() " {{{ + let b:_l_delimitMate_buffer = [] + return '' +endfunction " }}} + +function! delimitMate#BalancedParens(char) "{{{ + " Returns: + " = 0 => Parens balanced. + " > 0 => More opening parens. + " < 0 => More closing parens. + + let line = getline('.') + let col = col('.') - 2 + let col = col >= 0 ? col : 0 + let list = split(line, '\zs') + let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims, a:char)] + let right = a:char + let opening = 0 + let closing = 0 + + " If the cursor is not at the beginning, count what's behind it. + if col > 0 + " Find the first opening paren: + let start = index(list, left) + " Must be before cursor: + let start = start < col ? start : col - 1 + " Now count from the first opening until the cursor, this will prevent + " extra closing parens from being counted. + let opening = count(list[start : col - 1], left) + let closing = count(list[start : col - 1], right) + " I don't care if there are more closing parens than opening parens. + let closing = closing > opening ? opening : closing + endif + + " Evaluate parens from the cursor to the end: + let opening += count(list[col :], left) + let closing += count(list[col :], right) + + "echom "–––––––––" + "echom line + "echom col + ""echom left.":".a:char + "echom string(list) + "echom string(list[start : col - 1]) . " : " . string(list[col :]) + "echom opening . " - " . closing . " = " . (opening - closing) + + " Return the found balance: + return opening - closing +endfunction "}}} + +function! delimitMate#RmBuffer(num) " {{{ + if len(b:_l_delimitMate_buffer) > 0 + call remove(b:_l_delimitMate_buffer, 0, (a:num-1)) + endif + return "" +endfunction " }}} + +" }}} + +" Doers {{{ +function! delimitMate#SkipDelim(char) "{{{ + if delimitMate#IsForbidden(a:char) + return a:char + endif + let col = col('.') - 1 + let line = getline('.') + if col > 0 + let cur = line[col] + let pre = line[col-1] + else + let cur = line[col] + let pre = "" + endif + if pre == "\\" + " Escaped character + return a:char + elseif cur == a:char + " Exit pair + "return delimitMate#WriteBefore(a:char) + return a:char . delimitMate#Del() + elseif delimitMate#IsEmptyPair( pre . a:char ) + " Add closing delimiter and jump back to the middle. + call insert(b:_l_delimitMate_buffer, a:char) + return delimitMate#WriteAfter(a:char) + else + " Nothing special here, return the same character. + return a:char + endif +endfunction "}}} + +function! delimitMate#ParenDelim(char) " {{{ + if delimitMate#IsForbidden(a:char) + return '' + endif + " Try to balance matchpairs + if b:_l_delimitMate_balance_matchpairs && + \ delimitMate#BalancedParens(a:char) <= 0 + return '' + endif + let line = getline('.') + let col = col('.')-2 + let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims,a:char)] + let smart_matchpairs = substitute(b:_l_delimitMate_smart_matchpairs, '\\!', left, 'g') + let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:char, 'g') + "echom left.':'.smart_matchpairs . ':' . matchstr(line[col+1], smart_matchpairs) + if b:_l_delimitMate_smart_matchpairs != '' && + \ line[col+1:] =~ smart_matchpairs + return '' + elseif (col) < 0 + call setline('.',a:char.line) + call insert(b:_l_delimitMate_buffer, a:char) + else + "echom string(col).':'.line[:(col)].'|'.line[(col+1):] + call setline('.',line[:(col)].a:char.line[(col+1):]) + call insert(b:_l_delimitMate_buffer, a:char) + endif + return '' +endfunction " }}} + +function! delimitMate#QuoteDelim(char) "{{{ + if delimitMate#IsForbidden(a:char) + return a:char + endif + let line = getline('.') + let col = col('.') - 2 + if line[col] == "\\" + " Seems like a escaped character, insert one quotation mark. + return a:char + elseif line[col + 1] == a:char && + \ index(b:_l_delimitMate_nesting_quotes, a:char) < 0 + " Get out of the string. + return a:char . delimitMate#Del() + elseif (line[col] =~ '\w' && a:char == "'") || + \ (b:_l_delimitMate_smart_quotes && + \ (line[col] =~ '\w' || + \ line[col + 1] =~ '\w')) + " Seems like an apostrophe or a smart quote case, insert a single quote. + return a:char + elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:_l_delimitMate_smart_quotes + " Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle. + call insert(b:_l_delimitMate_buffer, a:char) + return delimitMate#WriteAfter(a:char) + else + " Insert a pair and jump to the middle. + call insert(b:_l_delimitMate_buffer, a:char) + call delimitMate#WriteAfter(a:char) + return a:char + endif +endfunction "}}} + +function! delimitMate#JumpOut(char) "{{{ + if delimitMate#IsForbidden(a:char) + return a:char + endif + let line = getline('.') + let col = col('.')-2 + if line[col+1] == a:char + return a:char . delimitMate#Del() + else + return a:char + endif +endfunction " }}} + +function! delimitMate#JumpAny(key) " {{{ + if delimitMate#IsForbidden('') + return a:key + endif + if !delimitMate#ShouldJump() + return a:key + endif + " Let's get the character on the right. + let char = getline('.')[col('.')-1] + if char == " " + " Space expansion. + "let char = char . getline('.')[col('.')] . delimitMate#Del() + return char . getline('.')[col('.')] . delimitMate#Del() . delimitMate#Del() + "call delimitMate#RmBuffer(1) + elseif char == "" + " CR expansion. + "let char = "\" . getline(line('.') + 1)[0] . "\" + let b:_l_delimitMate_buffer = [] + return "\" . getline(line('.') + 1)[0] . "\" + else + "call delimitMate#RmBuffer(1) + return char . delimitMate#Del() + endif +endfunction " delimitMate#JumpAny() }}} + +function! delimitMate#JumpMany() " {{{ + let line = getline('.')[col('.') - 1 : ] + let len = len(line) + let rights = "" + let found = 0 + let i = 0 + while i < len + let char = line[i] + if index(b:_l_delimitMate_quotes_list, char) >= 0 || + \ index(b:_l_delimitMate_right_delims, char) >= 0 + let rights .= "\" + let found = 1 + elseif found == 0 + let rights .= "\" + else + break + endif + let i += 1 + endwhile + if found == 1 + return rights + else + return '' + endif +endfunction " delimitMate#JumpMany() }}} + +function! delimitMate#ExpandReturn() "{{{ + if delimitMate#IsForbidden("") + return "\" + endif + if delimitMate#WithinEmptyPair() + " Expand: + call delimitMate#FlushBuffer() + "return "\a\x\\k$\"_xa" + return "\\\o" + else + return "\" + endif +endfunction "}}} + +function! delimitMate#ExpandSpace() "{{{ + if delimitMate#IsForbidden("\") + return "\" + endif + if delimitMate#WithinEmptyPair() + " Expand: + call insert(b:_l_delimitMate_buffer, 's') + return delimitMate#WriteAfter(' ') . "\" + else + return "\" + endif +endfunction "}}} + +function! delimitMate#BS() " {{{ + if delimitMate#IsForbidden("") + return "\" + endif + if delimitMate#WithinEmptyPair() + "call delimitMate#RmBuffer(1) + return "\" . delimitMate#Del() +" return "\\\" + elseif delimitMate#IsSpaceExpansion() + "call delimitMate#RmBuffer(1) + return "\" . delimitMate#Del() + elseif delimitMate#IsCRExpansion() + return "\\" + else + return "\" + endif +endfunction " }}} delimitMate#BS() + +function! delimitMate#Del() " {{{ + if len(b:_l_delimitMate_buffer) > 0 + let line = getline('.') + let col = col('.') - 2 + call delimitMate#RmBuffer(1) + call setline('.', line[:col] . line[col+2:]) + return '' + else + return "\" + endif +endfunction " }}} + +function! delimitMate#Finish(move_back) " {{{ + let len = len(b:_l_delimitMate_buffer) + if len > 0 + let buffer = join(b:_l_delimitMate_buffer, '') + let len2 = len(buffer) + " Reset buffer: + let b:_l_delimitMate_buffer = [] + let line = getline('.') + let col = col('.') -2 + "echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer + if col < 0 + call setline('.', line[col+len2+1:]) + else + call setline('.', line[:col] . line[col+len2+1:]) + endif + let i = 1 + let lefts = "" + while i <= len && a:move_back + let lefts = lefts . "\" + let i += 1 + endwhile + return substitute(buffer, "s", "\", 'g') . lefts + endif + return '' +endfunction " }}} + +" }}} + +" Tools: {{{ +function! delimitMate#TestMappings() "{{{ + let options = sort(keys(delimitMate#OptionsList())) + let optoutput = ['delimitMate Report', '==================', '', '* Options: ( ) default, (g) global, (b) buffer',''] + for option in options + exec 'call add(optoutput, ''('.(exists('b:delimitMate_'.option) ? 'b' : exists('g:delimitMate_'.option) ? 'g' : ' ').') delimitMate_''.option.'' = ''.string(b:_l_delimitMate_'.option.'))' + endfor + call append(line('$'), optoutput + ['--------------------','']) + + " Check if mappings were set. {{{ + let imaps = b:_l_delimitMate_right_delims + let imaps = imaps + ( b:_l_delimitMate_autoclose ? b:_l_delimitMate_left_delims : [] ) + let imaps = imaps + + \ b:_l_delimitMate_quotes_list + + \ b:_l_delimitMate_apostrophes_list + + \ ['', '', '', '', ''] + + \ ['', '', '', '', '', ''] + + \ ['', '', '', '', '', '', 'g'] + let imaps = imaps + ( b:_l_delimitMate_expand_cr ? [''] : [] ) + let imaps = imaps + ( b:_l_delimitMate_expand_space ? [''] : [] ) + + let vmaps = + \ b:_l_delimitMate_right_delims + + \ b:_l_delimitMate_left_delims + + \ b:_l_delimitMate_quotes_list + + let ibroken = [] + for map in imaps + if maparg(map, "i") !~? 'delimitMate' + let output = '' + if map == '|' + let map = '' + endif + redir => output | execute "verbose imap ".map | redir END + let ibroken = ibroken + [map.": is not set:"] + split(output, '\n') + endif + endfor + + unlet! output + if ibroken == [] + let output = ['* Mappings:', '', 'All mappings were set-up.', '--------------------', '', ''] + else + let output = ['* Mappings:', ''] + ibroken + ['--------------------', ''] + endif + call append('$', output+['* Showcase:', '']) + " }}} + if b:_l_delimitMate_autoclose + " {{{ + for i in range(len(b:_l_delimitMate_left_delims)) + exec "normal Go0\Open: " . b:_l_delimitMate_left_delims[i]. "|" + exec "normal o0\Delete: " . b:_l_delimitMate_left_delims[i] . "\|" + exec "normal o0\Exit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|" + if b:_l_delimitMate_expand_space == 1 + exec "normal o0\Space: " . b:_l_delimitMate_left_delims[i] . " |" + exec "normal o0\Delete space: " . b:_l_delimitMate_left_delims[i] . " \|" + endif + if b:_l_delimitMate_expand_cr == 1 + exec "normal o0\Car return: " . b:_l_delimitMate_left_delims[i] . "\|" + exec "normal Go0\Delete car return: " . b:_l_delimitMate_left_delims[i] . "\0\\|" + endif + call append(line('$'), '') + endfor + for i in range(len(b:_l_delimitMate_quotes_list)) + exec "normal Go0\Open: " . b:_l_delimitMate_quotes_list[i] . "|" + exec "normal o0\Delete: " . b:_l_delimitMate_quotes_list[i] . "\|" + exec "normal o0\Exit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|" + if b:_l_delimitMate_expand_space == 1 + exec "normal o0\Space: " . b:_l_delimitMate_quotes_list[i] . " |" + exec "normal o0\Delete space: " . b:_l_delimitMate_quotes_list[i] . " \|" + endif + if b:_l_delimitMate_expand_cr == 1 + exec "normal o0\Car return: " . b:_l_delimitMate_quotes_list[i] . "\|" + exec "normal Go0\Delete car return: " . b:_l_delimitMate_quotes_list[i] . "\\|" + endif + call append(line('$'), '') + endfor + "}}} + else + "{{{ + for i in range(len(b:_l_delimitMate_left_delims)) + exec "normal GoOpen & close: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|" + exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\|" + exec "normal oExit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . b:_l_delimitMate_right_delims[i] . "|" + if b:_l_delimitMate_expand_space == 1 + exec "normal oSpace: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " |" + exec "normal oDelete space: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " \|" + endif + if b:_l_delimitMate_expand_cr == 1 + exec "normal oCar return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\|" + exec "normal GoDelete car return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\\|" + endif + call append(line('$'), '') + endfor + for i in range(len(b:_l_delimitMate_quotes_list)) + exec "normal GoOpen & close: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|" + exec "normal oDelete: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\|" + exec "normal oExit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|" + if b:_l_delimitMate_expand_space == 1 + exec "normal oSpace: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " |" + exec "normal oDelete space: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " \|" + endif + if b:_l_delimitMate_expand_cr == 1 + exec "normal oCar return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\|" + exec "normal GoDelete car return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\\|" + endif + call append(line('$'), '') + endfor + endif "}}} + redir => setoptions | set | filetype | redir END + call append(line('$'), split(setoptions,"\n") + \ + ['--------------------']) + setlocal nowrap +endfunction "}}} + +function! delimitMate#OptionsList() "{{{ + return {'autoclose' : 1,'matchpairs': &matchpairs, 'quotes' : '" '' `', 'nesting_quotes' : [], 'expand_cr' : 0, 'expand_space' : 0, 'smart_quotes' : 1, 'smart_matchpairs' : '\w', 'balance_matchpairs' : 0, 'excluded_regions' : 'Comment', 'excluded_ft' : '', 'apostrophes' : ''} +endfunction " delimitMate#OptionsList }}} +"}}} + +" vim:foldmethod=marker:foldcolumn=4 diff --git a/vim/autoload/pathogen.vim b/vim/autoload/pathogen.vim new file mode 100644 index 0000000..4071992 --- /dev/null +++ b/vim/autoload/pathogen.vim @@ -0,0 +1,250 @@ +" pathogen.vim - path option manipulation +" Maintainer: Tim Pope +" Version: 2.0 + +" Install in ~/.vim/autoload (or ~\vimfiles\autoload). +" +" For management of individually installed plugins in ~/.vim/bundle (or +" ~\vimfiles\bundle), adding `call pathogen#infect()` to your .vimrc +" prior to `filetype plugin indent on` is the only other setup necessary. +" +" The API is documented inline below. For maximum ease of reading, +" :set foldmethod=marker + +if exists("g:loaded_pathogen") || &cp + finish +endif +let g:loaded_pathogen = 1 + +" Point of entry for basic default usage. Give a directory name to invoke +" pathogen#runtime_append_all_bundles() (defaults to "bundle"), or a full path +" to invoke pathogen#runtime_prepend_subdirectories(). Afterwards, +" pathogen#cycle_filetype() is invoked. +function! pathogen#infect(...) abort " {{{1 + let source_path = a:0 ? a:1 : 'bundle' + if source_path =~# '[\\/]' + call pathogen#runtime_prepend_subdirectories(source_path) + else + call pathogen#runtime_append_all_bundles(source_path) + endif + call pathogen#cycle_filetype() +endfunction " }}}1 + +" Split a path into a list. +function! pathogen#split(path) abort " {{{1 + if type(a:path) == type([]) | return a:path | endif + let split = split(a:path,'\\\@"),'!isdirectory(v:val)')) && (!filereadable(dir.sep.'doc'.sep.'tags') || filewritable(dir.sep.'doc'.sep.'tags')) + helptags `=dir.'/doc'` + endif + endfor +endfunction " }}}1 + +command! -bar Helptags :call pathogen#helptags() + +" Like findfile(), but hardcoded to use the runtimepath. +function! pathogen#runtime_findfile(file,count) "{{{1 + let rtp = pathogen#join(1,pathogen#split(&rtp)) + let file = findfile(a:file,rtp,a:count) + if file ==# '' + return '' + else + return fnamemodify(file,':p') + endif +endfunction " }}}1 + +" Backport of fnameescape(). +function! pathogen#fnameescape(string) " {{{1 + if exists('*fnameescape') + return fnameescape(a:string) + elseif a:string ==# '-' + return '\-' + else + return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','') + endif +endfunction " }}}1 + +function! s:find(count,cmd,file,lcd) " {{{1 + let rtp = pathogen#join(1,pathogen#split(&runtimepath)) + let file = pathogen#runtime_findfile(a:file,a:count) + if file ==# '' + return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'" + elseif a:lcd + let path = file[0:-strlen(a:file)-2] + execute 'lcd `=path`' + return a:cmd.' '.pathogen#fnameescape(a:file) + else + return a:cmd.' '.pathogen#fnameescape(file) + endif +endfunction " }}}1 + +function! s:Findcomplete(A,L,P) " {{{1 + let sep = pathogen#separator() + let cheats = { + \'a': 'autoload', + \'d': 'doc', + \'f': 'ftplugin', + \'i': 'indent', + \'p': 'plugin', + \'s': 'syntax'} + if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0]) + let request = cheats[a:A[0]].a:A[1:-1] + else + let request = a:A + endif + let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*' + let found = {} + for path in pathogen#split(&runtimepath) + let path = expand(path, ':p') + let matches = split(glob(path.sep.pattern),"\n") + call map(matches,'isdirectory(v:val) ? v:val.sep : v:val') + call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]') + for match in matches + let found[match] = 1 + endfor + endfor + return sort(keys(found)) +endfunction " }}}1 + +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(,'edit',,0) +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(,'edit',,0) +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(,'edit',,1) +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(,'split',,1) +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(,'vsplit',,1) +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(,'tabedit',,1) +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(,'pedit',,1) +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(,'read',,1) + +" vim:set ft=vim ts=8 sw=2 sts=2: diff --git a/vim/autoload/rails.vim b/vim/autoload/rails.vim new file mode 100644 index 0000000..ca36075 --- /dev/null +++ b/vim/autoload/rails.vim @@ -0,0 +1,4560 @@ +" autoload/rails.vim +" Author: Tim Pope + +" Install this file as autoload/rails.vim. + +if exists('g:autoloaded_rails') || &cp + finish +endif +let g:autoloaded_rails = '4.4' + +let s:cpo_save = &cpo +set cpo&vim + +" Utility Functions {{{1 + +let s:app_prototype = {} +let s:file_prototype = {} +let s:buffer_prototype = {} +let s:readable_prototype = {} + +function! s:add_methods(namespace, method_names) + for name in a:method_names + let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name) + endfor +endfunction + +function! s:function(name) + return function(substitute(a:name,'^s:',matchstr(expand(''), '\d\+_'),'')) +endfunction + +function! s:sub(str,pat,rep) + return substitute(a:str,'\v\C'.a:pat,a:rep,'') +endfunction + +function! s:gsub(str,pat,rep) + return substitute(a:str,'\v\C'.a:pat,a:rep,'g') +endfunction + +function! s:startswith(string,prefix) + return strpart(a:string, 0, strlen(a:prefix)) ==# a:prefix +endfunction + +function! s:compact(ary) + return s:sub(s:sub(s:gsub(a:ary,'\n\n+','\n'),'\n$',''),'^\n','') +endfunction + +function! s:uniq(list) + let seen = {} + let i = 0 + while i < len(a:list) + if has_key(seen,a:list[i]) + call remove(a:list, i) + else + let seen[a:list[i]] = 1 + let i += 1 + endif + endwhile + return a:list +endfunction + +function! s:scrub(collection,item) + " Removes item from a newline separated collection + let col = "\n" . a:collection + let idx = stridx(col,"\n".a:item."\n") + let cnt = 0 + while idx != -1 && cnt < 100 + let col = strpart(col,0,idx).strpart(col,idx+strlen(a:item)+1) + let idx = stridx(col,"\n".a:item."\n") + let cnt += 1 + endwhile + return strpart(col,1) +endfunction + +function! s:escarg(p) + return s:gsub(a:p,'[ !%#]','\\&') +endfunction + +function! s:esccmd(p) + return s:gsub(a:p,'[!%#]','\\&') +endfunction + +function! s:rquote(str) + " Imperfect but adequate for Ruby arguments + if a:str =~ '^[A-Za-z0-9_/.:-]\+$' + return a:str + elseif &shell =~? 'cmd' + return '"'.s:gsub(s:gsub(a:str,'\','\\'),'"','\\"').'"' + else + return "'".s:gsub(s:gsub(a:str,'\','\\'),"'","'\\\\''")."'" + endif +endfunction + +function! s:sname() + return fnamemodify(s:file,':t:r') +endfunction + +function! s:pop_command() + if exists("s:command_stack") && len(s:command_stack) > 0 + exe remove(s:command_stack,-1) + endif +endfunction + +function! s:push_chdir(...) + if !exists("s:command_stack") | let s:command_stack = [] | endif + if exists("b:rails_root") && (a:0 ? getcwd() !=# rails#app().path() : !s:startswith(getcwd(), rails#app().path())) + let chdir = exists("*haslocaldir") && haslocaldir() ? "lchdir " : "chdir " + call add(s:command_stack,chdir.s:escarg(getcwd())) + exe chdir.s:escarg(rails#app().path()) + else + call add(s:command_stack,"") + endif +endfunction + +function! s:app_path(...) dict + return join([self.root]+a:000,'/') +endfunction + +function! s:app_has_file(file) dict + return filereadable(self.path(a:file)) +endfunction + +function! s:app_find_file(name, ...) dict abort + let trim = strlen(self.path())+1 + if a:0 + let path = s:pathjoin(map(s:pathsplit(a:1),'self.path(v:val)')) + else + let path = s:pathjoin([self.path()]) + endif + let suffixesadd = s:pathjoin(get(a:000,1,&suffixesadd)) + let default = get(a:000,2,'') + let oldsuffixesadd = &l:suffixesadd + try + let &suffixesadd = suffixesadd + " Versions before 7.1.256 returned directories from findfile + if type(default) == type(0) && (v:version < 702 || default == -1) + let all = findfile(a:name,path,-1) + if v:version < 702 + call filter(all,'!isdirectory(v:val)') + endif + call map(all,'s:gsub(strpart(fnamemodify(v:val,":p"),trim),"\\\\","/")') + return default < 0 ? all : get(all,default-1,'') + elseif type(default) == type(0) + let found = findfile(a:name,path,default) + else + let i = 1 + let found = findfile(a:name,path) + while v:version < 702 && found != "" && isdirectory(found) + let i += 1 + let found = findfile(a:name,path,i) + endwhile + endif + return found == "" ? default : s:gsub(strpart(fnamemodify(found,':p'),trim),'\\','/') + finally + let &l:suffixesadd = oldsuffixesadd + endtry +endfunction + +call s:add_methods('app',['path','has_file','find_file']) + +" Split a path into a list. From pathogen.vim +function! s:pathsplit(path) abort + if type(a:path) == type([]) | return copy(a:path) | endif + let split = split(a:path,'\\\@' + if matchstr(self.getline(a:lnum+1),'^'.spc) && !matchstr(self.getline(a:lnum+1),'^'.spc.endpat) && matchstr(cline,endpat) + return a:lnum + endif + let endl = a:lnum + while endl <= self.line_count() + let endl += 1 + if self.getline(endl) =~ '^'.spc.endpat + return endl + elseif self.getline(endl) =~ '^=begin\>' + while self.getline(endl) !~ '^=end\>' && endl <= self.line_count() + let endl += 1 + endwhile + let endl += 1 + elseif self.getline(endl) !~ '^'.spc && self.getline(endl) !~ '^\s*\%(#.*\)\=$' + return 0 + endif + endwhile + return 0 +endfunction + +function! s:endof(lnum) + return rails#buffer().end_of(a:lnum) +endfunction + +function! s:readable_last_opening_line(start,pattern,limit) dict abort + let line = a:start + while line > a:limit && self.getline(line) !~ a:pattern + let line -= 1 + endwhile + let lend = self.end_of(line) + if line > a:limit && (lend < 0 || lend >= a:start) + return line + else + return -1 + endif +endfunction + +function! s:lastopeningline(pattern,limit,start) + return rails#buffer().last_opening_line(a:start,a:pattern,a:limit) +endfunction + +function! s:readable_define_pattern() dict abort + if self.name() =~ '\.yml$' + return '^\%(\h\k*:\)\@=' + endif + let define = '^\s*def\s\+\(self\.\)\=' + if self.name() =~# '\.rake$' + let define .= "\\\|^\\s*\\%(task\\\|file\\)\\s\\+[:'\"]" + endif + if self.name() =~# '/schema\.rb$' + let define .= "\\\|^\\s*create_table\\s\\+[:'\"]" + endif + if self.type_name('test') + let define .= '\|^\s*test\s*[''"]' + endif + return define +endfunction + +function! s:readable_last_method_line(start) dict abort + return self.last_opening_line(a:start,self.define_pattern(),0) +endfunction + +function! s:lastmethodline(start) + return rails#buffer().last_method_line(a:start) +endfunction + +function! s:readable_last_method(start) dict abort + let lnum = self.last_method_line(a:start) + let line = self.getline(lnum) + if line =~# '^\s*test\s*\([''"]\).*\1' + let string = matchstr(line,'^\s*\w\+\s*\([''"]\)\zs.*\ze\1') + return 'test_'.s:gsub(string,' +','_') + elseif lnum + return s:sub(matchstr(line,'\%('.self.define_pattern().'\)\zs\h\%(\k\|[:.]\)*[?!=]\='),':$','') + else + return "" + endif +endfunction + +function! s:lastmethod(...) + return rails#buffer().last_method(a:0 ? a:1 : line(".")) +endfunction + +function! s:readable_last_format(start) dict abort + if self.type_name('view') + let format = fnamemodify(self.path(),':r:e') + if format == '' + return get({'rhtml': 'html', 'rxml': 'xml', 'rjs': 'js', 'haml': 'html'},fnamemodify(self.path(),':e'),'') + else + return format + endif + endif + let rline = self.last_opening_line(a:start,'\C^\s*\%(mail\>.*\|respond_to\)\s*\%(\.*\|respond_to\)\s*\%(\ rline + let match = matchstr(self.getline(line),'\C^\s*'.variable.'\s*\.\s*\zs\h\k*') + if match != '' + return match + endif + let line -= 1 + endwhile + endif + return "" +endfunction + +function! s:lastformat(start) + return rails#buffer().last_format(a:start) +endfunction + +function! s:format(...) + let format = rails#buffer().last_format(a:0 > 1 ? a:2 : line(".")) + return format ==# '' && a:0 ? a:1 : format +endfunction + +call s:add_methods('readable',['end_of','last_opening_line','last_method_line','last_method','last_format','define_pattern']) + +let s:view_types = split('rhtml,erb,rxml,builder,rjs,mab,liquid,haml,dryml,mn,slim',',') + +function! s:viewspattern() + return '\%('.join(s:view_types,'\|').'\)' +endfunction + +function! s:controller(...) + return rails#buffer().controller_name(a:0 ? a:1 : 0) +endfunction + +function! s:readable_controller_name(...) dict abort + let f = self.name() + if has_key(self,'getvar') && self.getvar('rails_controller') != '' + return self.getvar('rails_controller') + elseif f =~ '\ get(self,last_lines_ftime,0) + let self.last_lines = readfile(self.path()) + let self.last_lines_ftime = ftime + endif + return get(self,'last_lines',[]) +endfunction + +function! s:file_getline(lnum,...) dict abort + if a:0 + return self.lines[lnum-1 : a:1-1] + else + return self.lines[lnum-1] + endif +endfunction + +function! s:buffer_lines() dict abort + return self.getline(1,'$') +endfunction + +function! s:buffer_getline(...) dict abort + if a:0 == 1 + return get(call('getbufline',[self.number()]+a:000),0,'') + else + return call('getbufline',[self.number()]+a:000) + endif +endfunction + +function! s:readable_line_count() dict abort + return len(self.lines()) +endfunction + +function! s:environment() + if exists('$RAILS_ENV') + return $RAILS_ENV + else + return "development" + endif +endfunction + +function! s:Complete_environments(...) + return s:completion_filter(rails#app().environments(),a:0 ? a:1 : "") +endfunction + +function! s:warn(str) + echohl WarningMsg + echomsg a:str + echohl None + " Sometimes required to flush output + echo "" + let v:warningmsg = a:str +endfunction + +function! s:error(str) + echohl ErrorMsg + echomsg a:str + echohl None + let v:errmsg = a:str +endfunction + +function! s:debug(str) + if exists("g:rails_debug") && g:rails_debug + echohl Debug + echomsg a:str + echohl None + endif +endfunction + +function! s:buffer_getvar(varname) dict abort + return getbufvar(self.number(),a:varname) +endfunction + +function! s:buffer_setvar(varname, val) dict abort + return setbufvar(self.number(),a:varname,a:val) +endfunction + +call s:add_methods('buffer',['getvar','setvar']) + +" }}}1 +" "Public" Interface {{{1 + +" RailsRoot() is the only official public function + +function! rails#underscore(str) + let str = s:gsub(a:str,'::','/') + let str = s:gsub(str,'(\u+)(\u\l)','\1_\2') + let str = s:gsub(str,'(\l|\d)(\u)','\1_\2') + let str = tolower(str) + return str +endfunction + +function! rails#camelize(str) + let str = s:gsub(a:str,'/(.=)','::\u\1') + let str = s:gsub(str,'%([_-]|<)(.)','\u\1') + return str +endfunction + +function! rails#singularize(word) + " Probably not worth it to be as comprehensive as Rails but we can + " still hit the common cases. + let word = a:word + if word =~? '\.js$' || word == '' + return word + endif + let word = s:sub(word,'eople$','ersons') + let word = s:sub(word,'%([Mm]ov|[aeio])@ 0 && getbufvar(nr,'rails_file_type') != '' + return getbufvar(nr,'rails_file_type') + elseif f =~ '_controller\.rb$' || f =~ '\' + let r = "controller-api" + else + let r = "controller" + endif + elseif f =~ '_api\.rb' + let r = "api" + elseif f =~ '\') + if class == "ActiveResource::Base" + let class = "ares" + let r = "model-ares" + elseif class == 'ActionMailer::Base' + let r = "mailer" + elseif class != '' + let class = tolower(s:gsub(class,'[^A-Z]','')) + let r = "model-".class + elseif f =~ '_mailer\.rb$' + let r = "mailer" + elseif top =~ '\<\%(validates_\w\+_of\|set_\%(table_name\|primary_key\)\|has_one\|has_many\|belongs_to\)\>' + let r = "model-arb" + else + let r = "model" + endif + elseif f =~ '\.*\.' + let r = "view-layout-" . e + elseif f =~ '\<\%(app/views\|components\)/.*/_\k\+\.\k\+\%(\.\k\+\)\=$' + let r = "view-partial-" . e + elseif f =~ '\.*\.' || f =~ '\' + if e == "yml" + let r = "fixtures-yaml" + else + let r = "fixtures" . (e == "" ? "" : "-" . e) + endif + elseif f =~ '\' + let r = "db-migration" + elseif f=~ '\.*\.rb$' + let r = "config-routes" + elseif f =~ '\' + let cmd = 'script/rails '.a:cmd + else + let cmd = 'script/'.a:cmd + endif + return self.ruby_shell_command(cmd) +endfunction + +function! s:app_background_script_command(cmd) dict abort + let cmd = s:esccmd(self.script_shell_command(a:cmd)) + if has_key(self,'options') && has_key(self.options,'gnu_screen') + let screen = self.options.gnu_screen + else + let screen = g:rails_gnu_screen + endif + if has("gui_win32") + if &shellcmdflag == "-c" && ($PATH . &shell) =~? 'cygwin' + silent exe "!cygstart -d ".s:rquote(self.path())." ruby ".a:cmd + else + exe "!start ".cmd + endif + elseif exists("$STY") && !has("gui_running") && screen && executable("screen") + silent exe "!screen -ln -fn -t ".s:sub(s:sub(a:cmd,'\s.*',''),'^%(script|-rcommand)/','rails-').' '.cmd + elseif exists("$TMUX") && !has("gui_running") && screen && executable("tmux") + silent exe '!tmux new-window -d -n "'.s:sub(s:sub(a:cmd,'\s.*',''),'^%(script|-rcommand)/','rails-').'" "'.cmd.'"' + else + exe "!".cmd + endif + return v:shell_error +endfunction + +function! s:app_execute_script_command(cmd) dict abort + exe '!'.s:esccmd(self.script_shell_command(a:cmd)) + return v:shell_error +endfunction + +function! s:app_lightweight_ruby_eval(ruby,...) dict abort + let def = a:0 ? a:1 : "" + if !executable("ruby") + return def + endif + let args = '-e '.s:rquote('begin; require %{rubygems}; rescue LoadError; end; begin; require %{active_support}; rescue LoadError; end; '.a:ruby) + let cmd = self.ruby_shell_command(args) + " If the shell is messed up, this command could cause an error message + silent! let results = system(cmd) + return v:shell_error == 0 ? results : def +endfunction + +function! s:app_eval(ruby,...) dict abort + let def = a:0 ? a:1 : "" + if !executable("ruby") + return def + endif + let args = "-r./config/boot -r ".s:rquote(self.path("config/environment"))." -e ".s:rquote(a:ruby) + let cmd = self.ruby_shell_command(args) + " If the shell is messed up, this command could cause an error message + silent! let results = system(cmd) + return v:shell_error == 0 ? results : def +endfunction + +call s:add_methods('app', ['ruby_shell_command','script_shell_command','execute_script_command','background_script_command','lightweight_ruby_eval','eval']) + +" }}}1 +" Commands {{{1 + +function! s:prephelp() + let fn = fnamemodify(s:file,':h:h').'/doc/' + if filereadable(fn.'rails.txt') + if !filereadable(fn.'tags') || getftime(fn.'tags') <= getftime(fn.'rails.txt') + silent! helptags `=fn` + endif + endif +endfunction + +function! RailsHelpCommand(...) + call s:prephelp() + let topic = a:0 ? a:1 : "" + if topic == "" || topic == "-" + return "help rails" + elseif topic =~ '^g:' + return "help ".topic + elseif topic =~ '^-' + return "help rails".topic + else + return "help rails-".topic + endif +endfunction + +function! s:BufCommands() + call s:BufFinderCommands() + call s:BufNavCommands() + call s:BufScriptWrappers() + command! -buffer -bar -nargs=? -bang -count -complete=customlist,s:Complete_rake Rake :call s:Rake(0,! && ? -1 : ,) + command! -buffer -bar -nargs=? -bang -range -complete=customlist,s:Complete_preview Rpreview :call s:Preview(0,,) + command! -buffer -bar -nargs=? -bang -complete=customlist,s:Complete_environments Rlog :call s:Log(0,) + command! -buffer -bar -nargs=* -bang -complete=customlist,s:Complete_set Rset :call s:Set(0,) + command! -buffer -bar -nargs=0 Rtags :call rails#app().tags_command() + " Embedding all this logic directly into the command makes the error + " messages more concise. + command! -buffer -bar -nargs=? -bang Rdoc : + \ if 0 || =~ "^\\([:'-]\\|g:\\)" | + \ exe RailsHelpCommand() | + \ else | call s:Doc(0,) | endif + command! -buffer -bar -nargs=0 -bang Rrefresh :if 0|unlet! g:autoloaded_rails|source `=s:file`|endif|call s:Refresh(0) + if exists(":NERDTree") + command! -buffer -bar -nargs=? -complete=customlist,s:Complete_cd Rtree :NERDTree `=rails#app().path()` + endif + if exists("g:loaded_dbext") + command! -buffer -bar -nargs=? -complete=customlist,s:Complete_environments Rdbext :call s:BufDatabase(2,)|let b:dbext_buffer_defaulted = 1 + endif + let ext = expand("%:e") + if ext =~ s:viewspattern() + " TODO: complete controller names with trailing slashes here + command! -buffer -bar -bang -nargs=? -range -complete=customlist,s:controllerList Rextract :,call s:Extract(0,) + endif + if RailsFilePath() =~ '\0) + endif +endfunction + +function! s:Doc(bang, string) + if a:string != "" + if exists("g:rails_search_url") + let query = substitute(a:string,'[^A-Za-z0-9_.~-]','\="%".printf("%02X",char2nr(submatch(0)))','g') + let url = printf(g:rails_search_url, query) + else + return s:error("specify a g:rails_search_url with %s for a query placeholder") + endif + elseif isdirectory(rails#app().path("doc/api/classes")) + let url = rails#app().path("/doc/api/index.html") + elseif s:getpidfor("0.0.0.0","8808") > 0 + let url = "http://localhost:8808" + else + let url = "http://api.rubyonrails.org" + endif + call s:initOpenURL() + if exists(":OpenURL") + exe "OpenURL ".s:escarg(url) + else + return s:error("No :OpenURL command found") + endif +endfunction + +function! s:Log(bang,arg) + if a:arg == "" + let lf = "log/".s:environment().".log" + else + let lf = "log/".a:arg.".log" + endif + let size = getfsize(rails#app().path(lf)) + if size >= 1048576 + call s:warn("Log file is ".((size+512)/1024)."KB. Consider :Rake log:clear") + endif + if a:bang + exe "cgetfile ".lf + clast + else + if exists(":Tail") + Tail `=rails#app().path(lf)` + else + pedit `=rails#app().path(lf)` + endif + endif +endfunction + +function! rails#new_app_command(bang,...) + if a:0 == 0 + let msg = "rails.vim ".g:autoloaded_rails + if a:bang && exists('b:rails_root') && rails#buffer().type_name() == '' + echo msg." (Rails)" + elseif a:bang && exists('b:rails_root') + echo msg." (Rails-".rails#buffer().type_name().")" + elseif a:bang + echo msg + else + !rails + endif + return + endif + let args = map(copy(a:000),'expand(v:val)') + if a:bang + let args = ['--force'] + args + endif + exe '!rails '.join(map(copy(args),'s:rquote(v:val)'),' ') + for dir in args + if dir !~# '^-' && filereadable(dir.'/'.g:rails_default_file) + edit `=dir.'/'.g:rails_default_file` + return + endif + endfor +endfunction + +function! s:app_tags_command() dict + if exists("g:Tlist_Ctags_Cmd") + let cmd = g:Tlist_Ctags_Cmd + elseif executable("exuberant-ctags") + let cmd = "exuberant-ctags" + elseif executable("ctags-exuberant") + let cmd = "ctags-exuberant" + elseif executable("ctags") + let cmd = "ctags" + elseif executable("ctags.exe") + let cmd = "ctags.exe" + else + return s:error("ctags not found") + endif + exe '!'.cmd.' -f '.s:escarg(self.path("tmp/tags")).' -R --langmap="ruby:+.rake.builder.rjs" '.g:rails_ctags_arguments.' '.s:escarg(self.path()) +endfunction + +call s:add_methods('app',['tags_command']) + +function! s:Refresh(bang) + if exists("g:rubycomplete_rails") && g:rubycomplete_rails && has("ruby") && exists('g:rubycomplete_completions') + silent! ruby ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord) + silent! ruby if defined?(ActiveSupport::Dependencies); ActiveSupport::Dependencies.clear; elsif defined?(Dependencies); Dependencies.clear; end + if a:bang + silent! ruby ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord) + endif + endif + call rails#app().cache.clear() + silent doautocmd User BufLeaveRails + if a:bang + for key in keys(s:apps) + if type(s:apps[key]) == type({}) + call s:apps[key].cache.clear() + endif + call extend(s:apps[key],filter(copy(s:app_prototype),'type(v:val) == type(function("tr"))'),'force') + endfor + endif + let i = 1 + let max = bufnr('$') + while i <= max + let rr = getbufvar(i,"rails_root") + if rr != "" + call setbufvar(i,"rails_refresh",1) + endif + let i += 1 + endwhile + silent doautocmd User BufEnterRails +endfunction + +function! s:RefreshBuffer() + if exists("b:rails_refresh") && b:rails_refresh + let oldroot = b:rails_root + unlet! b:rails_root + let b:rails_refresh = 0 + call RailsBufInit(oldroot) + unlet! b:rails_refresh + endif +endfunction + +" }}}1 +" Rake {{{1 + +function! s:app_rake_tasks() dict + if self.cache.needs('rake_tasks') + call s:push_chdir() + try + let lines = split(system("rake -T"),"\n") + finally + call s:pop_command() + endtry + if v:shell_error != 0 + return [] + endif + call map(lines,'matchstr(v:val,"^rake\\s\\+\\zs\\S*")') + call filter(lines,'v:val != ""') + call self.cache.set('rake_tasks',lines) + endif + return self.cache.get('rake_tasks') +endfunction + +call s:add_methods('app', ['rake_tasks']) + +let s:efm_backtrace='%D(in\ %f),' + \.'%\\s%#from\ %f:%l:%m,' + \.'%\\s%#from\ %f:%l:,' + \.'%\\s#{RAILS_ROOT}/%f:%l:\ %#%m,' + \.'%\\s%##\ %f:%l:%m,' + \.'%\\s%##\ %f:%l,' + \.'%\\s%#[%f:%l:\ %#%m,' + \.'%\\s%#%f:%l:\ %#%m,' + \.'%\\s%#%f:%l:,' + \.'%m\ [%f:%l]:' + +function! s:makewithruby(arg,bang,...) + let old_make = &makeprg + try + let &l:makeprg = rails#app().ruby_shell_command(a:arg) + exe 'make'.(a:bang ? '!' : '') + if !a:bang + cwindow + endif + finally + let &l:makeprg = old_make + endtry +endfunction + +function! s:Rake(bang,lnum,arg) + let self = rails#app() + let lnum = a:lnum < 0 ? 0 : a:lnum + let old_makeprg = &l:makeprg + let old_errorformat = &l:errorformat + try + if exists('b:bundler_root') && b:bundler_root ==# rails#app().path() + let &l:makeprg = 'bundle exec rake' + else + let &l:makeprg = 'rake' + endif + let &l:errorformat = s:efm_backtrace + let arg = a:arg + if &filetype == "ruby" && arg == '' && g:rails_modelines + let mnum = s:lastmethodline(lnum) + let str = getline(mnum)."\n".getline(mnum+1)."\n".getline(mnum+2)."\n" + let pat = '\s\+\zs.\{-\}\ze\%(\n\|\s\s\|#{\@!\|$\)' + let mat = matchstr(str,'#\s*rake'.pat) + let mat = s:sub(mat,'\s+$','') + if mat != "" + let arg = mat + endif + endif + if arg == '' + let opt = s:getopt('task','bl') + if opt != '' + let arg = opt + else + let arg = rails#buffer().default_rake_task(lnum) + endif + endif + if !has_key(self,'options') | let self.options = {} | endif + if arg == '-' + let arg = get(self.options,'last_rake_task','') + endif + let self.options['last_rake_task'] = arg + let withrubyargs = '-r ./config/boot -r '.s:rquote(self.path('config/environment')).' -e "puts \%((in \#{Dir.getwd}))" ' + if arg =~# '^notes\>' + let &l:errorformat = '%-P%f:,\ \ *\ [%*[\ ]%l]\ [%t%*[^]]] %m,\ \ *\ [%*[\ ]%l] %m,%-Q' + " %D to chdir is apparently incompatible with %P multiline messages + call s:push_chdir(1) + exe 'make! '.arg + call s:pop_command() + if !a:bang + cwindow + endif + elseif arg =~# '^\%(stats\|routes\|secret\|time:zones\|db:\%(charset\|collation\|fixtures:identify\>.*\|migrate:status\|version\)\)\%([: ]\|$\)' + let &l:errorformat = '%D(in\ %f),%+G%.%#' + exe 'make! '.arg + if !a:bang + copen + endif + elseif arg =~ '^preview\>' + exe (lnum == 0 ? '' : lnum).'R'.s:gsub(arg,':','/') + elseif arg =~ '^runner:' + let arg = s:sub(arg,'^runner:','') + let root = matchstr(arg,'%\%(:\w\)*') + let file = expand(root).matchstr(arg,'%\%(:\w\)*\zs.*') + if file =~ '#.*$' + let extra = " -- -n ".matchstr(file,'#\zs.*') + let file = s:sub(file,'#.*','') + else + let extra = '' + endif + if self.has_file(file) || self.has_file(file.'.rb') + call s:makewithruby(withrubyargs.'-r"'.file.'"'.extra,a:bang,file !~# '_\%(spec\|test\)\%(\.rb\)\=$') + else + call s:makewithruby(withrubyargs.'-e '.s:esccmd(s:rquote(arg)),a:bang) + endif + elseif arg == 'run' || arg == 'runner' + call s:makewithruby(withrubyargs.'-r"'.RailsFilePath().'"',a:bang,RailsFilePath() !~# '_\%(spec\|test\)\%(\.rb\)\=$') + elseif arg =~ '^run:' + let arg = s:sub(arg,'^run:','') + let arg = s:sub(arg,'^\%:h',expand('%:h')) + let arg = s:sub(arg,'^%(\%|$|#@=)',expand('%')) + let arg = s:sub(arg,'#(\w+[?!=]=)$',' -- -n\1') + call s:makewithruby(withrubyargs.'-r'.arg,a:bang,arg !~# '_\%(spec\|test\)\.rb$') + else + exe 'make! '.arg + if !a:bang + cwindow + endif + endif + finally + let &l:errorformat = old_errorformat + let &l:makeprg = old_makeprg + endtry +endfunction + +function! s:readable_default_rake_task(lnum) dict abort + let app = self.app() + let lnum = a:lnum < 0 ? 0 : a:lnum + if self.getvar('&buftype') == 'quickfix' + return '-' + elseif self.getline(lnum) =~# '# rake ' + return matchstr(self.getline(lnum),'\C# rake \zs.*') + elseif self.getline(self.last_method_line(lnum)-1) =~# '# rake ' + return matchstr(self.getline(self.last_method_line(lnum)-1),'\C# rake \zs.*') + elseif self.getline(self.last_method_line(lnum)) =~# '# rake ' + return matchstr(self.getline(self.last_method_line(lnum)),'\C# rake \zs.*') + elseif self.getline(1) =~# '# rake ' && !lnum + return matchstr(self.getline(1),'\C# rake \zs.*') + elseif self.type_name('config-routes') + return 'routes' + elseif self.type_name('fixtures-yaml') && lnum + return "db:fixtures:identify LABEL=".self.last_method(lnum) + elseif self.type_name('fixtures') && lnum == 0 + return "db:fixtures:load FIXTURES=".s:sub(fnamemodify(self.name(),':r'),'^.{-}/fixtures/','') + elseif self.type_name('task') + let mnum = self.last_method_line(lnum) + let line = getline(mnum) + " We can't grab the namespace so only run tasks at the start of the line + if line =~# '^\%(task\|file\)\>' + return self.last_method(a:lnum) + else + return matchstr(self.getline(1),'\C# rake \zs.*') + endif + elseif self.type_name('spec') + if self.name() =~# '\ 0 + return 'spec SPEC="'.self.path().'":'.lnum + else + return 'spec SPEC="'.self.path().'"' + endif + elseif self.type_name('test') + let meth = self.last_method(lnum) + if meth =~ '^test_' + let call = " -n".meth."" + else + let call = "" + endif + if self.type_name('test-unit','test-functional','test-integration') + return s:sub(s:gsub(self.type_name(),'-',':'),'unit$|functional$','&s').' TEST="'.self.path().'"'.s:sub(call,'^ ',' TESTOPTS=') + elseif self.name() =~# '\ 0 + return 'cucumber FEATURE="'.self.path().'":'.lnum + else + return 'cucumber FEATURE="'.self.path().'"' + endif + elseif self.type_name('cucumber') + return 'cucumber' + else + return '' + endif +endfunction + +function! s:Complete_rake(A,L,P) + return s:completion_filter(rails#app().rake_tasks(),a:A) +endfunction + +call s:add_methods('readable',['default_rake_task']) + +" }}}1 +" Preview {{{1 + +function! s:initOpenURL() + if !exists(":OpenURL") + if has("gui_mac") || has("gui_macvim") || exists("$SECURITYSESSIONID") + command -bar -nargs=1 OpenURL :!open + elseif has("gui_win32") + command -bar -nargs=1 OpenURL :!start cmd /cstart /b + elseif executable("sensible-browser") + command -bar -nargs=1 OpenURL :!sensible-browser + endif + endif +endfunction + +function! s:scanlineforuris(line) + let url = matchstr(a:line,"\\v\\C%(%(GET|PUT|POST|DELETE)\\s+|\\w+://[^/]*)/[^ \n\r\t<>\"]*[^] .,;\n\r\t<>\":]") + if url =~ '\C^\u\+\s\+' + let method = matchstr(url,'^\u\+') + let url = matchstr(url,'\s\+\zs.*') + if method !=? "GET" + let url .= (url =~ '?' ? '&' : '?') . '_method='.tolower(method) + endif + endif + if url != "" + return [url] + else + return [] + endif +endfunction + +function! s:readable_preview_urls(lnum) dict abort + let urls = [] + let start = self.last_method_line(a:lnum) - 1 + while start > 0 && self.getline(start) =~ '^\s*\%(\%(-\=\|<%\)#.*\)\=$' + let urls = s:scanlineforuris(self.getline(start)) + urls + let start -= 1 + endwhile + let start = 1 + while start < self.line_count() && self.getline(start) =~ '^\s*\%(\%(-\=\|<%\)#.*\)\=$' + let urls += s:scanlineforuris(self.getline(start)) + let start += 1 + endwhile + if has_key(self,'getvar') && self.getvar('rails_preview') != '' + let url += [self.getvar('rails_preview')] + end + if self.name() =~ '^public/stylesheets/sass/' + let urls = urls + [s:sub(s:sub(self.name(),'^public/stylesheets/sass/','/stylesheets/'),'\.s[ac]ss$','.css')] + elseif self.name() =~ '^public/' + let urls = urls + [s:sub(self.name(),'^public','')] + elseif self.name() =~ '^app/assets/stylesheets/' + let urls = urls + ['/assets/application.css'] + elseif self.name() =~ '^app/assets/javascripts/' + let urls = urls + ['/assets/application.js'] + elseif self.name() =~ '^app/stylesheets/' + let urls = urls + [s:sub(s:sub(self.name(),'^app/stylesheets/','/stylesheets/'),'\.less$','.css')] + elseif self.name() =~ '^app/scripts/' + let urls = urls + [s:sub(s:sub(self.name(),'^app/scripts/','/javascripts/'),'\.coffee$','.js')] + elseif self.controller_name() != '' && self.controller_name() != 'application' + if self.type_name('controller') && self.last_method(a:lnum) != '' + let urls += ['/'.self.controller_name().'/'.self.last_method(a:lnum).'/'] + elseif self.type_name('controller','view-layout','view-partial') + let urls += ['/'.self.controller_name().'/'] + elseif self.type_name('view') + let urls += ['/'.s:controller().'/'.fnamemodify(self.name(),':t:r:r').'/'] + endif + endif + return urls +endfunction + +call s:add_methods('readable',['preview_urls']) + +function! s:Preview(bang,lnum,arg) + let root = s:getopt("root_url") + if root == '' + let root = s:getopt("url") + endif + let root = s:sub(root,'/$','') + if a:arg =~ '://' + let uri = a:arg + elseif a:arg != '' + let uri = root.'/'.s:sub(a:arg,'^/','') + else + let uri = get(rails#buffer().preview_urls(a:lnum),0,'') + let uri = root.'/'.s:sub(s:sub(uri,'^/',''),'/$','') + endif + call s:initOpenURL() + if exists(':OpenURL') && !a:bang + exe 'OpenURL '.uri + else + " Work around bug where URLs ending in / get handled as FTP + let url = uri.(uri =~ '/$' ? '?' : '') + silent exe 'pedit '.url + wincmd w + if &filetype == '' + if uri =~ '\.css$' + setlocal filetype=css + elseif uri =~ '\.js$' + setlocal filetype=javascript + elseif getline(1) =~ '^\s*<' + setlocal filetype=xhtml + endif + endif + call RailsBufInit(rails#app().path()) + map q :bwipe + wincmd p + if !a:bang + call s:warn("Define a :OpenURL command to use a browser") + endif + endif +endfunction + +function! s:Complete_preview(A,L,P) + return rails#buffer().preview_urls(a:L =~ '^\d' ? matchstr(a:L,'^\d\+') : line('.')) +endfunction + +" }}}1 +" Script Wrappers {{{1 + +function! s:BufScriptWrappers() + command! -buffer -bar -nargs=* -complete=customlist,s:Complete_script Rscript :call rails#app().script_command(0,) + command! -buffer -bar -nargs=* -complete=customlist,s:Complete_generate Rgenerate :call rails#app().generate_command(0,) + command! -buffer -bar -nargs=* -complete=customlist,s:Complete_destroy Rdestroy :call rails#app().destroy_command(0,) + command! -buffer -bar -nargs=? -bang -complete=customlist,s:Complete_server Rserver :call rails#app().server_command(0,) + command! -buffer -bang -nargs=1 -range=0 -complete=customlist,s:Complete_ruby Rrunner :call rails#app().runner_command(0 ? -2 : (==?:-1),) + command! -buffer -nargs=1 -range=0 -complete=customlist,s:Complete_ruby Rp :call rails#app().runner_command(==?:-1,'p begin '..' end') + command! -buffer -nargs=1 -range=0 -complete=customlist,s:Complete_ruby Rpp :call rails#app().runner_command(==?:-1,'require %{pp}; pp begin '..' end') + command! -buffer -nargs=1 -range=0 -complete=customlist,s:Complete_ruby Ry :call rails#app().runner_command(==?:-1,'y begin '..' end') +endfunction + +function! s:app_generators() dict + if self.cache.needs('generators') + let generators = self.relglob("vendor/plugins/","*/generators/*") + let generators += self.relglob("","lib/generators/*") + call filter(generators,'v:val =~ "/$"') + let generators += split(glob(expand("~/.rails/generators")."/*"),"\n") + call map(generators,'s:sub(v:val,"^.*[\\\\/]generators[\\\\/]\\ze.","")') + call map(generators,'s:sub(v:val,"[\\\\/]$","")') + call self.cache.set('generators',generators) + endif + return sort(split(g:rails_generators,"\n") + self.cache.get('generators')) +endfunction + +function! s:app_script_command(bang,...) dict + let str = "" + let cmd = a:0 ? a:1 : "console" + let c = 2 + while c <= a:0 + let str .= " " . s:rquote(a:{c}) + let c += 1 + endwhile + if cmd ==# "plugin" + call self.cache.clear('generators') + endif + if a:bang || cmd =~# 'console' + return self.background_script_command(cmd.str) + else + return self.execute_script_command(cmd.str) + endif +endfunction + +function! s:app_runner_command(count,args) dict + if a:count == -2 + return self.script_command(a:bang,"runner",a:args) + else + let str = self.ruby_shell_command('-r./config/boot -e "require '."'commands/runner'".'" '.s:rquote(a:args)) + let res = s:sub(system(str),'\n$','') + if a:count < 0 + echo res + else + exe a:count.'put =res' + endif + endif +endfunction + +function! s:getpidfor(bind,port) + if has("win32") || has("win64") + let netstat = system("netstat -anop tcp") + let pid = matchstr(netstat,'\<'.a:bind.':'.a:port.'\>.\{-\}LISTENING\s\+\zs\d\+') + elseif executable('lsof') + let pid = system("lsof -i 4tcp@".a:bind.':'.a:port."|grep LISTEN|awk '{print $2}'") + let pid = s:sub(pid,'\n','') + else + let pid = "" + endif + return pid +endfunction + +function! s:app_server_command(bang,arg) dict + let port = matchstr(a:arg,'\%(-p\|--port=\=\)\s*\zs\d\+') + if port == '' + let port = "3000" + endif + " TODO: Extract bind argument + let bind = "0.0.0.0" + if a:bang && executable("ruby") + let pid = s:getpidfor(bind,port) + if pid =~ '^\d\+$' + echo "Killing server with pid ".pid + if !has("win32") + call system("ruby -e 'Process.kill(:TERM,".pid.")'") + sleep 100m + endif + call system("ruby -e 'Process.kill(9,".pid.")'") + sleep 100m + endif + if a:arg == "-" + return + endif + endif + if has_key(self,'options') && has_key(self.options,'gnu_screen') + let screen = self.options.gnu_screen + else + let screen = g:rails_gnu_screen + endif + if has("win32") || has("win64") || (exists("$STY") && !has("gui_running") && screen && executable("screen")) || (exists("$TMUX") && !has("gui_running") && screen && executable("tmux")) + call self.background_script_command('server '.a:arg) + else + " --daemon would be more descriptive but lighttpd does not support it + call self.execute_script_command('server '.a:arg." -d") + endif + call s:setopt('a:root_url','http://'.(bind=='0.0.0.0'?'localhost': bind).':'.port.'/') +endfunction + +function! s:app_destroy_command(bang,...) dict + if a:0 == 0 + return self.execute_script_command('destroy') + elseif a:0 == 1 + return self.execute_script_command('destroy '.s:rquote(a:1)) + endif + let str = "" + let c = 1 + while c <= a:0 + let str .= " " . s:rquote(a:{c}) + let c += 1 + endwhile + call self.execute_script_command('destroy'.str) + call self.cache.clear('user_classes') +endfunction + +function! s:app_generate_command(bang,...) dict + if a:0 == 0 + return self.execute_script_command('generate') + elseif a:0 == 1 + return self.execute_script_command('generate '.s:rquote(a:1)) + endif + let cmd = join(map(copy(a:000),'s:rquote(v:val)'),' ') + if cmd !~ '-p\>' && cmd !~ '--pretend\>' + let execstr = self.script_shell_command('generate '.cmd.' -p -f') + let res = system(execstr) + let g:res = res + let junk = '\%(\e\[[0-9;]*m\)\=' + let file = matchstr(res,junk.'\s\+\%(create\|force\)'.junk.'\s\+\zs\f\+\.rb\ze\n') + if file == "" + let file = matchstr(res,junk.'\s\+\%(identical\)'.junk.'\s\+\zs\f\+\.rb\ze\n') + endif + else + let file = "" + endif + if !self.execute_script_command('generate '.cmd) && file != '' + call self.cache.clear('user_classes') + call self.cache.clear('features') + if file =~ '^db/migrate/\d\d\d\d' + let file = get(self.relglob('',s:sub(file,'\d+','[0-9]*[0-9]')),-1,file) + endif + edit `=self.path(file)` + endif +endfunction + +call s:add_methods('app', ['generators','script_command','runner_command','server_command','destroy_command','generate_command']) + +function! s:Complete_script(ArgLead,CmdLine,P) + let cmd = s:sub(a:CmdLine,'^\u\w*\s+','') + if cmd !~ '^[ A-Za-z0-9_=:-]*$' + return [] + elseif cmd =~# '^\w*$' + return s:completion_filter(rails#app().relglob("script/","**/*"),a:ArgLead) + elseif cmd =~# '^\%(plugin\)\s\+'.a:ArgLead.'$' + return s:completion_filter(["discover","list","install","update","remove","source","unsource","sources"],a:ArgLead) + elseif cmd =~# '\%(plugin\)\s\+\%(install\|remove\)\s\+'.a:ArgLead.'$' || cmd =~ '\%(generate\|destroy\)\s\+plugin\s\+'.a:ArgLead.'$' + return s:pluginList(a:ArgLead,a:CmdLine,a:P) + elseif cmd =~# '^\%(generate\|destroy\)\s\+'.a:ArgLead.'$' + return s:completion_filter(rails#app().generators(),a:ArgLead) + elseif cmd =~# '^\%(generate\|destroy\)\s\+\w\+\s\+'.a:ArgLead.'$' + let target = matchstr(cmd,'^\w\+\s\+\%(\w\+:\)\=\zs\w\+\ze\s\+') + if target =~# '^\w*controller$' + return filter(s:controllerList(a:ArgLead,"",""),'v:val !=# "application"') + elseif target ==# 'generator' + return s:completion_filter(map(rails#app().relglob('lib/generators/','*'),'s:sub(v:val,"/$","")')) + elseif target ==# 'helper' + return s:helperList(a:ArgLead,"","") + elseif target ==# 'integration_test' || target ==# 'integration_spec' || target ==# 'feature' + return s:integrationtestList(a:ArgLead,"","") + elseif target ==# 'metal' + return s:metalList(a:ArgLead,"","") + elseif target ==# 'migration' || target ==# 'session_migration' + return s:migrationList(a:ArgLead,"","") + elseif target =~# '^\w*\%(model\|resource\)$' || target =~# '\w*scaffold\%(_controller\)\=$' || target ==# 'mailer' + return s:modelList(a:ArgLead,"","") + elseif target ==# 'observer' + let observers = s:observerList("","","") + let models = s:modelList("","","") + if cmd =~# '^destroy\>' + let models = [] + endif + call filter(models,'index(observers,v:val) < 0') + return s:completion_filter(observers + models,a:ArgLead) + else + return [] + endif + elseif cmd =~# '^\%(generate\|destroy\)\s\+scaffold\s\+\w\+\s\+'.a:ArgLead.'$' + return filter(s:controllerList(a:ArgLead,"",""),'v:val !=# "application"') + return s:completion_filter(rails#app().environments()) + elseif cmd =~# '^\%(console\)\s\+\(--\=\w\+\s\+\)\='.a:ArgLead."$" + return s:completion_filter(rails#app().environments()+["-s","--sandbox"],a:ArgLead) + elseif cmd =~# '^\%(server\)\s\+.*-e\s\+'.a:ArgLead."$" + return s:completion_filter(rails#app().environments(),a:ArgLead) + elseif cmd =~# '^\%(server\)\s\+' + if a:ArgLead =~# '^--environment=' + return s:completion_filter(map(copy(rails#app().environments()),'"--environment=".v:val'),a:ArgLead) + else + return filter(["-p","-b","-e","-m","-d","-u","-c","-h","--port=","--binding=","--environment=","--mime-types=","--daemon","--debugger","--charset=","--help"],'s:startswith(v:val,a:ArgLead)') + endif + endif + return "" +endfunction + +function! s:CustomComplete(A,L,P,cmd) + let L = "Rscript ".a:cmd." ".s:sub(a:L,'^\h\w*\s+','') + let P = a:P - strlen(a:L) + strlen(L) + return s:Complete_script(a:A,L,P) +endfunction + +function! s:Complete_server(A,L,P) + return s:CustomComplete(a:A,a:L,a:P,"server") +endfunction + +function! s:Complete_console(A,L,P) + return s:CustomComplete(a:A,a:L,a:P,"console") +endfunction + +function! s:Complete_generate(A,L,P) + return s:CustomComplete(a:A,a:L,a:P,"generate") +endfunction + +function! s:Complete_destroy(A,L,P) + return s:CustomComplete(a:A,a:L,a:P,"destroy") +endfunction + +function! s:Complete_ruby(A,L,P) + return s:completion_filter(rails#app().user_classes()+["ActiveRecord::Base"],a:A) +endfunction + +" }}}1 +" Navigation {{{1 + +function! s:BufNavCommands() + command! -buffer -bar -nargs=? -complete=customlist,s:Complete_cd Rcd :cd `=rails#app().path()` + command! -buffer -bar -nargs=? -complete=customlist,s:Complete_cd Rlcd :lcd `=rails#app().path()` + command! -buffer -bar -nargs=* -count=1 -complete=customlist,s:Complete_find Rfind :call s:warn( 'Rfind has been deprecated in favor of :1R or :find' )|call s:Find(,'' ,) + command! -buffer -bar -nargs=* -count=1 -complete=customlist,s:Complete_find REfind :call s:warn('REfind has been deprecated in favor of :1RE or :find')|call s:Find(,'E',) + command! -buffer -bar -nargs=* -count=1 -complete=customlist,s:Complete_find RSfind :call s:warn('RSfind has been deprecated in favor of :1RS or :find')|call s:Find(,'S',) + command! -buffer -bar -nargs=* -count=1 -complete=customlist,s:Complete_find RVfind :call s:warn('RVfind has been deprecated in favor of :1RV or :find')|call s:Find(,'V',) + command! -buffer -bar -nargs=* -count=1 -complete=customlist,s:Complete_find RTfind :call s:warn('RTfind has been deprecated in favor of :1RT or :find')|call s:Find(,'T',) + command! -buffer -bar -nargs=* -count=1 -complete=customlist,s:Complete_find Rsfind :call s:warn('Rsfind has been deprecated in favor of :1RS or :sfind')|RSfind + command! -buffer -bar -nargs=* -count=1 -complete=customlist,s:Complete_find Rtabfind :call s:warn('Rtabfind has been deprecated in favor of :1RT or :tabfind')|RTfind + command! -buffer -bar -nargs=* -bang -complete=customlist,s:Complete_edit Redit :call s:warn( 'Redit has been deprecated in favor of :R')|call s:Edit(,'' ,) + command! -buffer -bar -nargs=* -bang -complete=customlist,s:Complete_edit REedit :call s:warn('REedit has been deprecated in favor of :RE')|call s:Edit(,'E',) + command! -buffer -bar -nargs=* -bang -complete=customlist,s:Complete_edit RSedit :call s:warn('RSedit has been deprecated in favor of :RS')|call s:Edit(,'S',) + command! -buffer -bar -nargs=* -bang -complete=customlist,s:Complete_edit RVedit :call s:warn('RVedit has been deprecated in favor of :RV')|call s:Edit(,'V',) + command! -buffer -bar -nargs=* -bang -complete=customlist,s:Complete_edit RTedit :call s:warn('RTedit has been deprecated in favor of :RT')|call s:Edit(,'T',) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_edit RDedit :call s:warn('RDedit has been deprecated in favor of :RD')|call s:Edit(,'D',) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related A :call s:Alternate('', ,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AE :call s:Alternate('E',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AS :call s:Alternate('S',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AV :call s:Alternate('V',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AT :call s:Alternate('T',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AD :call s:Alternate('D',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related AN :call s:Related('' ,,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related R :call s:Related('' ,,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RE :call s:Related('E',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RS :call s:Related('S',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RV :call s:Related('V',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RT :call s:Related('T',,,,) + command! -buffer -bar -nargs=* -range=0 -complete=customlist,s:Complete_related RD :call s:Related('D',,,,) +endfunction + +function! s:djump(def) + let def = s:sub(a:def,'^[#:]','') + if def =~ '^\d\+$' + exe def + elseif def =~ '^!' + if expand('%') !~ '://' && !isdirectory(expand('%:p:h')) + call mkdir(expand('%:p:h'),'p') + endif + elseif def != '' + let ext = matchstr(def,'\.\zs.*') + let def = matchstr(def,'[^.]*') + let v:errmsg = '' + silent! exe "djump ".def + if ext != '' && (v:errmsg == '' || v:errmsg =~ '^E387') + let rpat = '\C^\s*\%(mail\>.*\|respond_to\)\s*\%(\ 0 + let variable = matchstr(getline(rline),rpat) + let success = search('\C^\s*'.variable.'\s*\.\s*\zs'.ext.'\>','',end) + if !success + silent! exe "djump ".def + endif + endif + endif + endif +endfunction + +function! s:Find(count,cmd,...) + let str = "" + if a:0 + let i = 1 + while i < a:0 + let str .= s:escarg(a:{i}) . " " + let i += 1 + endwhile + let file = a:{i} + let tail = matchstr(file,'[#!].*$\|:\d*\%(:in\>.*\)\=$') + if tail != "" + let file = s:sub(file,'[#!].*$|:\d*%(:in>.*)=$','') + endif + if file != "" + let file = s:RailsIncludefind(file) + endif + else + let file = s:RailsFind() + let tail = "" + endif + call s:findedit((a:count==1?'' : a:count).a:cmd,file.tail,str) +endfunction + +function! s:Edit(count,cmd,...) + if a:0 + let str = "" + let i = 1 + while i < a:0 + let str .= "`=a:".i."` " + let i += 1 + endwhile + let file = a:{i} + call s:findedit(s:editcmdfor(a:cmd),file,str) + else + exe s:editcmdfor(a:cmd) + endif +endfunction + +function! s:fuzzyglob(arg) + return s:gsub(s:gsub(a:arg,'[^/.]','[&]*'),'%(/|^)\.@!|\.','&*') +endfunction + +function! s:Complete_find(ArgLead, CmdLine, CursorPos) + let paths = s:pathsplit(&l:path) + let seen = {} + for path in paths + if s:startswith(path,rails#app().path()) && path !~ '[][*]' + let path = path[strlen(rails#app().path()) + 1 : ] + for file in rails#app().relglob(path == '' ? '' : path.'/',s:fuzzyglob(rails#underscore(a:ArgLead)), a:ArgLead =~# '\u' ? '.rb' : '') + let seen[file] = 1 + endfor + endif + endfor + return s:autocamelize(sort(keys(seen)),a:ArgLead) +endfunction + +function! s:Complete_edit(ArgLead, CmdLine, CursorPos) + return s:completion_filter(rails#app().relglob("",s:fuzzyglob(a:ArgLead)),a:ArgLead) +endfunction + +function! s:Complete_cd(ArgLead, CmdLine, CursorPos) + let all = rails#app().relglob("",a:ArgLead."*") + call filter(all,'v:val =~ "/$"') + return filter(all,'s:startswith(v:val,a:ArgLead)') +endfunction + +function! RailsIncludeexpr() + " Is this foolproof? + if mode() =~ '[iR]' || expand("") != v:fname + return s:RailsIncludefind(v:fname) + else + return s:RailsIncludefind(v:fname,1) + endif +endfunction + +function! s:linepeak() + let line = getline(line(".")) + let line = s:sub(line,'^(.{'.col(".").'}).*','\1') + let line = s:sub(line,'([:"'."'".']|\%[qQ]=[[({<])=\f*$','') + return line +endfunction + +function! s:matchcursor(pat) + let line = getline(".") + let lastend = 0 + while lastend >= 0 + let beg = match(line,'\C'.a:pat,lastend) + let end = matchend(line,'\C'.a:pat,lastend) + if beg < col(".") && end >= col(".") + return matchstr(line,'\C'.a:pat,lastend) + endif + let lastend = end + endwhile + return "" +endfunction + +function! s:findit(pat,repl) + let res = s:matchcursor(a:pat) + if res != "" + return substitute(res,'\C'.a:pat,a:repl,'') + else + return "" + endif +endfunction + +function! s:findamethod(func,repl) + return s:findit('\s*\<\%('.a:func.'\)\s*(\=\s*[@:'."'".'"]\(\f\+\)\>.\=',a:repl) +endfunction + +function! s:findasymbol(sym,repl) + return s:findit('\s*\%(:\%('.a:sym.'\)\s*=>\|\<'.a:sym.':\)\s*(\=\s*[@:'."'".'"]\(\f\+\)\>.\=',a:repl) +endfunction + +function! s:findfromview(func,repl) + " ( ) ( ) ( \1 ) ( ) + return s:findit('\s*\%(<%\)\==\=\s*\<\%('.a:func.'\)\s*(\=\s*[@:'."'".'"]\(\f\+\)\>['."'".'"]\=\s*\%(%>\s*\)\=',a:repl) +endfunction + +function! s:RailsFind() + if filereadable(expand("")) + return expand("") + endif + + " UGH + let buffer = rails#buffer() + let format = s:format('html') + + let res = s:findit('\v\s*.=',expand('%:h').'/\1') + if res != ""|return res.(fnamemodify(res,':e') == '' ? '.rb' : '')|endif + + let res = s:findit('\v['."'".'"]=',expand('%:h').'\1') + if res != ""|return res|endif + + let res = rails#underscore(s:findit('\v\s*<%(include|extend)\(=\s*<([[:alnum:]_:]+)>','\1')) + if res != ""|return res.".rb"|endif + + let res = s:findamethod('require','\1') + if res != ""|return res.(fnamemodify(res,':e') == '' ? '.rb' : '')|endif + + let res = s:findamethod('belongs_to\|has_one\|composed_of\|validates_associated\|scaffold','app/models/\1.rb') + if res != ""|return res|endif + + let res = rails#singularize(s:findamethod('has_many\|has_and_belongs_to_many','app/models/\1')) + if res != ""|return res.".rb"|endif + + let res = rails#singularize(s:findamethod('create_table\|change_table\|drop_table\|add_column\|rename_column\|remove_column\|add_index','app/models/\1')) + if res != ""|return res.".rb"|endif + + let res = rails#singularize(s:findasymbol('through','app/models/\1')) + if res != ""|return res.".rb"|endif + + let res = s:findamethod('fixtures','fixtures/\1') + if res != "" + return RailsFilePath() =~ '\\|\\|,\s*to:\)\s*','app/controllers/\1') + if res =~ '#'|return s:sub(res,'#','_controller.rb#')|endif + + let res = s:findamethod('layout','\=s:findlayout(submatch(1))') + if res != ""|return res|endif + + let res = s:findasymbol('layout','\=s:findlayout(submatch(1))') + if res != ""|return res|endif + + let res = s:findamethod('helper','app/helpers/\1_helper.rb') + if res != ""|return res|endif + + let res = s:findasymbol('controller','app/controllers/\1_controller.rb') + if res != ""|return res|endif + + let res = s:findasymbol('action','\1') + if res != ""|return res|endif + + let res = s:findasymbol('template','app/views/\1') + if res != ""|return res|endif + + let res = s:sub(s:sub(s:findasymbol('partial','\1'),'^/',''),'[^/]+$','_&') + if res != ""|return res."\n".s:findview(res)|endif + + let res = s:sub(s:sub(s:findfromview('render\s*(\=\s*\%(:partial\s\+=>\|partial:\)\s*','\1'),'^/',''),'[^/]+$','_&') + if res != ""|return res."\n".s:findview(res)|endif + + let res = s:findamethod('render\>\s*\%(:\%(template\|action\)\s\+=>\|template:\|action:\)\s*','\1.'.format.'\n\1') + if res != ""|return res|endif + + let res = s:sub(s:findfromview('render','\1'),'^/','') + if buffer.type_name('view') | let res = s:sub(res,'[^/]+$','_&') | endif + if res != ""|return res."\n".s:findview(res)|endif + + let res = s:findamethod('redirect_to\s*(\=\s*\%\(:action\s\+=>\|\','/application') + if res != '' && fnamemodify(res, ':e') == '' " Append the default extension iff the filename doesn't already contains an extension + let res .= '.js' + end + if res != ""|return res|endif + + if buffer.type_name('controller') + let contr = s:controller() + let view = s:findit('\s*\(\=','/\1') + let res = s:findview(contr.'/'.view) + if res != ""|return res|endif + endif + + let old_isfname = &isfname + try + set isfname=@,48-57,/,-,_,:,# + " TODO: grab visual selection in visual mode + let cfile = expand("") + finally + let &isfname = old_isfname + endtry + let res = s:RailsIncludefind(cfile,1) + return res +endfunction + +function! s:app_named_route_file(route) dict + call self.route_names() + if self.cache.has("named_routes") && has_key(self.cache.get("named_routes"),a:route) + return self.cache.get("named_routes")[a:route] + endif + return "" +endfunction + +function! s:app_route_names() dict + if self.cache.needs("named_routes") + let exec = "ActionController::Routing::Routes.named_routes.each {|n,r| puts %{#{n} app/controllers/#{r.requirements[:controller]}_controller.rb##{r.requirements[:action]}}}" + let string = self.eval(exec) + let routes = {} + for line in split(string,"\n") + let route = split(line," ") + let name = route[0] + let routes[name] = route[1] + endfor + call self.cache.set("named_routes",routes) + endif + + return keys(self.cache.get("named_routes")) +endfunction + +call s:add_methods('app', ['route_names','named_route_file']) + +function! RailsNamedRoutes() + return rails#app().route_names() +endfunction + +function! s:RailsIncludefind(str,...) + if a:str ==# "ApplicationController" + return "application_controller.rb\napp/controllers/application.rb" + elseif a:str ==# "Test::Unit::TestCase" + return "test/unit/testcase.rb" + endif + let str = a:str + if a:0 == 1 + " Get the text before the filename under the cursor. + " We'll cheat and peak at this in a bit + let line = s:linepeak() + let line = s:sub(line,'([:"'."'".']|\%[qQ]=[[({<])=\f*$','') + else + let line = "" + endif + let str = s:sub(str,'^\s*','') + let str = s:sub(str,'\s*$','') + let str = s:sub(str,'^:=[:@]','') + let str = s:sub(str,':0x\x+$','') " For # style output + let str = s:gsub(str,"[\"']",'') + if line =~# '\<\(require\|load\)\s*(\s*$' + return str + elseif str =~# '^\l\w*#\w\+$' + return 'app/controllers/'.s:sub(str,'#','_controller.rb#') + endif + let str = rails#underscore(str) + let fpat = '\(\s*\%("\f*"\|:\f*\|'."'\\f*'".'\)\s*,\s*\)*' + if a:str =~# '\u' + " Classes should always be in .rb files + let str .= '.rb' + elseif line =~# ':partial\s*=>\s*' + let str = s:sub(str,'[^/]+$','_&') + let str = s:findview(str) + elseif line =~# '\\s*' + let str = s:findview(s:sub(str,'^/=','layouts/')) + elseif line =~# ':controller\s*=>\s*' + let str = 'app/controllers/'.str.'_controller.rb' + elseif line =~# '\\s*$' && rails#buffer().type_name('config-routes')) + if line !~# ':as\s*=>\s*$' + let str = s:sub(str,'_%(path|url)$','') + let str = s:sub(str,'^hash_for_','') + endif + let file = rails#app().named_route_file(str) + if file == "" + let str = s:sub(str,'^formatted_','') + if str =~# '^\%(new\|edit\)_' + let str = 'app/controllers/'.s:sub(rails#pluralize(str),'^(new|edit)_(.*)','\2_controller.rb#\1') + elseif str ==# rails#singularize(str) + " If the word can't be singularized, it's probably a link to the show + " method. We should verify by checking for an argument, but that's + " difficult the way things here are currently structured. + let str = 'app/controllers/'.rails#pluralize(str).'_controller.rb#show' + else + let str = 'app/controllers/'.str.'_controller.rb#index' + endif + else + let str = file + endif + elseif str !~ '/' + " If we made it this far, we'll risk making it singular. + let str = rails#singularize(str) + let str = s:sub(str,'_id$','') + endif + if str =~ '^/' && !filereadable(str) + let str = s:sub(str,'^/','') + endif + if str =~# '^lib/' && !filereadable(str) + let str = s:sub(str,'^lib/','') + endif + return str +endfunction + +" }}}1 +" File Finders {{{1 + +function! s:addfilecmds(type) + let l = s:sub(a:type,'^.','\l&') + let cmds = 'ESVTD ' + let cmd = '' + while cmds != '' + let cplt = " -complete=customlist,".s:sid.l."List" + exe "command! -buffer -bar ".(cmd == 'D' ? '-range=0 ' : '')."-nargs=*".cplt." R".cmd.l." :call s:".l.'Edit("'.(cmd == 'D' ? '' : '').cmd.'",)' + let cmd = strpart(cmds,0,1) + let cmds = strpart(cmds,1) + endwhile +endfunction + +function! s:BufFinderCommands() + command! -buffer -bar -nargs=+ Rnavcommand :call s:Navcommand(0,) + call s:addfilecmds("metal") + call s:addfilecmds("model") + call s:addfilecmds("view") + call s:addfilecmds("controller") + call s:addfilecmds("mailer") + call s:addfilecmds("migration") + call s:addfilecmds("observer") + call s:addfilecmds("helper") + call s:addfilecmds("layout") + call s:addfilecmds("fixtures") + call s:addfilecmds("locale") + if rails#app().has('test') || rails#app().has('spec') + call s:addfilecmds("unittest") + call s:addfilecmds("functionaltest") + endif + if rails#app().has('test') || rails#app().has('spec') || rails#app().has('cucumber') + call s:addfilecmds("integrationtest") + endif + if rails#app().has('spec') + call s:addfilecmds("spec") + endif + call s:addfilecmds("stylesheet") + call s:addfilecmds("javascript") + call s:addfilecmds("plugin") + call s:addfilecmds("task") + call s:addfilecmds("lib") + call s:addfilecmds("environment") + call s:addfilecmds("initializer") +endfunction + +function! s:completion_filter(results,A) + let results = sort(type(a:results) == type("") ? split(a:results,"\n") : copy(a:results)) + call filter(results,'v:val !~# "\\~$"') + let filtered = filter(copy(results),'s:startswith(v:val,a:A)') + if !empty(filtered) | return filtered | endif + let regex = s:gsub(a:A,'[^/]','[&].*') + let filtered = filter(copy(results),'v:val =~# "^".regex') + if !empty(filtered) | return filtered | endif + let regex = s:gsub(a:A,'.','[&].*') + let filtered = filter(copy(results),'v:val =~# regex') + return filtered +endfunction + +function! s:autocamelize(files,test) + if a:test =~# '^\u' + return s:completion_filter(map(copy(a:files),'rails#camelize(v:val)'),a:test) + else + return s:completion_filter(a:files,a:test) + endif +endfunction + +function! s:app_relglob(path,glob,...) dict + if exists("+shellslash") && ! &shellslash + let old_ss = &shellslash + let &shellslash = 1 + endif + let path = a:path + if path !~ '^/' && path !~ '^\w:' + let path = self.path(path) + endif + let suffix = a:0 ? a:1 : '' + let full_paths = split(glob(path.a:glob.suffix),"\n") + let relative_paths = [] + for entry in full_paths + if suffix == '' && isdirectory(entry) && entry !~ '/$' + let entry .= '/' + endif + let relative_paths += [entry[strlen(path) : -strlen(suffix)-1]] + endfor + if exists("old_ss") + let &shellslash = old_ss + endif + return relative_paths +endfunction + +call s:add_methods('app', ['relglob']) + +function! s:relglob(...) + return join(call(rails#app().relglob,a:000,rails#app()),"\n") +endfunction + +function! s:helperList(A,L,P) + return s:autocamelize(rails#app().relglob("app/helpers/","**/*","_helper.rb"),a:A) +endfunction + +function! s:controllerList(A,L,P) + let con = rails#app().relglob("app/controllers/","**/*",".rb") + call map(con,'s:sub(v:val,"_controller$","")') + return s:autocamelize(con,a:A) +endfunction + +function! s:mailerList(A,L,P) + return s:autocamelize(rails#app().relglob("app/mailers/","**/*",".rb"),a:A) +endfunction + +function! s:viewList(A,L,P) + let c = s:controller(1) + let top = rails#app().relglob("app/views/",s:fuzzyglob(a:A)) + call filter(top,'v:val !~# "\\~$"') + if c != '' && a:A !~ '/' + let local = rails#app().relglob("app/views/".c."/","*.*[^~]") + return s:completion_filter(local+top,a:A) + endif + return s:completion_filter(top,a:A) +endfunction + +function! s:layoutList(A,L,P) + return s:completion_filter(rails#app().relglob("app/views/layouts/","*"),a:A) +endfunction + +function! s:stylesheetList(A,L,P) + let list = rails#app().relglob('app/assets/stylesheets/','**/*.*','') + call map(list,'s:sub(v:val,"\\..*$","")') + let list += rails#app().relglob('public/stylesheets/','**/*','.css') + if rails#app().has('sass') + call extend(list,rails#app().relglob('public/stylesheets/sass/','**/*','.s?ss')) + call s:uniq(list) + endif + return s:completion_filter(list,a:A) +endfunction + +function! s:javascriptList(A,L,P) + let list = rails#app().relglob('app/assets/javascripts/','**/*.*','') + call map(list,'s:sub(v:val,"\\..*$","")') + let list += rails#app().relglob("public/javascripts/","**/*",".js") + return s:completion_filter(list,a:A) +endfunction + +function! s:metalList(A,L,P) + return s:autocamelize(rails#app().relglob("app/metal/","**/*",".rb"),a:A) +endfunction + +function! s:modelList(A,L,P) + let models = rails#app().relglob("app/models/","**/*",".rb") + call filter(models,'v:val !~# "_observer$"') + return s:autocamelize(models,a:A) +endfunction + +function! s:observerList(A,L,P) + return s:autocamelize(rails#app().relglob("app/models/","**/*","_observer.rb"),a:A) +endfunction + +function! s:fixturesList(A,L,P) + return s:completion_filter(rails#app().relglob("test/fixtures/","**/*")+rails#app().relglob("spec/fixtures/","**/*"),a:A) +endfunction + +function! s:localeList(A,L,P) + return s:completion_filter(rails#app().relglob("config/locales/","**/*"),a:A) +endfunction + +function! s:migrationList(A,L,P) + if a:A =~ '^\d' + let migrations = rails#app().relglob("db/migrate/",a:A."[0-9_]*",".rb") + return map(migrations,'matchstr(v:val,"^[0-9]*")') + else + let migrations = rails#app().relglob("db/migrate/","[0-9]*[0-9]_*",".rb") + call map(migrations,'s:sub(v:val,"^[0-9]*_","")') + return s:autocamelize(migrations,a:A) + endif +endfunction + +function! s:unittestList(A,L,P) + let found = [] + if rails#app().has('test') + let found += rails#app().relglob("test/unit/","**/*","_test.rb") + endif + if rails#app().has('spec') + let found += rails#app().relglob("spec/models/","**/*","_spec.rb") + endif + return s:autocamelize(found,a:A) +endfunction + +function! s:functionaltestList(A,L,P) + let found = [] + if rails#app().has('test') + let found += rails#app().relglob("test/functional/","**/*","_test.rb") + endif + if rails#app().has('spec') + let found += rails#app().relglob("spec/controllers/","**/*","_spec.rb") + let found += rails#app().relglob("spec/mailers/","**/*","_spec.rb") + endif + return s:autocamelize(found,a:A) +endfunction + +function! s:integrationtestList(A,L,P) + if a:A =~# '^\u' + return s:autocamelize(rails#app().relglob("test/integration/","**/*","_test.rb"),a:A) + endif + let found = [] + if rails#app().has('test') + let found += rails#app().relglob("test/integration/","**/*","_test.rb") + endif + if rails#app().has('spec') + let found += rails#app().relglob("spec/requests/","**/*","_spec.rb") + let found += rails#app().relglob("spec/integration/","**/*","_spec.rb") + endif + if rails#app().has('cucumber') + let found += rails#app().relglob("features/","**/*",".feature") + endif + return s:completion_filter(found,a:A) +endfunction + +function! s:specList(A,L,P) + return s:completion_filter(rails#app().relglob("spec/","**/*","_spec.rb"),a:A) +endfunction + +function! s:pluginList(A,L,P) + if a:A =~ '/' + return s:completion_filter(rails#app().relglob('vendor/plugins/',matchstr(a:A,'.\{-\}/').'**/*'),a:A) + else + return s:completion_filter(rails#app().relglob('vendor/plugins/',"*","/init.rb"),a:A) + endif +endfunction + +" Task files, not actual rake tasks +function! s:taskList(A,L,P) + let all = rails#app().relglob("lib/tasks/","**/*",".rake") + if RailsFilePath() =~ '\','".name."',\"".prefix."\",".string(suffix).",".string(filter).",".string(default).",)" + let cmd = strpart(cmds,0,1) + let cmds = strpart(cmds,1) + endwhile +endfunction + +function! s:CommandList(A,L,P) + let cmd = matchstr(a:L,'\CR[A-Z]\=\w\+') + exe cmd." &" + let lp = s:last_prefix . "\n" + let res = [] + while lp != "" + let p = matchstr(lp,'.\{-\}\ze\n') + let lp = s:sub(lp,'.{-}\n','') + let res += rails#app().relglob(p,s:last_filter,s:last_suffix) + endwhile + if s:last_camelize + return s:autocamelize(res,a:A) + else + return s:completion_filter(res,a:A) + endif +endfunction + +function! s:CommandEdit(cmd,name,prefix,suffix,filter,default,...) + if a:0 && a:1 == "&" + let s:last_prefix = a:prefix + let s:last_suffix = a:suffix + let s:last_filter = a:filter + let s:last_camelize = (a:suffix =~# '\.rb$') + else + if a:default == "both()" + if s:model() != "" + let default = s:model() + else + let default = s:controller() + endif + elseif a:default == "model()" + let default = s:model(1) + elseif a:default == "controller()" + let default = s:controller(1) + else + let default = a:default + endif + call s:EditSimpleRb(a:cmd,a:name,a:0 ? a:1 : default,a:prefix,a:suffix) + endif +endfunction + +function! s:EditSimpleRb(cmd,name,target,prefix,suffix,...) + let cmd = s:findcmdfor(a:cmd) + if a:target == "" + " Good idea to emulate error numbers like this? + return s:error("E471: Argument required") + endif + let f = a:0 ? a:target : rails#underscore(a:target) + let jump = matchstr(f,'[#!].*\|:\d*\%(:in\)\=$') + let f = s:sub(f,'[#!].*|:\d*%(:in)=$','') + if jump =~ '^!' + let cmd = s:editcmdfor(cmd) + endif + if f == '.' + let f = s:sub(f,'\.$','') + else + let f .= a:suffix.jump + endif + let f = s:gsub(a:prefix,'\n',f.'\n').f + return s:findedit(cmd,f) +endfunction + +function! s:app_migration(file) dict + let arg = a:file + if arg =~ '^0$\|^0\=[#:]' + let suffix = s:sub(arg,'^0*','') + if self.has_file('db/schema.rb') + return 'db/schema.rb'.suffix + elseif self.has_file('db/'.s:environment().'_structure.sql') + return 'db/'.s:environment().'_structure.sql'.suffix + else + return 'db/schema.rb'.suffix + endif + elseif arg =~ '^\d$' + let glob = '00'.arg.'_*.rb' + elseif arg =~ '^\d\d$' + let glob = '0'.arg.'_*.rb' + elseif arg =~ '^\d\d\d$' + let glob = ''.arg.'_*.rb' + elseif arg == '' + let glob = '*.rb' + else + let glob = '*'.rails#underscore(arg).'*rb' + endif + let files = split(glob(self.path('db/migrate/').glob),"\n") + if arg == '' + return get(files,-1,'') + endif + call map(files,'strpart(v:val,1+strlen(self.path()))') + let keep = get(files,0,'') + if glob =~# '^\*.*\*rb' + let pattern = glob[1:-4] + call filter(files,'v:val =~# ''db/migrate/\d\+_''.pattern.''\.rb''') + let keep = get(files,0,keep) + endif + return keep +endfunction + +call s:add_methods('app', ['migration']) + +function! s:migrationEdit(cmd,...) + let cmd = s:findcmdfor(a:cmd) + let arg = a:0 ? a:1 : '' + let migr = arg == "." ? "db/migrate" : rails#app().migration(arg) + if migr != '' + call s:findedit(cmd,migr) + else + return s:error("Migration not found".(arg=='' ? '' : ': '.arg)) + endif +endfunction + +function! s:fixturesEdit(cmd,...) + if a:0 + let c = rails#underscore(a:1) + else + let c = rails#pluralize(s:model(1)) + endif + if c == "" + return s:error("E471: Argument required") + endif + let e = fnamemodify(c,':e') + let e = e == '' ? e : '.'.e + let c = fnamemodify(c,':r') + let file = get(rails#app().test_suites(),0,'test').'/fixtures/'.c.e + if file =~ '\.\w\+$' && rails#app().find_file(c.e,["test/fixtures","spec/fixtures"]) ==# '' + call s:edit(a:cmd,file) + else + call s:findedit(a:cmd,rails#app().find_file(c.e,["test/fixtures","spec/fixtures"],[".yml",".csv"],file)) + endif +endfunction + +function! s:localeEdit(cmd,...) + let c = a:0 ? a:1 : rails#app().default_locale() + if c =~# '\.' + call s:edit(a:cmd,rails#app().find_file(c,'config/locales',[],'config/locales/'.c)) + else + call s:findedit(a:cmd,rails#app().find_file(c,'config/locales',['.yml','.rb'],'config/locales/'.c)) + endif +endfunction + +function! s:metalEdit(cmd,...) + if a:0 + call s:EditSimpleRb(a:cmd,"metal",a:1,"app/metal/",".rb") + else + call s:EditSimpleRb(a:cmd,"metal",'config/boot',"",".rb") + endif +endfunction + +function! s:modelEdit(cmd,...) + call s:EditSimpleRb(a:cmd,"model",a:0? a:1 : s:model(1),"app/models/",".rb") +endfunction + +function! s:observerEdit(cmd,...) + call s:EditSimpleRb(a:cmd,"observer",a:0? a:1 : s:model(1),"app/models/","_observer.rb") +endfunction + +function! s:viewEdit(cmd,...) + if a:0 && a:1 =~ '^[^!#:]' + let view = matchstr(a:1,'[^!#:]*') + elseif rails#buffer().type_name('controller','mailer') + let view = s:lastmethod(line('.')) + else + let view = '' + endif + if view == '' + return s:error("No view name given") + elseif view == '.' + return s:edit(a:cmd,'app/views') + elseif view !~ '/' && s:controller(1) != '' + let view = s:controller(1) . '/' . view + endif + if view !~ '/' + return s:error("Cannot find view without controller") + endif + let file = "app/views/".view + let found = s:findview(view) + if found != '' + let dir = fnamemodify(rails#app().path(found),':h') + if !isdirectory(dir) + if a:0 && a:1 =~ '!' + call mkdir(dir,'p') + else + return s:error('No such directory') + endif + endif + call s:edit(a:cmd,found) + elseif file =~ '\.\w\+$' + call s:findedit(a:cmd,file) + else + let format = s:format(rails#buffer().type_name('mailer') ? 'text' : 'html') + if glob(rails#app().path(file.'.'.format).'.*[^~]') != '' + let file .= '.' . format + endif + call s:findedit(a:cmd,file) + endif +endfunction + +function! s:findview(name) + let self = rails#buffer() + let name = a:name + let pre = 'app/views/' + if name !~# '/' + let controller = self.controller_name(1) + if controller != '' + let name = controller.'/'.name + endif + endif + if name =~# '\.\w\+\.\w\+$' || name =~# '\.'.s:viewspattern().'$' + return pre.name + else + for format in ['.'.s:format('html'), ''] + for type in s:view_types + if self.app().has_file(pre.name.format.'.'.type) + return pre.name.format.'.'.type + endif + endfor + endfor + endif + return '' +endfunction + +function! s:findlayout(name) + return s:findview("layouts/".(a:name == '' ? 'application' : a:name)) +endfunction + +function! s:layoutEdit(cmd,...) + if a:0 + return s:viewEdit(a:cmd,"layouts/".a:1) + endif + let file = s:findlayout(s:controller(1)) + if file == "" + let file = s:findlayout("application") + endif + if file == "" + let file = "app/views/layouts/application.html.erb" + endif + call s:edit(a:cmd,s:sub(file,'^/','')) +endfunction + +function! s:controllerEdit(cmd,...) + let suffix = '.rb' + if a:0 == 0 + let controller = s:controller(1) + if rails#buffer().type_name() =~# '^view\%(-layout\|-partial\)\@!' + let suffix .= '#'.expand('%:t:r') + endif + else + let controller = a:1 + endif + if rails#app().has_file("app/controllers/".controller."_controller.rb") || !rails#app().has_file("app/controllers/".controller.".rb") + let suffix = "_controller".suffix + endif + return s:EditSimpleRb(a:cmd,"controller",controller,"app/controllers/",suffix) +endfunction + +function! s:mailerEdit(cmd,...) + return s:EditSimpleRb(a:cmd,"mailer",a:0? a:1 : s:controller(1),"app/mailers/\napp/models/",".rb") +endfunction + +function! s:helperEdit(cmd,...) + return s:EditSimpleRb(a:cmd,"helper",a:0? a:1 : s:controller(1),"app/helpers/","_helper.rb") +endfunction + +function! s:stylesheetEdit(cmd,...) + let name = a:0 ? a:1 : s:controller(1) + if rails#app().has('sass') && rails#app().has_file('public/stylesheets/sass/'.name.'.sass') + return s:EditSimpleRb(a:cmd,"stylesheet",name,"public/stylesheets/sass/",".sass",1) + elseif rails#app().has('sass') && rails#app().has_file('public/stylesheets/sass/'.name.'.scss') + return s:EditSimpleRb(a:cmd,"stylesheet",name,"public/stylesheets/sass/",".scss",1) + elseif rails#app().has('lesscss') && rails#app().has_file('app/stylesheets/'.name.'.less') + return s:EditSimpleRb(a:cmd,"stylesheet",name,"app/stylesheets/",".less",1) + else + let types = rails#app().relglob('app/assets/stylesheets/'.name,'.*','') + if !empty(types) + return s:EditSimpleRb(a:cmd,'stylesheet',name,'app/assets/stylesheets/',types[0],1) + else + return s:EditSimpleRb(a:cmd,'stylesheet',name,'public/stylesheets/','.css',1) + endif + endif +endfunction + +function! s:javascriptEdit(cmd,...) + let name = a:0 ? a:1 : s:controller(1) + if rails#app().has('coffee') && rails#app().has_file('app/scripts/'.name.'.coffee') + return s:EditSimpleRb(a:cmd,'javascript',name,'app/scripts/','.coffee',1) + elseif rails#app().has('coffee') && rails#app().has_file('app/scripts/'.name.'.js') + return s:EditSimpleRb(a:cmd,'javascript',name,'app/scripts/','.js',1) + else + let types = rails#app().relglob('app/assets/javascripts/'.name,'.*','') + if !empty(types) + return s:EditSimpleRb(a:cmd,'javascript',name,'app/assets/javascripts/',types[0],1) + else + return s:EditSimpleRb(a:cmd,'javascript',name,'public/javascripts/','.js',1) + endif + endif +endfunction + +function! s:unittestEdit(cmd,...) + let f = rails#underscore(a:0 ? matchstr(a:1,'[^!#:]*') : s:model(1)) + let jump = a:0 ? matchstr(a:1,'[!#:].*') : '' + if jump =~ '!' + let cmd = s:editcmdfor(a:cmd) + else + let cmd = s:findcmdfor(a:cmd) + endif + let mapping = {'test': ['test/unit/','_test.rb'], 'spec': ['spec/models/','_spec.rb']} + let tests = map(filter(rails#app().test_suites(),'has_key(mapping,v:val)'),'get(mapping,v:val)') + if empty(tests) + let tests = [mapping['test']] + endif + for [prefix, suffix] in tests + if !a:0 && rails#buffer().type_name('model-aro') && f != '' && f !~# '_observer$' + if rails#app().has_file(prefix.f.'_observer'.suffix) + return s:findedit(cmd,prefix.f.'_observer'.suffix.jump) + endif + endif + endfor + for [prefix, suffix] in tests + if rails#app().has_file(prefix.f.suffix) + return s:findedit(cmd,prefix.f.suffix.jump) + endif + endfor + return s:EditSimpleRb(a:cmd,"unittest",f.jump,tests[0][0],tests[0][1],1) +endfunction + +function! s:functionaltestEdit(cmd,...) + let f = rails#underscore(a:0 ? matchstr(a:1,'[^!#:]*') : s:controller(1)) + let jump = a:0 ? matchstr(a:1,'[!#:].*') : '' + if jump =~ '!' + let cmd = s:editcmdfor(a:cmd) + else + let cmd = s:findcmdfor(a:cmd) + endif + let mapping = {'test': [['test/functional/'],['_test.rb','_controller_test.rb']], 'spec': [['spec/controllers/','spec/mailers/'],['_spec.rb','_controller_spec.rb']]} + let tests = map(filter(rails#app().test_suites(),'has_key(mapping,v:val)'),'get(mapping,v:val)') + if empty(tests) + let tests = [mapping[tests]] + endif + for [prefixes, suffixes] in tests + for prefix in prefixes + for suffix in suffixes + if rails#app().has_file(prefix.f.suffix) + return s:findedit(cmd,prefix.f.suffix.jump) + endif + endfor + endfor + endfor + return s:EditSimpleRb(a:cmd,"functionaltest",f.jump,tests[0][0][0],tests[0][1][0],1) +endfunction + +function! s:integrationtestEdit(cmd,...) + if !a:0 + return s:EditSimpleRb(a:cmd,"integrationtest","test/test_helper\nfeatures/support/env\nspec/spec_helper","",".rb") + endif + let f = rails#underscore(matchstr(a:1,'[^!#:]*')) + let jump = matchstr(a:1,'[!#:].*') + if jump =~ '!' + let cmd = s:editcmdfor(a:cmd) + else + let cmd = s:findcmdfor(a:cmd) + endif + let tests = [['test/integration/','_test.rb'], [ 'spec/requests/','_spec.rb'], [ 'spec/integration/','_spec.rb'], [ 'features/','.feature']] + call filter(tests, 'isdirectory(rails#app().path(v:val[0]))') + if empty(tests) + let tests = [['test/integration/','_test.rb']] + endif + for [prefix, suffix] in tests + if rails#app().has_file(prefix.f.suffix) + return s:findedit(cmd,prefix.f.suffix.jump) + elseif rails#app().has_file(prefix.rails#underscore(f).suffix) + return s:findedit(cmd,prefix.rails#underscore(f).suffix.jump) + endif + endfor + return s:EditSimpleRb(a:cmd,"integrationtest",f.jump,tests[0][0],tests[0][1],1) +endfunction + +function! s:specEdit(cmd,...) + if a:0 + return s:EditSimpleRb(a:cmd,"spec",a:1,"spec/","_spec.rb") + else + call s:EditSimpleRb(a:cmd,"spec","spec_helper","spec/",".rb") + endif +endfunction + +function! s:pluginEdit(cmd,...) + let cmd = s:findcmdfor(a:cmd) + let plugin = "" + let extra = "" + if RailsFilePath() =~ '\','split') + let cmd = s:sub(cmd,'find>','edit') + return cmd +endfunction + +function! s:try(cmd) abort + if !exists(":try") + " I've seen at least one weird setup without :try + exe a:cmd + else + try + exe a:cmd + catch + call s:error(s:sub(v:exception,'^.{-}:\zeE','')) + return 0 + endtry + endif + return 1 +endfunction + +function! s:findedit(cmd,files,...) abort + let cmd = s:findcmdfor(a:cmd) + let files = type(a:files) == type([]) ? copy(a:files) : split(a:files,"\n") + if len(files) == 1 + let file = files[0] + else + let file = get(filter(copy(files),'rails#app().has_file(s:sub(v:val,"#.*|:\\d*$",""))'),0,get(files,0,'')) + endif + if file =~ '[#!]\|:\d*\%(:in\)\=$' + let djump = matchstr(file,'!.*\|#\zs.*\|:\zs\d*\ze\%(:in\)\=$') + let file = s:sub(file,'[#!].*|:\d*%(:in)=$','') + else + let djump = '' + endif + if file == '' + let testcmd = "edit" + elseif isdirectory(rails#app().path(file)) + let arg = file == "." ? rails#app().path() : rails#app().path(file) + let testcmd = s:editcmdfor(cmd).' '.(a:0 ? a:1 . ' ' : '').s:escarg(arg) + exe testcmd + return + elseif rails#app().path() =~ '://' || cmd =~ 'edit' || cmd =~ 'split' + if file !~ '^/' && file !~ '^\w:' && file !~ '://' + let file = s:escarg(rails#app().path(file)) + endif + let testcmd = s:editcmdfor(cmd).' '.(a:0 ? a:1 . ' ' : '').file + else + let testcmd = cmd.' '.(a:0 ? a:1 . ' ' : '').file + endif + if s:try(testcmd) + call s:djump(djump) + endif +endfunction + +function! s:edit(cmd,file,...) + let cmd = s:editcmdfor(a:cmd) + let cmd .= ' '.(a:0 ? a:1 . ' ' : '') + let file = a:file + if file !~ '^/' && file !~ '^\w:' && file !~ '://' + exe cmd."`=fnamemodify(rails#app().path(file),':.')`" + else + exe cmd.file + endif +endfunction + +function! s:Alternate(cmd,line1,line2,count,...) + if a:0 + if a:count && a:cmd !~# 'D' + return call('s:Find',[1,a:line1.a:cmd]+a:000) + elseif a:count + return call('s:Edit',[1,a:line1.a:cmd]+a:000) + else + return call('s:Edit',[1,a:cmd]+a:000) + endif + else + let file = s:getopt(a:count ? 'related' : 'alternate', 'bl') + if file == '' + let file = rails#buffer().related(a:count) + endif + if file != '' + call s:findedit(a:cmd,file) + else + call s:warn("No alternate file is defined") + endif + endif +endfunction + +function! s:Related(cmd,line1,line2,count,...) + if a:count == 0 && a:0 == 0 + return s:Alternate(a:cmd,a:line1,a:line1,a:line1) + else + return call('s:Alternate',[a:cmd,a:line1,a:line2,a:count]+a:000) + endif +endfunction + +function! s:Complete_related(A,L,P) + if a:L =~# '^[[:alpha:]]' + return s:Complete_edit(a:A,a:L,a:P) + else + return s:Complete_find(a:A,a:L,a:P) + endif +endfunction + +function! s:readable_related(...) dict abort + let f = self.name() + if a:0 && a:1 + let lastmethod = self.last_method(a:1) + if self.type_name('controller','mailer') && lastmethod != "" + let root = s:sub(s:sub(s:sub(f,'/application%(_controller)=\.rb$','/shared_controller.rb'),'/%(controllers|models|mailers)/','/views/'),'%(_controller)=\.rb$','/'.lastmethod) + let format = self.last_format(a:1) + if format == '' + let format = self.type_name('mailer') ? 'text' : 'html' + endif + if glob(self.app().path().'/'.root.'.'.format.'.*[^~]') != '' + return root . '.' . format + else + return root + endif + elseif f =~ '\ me') + let migration = "db/migrate/".get(candidates,0,migrations[0]).".rb" + endif + return migration . (exists('l:lastmethod') && lastmethod != '' ? '#'.lastmethod : '') + elseif f =~ '\??').'/layout.'.fnamemodify(f,':e') + else + let dest = f + endif + return s:sub(s:sub(dest,' 1 + return s:error("Incorrect number of arguments") + endif + if a:1 =~ '[^a-z0-9_/.]' + return s:error("Invalid partial name") + endif + let rails_root = rails#app().path() + let ext = expand("%:e") + let file = s:sub(a:1,'%(/|^)\zs_\ze[^/]*$','') + let first = a:firstline + let last = a:lastline + let range = first.",".last + if rails#buffer().type_name('view-layout') + if RailsFilePath() =~ '\' + let curdir = 'app/views/shared' + if file !~ '/' + let file = "shared/" .file + endif + else + let curdir = s:sub(RailsFilePath(),'.*]+)'.erub2.'\s*$' + let collection = s:sub(getline(first-1),'^'.fspaces.erub1.'for\s+(\k+)\s+in\s+([^ >]+)'.erub2.'\s*$','\1>\2') + elseif getline(first-1) =~ '\v^'.fspaces.erub1.'([^ %>]+)\.each\s+do\s+\|\s*(\k+)\s*\|'.erub2.'\s*$' + let collection = s:sub(getline(first-1),'^'.fspaces.erub1.'([^ %>]+)\.each\s+do\s+\|\s*(\k+)\s*\|'.erub2.'\s*$','\2>\1') + endif + if collection != '' + let var = matchstr(collection,'^\k\+') + let collection = s:sub(collection,'^\k+\>','') + let first -= 1 + let last += 1 + endif + else + let fspaces = spaces + endif + let renderstr = "render :partial => '".fnamemodify(file,":r:r")."'" + if collection != "" + let renderstr .= ", :collection => ".collection + elseif "@".name != var + let renderstr .= ", :object => ".var + endif + if ext =~? '^\%(rhtml\|erb\|dryml\)$' + let renderstr = "<%= ".renderstr." %>" + elseif ext == "rxml" || ext == "builder" + let renderstr = "xml << ".s:sub(renderstr,"render ","render(").")" + elseif ext == "rjs" + let renderstr = "page << ".s:sub(renderstr,"render ","render(").")" + elseif ext == "haml" + let renderstr = "= ".renderstr + elseif ext == "mn" + let renderstr = "_".renderstr + endif + let buf = @@ + silent exe range."yank" + let partial = @@ + let @@ = buf + let old_ai = &ai + try + let &ai = 0 + silent exe "norm! :".first.",".last."change\".fspaces.renderstr."\.\" + finally + let &ai = old_ai + endtry + if renderstr =~ '<%' + norm ^6w + else + norm ^5w + endif + let ft = &ft + let shortout = fnamemodify(out,':.') + silent split `=shortout` + silent %delete + let &ft = ft + let @@ = partial + silent put + 0delete + let @@ = buf + if spaces != "" + silent! exe '%substitute/^'.spaces.'//' + endif + silent! exe '%substitute?\%(\w\|[@:"'."'".'-]\)\@?'.name.'?g' + 1 +endfunction + +" }}}1 +" Migration Inversion {{{1 + +function! s:mkeep(str) + " Things to keep (like comments) from a migration statement + return matchstr(a:str,' #[^{].*') +endfunction + +function! s:mextargs(str,num) + if a:str =~ '^\s*\w\+\s*(' + return s:sub(matchstr(a:str,'^\s*\w\+\s*\zs(\%([^,)]\+[,)]\)\{,'.a:num.'\}'),',$',')') + else + return s:sub(s:sub(matchstr(a:str,'\w\+\>\zs\s*\%([^,){ ]*[, ]*\)\{,'.a:num.'\}'),'[, ]*$',''),'^\s+',' ') + endif +endfunction + +function! s:migspc(line) + return matchstr(a:line,'^\s*') +endfunction + +function! s:invertrange(beg,end) + let str = "" + let lnum = a:beg + while lnum <= a:end + let line = getline(lnum) + let add = "" + if line == '' + let add = ' ' + elseif line =~ '^\s*\(#[^{].*\)\=$' + let add = line + elseif line =~ '\' + let add = s:migspc(line)."drop_table".s:mextargs(line,1).s:mkeep(line) + let lnum = s:endof(lnum) + elseif line =~ '\' + let add = s:sub(line,'\s*\(=\s*([^,){ ]*).*','create_table \1 do |t|'."\n".matchstr(line,'^\s*').'end').s:mkeep(line) + elseif line =~ '\' + let add = s:migspc(line).'remove_column'.s:mextargs(line,2).s:mkeep(line) + elseif line =~ '\' + let add = s:sub(line,'','add_column') + elseif line =~ '\' + let add = s:migspc(line).'remove_index'.s:mextargs(line,1) + let mat = matchstr(line,':name\s*=>\s*\zs[^ ,)]*') + if mat != '' + let add = s:sub(add,'\)=$',', :name => '.mat.'&') + else + let mat = matchstr(line,'\[^,]*,\s*\zs\%(\[[^]]*\]\|[:"'."'".']\w*["'."'".']\=\)') + if mat != '' + let add = s:sub(add,'\)=$',', :column => '.mat.'&') + endif + endif + let add .= s:mkeep(line) + elseif line =~ '\' + let add = s:sub(s:sub(line,'\s*','') + elseif line =~ '\' + let add = s:sub(line,'' + let add = s:migspc(line).'change_column'.s:mextargs(line,2).s:mkeep(line) + elseif line =~ '\' + let add = s:migspc(line).'change_column_default'.s:mextargs(line,2).s:mkeep(line) + elseif line =~ '\.update_all(\(["'."'".']\).*\1)$' || line =~ '\.update_all \(["'."'".']\).*\1$' + " .update_all('a = b') => .update_all('b = a') + let pre = matchstr(line,'^.*\.update_all[( ][}'."'".'"]') + let post = matchstr(line,'["'."'".'])\=$') + let mat = strpart(line,strlen(pre),strlen(line)-strlen(pre)-strlen(post)) + let mat = s:gsub(','.mat.',','%(,\s*)@<=([^ ,=]{-})(\s*\=\s*)([^,=]{-})%(\s*,)@=','\3\2\1') + let add = pre.s:sub(s:sub(mat,'^,',''),',$','').post + elseif line =~ '^s\*\%(if\|unless\|while\|until\|for\)\>' + let lnum = s:endof(lnum) + endif + if lnum == 0 + return -1 + endif + if add == "" + let add = s:sub(line,'^\s*\zs.*','raise ActiveRecord::IrreversibleMigration') + elseif add == " " + let add = "" + endif + let str = add."\n".str + let lnum += 1 + endwhile + let str = s:gsub(str,'(\s*raise ActiveRecord::IrreversibleMigration\n)+','\1') + return str +endfunction + +function! s:Invert(bang) + let err = "Could not parse method" + let src = "up" + let dst = "down" + let beg = search('\%('.&l:define.'\).*'.src.'\>',"w") + let end = s:endof(beg) + if beg + 1 == end + let src = "down" + let dst = "up" + let beg = search('\%('.&l:define.'\).*'.src.'\>',"w") + let end = s:endof(beg) + endif + if !beg || !end + return s:error(err) + endif + let str = s:invertrange(beg+1,end-1) + if str == -1 + return s:error(err) + endif + let beg = search('\%('.&l:define.'\).*'.dst.'\>',"w") + let end = s:endof(beg) + if !beg || !end + return s:error(err) + endif + if foldclosed(beg) > 0 + exe beg."foldopen!" + endif + if beg + 1 < end + exe (beg+1).",".(end-1)."delete _" + endif + if str != '' + exe beg.'put =str' + exe 1+beg + endif +endfunction + +" }}}1 +" Cache {{{1 + +let s:cache_prototype = {'dict': {}} + +function! s:cache_clear(...) dict + if a:0 == 0 + let self.dict = {} + elseif has_key(self,'dict') && has_key(self.dict,a:1) + unlet! self.dict[a:1] + endif +endfunction + +function! rails#cache_clear(...) + if exists('b:rails_root') + return call(rails#app().cache.clear,a:000,rails#app().cache) + endif +endfunction + +function! s:cache_get(...) dict + if a:0 == 1 + return self.dict[a:1] + else + return self.dict + endif +endfunction + +function! s:cache_has(key) dict + return has_key(self.dict,a:key) +endfunction + +function! s:cache_needs(key) dict + return !has_key(self.dict,a:key) +endfunction + +function! s:cache_set(key,value) dict + let self.dict[a:key] = a:value +endfunction + +call s:add_methods('cache', ['clear','needs','has','get','set']) + +let s:app_prototype.cache = s:cache_prototype + +" }}}1 +" Syntax {{{1 + +function! s:resetomnicomplete() + if exists("+completefunc") && &completefunc == 'syntaxcomplete#Complete' + if exists("g:loaded_syntax_completion") + " Ugly but necessary, until we have our own completion + unlet g:loaded_syntax_completion + silent! delfunction syntaxcomplete#Complete + endif + endif +endfunction + +function! s:helpermethods() + return "" + \."action_name atom_feed audio_path audio_tag auto_discovery_link_tag " + \."button_tag button_to button_to_function " + \."cache capture cdata_section check_box check_box_tag collection_select concat content_for content_tag content_tag_for controller controller_name controller_path convert_to_model cookies csrf_meta_tag csrf_meta_tags current_cycle cycle " + \."date_select datetime_select debug distance_of_time_in_words distance_of_time_in_words_to_now div_for dom_class dom_id " + \."email_field email_field_tag escape_javascript escape_once excerpt " + \."favicon_link_tag field_set_tag fields_for file_field file_field_tag flash form_for form_tag " + \."grouped_collection_select grouped_options_for_select " + \."headers hidden_field hidden_field_tag highlight " + \."image_alt image_path image_submit_tag image_tag " + \."j javascript_cdata_section javascript_include_tag javascript_path javascript_tag " + \."l label label_tag link_to link_to_function link_to_if link_to_unless link_to_unless_current localize logger " + \."mail_to " + \."number_field number_field_tag number_to_currency number_to_human number_to_human_size number_to_percentage number_to_phone number_with_delimiter number_with_precision " + \."option_groups_from_collection_for_select options_for_select options_from_collection_for_select " + \."params password_field password_field_tag path_to_audio path_to_image path_to_javascript path_to_stylesheet path_to_video phone_field phone_field_tag pluralize provide " + \."radio_button radio_button_tag range_field range_field_tag raw render request request_forgery_protection_token reset_cycle response " + \."safe_concat safe_join sanitize sanitize_css search_field search_field_tag select select_date select_datetime select_day select_hour select_minute select_month select_second select_tag select_time select_year session simple_format strip_links strip_tags stylesheet_link_tag stylesheet_path submit_tag " + \."t tag telephone_field telephone_field_tag text_area text_area_tag text_field text_field_tag time_ago_in_words time_select time_tag time_zone_options_for_select time_zone_select translate truncate " + \."url_field url_field_tag url_for url_options " + \."video_path video_tag " + \."word_wrap" +endfunction + +function! s:app_user_classes() dict + if self.cache.needs("user_classes") + let controllers = self.relglob("app/controllers/","**/*",".rb") + call map(controllers,'v:val == "application" ? v:val."_controller" : v:val') + let classes = + \ self.relglob("app/models/","**/*",".rb") + + \ controllers + + \ self.relglob("app/helpers/","**/*",".rb") + + \ self.relglob("lib/","**/*",".rb") + call map(classes,'rails#camelize(v:val)') + call self.cache.set("user_classes",classes) + endif + return self.cache.get('user_classes') +endfunction + +function! s:app_user_assertions() dict + if self.cache.needs("user_assertions") + if self.has_file("test/test_helper.rb") + let assertions = map(filter(s:readfile(self.path("test/test_helper.rb")),'v:val =~ "^ def assert_"'),'matchstr(v:val,"^ def \\zsassert_\\w\\+")') + else + let assertions = [] + endif + call self.cache.set("user_assertions",assertions) + endif + return self.cache.get('user_assertions') +endfunction + +call s:add_methods('app', ['user_classes','user_assertions']) + +function! s:BufSyntax() + if (!exists("g:rails_syntax") || g:rails_syntax) + let buffer = rails#buffer() + let s:javascript_functions = "$ $$ $A $F $H $R $w jQuery" + let classes = s:gsub(join(rails#app().user_classes(),' '),'::',' ') + if &syntax == 'ruby' + if classes != '' + exe "syn keyword rubyRailsUserClass ".classes." containedin=rubyClassDeclaration,rubyModuleDeclaration,rubyClass,rubyModule" + endif + if buffer.type_name() == '' + syn keyword rubyRailsMethod params request response session headers cookies flash + endif + if buffer.type_name('api') + syn keyword rubyRailsAPIMethod api_method inflect_names + endif + if buffer.type_name() ==# 'model' || buffer.type_name('model-arb') + syn keyword rubyRailsARMethod default_scope named_scope scope serialize + syn keyword rubyRailsARAssociationMethod belongs_to has_one has_many has_and_belongs_to_many composed_of accepts_nested_attributes_for + syn keyword rubyRailsARCallbackMethod before_create before_destroy before_save before_update before_validation before_validation_on_create before_validation_on_update + syn keyword rubyRailsARCallbackMethod after_create after_destroy after_save after_update after_validation after_validation_on_create after_validation_on_update + syn keyword rubyRailsARCallbackMethod around_create around_destroy around_save around_update + syn keyword rubyRailsARCallbackMethod after_commit after_find after_initialize after_rollback after_touch + syn keyword rubyRailsARClassMethod attr_accessible attr_protected attr_readonly establish_connection set_inheritance_column set_locking_column set_primary_key set_sequence_name set_table_name + syn keyword rubyRailsARValidationMethod validate validates validate_on_create validate_on_update validates_acceptance_of validates_associated validates_confirmation_of validates_each validates_exclusion_of validates_format_of validates_inclusion_of validates_length_of validates_numericality_of validates_presence_of validates_size_of validates_uniqueness_of + syn keyword rubyRailsMethod logger + endif + if buffer.type_name('model-aro') + syn keyword rubyRailsARMethod observe + endif + if buffer.type_name('mailer') + syn keyword rubyRailsMethod logger url_for polymorphic_path polymorphic_url + syn keyword rubyRailsRenderMethod mail render + syn keyword rubyRailsControllerMethod attachments default helper helper_attr helper_method + endif + if buffer.type_name('helper','view') + syn keyword rubyRailsViewMethod polymorphic_path polymorphic_url + exe "syn keyword rubyRailsHelperMethod ".s:gsub(s:helpermethods(),'<%(content_for|select)\s+','') + syn match rubyRailsHelperMethod '\\%(\s*{\|\s*do\>\|\s*(\=\s*&\)\@!' + syn match rubyRailsHelperMethod '\<\%(content_for?\=\|current_page?\)' + syn match rubyRailsViewMethod '\.\@' + if buffer.type_name('view-partial') + syn keyword rubyRailsMethod local_assigns + endif + elseif buffer.type_name('controller') + syn keyword rubyRailsMethod params request response session headers cookies flash + syn keyword rubyRailsRenderMethod render + syn keyword rubyRailsMethod logger polymorphic_path polymorphic_url + syn keyword rubyRailsControllerMethod helper helper_attr helper_method filter layout url_for serialize exempt_from_layout filter_parameter_logging hide_action cache_sweeper protect_from_forgery caches_page cache_page caches_action expire_page expire_action rescue_from + syn keyword rubyRailsRenderMethod head redirect_to render_to_string respond_with + syn match rubyRailsRenderMethod '\?\@!' + syn keyword rubyRailsFilterMethod before_filter append_before_filter prepend_before_filter after_filter append_after_filter prepend_after_filter around_filter append_around_filter prepend_around_filter skip_before_filter skip_after_filter + syn keyword rubyRailsFilterMethod verify + endif + if buffer.type_name('db-migration','db-schema') + syn keyword rubyRailsMigrationMethod create_table change_table drop_table rename_table add_column rename_column change_column change_column_default remove_column add_index remove_index rename_index execute + endif + if buffer.type_name('test') + if !empty(rails#app().user_assertions()) + exe "syn keyword rubyRailsUserMethod ".join(rails#app().user_assertions()) + endif + syn keyword rubyRailsTestMethod add_assertion assert assert_block assert_equal assert_in_delta assert_instance_of assert_kind_of assert_match assert_nil assert_no_match assert_not_equal assert_not_nil assert_not_same assert_nothing_raised assert_nothing_thrown assert_operator assert_raise assert_respond_to assert_same assert_send assert_throws assert_recognizes assert_generates assert_routing flunk fixtures fixture_path use_transactional_fixtures use_instantiated_fixtures assert_difference assert_no_difference assert_valid + syn keyword rubyRailsTestMethod test setup teardown + if !buffer.type_name('test-unit') + syn match rubyRailsTestControllerMethod '\.\@' + syn keyword rubyRailsTestControllerMethod get_via_redirect post_via_redirect put_via_redirect delete_via_redirect request_via_redirect + syn keyword rubyRailsTestControllerMethod assert_response assert_redirected_to assert_template assert_recognizes assert_generates assert_routing assert_dom_equal assert_dom_not_equal assert_select assert_select_rjs assert_select_encoded assert_select_email assert_tag assert_no_tag + endif + elseif buffer.type_name('spec') + syn keyword rubyRailsTestMethod describe context it its specify shared_examples_for it_should_behave_like before after around subject fixtures controller_name helper_name + syn match rubyRailsTestMethod '\!\=' + syn keyword rubyRailsTestMethod violated pending expect double mock mock_model stub_model + syn match rubyRailsTestMethod '\.\@!\@!' + if !buffer.type_name('spec-model') + syn match rubyRailsTestControllerMethod '\.\@' + syn keyword rubyRailsTestControllerMethod integrate_views + syn keyword rubyRailsMethod params request response session flash + syn keyword rubyRailsMethod polymorphic_path polymorphic_url + endif + endif + if buffer.type_name('task') + syn match rubyRailsRakeMethod '^\s*\zs\%(task\|file\|namespace\|desc\|before\|after\|on\)\>\%(\s*=\)\@!' + endif + if buffer.type_name('model-awss') + syn keyword rubyRailsMethod member + endif + if buffer.type_name('config-routes') + syn match rubyRailsMethod '\.\zs\%(connect\|named_route\)\>' + syn keyword rubyRailsMethod match get put post delete redirect root resource resources collection member nested scope namespace controller constraints + endif + syn keyword rubyRailsMethod debugger + syn keyword rubyRailsMethod alias_attribute alias_method_chain attr_accessor_with_default attr_internal attr_internal_accessor attr_internal_reader attr_internal_writer delegate mattr_accessor mattr_reader mattr_writer superclass_delegating_accessor superclass_delegating_reader superclass_delegating_writer + syn keyword rubyRailsMethod cattr_accessor cattr_reader cattr_writer class_inheritable_accessor class_inheritable_array class_inheritable_array_writer class_inheritable_hash class_inheritable_hash_writer class_inheritable_option class_inheritable_reader class_inheritable_writer inheritable_attributes read_inheritable_attribute reset_inheritable_attributes write_inheritable_array write_inheritable_attribute write_inheritable_hash + syn keyword rubyRailsInclude require_dependency + + syn region rubyString matchgroup=rubyStringDelimiter start=+\%(:order\s*=>\s*\)\@<="+ skip=+\\\\\|\\"+ end=+"+ contains=@rubyStringSpecial,railsOrderSpecial + syn region rubyString matchgroup=rubyStringDelimiter start=+\%(:order\s*=>\s*\)\@<='+ skip=+\\\\\|\\'+ end=+'+ contains=@rubyStringSpecial,railsOrderSpecial + syn match railsOrderSpecial +\c\<\%(DE\|A\)SC\>+ contained + syn region rubyString matchgroup=rubyStringDelimiter start=+\%(:conditions\s*=>\s*\[\s*\)\@<="+ skip=+\\\\\|\\"+ end=+"+ contains=@rubyStringSpecial,railsConditionsSpecial + syn region rubyString matchgroup=rubyStringDelimiter start=+\%(:conditions\s*=>\s*\[\s*\)\@<='+ skip=+\\\\\|\\'+ end=+'+ contains=@rubyStringSpecial,railsConditionsSpecial + syn match railsConditionsSpecial +?\|:\h\w*+ contained + syn cluster rubyNotTop add=railsOrderSpecial,railsConditionsSpecial + + " XHTML highlighting inside %Q<> + unlet! b:current_syntax + let removenorend = !exists("g:html_no_rendering") + let g:html_no_rendering = 1 + syn include @htmlTop syntax/xhtml.vim + if removenorend + unlet! g:html_no_rendering + endif + let b:current_syntax = "ruby" + " Restore syn sync, as best we can + if !exists("g:ruby_minlines") + let g:ruby_minlines = 50 + endif + syn sync fromstart + exe "syn sync minlines=" . g:ruby_minlines + syn case match + syn region rubyString matchgroup=rubyStringDelimiter start=+%Q\=<+ end=+>+ contains=@htmlTop,@rubyStringSpecial + syn cluster htmlArgCluster add=@rubyStringSpecial + syn cluster htmlPreProc add=@rubyStringSpecial + + elseif &syntax =~# '^eruby\>' || &syntax == 'haml' + syn case match + if classes != '' + exe 'syn keyword '.&syntax.'RailsUserClass '.classes.' contained containedin=@'.&syntax.'RailsRegions' + endif + if &syntax == 'haml' + exe 'syn cluster hamlRailsRegions contains=hamlRubyCodeIncluded,hamlRubyCode,hamlRubyHash,@hamlEmbeddedRuby,rubyInterpolation' + else + exe 'syn cluster erubyRailsRegions contains=erubyOneLiner,erubyBlock,erubyExpression,rubyInterpolation' + endif + exe 'syn keyword '.&syntax.'RailsHelperMethod '.s:gsub(s:helpermethods(),'<%(content_for|select)\s+','').' contained containedin=@'.&syntax.'RailsRegions' + exe 'syn match '.&syntax.'RailsHelperMethod "\\%(\s*{\|\s*do\>\|\s*(\=\s*&\)\@!" contained containedin=@'.&syntax.'RailsRegions' + exe 'syn match '.&syntax.'RailsHelperMethod "\<\%(content_for?\=\|current_page?\)" contained containedin=@'.&syntax.'RailsRegions' + exe 'syn keyword '.&syntax.'RailsMethod debugger polymorphic_path polymorphic_url contained containedin=@'.&syntax.'RailsRegions' + exe 'syn match '.&syntax.'RailsViewMethod "\.\@" contained containedin=@'.&syntax.'RailsRegions' + if buffer.type_name('view-partial') + exe 'syn keyword '.&syntax.'RailsMethod local_assigns contained containedin=@'.&syntax.'RailsRegions' + endif + exe 'syn keyword '.&syntax.'RailsRenderMethod render contained containedin=@'.&syntax.'RailsRegions' + exe 'syn case match' + set isk+=$ + exe 'syn keyword javascriptRailsFunction contained '.s:javascript_functions + exe 'syn cluster htmlJavaScript add=javascriptRailsFunction' + elseif &syntax == "yaml" + syn case match + " Modeled after syntax/eruby.vim + unlet! b:current_syntax + let g:main_syntax = 'eruby' + syn include @rubyTop syntax/ruby.vim + unlet g:main_syntax + syn cluster yamlRailsRegions contains=yamlRailsOneLiner,yamlRailsBlock,yamlRailsExpression + syn region yamlRailsOneLiner matchgroup=yamlRailsDelimiter start="^%%\@!" end="$" contains=@rubyRailsTop containedin=ALLBUT,@yamlRailsRegions,yamlRailsComment keepend oneline + syn region yamlRailsBlock matchgroup=yamlRailsDelimiter start="<%%\@!" end="%>" contains=@rubyTop containedin=ALLBUT,@yamlRailsRegions,yamlRailsComment + syn region yamlRailsExpression matchgroup=yamlRailsDelimiter start="<%=" end="%>" contains=@rubyTop containedin=ALLBUT,@yamlRailsRegions,yamlRailsComment + syn region yamlRailsComment matchgroup=yamlRailsDelimiter start="<%#" end="%>" contains=rubyTodo,@Spell containedin=ALLBUT,@yamlRailsRegions,yamlRailsComment keepend + syn match yamlRailsMethod '\.\@' contained containedin=@yamlRailsRegions + if classes != '' + exe "syn keyword yamlRailsUserClass ".classes." contained containedin=@yamlRailsRegions" + endif + let b:current_syntax = "yaml" + elseif &syntax == "html" + syn case match + set isk+=$ + exe "syn keyword javascriptRailsFunction contained ".s:javascript_functions + syn cluster htmlJavaScript add=javascriptRailsFunction + elseif &syntax == "javascript" || &syntax == "coffee" + " The syntax file included with Vim incorrectly sets syn case ignore. + syn case match + set isk+=$ + exe "syn keyword javascriptRailsFunction ".s:javascript_functions + + endif + endif + call s:HiDefaults() +endfunction + +function! s:HiDefaults() + hi def link rubyRailsAPIMethod rubyRailsMethod + hi def link rubyRailsARAssociationMethod rubyRailsARMethod + hi def link rubyRailsARCallbackMethod rubyRailsARMethod + hi def link rubyRailsARClassMethod rubyRailsARMethod + hi def link rubyRailsARValidationMethod rubyRailsARMethod + hi def link rubyRailsARMethod rubyRailsMethod + hi def link rubyRailsRenderMethod rubyRailsMethod + hi def link rubyRailsHelperMethod rubyRailsMethod + hi def link rubyRailsViewMethod rubyRailsMethod + hi def link rubyRailsMigrationMethod rubyRailsMethod + hi def link rubyRailsControllerMethod rubyRailsMethod + hi def link rubyRailsFilterMethod rubyRailsMethod + hi def link rubyRailsTestControllerMethod rubyRailsTestMethod + hi def link rubyRailsTestMethod rubyRailsMethod + hi def link rubyRailsRakeMethod rubyRailsMethod + hi def link rubyRailsMethod railsMethod + hi def link rubyRailsInclude rubyInclude + hi def link rubyRailsUserClass railsUserClass + hi def link rubyRailsUserMethod railsUserMethod + hi def link erubyRailsHelperMethod erubyRailsMethod + hi def link erubyRailsViewMethod erubyRailsMethod + hi def link erubyRailsRenderMethod erubyRailsMethod + hi def link erubyRailsMethod railsMethod + hi def link erubyRailsUserMethod railsUserMethod + hi def link erubyRailsUserClass railsUserClass + hi def link hamlRailsHelperMethod hamlRailsMethod + hi def link hamlRailsViewMethod hamlRailsMethod + hi def link hamlRailsRenderMethod hamlRailsMethod + hi def link hamlRailsMethod railsMethod + hi def link hamlRailsUserMethod railsUserMethod + hi def link hamlRailsUserClass railsUserClass + hi def link railsUserMethod railsMethod + hi def link yamlRailsDelimiter Delimiter + hi def link yamlRailsMethod railsMethod + hi def link yamlRailsComment Comment + hi def link yamlRailsUserClass railsUserClass + hi def link yamlRailsUserMethod railsUserMethod + hi def link javascriptRailsFunction railsMethod + hi def link railsUserClass railsClass + hi def link railsMethod Function + hi def link railsClass Type + hi def link railsOrderSpecial railsStringSpecial + hi def link railsConditionsSpecial railsStringSpecial + hi def link railsStringSpecial Identifier +endfunction + +function! rails#log_syntax() + if has('conceal') + syn match railslogEscape '\e\[[0-9;]*m' conceal + syn match railslogEscapeMN '\e\[[0-9;]*m' conceal nextgroup=railslogModelNum,railslogEscapeMN skipwhite contained + syn match railslogEscapeSQL '\e\[[0-9;]*m' conceal nextgroup=railslogSQL,railslogEscapeSQL skipwhite contained + else + syn match railslogEscape '\e\[[0-9;]*m' + syn match railslogEscapeMN '\e\[[0-9;]*m' nextgroup=railslogModelNum,railslogEscapeMN skipwhite contained + syn match railslogEscapeSQL '\e\[[0-9;]*m' nextgroup=railslogSQL,railslogEscapeSQL skipwhite contained + endif + syn match railslogRender '\%(^\s*\%(\e\[[0-9;]*m\)\=\)\@<=\%(Processing\|Rendering\|Rendered\|Redirected\|Completed\)\>' + syn match railslogComment '^\s*# .*' + syn match railslogModel '\%(^\s*\%(\e\[[0-9;]*m\)\=\)\@<=\u\%(\w\|:\)* \%(Load\%( Including Associations\| IDs For Limited Eager Loading\)\=\|Columns\|Count\|Create\|Update\|Destroy\|Delete all\)\>' skipwhite nextgroup=railslogModelNum,railslogEscapeMN + syn match railslogModel '\%(^\s*\%(\e\[[0-9;]*m\)\=\)\@<=SQL\>' skipwhite nextgroup=railslogModelNum,railslogEscapeMN + syn region railslogModelNum start='(' end=')' contains=railslogNumber contained skipwhite nextgroup=railslogSQL,railslogEscapeSQL + syn match railslogSQL '\u[^\e]*' contained + " Destroy generates multiline SQL, ugh + syn match railslogSQL '\%(^ \%(\e\[[0-9;]*m\)\=\)\@<=\%(FROM\|WHERE\|ON\|AND\|OR\|ORDER\) .*$' + syn match railslogNumber '\<\d\+\>%' + syn match railslogNumber '[ (]\@<=\<\d\+\.\d\+\>\.\@!' + syn region railslogString start='"' skip='\\"' end='"' oneline contained + syn region railslogHash start='{' end='}' oneline contains=railslogHash,railslogString + syn match railslogIP '\<\d\{1,3\}\%(\.\d\{1,3}\)\{3\}\>' + syn match railslogTimestamp '\<\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\>' + syn match railslogSessionID '\<\x\{32\}\>' + syn match railslogIdentifier '^\s*\%(Session ID\|Parameters\)\ze:' + syn match railslogSuccess '\<2\d\d \u[A-Za-z0-9 ]*\>' + syn match railslogRedirect '\<3\d\d \u[A-Za-z0-9 ]*\>' + syn match railslogError '\<[45]\d\d \u[A-Za-z0-9 ]*\>' + syn match railslogError '^DEPRECATION WARNING\>' + syn keyword railslogHTTP OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT + syn region railslogStackTrace start=":\d\+:in `\w\+'$" end="^\s*$" keepend fold + hi def link railslogEscapeMN railslogEscape + hi def link railslogEscapeSQL railslogEscape + hi def link railslogEscape Ignore + hi def link railslogComment Comment + hi def link railslogRender Keyword + hi def link railslogModel Type + hi def link railslogSQL PreProc + hi def link railslogNumber Number + hi def link railslogString String + hi def link railslogSessionID Constant + hi def link railslogIdentifier Identifier + hi def link railslogRedirect railslogSuccess + hi def link railslogSuccess Special + hi def link railslogError Error + hi def link railslogHTTP Special +endfunction + +" }}}1 +" Mappings {{{1 + +function! s:BufMappings() + nnoremap RailsFind :call Find(v:count1,'E') + nnoremap RailsSplitFind :call Find(v:count1,'S') + nnoremap RailsVSplitFind :call Find(v:count1,'V') + nnoremap RailsTabFind :call Find(v:count1,'T') + if g:rails_mappings + if !hasmapto("RailsFind") + nmap gf RailsFind + endif + if !hasmapto("RailsSplitFind") + nmap f RailsSplitFind + endif + if !hasmapto("RailsTabFind") + nmap gf RailsTabFind + endif + if exists("$CREAM") + imap RailsFind + imap RailsAlternate + imap RailsRelated + endif + endif + " SelectBuf you're a dirty hack + let v:errmsg = "" +endfunction + +" }}}1 +" Database {{{1 + +function! s:extractdbvar(str,arg) + return matchstr("\n".a:str."\n",'\n'.a:arg.'=\zs.\{-\}\ze\n') +endfunction + +function! s:app_dbext_settings(environment) dict + if self.cache.needs('dbext_settings') + call self.cache.set('dbext_settings',{}) + endif + let cache = self.cache.get('dbext_settings') + if !has_key(cache,a:environment) + let dict = {} + if self.has_file("config/database.yml") + let cmdb = 'require %{yaml}; File.open(%q{'.self.path().'/config/database.yml}) {|f| y = YAML::load(f); e = y[%{' + let cmde = '}]; i=0; e=y[e] while e.respond_to?(:to_str) && (i+=1)<16; e.each{|k,v|puts k.to_s+%{=}+v.to_s}}' + let out = self.lightweight_ruby_eval(cmdb.a:environment.cmde) + let adapter = s:extractdbvar(out,'adapter') + let adapter = get({'mysql2': 'mysql', 'postgresql': 'pgsql', 'sqlite3': 'sqlite', 'sqlserver': 'sqlsrv', 'sybase': 'asa', 'oracle': 'ora'},adapter,adapter) + let dict['type'] = toupper(adapter) + let dict['user'] = s:extractdbvar(out,'username') + let dict['passwd'] = s:extractdbvar(out,'password') + if dict['passwd'] == '' && adapter == 'mysql' + " Hack to override password from .my.cnf + let dict['extra'] = ' --password=' + else + let dict['extra'] = '' + endif + let dict['dbname'] = s:extractdbvar(out,'database') + if dict['dbname'] == '' + let dict['dbname'] = s:extractdbvar(out,'dbfile') + endif + if dict['dbname'] != '' && dict['dbname'] !~ '^:' && adapter =~? '^sqlite' + let dict['dbname'] = self.path(dict['dbname']) + endif + let dict['profile'] = '' + if adapter == 'ora' + let dict['srvname'] = s:extractdbvar(out,'database') + else + let dict['srvname'] = s:extractdbvar(out,'host') + endif + let dict['host'] = s:extractdbvar(out,'host') + let dict['port'] = s:extractdbvar(out,'port') + let dict['dsnname'] = s:extractdbvar(out,'dsn') + if dict['host'] =~? '^\cDBI:' + if dict['host'] =~? '\c\' + let dict['integratedlogin'] = 1 + endif + let dict['host'] = matchstr(dict['host'],'\c\<\%(Server\|Data Source\)\s*=\s*\zs[^;]*') + endif + call filter(dict,'v:val != ""') + endif + let cache[a:environment] = dict + endif + return cache[a:environment] +endfunction + +function! s:BufDatabase(...) + if exists("s:lock_database") || !exists('g:loaded_dbext') || !exists('b:rails_root') + return + endif + let self = rails#app() + let s:lock_database = 1 + if (a:0 && a:1 > 1) + call self.cache.clear('dbext_settings') + endif + if (a:0 > 1 && a:2 != '') + let env = a:2 + else + let env = s:environment() + endif + if (!self.cache.has('dbext_settings') || !has_key(self.cache.get('dbext_settings'),env)) && (a:0 ? a:1 : 0) <= 0 + unlet! s:lock_database + return + endif + let dict = self.dbext_settings(env) + for key in ['type', 'profile', 'bin', 'user', 'passwd', 'dbname', 'srvname', 'host', 'port', 'dsnname', 'extra', 'integratedlogin'] + let b:dbext_{key} = get(dict,key,'') + endfor + if b:dbext_type == 'PGSQL' + let $PGPASSWORD = b:dbext_passwd + elseif exists('$PGPASSWORD') + let $PGPASSWORD = '' + endif + unlet! s:lock_database +endfunction + +call s:add_methods('app', ['dbext_settings']) + +" }}}1 +" Abbreviations {{{1 + +function! s:selectiveexpand(pat,good,default,...) + if a:0 > 0 + let nd = a:1 + else + let nd = "" + endif + let c = nr2char(getchar(0)) + let good = a:good + if c == "" " ^] + return s:sub(good.(a:0 ? " ".a:1 : ''),'\s+$','') + elseif c == "\t" + return good.(a:0 ? " ".a:1 : '') + elseif c =~ a:pat + return good.c.(a:0 ? a:1 : '') + else + return a:default.c + endif +endfunction + +function! s:TheCWord() + let l = s:linepeak() + if l =~ '\<\%(find\|first\|last\|all\|paginate\)\>' + return s:selectiveexpand('..',':conditions => ',':c') + elseif l =~ '\\s*' + return s:selectiveexpand('..',':collection => ',':c') + elseif l =~ '\<\%(url_for\|link_to\|form_tag\)\>' || l =~ ':url\s*=>\s*{\s*' + return s:selectiveexpand('..',':controller => ',':c') + else + return s:selectiveexpand('..',':conditions => ',':c') + endif +endfunction + +function! s:AddSelectiveExpand(abbr,pat,expn,...) + let expn = s:gsub(s:gsub(a:expn ,'[\"|]','\\&'),'\<','\\') + let expn2 = s:gsub(s:gsub(a:0 ? a:1 : '','[\"|]','\\&'),'\<','\\') + if a:0 + exe "inoreabbrev ".a:abbr." =selectiveexpand(".string(a:pat).",\"".expn."\",".string(a:abbr).",\"".expn2."\")" + else + exe "inoreabbrev ".a:abbr." =selectiveexpand(".string(a:pat).",\"".expn."\",".string(a:abbr).")" + endif +endfunction + +function! s:AddTabExpand(abbr,expn) + call s:AddSelectiveExpand(a:abbr,'..',a:expn) +endfunction + +function! s:AddBracketExpand(abbr,expn) + call s:AddSelectiveExpand(a:abbr,'[[.]',a:expn) +endfunction + +function! s:AddColonExpand(abbr,expn) + call s:AddSelectiveExpand(a:abbr,'[:.]',a:expn) +endfunction + +function! s:AddParenExpand(abbr,expn,...) + if a:0 + call s:AddSelectiveExpand(a:abbr,'(',a:expn,a:1) + else + call s:AddSelectiveExpand(a:abbr,'(',a:expn,'') + endif +endfunction + +function! s:BufAbbreviations() + command! -buffer -bar -nargs=* -bang Rabbrev :call s:Abbrev(0,) + " Some of these were cherry picked from the TextMate snippets + if g:rails_abbreviations + let buffer = rails#buffer() + " Limit to the right filetypes. But error on the liberal side + if buffer.type_name('controller','view','helper','test-functional','test-integration') + Rabbrev pa[ params + Rabbrev rq[ request + Rabbrev rs[ response + Rabbrev se[ session + Rabbrev hd[ headers + Rabbrev coo[ cookies + Rabbrev fl[ flash + Rabbrev rr( render + Rabbrev ra( render :action\ =>\ + Rabbrev rc( render :controller\ =>\ + Rabbrev rf( render :file\ =>\ + Rabbrev ri( render :inline\ =>\ + Rabbrev rj( render :json\ =>\ + Rabbrev rl( render :layout\ =>\ + Rabbrev rp( render :partial\ =>\ + Rabbrev rt( render :text\ =>\ + Rabbrev rx( render :xml\ =>\ + endif + if buffer.type_name('view','helper') + Rabbrev dotiw distance_of_time_in_words + Rabbrev taiw time_ago_in_words + endif + if buffer.type_name('controller') + Rabbrev re( redirect_to + Rabbrev rea( redirect_to :action\ =>\ + Rabbrev rec( redirect_to :controller\ =>\ + Rabbrev rst( respond_to + endif + if buffer.type_name() ==# 'model' || buffer.type_name('model-arb') + Rabbrev bt( belongs_to + Rabbrev ho( has_one + Rabbrev hm( has_many + Rabbrev habtm( has_and_belongs_to_many + Rabbrev co( composed_of + Rabbrev va( validates_associated + Rabbrev vb( validates_acceptance_of + Rabbrev vc( validates_confirmation_of + Rabbrev ve( validates_exclusion_of + Rabbrev vf( validates_format_of + Rabbrev vi( validates_inclusion_of + Rabbrev vl( validates_length_of + Rabbrev vn( validates_numericality_of + Rabbrev vp( validates_presence_of + Rabbrev vu( validates_uniqueness_of + endif + if buffer.type_name('db-migration','db-schema') + Rabbrev mac( add_column + Rabbrev mrnc( rename_column + Rabbrev mrc( remove_column + Rabbrev mct( create_table + Rabbrev mcht( change_table + Rabbrev mrnt( rename_table + Rabbrev mdt( drop_table + Rabbrev mcc( t.column + endif + if buffer.type_name('test') + Rabbrev ase( assert_equal + Rabbrev asko( assert_kind_of + Rabbrev asnn( assert_not_nil + Rabbrev asr( assert_raise + Rabbrev asre( assert_response + Rabbrev art( assert_redirected_to + endif + Rabbrev :a :action\ =>\ + " hax + Rabbrev :c :co________\ =>\ + inoreabbrev :c =TheCWord() + Rabbrev :i :id\ =>\ + Rabbrev :o :object\ =>\ + Rabbrev :p :partial\ =>\ + Rabbrev logd( logger.debug + Rabbrev logi( logger.info + Rabbrev logw( logger.warn + Rabbrev loge( logger.error + Rabbrev logf( logger.fatal + Rabbrev fi( find + Rabbrev AR:: ActiveRecord + Rabbrev AV:: ActionView + Rabbrev AC:: ActionController + Rabbrev AD:: ActionDispatch + Rabbrev AS:: ActiveSupport + Rabbrev AM:: ActionMailer + Rabbrev AO:: ActiveModel + Rabbrev AE:: ActiveResource + endif +endfunction + +function! s:Abbrev(bang,...) abort + if !exists("b:rails_abbreviations") + let b:rails_abbreviations = {} + endif + if a:0 > 3 || (a:bang && (a:0 != 1)) + return s:error("Rabbrev: invalid arguments") + endif + if a:0 == 0 + for key in sort(keys(b:rails_abbreviations)) + echo key . join(b:rails_abbreviations[key],"\t") + endfor + return + endif + let lhs = a:1 + let root = s:sub(lhs,'%(::|\(|\[)$','') + if a:bang + if has_key(b:rails_abbreviations,root) + call remove(b:rails_abbreviations,root) + endif + exe "iunabbrev ".root + return + endif + if a:0 > 3 || a:0 < 2 + return s:error("Rabbrev: invalid arguments") + endif + let rhs = a:2 + if has_key(b:rails_abbreviations,root) + call remove(b:rails_abbreviations,root) + endif + if lhs =~ '($' + let b:rails_abbreviations[root] = ["(", rhs . (a:0 > 2 ? "\t".a:3 : "")] + if a:0 > 2 + call s:AddParenExpand(root,rhs,a:3) + else + call s:AddParenExpand(root,rhs) + endif + return + endif + if a:0 > 2 + return s:error("Rabbrev: invalid arguments") + endif + if lhs =~ ':$' + call s:AddColonExpand(root,rhs) + elseif lhs =~ '\[$' + call s:AddBracketExpand(root,rhs) + elseif lhs =~ '\w$' + call s:AddTabExpand(lhs,rhs) + else + return s:error("Rabbrev: unimplemented") + endif + let b:rails_abbreviations[root] = [matchstr(lhs,'\W*$'),rhs] +endfunction + +" }}}1 +" Settings {{{1 + +function! s:Set(bang,...) + let c = 1 + let defscope = '' + for arg in a:000 + if arg =~? '^<[abgl]\=>$' + let defscope = (matchstr(arg,'<\zs.*\ze>')) + elseif arg !~ '=' + if defscope != '' && arg !~ '^\w:' + let arg = defscope.':'.opt + endif + let val = s:getopt(arg) + if val == '' && !has_key(s:opts(),arg) + call s:error("No such rails.vim option: ".arg) + else + echo arg."=".val + endif + else + let opt = matchstr(arg,'[^=]*') + let val = s:sub(arg,'^[^=]*\=','') + if defscope != '' && opt !~ '^\w:' + let opt = defscope.':'.opt + endif + call s:setopt(opt,val) + endif + endfor +endfunction + +function! s:getopt(opt,...) + let app = rails#app() + let opt = a:opt + if a:0 + let scope = a:1 + elseif opt =~ '^[abgl]:' + let scope = tolower(matchstr(opt,'^\w')) + let opt = s:sub(opt,'^\w:','') + else + let scope = 'abgl' + endif + let lnum = a:0 > 1 ? a:2 : line('.') + if scope =~ 'l' && &filetype != 'ruby' + let scope = s:sub(scope,'l','b') + endif + if scope =~ 'l' + call s:LocalModelines(lnum) + endif + let var = s:sname().'_'.opt + let lastmethod = s:lastmethod(lnum) + if lastmethod == '' | let lastmethod = ' ' | endif + " Get buffer option + if scope =~ 'l' && exists('b:_'.var) && has_key(b:_{var},lastmethod) + return b:_{var}[lastmethod] + elseif exists('b:'.var) && (scope =~ 'b' || (scope =~ 'l' && lastmethod == ' ')) + return b:{var} + elseif scope =~ 'a' && has_key(app,'options') && has_key(app.options,opt) + return app.options[opt] + elseif scope =~ 'g' && exists("g:".s:sname()."_".opt) + return g:{var} + else + return "" + endif +endfunction + +function! s:setopt(opt,val) + let app = rails#app() + if a:opt =~? '[abgl]:' + let scope = matchstr(a:opt,'^\w') + let opt = s:sub(a:opt,'^\w:','') + else + let scope = '' + let opt = a:opt + endif + let defscope = get(s:opts(),opt,'a') + if scope == '' + let scope = defscope + endif + if &filetype != 'ruby' && (scope ==# 'B' || scope ==# 'l') + let scope = 'b' + endif + let var = s:sname().'_'.opt + if opt =~ '\W' + return s:error("Invalid option ".a:opt) + elseif scope ==# 'B' && defscope == 'l' + if !exists('b:_'.var) | let b:_{var} = {} | endif + let b:_{var}[' '] = a:val + elseif scope =~? 'b' + let b:{var} = a:val + elseif scope =~? 'a' + if !has_key(app,'options') | let app.options = {} | endif + let app.options[opt] = a:val + elseif scope =~? 'g' + let g:{var} = a:val + elseif scope =~? 'l' + if !exists('b:_'.var) | let b:_{var} = {} | endif + let lastmethod = s:lastmethod(lnum) + let b:_{var}[lastmethod == '' ? ' ' : lastmethod] = a:val + else + return s:error("Invalid scope for ".a:opt) + endif +endfunction + +function! s:opts() + return {'alternate': 'b', 'controller': 'b', 'gnu_screen': 'a', 'model': 'b', 'preview': 'l', 'task': 'b', 'related': 'l', 'root_url': 'a'} +endfunction + +function! s:Complete_set(A,L,P) + if a:A =~ '=' + let opt = matchstr(a:A,'[^=]*') + return [opt."=".s:getopt(opt)] + else + let extra = matchstr(a:A,'^[abgl]:') + return filter(sort(map(keys(s:opts()),'extra.v:val')),'s:startswith(v:val,a:A)') + endif + return [] +endfunction + +function! s:BufModelines() + if !g:rails_modelines + return + endif + let lines = getline("$")."\n".getline(line("$")-1)."\n".getline(1)."\n".getline(2)."\n".getline(3)."\n" + let pat = '\s\+\zs.\{-\}\ze\%(\n\|\s\s\|#{\@!\|%>\|-->\|$\)' + let cnt = 1 + let mat = matchstr(lines,'\C\ ".mat + endif + let mat = matchstr(lines,'\C\ ".mat + endif + let mat = matchstr(lines,'\C\ 0 + if !exists("g:RAILS_HISTORY") + let g:RAILS_HISTORY = "" + endif + let path = a:path + let g:RAILS_HISTORY = s:scrub(g:RAILS_HISTORY,path) + if has("win32") + let g:RAILS_HISTORY = s:scrub(g:RAILS_HISTORY,s:gsub(path,'\\','/')) + endif + let path = fnamemodify(path,':p:~:h') + let g:RAILS_HISTORY = s:scrub(g:RAILS_HISTORY,path) + if has("win32") + let g:RAILS_HISTORY = s:scrub(g:RAILS_HISTORY,s:gsub(path,'\\','/')) + endif + let g:RAILS_HISTORY = path."\n".g:RAILS_HISTORY + let g:RAILS_HISTORY = s:sub(g:RAILS_HISTORY,'%(.{-}\n){,'.g:rails_history_size.'}\zs.*','') + endif + call app.source_callback("config/syntax.vim") + if expand('%:t') =~ '\.yml\.example$' + setlocal filetype=yaml + elseif expand('%:e') =~ '^\%(rjs\|rxml\|builder\)$' + setlocal filetype=ruby + elseif firsttime + " Activate custom syntax + let &syntax = &syntax + endif + if expand('%:e') == 'log' + nnoremap R :checktime + nnoremap G :checktime$ + nnoremap q :bwipe + setlocal modifiable filetype=railslog noswapfile autoread foldmethod=syntax + if exists('+concealcursor') + setlocal concealcursor=nc conceallevel=2 + else + silent %s/\%(\e\[[0-9;]*m\|\r$\)//ge + endif + setlocal readonly nomodifiable + $ + endif + call s:BufSettings() + call s:BufCommands() + call s:BufAbbreviations() + " snippetsEmu.vim + if exists('g:loaded_snippet') + silent! runtime! ftplugin/rails_snippets.vim + " filetype snippets need to come last for higher priority + exe "silent! runtime! ftplugin/".&filetype."_snippets.vim" + endif + let t = rails#buffer().type_name() + let t = "-".t + let f = '/'.RailsFilePath() + if f =~ '[ !#$%\,]' + let f = '' + endif + runtime! macros/rails.vim + silent doautocmd User Rails + if t != '-' + exe "silent doautocmd User Rails".s:gsub(t,'-','.') + endif + if f != '' + exe "silent doautocmd User Rails".f + endif + call app.source_callback("config/rails.vim") + call s:BufModelines() + call s:BufMappings() + return b:rails_root +endfunction + +function! s:SetBasePath() + let self = rails#buffer() + if self.app().path() =~ '://' + return + endif + let transformed_path = s:pathsplit(s:pathjoin([self.app().path()]))[0] + let add_dot = self.getvar('&path') =~# '^\.\%(,\|$\)' + let old_path = s:pathsplit(s:sub(self.getvar('&path'),'^\.%(,|$)','')) + call filter(old_path,'!s:startswith(v:val,transformed_path)') + + let path = ['app', 'app/models', 'app/controllers', 'app/helpers', 'config', 'lib', 'app/views'] + if self.controller_name() != '' + let path += ['app/views/'.self.controller_name(), 'public'] + endif + if self.app().has('test') + let path += ['test', 'test/unit', 'test/functional', 'test/integration'] + endif + if self.app().has('spec') + let path += ['spec', 'spec/models', 'spec/controllers', 'spec/helpers', 'spec/views', 'spec/lib', 'spec/requests', 'spec/integration'] + endif + let path += ['app/*', 'vendor', 'vendor/plugins/*/lib', 'vendor/plugins/*/test', 'vendor/rails/*/lib', 'vendor/rails/*/test'] + call map(path,'self.app().path(v:val)') + call self.setvar('&path',(add_dot ? '.,' : '').s:pathjoin([self.app().path()],path,old_path)) +endfunction + +function! s:BufSettings() + if !exists('b:rails_root') + return '' + endif + let self = rails#buffer() + call s:SetBasePath() + let rp = s:gsub(self.app().path(),'[ ,]','\\&') + if stridx(&tags,rp.'/tmp/tags') == -1 + let &l:tags = rp . '/tmp/tags,' . &tags . ',' . rp . '/tags' + endif + if has("gui_win32") || has("gui_running") + let code = '*.rb;*.rake;Rakefile' + let templates = '*.'.join(s:view_types,';*.') + let fixtures = '*.yml;*.csv' + let statics = '*.html;*.css;*.js;*.xml;*.xsd;*.sql;.htaccess;README;README_FOR_APP' + let b:browsefilter = "" + \."All Rails Files\t".code.';'.templates.';'.fixtures.';'.statics."\n" + \."Source Code (*.rb, *.rake)\t".code."\n" + \."Templates (*.rhtml, *.rxml, *.rjs)\t".templates."\n" + \."Fixtures (*.yml, *.csv)\t".fixtures."\n" + \."Static Files (*.html, *.css, *.js)\t".statics."\n" + \."All Files (*.*)\t*.*\n" + endif + call self.setvar('&includeexpr','RailsIncludeexpr()') + call self.setvar('&suffixesadd', ".rb,.".join(s:view_types,',.')) + let ft = self.getvar('&filetype') + if ft =~ '^\%(e\=ruby\|[yh]aml\|coffee\|css\|s[ac]ss\|lesscss\)$' + call self.setvar('&shiftwidth',2) + call self.setvar('&softtabstop',2) + call self.setvar('&expandtab',1) + if exists('+completefunc') && self.getvar('&completefunc') == '' + call self.setvar('&completefunc','syntaxcomplete#Complete') + endif + endif + if ft == 'ruby' + call self.setvar('&define',self.define_pattern()) + " This really belongs in after/ftplugin/ruby.vim but we'll be nice + if exists('g:loaded_surround') && self.getvar('surround_101') == '' + call self.setvar('surround_5', "\r\nend") + call self.setvar('surround_69', "\1expr: \1\rend") + call self.setvar('surround_101', "\r\nend") + endif + elseif ft == 'yaml' || fnamemodify(self.name(),':e') == 'yml' + call self.setvar('&define',self.define_pattern()) + elseif ft =~# '^eruby\>' + if exists("g:loaded_allml") + call self.setvar('allml_stylesheet_link_tag', "<%= stylesheet_link_tag '\r' %>") + call self.setvar('allml_javascript_include_tag', "<%= javascript_include_tag '\r' %>") + call self.setvar('allml_doctype_index', 10) + endif + if exists("g:loaded_ragtag") + call self.setvar('ragtag_stylesheet_link_tag', "<%= stylesheet_link_tag '\r' %>") + call self.setvar('ragtag_javascript_include_tag', "<%= javascript_include_tag '\r' %>") + call self.setvar('ragtag_doctype_index', 10) + endif + elseif ft == 'haml' + if exists("g:loaded_allml") + call self.setvar('allml_stylesheet_link_tag', "= stylesheet_link_tag '\r'") + call self.setvar('allml_javascript_include_tag', "= javascript_include_tag '\r'") + call self.setvar('allml_doctype_index', 10) + endif + if exists("g:loaded_ragtag") + call self.setvar('ragtag_stylesheet_link_tag', "= stylesheet_link_tag '\r'") + call self.setvar('ragtag_javascript_include_tag', "= javascript_include_tag '\r'") + call self.setvar('ragtag_doctype_index', 10) + endif + endif + if ft =~# '^eruby\>' || ft ==# 'yaml' + " surround.vim + if exists("g:loaded_surround") + " The idea behind the || part here is that one can normally define the + " surrounding to omit the hyphen (since standard ERuby does not use it) + " but have it added in Rails ERuby files. Unfortunately, this makes it + " difficult if you really don't want a hyphen in Rails ERuby files. If + " this is your desire, you will need to accomplish it via a rails.vim + " autocommand. + if self.getvar('surround_45') == '' || self.getvar('surround_45') == "<% \r %>" " - + call self.setvar('surround_45', "<% \r -%>") + endif + if self.getvar('surround_61') == '' " = + call self.setvar('surround_61', "<%= \r %>") + endif + if self.getvar("surround_35") == '' " # + call self.setvar('surround_35', "<%# \r %>") + endif + if self.getvar('surround_101') == '' || self.getvar('surround_101')== "<% \r %>\n<% end %>" "e + call self.setvar('surround_5', "<% \r -%>\n<% end -%>") + call self.setvar('surround_69', "<% \1expr: \1 -%>\r<% end -%>") + call self.setvar('surround_101', "<% \r -%>\n<% end -%>") + endif + endif + endif +endfunction + +" }}}1 +" Autocommands {{{1 + +augroup railsPluginAuto + autocmd! + autocmd User BufEnterRails call s:RefreshBuffer() + autocmd User BufEnterRails call s:resetomnicomplete() + autocmd User BufEnterRails call s:BufDatabase(-1) + autocmd User dbextPreConnection call s:BufDatabase(1) + autocmd BufWritePost */config/database.yml call rails#cache_clear("dbext_settings") + autocmd BufWritePost */test/test_helper.rb call rails#cache_clear("user_assertions") + autocmd BufWritePost */config/routes.rb call rails#cache_clear("named_routes") + autocmd BufWritePost */config/environment.rb call rails#cache_clear("default_locale") + autocmd BufWritePost */config/environments/*.rb call rails#cache_clear("environments") + autocmd BufWritePost */tasks/**.rake call rails#cache_clear("rake_tasks") + autocmd BufWritePost */generators/** call rails#cache_clear("generators") + autocmd FileType * if exists("b:rails_root") | call s:BufSettings() | endif + autocmd Syntax ruby,eruby,yaml,haml,javascript,coffee,railslog if exists("b:rails_root") | call s:BufSyntax() | endif + autocmd QuickFixCmdPre *make* call s:push_chdir() + autocmd QuickFixCmdPost *make* call s:pop_command() +augroup END + +" }}}1 +" Initialization {{{1 + +map xx xx +let s:sid = s:sub(maparg("xx"),'xx$','') +unmap xx +let s:file = expand(':p') + +if !exists('s:apps') + let s:apps = {} +endif + +" }}}1 + +let &cpo = s:cpo_save + +" vim:set sw=2 sts=2: diff --git a/vim/autoload/snipMate.vim b/vim/autoload/snipMate.vim new file mode 100644 index 0000000..0ad5a58 --- /dev/null +++ b/vim/autoload/snipMate.vim @@ -0,0 +1,435 @@ +fun! Filename(...) + let filename = expand('%:t:r') + if filename == '' | return a:0 == 2 ? a:2 : '' | endif + return !a:0 || a:1 == '' ? filename : substitute(a:1, '$1', filename, 'g') +endf + +fun s:RemoveSnippet() + unl! g:snipPos s:curPos s:snipLen s:endCol s:endLine s:prevLen + \ s:lastBuf s:oldWord + if exists('s:update') + unl s:startCol s:origWordLen s:update + if exists('s:oldVars') | unl s:oldVars s:oldEndCol | endif + endif + aug! snipMateAutocmds +endf + +fun snipMate#expandSnip(snip, col) + let lnum = line('.') | let col = a:col + + let snippet = s:ProcessSnippet(a:snip) + " Avoid error if eval evaluates to nothing + if snippet == '' | return '' | endif + + " Expand snippet onto current position with the tab stops removed + let snipLines = split(substitute(snippet, '$\d\+\|${\d\+.\{-}}', '', 'g'), "\n", 1) + + let line = getline(lnum) + let afterCursor = strpart(line, col - 1) + " Keep text after the cursor + if afterCursor != "\t" && afterCursor != ' ' + let line = strpart(line, 0, col - 1) + let snipLines[-1] .= afterCursor + else + let afterCursor = '' + " For some reason the cursor needs to move one right after this + if line != '' && col == 1 && &ve != 'all' && &ve != 'onemore' + let col += 1 + endif + endif + + call setline(lnum, line.snipLines[0]) + + " Autoindent snippet according to previous indentation + let indent = matchend(line, '^.\{-}\ze\(\S\|$\)') + 1 + call append(lnum, map(snipLines[1:], "'".strpart(line, 0, indent - 1)."'.v:val")) + + " Open any folds snippet expands into + if &fen | sil! exe lnum.','.(lnum + len(snipLines) - 1).'foldopen' | endif + + let [g:snipPos, s:snipLen] = s:BuildTabStops(snippet, lnum, col - indent, indent) + + if s:snipLen + aug snipMateAutocmds + au CursorMovedI * call s:UpdateChangedSnip(0) + au InsertEnter * call s:UpdateChangedSnip(1) + aug END + let s:lastBuf = bufnr(0) " Only expand snippet while in current buffer + let s:curPos = 0 + let s:endCol = g:snipPos[s:curPos][1] + let s:endLine = g:snipPos[s:curPos][0] + + call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1]) + let s:prevLen = [line('$'), col('$')] + if g:snipPos[s:curPos][2] != -1 | return s:SelectWord() | endif + else + unl g:snipPos s:snipLen + " Place cursor at end of snippet if no tab stop is given + let newlines = len(snipLines) - 1 + call cursor(lnum + newlines, indent + len(snipLines[-1]) - len(afterCursor) + \ + (newlines ? 0: col - 1)) + endif + return '' +endf + +" Prepare snippet to be processed by s:BuildTabStops +fun s:ProcessSnippet(snip) + let snippet = a:snip + " Evaluate eval (`...`) expressions. + " Backquotes prefixed with a backslash "\" are ignored. + " Using a loop here instead of a regex fixes a bug with nested "\=". + if stridx(snippet, '`') != -1 + while match(snippet, '\(^\|[^\\]\)`.\{-}[^\\]`') != -1 + let snippet = substitute(snippet, '\(^\|[^\\]\)\zs`.\{-}[^\\]`\ze', + \ substitute(eval(matchstr(snippet, '\(^\|[^\\]\)`\zs.\{-}[^\\]\ze`')), + \ "\n\\%$", '', ''), '') + endw + let snippet = substitute(snippet, "\r", "\n", 'g') + let snippet = substitute(snippet, '\\`', '`', 'g') + endif + + " Place all text after a colon in a tab stop after the tab stop + " (e.g. "${#:foo}" becomes "${:foo}foo"). + " This helps tell the position of the tab stops later. + let snippet = substitute(snippet, '${\d\+:\(.\{-}\)}', '&\1', 'g') + + " Update the a:snip so that all the $# become the text after + " the colon in their associated ${#}. + " (e.g. "${1:foo}" turns all "$1"'s into "foo") + let i = 1 + while stridx(snippet, '${'.i) != -1 + let s = matchstr(snippet, '${'.i.':\zs.\{-}\ze}') + if s != '' + let snippet = substitute(snippet, '$'.i, s.'&', 'g') + endif + let i += 1 + endw + + if &et " Expand tabs to spaces if 'expandtab' is set. + return substitute(snippet, '\t', repeat(' ', &sts ? &sts : &sw), 'g') + endif + return snippet +endf + +" Counts occurences of haystack in needle +fun s:Count(haystack, needle) + let counter = 0 + let index = stridx(a:haystack, a:needle) + while index != -1 + let index = stridx(a:haystack, a:needle, index+1) + let counter += 1 + endw + return counter +endf + +" Builds a list of a list of each tab stop in the snippet containing: +" 1.) The tab stop's line number. +" 2.) The tab stop's column number +" (by getting the length of the string between the last "\n" and the +" tab stop). +" 3.) The length of the text after the colon for the current tab stop +" (e.g. "${1:foo}" would return 3). If there is no text, -1 is returned. +" 4.) If the "${#:}" construct is given, another list containing all +" the matches of "$#", to be replaced with the placeholder. This list is +" composed the same way as the parent; the first item is the line number, +" and the second is the column. +fun s:BuildTabStops(snip, lnum, col, indent) + let snipPos = [] + let i = 1 + let withoutVars = substitute(a:snip, '$\d\+', '', 'g') + while stridx(a:snip, '${'.i) != -1 + let beforeTabStop = matchstr(withoutVars, '^.*\ze${'.i.'\D') + let withoutOthers = substitute(withoutVars, '${\('.i.'\D\)\@!\d\+.\{-}}', '', 'g') + + let j = i - 1 + call add(snipPos, [0, 0, -1]) + let snipPos[j][0] = a:lnum + s:Count(beforeTabStop, "\n") + let snipPos[j][1] = a:indent + len(matchstr(withoutOthers, '.*\(\n\|^\)\zs.*\ze${'.i.'\D')) + if snipPos[j][0] == a:lnum | let snipPos[j][1] += a:col | endif + + " Get all $# matches in another list, if ${#:name} is given + if stridx(withoutVars, '${'.i.':') != -1 + let snipPos[j][2] = len(matchstr(withoutVars, '${'.i.':\zs.\{-}\ze}')) + let dots = repeat('.', snipPos[j][2]) + call add(snipPos[j], []) + let withoutOthers = substitute(a:snip, '${\d\+.\{-}}\|$'.i.'\@!\d\+', '', 'g') + while match(withoutOthers, '$'.i.'\(\D\|$\)') != -1 + let beforeMark = matchstr(withoutOthers, '^.\{-}\ze'.dots.'$'.i.'\(\D\|$\)') + call add(snipPos[j][3], [0, 0]) + let snipPos[j][3][-1][0] = a:lnum + s:Count(beforeMark, "\n") + let snipPos[j][3][-1][1] = a:indent + (snipPos[j][3][-1][0] > a:lnum + \ ? len(matchstr(beforeMark, '.*\n\zs.*')) + \ : a:col + len(beforeMark)) + let withoutOthers = substitute(withoutOthers, '$'.i.'\ze\(\D\|$\)', '', '') + endw + endif + let i += 1 + endw + return [snipPos, i - 1] +endf + +fun snipMate#jumpTabStop(backwards) + let leftPlaceholder = exists('s:origWordLen') + \ && s:origWordLen != g:snipPos[s:curPos][2] + if leftPlaceholder && exists('s:oldEndCol') + let startPlaceholder = s:oldEndCol + 1 + endif + + if exists('s:update') + call s:UpdatePlaceholderTabStops() + else + call s:UpdateTabStops() + endif + + " Don't reselect placeholder if it has been modified + if leftPlaceholder && g:snipPos[s:curPos][2] != -1 + if exists('startPlaceholder') + let g:snipPos[s:curPos][1] = startPlaceholder + else + let g:snipPos[s:curPos][1] = col('.') + let g:snipPos[s:curPos][2] = 0 + endif + endif + + let s:curPos += a:backwards ? -1 : 1 + " Loop over the snippet when going backwards from the beginning + if s:curPos < 0 | let s:curPos = s:snipLen - 1 | endif + + if s:curPos == s:snipLen + let sMode = s:endCol == g:snipPos[s:curPos-1][1]+g:snipPos[s:curPos-1][2] + call s:RemoveSnippet() + return sMode ? "\" : TriggerSnippet() + endif + + call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1]) + + let s:endLine = g:snipPos[s:curPos][0] + let s:endCol = g:snipPos[s:curPos][1] + let s:prevLen = [line('$'), col('$')] + + return g:snipPos[s:curPos][2] == -1 ? '' : s:SelectWord() +endf + +fun s:UpdatePlaceholderTabStops() + let changeLen = s:origWordLen - g:snipPos[s:curPos][2] + unl s:startCol s:origWordLen s:update + if !exists('s:oldVars') | return | endif + " Update tab stops in snippet if text has been added via "$#" + " (e.g., in "${1:foo}bar$1${2}"). + if changeLen != 0 + let curLine = line('.') + + for pos in g:snipPos + if pos == g:snipPos[s:curPos] | continue | endif + let changed = pos[0] == curLine && pos[1] > s:oldEndCol + let changedVars = 0 + let endPlaceholder = pos[2] - 1 + pos[1] + " Subtract changeLen from each tab stop that was after any of + " the current tab stop's placeholders. + for [lnum, col] in s:oldVars + if lnum > pos[0] | break | endif + if pos[0] == lnum + if pos[1] > col || (pos[2] == -1 && pos[1] == col) + let changed += 1 + elseif col < endPlaceholder + let changedVars += 1 + endif + endif + endfor + let pos[1] -= changeLen * changed + let pos[2] -= changeLen * changedVars " Parse variables within placeholders + " e.g., "${1:foo} ${2:$1bar}" + + if pos[2] == -1 | continue | endif + " Do the same to any placeholders in the other tab stops. + for nPos in pos[3] + let changed = nPos[0] == curLine && nPos[1] > s:oldEndCol + for [lnum, col] in s:oldVars + if lnum > nPos[0] | break | endif + if nPos[0] == lnum && nPos[1] > col + let changed += 1 + endif + endfor + let nPos[1] -= changeLen * changed + endfor + endfor + endif + unl s:endCol s:oldVars s:oldEndCol +endf + +fun s:UpdateTabStops() + let changeLine = s:endLine - g:snipPos[s:curPos][0] + let changeCol = s:endCol - g:snipPos[s:curPos][1] + if exists('s:origWordLen') + let changeCol -= s:origWordLen + unl s:origWordLen + endif + let lnum = g:snipPos[s:curPos][0] + let col = g:snipPos[s:curPos][1] + " Update the line number of all proceeding tab stops if has + " been inserted. + if changeLine != 0 + let changeLine -= 1 + for pos in g:snipPos + if pos[0] >= lnum + if pos[0] == lnum | let pos[1] += changeCol | endif + let pos[0] += changeLine + endif + if pos[2] == -1 | continue | endif + for nPos in pos[3] + if nPos[0] >= lnum + if nPos[0] == lnum | let nPos[1] += changeCol | endif + let nPos[0] += changeLine + endif + endfor + endfor + elseif changeCol != 0 + " Update the column of all proceeding tab stops if text has + " been inserted/deleted in the current line. + for pos in g:snipPos + if pos[1] >= col && pos[0] == lnum + let pos[1] += changeCol + endif + if pos[2] == -1 | continue | endif + for nPos in pos[3] + if nPos[0] > lnum | break | endif + if nPos[0] == lnum && nPos[1] >= col + let nPos[1] += changeCol + endif + endfor + endfor + endif +endf + +fun s:SelectWord() + let s:origWordLen = g:snipPos[s:curPos][2] + let s:oldWord = strpart(getline('.'), g:snipPos[s:curPos][1] - 1, + \ s:origWordLen) + let s:prevLen[1] -= s:origWordLen + if !empty(g:snipPos[s:curPos][3]) + let s:update = 1 + let s:endCol = -1 + let s:startCol = g:snipPos[s:curPos][1] - 1 + endif + if !s:origWordLen | return '' | endif + let l = col('.') != 1 ? 'l' : '' + if &sel == 'exclusive' + return "\".l.'v'.s:origWordLen."l\" + endif + return s:origWordLen == 1 ? "\".l.'gh' + \ : "\".l.'v'.(s:origWordLen - 1)."l\" +endf + +" This updates the snippet as you type when text needs to be inserted +" into multiple places (e.g. in "${1:default text}foo$1bar$1", +" "default text" would be highlighted, and if the user types something, +" UpdateChangedSnip() would be called so that the text after "foo" & "bar" +" are updated accordingly) +" +" It also automatically quits the snippet if the cursor is moved out of it +" while in insert mode. +fun s:UpdateChangedSnip(entering) + if exists('g:snipPos') && bufnr(0) != s:lastBuf + call s:RemoveSnippet() + elseif exists('s:update') " If modifying a placeholder + if !exists('s:oldVars') && s:curPos + 1 < s:snipLen + " Save the old snippet & word length before it's updated + " s:startCol must be saved too, in case text is added + " before the snippet (e.g. in "foo$1${2}bar${1:foo}"). + let s:oldEndCol = s:startCol + let s:oldVars = deepcopy(g:snipPos[s:curPos][3]) + endif + let col = col('.') - 1 + + if s:endCol != -1 + let changeLen = col('$') - s:prevLen[1] + let s:endCol += changeLen + else " When being updated the first time, after leaving select mode + if a:entering | return | endif + let s:endCol = col - 1 + endif + + " If the cursor moves outside the snippet, quit it + if line('.') != g:snipPos[s:curPos][0] || col < s:startCol || + \ col - 1 > s:endCol + unl! s:startCol s:origWordLen s:oldVars s:update + return s:RemoveSnippet() + endif + + call s:UpdateVars() + let s:prevLen[1] = col('$') + elseif exists('g:snipPos') + if !a:entering && g:snipPos[s:curPos][2] != -1 + let g:snipPos[s:curPos][2] = -2 + endif + + let col = col('.') + let lnum = line('.') + let changeLine = line('$') - s:prevLen[0] + + if lnum == s:endLine + let s:endCol += col('$') - s:prevLen[1] + let s:prevLen = [line('$'), col('$')] + endif + if changeLine != 0 + let s:endLine += changeLine + let s:endCol = col + endif + + " Delete snippet if cursor moves out of it in insert mode + if (lnum == s:endLine && (col > s:endCol || col < g:snipPos[s:curPos][1])) + \ || lnum > s:endLine || lnum < g:snipPos[s:curPos][0] + call s:RemoveSnippet() + endif + endif +endf + +" This updates the variables in a snippet when a placeholder has been edited. +" (e.g., each "$1" in "${1:foo} $1bar $1bar") +fun s:UpdateVars() + let newWordLen = s:endCol - s:startCol + 1 + let newWord = strpart(getline('.'), s:startCol, newWordLen) + if newWord == s:oldWord || empty(g:snipPos[s:curPos][3]) + return + endif + + let changeLen = g:snipPos[s:curPos][2] - newWordLen + let curLine = line('.') + let startCol = col('.') + let oldStartSnip = s:startCol + let updateTabStops = changeLen != 0 + let i = 0 + + for [lnum, col] in g:snipPos[s:curPos][3] + if updateTabStops + let start = s:startCol + if lnum == curLine && col <= start + let s:startCol -= changeLen + let s:endCol -= changeLen + endif + for nPos in g:snipPos[s:curPos][3][(i):] + " This list is in ascending order, so quit if we've gone too far. + if nPos[0] > lnum | break | endif + if nPos[0] == lnum && nPos[1] > col + let nPos[1] -= changeLen + endif + endfor + if lnum == curLine && col > start + let col -= changeLen + let g:snipPos[s:curPos][3][i][1] = col + endif + let i += 1 + endif + + " "Very nomagic" is used here to allow special characters. + call setline(lnum, substitute(getline(lnum), '\%'.col.'c\V'. + \ escape(s:oldWord, '\'), escape(newWord, '\&'), '')) + endfor + if oldStartSnip != s:startCol + call cursor(0, startCol + s:startCol - oldStartSnip) + endif + + let s:oldWord = newWord + let g:snipPos[s:curPos][2] = newWordLen +endf +" vim:noet:sw=4:ts=4:ft=vim diff --git a/vim/autoload/syntastic.vim b/vim/autoload/syntastic.vim new file mode 100644 index 0000000..a477736 --- /dev/null +++ b/vim/autoload/syntastic.vim @@ -0,0 +1,24 @@ + +function! syntastic#ErrorBalloonExpr() + if !exists('b:syntastic_balloons') | return '' | endif + return get(b:syntastic_balloons, v:beval_lnum, '') +endfunction + +function! syntastic#HighlightErrors(errors, termfunc, ...) + call clearmatches() + let forcecb = a:0 && a:1 + for item in a:errors + let group = item['type'] == 'E' ? 'SpellBad' : 'SpellCap' + if item['col'] && !forcecb + let lastcol = col([item['lnum'], '$']) + let lcol = min([lastcol, item['col']]) + call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c') + else + let term = a:termfunc(item) + if len(term) > 0 + call matchadd(group, '\%' . item['lnum'] . 'l' . term) + endif + endif + endfor +endfunction + diff --git a/vim/autoload/syntastic/c.vim b/vim/autoload/syntastic/c.vim new file mode 100644 index 0000000..c7232df --- /dev/null +++ b/vim/autoload/syntastic/c.vim @@ -0,0 +1,171 @@ +if exists("g:loaded_syntastic_c_autoload") + finish +endif +let g:loaded_syntastic_c_autoload = 1 + +let s:save_cpo = &cpo +set cpo&vim + +" initialize c/cpp syntax checker handlers +function! s:Init() + let s:handlers = [] + let s:cflags = {} + + call s:RegHandler('gtk', 'syntastic#c#CheckPKG', + \ ['gtk', 'gtk+-2.0', 'gtk+', 'glib-2.0', 'glib']) + call s:RegHandler('glib', 'syntastic#c#CheckPKG', + \ ['glib', 'glib-2.0', 'glib']) + call s:RegHandler('glade', 'syntastic#c#CheckPKG', + \ ['glade', 'libglade-2.0', 'libglade']) + call s:RegHandler('libsoup', 'syntastic#c#CheckPKG', + \ ['libsoup', 'libsoup-2.4', 'libsoup-2.2']) + call s:RegHandler('webkit', 'syntastic#c#CheckPKG', + \ ['webkit', 'webkit-1.0']) + call s:RegHandler('cairo', 'syntastic#c#CheckPKG', + \ ['cairo', 'cairo']) + call s:RegHandler('pango', 'syntastic#c#CheckPKG', + \ ['pango', 'pango']) + call s:RegHandler('libxml', 'syntastic#c#CheckPKG', + \ ['libxml', 'libxml-2.0', 'libxml']) + call s:RegHandler('freetype', 'syntastic#c#CheckPKG', + \ ['freetype', 'freetype2', 'freetype']) + call s:RegHandler('SDL', 'syntastic#c#CheckPKG', + \ ['sdl', 'sdl']) + call s:RegHandler('opengl', 'syntastic#c#CheckPKG', + \ ['opengl', 'gl']) + call s:RegHandler('ruby', 'syntastic#c#CheckRuby', []) + call s:RegHandler('Python\.h', 'syntastic#c#CheckPython', []) + call s:RegHandler('php\.h', 'syntastic#c#CheckPhp', []) +endfunction + +" search the first 100 lines for include statements that are +" given in the handlers dictionary +function! syntastic#c#SearchHeaders() + let includes = '' + let files = [] + let found = [] + let lines = filter(getline(1, 100), 'v:val =~# "#\s*include"') + + " search current buffer + for line in lines + let file = matchstr(line, '"\zs\S\+\ze"') + if file != '' + call add(files, file) + continue + endif + for handler in s:handlers + if line =~# handler["regex"] + let includes .= call(handler["func"], handler["args"]) + call add(found, handler["regex"]) + break + endif + endfor + endfor + + " search included headers + for hfile in files + if hfile != '' + let filename = expand('%:p:h') . ((has('win32') || has('win64')) ? + \ '\' : '/') . hfile + try + let lines = readfile(filename, '', 100) + catch /E484/ + continue + endtry + let lines = filter(lines, 'v:val =~# "#\s*include"') + for handler in s:handlers + if index(found, handler["regex"]) != -1 + continue + endif + for line in lines + if line =~# handler["regex"] + let includes .= call(handler["func"], handler["args"]) + call add(found, handler["regex"]) + break + endif + endfor + endfor + endif + endfor + + return includes +endfunction + +" try to find library with 'pkg-config' +" search possible libraries from first to last given +" argument until one is found +function! syntastic#c#CheckPKG(name, ...) + if executable('pkg-config') + if !has_key(s:cflags, a:name) + for i in range(a:0) + let l:cflags = system('pkg-config --cflags '.a:000[i]) + " since we cannot necessarily trust the pkg-config exit code + " we have to check for an error output as well + if v:shell_error == 0 && l:cflags !~? 'not found' + let l:cflags = ' '.substitute(l:cflags, "\n", '', '') + let s:cflags[a:name] = l:cflags + return l:cflags + endif + endfor + else + return s:cflags[a:name] + endif + endif + return '' +endfunction + +" try to find PHP includes with 'php-config' +function! syntastic#c#CheckPhp() + if executable('php-config') + if !exists('s:php_flags') + let s:php_flags = system('php-config --includes') + let s:php_flags = ' ' . substitute(s:php_flags, "\n", '', '') + endif + return s:php_flags + endif + return '' +endfunction + +" try to find the ruby headers with 'rbconfig' +function! syntastic#c#CheckRuby() + if executable('ruby') + if !exists('s:ruby_flags') + let s:ruby_flags = system('ruby -r rbconfig -e ' + \ . '''puts Config::CONFIG["archdir"]''') + let s:ruby_flags = substitute(s:ruby_flags, "\n", '', '') + let s:ruby_flags = ' -I' . s:ruby_flags + endif + return s:ruby_flags + endif + return '' +endfunction + +" try to find the python headers with distutils +function! syntastic#c#CheckPython() + if executable('python') + if !exists('s:python_flags') + let s:python_flags = system('python -c ''from distutils import ' + \ . 'sysconfig; import sys; sys.stdout.write(sysconfig.get_python_inc())''') + let s:python_flags = substitute(s:python_flags, "\n", '', '') + let s:python_flags = ' -I' . s:python_flags + endif + return s:python_flags + endif + return '' +endfunction + +" return a handler dictionary object +function! s:RegHandler(regex, function, args) + let handler = {} + let handler["regex"] = a:regex + let handler["func"] = function(a:function) + let handler["args"] = a:args + call add(s:handlers, handler) +endfunction + +call s:Init() + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set et sts=4 sw=4: diff --git a/vim/autoload/tagbar.vim b/vim/autoload/tagbar.vim new file mode 100644 index 0000000..48ad320 --- /dev/null +++ b/vim/autoload/tagbar.vim @@ -0,0 +1,3099 @@ +" ============================================================================ +" File: tagbar.vim +" Description: List the current file's tags in a sidebar, ordered by class etc +" Author: Jan Larres +" Licence: Vim licence +" Website: http://majutsushi.github.com/tagbar/ +" Version: 2.3 +" Note: This plugin was heavily inspired by the 'Taglist' plugin by +" Yegappan Lakshmanan and uses a small amount of code from it. +" +" Original taglist copyright notice: +" Permission is hereby granted to use and distribute this code, +" with or without modifications, provided that this copyright +" notice is copied with it. Like anything else that's free, +" taglist.vim is provided *as is* and comes with no warranty of +" any kind, either expressed or implied. In no event will the +" copyright holder be liable for any damamges resulting from the +" use of this software. +" ============================================================================ + +scriptencoding utf-8 + +" Initialization {{{1 + +" Basic init {{{2 + +if !exists('g:tagbar_ctags_bin') + if executable('ctags-exuberant') + let g:tagbar_ctags_bin = 'ctags-exuberant' + elseif executable('exuberant-ctags') + let g:tagbar_ctags_bin = 'exuberant-ctags' + elseif executable('exctags') + let g:tagbar_ctags_bin = 'exctags' + elseif has('macunix') && executable('/usr/local/bin/ctags') + " Homebrew default location + let g:tagbar_ctags_bin = '/usr/local/bin/ctags' + elseif has('macunix') && executable('/opt/local/bin/ctags') + " Macports default location + let g:tagbar_ctags_bin = '/opt/local/bin/ctags' + elseif executable('ctags') + let g:tagbar_ctags_bin = 'ctags' + elseif executable('ctags.exe') + let g:tagbar_ctags_bin = 'ctags.exe' + elseif executable('tags') + let g:tagbar_ctags_bin = 'tags' + else + echomsg 'Tagbar: Exuberant ctags not found, skipping plugin' + finish + endif +else + " reset 'wildignore' temporarily in case *.exe is included in it + let wildignore_save = &wildignore + set wildignore& + + let g:tagbar_ctags_bin = expand(g:tagbar_ctags_bin) + + let &wildignore = wildignore_save + + if !executable(g:tagbar_ctags_bin) + echomsg 'Tagbar: Exuberant ctags not found in specified place,' + \ 'skipping plugin' + finish + endif +endif + +redir => s:ftype_out +silent filetype +redir END +if s:ftype_out !~# 'detection:ON' + echomsg 'Tagbar: Filetype detection is turned off, skipping plugin' + unlet s:ftype_out + finish +endif +unlet s:ftype_out + +let s:icon_closed = g:tagbar_iconchars[0] +let s:icon_open = g:tagbar_iconchars[1] + +let s:type_init_done = 0 +let s:autocommands_done = 0 +let s:checked_ctags = 0 +let s:window_expanded = 0 + +let s:access_symbols = { + \ 'public' : '+', + \ 'protected' : '#', + \ 'private' : '-' +\ } + +let g:loaded_tagbar = 1 + +let s:last_highlight_tline = 0 +let s:debug = 0 +let s:debug_file = '' + +" s:Init() {{{2 +function! s:Init() + if !s:type_init_done + call s:InitTypes() + endif + + if !s:checked_ctags + if !s:CheckForExCtags() + return + endif + endif +endfunction + +" s:InitTypes() {{{2 +function! s:InitTypes() + call s:LogDebugMessage('Initializing types') + + let s:known_types = {} + + " Ant {{{3 + let type_ant = {} + let type_ant.ctagstype = 'ant' + let type_ant.kinds = [ + \ {'short' : 'p', 'long' : 'projects', 'fold' : 0}, + \ {'short' : 't', 'long' : 'targets', 'fold' : 0} + \ ] + let s:known_types.ant = type_ant + " Asm {{{3 + let type_asm = {} + let type_asm.ctagstype = 'asm' + let type_asm.kinds = [ + \ {'short' : 'm', 'long' : 'macros', 'fold' : 0}, + \ {'short' : 't', 'long' : 'types', 'fold' : 0}, + \ {'short' : 'd', 'long' : 'defines', 'fold' : 0}, + \ {'short' : 'l', 'long' : 'labels', 'fold' : 0} + \ ] + let s:known_types.asm = type_asm + " ASP {{{3 + let type_aspvbs = {} + let type_aspvbs.ctagstype = 'asp' + let type_aspvbs.kinds = [ + \ {'short' : 'd', 'long' : 'constants', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 's', 'long' : 'subroutines', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0} + \ ] + let s:known_types.aspvbs = type_aspvbs + " Awk {{{3 + let type_awk = {} + let type_awk.ctagstype = 'awk' + let type_awk.kinds = [ + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let s:known_types.awk = type_awk + " Basic {{{3 + let type_basic = {} + let type_basic.ctagstype = 'basic' + let type_basic.kinds = [ + \ {'short' : 'c', 'long' : 'constants', 'fold' : 0}, + \ {'short' : 'g', 'long' : 'enumerations', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'l', 'long' : 'labels', 'fold' : 0}, + \ {'short' : 't', 'long' : 'types', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0} + \ ] + let s:known_types.basic = type_basic + " BETA {{{3 + let type_beta = {} + let type_beta.ctagstype = 'beta' + let type_beta.kinds = [ + \ {'short' : 'f', 'long' : 'fragments', 'fold' : 0}, + \ {'short' : 's', 'long' : 'slots', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'patterns', 'fold' : 0} + \ ] + let s:known_types.beta = type_beta + " C {{{3 + let type_c = {} + let type_c.ctagstype = 'c' + let type_c.kinds = [ + \ {'short' : 'd', 'long' : 'macros', 'fold' : 1}, + \ {'short' : 'p', 'long' : 'prototypes', 'fold' : 1}, + \ {'short' : 'g', 'long' : 'enums', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0}, + \ {'short' : 't', 'long' : 'typedefs', 'fold' : 0}, + \ {'short' : 's', 'long' : 'structs', 'fold' : 0}, + \ {'short' : 'u', 'long' : 'unions', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'members', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let type_c.sro = '::' + let type_c.kind2scope = { + \ 'g' : 'enum', + \ 's' : 'struct', + \ 'u' : 'union' + \ } + let type_c.scope2kind = { + \ 'enum' : 'g', + \ 'struct' : 's', + \ 'union' : 'u' + \ } + let s:known_types.c = type_c + " C++ {{{3 + let type_cpp = {} + let type_cpp.ctagstype = 'c++' + let type_cpp.kinds = [ + \ {'short' : 'd', 'long' : 'macros', 'fold' : 1}, + \ {'short' : 'p', 'long' : 'prototypes', 'fold' : 1}, + \ {'short' : 'g', 'long' : 'enums', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0}, + \ {'short' : 't', 'long' : 'typedefs', 'fold' : 0}, + \ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 's', 'long' : 'structs', 'fold' : 0}, + \ {'short' : 'u', 'long' : 'unions', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'members', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0} + \ ] + let type_cpp.sro = '::' + let type_cpp.kind2scope = { + \ 'g' : 'enum', + \ 'n' : 'namespace', + \ 'c' : 'class', + \ 's' : 'struct', + \ 'u' : 'union' + \ } + let type_cpp.scope2kind = { + \ 'enum' : 'g', + \ 'namespace' : 'n', + \ 'class' : 'c', + \ 'struct' : 's', + \ 'union' : 'u' + \ } + let s:known_types.cpp = type_cpp + " C# {{{3 + let type_cs = {} + let type_cs.ctagstype = 'c#' + let type_cs.kinds = [ + \ {'short' : 'd', 'long' : 'macros', 'fold' : 1}, + \ {'short' : 'f', 'long' : 'fields', 'fold' : 0}, + \ {'short' : 'g', 'long' : 'enums', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0}, + \ {'short' : 't', 'long' : 'typedefs', 'fold' : 0}, + \ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0}, + \ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 's', 'long' : 'structs', 'fold' : 0}, + \ {'short' : 'E', 'long' : 'events', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'methods', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'properties', 'fold' : 0} + \ ] + let type_cs.sro = '.' + let type_cs.kind2scope = { + \ 'n' : 'namespace', + \ 'i' : 'interface', + \ 'c' : 'class', + \ 's' : 'struct', + \ 'g' : 'enum' + \ } + let type_cs.scope2kind = { + \ 'namespace' : 'n', + \ 'interface' : 'i', + \ 'class' : 'c', + \ 'struct' : 's', + \ 'enum' : 'g' + \ } + let s:known_types.cs = type_cs + " COBOL {{{3 + let type_cobol = {} + let type_cobol.ctagstype = 'cobol' + let type_cobol.kinds = [ + \ {'short' : 'd', 'long' : 'data items', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'file descriptions', 'fold' : 0}, + \ {'short' : 'g', 'long' : 'group items', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'paragraphs', 'fold' : 0}, + \ {'short' : 'P', 'long' : 'program ids', 'fold' : 0}, + \ {'short' : 's', 'long' : 'sections', 'fold' : 0} + \ ] + let s:known_types.cobol = type_cobol + " DOS Batch {{{3 + let type_dosbatch = {} + let type_dosbatch.ctagstype = 'dosbatch' + let type_dosbatch.kinds = [ + \ {'short' : 'l', 'long' : 'labels', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0} + \ ] + let s:known_types.dosbatch = type_dosbatch + " Eiffel {{{3 + let type_eiffel = {} + let type_eiffel.ctagstype = 'eiffel' + let type_eiffel.kinds = [ + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'features', 'fold' : 0} + \ ] + let type_eiffel.sro = '.' " Not sure, is nesting even possible? + let type_eiffel.kind2scope = { + \ 'c' : 'class', + \ 'f' : 'feature' + \ } + let type_eiffel.scope2kind = { + \ 'class' : 'c', + \ 'feature' : 'f' + \ } + let s:known_types.eiffel = type_eiffel + " Erlang {{{3 + let type_erlang = {} + let type_erlang.ctagstype = 'erlang' + let type_erlang.kinds = [ + \ {'short' : 'm', 'long' : 'modules', 'fold' : 0}, + \ {'short' : 'd', 'long' : 'macro definitions', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'r', 'long' : 'record definitions', 'fold' : 0} + \ ] + let type_erlang.sro = '.' " Not sure, is nesting even possible? + let type_erlang.kind2scope = { + \ 'm' : 'module' + \ } + let type_erlang.scope2kind = { + \ 'module' : 'm' + \ } + let s:known_types.erlang = type_erlang + " Flex {{{3 + " Vim doesn't support Flex out of the box, this is based on rough + " guesses and probably requires + " http://www.vim.org/scripts/script.php?script_id=2909 + " Improvements welcome! + let type_mxml = {} + let type_mxml.ctagstype = 'flex' + let type_mxml.kinds = [ + \ {'short' : 'v', 'long' : 'global variables', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'methods', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'properties', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'x', 'long' : 'mxtags', 'fold' : 0} + \ ] + let type_mxml.sro = '.' + let type_mxml.kind2scope = { + \ 'c' : 'class' + \ } + let type_mxml.scope2kind = { + \ 'class' : 'c' + \ } + let s:known_types.mxml = type_mxml + " Fortran {{{3 + let type_fortran = {} + let type_fortran.ctagstype = 'fortran' + let type_fortran.kinds = [ + \ {'short' : 'm', 'long' : 'modules', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'programs', 'fold' : 0}, + \ {'short' : 'k', 'long' : 'components', 'fold' : 0}, + \ {'short' : 't', 'long' : 'derived types and structures', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'common blocks', 'fold' : 0}, + \ {'short' : 'b', 'long' : 'block data', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'entry points', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 's', 'long' : 'subroutines', 'fold' : 0}, + \ {'short' : 'l', 'long' : 'labels', 'fold' : 0}, + \ {'short' : 'n', 'long' : 'namelists', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0} + \ ] + let type_fortran.sro = '.' " Not sure, is nesting even possible? + let type_fortran.kind2scope = { + \ 'm' : 'module', + \ 'p' : 'program', + \ 'f' : 'function', + \ 's' : 'subroutine' + \ } + let type_fortran.scope2kind = { + \ 'module' : 'm', + \ 'program' : 'p', + \ 'function' : 'f', + \ 'subroutine' : 's' + \ } + let s:known_types.fortran = type_fortran + " HTML {{{3 + let type_html = {} + let type_html.ctagstype = 'html' + let type_html.kinds = [ + \ {'short' : 'f', 'long' : 'JavaScript funtions', 'fold' : 0}, + \ {'short' : 'a', 'long' : 'named anchors', 'fold' : 0} + \ ] + let s:known_types.html = type_html + " Java {{{3 + let type_java = {} + let type_java.ctagstype = 'java' + let type_java.kinds = [ + \ {'short' : 'p', 'long' : 'packages', 'fold' : 1}, + \ {'short' : 'f', 'long' : 'fields', 'fold' : 0}, + \ {'short' : 'g', 'long' : 'enum types', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'enum constants', 'fold' : 0}, + \ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'methods', 'fold' : 0} + \ ] + let type_java.sro = '.' + let type_java.kind2scope = { + \ 'g' : 'enum', + \ 'i' : 'interface', + \ 'c' : 'class' + \ } + let type_java.scope2kind = { + \ 'enum' : 'g', + \ 'interface' : 'i', + \ 'class' : 'c' + \ } + let s:known_types.java = type_java + " JavaScript {{{3 + " JavaScript is weird -- it does have scopes, but ctags doesn't seem to + " properly generate the information for them, instead it simply uses the + " complete name. So ctags has to be fixed before I can do anything here. + " Alternatively jsctags/doctorjs will be used if available. + let type_javascript = {} + let type_javascript.ctagstype = 'javascript' + let jsctags = s:CheckFTCtags('jsctags', 'javascript') + if jsctags != '' + let type_javascript.kinds = [ + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let type_javascript.sro = '.' + let type_javascript.kind2scope = { + \ 'v' : 'namespace', + \ 'f' : 'namespace' + \ } + let type_javascript.scope2kind = { + \ 'namespace' : 'v' + \ } + let type_javascript.ctagsbin = jsctags + let type_javascript.ctagsargs = '-f -' + else + let type_javascript.kinds = [ + \ {'short' : 'v', 'long' : 'global variables', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'properties', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'methods', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + endif + let s:known_types.javascript = type_javascript + " Lisp {{{3 + let type_lisp = {} + let type_lisp.ctagstype = 'lisp' + let type_lisp.kinds = [ + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let s:known_types.lisp = type_lisp + " Lua {{{3 + let type_lua = {} + let type_lua.ctagstype = 'lua' + let type_lua.kinds = [ + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let s:known_types.lua = type_lua + " Make {{{3 + let type_make = {} + let type_make.ctagstype = 'make' + let type_make.kinds = [ + \ {'short' : 'm', 'long' : 'macros', 'fold' : 0} + \ ] + let s:known_types.make = type_make + " Matlab {{{3 + let type_matlab = {} + let type_matlab.ctagstype = 'matlab' + let type_matlab.kinds = [ + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let s:known_types.matlab = type_matlab + " Ocaml {{{3 + let type_ocaml = {} + let type_ocaml.ctagstype = 'ocaml' + let type_ocaml.kinds = [ + \ {'short' : 'M', 'long' : 'modules or functors', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'global variables', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'C', 'long' : 'constructors', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'methods', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'exceptions', 'fold' : 0}, + \ {'short' : 't', 'long' : 'type names', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'r', 'long' : 'structure fields', 'fold' : 0} + \ ] + let type_ocaml.sro = '.' " Not sure, is nesting even possible? + let type_ocaml.kind2scope = { + \ 'M' : 'Module', + \ 'c' : 'class', + \ 't' : 'type' + \ } + let type_ocaml.scope2kind = { + \ 'Module' : 'M', + \ 'class' : 'c', + \ 'type' : 't' + \ } + let s:known_types.ocaml = type_ocaml + " Pascal {{{3 + let type_pascal = {} + let type_pascal.ctagstype = 'pascal' + let type_pascal.kinds = [ + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'procedures', 'fold' : 0} + \ ] + let s:known_types.pascal = type_pascal + " Perl {{{3 + let type_perl = {} + let type_perl.ctagstype = 'perl' + let type_perl.kinds = [ + \ {'short' : 'p', 'long' : 'packages', 'fold' : 1}, + \ {'short' : 'c', 'long' : 'constants', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'formats', 'fold' : 0}, + \ {'short' : 'l', 'long' : 'labels', 'fold' : 0}, + \ {'short' : 's', 'long' : 'subroutines', 'fold' : 0} + \ ] + let s:known_types.perl = type_perl + " PHP {{{3 + let type_php = {} + let type_php.ctagstype = 'php' + let type_php.kinds = [ + \ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'd', 'long' : 'constant definitions', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0}, + \ {'short' : 'j', 'long' : 'javascript functions', 'fold' : 0} + \ ] + let s:known_types.php = type_php + " Python {{{3 + let type_python = {} + let type_python.ctagstype = 'python' + let type_python.kinds = [ + \ {'short' : 'i', 'long' : 'imports', 'fold' : 1}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'members', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0} + \ ] + let type_python.sro = '.' + let type_python.kind2scope = { + \ 'c' : 'class', + \ 'f' : 'function', + \ 'm' : 'function' + \ } + let type_python.scope2kind = { + \ 'class' : 'c', + \ 'function' : 'f' + \ } + let s:known_types.python = type_python + " REXX {{{3 + let type_rexx = {} + let type_rexx.ctagstype = 'rexx' + let type_rexx.kinds = [ + \ {'short' : 's', 'long' : 'subroutines', 'fold' : 0} + \ ] + let s:known_types.rexx = type_rexx + " Ruby {{{3 + let type_ruby = {} + let type_ruby.ctagstype = 'ruby' + let type_ruby.kinds = [ + \ {'short' : 'm', 'long' : 'modules', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'methods', 'fold' : 0}, + \ {'short' : 'F', 'long' : 'singleton methods', 'fold' : 0} + \ ] + let type_ruby.sro = '.' + let type_ruby.kind2scope = { + \ 'c' : 'class', + \ 'm' : 'class' + \ } + let type_ruby.scope2kind = { + \ 'class' : 'c' + \ } + let s:known_types.ruby = type_ruby + " Scheme {{{3 + let type_scheme = {} + let type_scheme.ctagstype = 'scheme' + let type_scheme.kinds = [ + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 's', 'long' : 'sets', 'fold' : 0} + \ ] + let s:known_types.scheme = type_scheme + " Shell script {{{3 + let type_sh = {} + let type_sh.ctagstype = 'sh' + let type_sh.kinds = [ + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let s:known_types.sh = type_sh + let s:known_types.csh = type_sh + let s:known_types.zsh = type_sh + " SLang {{{3 + let type_slang = {} + let type_slang.ctagstype = 'slang' + let type_slang.kinds = [ + \ {'short' : 'n', 'long' : 'namespaces', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0} + \ ] + let s:known_types.slang = type_slang + " SML {{{3 + let type_sml = {} + let type_sml.ctagstype = 'sml' + let type_sml.kinds = [ + \ {'short' : 'e', 'long' : 'exception declarations', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'function definitions', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'functor definitions', 'fold' : 0}, + \ {'short' : 's', 'long' : 'signature declarations', 'fold' : 0}, + \ {'short' : 'r', 'long' : 'structure declarations', 'fold' : 0}, + \ {'short' : 't', 'long' : 'type definitions', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'value bindings', 'fold' : 0} + \ ] + let s:known_types.sml = type_sml + " SQL {{{3 + " The SQL ctags parser seems to be buggy for me, so this just uses the + " normal kinds even though scopes should be available. Improvements + " welcome! + let type_sql = {} + let type_sql.ctagstype = 'sql' + let type_sql.kinds = [ + \ {'short' : 'P', 'long' : 'packages', 'fold' : 1}, + \ {'short' : 'c', 'long' : 'cursors', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'F', 'long' : 'record fields', 'fold' : 0}, + \ {'short' : 'L', 'long' : 'block label', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'procedures', 'fold' : 0}, + \ {'short' : 's', 'long' : 'subtypes', 'fold' : 0}, + \ {'short' : 't', 'long' : 'tables', 'fold' : 0}, + \ {'short' : 'T', 'long' : 'triggers', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0}, + \ {'short' : 'i', 'long' : 'indexes', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'events', 'fold' : 0}, + \ {'short' : 'U', 'long' : 'publications', 'fold' : 0}, + \ {'short' : 'R', 'long' : 'services', 'fold' : 0}, + \ {'short' : 'D', 'long' : 'domains', 'fold' : 0}, + \ {'short' : 'V', 'long' : 'views', 'fold' : 0}, + \ {'short' : 'n', 'long' : 'synonyms', 'fold' : 0}, + \ {'short' : 'x', 'long' : 'MobiLink Table Scripts', 'fold' : 0}, + \ {'short' : 'y', 'long' : 'MobiLink Conn Scripts', 'fold' : 0} + \ ] + let s:known_types.sql = type_sql + " Tcl {{{3 + let type_tcl = {} + let type_tcl.ctagstype = 'tcl' + let type_tcl.kinds = [ + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'methods', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'procedures', 'fold' : 0} + \ ] + let s:known_types.tcl = type_tcl + " LaTeX {{{3 + let type_tex = {} + let type_tex.ctagstype = 'tex' + let type_tex.kinds = [ + \ {'short' : 'p', 'long' : 'parts', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'chapters', 'fold' : 0}, + \ {'short' : 's', 'long' : 'sections', 'fold' : 0}, + \ {'short' : 'u', 'long' : 'subsections', 'fold' : 0}, + \ {'short' : 'b', 'long' : 'subsubsections', 'fold' : 0}, + \ {'short' : 'P', 'long' : 'paragraphs', 'fold' : 0}, + \ {'short' : 'G', 'long' : 'subparagraphs', 'fold' : 0} + \ ] + let s:known_types.tex = type_tex + " Vera {{{3 + " Why are variables 'virtual'? + let type_vera = {} + let type_vera.ctagstype = 'vera' + let type_vera.kinds = [ + \ {'short' : 'd', 'long' : 'macros', 'fold' : 1}, + \ {'short' : 'g', 'long' : 'enums', 'fold' : 0}, + \ {'short' : 'T', 'long' : 'typedefs', 'fold' : 0}, + \ {'short' : 'c', 'long' : 'classes', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'enumerators', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'members', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 't', 'long' : 'tasks', 'fold' : 0}, + \ {'short' : 'v', 'long' : 'variables', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'programs', 'fold' : 0} + \ ] + let type_vera.sro = '.' " Nesting doesn't seem to be possible + let type_vera.kind2scope = { + \ 'g' : 'enum', + \ 'c' : 'class', + \ 'v' : 'virtual' + \ } + let type_vera.scope2kind = { + \ 'enum' : 'g', + \ 'class' : 'c', + \ 'virtual' : 'v' + \ } + let s:known_types.vera = type_vera + " Verilog {{{3 + let type_verilog = {} + let type_verilog.ctagstype = 'verilog' + let type_verilog.kinds = [ + \ {'short' : 'c', 'long' : 'constants', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'events', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'modules', 'fold' : 0}, + \ {'short' : 'n', 'long' : 'net data types', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'ports', 'fold' : 0}, + \ {'short' : 'r', 'long' : 'register data types', 'fold' : 0}, + \ {'short' : 't', 'long' : 'tasks', 'fold' : 0} + \ ] + let s:known_types.verilog = type_verilog + " VHDL {{{3 + " The VHDL ctags parser unfortunately doesn't generate proper scopes + let type_vhdl = {} + let type_vhdl.ctagstype = 'vhdl' + let type_vhdl.kinds = [ + \ {'short' : 'P', 'long' : 'packages', 'fold' : 1}, + \ {'short' : 'c', 'long' : 'constants', 'fold' : 0}, + \ {'short' : 't', 'long' : 'types', 'fold' : 0}, + \ {'short' : 'T', 'long' : 'subtypes', 'fold' : 0}, + \ {'short' : 'r', 'long' : 'records', 'fold' : 0}, + \ {'short' : 'e', 'long' : 'entities', 'fold' : 0}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'p', 'long' : 'procedures', 'fold' : 0} + \ ] + let s:known_types.vhdl = type_vhdl + " Vim {{{3 + let type_vim = {} + let type_vim.ctagstype = 'vim' + let type_vim.kinds = [ + \ {'short' : 'v', 'long' : 'variables', 'fold' : 1}, + \ {'short' : 'f', 'long' : 'functions', 'fold' : 0}, + \ {'short' : 'a', 'long' : 'autocommand groups', 'fold' : 1}, + \ {'short' : 'c', 'long' : 'commands', 'fold' : 0}, + \ {'short' : 'm', 'long' : 'maps', 'fold' : 1} + \ ] + let s:known_types.vim = type_vim + " YACC {{{3 + let type_yacc = {} + let type_yacc.ctagstype = 'yacc' + let type_yacc.kinds = [ + \ {'short' : 'l', 'long' : 'labels', 'fold' : 0} + \ ] + let s:known_types.yacc = type_yacc + " }}}3 + + let user_defs = s:GetUserTypeDefs() + for [key, value] in items(user_defs) + if !has_key(s:known_types, key) || + \ (has_key(value, 'replace') && value.replace) + let s:known_types[key] = value + else + call extend(s:known_types[key], value) + endif + endfor + + " Create a dictionary of the kind order for fast + " access in sorting functions + for type in values(s:known_types) + let i = 0 + let type.kinddict = {} + for kind in type.kinds + let type.kinddict[kind.short] = i + let i += 1 + endfor + endfor + + let s:type_init_done = 1 +endfunction + +" s:GetUserTypeDefs() {{{2 +function! s:GetUserTypeDefs() + call s:LogDebugMessage('Initializing user types') + + redir => defs + silent execute 'let g:' + redir END + + let deflist = split(defs, '\n') + call map(deflist, 'substitute(v:val, ''^\S\+\zs.*'', "", "")') + call filter(deflist, 'v:val =~ "^tagbar_type_"') + + let defdict = {} + for defstr in deflist + let type = substitute(defstr, '^tagbar_type_', '', '') + execute 'let defdict["' . type . '"] = g:' . defstr + endfor + + " If the user only specified one of kind2scope and scope2kind use it to + " generate the other one + " Also, transform the 'kind' definitions into dictionary format + for def in values(defdict) + if has_key(def, 'kinds') + let kinds = def.kinds + let def.kinds = [] + for kind in kinds + let kindlist = split(kind, ':') + let kinddict = {'short' : kindlist[0], 'long' : kindlist[1]} + if len(kindlist) == 3 + let kinddict.fold = kindlist[2] + else + let kinddict.fold = 0 + endif + call add(def.kinds, kinddict) + endfor + endif + + if has_key(def, 'kind2scope') && !has_key(def, 'scope2kind') + let def.scope2kind = {} + for [key, value] in items(def.kind2scope) + let def.scope2kind[value] = key + endfor + elseif has_key(def, 'scope2kind') && !has_key(def, 'kind2scope') + let def.kind2scope = {} + for [key, value] in items(def.scope2kind) + let def.kind2scope[value] = key + endfor + endif + endfor + + return defdict +endfunction + +" s:RestoreSession() {{{2 +" Properly restore Tagbar after a session got loaded +function! s:RestoreSession() + call s:LogDebugMessage('Restoring session') + + let tagbarwinnr = bufwinnr('__Tagbar__') + if tagbarwinnr == -1 + " Tagbar wasn't open in the saved session, nothing to do + return + else + let in_tagbar = 1 + if winnr() != tagbarwinnr + execute tagbarwinnr . 'wincmd w' + let in_tagbar = 0 + endif + endif + + call s:Init() + + call s:InitWindow(g:tagbar_autoclose) + + " Leave the Tagbar window and come back so the update event gets triggered + wincmd p + execute tagbarwinnr . 'wincmd w' + + if !in_tagbar + wincmd p + endif +endfunction + +" s:MapKeys() {{{2 +function! s:MapKeys() + call s:LogDebugMessage('Mapping keys') + + nnoremap ${2} +snippet scriptsrc + ${2} +snippet style + ${3} +snippet base + +snippet r + +snippet div +
+ ${2} +
+# Embed QT Movie +snippet movie + + + + + + ${6} +snippet fieldset +
+ ${1:name} + + ${3} +
+snippet form +
+ ${3} + + +

+
+snippet h1 +

${2:$1}

+snippet input + ${4} +snippet label + ${7} +snippet link + ${4} +snippet mailto + ${3:email me} +snippet meta + ${3} +snippet opt + ${3} +snippet optt + ${2} +snippet select + ${5} +snippet table + + + +
${2:Header}
${3:Data}
${4} +snippet textarea + ${5} diff --git a/vim/snippets/java.snippets b/vim/snippets/java.snippets new file mode 100644 index 0000000..dd96b79 --- /dev/null +++ b/vim/snippets/java.snippets @@ -0,0 +1,95 @@ +snippet main + public static void main (String [] args) + { + ${1:/* code */} + } +snippet pu + public +snippet po + protected +snippet pr + private +snippet st + static +snippet fi + final +snippet ab + abstract +snippet re + return +snippet br + break; +snippet de + default: + ${1} +snippet ca + catch(${1:Exception} ${2:e}) ${3} +snippet th + throw +snippet sy + synchronized +snippet im + import +snippet imp + implements +snippet ext + extends +snippet j.u + java.util +snippet j.i + java.io. +snippet j.b + java.beans. +snippet j.n + java.net. +snippet j.m + java.math. +snippet if + if (${1}) ${2} +snippet el + else +snippet elif + else if (${1}) ${2} +snippet wh + while (${1}) ${2} +snippet for + for (${1}; ${2}; ${3}) ${4} +snippet fore + for (${1} : ${2}) ${3} +snippet sw + switch (${1}) ${2} +snippet cs + case ${1}: + ${2} + ${3} +snippet tc + public class ${1:`Filename()`} extends ${2:TestCase} +snippet t + public void test${1:Name}() throws Exception ${2} +snippet cl + class ${1:`Filename("", "untitled")`} ${2} +snippet in + interface ${1:`Filename("", "untitled")`} ${2:extends Parent}${3} +snippet m + ${1:void} ${2:method}(${3}) ${4:throws }${5} +snippet v + ${1:String} ${2:var}${3: = null}${4};${5} +snippet co + static public final ${1:String} ${2:var} = ${3};${4} +snippet cos + static public final String ${1:var} = "${2}";${3} +snippet as + assert ${1:test} : "${2:Failure message}";${3} +snippet try + try { + ${3} + } catch(${1:Exception} ${2:e}) { + } +snippet tryf + try { + ${3} + } catch(${1:Exception} ${2:e}) { + } finally { + } +snippet rst + ResultSet ${1:rst}${2: = null}${3};${4} diff --git a/vim/snippets/javascript.snippets b/vim/snippets/javascript.snippets new file mode 100644 index 0000000..f869e2f --- /dev/null +++ b/vim/snippets/javascript.snippets @@ -0,0 +1,74 @@ +# Prototype +snippet proto + ${1:class_name}.prototype.${2:method_name} = + function(${3:first_argument}) { + ${4:// body...} + }; +# Function +snippet fun + function ${1:function_name} (${2:argument}) { + ${3:// body...} + } +# Anonymous Function +snippet f + function(${1}) {${2}}; +# if +snippet if + if (${1:true}) {${2}} +# if ... else +snippet ife + if (${1:true}) {${2}} + else{${3}} +# tertiary conditional +snippet t + ${1:/* condition */} ? ${2:a} : ${3:b} +# switch +snippet switch + switch(${1:expression}) { + case '${3:case}': + ${4:// code} + break; + ${5} + default: + ${2:// code} + } +# case +snippet case + case '${1:case}': + ${2:// code} + break; + ${3} +# for (...) {...} +snippet for + for (var ${2:i} = 0; $2 < ${1:Things}.length; $2${3:++}) { + ${4:$1[$2]} + }; +# for (...) {...} (Improved Native For-Loop) +snippet forr + for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2${3:--}) { + ${4:$1[$2]} + }; +# while (...) {...} +snippet wh + while (${1:/* condition */}) { + ${2:/* code */} + } +# do...while +snippet do + do { + ${2:/* code */} + } while (${1:/* condition */}); +# Object Method +snippet :f + ${1:method_name}: function(${2:attribute}) { + ${4} + }${3:,} +# setTimeout function +snippet timeout + setTimeout(function() {${3}}${2}, ${1:10}; +# Get Elements +snippet get + getElementsBy${1:TagName}('${2}')${3} +# Get Element +snippet gett + getElementBy${1:Id}('${2}')${3} diff --git a/vim/snippets/mako.snippets b/vim/snippets/mako.snippets new file mode 100644 index 0000000..2a0aef9 --- /dev/null +++ b/vim/snippets/mako.snippets @@ -0,0 +1,54 @@ +snippet def + <%def name="${1:name}"> + ${2:} + +snippet call + <%call expr="${1:name}"> + ${2:} + +snippet doc + <%doc> + ${1:} + +snippet text + <%text> + ${1:} + +snippet for + % for ${1:i} in ${2:iter}: + ${3:} + % endfor +snippet if if + % if ${1:condition}: + ${2:} + % endif +snippet if if/else + % if ${1:condition}: + ${2:} + % else: + ${3:} + % endif +snippet try + % try: + ${1:} + % except${2:}: + ${3:pass} + % endtry +snippet wh + % while ${1:}: + ${2:} + % endwhile +snippet $ + ${ ${1:} } +snippet <% + <% ${1:} %> +snippet +snippet inherit + <%inherit file="${1:filename}" /> +snippet include + <%include file="${1:filename}" /> +snippet namespace + <%namespace file="${1:name}" /> +snippet page + <%page args="${1:}" /> diff --git a/vim/snippets/objc.snippets b/vim/snippets/objc.snippets new file mode 100644 index 0000000..85b80d9 --- /dev/null +++ b/vim/snippets/objc.snippets @@ -0,0 +1,247 @@ +# #import <...> +snippet Imp + #import <${1:Cocoa/Cocoa.h}>${2} +# #import "..." +snippet imp + #import "${1:`Filename()`.h}"${2} +# @selector(...) +snippet sel + @selector(${1:method}:)${3} +# @"..." string +snippet s + @"${1}"${2} +# Object +snippet o + ${1:NSObject} *${2:foo} = [${3:$1 alloc}]${4};${5} +# NSLog(...) +snippet log + NSLog(@"${1:%@}"${2});${3} +# Class +snippet objc + @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} + { + } + @end + + @implementation $1 + ${3} + @end +# Class Interface +snippet int + @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} + {${3} + } + ${4} + @end +snippet @interface + @interface ${1:`Filename('', 'someClass')`} : ${2:NSObject} + {${3} + } + ${4} + @end +# Class Implementation +snippet impl + @implementation ${1:`Filename('', 'someClass')`} + ${2} + @end +snippet @implementation + @implementation ${1:`Filename('', 'someClass')`} + ${2} + @end +# Protocol +snippet pro + @protocol ${1:`Filename('$1Delegate', 'MyProtocol')`} ${2:} + ${3} + @end +snippet @protocol + @protocol ${1:`Filename('$1Delegate', 'MyProtocol')`} ${2:} + ${3} + @end +# init Definition +snippet init + - (id)init + { + if (self = [super init]) { + ${1} + } + return self; + } +# dealloc Definition +snippet dealloc + - (void) dealloc + { + ${1:deallocations} + [super dealloc]; + } +snippet su + [super ${1:init}]${2} +snippet ibo + IBOutlet ${1:NSSomeClass} *${2:$1};${3} +# Category +snippet cat + @interface ${1:NSObject} (${2:MyCategory}) + @end + + @implementation $1 ($2) + ${3} + @end +# Category Interface +snippet cath + @interface ${1:`Filename('$1', 'NSObject')`} (${2:MyCategory}) + ${3} + @end +# Method +snippet m + - (${1:id})${2:method} + { + ${3} + } +# Method declaration +snippet md + - (${1:id})${2:method};${3} +# IBAction declaration +snippet ibad + - (IBAction)${1:method}:(${2:id})sender;${3} +# IBAction method +snippet iba + - (IBAction)${1:method}:(${2:id})sender + { + ${3} + } +# awakeFromNib method +snippet wake + - (void)awakeFromNib + { + ${1} + } +# Class Method +snippet M + + (${1:id})${2:method} + { + ${3:return nil;} + } +# Sub-method (Call super) +snippet sm + - (${1:id})${2:method} + { + [super $2];${3} + return self; + } +# Accessor Methods For: +# Object +snippet objacc + - (${1:id})${2:thing} + { + return $2; + } + + - (void)set$2:($1)${3:new$2} + { + [$3 retain]; + [$2 release]; + $2 = $3; + }${4} +# for (object in array) +snippet forin + for (${1:Class} *${2:some$1} in ${3:array}) { + ${4} + } +snippet fore + for (${1:object} in ${2:array}) { + ${3:statements} + } +snippet forarray + unsigned int ${1:object}Count = [${2:array} count]; + + for (unsigned int index = 0; index < $1Count; index++) { + ${3:id} $1 = [$2 $1AtIndex:index]; + ${4} + } +snippet fora + unsigned int ${1:object}Count = [${2:array} count]; + + for (unsigned int index = 0; index < $1Count; index++) { + ${3:id} $1 = [$2 $1AtIndex:index]; + ${4} + } +# Try / Catch Block +snippet @try + @try { + ${1:statements} + } + @catch (NSException * e) { + ${2:handler} + } + @finally { + ${3:statements} + } +snippet @catch + @catch (${1:exception}) { + ${2:handler} + } +snippet @finally + @finally { + ${1:statements} + } +# IBOutlet +# @property (Objective-C 2.0) +snippet prop + @property (${1:retain}) ${2:NSSomeClass} ${3:*$2};${4} +# @synthesize (Objective-C 2.0) +snippet syn + @synthesize ${1:property};${2} +# [[ alloc] init] +snippet alloc + [[${1:foo} alloc] init${2}];${3} +snippet a + [[${1:foo} alloc] init${2}];${3} +# retain +snippet ret + [${1:foo} retain];${2} +# release +snippet rel + [${1:foo} release]; +# autorelease +snippet arel + [${1:foo} autorelease]; +# autorelease pool +snippet pool + NSAutoreleasePool *${1:pool} = [[NSAutoreleasePool alloc] init]; + ${2:/* code */} + [$1 drain]; +# Throw an exception +snippet except + NSException *${1:badness}; + $1 = [NSException exceptionWithName:@"${2:$1Name}" + reason:@"${3}" + userInfo:nil]; + [$1 raise]; +snippet prag + #pragma mark ${1:-} +snippet cl + @class ${1:Foo};${2} +snippet color + [[NSColor ${1:blackColor}] set]; +# NSArray +snippet array + NSMutableArray *${1:array} = [NSMutable array];${2} +snippet nsa + NSArray ${1} +snippet nsma + NSMutableArray ${1} +snippet aa + NSArray * array;${1} +snippet ma + NSMutableArray * array;${1} +# NSDictionary +snippet dict + NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary];${2} +snippet nsd + NSDictionary ${1} +snippet nsmd + NSMutableDictionary ${1} +# NSString +snippet nss + NSString ${1} +snippet nsms + NSMutableString ${1} diff --git a/vim/snippets/perl.snippets b/vim/snippets/perl.snippets new file mode 100644 index 0000000..c85ff11 --- /dev/null +++ b/vim/snippets/perl.snippets @@ -0,0 +1,97 @@ +# #!/usr/bin/perl +snippet #! + #!/usr/bin/perl + +# Hash Pointer +snippet . + => +# Function +snippet sub + sub ${1:function_name} { + ${2:#body ...} + } +# Conditional +snippet if + if (${1}) { + ${2:# body...} + } +# Conditional if..else +snippet ife + if (${1}) { + ${2:# body...} + } + else { + ${3:# else...} + } +# Conditional if..elsif..else +snippet ifee + if (${1}) { + ${2:# body...} + } + elsif (${3}) { + ${4:# elsif...} + } + else { + ${5:# else...} + } +# Conditional One-line +snippet xif + ${1:expression} if ${2:condition};${3} +# Unless conditional +snippet unless + unless (${1}) { + ${2:# body...} + } +# Unless conditional One-line +snippet xunless + ${1:expression} unless ${2:condition};${3} +# Try/Except +snippet eval + eval { + ${1:# do something risky...} + }; + if ($@) { + ${2:# handle failure...} + } +# While Loop +snippet wh + while (${1}) { + ${2:# body...} + } +# While Loop One-line +snippet xwh + ${1:expression} while ${2:condition};${3} +# C-style For Loop +snippet cfor + for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) { + ${4:# body...} + } +# For loop one-line +snippet xfor + ${1:expression} for @${2:array};${3} +# Foreach Loop +snippet for + foreach my $${1:x} (@${2:array}) { + ${3:# body...} + } +# Foreach Loop One-line +snippet fore + ${1:expression} foreach @${2:array};${3} +# Package +snippet cl + package ${1:ClassName}; + + use base qw(${2:ParentClass}); + + sub new { + my $class = shift; + $class = ref $class if ref $class; + my $self = bless {}, $class; + $self; + } + + 1;${3} +# Read File +snippet slurp + my $${1:var}; + { local $/ = undef; local *FILE; open FILE, "<${2:file}"; $$1 = ; close FILE }${3} diff --git a/vim/snippets/php.snippets b/vim/snippets/php.snippets new file mode 100644 index 0000000..3ce9e26 --- /dev/null +++ b/vim/snippets/php.snippets @@ -0,0 +1,216 @@ +snippet php + +snippet ec + echo "${1:string}"${2}; +snippet inc + include '${1:file}';${2} +snippet inc1 + include_once '${1:file}';${2} +snippet req + require '${1:file}';${2} +snippet req1 + require_once '${1:file}';${2} +# $GLOBALS['...'] +snippet globals + $GLOBALS['${1:variable}']${2: = }${3:something}${4:;}${5} +snippet $_ COOKIE['...'] + $_COOKIE['${1:variable}']${2} +snippet $_ ENV['...'] + $_ENV['${1:variable}']${2} +snippet $_ FILES['...'] + $_FILES['${1:variable}']${2} +snippet $_ Get['...'] + $_GET['${1:variable}']${2} +snippet $_ POST['...'] + $_POST['${1:variable}']${2} +snippet $_ REQUEST['...'] + $_REQUEST['${1:variable}']${2} +snippet $_ SERVER['...'] + $_SERVER['${1:variable}']${2} +snippet $_ SESSION['...'] + $_SESSION['${1:variable}']${2} +# Start Docblock +snippet /* + /** + * ${1} + **/ +# Class - post doc +snippet doc_cp + /** + * ${1:undocumented class} + * + * @package ${2:default} + * @author ${3:`g:snips_author`} + **/${4} +# Class Variable - post doc +snippet doc_vp + /** + * ${1:undocumented class variable} + * + * @var ${2:string} + **/${3} +# Class Variable +snippet doc_v + /** + * ${3:undocumented class variable} + * + * @var ${4:string} + **/ + ${1:var} $${2};${5} +# Class +snippet doc_c + /** + * ${3:undocumented class} + * + * @packaged ${4:default} + * @author ${5:`g:snips_author`} + **/ + ${1:}class ${2:} + {${6} + } // END $1class $2 +# Constant Definition - post doc +snippet doc_dp + /** + * ${1:undocumented constant} + **/${2} +# Constant Definition +snippet doc_d + /** + * ${3:undocumented constant} + **/ + define(${1}, ${2});${4} +# Function - post doc +snippet doc_fp + /** + * ${1:undocumented function} + * + * @return ${2:void} + * @author ${3:`g:snips_author`} + **/${4} +# Function signature +snippet doc_s + /** + * ${4:undocumented function} + * + * @return ${5:void} + * @author ${6:`g:snips_author`} + **/ + ${1}function ${2}(${3});${7} +# Function +snippet doc_f + /** + * ${4:undocumented function} + * + * @return ${5:void} + * @author ${6:`g:snips_author`} + **/ + ${1}function ${2}(${3}) + {${7} + } +# Header +snippet doc_h + /** + * ${1} + * + * @author ${2:`g:snips_author`} + * @version ${3:$Id$} + * @copyright ${4:$2}, `strftime('%d %B, %Y')` + * @package ${5:default} + **/ + + /** + * Define DocBlock + *// +# Interface +snippet doc_i + /** + * ${2:undocumented class} + * + * @package ${3:default} + * @author ${4:`g:snips_author`} + **/ + interface ${1:} + {${5} + } // END interface $1 +# class ... +snippet class + /** + * ${1} + **/ + class ${2:ClassName} + { + ${3} + function ${4:__construct}(${5:argument}) + { + ${6:// code...} + } + } +# define(...) +snippet def + define('${1}'${2});${3} +# defined(...) +snippet def? + ${1}defined('${2}')${3} +snippet wh + while (${1:/* condition */}) { + ${2:// code...} + } +# do ... while +snippet do + do { + ${2:// code... } + } while (${1:/* condition */}); +snippet if + if (${1:/* condition */}) { + ${2:// code...} + } +snippet ife + if (${1:/* condition */}) { + ${2:// code...} + } else { + ${3:// code...} + } + ${4} +snippet else + else { + ${1:// code...} + } +snippet elseif + elseif (${1:/* condition */}) { + ${2:// code...} + } +# Tertiary conditional +snippet t + $${1:retVal} = (${2:condition}) ? ${3:a} : ${4:b};${5} +snippet switch + switch ($${1:variable}) { + case '${2:value}': + ${3:// code...} + break; + ${5} + default: + ${4:// code...} + break; + } +snippet case + case '${1:value}': + ${2:// code...} + break;${3} +snippet for + for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) { + ${4: // code...} + } +snippet foreach + foreach ($${1:variable} as $${2:key}) { + ${3:// code...} + } +snippet fun + ${1:public }function ${2:FunctionName}(${3}) + { + ${4:// code...} + } +# $... = array (...) +snippet array + $${1:arrayName} = array('${2}' => ${3});${4} diff --git a/vim/snippets/puppet.snippets b/vim/snippets/puppet.snippets new file mode 100644 index 0000000..1bb62d0 --- /dev/null +++ b/vim/snippets/puppet.snippets @@ -0,0 +1,82 @@ +# vim: nofoldenable foldmethod=manual +snippet file + file { + "${1:filename}": + ensure => "${3:file}", + source => "puppet:///${2:source}", + owner => "${4:root}", + group => "${5:root}", + mode => '${6:0755}'; + } +snippet exec + exec { + "${1:name}": + command => "${2:command}", + refreshonly => "${3:true}", + onlyif => "${4:run_if_true}", + unless => "${5:run_if_false}", + } +snippet encap + encap { + "${1:package_name}": + ensure => "${2:package_version}"; + } +snippet package + package { + "${1:package_name}": + ensure => "${2:installed}"; + provider => "yum", + } +snippet tidy + tidy { + "${1:directory}": + age => "${2:0}", + matches => [ "${3:pattern}" ], + recurse => "${4:true}", + rmdirs => "${5:true}"; + } +snippet cron + cron { + "${1:name}": + command => "${2:command}", + hour => ${3:hour}, + minute => ${4:minute}, + day => ${5:day}; + } +snippet class + # Class:: $1 + # + # + class ${1:classname} { + ${2:#code...} + } # Class:: $1 +snippet def + # Define:: $1 + # Args:: $2 + # + define ${1:defname}(${2:args}) { + ${3:#code} + } # Define: $1 +snippet inc + include "${1}" +snippet #head + # Module:: ${1:modulename} + # Manifest:: ${2:init.pp} + # + # Author:: `system("git config user.name")` (<`system("git config user.email")`>) + # Date:: `system("ruby -e 'puts Time.now'")` + # + ${3} +snippet #class + # Module:: ${1:modulename} + # Class: ${2:classname} + # + # ${3:description} + # + # Author:: `system("git config user.name")` (<`system("git config user.email")`>) + # Date:: `system("ruby -e 'puts Time.now'")` + # + class $1::$2 + { + + } diff --git a/vim/snippets/python.snippets b/vim/snippets/python.snippets new file mode 100644 index 0000000..28a2948 --- /dev/null +++ b/vim/snippets/python.snippets @@ -0,0 +1,86 @@ +snippet #! + #!/usr/bin/env python + +snippet imp + import ${1:module} +# Module Docstring +snippet docs + ''' + File: ${1:`Filename('$1.py', 'foo.py')`} + Author: ${2:`g:snips_author`} + Description: ${3} + ''' +snippet wh + while ${1:condition}: + ${2:# code...} +snippet for + for ${1:needle} in ${2:haystack}: + ${3:# code...} +# New Class +snippet cl + class ${1:ClassName}(${2:object}): + """${3:docstring for $1}""" + def __init__(self, ${4:arg}): + ${5:super($1, self).__init__()} + self.$4 = $4 + ${6} +# New Function +snippet def + def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): + """${3:docstring for $1}""" + ${4:pass} +snippet deff + def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): + ${3} +# New Method +snippet defs + def ${1:mname}(self, ${2:arg}): + ${3:pass} +# New Property +snippet property + def ${1:foo}(): + doc = "${2:The $1 property.}" + def fget(self): + ${3:return self._$1} + def fset(self, value): + ${4:self._$1 = value} +# Lambda +snippet ld + ${1:var} = lambda ${2:vars} : ${3:action} +snippet . + self. +snippet try Try/Except + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} +snippet try Try/Except/Else + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} + else: + ${5:pass} +snippet try Try/Except/Finally + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} + finally: + ${5:pass} +snippet try Try/Except/Else/Finally + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} + else: + ${5:pass} + finally: + ${6:pass} +# if __name__ == '__main__': +snippet ifmain + if __name__ == '__main__': + ${1:main()} +# __magic__ +snippet _ + __${1:init}__${2} diff --git a/vim/snippets/ruby.snippets b/vim/snippets/ruby.snippets new file mode 100644 index 0000000..50080d9 --- /dev/null +++ b/vim/snippets/ruby.snippets @@ -0,0 +1,504 @@ +# #!/usr/bin/env ruby +snippet #! + #!/usr/bin/env ruby + +# New Block +snippet =b + =begin rdoc + ${1} + =end +snippet y + :yields: ${1:arguments} +snippet rb + #!/usr/bin/env ruby -wKU +snippet beg + begin + ${3} + rescue ${1:Exception} => ${2:e} + end + +snippet req + require "${1}"${2} +snippet # + # => +snippet end + __END__ +snippet case + case ${1:object} + when ${2:condition} + ${3} + end +snippet when + when ${1:condition} + ${2} +snippet def + def ${1:method_name} + ${2} + end +snippet deft + def test_${1:case_name} + ${2} + end +snippet if + if ${1:condition} + ${2} + end +snippet ife + if ${1:condition} + ${2} + else + ${3} + end +snippet elsif + elsif ${1:condition} + ${2} +snippet unless + unless ${1:condition} + ${2} + end +snippet while + while ${1:condition} + ${2} + end +snippet for + for ${1:e} in ${2:c} + ${3} + end +snippet until + until ${1:condition} + ${2} + end +snippet cla class .. end + class ${1:`substitute(Filename(), '^.', '\u&', '')`} + ${2} + end +snippet cla class .. initialize .. end + class ${1:`substitute(Filename(), '^.', '\u&', '')`} + def initialize(${2:args}) + ${3} + end + + + end +snippet cla class .. < ParentClass .. initialize .. end + class ${1:`substitute(Filename(), '^.', '\u&', '')`} < ${2:ParentClass} + def initialize(${3:args}) + ${4} + end + + + end +snippet cla ClassName = Struct .. do .. end + ${1:`substitute(Filename(), '^.', '\u&', '')`} = Struct.new(:${2:attr_names}) do + def ${3:method_name} + ${4} + end + + + end +snippet cla class BlankSlate .. initialize .. end + class ${1:BlankSlate} + instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ } +snippet cla class << self .. end + class << ${1:self} + ${2} + end +# class .. < DelegateClass .. initialize .. end +snippet cla- + class ${1:`substitute(Filename(), '^.', '\u&', '')`} < DelegateClass(${2:ParentClass}) + def initialize(${3:args}) + super(${4:del_obj}) + + ${5} + end + + + end +snippet mod module .. end + module ${1:`substitute(Filename(), '^.', '\u&', '')`} + ${2} + end +snippet mod module .. module_function .. end + module ${1:`substitute(Filename(), '^.', '\u&', '')`} + module_function + + ${2} + end +snippet mod module .. ClassMethods .. end + module ${1:`substitute(Filename(), '^.', '\u&', '')`} + module ClassMethods + ${2} + end + + module InstanceMethods + + end + + def self.included(receiver) + receiver.extend ClassMethods + receiver.send :include, InstanceMethods + end + end +# attr_reader +snippet r + attr_reader :${1:attr_names} +# attr_writer +snippet w + attr_writer :${1:attr_names} +# attr_accessor +snippet rw + attr_accessor :${1:attr_names} +# include Enumerable +snippet Enum + include Enumerable + + def each(&block) + ${1} + end +# include Comparable +snippet Comp + include Comparable + + def <=>(other) + ${1} + end +# extend Forwardable +snippet Forw- + extend Forwardable +# def self +snippet defs + def self.${1:class_method_name} + ${2} + end +# def method_missing +snippet defmm + def method_missing(meth, *args, &blk) + ${1} + end +snippet defd + def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name} +snippet defds + def_delegators :${1:@del_obj}, :${2:del_methods} +snippet am + alias_method :${1:new_name}, :${2:old_name} +snippet app + if __FILE__ == $PROGRAM_NAME + ${1} + end +# usage_if() +snippet usai + if ARGV.${1} + abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3} + end +# usage_unless() +snippet usau + unless ARGV.${1} + abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${3} + end +snippet array + Array.new(${1:10}) { |${2:i}| ${3} } +snippet hash + Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${3} } +snippet file File.foreach() { |line| .. } + File.foreach(${1:"path/to/file"}) { |${2:line}| ${3} } +snippet file File.read() + File.read(${1:"path/to/file"})${2} +snippet Dir Dir.global() { |file| .. } + Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${3} } +snippet Dir Dir[".."] + Dir[${1:"glob/**/*.rb"}]${2} +snippet dir + Filename.dirname(__FILE__) +snippet deli + delete_if { |${1:e}| ${2} } +snippet fil + fill(${1:range}) { |${2:i}| ${3} } +# flatten_once() +snippet flao + inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}${3} +snippet zip + zip(${1:enums}) { |${2:row}| ${3} } +# downto(0) { |n| .. } +snippet dow + downto(${1:0}) { |${2:n}| ${3} } +snippet ste + step(${1:2}) { |${2:n}| ${3} } +snippet tim + times { |${1:n}| ${2} } +snippet upt + upto(${1:1.0/0.0}) { |${2:n}| ${3} } +snippet loo + loop { ${1} } +snippet ea + each { |${1:e}| ${2} } +snippet ead + each do |${1:e}| + ${2} + end +snippet eab + each_byte { |${1:byte}| ${2} } +snippet eac- each_char { |chr| .. } + each_char { |${1:chr}| ${2} } +snippet eac- each_cons(..) { |group| .. } + each_cons(${1:2}) { |${2:group}| ${3} } +snippet eai + each_index { |${1:i}| ${2} } +snippet eaid + each_index do |${1:i}| + end +snippet eak + each_key { |${1:key}| ${2} } +snippet eakd + each_key do |${1:key}| + ${2} + end +snippet eal + each_line { |${1:line}| ${2} } +snippet eald + each_line do |${1:line}| + ${2} + end +snippet eap + each_pair { |${1:name}, ${2:val}| ${3} } +snippet eapd + each_pair do |${1:name}, ${2:val}| + ${3} + end +snippet eas- + each_slice(${1:2}) { |${2:group}| ${3} } +snippet easd- + each_slice(${1:2}) do |${2:group}| + ${3} + end +snippet eav + each_value { |${1:val}| ${2} } +snippet eavd + each_value do |${1:val}| + ${2} + end +snippet eawi + each_with_index { |${1:e}, ${2:i}| ${3} } +snippet eawid + each_with_index do |${1:e},${2:i}| + ${3} + end +snippet reve + reverse_each { |${1:e}| ${2} } +snippet reved + reverse_each do |${1:e}| + ${2} + end +snippet inj + inject(${1:init}) { |${2:mem}, ${3:var}| ${4} } +snippet injd + inject(${1:init}) do |${2:mem}, ${3:var}| + ${4} + end +snippet map + map { |${1:e}| ${2} } +snippet mapd + map do |${1:e}| + ${2} + end +snippet mapwi- + enum_with_index.map { |${1:e}, ${2:i}| ${3} } +snippet sor + sort { |a, b| ${1} } +snippet sorb + sort_by { |${1:e}| ${2} } +snippet ran + sort_by { rand } +snippet all + all? { |${1:e}| ${2} } +snippet any + any? { |${1:e}| ${2} } +snippet cl + classify { |${1:e}| ${2} } +snippet col + collect { |${1:e}| ${2} } +snippet cold + collect do |${1:e}| + ${2} + end +snippet det + detect { |${1:e}| ${2} } +snippet detd + detect do |${1:e}| + ${2} + end +snippet fet + fetch(${1:name}) { |${2:key}| ${3} } +snippet fin + find { |${1:e}| ${2} } +snippet find + find do |${1:e}| + ${2} + end +snippet fina + find_all { |${1:e}| ${2} } +snippet finad + find_all do |${1:e}| + ${2} + end +snippet gre + grep(${1:/pattern/}) { |${2:match}| ${3} } +snippet sub + ${1:g}sub(${2:/pattern/}) { |${3:match}| ${4} } +snippet sca + scan(${1:/pattern/}) { |${2:match}| ${3} } +snippet scad + scan(${1:/pattern/}) do |${2:match}| + ${3} + end +snippet max + max { |a, b| ${1} } +snippet min + min { |a, b| ${1} } +snippet par + partition { |${1:e}| ${2} } +snippet pard + partition do |${1:e}| + ${2} + end +snippet rej + reject { |${1:e}| ${2} } +snippet rejd + reject do |${1:e}| + ${2} + end +snippet sel + select { |${1:e}| ${2} } +snippet seld + select do |${1:e}| + ${2} + end +snippet lam + lambda { |${1:args}| ${2} } +snippet do + do |${1:variable}| + ${2} + end +snippet : + :${1:key} => ${2:"value"}${3} +snippet ope + open(${1:"path/or/url/or/pipe"}, "${2:w}") { |${3:io}| ${4} } +# path_from_here() +snippet patfh + File.join(File.dirname(__FILE__), *%2[${1:rel path here}])${2} +# unix_filter {} +snippet unif + ARGF.each_line${1} do |${2:line}| + ${3} + end +# option_parse {} +snippet optp + require "optparse" + + options = {${1:default => "args"}} + + ARGV.options do |opts| + opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} +snippet opt + opts.on( "-${1:o}", "--${2:long-option-name}", ${3:String}, + "${4:Option description.}") do |${5:opt}| + ${6} + end +snippet tc + require "test/unit" + + require "${1:library_file_name}" + + class Test${2:$1} < Test::Unit::TestCase + def test_${3:case_name} + ${4} + end + end +snippet ts + require "test/unit" + + require "tc_${1:test_case_file}" + require "tc_${2:test_case_file}"${3} +snippet as + assert(${1:test}, "${2:Failure message.}")${3} +snippet ase + assert_equal(${1:expected}, ${2:actual})${3} +snippet asne + assert_not_equal(${1:unexpected}, ${2:actual})${3} +snippet asid + assert_in_delta(${1:expected_float}, ${2:actual_float}, ${3:2 ** -20})${4} +snippet asio + assert_instance_of(${1:ExpectedClass}, ${2:actual_instance})${3} +snippet asko + assert_kind_of(${1:ExpectedKind}, ${2:actual_instance})${3} +snippet asn + assert_nil(${1:instance})${2} +snippet asnn + assert_not_nil(${1:instance})${2} +snippet asm + assert_match(/${1:expected_pattern}/, ${2:actual_string})${3} +snippet asnm + assert_no_match(/${1:unexpected_pattern}/, ${2:actual_string})${3} +snippet aso + assert_operator(${1:left}, :${2:operator}, ${3:right})${4} +snippet asr + assert_raise(${1:Exception}) { ${2} } +snippet asnr + assert_nothing_raised(${1:Exception}) { ${2} } +snippet asrt + assert_respond_to(${1:object}, :${2:method})${3} +snippet ass assert_same(..) + assert_same(${1:expected}, ${2:actual})${3} +snippet ass assert_send(..) + assert_send([${1:object}, :${2:message}, ${3:args}])${4} +snippet asns + assert_not_same(${1:unexpected}, ${2:actual})${3} +snippet ast + assert_throws(:${1:expected}) { ${2} } +snippet asnt + assert_nothing_thrown { ${1} } +snippet fl + flunk("${1:Failure message.}")${2} +# Benchmark.bmbm do .. end +snippet bm- + TESTS = ${1:10_000} + Benchmark.bmbm do |results| + ${2} + end +snippet rep + results.report("${1:name}:") { TESTS.times { ${2} }} +# Marshal.dump(.., file) +snippet Md + File.open(${1:"path/to/file.dump"}, "wb") { |${2:file}| Marshal.dump(${3:obj}, $2) }${4} +# Mashal.load(obj) +snippet Ml + File.open(${1:"path/to/file.dump"}, "rb") { |${2:file}| Marshal.load($2) }${3} +# deep_copy(..) +snippet deec + Marshal.load(Marshal.dump(${1:obj_to_copy}))${2} +snippet Pn- + PStore.new(${1:"file_name.pstore"})${2} +snippet tra + transaction(${1:true}) { ${2} } +# xmlread(..) +snippet xml- + REXML::Document.new(File.read(${1:"path/to/file"}))${2} +# xpath(..) { .. } +snippet xpa + elements.each(${1:"//Xpath"}) do |${2:node}| + ${3} + end +# class_from_name() +snippet clafn + split("::").inject(Object) { |par, const| par.const_get(const) } +# singleton_class() +snippet sinc + class << self; self end +snippet nam + namespace :${1:`Filename()`} do + ${2} + end +snippet tas + desc "${1:Task description\}" + task :${2:task_name => [:dependent, :tasks]} do + ${3} + end diff --git a/vim/snippets/sh.snippets b/vim/snippets/sh.snippets new file mode 100644 index 0000000..f035126 --- /dev/null +++ b/vim/snippets/sh.snippets @@ -0,0 +1,28 @@ +# #!/bin/bash +snippet #! + #!/bin/bash + +snippet if + if [[ ${1:condition} ]]; then + ${2:#statements} + fi +snippet elif + elif [[ ${1:condition} ]]; then + ${2:#statements} +snippet for + for (( ${2:i} = 0; $2 < ${1:count}; $2++ )); do + ${3:#statements} + done +snippet wh + while [[ ${1:condition} ]]; do + ${2:#statements} + done +snippet until + until [[ ${1:condition} ]]; do + ${2:#statements} + done +snippet case + case ${1:word} in + ${2:pattern}) + ${3};; + esac diff --git a/vim/snippets/snippet.snippets b/vim/snippets/snippet.snippets new file mode 100644 index 0000000..854c058 --- /dev/null +++ b/vim/snippets/snippet.snippets @@ -0,0 +1,7 @@ +# snippets for making snippets :) +snippet snip + snippet ${1:trigger} + ${2} +snippet msnip + snippet ${1:trigger} ${2:description} + ${3} diff --git a/vim/snippets/tcl.snippets b/vim/snippets/tcl.snippets new file mode 100644 index 0000000..1fe1cb9 --- /dev/null +++ b/vim/snippets/tcl.snippets @@ -0,0 +1,92 @@ +# #!/usr/bin/env tclsh +snippet #! + #!/usr/bin/env tclsh + +# Process +snippet pro + proc ${1:function_name} {${2:args}} { + ${3:#body ...} + } +#xif +snippet xif + ${1:expr}? ${2:true} : ${3:false} +# Conditional +snippet if + if {${1}} { + ${2:# body...} + } +# Conditional if..else +snippet ife + if {${1}} { + ${2:# body...} + } else { + ${3:# else...} + } +# Conditional if..elsif..else +snippet ifee + if {${1}} { + ${2:# body...} + } elseif {${3}} { + ${4:# elsif...} + } else { + ${5:# else...} + } +# If catch then +snippet ifc + if { [catch {${1:#do something...}} ${2:err}] } { + ${3:# handle failure...} + } +# Catch +snippet catch + catch {${1}} ${2:err} ${3:options} +# While Loop +snippet wh + while {${1}} { + ${2:# body...} + } +# For Loop +snippet for + for {set ${2:var} 0} {$$2 < ${1:count}} {${3:incr} $2} { + ${4:# body...} + } +# Foreach Loop +snippet fore + foreach ${1:x} {${2:#list}} { + ${3:# body...} + } +# after ms script... +snippet af + after ${1:ms} ${2:#do something} +# after cancel id +snippet afc + after cancel ${1:id or script} +# after idle +snippet afi + after idle ${1:script} +# after info id +snippet afin + after info ${1:id} +# Expr +snippet exp + expr {${1:#expression here}} +# Switch +snippet sw + switch ${1:var} { + ${3:pattern 1} { + ${4:#do something} + } + default { + ${2:#do something} + } + } +# Case +snippet ca + ${1:pattern} { + ${2:#do something} + }${3} +# Namespace eval +snippet ns + namespace eval ${1:path} {${2:#script...}} +# Namespace current +snippet nsc + namespace current diff --git a/vim/snippets/tex.snippets b/vim/snippets/tex.snippets new file mode 100644 index 0000000..22f7316 --- /dev/null +++ b/vim/snippets/tex.snippets @@ -0,0 +1,115 @@ +# \begin{}...\end{} +snippet begin + \begin{${1:env}} + ${2} + \end{$1} +# Tabular +snippet tab + \begin{${1:tabular}}{${2:c}} + ${3} + \end{$1} +# Align(ed) +snippet ali + \begin{align${1:ed}} + ${2} + \end{align$1} +# Gather(ed) +snippet gat + \begin{gather${1:ed}} + ${2} + \end{gather$1} +# Equation +snippet eq + \begin{equation} + ${1} + \end{equation} +# Unnumbered Equation +snippet \ + \\[ + ${1} + \\] +# Enumerate +snippet enum + \begin{enumerate} + \item ${1} + \end{enumerate} +# Itemize +snippet item + \begin{itemize} + \item ${1} + \end{itemize} +# Description +snippet desc + \begin{description} + \item[${1}] ${2} + \end{description} +# Matrix +snippet mat + \begin{${1:p/b/v/V/B/small}matrix} + ${2} + \end{$1matrix} +# Cases +snippet cas + \begin{cases} + ${1:equation}, &\text{ if }${2:case}\\ + ${3} + \end{cases} +# Split +snippet spl + \begin{split} + ${1} + \end{split} +# Part +snippet part + \part{${1:part name}} % (fold) + \label{prt:${2:$1}} + ${3} + % part $2 (end) +# Chapter +snippet cha + \chapter{${1:chapter name}} % (fold) + \label{cha:${2:$1}} + ${3} + % chapter $2 (end) +# Section +snippet sec + \section{${1:section name}} % (fold) + \label{sec:${2:$1}} + ${3} + % section $2 (end) +# Sub Section +snippet sub + \subsection{${1:subsection name}} % (fold) + \label{sub:${2:$1}} + ${3} + % subsection $2 (end) +# Sub Sub Section +snippet subs + \subsubsection{${1:subsubsection name}} % (fold) + \label{ssub:${2:$1}} + ${3} + % subsubsection $2 (end) +# Paragraph +snippet par + \paragraph{${1:paragraph name}} % (fold) + \label{par:${2:$1}} + ${3} + % paragraph $2 (end) +# Sub Paragraph +snippet subp + \subparagraph{${1:subparagraph name}} % (fold) + \label{subp:${2:$1}} + ${3} + % subparagraph $2 (end) +snippet itd + \item[${1:description}] ${2:item} +snippet figure + ${1:Figure}~\ref{${2:fig:}}${3} +snippet table + ${1:Table}~\ref{${2:tab:}}${3} +snippet listing + ${1:Listing}~\ref{${2:list}}${3} +snippet section + ${1:Section}~\ref{${2:sec:}}${3} +snippet page + ${1:page}~\pageref{${2}}${3} diff --git a/vim/snippets/vim.snippets b/vim/snippets/vim.snippets new file mode 100644 index 0000000..64e7807 --- /dev/null +++ b/vim/snippets/vim.snippets @@ -0,0 +1,32 @@ +snippet header + " File: ${1:`expand('%:t')`} + " Author: ${2:`g:snips_author`} + " Description: ${3} + ${4:" Last Modified: `strftime("%B %d, %Y")`} +snippet guard + if exists('${1:did_`Filename()`}') || &cp${2: || version < 700} + finish + endif + let $1 = 1${3} +snippet f + fun ${1:function_name}(${2}) + ${3:" code} + endf +snippet for + for ${1:needle} in ${2:haystack} + ${3:" code} + endfor +snippet wh + while ${1:condition} + ${2:" code} + endw +snippet if + if ${1:condition} + ${2:" code} + endif +snippet ife + if ${1:condition} + ${2} + else + ${3} + endif diff --git a/vim/snippets/zsh.snippets b/vim/snippets/zsh.snippets new file mode 100644 index 0000000..7aee05b --- /dev/null +++ b/vim/snippets/zsh.snippets @@ -0,0 +1,58 @@ +# #!/bin/zsh +snippet #! + #!/bin/zsh + +snippet if + if ${1:condition}; then + ${2:# statements} + fi +snippet ife + if ${1:condition}; then + ${2:# statements} + else + ${3:# statements} + fi +snippet elif + elif ${1:condition} ; then + ${2:# statements} +snippet for + for (( ${2:i} = 0; $2 < ${1:count}; $2++ )); do + ${3:# statements} + done +snippet fore + for ${1:item} in ${2:list}; do + ${3:# statements} + done +snippet wh + while ${1:condition}; do + ${2:# statements} + done +snippet until + until ${1:condition}; do + ${2:# statements} + done +snippet repeat + repeat ${1:integer}; do + ${2:# statements} + done +snippet case + case ${1:word} in + ${2:pattern}) + ${3};; + esac +snippet select + select ${1:answer} in ${2:choices}; do + ${3:# statements} + done +snippet ( + ( ${1:#statements} ) +snippet { + { ${1:#statements} } +snippet [ + [[ ${1:test} ]] +snippet always + { ${1:try} } always { ${2:always} } +snippet fun + function ${1:name} (${2:args}) { + ${3:# body} + } diff --git a/vim/syntax/arduino.vim b/vim/syntax/arduino.vim new file mode 100644 index 0000000..fb52283 --- /dev/null +++ b/vim/syntax/arduino.vim @@ -0,0 +1,57 @@ +" Vim syntax file +" Language: Arduino +" Maintainer: Johannes Hoff +" Last Change: 06 June 2011 +" License: VIM license (:help license, replace vim by arduino.vim) + +" Syntax highlighting like in the Arduino IDE +" Automatically generated by the script available at +" https://bitbucket.org/johannes/arduino-vim-syntax +" Using keywords from /build/shared/lib/keywords.txt +" From version: ARDUINO 0022 - 2010.12.24 + +" Thanks to Rik, Erik Nomitch, Adam Obeng and Graeme Cross for helpful feedback! + +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" Read the C syntax to start with +if version < 600 + so :p:h/cpp.vim +else + runtime! syntax/cpp.vim +endif + +syn keyword arduinoConstant BIN BYTE CHANGE DEC DEFAULT EXTERNAL FALLING HALF_PI +syn keyword arduinoConstant HEX HIGH INPUT INTERNAL INTERNAL1V1 INTERNAL2V56 +syn keyword arduinoConstant LOW LSBFIRST MSBFIRST OCT OUTPUT PI RISING TWO_PI + +syn keyword arduinoFunc analogRead analogReference analogWrite +syn keyword arduinoFunc attachInterrupt bit bitClear bitRead bitSet +syn keyword arduinoFunc bitWrite delay delayMicroseconds detachInterrupt +syn keyword arduinoFunc digitalRead digitalWrite highByte interrupts +syn keyword arduinoFunc lowByte micros millis noInterrupts noTone pinMode +syn keyword arduinoFunc pulseIn shiftIn shiftOut tone + +syn keyword arduinoMethod available begin end flush loop peek print println +syn keyword arduinoMethod read setup + +syn keyword arduinoModule Serial Serial1 Serial2 Serial3 + +syn keyword arduinoStdFunc abs acos asin atan atan2 ceil constrain cos degrees +syn keyword arduinoStdFunc exp floor log map max min radians random randomSeed +syn keyword arduinoStdFunc round sin sq sqrt tan + +syn keyword arduinoType boolean byte null String word + +hi def link arduinoType Type +hi def link arduinoConstant Constant +hi def link arduinoStdFunc Function +hi def link arduinoFunc Function +hi def link arduinoMethod Function +hi def link arduinoModule Identifier diff --git a/vim/syntax/coffee.vim b/vim/syntax/coffee.vim new file mode 100755 index 0000000..ff2cd12 --- /dev/null +++ b/vim/syntax/coffee.vim @@ -0,0 +1,237 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +" Bail if our syntax is already loaded. +if exists('b:current_syntax') && b:current_syntax == 'coffee' + finish +endif + +if version < 600 + syn clear +endif + +" Include JavaScript for coffeeEmbed. +syn include @coffeeJS syntax/javascript.vim + +" Highlight long strings. +syn sync minlines=100 + +" CoffeeScript identifiers can have dollar signs. +setlocal isident+=$ + +" These are `matches` instead of `keywords` because vim's highlighting +" priority for keywords is higher than matches. This causes keywords to be +" highlighted inside matches, even if a match says it shouldn't contain them -- +" like with coffeeAssign and coffeeDot. +syn match coffeeStatement /\<\%(return\|break\|continue\|throw\)\>/ display +hi def link coffeeStatement Statement + +syn match coffeeRepeat /\<\%(for\|while\|until\|loop\)\>/ display +hi def link coffeeRepeat Repeat + +syn match coffeeConditional /\<\%(if\|else\|unless\|switch\|when\|then\)\>/ +\ display +hi def link coffeeConditional Conditional + +syn match coffeeException /\<\%(try\|catch\|finally\)\>/ display +hi def link coffeeException Exception + +syn match coffeeKeyword /\<\%(new\|in\|of\|by\|and\|or\|not\|is\|isnt\|class\|extends\|super\|own\|do\)\>/ +\ display +hi def link coffeeKeyword Keyword + +syn match coffeeOperator /\<\%(instanceof\|typeof\|delete\)\>/ display +hi def link coffeeOperator Operator + +" The first case matches symbol operators only if they have an operand before. +syn match coffeeExtendedOp /\%(\S\s*\)\@<=[+\-*/%&|\^=!<>?.]\+\|--\|++\|::/ +\ display +syn match coffeeExtendedOp /\%(and\|or\)=/ display +hi def link coffeeExtendedOp coffeeOperator + +" This is separate from `coffeeExtendedOp` to help differentiate commas from +" dots. +syn match coffeeSpecialOp /[,;]/ display +hi def link coffeeSpecialOp SpecialChar + +syn match coffeeBoolean /\<\%(true\|on\|yes\|false\|off\|no\)\>/ display +hi def link coffeeBoolean Boolean + +syn match coffeeGlobal /\<\%(null\|undefined\)\>/ display +hi def link coffeeGlobal Type + +" A special variable +syn match coffeeSpecialVar /\<\%(this\|prototype\|arguments\)\>/ display +" An @-variable +syn match coffeeSpecialVar /@\%(\I\i*\)\?/ display +hi def link coffeeSpecialVar Special + +" A class-like name that starts with a capital letter +syn match coffeeObject /\<\u\w*\>/ display +hi def link coffeeObject Structure + +" A constant-like name in SCREAMING_CAPS +syn match coffeeConstant /\<\u[A-Z0-9_]\+\>/ display +hi def link coffeeConstant Constant + +" A variable name +syn cluster coffeeIdentifier contains=coffeeSpecialVar,coffeeObject, +\ coffeeConstant + +" A non-interpolated string +syn cluster coffeeBasicString contains=@Spell,coffeeEscape +" An interpolated string +syn cluster coffeeInterpString contains=@coffeeBasicString,coffeeInterp + +" Regular strings +syn region coffeeString start=/"/ skip=/\\\\\|\\"/ end=/"/ +\ contains=@coffeeInterpString +syn region coffeeString start=/'/ skip=/\\\\\|\\'/ end=/'/ +\ contains=@coffeeBasicString +hi def link coffeeString String + +" A integer, including a leading plus or minus +syn match coffeeNumber /\i\@/ display +hi def link coffeeNumber Number + +" A floating-point number, including a leading plus or minus +syn match coffeeFloat /\i\@/ + \ display + hi def link coffeeReservedError Error +endif + +" This is separate from `coffeeExtendedOp` since assignments require it. +syn match coffeeAssignOp /:/ contained display +hi def link coffeeAssignOp coffeeOperator + +" Strings used in string assignments, which can't have interpolations +syn region coffeeAssignString start=/"/ skip=/\\\\\|\\"/ end=/"/ contained +\ contains=@coffeeBasicString +syn region coffeeAssignString start=/'/ skip=/\\\\\|\\'/ end=/'/ contained +\ contains=@coffeeBasicString +hi def link coffeeAssignString String + +" A normal object assignment +syn match coffeeObjAssign /@\?\I\i*\s*:\@ .*$" contains=MySQLKeyword,MySQLPrompt,MySQLString oneline +syn match MySQLPromptLine "^ -> .*$" contains=MySQLKeyword,MySQLPrompt,MySQLString oneline +syn match MySQLPrompt "^.\?mysql>" contained oneline +syn match MySQLPrompt "^ ->" contained oneline +syn case ignore +syn keyword MySQLKeyword select count max sum avg date show table tables status like as from left right outer inner join contained +syn keyword MySQLKeyword where group by having limit offset order desc asc show contained +syn case match +syn region MySQLString start=+'+ end=+'+ skip=+\\'+ contained oneline +syn region MySQLString start=+"+ end=+"+ skip=+\\"+ contained oneline +syn region MySQLString start=+`+ end=+`+ skip=+\\`+ contained oneline + +hi def link MySQLPrompt Identifier +hi def link MySQLTableHead Title +hi def link MySQLTableBody Normal +hi def link MySQLBool Boolean +hi def link MySQLStorageClass StorageClass +hi def link MySQLNumber Number +hi def link MySQLKeyword Keyword +hi def link MySQLString String + +" terms which have no reasonable default highlight group to link to +hi MySQLTableHead term=bold cterm=bold gui=bold +if &background == 'dark' + hi MySQLTableEnd term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLTableDivide term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLTableStart term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLTableBar term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLNull term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLQueryStat term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 +elseif &background == 'light' + hi MySQLTableEnd term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLTableDivide term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLTableStart term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLTableBar term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLNull term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLQueryStat term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e +endif + + +" ******************************************************************************************************************* +" Bash ************************************************************************************************************** +" ******************************************************************************************************************* + +" Typical Prompt +silent execute "syn match ConquePromptLine '" . g:ConqueTerm_PromptRegex . ".*$' contains=ConquePrompt,ConqueString oneline" +silent execute "syn match ConquePrompt '" . g:ConqueTerm_PromptRegex . "' contained oneline" +hi def link ConquePrompt Identifier + +" Strings +syn region ConqueString start=+'+ end=+'+ skip=+\\'+ contained oneline +syn region ConqueString start=+"+ end=+"+ skip=+\\"+ contained oneline +syn region ConqueString start=+`+ end=+`+ skip=+\\`+ contained oneline +hi def link ConqueString String + +" vim: foldmethod=marker diff --git a/vim/syntax/cucumber.vim b/vim/syntax/cucumber.vim new file mode 100644 index 0000000..3693a12 --- /dev/null +++ b/vim/syntax/cucumber.vim @@ -0,0 +1,126 @@ +" Vim syntax file +" Language: Cucumber +" Maintainer: Tim Pope +" Filenames: *.feature +" Last Change: 2010 May 21 + +if exists("b:current_syntax") + finish +endif +syn case match +syn sync minlines=20 + +let g:cucumber_languages = { + \"en": {"and": "And\\>", "background": "Background\\>", "but": "But\\>", "examples": "Scenarios\\>\\|Examples\\>", "feature": "Feature\\>", "given": "Given\\>", "scenario": "Scenario\\>", "scenario_outline": "Scenario Outline\\>", "then": "Then\\>", "when": "When\\>"}, + \"ar": {"and": "\\%u0648\\>", "background": "\\%u0627\\%u0644\\%u062e\\%u0644\\%u0641\\%u064a\\%u0629\\>", "but": "\\%u0644\\%u0643\\%u0646\\>", "examples": "\\%u0627\\%u0645\\%u062b\\%u0644\\%u0629\\>", "feature": "\\%u062e\\%u0627\\%u0635\\%u064a\\%u0629\\>", "given": "\\%u0628\\%u0641\\%u0631\\%u0636\\>", "scenario": "\\%u0633\\%u064a\\%u0646\\%u0627\\%u0631\\%u064a\\%u0648\\>", "scenario_outline": "\\%u0633\\%u064a\\%u0646\\%u0627\\%u0631\\%u064a\\%u0648 \\%u0645\\%u062e\\%u0637\\%u0637\\>", "then": "\\%u0627\\%u0630\\%u0627\\%u064b\\>\\|\\%u062b\\%u0645\\>", "when": "\\%u0639\\%u0646\\%u062f\\%u0645\\%u0627\\>\\|\\%u0645\\%u062a\\%u0649\\>"}, + \"bg": {"and": "\\%u0418\\>", "background": "\\%u041f\\%u0440\\%u0435\\%u0434\\%u0438\\%u0441\\%u0442\\%u043e\\%u0440\\%u0438\\%u044f\\>", "but": "\\%u041d\\%u043e\\>", "examples": "\\%u041f\\%u0440\\%u0438\\%u043c\\%u0435\\%u0440\\%u0438\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\%u043d\\%u043e\\%u0441\\%u0442\\>", "given": "\\%u0414\\%u0430\\%u0434\\%u0435\\%u043d\\%u043e\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "scenario_outline": "\\%u0420\\%u0430\\%u043c\\%u043a\\%u0430 \\%u043d\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "then": "\\%u0422\\%u043e\\>", "when": "\\%u041a\\%u043e\\%u0433\\%u0430\\%u0442\\%u043e\\>"}, + \"ca": {"and": "I\\>", "background": "Antecedents\\>\\|Rerefons\\>", "but": "Per\\%u00f2\\>", "examples": "Exemples\\>", "feature": "Caracter\\%u00edstica\\>\\|Funcionalitat\\>", "given": "At\\%u00e8s\\>\\|Donada\\>\\|Donat\\>\\|Atesa\\>", "scenario": "Escenari\\>", "scenario_outline": "Esquema de l'escenari\\>", "then": "Aleshores\\>\\|Cal\\>", "when": "Quan\\>"}, + \"cs": {"and": "A tak\\%u00e9\\>\\|A\\>", "background": "Pozad\\%u00ed\\>\\|Kontext\\>", "but": "Ale\\>", "examples": "P\\%u0159\\%u00edklady\\>", "feature": "Po\\%u017eadavek\\>", "given": "Pokud\\>", "scenario": "Sc\\%u00e9n\\%u00e1\\%u0159\\>", "scenario_outline": "N\\%u00e1\\%u010drt Sc\\%u00e9n\\%u00e1\\%u0159e\\>\\|Osnova sc\\%u00e9n\\%u00e1\\%u0159e\\>", "then": "Pak\\>", "when": "Kdy\\%u017e\\>"}, + \"cy-GB": {"and": "A\\>", "background": "Cefndir\\>", "but": "Ond\\>", "examples": "Enghreifftiau\\>", "feature": "Arwedd\\>", "given": "Anrhegedig a\\>", "scenario": "Scenario\\>", "scenario_outline": "Scenario Amlinellol\\>", "then": "Yna\\>", "when": "Pryd\\>"}, + \"da": {"and": "Og\\>", "background": "Baggrund\\>", "but": "Men\\>", "examples": "Eksempler\\>", "feature": "Egenskab\\>", "given": "Givet\\>", "scenario": "Scenarie\\>", "scenario_outline": "Abstrakt Scenario\\>", "then": "S\\%u00e5\\>", "when": "N\\%u00e5r\\>"}, + \"de": {"and": "Und\\>", "background": "Grundlage\\>", "but": "Aber\\>", "examples": "Beispiele\\>", "feature": "Funktionalit\\%u00e4t\\>", "given": "Gegeben sei\\>\\|Angenommen\\>", "scenario": "Szenario\\>", "scenario_outline": "Szenariogrundriss\\>", "then": "Dann\\>", "when": "Wenn\\>"}, + \"en-Scouse": {"and": "An\\>", "background": "Dis is what went down\\>", "but": "Buh\\>", "examples": "Examples\\>", "feature": "Feature\\>", "given": "Youse know when youse got\\>\\|Givun\\>", "scenario": "The thing of it is\\>", "scenario_outline": "Wharrimean is\\>", "then": "Den youse gotta\\>\\|Dun\\>", "when": "Youse know like when\\>\\|Wun\\>"}, + \"en-au": {"and": "N\\>", "background": "Background\\>", "but": "Cept\\>", "examples": "Cobber\\>", "feature": "Crikey\\>", "given": "Ya know how\\>", "scenario": "Mate\\>", "scenario_outline": "Blokes\\>", "then": "Ya gotta\\>", "when": "When\\>"}, + \"en-lol": {"and": "AN\\>", "background": "B4\\>", "but": "BUT\\>", "examples": "EXAMPLZ\\>", "feature": "OH HAI\\>", "given": "I CAN HAZ\\>", "scenario": "MISHUN\\>", "scenario_outline": "MISHUN SRSLY\\>", "then": "DEN\\>", "when": "WEN\\>"}, + \"en-tx": {"and": "And y'all\\>", "background": "Background\\>", "but": "But y'all\\>", "examples": "Examples\\>", "feature": "Feature\\>", "given": "Given y'all\\>", "scenario": "Scenario\\>", "scenario_outline": "All y'all\\>", "then": "Then y'all\\>", "when": "When y'all\\>"}, + \"eo": {"and": "Kaj\\>", "background": "Fono\\>", "but": "Sed\\>", "examples": "Ekzemploj\\>", "feature": "Trajto\\>", "given": "Donita\\%u0135o\\>", "scenario": "Scenaro\\>", "scenario_outline": "Konturo de la scenaro\\>", "then": "Do\\>", "when": "Se\\>"}, + \"es": {"and": "Y\\>", "background": "Antecedentes\\>", "but": "Pero\\>", "examples": "Ejemplos\\>", "feature": "Caracter\\%u00edstica\\>", "given": "Dado\\>", "scenario": "Escenario\\>", "scenario_outline": "Esquema del escenario\\>", "then": "Entonces\\>", "when": "Cuando\\>"}, + \"et": {"and": "Ja\\>", "background": "Taust\\>", "but": "Kuid\\>", "examples": "Juhtumid\\>", "feature": "Omadus\\>", "given": "Eeldades\\>", "scenario": "Stsenaarium\\>", "scenario_outline": "Raamstsenaarium\\>", "then": "Siis\\>", "when": "Kui\\>"}, + \"fi": {"and": "Ja\\>", "background": "Tausta\\>", "but": "Mutta\\>", "examples": "Tapaukset\\>", "feature": "Ominaisuus\\>", "given": "Oletetaan\\>", "scenario": "Tapaus\\>", "scenario_outline": "Tapausaihio\\>", "then": "Niin\\>", "when": "Kun\\>"}, + \"fr": {"and": "Et\\>", "background": "Contexte\\>", "but": "Mais\\>", "examples": "Exemples\\>", "feature": "Fonctionnalit\\%u00e9\\>", "given": "Etant donn\\%u00e9\\>\\|Soit\\>", "scenario": "Sc\\%u00e9nario\\>", "scenario_outline": "Plan du sc\\%u00e9nario\\>\\|Plan du Sc\\%u00e9nario\\>", "then": "Alors\\>", "when": "Lorsqu'\\|Lorsque\\>\\|Quand\\>"}, + \"he": {"and": "\\%u05d5\\%u05d2\\%u05dd\\>", "background": "\\%u05e8\\%u05e7\\%u05e2\\>", "but": "\\%u05d0\\%u05d1\\%u05dc\\>", "examples": "\\%u05d3\\%u05d5\\%u05d2\\%u05de\\%u05d0\\%u05d5\\%u05ea\\>", "feature": "\\%u05ea\\%u05db\\%u05d5\\%u05e0\\%u05d4\\>", "given": "\\%u05d1\\%u05d4\\%u05d9\\%u05e0\\%u05ea\\%u05df\\>", "scenario": "\\%u05ea\\%u05e8\\%u05d7\\%u05d9\\%u05e9\\>", "scenario_outline": "\\%u05ea\\%u05d1\\%u05e0\\%u05d9\\%u05ea \\%u05ea\\%u05e8\\%u05d7\\%u05d9\\%u05e9\\>", "then": "\\%u05d0\\%u05d6\\%u05d9\\>\\|\\%u05d0\\%u05d6\\>", "when": "\\%u05db\\%u05d0\\%u05e9\\%u05e8\\>"}, + \"hr": {"and": "I\\>", "background": "Pozadina\\>", "but": "Ali\\>", "examples": "Scenariji\\>\\|Primjeri\\>", "feature": "Mogu\\%u0107nost\\>\\|Mogucnost\\>\\|Osobina\\>", "given": "Zadano\\>\\|Zadani\\>\\|Zadan\\>", "scenario": "Scenarij\\>", "scenario_outline": "Koncept\\>\\|Skica\\>", "then": "Onda\\>", "when": "Kada\\>\\|Kad\\>"}, + \"hu": {"and": "\\%u00c9s\\>", "background": "H\\%u00e1tt\\%u00e9r\\>", "but": "De\\>", "examples": "P\\%u00e9ld\\%u00e1k\\>", "feature": "Jellemz\\%u0151\\>", "given": "Ha\\>", "scenario": "Forgat\\%u00f3k\\%u00f6nyv\\>", "scenario_outline": "Forgat\\%u00f3k\\%u00f6nyv v\\%u00e1zlat\\>", "then": "Akkor\\>", "when": "Majd\\>"}, + \"id": {"and": "Dan\\>", "background": "Dasar\\>", "but": "Tapi\\>", "examples": "Contoh\\>", "feature": "Fitur\\>", "given": "Dengan\\>", "scenario": "Skenario\\>", "scenario_outline": "Skenario konsep\\>", "then": "Maka\\>", "when": "Ketika\\>"}, + \"it": {"and": "E\\>", "background": "Contesto\\>", "but": "Ma\\>", "examples": "Esempi\\>", "feature": "Funzionalit\\%u00e0\\>", "given": "Dato\\>", "scenario": "Scenario\\>", "scenario_outline": "Schema dello scenario\\>", "then": "Allora\\>", "when": "Quando\\>"}, + \"ja": {"and": "\\%u304b\\%u3064", "background": "\\%u80cc\\%u666f\\>", "but": "\\%u3057\\%u304b\\%u3057\\|\\%u305f\\%u3060\\%u3057\\|\\%u4f46\\%u3057", "examples": "\\%u30b5\\%u30f3\\%u30d7\\%u30eb\\>\\|\\%u4f8b\\>", "feature": "\\%u30d5\\%u30a3\\%u30fc\\%u30c1\\%u30e3\\>\\|\\%u6a5f\\%u80fd\\>", "given": "\\%u524d\\%u63d0", "scenario": "\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\>", "scenario_outline": "\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\%u30a2\\%u30a6\\%u30c8\\%u30e9\\%u30a4\\%u30f3\\>\\|\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\%u30c6\\%u30f3\\%u30d7\\%u30ec\\%u30fc\\%u30c8\\>\\|\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\%u30c6\\%u30f3\\%u30d7\\%u30ec\\>\\|\\%u30c6\\%u30f3\\%u30d7\\%u30ec\\>", "then": "\\%u306a\\%u3089\\%u3070", "when": "\\%u3082\\%u3057"}, + \"ko": {"and": "\\%uadf8\\%ub9ac\\%uace0", "background": "\\%ubc30\\%uacbd\\>", "but": "\\%ud558\\%uc9c0\\%ub9cc\\|\\%ub2e8", "examples": "\\%uc608\\>", "feature": "\\%uae30\\%ub2a5\\>", "given": "\\%uc870\\%uac74\\|\\%uba3c\\%uc800", "scenario": "\\%uc2dc\\%ub098\\%ub9ac\\%uc624\\>", "scenario_outline": "\\%uc2dc\\%ub098\\%ub9ac\\%uc624 \\%uac1c\\%uc694\\>", "then": "\\%uadf8\\%ub7ec\\%uba74", "when": "\\%ub9cc\\%uc77c\\|\\%ub9cc\\%uc57d"}, + \"lt": {"and": "Ir\\>", "background": "Kontekstas\\>", "but": "Bet\\>", "examples": "Pavyzd\\%u017eiai\\>\\|Scenarijai\\>\\|Variantai\\>", "feature": "Savyb\\%u0117\\>", "given": "Duota\\>", "scenario": "Scenarijus\\>", "scenario_outline": "Scenarijaus \\%u0161ablonas\\>", "then": "Tada\\>", "when": "Kai\\>"}, + \"lu": {"and": "an\\>\\|a\\>", "background": "Hannergrond\\>", "but": "m\\%u00e4\\>\\|awer\\>", "examples": "Beispiller\\>", "feature": "Funktionalit\\%u00e9it\\>", "given": "ugeholl\\>", "scenario": "Szenario\\>", "scenario_outline": "Plang vum Szenario\\>", "then": "dann\\>", "when": "wann\\>"}, + \"lv": {"and": "Un\\>", "background": "Situ\\%u0101cija\\>\\|Konteksts\\>", "but": "Bet\\>", "examples": "Piem\\%u0113ri\\>\\|Paraugs\\>", "feature": "Funkcionalit\\%u0101te\\>\\|F\\%u012b\\%u010da\\>", "given": "Kad\\>", "scenario": "Scen\\%u0101rijs\\>", "scenario_outline": "Scen\\%u0101rijs p\\%u0113c parauga\\>", "then": "Tad\\>", "when": "Ja\\>"}, + \"nl": {"and": "En\\>", "background": "Achtergrond\\>", "but": "Maar\\>", "examples": "Voorbeelden\\>", "feature": "Functionaliteit\\>", "given": "Gegeven\\>\\|Stel\\>", "scenario": "Scenario\\>", "scenario_outline": "Abstract Scenario\\>", "then": "Dan\\>", "when": "Als\\>"}, + \"no": {"and": "Og\\>", "background": "Bakgrunn\\>", "but": "Men\\>", "examples": "Eksempler\\>", "feature": "Egenskap\\>", "given": "Gitt\\>", "scenario": "Scenario\\>", "scenario_outline": "Abstrakt Scenario\\>", "then": "S\\%u00e5\\>", "when": "N\\%u00e5r\\>"}, + \"pl": {"and": "Oraz\\>", "background": "Za\\%u0142o\\%u017cenia\\>", "but": "Ale\\>", "examples": "Przyk\\%u0142ady\\>", "feature": "W\\%u0142a\\%u015bciwo\\%u015b\\%u0107\\>", "given": "Zak\\%u0142adaj\\%u0105c\\>", "scenario": "Scenariusz\\>", "scenario_outline": "Szablon scenariusza\\>", "then": "Wtedy\\>", "when": "Je\\%u017celi\\>"}, + \"pt": {"and": "E\\>", "background": "Contexto\\>", "but": "Mas\\>", "examples": "Exemplos\\>", "feature": "Funcionalidade\\>", "given": "Dado\\>", "scenario": "Cen\\%u00e1rio\\>\\|Cenario\\>", "scenario_outline": "Esquema do Cen\\%u00e1rio\\>\\|Esquema do Cenario\\>", "then": "Ent\\%u00e3o\\>\\|Entao\\>", "when": "Quando\\>"}, + \"ro": {"and": "Si\\>", "background": "Conditii\\>", "but": "Dar\\>", "examples": "Exemplele\\>", "feature": "Functionalitate\\>", "given": "Daca\\>", "scenario": "Scenariu\\>", "scenario_outline": "Scenariul de sablon\\>", "then": "Atunci\\>", "when": "Cand\\>"}, + \"ro-RO": {"and": "\\%u0218i\\>", "background": "Condi\\%u0163ii\\>", "but": "Dar\\>", "examples": "Exemplele\\>", "feature": "Func\\%u021bionalitate\\>", "given": "Dac\\%u0103\\>", "scenario": "Scenariu\\>", "scenario_outline": "Scenariul de \\%u015fablon\\>", "then": "Atunci\\>", "when": "C\\%u00e2nd\\>"}, + \"ru": {"and": "\\%u041a \\%u0442\\%u043e\\%u043c\\%u0443 \\%u0436\\%u0435\\>\\|\\%u0418\\>", "background": "\\%u041f\\%u0440\\%u0435\\%u0434\\%u044b\\%u0441\\%u0442\\%u043e\\%u0440\\%u0438\\%u044f\\>", "but": "\\%u041d\\%u043e\\>\\|\\%u0410\\>", "examples": "\\%u0417\\%u043d\\%u0430\\%u0447\\%u0435\\%u043d\\%u0438\\%u044f\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\>\\|\\%u0424\\%u0438\\%u0447\\%u0430\\>", "given": "\\%u0414\\%u043e\\%u043f\\%u0443\\%u0441\\%u0442\\%u0438\\%u043c\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "scenario_outline": "\\%u0421\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u044f\\>", "then": "\\%u0422\\%u043e\\>", "when": "\\%u0415\\%u0441\\%u043b\\%u0438\\>"}, + \"sk": {"and": "A\\>", "background": "Pozadie\\>", "but": "Ale\\>", "examples": "Pr\\%u00edklady\\>", "feature": "Po\\%u017eiadavka\\>", "given": "Pokia\\%u013e\\>", "scenario": "Scen\\%u00e1r\\>", "scenario_outline": "N\\%u00e1\\%u010drt Scen\\%u00e1ru\\>", "then": "Tak\\>", "when": "Ke\\%u010f\\>"}, + \"sr-Cyrl": {"and": "\\%u0418\\>", "background": "\\%u041a\\%u043e\\%u043d\\%u0442\\%u0435\\%u043a\\%u0441\\%u0442\\>\\|\\%u041f\\%u043e\\%u0437\\%u0430\\%u0434\\%u0438\\%u043d\\%u0430\\>\\|\\%u041e\\%u0441\\%u043d\\%u043e\\%u0432\\%u0430\\>", "but": "\\%u0410\\%u043b\\%u0438\\>", "examples": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0458\\%u0438\\>\\|\\%u041f\\%u0440\\%u0438\\%u043c\\%u0435\\%u0440\\%u0438\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\%u043d\\%u043e\\%u0441\\%u0442\\>\\|\\%u041c\\%u043e\\%u0433\\%u0443\\%u045b\\%u043d\\%u043e\\%u0441\\%u0442\\>\\|\\%u041e\\%u0441\\%u043e\\%u0431\\%u0438\\%u043d\\%u0430\\>", "given": "\\%u0417\\%u0430\\%u0434\\%u0430\\%u0442\\%u043e\\>\\|\\%u0417\\%u0430\\%u0434\\%u0430\\%u0442\\%u0435\\>\\|\\%u0417\\%u0430\\%u0434\\%u0430\\%u0442\\%u0438\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u043e\\>\\|\\%u041f\\%u0440\\%u0438\\%u043c\\%u0435\\%u0440\\>", "scenario_outline": "\\%u0421\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0458\\%u0430\\>\\|\\%u041a\\%u043e\\%u043d\\%u0446\\%u0435\\%u043f\\%u0442\\>\\|\\%u0421\\%u043a\\%u0438\\%u0446\\%u0430\\>", "then": "\\%u041e\\%u043d\\%u0434\\%u0430\\>", "when": "\\%u041a\\%u0430\\%u0434\\%u0430\\>\\|\\%u041a\\%u0430\\%u0434\\>"}, + \"sr-Latn": {"and": "I\\>", "background": "Kontekst\\>\\|Pozadina\\>\\|Osnova\\>", "but": "Ali\\>", "examples": "Scenariji\\>\\|Primeri\\>", "feature": "Mogu\\%u0107nost\\>\\|Funkcionalnost\\>\\|Mogucnost\\>\\|Osobina\\>", "given": "Zadato\\>\\|Zadate\\>\\|Zatati\\>", "scenario": "Scenario\\>\\|Primer\\>", "scenario_outline": "Struktura scenarija\\>\\|Koncept\\>\\|Skica\\>", "then": "Onda\\>", "when": "Kada\\>\\|Kad\\>"}, + \"sv": {"and": "Och\\>", "background": "Bakgrund\\>", "but": "Men\\>", "examples": "Exempel\\>", "feature": "Egenskap\\>", "given": "Givet\\>", "scenario": "Scenario\\>", "scenario_outline": "Abstrakt Scenario\\>", "then": "S\\%u00e5\\>", "when": "N\\%u00e4r\\>"}, + \"tr": {"and": "Ve\\>", "background": "Ge\\%u00e7mi\\%u015f\\>", "but": "Fakat\\>\\|Ama\\>", "examples": "\\%u00d6rnekler\\>", "feature": "\\%u00d6zellik\\>", "given": "Diyelim ki\\>", "scenario": "Senaryo\\>", "scenario_outline": "Senaryo tasla\\%u011f\\%u0131\\>", "then": "O zaman\\>", "when": "E\\%u011fer ki\\>"}, + \"uk": {"and": "\\%u0406\\>", "background": "\\%u041f\\%u0435\\%u0440\\%u0435\\%u0434\\%u0443\\%u043c\\%u043e\\%u0432\\%u0430\\>", "but": "\\%u0410\\%u043b\\%u0435\\>", "examples": "\\%u041f\\%u0440\\%u0438\\%u043a\\%u043b\\%u0430\\%u0434\\%u0438\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0456\\%u043e\\%u043d\\%u0430\\%u043b\\>", "given": "\\%u041f\\%u0440\\%u0438\\%u043f\\%u0443\\%u0441\\%u0442\\%u0438\\%u043c\\%u043e, \\%u0449\\%u043e\\>\\|\\%u041f\\%u0440\\%u0438\\%u043f\\%u0443\\%u0441\\%u0442\\%u0438\\%u043c\\%u043e\\>\\|\\%u041d\\%u0435\\%u0445\\%u0430\\%u0439\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0456\\%u0439\\>", "scenario_outline": "\\%u0421\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0456\\%u044e\\>", "then": "\\%u0422\\%u043e\\>", "when": "\\%u042f\\%u043a\\%u0449\\%u043e\\>"}, + \"uz": {"and": "\\%u0412\\%u0430\\>", "background": "\\%u0422\\%u0430\\%u0440\\%u0438\\%u0445\\>", "but": "\\%u041b\\%u0435\\%u043a\\%u0438\\%u043d\\>\\|\\%u0411\\%u0438\\%u0440\\%u043e\\%u043a\\>\\|\\%u0410\\%u043c\\%u043c\\%u043e\\>", "examples": "\\%u041c\\%u0438\\%u0441\\%u043e\\%u043b\\%u043b\\%u0430\\%u0440\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\>", "given": "\\%u0410\\%u0433\\%u0430\\%u0440\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "scenario_outline": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439 \\%u0441\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430\\%u0441\\%u0438\\>", "then": "\\%u0423\\%u043d\\%u0434\\%u0430\\>", "when": "\\%u0410\\%u0433\\%u0430\\%u0440\\>"}, + \"vi": {"and": "V\\%u00e0\\>", "background": "B\\%u1ed1i c\\%u1ea3nh\\>", "but": "Nh\\%u01b0ng\\>", "examples": "D\\%u1eef li\\%u1ec7u\\>", "feature": "T\\%u00ednh n\\%u0103ng\\>", "given": "Bi\\%u1ebft\\>\\|Cho\\>", "scenario": "T\\%u00ecnh hu\\%u1ed1ng\\>\\|K\\%u1ecbch b\\%u1ea3n\\>", "scenario_outline": "Khung t\\%u00ecnh hu\\%u1ed1ng\\>\\|Khung k\\%u1ecbch b\\%u1ea3n\\>", "then": "Th\\%u00ec\\>", "when": "Khi\\>"}, + \"zh-CN": {"and": "\\%u800c\\%u4e14", "background": "\\%u80cc\\%u666f\\>", "but": "\\%u4f46\\%u662f", "examples": "\\%u4f8b\\%u5b50\\>", "feature": "\\%u529f\\%u80fd\\>", "given": "\\%u5047\\%u5982", "scenario": "\\%u573a\\%u666f\\>", "scenario_outline": "\\%u573a\\%u666f\\%u5927\\%u7eb2\\>", "then": "\\%u90a3\\%u4e48", "when": "\\%u5f53"}, + \"zh-TW": {"and": "\\%u800c\\%u4e14\\|\\%u4e26\\%u4e14", "background": "\\%u80cc\\%u666f\\>", "but": "\\%u4f46\\%u662f", "examples": "\\%u4f8b\\%u5b50\\>", "feature": "\\%u529f\\%u80fd\\>", "given": "\\%u5047\\%u8a2d", "scenario": "\\%u5834\\%u666f\\>\\|\\%u5287\\%u672c\\>", "scenario_outline": "\\%u5834\\%u666f\\%u5927\\%u7db1\\>\\|\\%u5287\\%u672c\\%u5927\\%u7db1\\>", "then": "\\%u90a3\\%u9ebc", "when": "\\%u7576"}} + +function! s:pattern(key) + let language = matchstr(getline(1),'#\s*language:\s*\zs\S\+') + if &fileencoding == 'latin1' && language == '' + let language = 'en' + endif + if has_key(g:cucumber_languages, language) + let languages = [g:cucumber_languages[language]] + else + let languages = values(g:cucumber_languages) + end + return '\<\%('.join(map(languages,'get(v:val,a:key,"\\%(a\\&b\\)")'),'\|').'\)' +endfunction + +function! s:Add(name) + let next = " skipempty skipwhite nextgroup=".join(map(["Region","AndRegion","ButRegion","Comment","String","Table"],'"cucumber".a:name.v:val'),",") + exe "syn region cucumber".a:name.'Region matchgroup=cucumber'.a:name.' start="\%(^\s*\)\@<=\%('.s:pattern(tolower(a:name)).'\)" end="$"'.next + exe 'syn region cucumber'.a:name.'AndRegion matchgroup=cucumber'.a:name.'And start="\%(^\s*\)\@<='.s:pattern('and').'" end="$" contained'.next + exe 'syn region cucumber'.a:name.'ButRegion matchgroup=cucumber'.a:name.'But start="\%(^\s*\)\@<='.s:pattern('but').'" end="$" contained'.next + exe 'syn match cucumber'.a:name.'Comment "\%(^\s*\)\@<=#.*" contained'.next + exe 'syn region cucumber'.a:name.'String start=+\%(^\s*\)\@<="""+ end=+"""+ contained'.next + exe 'syn match cucumber'.a:name.'Table "\%(^\s*\)\@<=|.*" contained contains=cucumberDelimiter'.next + exe 'hi def link cucumber'.a:name.'Comment cucumberComment' + exe 'hi def link cucumber'.a:name.'String cucumberString' + exe 'hi def link cucumber'.a:name.'But cucumber'.a:name.'And' + exe 'hi def link cucumber'.a:name.'And cucumber'.a:name + exe 'syn cluster cucumberStepRegions add=cucumber'.a:name.'Region,cucumber'.a:name.'AndRegion,cucumber'.a:name.'ButRegion' +endfunction + +syn match cucumberComment "\%(^\s*\)\@<=#.*" +syn match cucumberComment "\%(\%^\s*\)\@<=#.*" contains=cucumberLanguage +syn match cucumberLanguage "\%(#\s*\)\@<=language:" contained +syn match cucumberUnparsed "\S.*" nextgroup=cucumberUnparsedComment,cucumberUnparsed,cucumberTags,cucumberBackground,cucumberScenario,cucumberScenarioOutline,cucumberExamples skipwhite skipempty contained +syn match cucumberUnparsedComment "#.*" nextgroup=cucumberUnparsedComment,cucumberUnparsed,cucumberTags,cucumberBackground,cucumberScenario,cucumberScenarioOutline,cucumberExamples skipwhite skipempty contained + +exe 'syn match cucumberFeature "\%(^\s*\)\@<='.s:pattern('feature').':" nextgroup=cucumberUnparsedComment,cucumberUnparsed,cucumberBackground,cucumberScenario,cucumberScenarioOutline,cucumberExamples skipwhite skipempty' +exe 'syn match cucumberBackground "\%(^\s*\)\@<='.s:pattern('background').':"' +exe 'syn match cucumberScenario "\%(^\s*\)\@<='.s:pattern('scenario').':"' +exe 'syn match cucumberScenarioOutline "\%(^\s*\)\@<='.s:pattern('scenario_outline').':"' +exe 'syn match cucumberExamples "\%(^\s*\)\@<='.s:pattern('examples').':" nextgroup=cucumberExampleTable skipempty skipwhite' + +syn match cucumberPlaceholder "<[^<>]*>" contained containedin=@cucumberStepRegions +syn match cucumberExampleTable "\%(^\s*\)\@<=|.*" contains=cucumberDelimiter +syn match cucumberDelimiter "\\\@/ contains=@coffeeTop containedin=ALLBUT,@ecoRegions keepend +syn region ecoExpression matchgroup=ecoDelimiter start=/<%[=\-]/ end=/%>/ contains=@coffeeTop containedin=ALLBUT,@ecoRegions keepend +syn region ecoComment matchgroup=ecoComment start=/<%#/ end=/%>/ contains=@coffeeTodo,@Spell containedin=ALLBUT,@ecoRegions keepend + +" eco features not in coffeescript proper +syn keyword ecoEnd end containedin=@ecoRegions +syn match ecoIndentColon /\s+\w+:/ containedin=@ecoRegions + +" Define the default highlighting. + +hi def link ecoDelimiter Delimiter +hi def link ecoComment Comment +hi def link ecoEnd coffeeConditional +hi def link ecoIndentColon None + +let b:current_syntax = 'eco' + +" vim: nowrap sw=2 sts=2 ts=8: diff --git a/vim/syntax/git.vim b/vim/syntax/git.vim new file mode 100644 index 0000000..729bf62 --- /dev/null +++ b/vim/syntax/git.vim @@ -0,0 +1,77 @@ +" Vim syntax file +" Language: generic git output +" Maintainer: Tim Pope + +if exists("b:current_syntax") + finish +endif + +syn case match +syn sync minlines=50 + +syn include @gitDiff syntax/diff.vim + +syn region gitHead start=/\%^/ end=/^$/ +syn region gitHead start=/\%(^commit \x\{40\}\%(\s*(.*)\)\=$\)\@=/ end=/^$/ + +" For git reflog and git show ...^{tree}, avoid sync issues +syn match gitHead /^\d\{6\} \%(\w\{4} \)\=\x\{40\}\%( [0-3]\)\=\t.*/ +syn match gitHead /^\x\{40\} \x\{40}\t.*/ + +syn region gitDiff start=/^\%(diff --git \)\@=/ end=/^\%(diff --\|$\)\@=/ contains=@gitDiff fold +syn region gitDiff start=/^\%(@@ -\)\@=/ end=/^\%(diff --\%(git\|cc\|combined\) \|$\)\@=/ contains=@gitDiff + +syn region gitDiffMerge start=/^\%(diff --\%(cc\|combined\) \)\@=/ end=/^\%(diff --\|$\)\@=/ contains=@gitDiff +syn region gitDiffMerge start=/^\%(@@@@* -\)\@=/ end=/^\%(diff --\|$\)\@=/ contains=@gitDiff +syn match gitDiffAdded "^ \++.*" contained containedin=gitDiffMerge +syn match gitDiffRemoved "^ \+-.*" contained containedin=gitDiffMerge + +syn match gitKeyword /^\%(object\|type\|tag\|commit\|tree\|parent\|encoding\)\>/ contained containedin=gitHead nextgroup=gitHash,gitType skipwhite +syn match gitKeyword /^\%(tag\>\|ref:\)/ contained containedin=gitHead nextgroup=gitReference skipwhite +syn match gitKeyword /^Merge:/ contained containedin=gitHead nextgroup=gitHashAbbrev skipwhite +syn match gitMode /^\d\{6\}/ contained containedin=gitHead nextgroup=gitType,gitHash skipwhite +syn match gitIdentityKeyword /^\%(author\|committer\|tagger\)\>/ contained containedin=gitHead nextgroup=gitIdentity skipwhite +syn match gitIdentityHeader /^\%(Author\|Commit\|Tagger\):/ contained containedin=gitHead nextgroup=gitIdentity skipwhite +syn match gitDateHeader /^\%(AuthorDate\|CommitDate\|Date\):/ contained containedin=gitHead nextgroup=gitDate skipwhite + +syn match gitReflogHeader /^Reflog:/ contained containedin=gitHead nextgroup=gitReflogMiddle skipwhite +syn match gitReflogHeader /^Reflog message:/ contained containedin=gitHead skipwhite +syn match gitReflogMiddle /\S\+@{\d\+} (/he=e-2 nextgroup=gitIdentity + +syn match gitDate /\<\u\l\l \u\l\l \d\=\d \d\d:\d\d:\d\d \d\d\d\d [+-]\d\d\d\d/ contained +syn match gitDate /-\=\d\+ [+-]\d\d\d\d\>/ contained +syn match gitDate /\<\d\+ \l\+ ago\>/ contained +syn match gitType /\<\%(tag\|commit\|tree\|blob\)\>/ contained nextgroup=gitHash skipwhite +syn match gitStage /\<\d\t\@=/ contained +syn match gitReference /\S\+\S\@!/ contained +syn match gitHash /\<\x\{40\}\>/ contained nextgroup=gitIdentity,gitStage,gitHash skipwhite +syn match gitHash /^\<\x\{40\}\>/ containedin=gitHead contained nextgroup=gitHash skipwhite +syn match gitHashAbbrev /\<\x\{4,40\}\>/ contained nextgroup=gitHashAbbrev skipwhite +syn match gitHashAbbrev /\<\x\{4,39\}\.\.\./he=e-3 contained nextgroup=gitHashAbbrev skipwhite + +syn match gitIdentity /\S.\{-\} <[^>]*>/ contained nextgroup=gitDate skipwhite +syn region gitEmail matchgroup=gitEmailDelimiter start=// keepend oneline contained containedin=gitIdentity + +syn match gitNotesHeader /^Notes:\ze\n / + +hi def link gitDateHeader gitIdentityHeader +hi def link gitIdentityHeader gitIdentityKeyword +hi def link gitIdentityKeyword Label +hi def link gitNotesHeader gitKeyword +hi def link gitReflogHeader gitKeyword +hi def link gitKeyword Keyword +hi def link gitIdentity String +hi def link gitEmailDelimiter Delimiter +hi def link gitEmail Special +hi def link gitDate Number +hi def link gitMode Number +hi def link gitHashAbbrev gitHash +hi def link gitHash Identifier +hi def link gitReflogMiddle gitReference +hi def link gitReference Function +hi def link gitStage gitType +hi def link gitType Type +hi def link gitDiffAdded diffAdded +hi def link gitDiffRemoved diffRemoved + +let b:current_syntax = "git" diff --git a/vim/syntax/gitcommit.vim b/vim/syntax/gitcommit.vim new file mode 100644 index 0000000..3c43cdf --- /dev/null +++ b/vim/syntax/gitcommit.vim @@ -0,0 +1,82 @@ +" Vim syntax file +" Language: git commit file +" Maintainer: Tim Pope +" Filenames: *.git/COMMIT_EDITMSG + +if exists("b:current_syntax") + finish +endif + +syn case match +syn sync minlines=50 + +if has("spell") + syn spell toplevel +endif + +syn include @gitcommitDiff syntax/diff.vim +syn region gitcommitDiff start=/\%(^diff --\%(git\|cc\|combined\) \)\@=/ end=/^$\|^#\@=/ contains=@gitcommitDiff + +syn match gitcommitFirstLine "\%^[^#].*" nextgroup=gitcommitBlank skipnl +syn match gitcommitSummary "^.\{0,50\}" contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell +syn match gitcommitOverflow ".*" contained contains=@Spell +syn match gitcommitBlank "^[^#].*" contained contains=@Spell +syn match gitcommitComment "^#.*" +syn match gitcommitHead "^\%(# .*\n\)\+#$" contained transparent +syn match gitcommitOnBranch "\%(^# \)\@<=On branch" contained containedin=gitcommitComment nextgroup=gitcommitBranch skipwhite +syn match gitcommitOnBranch "\%(^# \)\@<=Your branch .\{-\} '" contained containedin=gitcommitComment nextgroup=gitcommitBranch skipwhite +syn match gitcommitBranch "[^ \t']\+" contained +syn match gitcommitNoBranch "\%(^# \)\@<=Not currently on any branch." contained containedin=gitcommitComment +syn match gitcommitHeader "\%(^# \)\@<=.*:$" contained containedin=gitcommitComment +syn region gitcommitAuthor matchgroup=gitCommitHeader start=/\%(^# \)\@<=\%(Author\|Committer\):/ end=/$/ keepend oneline contained containedin=gitcommitComment transparent +syn match gitcommitNoChanges "\%(^# \)\@<=No changes$" contained containedin=gitcommitComment + +syn region gitcommitUntracked start=/^# Untracked files:/ end=/^#$\|^#\@!/ contains=gitcommitHeader,gitcommitHead,gitcommitUntrackedFile fold +syn match gitcommitUntrackedFile "\t\@<=.*" contained + +syn region gitcommitDiscarded start=/^# Changed but not updated:/ end=/^#$\|^#\@!/ contains=gitcommitHeader,gitcommitHead,gitcommitDiscardedType fold +syn region gitcommitSelected start=/^# Changes to be committed:/ end=/^#$\|^#\@!/ contains=gitcommitHeader,gitcommitHead,gitcommitSelectedType fold +syn region gitcommitUnmerged start=/^# Unmerged paths:/ end=/^#$\|^#\@!/ contains=gitcommitHeader,gitcommitHead,gitcommitUnmergedType fold + +syn match gitcommitDiscardedType "\t\@<=[a-z][a-z ]*[a-z]: "he=e-2 contained containedin=gitcommitComment nextgroup=gitcommitDiscardedFile skipwhite +syn match gitcommitSelectedType "\t\@<=[a-z][a-z ]*[a-z]: "he=e-2 contained containedin=gitcommitComment nextgroup=gitcommitSelectedFile skipwhite +syn match gitcommitUnmergedType "\t\@<=[a-z][a-z ]*[a-z]: "he=e-2 contained containedin=gitcommitComment nextgroup=gitcommitUnmergedFile skipwhite +syn match gitcommitDiscardedFile ".\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitDiscardedArrow +syn match gitcommitSelectedFile ".\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitSelectedArrow +syn match gitcommitUnmergedFile ".\{-\}\%($\| -> \)\@=" contained nextgroup=gitcommitSelectedArrow +syn match gitcommitDiscardedArrow " -> " contained nextgroup=gitcommitDiscardedFile +syn match gitcommitSelectedArrow " -> " contained nextgroup=gitcommitSelectedFile +syn match gitcommitUnmergedArrow " -> " contained nextgroup=gitcommitSelectedFile + +syn match gitcommitWarning "\%^[^#].*: needs merge$" nextgroup=gitcommitWarning skipnl +syn match gitcommitWarning "^[^#].*: needs merge$" nextgroup=gitcommitWarning skipnl contained +syn match gitcommitWarning "^\%(no changes added to commit\|nothing \%(added \)\=to commit\)\>.*\%$" + +hi def link gitcommitSummary Keyword +hi def link gitcommitComment Comment +hi def link gitcommitUntracked gitcommitComment +hi def link gitcommitDiscarded gitcommitComment +hi def link gitcommitSelected gitcommitComment +hi def link gitcommitUnmerged gitcommitComment +hi def link gitcommitOnBranch Comment +hi def link gitcommitBranch Special +hi def link gitcommitNoBranch gitCommitBranch +hi def link gitcommitDiscardedType gitcommitType +hi def link gitcommitSelectedType gitcommitType +hi def link gitcommitUnmergedType gitcommitType +hi def link gitcommitType Type +hi def link gitcommitNoChanges gitcommitHeader +hi def link gitcommitHeader PreProc +hi def link gitcommitUntrackedFile gitcommitFile +hi def link gitcommitDiscardedFile gitcommitFile +hi def link gitcommitSelectedFile gitcommitFile +hi def link gitcommitUnmergedFile gitcommitFile +hi def link gitcommitFile Constant +hi def link gitcommitDiscardedArrow gitcommitArrow +hi def link gitcommitSelectedArrow gitcommitArrow +hi def link gitcommitUnmergedArrow gitcommitArrow +hi def link gitcommitArrow gitcommitComment +"hi def link gitcommitOverflow Error +hi def link gitcommitBlank Error + +let b:current_syntax = "gitcommit" diff --git a/vim/syntax/gitconfig.vim b/vim/syntax/gitconfig.vim new file mode 100644 index 0000000..0e64022 --- /dev/null +++ b/vim/syntax/gitconfig.vim @@ -0,0 +1,37 @@ +" Vim syntax file +" Language: git config file +" Maintainer: Tim Pope +" Filenames: gitconfig, .gitconfig, *.git/config + +if exists("b:current_syntax") + finish +endif + +setlocal iskeyword+=- +setlocal iskeyword-=_ +syn case ignore +syn sync minlines=10 + +syn match gitconfigComment "[#;].*" +syn match gitconfigSection "\%(^\s*\)\@<=\[[a-z0-9.-]\+\]" +syn match gitconfigSection '\%(^\s*\)\@<=\[[a-z0-9.-]\+ \+\"\%([^\\"]\|\\.\)*"\]' +syn match gitconfigVariable "\%(^\s*\)\@<=\a\k*\%(\s*\%([=#;]\|$\)\)\@=" nextgroup=gitconfigAssignment skipwhite +syn region gitconfigAssignment matchgroup=gitconfigNone start=+=\s*+ skip=+\\+ end=+\s*$+ contained contains=gitconfigBoolean,gitconfigNumber,gitConfigString,gitConfigEscape,gitConfigError,gitconfigComment keepend +syn keyword gitconfigBoolean true false yes no contained +syn match gitconfigNumber "\d\+" contained +syn region gitconfigString matchgroup=gitconfigDelim start=+"+ skip=+\\+ end=+"+ matchgroup=gitconfigError end=+[^\\"]\%#\@!$+ contained contains=gitconfigEscape,gitconfigEscapeError +syn match gitconfigError +\\.+ contained +syn match gitconfigEscape +\\[\\"ntb]+ contained +syn match gitconfigEscape +\\$+ contained + +hi def link gitconfigComment Comment +hi def link gitconfigSection Keyword +hi def link gitconfigVariable Identifier +hi def link gitconfigBoolean Boolean +hi def link gitconfigNumber Number +hi def link gitconfigString String +hi def link gitconfigDelim Delimiter +hi def link gitconfigEscape Delimiter +hi def link gitconfigError Error + +let b:current_syntax = "gitconfig" diff --git a/vim/syntax/gitrebase.vim b/vim/syntax/gitrebase.vim new file mode 100644 index 0000000..5edef89 --- /dev/null +++ b/vim/syntax/gitrebase.vim @@ -0,0 +1,34 @@ +" Vim syntax file +" Language: git rebase --interactive +" Maintainer: Tim Pope +" Filenames: git-rebase-todo + +if exists("b:current_syntax") + finish +endif + +syn case match + +syn match gitrebaseHash "\v<\x{7,40}>" contained +syn match gitrebaseCommit "\v<\x{7,40}>" nextgroup=gitrebaseSummary skipwhite +syn match gitrebasePick "\v^p%(ick)=>" nextgroup=gitrebaseCommit skipwhite +syn match gitrebaseReword "\v^r%(eword)=>" nextgroup=gitrebaseCommit skipwhite +syn match gitrebaseEdit "\v^e%(dit)=>" nextgroup=gitrebaseCommit skipwhite +syn match gitrebaseSquash "\v^s%(quash)=>" nextgroup=gitrebaseCommit skipwhite +syn match gitrebaseFixup "\v^f%(ixup)=>" nextgroup=gitrebaseCommit skipwhite +syn match gitrebaseSummary ".*" contains=gitrebaseHash contained +syn match gitrebaseComment "^#.*" contains=gitrebaseHash +syn match gitrebaseSquashError "\v%^%(s%(quash)=>|f%(ixup)=>)" nextgroup=gitrebaseCommit skipwhite + +hi def link gitrebaseCommit gitrebaseHash +hi def link gitrebaseHash Identifier +hi def link gitrebasePick Statement +hi def link gitrebaseReword Number +hi def link gitrebaseEdit PreProc +hi def link gitrebaseSquash Type +hi def link gitrebaseFixup Special +hi def link gitrebaseSummary String +hi def link gitrebaseComment Comment +hi def link gitrebaseSquashError Error + +let b:current_syntax = "gitrebase" diff --git a/vim/syntax/gitsendemail.vim b/vim/syntax/gitsendemail.vim new file mode 100644 index 0000000..bb9ae9c --- /dev/null +++ b/vim/syntax/gitsendemail.vim @@ -0,0 +1,18 @@ +" Vim syntax file +" Language: git send-email message +" Maintainer: Tim Pope +" Filenames: *.msg.[0-9]* (first line is "From ... # This line is ignored.") + +if exists("b:current_syntax") + finish +endif + +runtime! syntax/mail.vim +syn case match + +syn match gitsendemailComment "\%^From.*#.*" +syn match gitsendemailComment "^GIT:.*" + +hi def link gitsendemailComment Comment + +let b:current_syntax = "gitsendemail" diff --git a/vim/syntax/javascript.vim b/vim/syntax/javascript.vim new file mode 100644 index 0000000..91d2506 --- /dev/null +++ b/vim/syntax/javascript.vim @@ -0,0 +1,258 @@ +" Vim syntax file +" Language: JavaScript +" Maintainer: Yi Zhao (ZHAOYI) +" Last Change By: Marc Harter +" Last Change: February 18, 2011 +" Version: 0.7.9 +" Changes: Updates JSDoc syntax +" +" TODO: +" - Add the HTML syntax inside the JSDoc + +if !exists("main_syntax") + if version < 600 + syntax clear + elseif exists("b:current_syntax") + finish + endif + let main_syntax = 'javascript' +endif + +"" Drop fold if it set but VIM doesn't support it. +let b:javascript_fold='true' +if version < 600 " Don't support the old version + unlet! b:javascript_fold +endif + +"" dollar sigh is permittd anywhere in an identifier +setlocal iskeyword+=$ + +syntax sync fromstart + +"" JavaScript comments +syntax keyword javaScriptCommentTodo TODO FIXME XXX TBD contained +syntax region javaScriptLineComment start=+\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell +syntax region javaScriptEnvComment start="\%^#!" end="$" display +syntax region javaScriptLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell fold +syntax region javaScriptCvsTag start="\$\cid:" end="\$" oneline contained +syntax region javaScriptComment start="/\*" end="\*/" contains=javaScriptCommentTodo,javaScriptCvsTag,@Spell fold + +"" JSDoc / JSDoc Toolkit +if !exists("javascript_ignore_javaScriptdoc") + syntax case ignore + + "" syntax coloring for javadoc comments (HTML) + "syntax include @javaHtml :p:h/html.vim + "unlet b:current_syntax + + syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold + + " tags containing a param + syntax match javaScriptDocTags contained "@\(augments\|base\|borrows\|class\|constructs\|default\|exception\|exports\|extends\|file\|member\|memberOf\|module\|name\|namespace\|optional\|requires\|title\|throws\|version\)\>" nextgroup=javaScriptDocParam skipwhite + " tags containing type and param + syntax match javaScriptDocTags contained "@\(argument\|param\|property\)\>" nextgroup=javaScriptDocType skipwhite + " tags containing type but no param + syntax match javaScriptDocTags contained "@\(type\|return\|returns\)\>" nextgroup=javaScriptDocTypeNoParam skipwhite + " tags containing references + syntax match javaScriptDocTags contained "@\(lends\|link\|see\)\>" nextgroup=javaScriptDocSeeTag skipwhite + " other tags (no extra syntax) + syntax match javaScriptDocTags contained "@\(access\|addon\|alias\|author\|beta\|constant\|constructor\|copyright\|deprecated\|description\|event\|example\|exec\|field\|fileOverview\|fileoverview\|function\|global\|ignore\|inner\|license\|overview\|private\|protected\|project\|public\|readonly\|since\|static\)\>" + + syntax region javaScriptDocType start="{" end="}" oneline contained nextgroup=javaScriptDocParam skipwhite + syntax match javaScriptDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" nextgroup=javaScriptDocParam skipwhite + syntax region javaScriptDocTypeNoParam start="{" end="}" oneline contained + syntax match javaScriptDocTypeNoParam contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" + syntax match javaScriptDocParam contained "\%(#\|\"\|{\|}\|\w\|\.\|:\|\/\)\+" + syntax region javaScriptDocSeeTag contained matchgroup=javaScriptDocSeeTag start="{" end="}" contains=javaScriptDocTags + + syntax case match +endif "" JSDoc end + +syntax case match + +"" Syntax in the JavaScript code +syntax match javaScriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\." +syntax region javaScriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=javaScriptSpecial,@htmlPreproc +syntax region javaScriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc +syntax region javaScriptRegexpCharClass start=+\[\]\|\[^\]\|\[+ end=+\]+ contained +syntax region javaScriptRegexpString start=+\(\(\(return\|case\)\s\+\)\@<=\|\(\([)\]"']\|\d\|\w\)\s*\)\@\|\<0[xX]\x\+\>/ +syntax match javaScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/ +syntax match javaScriptLabel /\(?\s*\)\@/ + syntax match javaScriptDomElemFuncs contained /\%(insertBefore\|replaceChild\|removeChild\|appendChild\|hasChildNodes\|cloneNode\|normalize\|isSupported\|hasAttributes\|getAttribute\|setAttribute\|removeAttribute\|getAttributeNode\|setAttributeNode\|removeAttributeNode\|getElementsByTagName\|getAttributeNS\|setAttributeNS\|removeAttributeNS\|getAttributeNodeNS\|setAttributeNodeNS\|getElementsByTagNameNS\|hasAttribute\|hasAttributeNS\)\>/ nextgroup=javaScriptParen skipwhite + " HTML things + syntax match javaScriptHtmlElemAttrs contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/ + syntax match javaScriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=javaScriptParen skipwhite + + " CSS Styles in JavaScript + syntax keyword javaScriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition + syntax keyword javaScriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition + syntax keyword javaScriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode + syntax keyword javaScriptCssStyles contained bottom height left position right top width zIndex + syntax keyword javaScriptCssStyles contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout + syntax keyword javaScriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop + syntax keyword javaScriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType + syntax keyword javaScriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat + syntax keyword javaScriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType + syntax keyword javaScriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText + syntax keyword javaScriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor + + " Highlight ways + syntax match javaScriptDotNotation "\." nextgroup=javaScriptPrototype,javaScriptDomElemAttrs,javaScriptDomElemFuncs,javaScriptHtmlElemAttrs,javaScriptHtmlElemFuncs + syntax match javaScriptDotNotation "\.style\." nextgroup=javaScriptCssStyles + +endif "DOM/HTML/CSS + +"" end DOM/HTML/CSS specified things + + +"" Code blocks +syntax cluster javaScriptAll contains=javaScriptComment,javaScriptLineComment,javaScriptDocComment,javaScriptStringD,javaScriptStringS,javaScriptRegexpString,javaScriptNumber,javaScriptFloat,javaScriptLabel,javaScriptSource,javaScriptThis,javaScriptType,javaScriptOperator,javaScriptBoolean,javaScriptNull,javaScriptFunction,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptStatement,javaScriptGlobalObjects,javaScriptExceptions,javaScriptFutureKeys,javaScriptDomErrNo,javaScriptDomNodeConsts,javaScriptHtmlEvents,javaScriptDotNotation +syntax region javaScriptBracket matchgroup=javaScriptBracket transparent start="\[" end="\]" contains=@javaScriptAll,javaScriptParensErrB,javaScriptParensErrC,javaScriptBracket,javaScriptParen,javaScriptBlock,@htmlPreproc +syntax region javaScriptParen matchgroup=javaScriptParen transparent start="(" end=")" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrC,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc +syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc + +"" catch errors caused by wrong parenthesis +syntax match javaScriptParensError ")\|}\|\]" +syntax match javaScriptParensErrA contained "\]" +syntax match javaScriptParensErrB contained ")" +syntax match javaScriptParensErrC contained "}" + +if main_syntax == "javascript" + syntax sync clear + syntax sync ccomment javaScriptComment minlines=200 + syntax sync match javaScriptHighlight grouphere javaScriptBlock /{/ +endif + +"" Fold control +if exists("b:javascript_fold") + syntax match javaScriptFunction /\/ nextgroup=javaScriptFuncName skipwhite + syntax match javaScriptOpAssign /=\@= 508 || !exists("did_javascript_syn_inits") + if version < 508 + let did_javascript_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + HiLink javaScriptComment Comment + HiLink javaScriptLineComment Comment + HiLink javaScriptEnvComment PreProc + HiLink javaScriptDocComment Comment + HiLink javaScriptCommentTodo Todo + HiLink javaScriptCvsTag Function + HiLink javaScriptDocTags Special + HiLink javaScriptDocSeeTag Function + HiLink javaScriptDocType Type + HiLink javaScriptDocTypeNoParam Type + HiLink javaScriptDocParam Label + HiLink javaScriptStringS String + HiLink javaScriptStringD String + HiLink javaScriptRegexpString String + HiLink javaScriptRegexpCharClass Character + HiLink javaScriptCharacter Character + HiLink javaScriptPrototype Type + HiLink javaScriptConditional Conditional + HiLink javaScriptBranch Conditional + HiLink javaScriptRepeat Repeat + HiLink javaScriptStatement Statement + HiLink javaScriptFunction Function + HiLink javaScriptError Error + HiLink javaScriptParensError Error + HiLink javaScriptParensErrA Error + HiLink javaScriptParensErrB Error + HiLink javaScriptParensErrC Error + HiLink javaScriptOperator Operator + HiLink javaScriptType Type + HiLink javaScriptThis Type + HiLink javaScriptNull Type + HiLink javaScriptNumber Number + HiLink javaScriptFloat Number + HiLink javaScriptBoolean Boolean + HiLink javaScriptLabel Label + HiLink javaScriptSpecial Special + HiLink javaScriptSource Special + HiLink javaScriptGlobalObjects Special + HiLink javaScriptExceptions Special + + HiLink javaScriptDomErrNo Constant + HiLink javaScriptDomNodeConsts Constant + HiLink javaScriptDomElemAttrs Label + HiLink javaScriptDomElemFuncs PreProc + + HiLink javaScriptHtmlEvents Special + HiLink javaScriptHtmlElemAttrs Label + HiLink javaScriptHtmlElemFuncs PreProc + + HiLink javaScriptCssStyles Label + + delcommand HiLink +endif + +" Define the htmlJavaScript for HTML syntax html.vim +"syntax clear htmlJavaScript +"syntax clear javaScriptExpression +syntax cluster htmlJavaScript contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError +syntax cluster javaScriptExpression contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError,@htmlPreproc + +let b:current_syntax = "javascript" +if main_syntax == 'javascript' + unlet main_syntax +endif + +" vim: ts=4 diff --git a/vim/syntax/markdown.vim b/vim/syntax/markdown.vim new file mode 100644 index 0000000..072865e --- /dev/null +++ b/vim/syntax/markdown.vim @@ -0,0 +1,107 @@ +" Vim syntax file +" Language: Markdown +" Maintainer: Tim Pope +" Filenames: *.markdown + +if exists("b:current_syntax") + finish +endif + +runtime! syntax/html.vim +unlet! b:current_syntax + +syn sync minlines=10 +syn case ignore + +syn match markdownValid '[<>]\S\@!' +syn match markdownValid '&\%(#\=\w*;\)\@!' + +syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock + +syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule +syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop + +syn match markdownH1 ".\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule +syn match markdownH2 ".\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule + +syn match markdownHeadingRule "^[=-]\+$" contained + +syn region markdownH1 matchgroup=markdownHeadingDelimiter start="##\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH2 matchgroup=markdownHeadingDelimiter start="###\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH3 matchgroup=markdownHeadingDelimiter start="####\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH4 matchgroup=markdownHeadingDelimiter start="#####\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH5 matchgroup=markdownHeadingDelimiter start="######\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH6 matchgroup=markdownHeadingDelimiter start="#######\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained + +syn match markdownBlockquote ">\s" contained nextgroup=@markdownBlock + +syn region markdownCodeBlock start=" \|\t" end="$" contained + +" TODO: real nesting +syn match markdownListMarker " \{0,4\}[-*+]\%(\s\+\S\)\@=" contained +syn match markdownOrderedListMarker " \{0,4}\<\d\+\.\%(\s*\S\)\@=" contained + +syn match markdownRule "\* *\* *\*[ *]*$" contained +syn match markdownRule "- *- *-[ -]*$" contained + +syn match markdownLineBreak "\s\{2,\}$" + +syn region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^ \{0,3\}!\=\[" end="\]:" oneline keepend nextgroup=markdownUrl skipwhite +syn match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained +syn region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained + +syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" keepend nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart +syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained +syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained +syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline + +syn region markdownItalic start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=markdownLineStart +syn region markdownItalic start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" keepend contains=markdownLineStart +syn region markdownBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend contains=markdownLineStart +syn region markdownBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend contains=markdownLineStart +syn region markdownBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend contains=markdownLineStart +syn region markdownBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend contains=markdownLineStart +syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart +syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart +syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*\zs```\s*\w*\ze\s*$" end="^```\ze\s*$" keepend + +syn match markdownEscape "\\[][\\`*_{}()#+.!-]" +syn match markdownError "\w\@<=_\w\@=" + +hi def link markdownH1 htmlH1 +hi def link markdownH2 htmlH2 +hi def link markdownH3 htmlH3 +hi def link markdownH4 htmlH4 +hi def link markdownH5 htmlH5 +hi def link markdownH6 htmlH6 +hi def link markdownHeadingRule markdownRule +hi def link markdownHeadingDelimiter Delimiter +hi def link markdownOrderedListMarker markdownListMarker +hi def link markdownListMarker htmlTagName +hi def link markdownBlockquote Comment +hi def link markdownRule PreProc + +hi def link markdownLinkText htmlLink +hi def link markdownIdDeclaration Typedef +hi def link markdownId Type +hi def link markdownAutomaticLink markdownUrl +hi def link markdownUrl Float +hi def link markdownUrlTitle String +hi def link markdownIdDelimiter markdownLinkDelimiter +hi def link markdownUrlDelimiter htmlTag +hi def link markdownUrlTitleDelimiter Delimiter + +hi def link markdownItalic htmlItalic +hi def link markdownBold htmlBold +hi def link markdownBoldItalic htmlBoldItalic +hi def link markdownCodeDelimiter Delimiter + +hi def link markdownEscape Special +hi def link markdownError Error + +let b:current_syntax = "markdown" + +" vim:set sw=2: diff --git a/vim/syntax/mustache.vim b/vim/syntax/mustache.vim new file mode 100644 index 0000000..dd5aae8 --- /dev/null +++ b/vim/syntax/mustache.vim @@ -0,0 +1,69 @@ +" Vim syntax file +" Language: Mustache +" Maintainer: Juvenn Woo +" Screenshot: http://imgur.com/6F408 +" Version: 1 +" Last Change: 2009 Oct 15 +" Remark: +" It lexically hilights embedded mustaches (exclusively) in html file. +" While it was written for Ruby-based Mustache template system, it should work for Google's C-based *ctemplate* as well as Erlang-based *et*. All of them are, AFAIK, based on the idea of ctemplate. +" References: +" [Mustache](http://github.com/defunkt/mustache) +" [ctemplate](http://code.google.com/p/google-ctemplate/) +" [ctemplate doc](http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html) +" [et](http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html) +" TODO: Feedback is welcomed. + + +" Read the HTML syntax to start with +if version < 600 + so :p:h/html.vim +else + runtime! syntax/html.vim + unlet b:current_syntax +endif + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" Standard HiLink will not work with included syntax files +if version < 508 + command! -nargs=+ HtmlHiLink hi link +else + command! -nargs=+ HtmlHiLink hi def link +endif + +syntax match mustacheError '}}}\?' +syntax match mustacheInsideError '{{[{#^<>=!\/]\?' containedin=@mustacheInside +syntax region mustacheVariable matchgroup=mustacheMarker start=/{{/ end=/}}/ containedin=@htmlMustacheContainer +syntax region mustacheVariableUnescape matchgroup=mustacheMarker start=/{{{/ end=/}}}/ containedin=@htmlMustacheContainer +syntax region mustacheSection matchgroup=mustacheMarker start='{{[#^/]' end=/}}/ containedin=@htmlMustacheContainer +syntax region mustachePartial matchgroup=mustacheMarker start=/{{[<>]/ end=/}}/ +syntax region mustacheMarkerSet matchgroup=mustacheMarker start=/{{=/ end=/=}}/ +syntax region mustacheComment start=/{{!/ end=/}}/ contains=Todo containedin=htmlHead + + +" Clustering +syntax cluster mustacheInside add=mustacheVariable,mustacheVariableUnescape,mustacheSection,mustachePartial,mustacheMarkerSet +syntax cluster htmlMustacheContainer add=htmlHead,htmlTitle,htmlString,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6 + + +" Hilighting +" mustacheInside hilighted as Number, which is rarely used in html +" you might like change it to Function or Identifier +HtmlHiLink mustacheVariable Number +HtmlHiLink mustacheVariableUnescape Number +HtmlHiLink mustachePartial Number +HtmlHiLink mustacheSection Number +HtmlHiLink mustacheMarkerSet Number + +HtmlHiLink mustacheComment Comment +HtmlHiLink mustacheMarker Identifier +HtmlHiLink mustacheError Error +HtmlHiLink mustacheInsideError Error + +let b:current_syntax = "mustache" +delcommand HtmlHiLink \ No newline at end of file diff --git a/vim/syntax/puppet.vim b/vim/syntax/puppet.vim new file mode 100644 index 0000000..8cdada1 --- /dev/null +++ b/vim/syntax/puppet.vim @@ -0,0 +1,117 @@ +" puppet syntax file +" Filename: puppet.vim +" Language: puppet configuration file +" Maintainer: Luke Kanies +" URL: +" Last Change: +" Version: +" + +" Copied from the cfengine, ruby, and perl syntax files +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" match class/definition/node declarations +syn region puppetDefine start="^\s*\(class\|define\|node\)\s" end="{" contains=puppetDefType,puppetDefName,puppetDefArguments,puppetNodeRe +syn keyword puppetDefType class define node inherits contained +syn region puppetDefArguments start="(" end=")" contained contains=puppetArgument,puppetString +syn match puppetArgument "\w\+" contained +syn match puppetArgument "\$\w\+" contained +syn match puppetArgument "'[^']+'" contained +syn match puppetArgument '"[^"]+"' contained +syn match puppetDefName "\w\+" contained +syn match puppetNodeRe "/.*/" contained + +" match 'foo' in 'class foo { ...' +" match 'foo::bar' in 'class foo::bar { ...' +" match 'Foo::Bar' in 'Foo::Bar["..."] +"FIXME: "Foo-bar" doesn't get highlighted as expected, although "foo-bar" does. +syn match puppetInstance "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)*\s*{" contains=puppetTypeName,puppetTypeDefault +syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*[[{]" contains=puppetTypeName,puppetTypeDefault +syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*<\?<|" contains=puppetTypeName,puppetTypeDefault +syn match puppetTypeName "[a-z]\w*" contained +syn match puppetTypeDefault "[A-Z]\w*" contained + +" match 'foo' in 'foo => "bar"' +syn match puppetParam "\w\+\s*[=+]>" contains=puppetParamName +syn match puppetParamName "\w\+" contained + +" match 'present' in 'ensure => present' +" match '2755' in 'mode => 2755' +" don't match 'bar' in 'foo => bar' +syn match puppetParam "\w\+\s*[=+]>\s*[a-z0-9]\+" contains=puppetParamString,puppetParamName +syn match puppetParamString "[=+]>\s*\w\+" contains=puppetParamKeyword,puppetParamSpecial,puppetParamDigits contained +syn keyword puppetParamKeyword present absent purged latest installed running stopped mounted unmounted role configured file directory link contained +syn keyword puppetParamSpecial true false undef contained +syn match puppetParamDigits "[0-9]\+" + +" match 'template' in 'content => template("...")' +syn match puppetParam "\w\+\s*[=+]>\s*\w\+\s*(" contains=puppetFunction,puppetParamName +" statements +syn region puppetFunction start="^\s*\(alert\|crit\|debug\|emerg\|err\|fail\|include\|info\|notice\|realize\|require\|search\|tag\|warning\)\s*(" end=")" contained contains=puppetString +" rvalues +syn region puppetFunction start="^\s*\(defined\|file\|fqdn_rand\|generate\|inline_template\|regsubst\|sha1\|shellquote\|split\|sprintf\|tagged\|template\|versioncmp\)\s*(" end=")" contained contains=puppetString + +syn match puppetVariable "$[a-zA-Z0-9_:]\+" +syn match puppetVariable "${[a-zA-Z0-9_:]\+}" + +" match anything between simple/double quotes. +" don't match variables if preceded by a backslash. +syn region puppetString start=+'+ skip=+\\\\\|\\'+ end=+'+ +syn region puppetString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable,puppetNotVariable +syn match puppetString "/[^/]*/" +syn match puppetNotVariable "\\$\w\+" contained +syn match puppetNotVariable "\\${\w\+}" contained + +syn keyword puppetKeyword import inherits include +syn keyword puppetControl case default if else elsif +syn keyword puppetSpecial true false undef + +" comments last overriding everything else +syn match puppetComment "\s*#.*$" contains=puppetTodo +syn region puppetComment start="/\*" end="\*/" contains=puppetTodo extend +syn keyword puppetTodo TODO NOTE FIXME XXX BUG HACK contained + +" Define the default highlighting. +" For version 5.7 and earlier: only when not done already +" For version 5.8 and later: only when an item doesn't have highlighting yet +if version >= 508 || !exists("did_puppet_syn_inits") + if version < 508 + let did_puppet_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink puppetVariable Identifier + HiLink puppetType Identifier + HiLink puppetKeyword Define + HiLink puppetComment Comment + HiLink puppetString String + HiLink puppetParamKeyword String + HiLink puppetParamDigits String + HiLink puppetNotVariable String + HiLink puppetParamSpecial Special + HiLink puppetSpecial Special + HiLink puppetTodo Todo + HiLink puppetControl Statement + HiLink puppetDefType Define + HiLink puppetDefName Type + HiLink puppetNodeRe Type + HiLink puppetTypeName Statement + HiLink puppetTypeDefault Type + HiLink puppetParamName Identifier + HiLink puppetArgument Identifier + HiLink puppetFunction Function + + delcommand HiLink +endif + +let b:current_syntax = "puppet" +set iskeyword=-,:,@,48-57,_,192-255 + diff --git a/vim/syntax/sass.vim b/vim/syntax/sass.vim new file mode 100644 index 0000000..629da26 --- /dev/null +++ b/vim/syntax/sass.vim @@ -0,0 +1,90 @@ +" Vim syntax file +" Language: Sass +" Maintainer: Tim Pope +" Filenames: *.sass +" Last Change: 2010 Aug 09 + +if exists("b:current_syntax") + finish +endif + +runtime! syntax/css.vim + +syn case ignore + +syn cluster sassCssProperties contains=cssFontProp,cssFontDescriptorProp,cssColorProp,cssTextProp,cssBoxProp,cssGeneratedContentProp,cssPagingProp,cssUIProp,cssRenderProp,cssAuralProp,cssTableProp +syn cluster sassCssAttributes contains=css.*Attr,scssComment,cssValue.*,cssColor,cssURL,sassDefault,cssImportant,cssError,cssStringQ,cssStringQQ,cssFunction,cssUnicodeEscape,cssRenderProp + +syn region sassDefinition matchgroup=cssBraces start="{" end="}" contains=TOP + +syn match sassProperty "\%([{};]\s*\|^\)\@<=\%([[:alnum:]-]\|#{[^{}]*}\)\+:" contains=css.*Prop skipwhite nextgroup=sassCssAttribute contained containedin=sassDefinition +syn match sassProperty "^\s*\zs\s\%(\%([[:alnum:]-]\|#{[^{}]*}\)\+:\|:[[:alnum:]-]\+\)"hs=s+1 contains=css.*Prop skipwhite nextgroup=sassCssAttribute +syn match sassProperty "^\s*\zs\s\%(:\=[[:alnum:]-]\+\s*=\)"hs=s+1 contains=css.*Prop skipwhite nextgroup=sassCssAttribute +syn match sassCssAttribute +\%("\%([^"]\|\\"\)*"\|'\%([^']\|\\'\)*'\|#{[^{}]*}\|[^{};]\)*+ contained contains=@sassCssAttributes,sassVariable,sassFunction,sassInterpolation +syn match sassDefault "!default\>" contained +syn match sassVariable "!\%(important\>\|default\>\)\@![[:alnum:]_-]\+" +syn match sassVariable "$[[:alnum:]_-]\+" +syn match sassVariableAssignment "\%([!$][[:alnum:]_-]\+\s*\)\@<=\%(||\)\==" nextgroup=sassCssAttribute skipwhite +syn match sassVariableAssignment "\%([!$][[:alnum:]_-]\+\s*\)\@<=:" nextgroup=sassCssAttribute skipwhite + +syn match sassFunction "\<\%(rgb\|rgba\|red\|green\|blue\|mix\)\>(\@=" contained +syn match sassFunction "\<\%(hsl\|hsla\|hue\|saturation\|lightness\|adjust-hue\|lighten\|darken\|saturate\|desaturate\|grayscale\|complement\)\>(\@=" contained +syn match sassFunction "\<\%(alpha\|opacity\|rgba\|opacify\|fade-in\|transparentize\|fade-out\)\>(\@=" contained +syn match sassFunction "\<\%(unquote\|quote\)\>(\@=" contained +syn match sassFunction "\<\%(percentage\|round\|ceil\|floor\|abs\)\>(\@=" contained +syn match sassFunction "\<\%(type-of\|unit\|unitless\|comparable\)\>(\@=" contained + +syn region sassInterpolation matchgroup=sassInterpolationDelimiter start="#{" end="}" contains=@sassCssAttributes,sassVariable,sassFunction containedin=cssStringQ,cssStringQQ,sassProperty + +syn match sassMixinName "[[:alnum:]_-]\+" contained nextgroup=sassCssAttribute +syn match sassMixin "^=" nextgroup=sassMixinName skipwhite +syn match sassMixin "\%([{};]\s*\|^\s*\)\@<=@mixin" nextgroup=sassMixinName skipwhite +syn match sassMixing "^\s\+\zs+" nextgroup=sassMixinName +syn match sassMixing "\%([{};]\s*\|^\s*\)\@<=@include" nextgroup=sassMixinName skipwhite +syn match sassExtend "\%([{};]\s*\|^\s*\)\@<=@extend" + +syn match sassEscape "^\s*\zs\\" +syn match sassIdChar "#[[:alnum:]_-]\@=" nextgroup=sassId +syn match sassId "[[:alnum:]_-]\+" contained +syn match sassClassChar "\.[[:alnum:]_-]\@=" nextgroup=sassClass +syn match sassClass "[[:alnum:]_-]\+" contained +syn match sassAmpersand "&" + +" TODO: Attribute namespaces +" TODO: Arithmetic (including strings and concatenation) + +syn region sassInclude start="@import" end=";\|$" contains=scssComment,cssURL,cssUnicodeEscape,cssMediaType +syn region sassDebugLine end=";\|$" matchgroup=sassDebug start="@debug\>" contains=@sassCssAttributes,sassVariable,sassFunction +syn region sassWarnLine end=";\|$" matchgroup=sassWarn start="@warn\>" contains=@sassCssAttributes,sassVariable,sassFunction +syn region sassControlLine matchgroup=sassControl start="@\%(if\|else\%(\s\+if\)\=\|while\|for\|each\)\>" end="[{};]\@=\|$" contains=sassFor,@sassCssAttributes,sassVariable,sassFunction +syn keyword sassFor from to through in contained + +syn keyword sassTodo FIXME NOTE TODO OPTIMIZE XXX contained +syn region sassComment start="^\z(\s*\)//" end="^\%(\z1 \)\@!" contains=sassTodo,@Spell +syn region sassCssComment start="^\z(\s*\)/\*" end="^\%(\z1 \)\@!" contains=sassTodo,@Spell + +hi def link sassCssComment sassComment +hi def link sassComment Comment +hi def link sassDefault cssImportant +hi def link sassVariable Identifier +hi def link sassFunction Function +hi def link sassMixing PreProc +hi def link sassMixin PreProc +hi def link sassExtend PreProc +hi def link sassTodo Todo +hi def link sassInclude Include +hi def link sassDebug sassControl +hi def link sassWarn sassControl +hi def link sassControl PreProc +hi def link sassFor PreProc +hi def link sassEscape Special +hi def link sassIdChar Special +hi def link sassClassChar Special +hi def link sassInterpolationDelimiter Delimiter +hi def link sassAmpersand Character +hi def link sassId Identifier +hi def link sassClass Type + +let b:current_syntax = "sass" + +" vim:set sw=2: diff --git a/vim/syntax/scala.vim b/vim/syntax/scala.vim new file mode 100644 index 0000000..36605ab --- /dev/null +++ b/vim/syntax/scala.vim @@ -0,0 +1,151 @@ +" Vim syntax file +" Language : Scala (http://scala-lang.org/) +" Maintainers: Stefan Matthias Aust, Julien Wetterwald +" Last Change: 2007 June 13 + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +syn case match +syn sync minlines=50 + +" most Scala keywords +syn keyword scalaKeyword abstract case catch do else extends final finally for forSome if implicit lazy match new null override private protected requires return sealed super this throw try type while with yield +syn match scalaKeyword "=>" +syn match scalaKeyword "<-" +syn match scalaKeyword "\<_\>" + +syn match scalaOperator ":\{2,\}" "this is not a type + +" package and import statements +syn keyword scalaPackage package nextgroup=scalaFqn skipwhite +syn keyword scalaImport import nextgroup=scalaFqn skipwhite +syn match scalaFqn "\<[._$a-zA-Z0-9,]*" contained nextgroup=scalaFqnSet +syn region scalaFqnSet start="{" end="}" contained + +" boolean literals +syn keyword scalaBoolean true false + +" definitions +syn keyword scalaDef def nextgroup=scalaDefName skipwhite +syn keyword scalaVal val nextgroup=scalaValName skipwhite +syn keyword scalaVar var nextgroup=scalaVarName skipwhite +syn keyword scalaClass class nextgroup=scalaClassName skipwhite +syn keyword scalaObject object nextgroup=scalaClassName skipwhite +syn keyword scalaTrait trait nextgroup=scalaClassName skipwhite +syn match scalaDefName "[^ =:;([]\+" contained nextgroup=scalaDefSpecializer skipwhite +syn match scalaValName "[^ =:;([]\+" contained +syn match scalaVarName "[^ =:;([]\+" contained +syn match scalaClassName "[^ =:;(\[]\+" contained nextgroup=scalaClassSpecializer skipwhite +syn region scalaDefSpecializer start="\[" end="\]" contained contains=scalaDefSpecializer +syn region scalaClassSpecializer start="\[" end="\]" contained contains=scalaClassSpecializer + +" type constructor (actually anything with an uppercase letter) +syn match scalaConstructor "\<[A-Z][_$a-zA-Z0-9]*\>" nextgroup=scalaConstructorSpecializer +syn region scalaConstructorSpecializer start="\[" end="\]" contained contains=scalaConstructorSpecializer + +" method call +syn match scalaRoot "\<[a-zA-Z][_$a-zA-Z0-9]*\."me=e-1 +syn match scalaMethodCall "\.[a-z][_$a-zA-Z0-9]*"ms=s+1 + +" type declarations in val/var/def +syn match scalaType ":\s*\(=>\s*\)\?[._$a-zA-Z0-9]\+\(\[[^]]*\]\+\)\?\(\s*\(<:\|>:\|#\|=>\)\s*[._$a-zA-Z0-9]\+\(\[[^]]*\]\+\)*\)*"ms=s+1 + +" comments +syn match scalaTodo "[tT][oO][dD][oO]" contained +syn match scalaLineComment "//.*" contains=scalaTodo +syn region scalaComment start="/\*" end="\*/" contains=scalaTodo +syn case ignore +syn include @scalaHtml syntax/html.vim +unlet b:current_syntax +syn case match +syn region scalaDocComment start="/\*\*" end="\*/" contains=scalaDocTags,scalaTodo,@scalaHtml keepend +syn region scalaDocTags start="{@\(link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}" contained +syn match scalaDocTags "@[a-z]\+" contained + +syn match scalaEmptyString "\"\"" + +" multi-line string literals +syn region scalaMultiLineString start="\"\"\"" end="\"\"\"" contains=scalaUnicode +syn match scalaUnicode "\\u[0-9a-fA-F]\{4}" contained + +" string literals with escapes +syn region scalaString start="\"[^"]" skip="\\\"" end="\"" contains=scalaStringEscape " TODO end \n or not? +syn match scalaStringEscape "\\u[0-9a-fA-F]\{4}" contained +syn match scalaStringEscape "\\[nrfvb\\\"]" contained + +" symbol and character literals +syn match scalaSymbol "'[_a-zA-Z0-9][_a-zA-Z0-9]*\>" +syn match scalaChar "'[^'\\]'\|'\\.'\|'\\u[0-9a-fA-F]\{4}'" + +" number literals +syn match scalaNumber "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>" +syn match scalaNumber "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\=" +syn match scalaNumber "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>" +syn match scalaNumber "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>" + +" xml literals +syn match scalaXmlTag "<[a-zA-Z]\_[^>]*/>" contains=scalaXmlQuote,scalaXmlEscape,scalaXmlString +syn region scalaXmlString start="\"" end="\"" contained +syn match scalaXmlStart "<[a-zA-Z]\_[^>]*>" contained contains=scalaXmlQuote,scalaXmlEscape,scalaXmlString +syn region scalaXml start="<\([a-zA-Z]\_[^>]*\_[^/]\|[a-zA-Z]\)>" matchgroup=scalaXmlStart end="]\+>" contains=scalaXmlEscape,scalaXmlQuote,scalaXml,scalaXmlStart,scalaXmlComment +syn region scalaXmlEscape matchgroup=scalaXmlEscapeSpecial start="{" matchgroup=scalaXmlEscapeSpecial end="}" contained contains=TOP +syn match scalaXmlQuote "&[^;]\+;" contained +syn match scalaXmlComment "" contained + +syn sync fromstart + +" map Scala groups to standard groups +hi link scalaKeyword Keyword +hi link scalaPackage Include +hi link scalaImport Include +hi link scalaBoolean Boolean +hi link scalaOperator Normal +hi link scalaNumber Number +hi link scalaEmptyString String +hi link scalaString String +hi link scalaChar String +hi link scalaMultiLineString String +hi link scalaStringEscape Special +hi link scalaSymbol Special +hi link scalaUnicode Special +hi link scalaComment Comment +hi link scalaLineComment Comment +hi link scalaDocComment Comment +hi link scalaDocTags Special +hi link scalaTodo Todo +hi link scalaType Type +hi link scalaTypeSpecializer scalaType +hi link scalaXml String +hi link scalaXmlTag Include +hi link scalaXmlString String +hi link scalaXmlStart Include +hi link scalaXmlEscape Normal +hi link scalaXmlEscapeSpecial Special +hi link scalaXmlQuote Special +hi link scalaXmlComment Comment +hi link scalaDef Keyword +hi link scalaVar Keyword +hi link scalaVal Keyword +hi link scalaClass Keyword +hi link scalaObject Keyword +hi link scalaTrait Keyword +hi link scalaDefName Function +hi link scalaDefSpecializer Function +hi link scalaClassName Special +hi link scalaClassSpecializer Special +hi link scalaConstructor Special +hi link scalaConstructorSpecializer scalaConstructor + +let b:current_syntax = "scala" + +" you might like to put these lines in your .vimrc +" +" customize colors a little bit (should be a different file) +" hi scalaNew gui=underline +" hi scalaMethodCall gui=italic +" hi scalaValName gui=underline +" hi scalaVarName gui=underline diff --git a/vim/syntax/scss.vim b/vim/syntax/scss.vim new file mode 100644 index 0000000..6fb9691 --- /dev/null +++ b/vim/syntax/scss.vim @@ -0,0 +1,20 @@ +" Vim syntax file +" Language: SCSS +" Maintainer: Tim Pope +" Filenames: *.scss +" Last Change: 2010 Jul 26 + +if exists("b:current_syntax") + finish +endif + +runtime! syntax/sass.vim + +syn match scssComment "//.*" contains=sassTodo,@Spell +syn region scssComment start="/\*" end="\*/" contains=sassTodo,@Spell + +hi def link scssComment sassComment + +let b:current_syntax = "scss" + +" vim:set sw=2: diff --git a/vim/syntax/snippet.vim b/vim/syntax/snippet.vim new file mode 100644 index 0000000..3aa8571 --- /dev/null +++ b/vim/syntax/snippet.vim @@ -0,0 +1,19 @@ +" Syntax highlighting for snippet files (used for snipMate.vim) +" Hopefully this should make snippets a bit nicer to write! +syn match snipComment '^#.*' +syn match placeHolder '\${\d\+\(:.\{-}\)\=}' contains=snipCommand +syn match tabStop '\$\d\+' +syn match snipCommand '[^\\]`.\{-}`' +syn match snippet '^snippet.*' transparent contains=multiSnipText,snipKeyword +syn match multiSnipText '\S\+ \zs.*' contained +syn match snipKeyword '^snippet'me=s+8 contained +syn match snipError "^[^#s\t].*$" + +hi link snipComment Comment +hi link multiSnipText String +hi link snipKeyword Keyword +hi link snipComment Comment +hi link placeHolder Special +hi link tabStop Special +hi link snipCommand String +hi link snipError Error diff --git a/vim/syntax/tagbar.vim b/vim/syntax/tagbar.vim new file mode 100644 index 0000000..49b2ddc --- /dev/null +++ b/vim/syntax/tagbar.vim @@ -0,0 +1,63 @@ +" File: tagbar.vim +" Description: Tagbar syntax settings +" Author: Jan Larres +" Licence: Vim licence +" Website: http://majutsushi.github.com/tagbar/ +" Version: 2.3 + +scriptencoding utf-8 + +if exists("b:current_syntax") + finish +endif + +let s:ic = g:tagbar_iconchars[0] +if s:ic =~ '[]^\\-]' + let s:ic = '\' . s:ic +endif +let s:io = g:tagbar_iconchars[1] +if s:io =~ '[]^\\-]' + let s:io = '\' . s:io +endif + +let s:pattern = '\([' . s:ic . s:io . '] \)\@<=[^-+: ]\+[^:]\+$' +execute "syntax match TagbarKind '" . s:pattern . "'" + +let s:pattern = '\([' . s:ic . s:io . '][-+# ]\)\@<=[^*]\+\(\*\?\(([^)]\+)\)\? :\)\@=' +execute "syntax match TagbarScope '" . s:pattern . "'" + +let s:pattern = '[' . s:ic . s:io . ']\([-+# ]\)\@=' +execute "syntax match TagbarFoldIcon '" . s:pattern . "'" + +let s:pattern = '\([' . s:ic . s:io . ' ]\)\@<=+\([^-+# ]\)\@=' +execute "syntax match TagbarAccessPublic '" . s:pattern . "'" +let s:pattern = '\([' . s:ic . s:io . ' ]\)\@<=#\([^-+# ]\)\@=' +execute "syntax match TagbarAccessProtected '" . s:pattern . "'" +let s:pattern = '\([' . s:ic . s:io . ' ]\)\@<=-\([^-+# ]\)\@=' +execute "syntax match TagbarAccessPrivate '" . s:pattern . "'" + +unlet s:pattern + +syntax match TagbarNestedKind '^\s\+\[[^]]\+\]$' +syntax match TagbarComment '^".*' +syntax match TagbarType ' : \zs.*' +syntax match TagbarSignature '(.*)' +syntax match TagbarPseudoID '\*\ze :' + +highlight default link TagbarComment Comment +highlight default link TagbarKind Identifier +highlight default link TagbarNestedKind TagbarKind +highlight default link TagbarScope Title +highlight default link TagbarType Type +highlight default link TagbarSignature SpecialKey +highlight default link TagbarPseudoID NonText +highlight default link TagbarFoldIcon Statement +highlight default link TagbarHighlight Search + +highlight default TagbarAccessPublic guifg=Green ctermfg=Green +highlight default TagbarAccessProtected guifg=Blue ctermfg=Blue +highlight default TagbarAccessPrivate guifg=Red ctermfg=Red + +let b:current_syntax = "tagbar" + +" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1 diff --git a/vim/syntax/textile.vim b/vim/syntax/textile.vim new file mode 100644 index 0000000..48a5d65 --- /dev/null +++ b/vim/syntax/textile.vim @@ -0,0 +1,87 @@ +" +" You will have to restart vim for this to take effect. In any case +" it is a good idea to read ":he new-filetype" so that you know what +" is going on, and why the above lines work. +" +" Written originally by Dominic Mitchell, Jan 2006. +" happygiraffe.net +" +" Modified by Aaron Bieber, May 2007. +" blog.aaronbieber.com +" +" Modified by Tim Harper, July 2008 - current +" tim.theenchanter.com +" @(#) $Id$ + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" Textile commands like "h1" are case sensitive, AFAIK. +syn case match + +" Textile syntax: + +" Inline elements. +syn match txtEmphasis /_[^_]\+_/ +syn match txtBold /\*[^*]\+\*/ +syn match txtCite /??.\+??/ +syn match txtDeleted /-[^-]\+-/ +syn match txtInserted /+[^+]\++/ +syn match txtSuper /\^[^^]\+\^/ +syn match txtSub /\~[^~]\+\~/ +syn match txtSpan /%[^%]\+%/ +syn match txtFootnoteRef /\[[0-9]\+]/ +syn match txtCode /@[^@]\+@/ + +" Block elements. +syn match txtHeader /^h1\. .\+/ +syn match txtHeader2 /^h2\. .\+/ +syn match txtHeader3 /^h[3-6]\..\+/ +syn match txtBlockquote /^bq\./ +syn match txtFootnoteDef /^fn[0-9]\+\./ +syn match txtListBullet /\v^\*+ / +syn match txtListBullet2 /\v^(\*\*)+ / +syn match txtListNumber /\v^#+ / +syn match txtListNumber2 /\v^(##)+ / + +syn cluster txtBlockElement contains=txtHeader,txtBlockElement,txtFootnoteDef,txtListBullet,txtListNumber + + +" Everything after the first colon is from RFC 2396, with extra +" backslashes to keep vim happy... Original: +" ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? +" +" Revised the pattern to exclude spaces from the URL portion of the +" pattern. Aaron Bieber, 2007. +syn match txtLink /"[^"]\+":\(\([^:\/?# ]\+\):\)\?\(\/\/\([^\/?# ]*\)\)\?\([^?# ]*\)\(?\([^# ]*\)\)\?\(#\([^ ]*\)\)\?/ + +syn cluster txtInlineElement contains=txtEmphasis,txtBold,txtCite,txtDeleted,txtInserted,txtSuper,txtSub,txtSpan + +if version >= 508 || !exists("did_txt_syn_inits") + if version < 508 + let did_txt_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink txtHeader Title + HiLink txtHeader2 Question + HiLink txtHeader3 Statement + HiLink txtBlockquote Comment + HiLink txtListBullet Operator + HiLink txtListBullet2 Constant + HiLink txtListNumber Operator + HiLink txtListNumber2 Constant + HiLink txtLink String + HiLink txtCode Identifier + hi def txtEmphasis term=underline cterm=underline gui=italic + hi def txtBold term=bold cterm=bold gui=bold + + delcommand HiLink +endif + +" vim: set ai et sw=4 : diff --git a/vim/syntax/vim-rspec.vim b/vim/syntax/vim-rspec.vim new file mode 100644 index 0000000..4f063a2 --- /dev/null +++ b/vim/syntax/vim-rspec.vim @@ -0,0 +1,17 @@ +syntax match rspecHeader /^*/ +syntax match rspecTitle /^\[.\+/ +syntax match rspecOk /^+.\+/ +syntax match rspecError /^-.\+/ +syntax match rspecErrorDetail /^ \w.\+/ +syntax match rspecErrorURL /^ \/.\+/ +syntax match rspecNotImplemented /^#.\+/ +syntax match rspecCode /^ \d\+:/ + +highlight link rspecHeader Type +highlight link rspecTitle Identifier +highlight link rspecOk Tag +highlight link rspecError Error +highlight link rspecErrorDetail Constant +highlight link rspecErrorURL PreProc +highlight link rspecNotImplemented Todo +highlight link rspecCode Type diff --git a/vim/syntax_checkers/applescript.vim b/vim/syntax_checkers/applescript.vim new file mode 100644 index 0000000..eb7a6f2 --- /dev/null +++ b/vim/syntax_checkers/applescript.vim @@ -0,0 +1,43 @@ +"============================================================================== +" FileName: applescript.vim +" Desc: Syntax checking plugin for syntastic.vim +" Author: Zhao Cai +" Email: caizhaoff@gmail.com +" Version: 0.2.1 +" Date Created: Thu 09 Sep 2011 10:30:09 AM EST +" Last Modified: Fri 09 Dec 2011 01:10:24 PM EST +" +" History: 0.1.0 - working, but it will run the script everytime to check +" syntax. Should use osacompile but strangely it does not give +" errors. +" +" 0.2.0 - switch to osacompile, it gives less errors compared +" with osascript. +" +" 0.2.1 - remove g:syntastic_applescript_tempfile. use +" tempname() instead. +" +" License: This program is free software. It comes without any +" warranty, to the extent permitted by applicable law. You can +" redistribute it and/or modify it under the terms of the Do What The +" Fuck You Want To Public License, Version 2, as published by Sam +" Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +if exists("loaded_applescript_syntax_checker") + finish +endif +let loaded_applescript_syntax_checker = 1 + +"bail if the user doesnt have osacompile installed +if !executable("osacompile") + finish +endif + +function! SyntaxCheckers_applescript_GetLocList() + let makeprg = 'osacompile -o ' . tempname() . '.scpt '. shellescape(expand('%')) + let errorformat = '%f:%l:%m' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/c.vim b/vim/syntax_checkers/c.vim new file mode 100644 index 0000000..8bd486b --- /dev/null +++ b/vim/syntax_checkers/c.vim @@ -0,0 +1,156 @@ +"============================================================================ +"File: c.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Gregor Uhlenheuer +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" In order to also check header files add this to your .vimrc: +" (this usually creates a .gch file in your source directory) +" +" let g:syntastic_c_check_header = 1 +" +" To disable the search of included header files after special +" libraries like gtk and glib add this line to your .vimrc: +" +" let g:syntastic_c_no_include_search = 1 +" +" To enable header files being re-checked on every file write add the +" following line to your .vimrc. Otherwise the header files are checked only +" one time on initially loading the file. +" In order to force syntastic to refresh the header includes simply +" unlet b:syntastic_c_includes. Then the header files are being re-checked on +" the next file write. +" +" let g:syntastic_c_auto_refresh_includes = 1 +" +" Alternatively you can set the buffer local variable b:syntastic_c_cflags. +" If this variable is set for the current buffer no search for additional +" libraries is done. I.e. set the variable like this: +" +" let b:syntastic_c_cflags = ' -I/usr/include/libsoup-2.4' +" +" In order to add some custom include directories that should be added to the +" gcc command line you can add those to the global variable +" g:syntastic_c_include_dirs. This list can be used like this: +" +" let g:syntastic_c_include_dirs = [ 'includes', 'headers' ] +" +" Moreover it is possible to add additional compiler options to the syntax +" checking execution via the variable 'g:syntastic_c_compiler_options': +" +" let g:syntastic_c_compiler_options = ' -ansi' +" +" Using the global variable 'g:syntastic_c_remove_include_errors' you can +" specify whether errors of files included via the g:syntastic_c_include_dirs' +" setting are removed from the result set: +" +" let g:syntastic_c_remove_include_errors = 1 + +if exists('loaded_c_syntax_checker') + finish +endif +let loaded_c_syntax_checker = 1 + +if !executable('gcc') + finish +endif + +let s:save_cpo = &cpo +set cpo&vim + +" default include directories +let s:default_includes = [ '.', '..', 'include', 'includes', + \ '../include', '../includes' ] + +" uniquify the input list +function! s:Unique(list) + let l = [] + for elem in a:list + if index(l, elem) == -1 + let l = add(l, elem) + endif + endfor + return l +endfunction + +" get the gcc include directory argument depending on the default +" includes and the optional user-defined 'g:syntastic_c_include_dirs' +function! s:GetIncludeDirs() + let include_dirs = s:default_includes + + if exists('g:syntastic_c_include_dirs') + call extend(include_dirs, g:syntastic_c_include_dirs) + endif + + return join(map(s:Unique(include_dirs), '"-I" . v:val'), ' ') +endfunction + +function! SyntaxCheckers_c_GetLocList() + let makeprg = 'gcc -fsyntax-only -std=gnu99 '.shellescape(expand('%')). + \ ' '.s:GetIncludeDirs() + let errorformat = '%-G%f:%s:,%-G%f:%l: %#error: %#(Each undeclared '. + \ 'identifier is reported only%.%#,%-G%f:%l: %#error: %#for '. + \ 'each function it appears%.%#,%-GIn file included%.%#,'. + \ '%-G %#from %f:%l\,,%f:%l:%c: %m,%f:%l: %trror: %m,%f:%l: %m' + + " determine whether to parse header files as well + if expand('%') =~? '.h$' + if exists('g:syntastic_c_check_header') + let makeprg = 'gcc -c '.shellescape(expand('%')). + \ ' '.s:GetIncludeDirs() + else + return [] + endif + endif + + " add optional user-defined compiler options + if exists('g:syntastic_c_compiler_options') + let makeprg .= g:syntastic_c_compiler_options + endif + + " check if the user manually set some cflags + if !exists('b:syntastic_c_cflags') + " check whether to search for include files at all + if !exists('g:syntastic_c_no_include_search') || + \ g:syntastic_c_no_include_search != 1 + " refresh the include file search if desired + if exists('g:syntastic_c_auto_refresh_includes') && + \ g:syntastic_c_auto_refresh_includes != 0 + let makeprg .= syntastic#c#SearchHeaders() + else + " search for header includes if not cached already + if !exists('b:syntastic_c_includes') + let b:syntastic_c_includes = syntastic#c#SearchHeaders() + endif + let makeprg .= b:syntastic_c_includes + endif + endif + else + " use the user-defined cflags + let makeprg .= b:syntastic_c_cflags + endif + + " process makeprg + let errors = SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat }) + + " filter the processed errors if desired + if exists('g:syntastic_c_remove_include_errors') && + \ g:syntastic_c_remove_include_errors != 0 + return filter(errors, + \ 'has_key(v:val, "bufnr") && v:val["bufnr"]=='.bufnr('')) + else + return errors + endif +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set et sts=4 sw=4: diff --git a/vim/syntax_checkers/coffee.vim b/vim/syntax_checkers/coffee.vim new file mode 100644 index 0000000..59dca75 --- /dev/null +++ b/vim/syntax_checkers/coffee.vim @@ -0,0 +1,27 @@ +"============================================================================ +"File: coffee.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Lincoln Stoll +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_coffee_syntax_checker") + finish +endif +let loaded_coffee_syntax_checker = 1 + +"bail if the user doesnt have coffee installed +if !executable("coffee") + finish +endif + +function! SyntaxCheckers_coffee_GetLocList() + let makeprg = 'coffee -c -l -o /tmp '.shellescape(expand('%')) + let errorformat = 'Syntax%trror: In %f\, %m on line %l,%EError: In %f\, Parse error on line %l: %m,%EError: In %f\, %m on line %l,%W%f(%l): lint warning: %m,%-Z%p^,%W%f(%l): warning: %m,%-Z%p^,%E%f(%l): SyntaxError: %m,%-Z%p^,%-G%.%#' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/cpp.vim b/vim/syntax_checkers/cpp.vim new file mode 100644 index 0000000..1bacf93 --- /dev/null +++ b/vim/syntax_checkers/cpp.vim @@ -0,0 +1,94 @@ +"============================================================================ +"File: cpp.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Gregor Uhlenheuer +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" in order to also check header files add this to your .vimrc: +" (this usually creates a .gch file in your source directory) +" +" let g:syntastic_cpp_check_header = 1 +" +" To disable the search of included header files after special +" libraries like gtk and glib add this line to your .vimrc: +" +" let g:syntastic_cpp_no_include_search = 1 +" +" To enable header files being re-checked on every file write add the +" following line to your .vimrc. Otherwise the header files are checked only +" one time on initially loading the file. +" In order to force syntastic to refresh the header includes simply +" unlet b:syntastic_cpp_includes. Then the header files are being re-checked +" on the next file write. +" +" let g:syntastic_cpp_auto_refresh_includes = 1 +" +" Alternatively you can set the buffer local variable b:syntastic_cpp_cflags. +" If this variable is set for the current buffer no search for additional +" libraries is done. I.e. set the variable like this: +" +" let b:syntastic_cpp_cflags = ' -I/usr/include/libsoup-2.4' +" +" Moreover it is possible to add additional compiler options to the syntax +" checking execution via the variable 'g:syntastic_cpp_compiler_options': +" +" let g:syntastic_cpp_compiler_options = ' -std=c++0x' + +if exists('loaded_cpp_syntax_checker') + finish +endif +let loaded_cpp_syntax_checker = 1 + +if !executable('g++') + finish +endif + +let s:save_cpo = &cpo +set cpo&vim + +function! SyntaxCheckers_cpp_GetLocList() + let makeprg = 'g++ -fsyntax-only '.shellescape(expand('%')) + let errorformat = '%-G%f:%s:,%f:%l:%c: %m,%f:%l: %m' + + if expand('%') =~? '\%(.h\|.hpp\|.hh\)$' + if exists('g:syntastic_cpp_check_header') + let makeprg = 'g++ -c '.shellescape(expand('%')) + else + return [] + endif + endif + + if exists('g:syntastic_cpp_compiler_options') + let makeprg .= g:syntastic_cpp_compiler_options + endif + + if !exists('b:syntastic_cpp_cflags') + if !exists('g:syntastic_cpp_no_include_search') || + \ g:syntastic_cpp_no_include_search != 1 + if exists('g:syntastic_cpp_auto_refresh_includes') && + \ g:syntastic_cpp_auto_refresh_includes != 0 + let makeprg .= syntastic#c#SearchHeaders() + else + if !exists('b:syntastic_cpp_includes') + let b:syntastic_cpp_includes = syntastic#c#SearchHeaders() + endif + let makeprg .= b:syntastic_cpp_includes + endif + endif + else + let makeprg .= b:syntastic_cpp_cflags + endif + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set et sts=4 sw=4: diff --git a/vim/syntax_checkers/css.vim b/vim/syntax_checkers/css.vim new file mode 100644 index 0000000..99a16b8 --- /dev/null +++ b/vim/syntax_checkers/css.vim @@ -0,0 +1,31 @@ +"============================================================================ +"File: css.vim +"Description: Syntax checking plugin for syntastic.vim using `csslint` CLI tool (http://csslint.net). +"Maintainer: Ory Band +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ +if exists("loaded_css_syntax_checker") + finish +endif +let loaded_css_syntax_checker = 1 + +" Bail if the user doesn't have `csslint` installed. +if !executable("csslint") + finish +endif + +function! SyntaxCheckers_css_GetLocList() + let makeprg = 'csslint --format=compact '.shellescape(expand('%')) + + " Print CSS Lint's error/warning messages from compact format. Ignores blank lines. + let errorformat = '%-G,%-G%f: lint free!,%f: line %l\, col %c\, %trror - %m,%f: line %l\, col %c\, %tarning - %m,%f: line %l\, col %c\, %m,' + + return SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': {'bufnr': bufnr("")} }) + +endfunction diff --git a/vim/syntax_checkers/cucumber.vim b/vim/syntax_checkers/cucumber.vim new file mode 100644 index 0000000..c9a87e1 --- /dev/null +++ b/vim/syntax_checkers/cucumber.vim @@ -0,0 +1,27 @@ +"============================================================================ +"File: cucumber.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_cucumber_syntax_checker") + finish +endif +let loaded_cucumber_syntax_checker = 1 + +"bail if the user doesnt have cucumber installed +if !executable("cucumber") + finish +endif + +function! SyntaxCheckers_cucumber_GetLocList() + let makeprg = 'cucumber --dry-run --quiet --strict --format pretty '.shellescape(expand('%')) + let errorformat = '%f:%l:%c:%m,%W %.%# (%m),%-Z%f:%l:%.%#,%-G%.%#' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/cuda.vim b/vim/syntax_checkers/cuda.vim new file mode 100644 index 0000000..816505e --- /dev/null +++ b/vim/syntax_checkers/cuda.vim @@ -0,0 +1,37 @@ +"============================================================================ +"File: cuda.vim +"Description: Syntax checking plugin for syntastic.vim +" +"Author: Hannes Schulz +" +"============================================================================ + +" in order to also check header files add this to your .vimrc: +" (this creates an empty .syntastic_dummy.cu file in your source directory) +" +" let g:syntastic_cuda_check_header = 1 + +if exists('loaded_cuda_syntax_checker') + finish +endif +let loaded_cuda_syntax_checker = 1 + +if !executable('nvcc') + finish +endif + +function! SyntaxCheckers_cuda_GetLocList() + let makeprg = 'nvcc --cuda -O0 -I . -Xcompiler -fsyntax-only '.shellescape(expand('%')).' -o /dev/null' + "let errorformat = '%-G%f:%s:,%f:%l:%c: %m,%f:%l: %m' + let errorformat = '%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]: Entering directory `%f'',%X%*\a[%*\d]: Leaving directory `%f'',%D%*\a: Entering directory `%f'',%X%*\a: Leaving directory `%f'',%DMaking %*\a in %f,%f|%l| %m' + + if expand('%') =~? '\%(.h\|.hpp\|.cuh\)$' + if exists('g:syntastic_cuda_check_header') + let makeprg = 'echo > .syntastic_dummy.cu ; nvcc --cuda -O0 -I . .syntastic_dummy.cu -Xcompiler -fsyntax-only -include '.shellescape(expand('%')).' -o /dev/null' + else + return [] + endif + endif + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/docbk.vim b/vim/syntax_checkers/docbk.vim new file mode 100644 index 0000000..cd360e4 --- /dev/null +++ b/vim/syntax_checkers/docbk.vim @@ -0,0 +1,29 @@ +"============================================================================ +"File: docbk.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_docbk_syntax_checker") + finish +endif +let loaded_docbk_syntax_checker = 1 + +"bail if the user doesnt have tidy or grep installed +if !executable("xmllint") + finish +endif + +function! SyntaxCheckers_docbk_GetLocList() + + let makeprg="xmllint --xinclude --noout --postvalid ".shellescape(expand(%:p)) + let errorformat='%E%f:%l: parser error : %m,%W%f:%l: parser warning : %m,%E%f:%l:%.%# validity error : %m,%W%f:%l:%.%# validity warning : %m,%-Z%p^,%-C%.%#,%-G%.%#' + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + return loclist +endfunction diff --git a/vim/syntax_checkers/efm_perl.pl b/vim/syntax_checkers/efm_perl.pl new file mode 100644 index 0000000..570d6e7 --- /dev/null +++ b/vim/syntax_checkers/efm_perl.pl @@ -0,0 +1,153 @@ +#!/usr/bin/perl -w + +# vimparse.pl - Reformats the error messages of the Perl interpreter for use +# with the quickfix mode of Vim +# +# Copyright (©) 2001 by Jörg Ziefle +# You may use and distribute this software under the same terms as Perl itself. +# +# Usage: put one of the two configurations below in your ~/.vimrc (without the +# description and '# ') and enjoy (be sure to adjust the paths to vimparse.pl +# before): +# +# Program is run interactively with 'perl -w': +# +# set makeprg=$HOME/bin/vimparse.pl\ %\ $* +# set errorformat=%f:%l:%m +# +# Program is only compiled with 'perl -wc': +# +# set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $* +# set errorformat=%f:%l:%m +# +# Usage: +# vimparse.pl [-c] [-f ] [programargs] +# +# -c compile only, don't run (perl -wc) +# -f write errors to +# +# Example usages: +# * From the command line: +# vimparse.pl program.pl +# +# vimparse.pl -c -f errorfile program.pl +# Then run vim -q errorfile to edit the errors with Vim. +# +# * From Vim: +# Edit in Vim (and save, if you don't have autowrite on), then +# type ':mak' or ':mak args' (args being the program arguments) +# to error check. +# +# Version history: +# 0.2 (04/12/2001): +# * First public version (sent to Bram) +# * -c command line option for compiling only +# * grammatical fix: 'There was 1 error.' +# * bug fix for multiple arguments +# * more error checks +# * documentation (top of file, &usage) +# * minor code clean ups +# 0.1 (02/02/2001): +# * Initial version +# * Basic functionality +# +# Todo: +# * test on more systems +# * use portable way to determine the location of perl ('use Config') +# * include option that shows perldiag messages for each error +# * allow to pass in program by STDIN +# * more intuitive behaviour if no error is found (show message) +# +# Tested under SunOS 5.7 with Perl 5.6.0. Let me know if it's not working for +# you. + +use strict; +use Getopt::Std; + +use vars qw/$opt_c $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars' + +use constant VERSION => 0.2; + +getopts('cf:h'); + +&usage if $opt_h; # not necessarily needed, but good for further extension + +if (defined $opt_f) { + + open FILE, "> $opt_f" or do { + warn "Couldn't open $opt_f: $!. Using STDOUT instead.\n"; + undef $opt_f; + }; + +}; + +my $handle = (defined $opt_f ? \*FILE : \*STDOUT); + +(my $file = shift) or &usage; # display usage if no filename is supplied +my $args = (@ARGV ? ' ' . join ' ', @ARGV : ''); + +my @lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`; + +my $errors = 0; +foreach my $line (@lines) { + + chomp($line); + my ($file, $lineno, $message, $rest); + + if ($line =~ /^(.*)\sat\s(.*)\sline\s(\d+)(\.|,\snear\s\".*\")$/) { + + ($message, $file, $lineno, $rest) = ($1, $2, $3, $4); + $errors++; + $message .= $rest if ($rest =~ s/^,//); + print $handle "$file:$lineno:$message\n"; + + } else { next }; + +} + +if (defined $opt_f) { + + my $msg; + if ($errors == 1) { + + $msg = "There was 1 error.\n"; + + } else { + + $msg = "There were $errors errors.\n"; + + }; + + print STDOUT $msg; + close FILE; + unlink $opt_f unless $errors; + +}; + +sub usage { + + (local $0 = $0) =~ s/^.*\/([^\/]+)$/$1/; # remove path from name of program + print<] [programargs] + + -c compile only, don't run (executes 'perl -wc') + -f write errors to + +Examples: + * At the command line: + $0 program.pl + Displays output on STDOUT. + + $0 -c -f errorfile program.pl + Then run 'vim -q errorfile' to edit the errors with Vim. + + * In Vim: + Edit in Vim (and save, if you don't have autowrite on), then + type ':mak' or ':mak args' (args being the program arguments) + to error check. +EOT + + exit 0; + +}; diff --git a/vim/syntax_checkers/erlang.vim b/vim/syntax_checkers/erlang.vim new file mode 100644 index 0000000..d7dceae --- /dev/null +++ b/vim/syntax_checkers/erlang.vim @@ -0,0 +1,42 @@ +"============================================================================ +"File: erlang.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Pawel Salata +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_erlang_syntax_checker") + finish +endif +let loaded_erlang_syntax_checker = 1 + +"bail if the user doesnt have escript installed +if !executable("escript") + finish +endif + +let s:check_file = expand(':p:h') . '/erlang_check_file.erl' + +function! SyntaxCheckers_erlang_GetLocList() + let extension = expand('%:e') + if match(extension, 'hrl') >= 0 + return [] + endif + let shebang = getbufline(bufnr('%'), 1)[0] + if len(shebang) > 0 + if match(shebang, 'escript') >= 0 + let makeprg = 'escript -s '.shellescape(expand('%:p')) + else + let makeprg = s:check_file . ' '. shellescape(expand('%:p')) + endif + else + let makeprg = s:check_file . ' ' . shellescape(expand('%:p')) + endif + let errorformat = '%f:%l:\ %tarning:\ %m,%E%f:%l:\ %m' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/erlang_check_file.erl b/vim/syntax_checkers/erlang_check_file.erl new file mode 100755 index 0000000..8a85bf6 --- /dev/null +++ b/vim/syntax_checkers/erlang_check_file.erl @@ -0,0 +1,12 @@ +#!/usr/bin/env escript +-export([main/1]). + +main([FileName]) -> + compile:file(FileName, [warn_obsolete_guard, + warn_unused_import, + warn_shadow_vars, + warn_export_vars, + strong_validation, + report, + {i, filename:dirname(FileName) ++ "/../include"} + ]). diff --git a/vim/syntax_checkers/eruby.vim b/vim/syntax_checkers/eruby.vim new file mode 100644 index 0000000..fcff063 --- /dev/null +++ b/vim/syntax_checkers/eruby.vim @@ -0,0 +1,34 @@ +"============================================================================ +"File: eruby.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_eruby_syntax_checker") + finish +endif +let loaded_eruby_syntax_checker = 1 + +"bail if the user doesnt have ruby or cat installed +if !executable("ruby") || !executable("cat") + finish +endif + +function! SyntaxCheckers_eruby_GetLocList() + if has('win32') || has('win64') + let makeprg='sed "s/<\%=/<\%/g" '. shellescape(expand("%")) . ' \| ruby -e "require \"erb\"; puts ERB.new(ARGF.read, nil, \"-\").src" \| ruby -c' + else + let makeprg='sed "s/<\%=/<\%/g" '. shellescape(expand("%")) . ' \| RUBYOPT= ruby -e "require \"erb\"; puts ERB.new(ARGF.read, nil, \"-\").src" \| RUBYOPT= ruby -c' + endif + + let errorformat='%-GSyntax OK,%E-:%l: syntax error\, %m,%Z%p^,%W-:%l: warning: %m,%Z%p^,%-C%.%#' + return SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': {'bufnr': bufnr("")} }) + +endfunction diff --git a/vim/syntax_checkers/fortran.vim b/vim/syntax_checkers/fortran.vim new file mode 100644 index 0000000..ee176f2 --- /dev/null +++ b/vim/syntax_checkers/fortran.vim @@ -0,0 +1,44 @@ +"============================================================================ +"File: fortran.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Karl Yngve LervÃ¥g +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"Note: This syntax checker uses gfortran with the option -fsyntax-only +" to check for errors and warnings. Additional flags may be +" supplied through both local and global variables, +" b:syntastic_fortran_flags, +" g:syntastic_fortran_flags. +" This is particularly useful when the source requires module files +" in order to compile (that is when it needs modules defined in +" separate files). +" +"============================================================================ + +if exists("loaded_fortran_syntax_checker") + finish +endif +let loaded_fortran_syntax_checker = 1 + +"bail if the user doesnt have fortran installed +if !executable("gfortran") + finish +endif + +if !exists('g:syntastic_fortran_flags') + let g:syntastic_fortran_flags = '' +endif + +function! SyntaxCheckers_fortran_GetLocList() + let makeprg = 'gfortran -fsyntax-only' + let makeprg .= g:syntastic_fortran_flags + if exists('b:syntastic_fortran_flags') + let makeprg .= b:syntastic_fortran_flags + endif + let makeprg .= ' ' . shellescape(expand('%')) + let errorformat = '%-C %#,%-C %#%.%#,%A%f:%l.%c:,%Z%m,%G%.%#' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/gentoo_metadata.vim b/vim/syntax_checkers/gentoo_metadata.vim new file mode 100644 index 0000000..d016a88 --- /dev/null +++ b/vim/syntax_checkers/gentoo_metadata.vim @@ -0,0 +1,37 @@ +"============================================================================ +"File: gentoo-metadata.vim +"Description: Syntax checking plugin for Gentoo's metadata.xml files +"Maintainer: James Rowe +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" The DTDs required to validate metadata.xml files are available in +" $PORTDIR/metadata/dtd, and these local files can be used to significantly +" speed up validation. You can create a catalog file with: +" +" xmlcatalog --create --add rewriteURI http://www.gentoo.org/dtd/ \ +" ${PORTDIR:-/usr/portage}/metadata/dtd/ /etc/xml/gentoo +" +" See xmlcatalog(1) and http://www.xmlsoft.org/catalog.html for more +" information. + +if exists("loaded_gentoo_metadata_syntax_checker") + finish +endif +let loaded_gentoo_metadata_syntax_checker = 1 + +"bail if the user doesn't have xmllint installed +if !executable("xmllint") + finish +endif + +runtime syntax_checkers/xml.vim + +function! SyntaxCheckers_gentoo_metadata_GetLocList() + return SyntaxCheckers_xml_GetLocList() +endfunction diff --git a/vim/syntax_checkers/go.vim b/vim/syntax_checkers/go.vim new file mode 100644 index 0000000..395ae11 --- /dev/null +++ b/vim/syntax_checkers/go.vim @@ -0,0 +1,22 @@ +"============================================================================ +"File: go.vim +"Description: Loads a go syntax checker from the go directory +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +" Use g:syntastic_go_checker option to specify which go executable +" should be used (see below for a list of supported checkers). +" If g:syntastic_go_checker is not set, just use the first syntax +" checker that we find installed. +"============================================================================ +if exists("loaded_go_syntax_checker") + finish +endif +let loaded_go_syntax_checker = 1 + +let s:supported_checkers = ["6g", "gofmt"] +call SyntasticLoadChecker(s:supported_checkers) diff --git a/vim/syntax_checkers/go/6g.vim b/vim/syntax_checkers/go/6g.vim new file mode 100644 index 0000000..1a4249e --- /dev/null +++ b/vim/syntax_checkers/go/6g.vim @@ -0,0 +1,17 @@ +"============================================================================ +"File: 6g.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Sam Nguyen +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +function! SyntaxCheckers_go_GetLocList() + let makeprg = '6g -o /dev/null %' + let errorformat = '%E%f:%l: %m' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/go/gofmt.vim b/vim/syntax_checkers/go/gofmt.vim new file mode 100644 index 0000000..77abe7e --- /dev/null +++ b/vim/syntax_checkers/go/gofmt.vim @@ -0,0 +1,16 @@ +"============================================================================ +"File: gofmt.vim +"Description: Check go syntax using gofmt +"Maintainer: Brandon Thomson +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +function! SyntaxCheckers_go_GetLocList() + let makeprg = 'gofmt %' + let errorformat = '%f:%l:%c: %m,%-G%.%#' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'type': 'e'} }) +endfunction diff --git a/vim/syntax_checkers/haml.vim b/vim/syntax_checkers/haml.vim new file mode 100644 index 0000000..b9ad6ad --- /dev/null +++ b/vim/syntax_checkers/haml.vim @@ -0,0 +1,26 @@ +"============================================================================ +"File: haml.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_haml_syntax_checker") + finish +endif +let loaded_haml_syntax_checker = 1 + +"bail if the user doesnt have the haml binary installed +if !executable("haml") + finish +endif + +function! SyntaxCheckers_haml_GetLocList() + let makeprg = "haml -c " . shellescape(expand("%")) + let errorformat = 'Haml error on line %l: %m,Syntax error on line %l: %m,%-G%.%#' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/haskell.vim b/vim/syntax_checkers/haskell.vim new file mode 100644 index 0000000..07c55e8 --- /dev/null +++ b/vim/syntax_checkers/haskell.vim @@ -0,0 +1,37 @@ +"============================================================================ +"File: haskell.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Anthony Carapetis +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_haskell_syntax_checker") + finish +endif +let loaded_haskell_syntax_checker = 1 + +"bail if the user doesnt have ghc-mod installed +if !executable("ghc-mod") + finish +endif + +function! SyntaxCheckers_haskell_GetLocList() + let makeprg = + \ "{ ". + \ "ghc-mod check ". shellescape(expand('%')) . "; " . + \ "ghc-mod lint " . shellescape(expand('%')) . ";" . + \ " }" + let errorformat = '%-G\\s%#,%f:%l:%c:%trror: %m,%f:%l:%c:%tarning: %m,'. + \ '%f:%l:%c: %trror: %m,%f:%l:%c: %tarning: %m,%f:%l:%c:%m,'. + \ '%E%f:%l:%c:,%Z%m,' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction + +function! SyntaxCheckers_lhaskell_GetLocList() + return SyntaxCheckers_haskell_GetLocList() +endfunction diff --git a/vim/syntax_checkers/haxe.vim b/vim/syntax_checkers/haxe.vim new file mode 100644 index 0000000..22183ee --- /dev/null +++ b/vim/syntax_checkers/haxe.vim @@ -0,0 +1,55 @@ +"============================================================================ +"File: haxe.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: David Bernard +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_haxe_syntax_checker") + finish +endif +let loaded_haxe_syntax_checker = 1 + +"bail if the user doesn't have haxe installed +if !executable("haxe") + finish +endif + +" s:FindInParent +" find the file argument and returns the path to it. +" Starting with the current working dir, it walks up the parent folders +" until it finds the file, or it hits the stop dir. +" If it doesn't find it, it returns "Nothing" +function! s:FindInParent(fln,flsrt,flstp) + let here = a:flsrt + while ( strlen( here) > 0 ) + let p = split(globpath(here, a:fln), '\n') + if len(p) > 0 + return ['ok', here, fnamemodify(p[0], ':p:t')] + endif + let fr = match(here, '/[^/]*$') + if fr == -1 + break + endif + let here = strpart(here, 0, fr) + if here == a:flstp + break + endif + endwhile + return ['fail', '', ''] +endfunction + +function! SyntaxCheckers_haxe_GetLocList() + let [success, hxmldir, hxmlname] = s:FindInParent('*.hxml', expand('%:p:h'), '/') + if success == 'ok' + let makeprg = 'cd ' . hxmldir . '; haxe ' . hxmlname + let errorformat = '%E%f:%l: characters %c-%*[0-9] : %m' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + else + return SyntasticMake({}) + endif +endfunction diff --git a/vim/syntax_checkers/html.vim b/vim/syntax_checkers/html.vim new file mode 100644 index 0000000..2c1b8b4 --- /dev/null +++ b/vim/syntax_checkers/html.vim @@ -0,0 +1,86 @@ +"============================================================================ +"File: html.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_html_syntax_checker") + finish +endif +let loaded_html_syntax_checker = 1 + +"bail if the user doesnt have tidy or grep installed +if !executable("tidy") || !executable("grep") + finish +endif + +" TODO: join this with xhtml.vim for DRY's sake? +function! s:TidyEncOptByFenc() + let tidy_opts = { + \'utf-8' : '-utf8', + \'ascii' : '-ascii', + \'latin1' : '-latin1', + \'iso-2022-jp' : '-iso-2022', + \'cp1252' : '-win1252', + \'macroman' : '-mac', + \'utf-16le' : '-utf16le', + \'utf-16' : '-utf16', + \'big5' : '-big5', + \'sjis' : '-shiftjis', + \'cp850' : '-ibm858', + \} + return get(tidy_opts, &fileencoding, '-utf8') +endfunction + +let s:ignore_html_errors = [ + \ " lacks \"summary\" attribute", + \ "not approved by W3C", + \ "attribute \"placeholder\"", + \ " proprietary attribute \"charset\"", + \ " lacks \"content\" attribute", + \ "inserting \"type\" attribute", + \ "proprietary attribute \"data-" + \] + +function! s:ValidateError(text) + let valid = 0 + for i in s:ignore_html_errors + if stridx(a:text, i) != -1 + let valid = 1 + break + endif + endfor + return valid +endfunction + + +function! SyntaxCheckers_html_GetLocList() + + let encopt = s:TidyEncOptByFenc() + let makeprg="tidy ".encopt." --new-blocklevel-tags ".shellescape('section, article, aside, hgroup, header, footer, nav, figure, figcaption')." --new-inline-tags ".shellescape('video, audio, embed, mark, progress, meter, time, ruby, rt, rp, canvas, command, details, datalist')." --new-empty-tags ".shellescape('wbr, keygen')." -e ".shellescape(expand('%'))." 2>&1" + let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#' + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + " process loclist since we need to add some info and filter out valid HTML5 + " from the errors + let n = len(loclist) - 1 + let bufnum = bufnr("") + while n >= 0 + let i = loclist[n] + " filter out valid HTML5 + if s:ValidateError(i['text']) == 1 + unlet loclist[n] + else + "the file name isnt in the output so stick in the buf num manually + let i['bufnr'] = bufnum + endif + let n -= 1 + endwhile + + return loclist +endfunction diff --git a/vim/syntax_checkers/javascript.vim b/vim/syntax_checkers/javascript.vim new file mode 100644 index 0000000..026c737 --- /dev/null +++ b/vim/syntax_checkers/javascript.vim @@ -0,0 +1,23 @@ +"============================================================================ +"File: javascript.vim +"Description: Figures out which javascript syntax checker (if any) to load +" from the javascript directory. +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +" Use g:syntastic_javascript_checker option to specify which jslint executable +" should be used (see below for a list of supported checkers). +" If g:syntastic_javascript_checker is not set, just use the first syntax +" checker that we find installed. +"============================================================================ +if exists("loaded_javascript_syntax_checker") + finish +endif +let loaded_javascript_syntax_checker = 1 + +let s:supported_checkers = ["gjslint", "jslint", "jsl", "jshint"] +call SyntasticLoadChecker(s:supported_checkers) diff --git a/vim/syntax_checkers/javascript/gjslint.vim b/vim/syntax_checkers/javascript/gjslint.vim new file mode 100644 index 0000000..05e1c0f --- /dev/null +++ b/vim/syntax_checkers/javascript/gjslint.vim @@ -0,0 +1,20 @@ +"============================================================================ +"File: gjslint.vim +"Description: Javascript syntax checker - using gjslint +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ +if !exists("g:syntastic_javascript_gjslint_conf") + let g:syntastic_javascript_gjslint_conf = "" +endif + +function! SyntaxCheckers_javascript_GetLocList() + let makeprg = "gjslint " . g:syntastic_javascript_gjslint_conf . " --nosummary --unix_mode --nodebug_indentation --nobeep " . shellescape(expand('%')) + let errorformat="%f:%l:(New Error -%\\?\%n) %m,%f:%l:(-%\\?%n) %m,%-G1 files checked, no errors found.,%-G%.%#" + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction + diff --git a/vim/syntax_checkers/javascript/jshint.vim b/vim/syntax_checkers/javascript/jshint.vim new file mode 100644 index 0000000..164b7bd --- /dev/null +++ b/vim/syntax_checkers/javascript/jshint.vim @@ -0,0 +1,21 @@ +"============================================================================ +"File: jshint.vim +"Description: Javascript syntax checker - using jshint +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ +if !exists("g:syntastic_javascript_jshint_conf") + let g:syntastic_javascript_jshint_conf = "" +endif + +function! SyntaxCheckers_javascript_GetLocList() + " node-jshint uses .jshintrc as config unless --config arg is present + let args = !empty(g:syntastic_javascript_jshint_conf) ? ' --config ' . g:syntastic_javascript_jshint_conf : '' + let makeprg = 'jshint ' . shellescape(expand("%")) . args + let errorformat = '%ELine %l:%c,%Z\\s%#Reason: %m,%C%.%#,%f: line %l\, col %c\, %m,%-G%.%#' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr('')} }) +endfunction diff --git a/vim/syntax_checkers/javascript/jsl.vim b/vim/syntax_checkers/javascript/jsl.vim new file mode 100644 index 0000000..36c7efc --- /dev/null +++ b/vim/syntax_checkers/javascript/jsl.vim @@ -0,0 +1,20 @@ +"============================================================================ +"File: jsl.vim +"Description: Javascript syntax checker - using jsl +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ +if !exists("g:syntastic_javascript_jsl_conf") + let g:syntastic_javascript_jsl_conf = "" +endif + +function! SyntaxCheckers_javascript_GetLocList() + let makeprg = "jsl " . g:syntastic_javascript_jsl_conf . " -nologo -nofilelisting -nosummary -nocontext -process ".shellescape(expand('%')) + let errorformat='%W%f(%l): lint warning: %m,%-Z%p^,%W%f(%l): warning: %m,%-Z%p^,%E%f(%l): SyntaxError: %m,%-Z%p^,%-G' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction + diff --git a/vim/syntax_checkers/javascript/jslint.vim b/vim/syntax_checkers/javascript/jslint.vim new file mode 100644 index 0000000..94d48f0 --- /dev/null +++ b/vim/syntax_checkers/javascript/jslint.vim @@ -0,0 +1,31 @@ +"============================================================================ +"File: jslint.vim +"Description: Javascript syntax checker - using jslint +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"Tested with jslint 0.1.4. +"============================================================================ +if !exists("g:syntastic_javascript_jslint_conf") + let g:syntastic_javascript_jslint_conf = "--white --undef --nomen --regexp --plusplus --bitwise --newcap --sloppy --vars" +endif + +function! SyntaxCheckers_javascript_HighlightTerm(error) + let unexpected = matchstr(a:error['text'], 'Expected.*and instead saw \'\zs.*\ze\'') + if len(unexpected) < 1 | return '' | end + return '\V'.split(unexpected, "'")[1] +endfunction + +function! SyntaxCheckers_javascript_GetLocList() + let makeprg = "jslint " . g:syntastic_javascript_jslint_conf . " " . shellescape(expand('%')) + let errorformat='%E %##%n %m,%-Z%.%#Line %l\, Pos %c,%-G%.%#' + let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) + call SyntasticHighlightErrors(errors, function('SyntaxCheckers_javascript_HighlightTerm')) + + return errors +endfunction + diff --git a/vim/syntax_checkers/json.vim b/vim/syntax_checkers/json.vim new file mode 100644 index 0000000..2d2652d --- /dev/null +++ b/vim/syntax_checkers/json.vim @@ -0,0 +1,23 @@ +"============================================================================ +"File: json.vim +"Description: Figures out which json syntax checker (if any) to load +" from the json directory. +"Maintainer: Miller Medeiros +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +" Use g:syntastic_json_checker option to specify which jsonlint executable +" should be used (see below for a list of supported checkers). +" If g:syntastic_json_checker is not set, just use the first syntax +" checker that we find installed. +"============================================================================ +if exists("loaded_json_syntax_checker") + finish +endif +let loaded_json_syntax_checker = 1 + +let s:supported_checkers = ["jsonlint", "jsonval"] +call SyntasticLoadChecker(s:supported_checkers) diff --git a/vim/syntax_checkers/json/jsonlint.vim b/vim/syntax_checkers/json/jsonlint.vim new file mode 100644 index 0000000..6e4a4c0 --- /dev/null +++ b/vim/syntax_checkers/json/jsonlint.vim @@ -0,0 +1,16 @@ +"============================================================================ +"File: jsonlint.vim +"Description: JSON syntax checker - using jsonlint +"Maintainer: Miller Medeiros +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ + +function! SyntaxCheckers_json_GetLocList() + let makeprg = 'jsonlint ' . shellescape(expand("%")) . ' --compact' + let errorformat = '%ELine %l:%c,%Z\\s%#Reason: %m,%C%.%#,%f: line %l\, col %c\, %m,%-G%.%#' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr('')} }) +endfunction diff --git a/vim/syntax_checkers/json/jsonval.vim b/vim/syntax_checkers/json/jsonval.vim new file mode 100644 index 0000000..f288039 --- /dev/null +++ b/vim/syntax_checkers/json/jsonval.vim @@ -0,0 +1,17 @@ +"============================================================================ +"File: jsonval.vim +"Description: JSON syntax checker - using jsonval +"Maintainer: Miller Medeiros +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +"============================================================================ + +function! SyntaxCheckers_json_GetLocList() + " based on https://gist.github.com/1196345 + let makeprg = 'jsonval '. shellescape(expand('%')) + let errorformat = '%E%f:\ %m\ at\ line\ %l,%-G%.%#' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr('')} }) +endfunction diff --git a/vim/syntax_checkers/less.vim b/vim/syntax_checkers/less.vim new file mode 100644 index 0000000..1338ffd --- /dev/null +++ b/vim/syntax_checkers/less.vim @@ -0,0 +1,38 @@ +"============================================================================ +"File: less.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Julien Blanchard +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_less_syntax_checker") + finish +endif +let loaded_less_syntax_checker = 1 + +"bail if the user doesnt have the lessc binary installed +if !executable("lessc") + finish +endif + +if !exists("g:syntastic_less_options") + let g:syntastic_less_options = "--no-color" +endif + +function! SyntaxCheckers_less_GetLocList() + let makeprg = 'lessc '. g:syntastic_less_options .' '. shellescape(expand('%')) . ' /dev/null' + + "lessc >= 1.2 + let errorformat = '%m in %f:%l:%c' + "lessc < 1.2 + let errorformat .= ', Syntax %trror on line %l in %f,Syntax %trror on line %l,! Syntax %trror: on line %l: %m,%-G%.%#' + + return SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': {'bufnr': bufnr(""), 'text': "Syntax error"} }) +endfunction + diff --git a/vim/syntax_checkers/lua.vim b/vim/syntax_checkers/lua.vim new file mode 100644 index 0000000..03acb08 --- /dev/null +++ b/vim/syntax_checkers/lua.vim @@ -0,0 +1,58 @@ +"============================================================================ +"File: lua.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Gregor Uhlenheuer +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +if exists('loaded_lua_syntax_checker') + finish +endif +let loaded_lua_syntax_checker = 1 + +" check if the lua compiler is installed +if !executable('luac') + finish +endif + +function! SyntaxCheckers_lua_Term(pos) + let near = matchstr(a:pos['text'], "near '[^']\\+'") + let result = '' + if len(near) > 0 + let near = split(near, "'")[1] + if near == '' + let p = getpos('$') + let a:pos['lnum'] = p[1] + let a:pos['col'] = p[2] + let result = '\%'.p[2].'c' + else + let result = '\V'.near + endif + let open = matchstr(a:pos['text'], "(to close '[^']\\+' at line [0-9]\\+)") + if len(open) > 0 + let oline = split(open, "'")[1:2] + let line = 0+strpart(oline[1], 9) + call matchadd('SpellCap', '\%'.line.'l\V'.oline[0]) + endif + endif + return result +endfunction + +function! SyntaxCheckers_lua_GetLocList() + let makeprg = 'luac -p ' . shellescape(expand('%')) + let errorformat = 'luac: %#%f:%l: %m' + + let loclist = SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': { 'bufnr': bufnr(''), 'type': 'E' } }) + + call SyntasticHighlightErrors(loclist, function("SyntaxCheckers_lua_Term")) + + return loclist +endfunction + diff --git a/vim/syntax_checkers/matlab.vim b/vim/syntax_checkers/matlab.vim new file mode 100644 index 0000000..595b312 --- /dev/null +++ b/vim/syntax_checkers/matlab.vim @@ -0,0 +1,28 @@ +"============================================================================ +"File: matlab.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Jason Graham +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +if exists("loaded_matlab_syntax_checker") + finish +endif +let loaded_matlab_syntax_checker = 1 + +"bail if the user doesn't have mlint installed +if !executable("mlint") + finish +endif + +function! SyntaxCheckers_matlab_GetLocList() + let makeprg = 'mlint -id $* '.shellescape(expand('%')) + let errorformat = 'L %l (C %c): %*[a-zA-Z0-9]: %m,L %l (C %c-%*[0-9]): %*[a-zA-Z0-9]: %m' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) +endfunction + diff --git a/vim/syntax_checkers/ocaml.vim b/vim/syntax_checkers/ocaml.vim new file mode 100644 index 0000000..6a2470f --- /dev/null +++ b/vim/syntax_checkers/ocaml.vim @@ -0,0 +1,89 @@ +"============================================================================ +"File: ocaml.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Török Edwin +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +" +" By default the camlp4o preprocessor is used to check the syntax of .ml, and .mli files, +" ocamllex is used to check .mll files and menhir is used to check .mly files. +" The output is all redirected to /dev/null, nothing is written to the disk. +" +" If your source code needs camlp4r then you can define this in your .vimrc: +" +" let g:syntastic_ocaml_camlp4r = 1 +" +" If you used some syntax extensions, or you want to also typecheck the source +" code, then you can define this: +" +" let g:syntastic_ocaml_use_ocamlbuild = 1 +" +" This will run ocamlbuild .inferred.mli, so it will write to your _build +" directory (and possibly rebuild your myocamlbuild.ml plugin), only enable this +" if you are ok with that. +" +" If you are using syntax extensions / external libraries and have a properly +" set up _tags (and myocamlbuild.ml file) then it should just work +" to enable this flag and get syntax / type checks through syntastic. +" +" For best results your current directory should be the project root +" (same situation if you want useful output from :make). + +if exists("loaded_ocaml_syntax_checker") + finish +endif +let loaded_ocaml_syntax_checker = 1 + +if exists('g:syntastic_ocaml_camlp4r') && + \ g:syntastic_ocaml_camlp4r != 0 + let s:ocamlpp="camlp4r" +else + let s:ocamlpp="camlp4o" +endif + +"bail if the user doesnt have the preprocessor +if !executable(s:ocamlpp) + finish +endif + +function! SyntaxCheckers_ocaml_GetLocList() + if exists('g:syntastic_ocaml_use_ocamlbuild') && + \ g:syntastic_ocaml_use_ocamlbuild != 0 && + \ executable("ocamlbuild") && + \ isdirectory('_build') + let makeprg = "ocamlbuild -quiet -no-log -tag annot,". s:ocamlpp. " -no-links -no-hygiene -no-sanitize ". + \ shellescape(expand('%:r')).".cmi" + else + let extension = expand('%:e') + if match(extension, 'mly') >= 0 + " ocamlyacc output can't be redirected, so use menhir + if !executable("menhir") + return [] + endif + let makeprg = "menhir --only-preprocess ".shellescape(expand('%')) . " >/dev/null" + elseif match(extension,'mll') >= 0 + if !executable("ocamllex") + return [] + endif + let makeprg = "ocamllex -q -o /dev/null ".shellescape(expand('%')) + else + let makeprg = "camlp4o -o /dev/null ".shellescape(expand('%')) + endif + endif + let errorformat = '%AFile "%f"\, line %l\, characters %c-%*\d:,'. + \ '%AFile "%f"\, line %l\, characters %c-%*\d (end at line %*\d\, character %*\d):,'. + \ '%AFile "%f"\, line %l\, character %c:,'. + \ '%AFile "%f"\, line %l\, character %c:%m,'. + \ '%-GPreprocessing error %.%#,'. + \ '%-GCommand exited %.%#,'. + \ '%C%tarning %n: %m,'. + \ '%C%m,'. + \ '%-G+%.%#' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/perl.vim b/vim/syntax_checkers/perl.vim new file mode 100644 index 0000000..e8aa577 --- /dev/null +++ b/vim/syntax_checkers/perl.vim @@ -0,0 +1,29 @@ +"============================================================================ +"File: perl.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Anthony Carapetis +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_perl_syntax_checker") + finish +endif +let loaded_perl_syntax_checker = 1 + +"bail if the user doesnt have perl installed +if !executable("perl") + finish +endif + +let s:checker = 'perl ' . shellescape(expand(':p:h') . '/efm_perl.pl') . ' -c' + +function! SyntaxCheckers_perl_GetLocList() + let makeprg = s:checker . ' ' . shellescape(expand('%')) + let errorformat = '%f:%l:%m' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/php.vim b/vim/syntax_checkers/php.vim new file mode 100644 index 0000000..4f22f91 --- /dev/null +++ b/vim/syntax_checkers/php.vim @@ -0,0 +1,58 @@ +"============================================================================ +"File: php.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_php_syntax_checker") + finish +endif +let loaded_php_syntax_checker = 1 + +"bail if the user doesnt have php installed +if !executable("php") + finish +endif + +"Support passing configuration directives to phpcs +if !exists("g:syntastic_phpcs_conf") + let g:syntastic_phpcs_conf = "" +endif + +if !exists("g:syntastic_phpcs_disable") + let g:syntastic_phpcs_disable = 0 +endif + +function! SyntaxCheckers_php_Term(item) + let unexpected = matchstr(a:item['text'], "unexpected '[^']\\+'") + if len(unexpected) < 1 | return '' | end + return '\V'.split(unexpected, "'")[1] +endfunction + +function! SyntaxCheckers_php_GetLocList() + + let errors = [] + + let makeprg = "php -l ".shellescape(expand('%')) + let errorformat='%-GNo syntax errors detected in%.%#,PHP Parse error: %#syntax %trror\, %m in %f on line %l,PHP Fatal %trror: %m in %f on line %l,%-GErrors parsing %.%#,%-G\s%#,Parse error: %#syntax %trror\, %m in %f on line %l,Fatal %trror: %m in %f on line %l' + let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + if empty(errors) && !g:syntastic_phpcs_disable && executable("phpcs") + let errors = errors + s:GetPHPCSErrors() + endif + + call SyntasticHighlightErrors(errors, function('SyntaxCheckers_php_Term')) + + return errors +endfunction + +function! s:GetPHPCSErrors() + let makeprg = "phpcs " . g:syntastic_phpcs_conf . " --report=csv ".shellescape(expand('%')) + let errorformat = '%-GFile\,Line\,Column\,Type\,Message\,Source\,Severity,"%f"\,%l\,%c\,%t%*[a-zA-Z]\,"%m"\,%*[a-zA-Z0-9_.-]\,%*[0-9]' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' }) +endfunction diff --git a/vim/syntax_checkers/puppet.vim b/vim/syntax_checkers/puppet.vim new file mode 100644 index 0000000..51c898e --- /dev/null +++ b/vim/syntax_checkers/puppet.vim @@ -0,0 +1,54 @@ +"============================================================================ +"File: puppet.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Eivind Uggedal +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_puppet_syntax_checker") + finish +endif +let loaded_puppet_syntax_checker = 1 + +"bail if the user doesnt have puppet installed +if !executable("puppet") + finish +endif + +function! s:ExtractVersion() + let output = system("puppet --version") + let output = substitute(output, '\n$', '', '') + return split(output, '\.') +endfunction + +let s:puppetVersion = s:ExtractVersion() + +function! SyntaxCheckers_puppet_GetLocList() + "If puppet is >= version 2.7 then use the new executable + if s:puppetVersion[0] >= '2' && s:puppetVersion[1] >= '7' + let makeprg = 'puppet parser validate ' . + \ shellescape(expand('%')) . + \ ' --color=false' . + \ ' --storeconfigs' + + "add --ignoreimport for versions < 2.7.10 + if s:puppetVersion[2] < '10' + let makeprg .= ' --ignoreimport' + endif + + else + let makeprg = 'puppet --color=false --parseonly --ignoreimport '.shellescape(expand('%')) + endif + + "some versions of puppet (e.g. 2.7.10) output the message below if there + "are any syntax errors + let errorformat = '%-Gerr: Try ''puppet help parser validate'' for usage,' + + let errorformat .= 'err: Could not parse for environment %*[a-z]: %m at %f:%l' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/python.vim b/vim/syntax_checkers/python.vim new file mode 100644 index 0000000..a20539b --- /dev/null +++ b/vim/syntax_checkers/python.vim @@ -0,0 +1,80 @@ +"============================================================================ +"File: python.vim +"Description: Syntax checking plugin for syntastic.vim +" +"Authors: Martin Grenfell +" kstep +" Parantapa Bhattacharya +" +"============================================================================ +" +" For forcing the use of flake8, pyflakes, or pylint set +" +" let g:syntastic_python_checker = 'pyflakes' +" +" in your .vimrc. Default is flake8. + +if exists("loaded_python_syntax_checker") + finish +endif +let loaded_python_syntax_checker = 1 + +"bail if the user doesnt have his favorite checker or flake8 or pyflakes installed +if !exists('g:syntastic_python_checker') || !executable(g:syntastic_python_checker) + if executable("flake8") + let g:syntastic_python_checker = 'flake8' + elseif executable("pyflakes") + let g:syntastic_python_checker = 'pyflakes' + elseif executable("pylint") + let g:syntastic_python_checker = 'pylint' + else + finish + endif +endif +if !exists('g:syntastic_python_checker_args') + let g:syntastic_python_checker_args = '' +endif + +function! SyntaxCheckers_python_Term(i) + if a:i['type'] ==# 'E' + let a:i['text'] = "Syntax error" + endif + if match(a:i['text'], 'is assigned to but never used') > -1 + \ || match(a:i['text'], 'imported but unused') > -1 + \ || match(a:i['text'], 'undefined name') > -1 + \ || match(a:i['text'], 'redefinition of') > -1 + \ || match(a:i['text'], 'referenced before assignment') > -1 + \ || match(a:i['text'], 'duplicate argument') > -1 + \ || match(a:i['text'], 'after other statements') > -1 + \ || match(a:i['text'], 'shadowed by loop variable') > -1 + + let term = split(a:i['text'], "'", 1)[1] + return '\V\<'.term.'\>' + endif + return '' +endfunction + +if g:syntastic_python_checker == 'pylint' + function! SyntaxCheckers_python_GetLocList() + let makeprg = 'pylint -f parseable -r n -i y ' . + \ shellescape(expand('%')) . + \ ' \| sed ''s_: \[[RC]_: \[W_''' . + \ ' \| sed ''s_: \[[F]_:\ \[E_''' + let errorformat = '%f:%l: [%t%n] %m,%-GNo config%m' + let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + return errors + endfunction +else + function! SyntaxCheckers_python_GetLocList() + let makeprg = g:syntastic_python_checker.' '.g:syntastic_python_checker_args.' '.shellescape(expand('%')) + let errorformat = + \ '%E%f:%l: could not compile,%-Z%p^,%W%f:%l:%c: %m,%W%f:%l: %m,%-G%.%#' + + let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + call SyntasticHighlightErrors(errors, function('SyntaxCheckers_python_Term')) + + return errors + endfunction +endif diff --git a/vim/syntax_checkers/rst.vim b/vim/syntax_checkers/rst.vim new file mode 100644 index 0000000..107aafe --- /dev/null +++ b/vim/syntax_checkers/rst.vim @@ -0,0 +1,37 @@ +"============================================================================ +"File: rst.vim +"Description: Syntax checking plugin for docutil's reStructuredText files +"Maintainer: James Rowe +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" We use rst2pseudoxml.py, as it is ever so marginally faster than the other +" rst2${x} tools in docutils. + +if exists("loaded_rst_syntax_checker") + finish +endif +let loaded_rst_syntax_checker = 1 + +"bail if the user doesn't have rst2pseudoxml.py installed +if !executable("rst2pseudoxml.py") + finish +endif + +function! SyntaxCheckers_rst_GetLocList() + let makeprg = 'rst2pseudoxml.py --report=1 --exit-status=1 ' . + \ shellescape(expand('%')) . ' /dev/null' + + let errorformat = '%f:%l:\ (%tNFO/1)\ %m, + \%f:%l:\ (%tARNING/2)\ %m, + \%f:%l:\ (%tRROR/3)\ %m, + \%f:%l:\ (%tEVERE/4)\ %m, + \%-G%.%#' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/ruby.vim b/vim/syntax_checkers/ruby.vim new file mode 100644 index 0000000..8c3cd81 --- /dev/null +++ b/vim/syntax_checkers/ruby.vim @@ -0,0 +1,32 @@ +"============================================================================ +"File: ruby.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_ruby_syntax_checker") + finish +endif +let loaded_ruby_syntax_checker = 1 + +"bail if the user doesnt have ruby installed +if !executable("ruby") + finish +endif + +function! SyntaxCheckers_ruby_GetLocList() + " we cannot set RUBYOPT on windows like that + if has('win32') || has('win64') + let makeprg = 'ruby -W1 -T1 -c '.shellescape(expand('%')) + else + let makeprg = 'RUBYOPT= ruby -W1 -c '.shellescape(expand('%')) + endif + let errorformat = '%-GSyntax OK,%E%f:%l: syntax error\, %m,%Z%p^,%W%f:%l: warning: %m,%Z%p^,%W%f:%l: %m,%-C%.%#' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/rust.vim b/vim/syntax_checkers/rust.vim new file mode 100644 index 0000000..fef48e8 --- /dev/null +++ b/vim/syntax_checkers/rust.vim @@ -0,0 +1,33 @@ +"============================================================================ +"File: rust.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Chad Jablonski +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_rust_syntax_checker") + finish +endif +let loaded_rust_syntax_checker = 1 + +"bail if the user doesnt have rustc installed +if !executable("rustc") + finish +endif + +function! SyntaxCheckers_rust_GetLocList() + let makeprg = 'rustc --parse-only '.shellescape(expand('%')) + + let errorformat = '%E%f:%l:%c: \\d%#:\\d%# %.%\{-}error:%.%\{-} %m,' . + \ '%W%f:%l:%c: \\d%#:\\d%# %.%\{-}warning:%.%\{-} %m,' . + \ '%C%f:%l %m,' . + \ '%-Z%.%#' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction + + diff --git a/vim/syntax_checkers/sass.vim b/vim/syntax_checkers/sass.vim new file mode 100644 index 0000000..23bf345 --- /dev/null +++ b/vim/syntax_checkers/sass.vim @@ -0,0 +1,35 @@ +"============================================================================ +"File: sass.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_sass_syntax_checker") + finish +endif +let loaded_sass_syntax_checker = 1 + +"bail if the user doesnt have the sass binary installed +if !executable("sass") + finish +endif + +"use compass imports if available +let s:imports = "" +if executable("compass") + let s:imports = "--compass" +endif + +function! SyntaxCheckers_sass_GetLocList() + let makeprg='sass '.s:imports.' --check '.shellescape(expand('%')) + let errorformat = '%ESyntax %trror:%m,%C on line %l of %f,%Z%.%#' + let errorformat .= ',%Wwarning on line %l:,%Z%m,Syntax %trror on line %l: %m' + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + return loclist +endfunction diff --git a/vim/syntax_checkers/scss.vim b/vim/syntax_checkers/scss.vim new file mode 100644 index 0000000..d3ae5e7 --- /dev/null +++ b/vim/syntax_checkers/scss.vim @@ -0,0 +1,27 @@ + +"============================================================================ +"File: scss.vim +"Description: scss syntax checking plugin for syntastic +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_scss_syntax_checker") + finish +endif +let loaded_scss_syntax_checker = 1 + +"bail if the user doesnt have the sass binary installed +if !executable("sass") + finish +endif + +runtime syntax_checkers/sass.vim + +function! SyntaxCheckers_scss_GetLocList() + return SyntaxCheckers_sass_GetLocList() +endfunction diff --git a/vim/syntax_checkers/sh.vim b/vim/syntax_checkers/sh.vim new file mode 100644 index 0000000..5b55172 --- /dev/null +++ b/vim/syntax_checkers/sh.vim @@ -0,0 +1,52 @@ +"============================================================================ +"File: sh.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Gregor Uhlenheuer +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists('loaded_sh_syntax_checker') + finish +endif +let loaded_sh_syntax_checker = 1 + +function! s:GetShell() + if !exists('b:shell') || b:shell == "" + let b:shell = '' + let shebang = getbufline(bufnr('%'), 1)[0] + if len(shebang) > 0 + if match(shebang, 'bash') >= 0 + let b:shell = 'bash' + elseif match(shebang, 'zsh') >= 0 + let b:shell = 'zsh' + elseif match(shebang, 'sh') >= 0 + let b:shell = 'sh' + endif + endif + endif + return b:shell +endfunction + +function! SyntaxCheckers_sh_GetLocList() + if len(s:GetShell()) == 0 || !executable(s:GetShell()) + return [] + endif + let output = split(system(s:GetShell().' -n '.shellescape(expand('%'))), '\n') + if v:shell_error != 0 + let result = [] + for err_line in output + let line = substitute(err_line, '^[^:]*:\D\{-}\(\d\+\):.*', '\1', '') + let msg = substitute(err_line, '^[^:]*:\D\{-}\d\+: \(.*\)', '\1', '') + call add(result, {'lnum' : line, + \ 'text' : msg, + \ 'bufnr': bufnr(''), + \ 'type': 'E' }) + endfor + return result + endif + return [] +endfunction diff --git a/vim/syntax_checkers/tcl.vim b/vim/syntax_checkers/tcl.vim new file mode 100644 index 0000000..83b5df3 --- /dev/null +++ b/vim/syntax_checkers/tcl.vim @@ -0,0 +1,28 @@ +"============================================================================ +"File: tcl.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Eric Thomas +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +if exists("loaded_tcl_syntax_checker") + finish +endif +let loaded_tcl_syntax_checker = 1 + +"bail if the user doesnt have tclsh installed +if !executable("tclsh") + finish +endif + +function! SyntaxCheckers_tcl_GetLocList() + let makeprg = 'tclsh '.shellescape(expand('%')) + let errorformat = '%f:%l:%m' + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/tex.vim b/vim/syntax_checkers/tex.vim new file mode 100644 index 0000000..4369f4c --- /dev/null +++ b/vim/syntax_checkers/tex.vim @@ -0,0 +1,26 @@ +"============================================================================ +"File: tex.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_tex_syntax_checker") + finish +endif +let loaded_tex_syntax_checker = 1 + +"bail if the user doesnt have lacheck installed +if !executable("lacheck") + finish +endif + +function! SyntaxCheckers_tex_GetLocList() + let makeprg = 'lacheck '.shellescape(expand('%')) + let errorformat = '%-G** %f:,%E"%f"\, line %l: %m' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/syntax_checkers/vala.vim b/vim/syntax_checkers/vala.vim new file mode 100644 index 0000000..f174790 --- /dev/null +++ b/vim/syntax_checkers/vala.vim @@ -0,0 +1,56 @@ +"============================================================================ +"File: vala.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Konstantin Stepanov (me@kstep.me) +"Notes: Add special comment line into your vala file starting with +" "// modules: " and containing space delimited list of vala +" modules, used by the file, so this script can build correct +" --pkg arguments. +" Valac compiler is not the fastest thing in the world, so you +" may want to disable this plugin with +" let g:syntastic_vala_check_disabled = 1 command in your .vimrc or +" command line. Unlet this variable to set it to 0 to reenable +" this checker. +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +if exists('loaded_vala_syntax_checker') + finish +endif +let loaded_vala_syntax_checker = 1 + +if !executable('valac') + finish +endif + +if exists('g:syntastic_vala_check_disabled') && g:syntastic_vala_check_disabled + finish +endif + +function! SyntaxCheckers_vala_Term(pos) + let strlength = strlen(matchstr(a:pos['text'], '\^\+$')) + return '\%>'.(a:pos.col-1).'c.*\%<'.(a:pos.col+strlength+1).'c' +endfunction + +function! s:GetValaModules() + let modules_line = search('^// modules: ', 'n') + let modules_str = getline(modules_line) + let modules = split(strpart(modules_str, 12), '\s\+') + return modules +endfunction + +function! SyntaxCheckers_vala_GetLocList() + let vala_pkg_args = join(map(s:GetValaModules(), '"--pkg ".v:val'), ' ') + let makeprg = 'valac -C ' . vala_pkg_args . ' ' .shellescape(expand('%')) + let errorformat = '%A%f:%l.%c-%\d%\+.%\d%\+: %t%[a-z]%\+: %m,%C%m,%Z%m' + + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + call SyntasticHighlightErrors(loclist, function("SyntaxCheckers_vala_Term"), 1) + return loclist +endfunction + diff --git a/vim/syntax_checkers/xhtml.vim b/vim/syntax_checkers/xhtml.vim new file mode 100644 index 0000000..80d981a --- /dev/null +++ b/vim/syntax_checkers/xhtml.vim @@ -0,0 +1,46 @@ +"============================================================================ +"File: xhtml.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_xhtml_syntax_checker") + finish +endif +let loaded_xhtml_syntax_checker = 1 + +"bail if the user doesnt have tidy or grep installed +if !executable("tidy") + finish +endif + +" TODO: join this with html.vim DRY's sake? +function! s:TidyEncOptByFenc() + let tidy_opts = { + \'utf-8' : '-utf8', + \'ascii' : '-ascii', + \'latin1' : '-latin1', + \'iso-2022-jp' : '-iso-2022', + \'cp1252' : '-win1252', + \'macroman' : '-mac', + \'utf-16le' : '-utf16le', + \'utf-16' : '-utf16', + \'big5' : '-big5', + \'sjis' : '-shiftjis', + \'cp850' : '-ibm858', + \} + return get(tidy_opts, &fileencoding, '-utf8') +endfunction + +function! SyntaxCheckers_xhtml_GetLocList() + + let encopt = s:TidyEncOptByFenc() + let makeprg="tidy ".encopt." -xml -e ".shellescape(expand('%')) + let errorformat='%Wline %l column %c - Warning: %m,%Eline %l column %c - Error: %m,%-G%.%#,%-G%.%#' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'bufnr': bufnr("")} }) +endfunction diff --git a/vim/syntax_checkers/xml.vim b/vim/syntax_checkers/xml.vim new file mode 100644 index 0000000..55c0cdd --- /dev/null +++ b/vim/syntax_checkers/xml.vim @@ -0,0 +1,42 @@ +"============================================================================ +"File: xml.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Sebastian Kusnier +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" You can use a local installation of DTDs to significantly speed up validation +" and allow you to validate XML data without network access, see xmlcatalog(1) +" and http://www.xmlsoft.org/catalog.html for more information. + +if exists("loaded_xml_syntax_checker") + finish +endif +let loaded_xml_syntax_checker = 1 + +"bail if the user doesnt have tidy or grep installed +if !executable("xmllint") + finish +endif + +function! SyntaxCheckers_xml_GetLocList() + + let makeprg="xmllint --xinclude --noout --postvalid " . shellescape(expand("%:p")) + let errorformat='%E%f:%l:\ error\ :\ %m, + \%-G%f:%l:\ validity\ error\ :\ Validation\ failed:\ no\ DTD\ found\ %m, + \%W%f:%l:\ warning\ :\ %m, + \%W%f:%l:\ validity\ warning\ :\ %m, + \%E%f:%l:\ validity\ error\ :\ %m, + \%E%f:%l:\ parser\ error\ :\ %m, + \%E%f:%l:\ %m, + \%-Z%p^, + \%-G%.%#' + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + return loclist +endfunction diff --git a/vim/syntax_checkers/xslt.vim b/vim/syntax_checkers/xslt.vim new file mode 100644 index 0000000..b9b3cac --- /dev/null +++ b/vim/syntax_checkers/xslt.vim @@ -0,0 +1,38 @@ +"============================================================================ +"File: xslt.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Sebastian Kusnier +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ +if exists("loaded_xslt_syntax_checker") + finish +endif +let loaded_xslt_syntax_checker = 1 + +"bail if the user doesnt have tidy or grep installed +if !executable("xmllint") + finish +endif + +function! SyntaxCheckers_xslt_GetLocList() + + let makeprg="xmllint --xinclude --noout --postvalid " . shellescape(expand("%:p")) + let errorformat='%E%f:%l:\ error\ :\ %m, + \%-G%f:%l:\ validity\ error\ :\ Validation\ failed:\ no\ DTD\ found\ %m, + \%W%f:%l:\ warning\ :\ %m, + \%W%f:%l:\ validity\ warning\ :\ %m, + \%E%f:%l:\ validity\ error\ :\ %m, + \%E%f:%l:\ parser\ error\ :\ %m, + \%E%f:%l:\ namespace\ error\ :\ %m, + \%E%f:%l:\ %m, + \%-Z%p^, + \%-G%.%#' + let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + + return loclist +endfunction diff --git a/vim/syntax_checkers/yaml.vim b/vim/syntax_checkers/yaml.vim new file mode 100644 index 0000000..f45d849 --- /dev/null +++ b/vim/syntax_checkers/yaml.vim @@ -0,0 +1,30 @@ +"============================================================================ +"File: yaml.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: Martin Grenfell +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +" +"Installation: $ npm install -g js-yaml.bin +" +"============================================================================ +if exists("loaded_yaml_syntax_checker") + finish +endif +let loaded_yaml_syntax_checker = 1 + +if !executable("js-yaml") + finish +endif + +function! SyntaxCheckers_yaml_GetLocList() + let makeprg='js-yaml --compact ' . shellescape(expand('%')) + let errorformat='Error on line %l\, col %c:%m,%-G%.%#' + return SyntasticMake({ 'makeprg': makeprg, + \ 'errorformat': errorformat, + \ 'defaults': {'bufnr': bufnr("")} }) +endfunction diff --git a/vim/syntax_checkers/zpt.vim b/vim/syntax_checkers/zpt.vim new file mode 100644 index 0000000..0b0063b --- /dev/null +++ b/vim/syntax_checkers/zpt.vim @@ -0,0 +1,36 @@ +"============================================================================ +"File: zpt.vim +"Description: Syntax checking plugin for syntastic.vim +"Maintainer: claytron +"License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +"============================================================================ + +" In order for this plugin to be useful, you will need to set up the +" zpt filetype in your vimrc +" +" " set up zope page templates as the zpt filetype +" au BufNewFile,BufRead *.pt,*.cpt,*.zpt set filetype=zpt syntax=xml +" +" Then install the zptlint program, found on pypi: +" http://pypi.python.org/pypi/zptlint + +if exists("loaded_zpt_syntax_checker") + finish +endif +let loaded_zpt_syntax_checker = 1 + +" Bail if the user doesn't have zptlint installed +if !executable("zptlint") + finish +endif + +function! SyntaxCheckers_zpt_GetLocList() + let makeprg="zptlint ".shellescape(expand('%')) + let errorformat='%-P*** Error in: %f,%Z%*\s\, at line %l\, column %c,%E%*\s%m,%-Q' + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endfunction diff --git a/vim/tmp/ack.vim b/vim/tmp/ack.vim new file mode 160000 index 0000000..a41d5d5 --- /dev/null +++ b/vim/tmp/ack.vim @@ -0,0 +1 @@ +Subproject commit a41d5d52c39a31128e969e69acf800b198cb07f9 diff --git a/vim/tmp/align b/vim/tmp/align new file mode 160000 index 0000000..fa5fdee --- /dev/null +++ b/vim/tmp/align @@ -0,0 +1 @@ +Subproject commit fa5fdeeea25269c3e83262c03dfa1ccd27dbd3c9 diff --git a/vim/tmp/arduino b/vim/tmp/arduino new file mode 160000 index 0000000..c97f8ca --- /dev/null +++ b/vim/tmp/arduino @@ -0,0 +1 @@ +Subproject commit c97f8ca8941e63c446ecc87eca089b293c7ac01a diff --git a/vim/tmp/color-sampler b/vim/tmp/color-sampler new file mode 160000 index 0000000..681ed9e --- /dev/null +++ b/vim/tmp/color-sampler @@ -0,0 +1 @@ +Subproject commit 681ed9e94b7d498810be7a3ac0f048bcca8fd46d diff --git a/vim/tmp/command-t-1.2.1.vba b/vim/tmp/command-t-1.2.1.vba new file mode 100644 index 0000000..015f593 --- /dev/null +++ b/vim/tmp/command-t-1.2.1.vba @@ -0,0 +1,3054 @@ +" Vimball Archiver by Charles E. Campbell, Jr., Ph.D. +UseVimball +finish +ruby/command-t/controller.rb [[[1 +317 +# Copyright 2010-2011 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/finder/buffer_finder' +require 'command-t/finder/file_finder' +require 'command-t/match_window' +require 'command-t/prompt' +require 'command-t/vim/path_utilities' + +module CommandT + class Controller + include VIM::PathUtilities + + def initialize + @prompt = Prompt.new + @buffer_finder = CommandT::BufferFinder.new + set_up_file_finder + set_up_max_height + end + + def show_buffer_finder + @path = VIM::pwd + @active_finder = @buffer_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) + @file_finder.path = @path + @active_finder = @file_finder + show + rescue Errno::ENOENT + # probably a problem with the optional parameter + @match_window.print_no_such_file_or_directory + end + + def hide + @match_window.close + if VIM::Window.select @initial_window + if @initial_buffer.number == 0 + # upstream bug: buffer number misreported as 0 + # see: https://wincent.com/issues/1617 + ::VIM::command "silent b #{@initial_buffer.name}" + else + ::VIM::command "silent b #{@initial_buffer.number}" + end + end + end + + def flush + set_up_max_height + set_up_file_finder + end + + def handle_key + key = ::VIM::evaluate('a:arg').to_i.chr + if @focus == @prompt + @prompt.add! key + list_matches + else + @match_window.find key + end + end + + def backspace + if @focus == @prompt + @prompt.backspace! + list_matches + end + end + + def delete + if @focus == @prompt + @prompt.delete! + list_matches + end + end + + def accept_selection options = {} + selection = @match_window.selection + hide + open_selection(selection, options) unless selection.nil? + end + + def toggle_focus + @focus.unfocus # old focus + @focus = @focus == @prompt ? @match_window : @prompt + @focus.focus # new focus + end + + def cancel + hide + end + + def select_next + @match_window.select_next + end + + def select_prev + @match_window.select_prev + end + + def clear + @prompt.clear! + list_matches + end + + def cursor_left + @prompt.cursor_left if @focus == @prompt + end + + def cursor_right + @prompt.cursor_right if @focus == @prompt + end + + def cursor_end + @prompt.cursor_end if @focus == @prompt + end + + def cursor_start + @prompt.cursor_start if @focus == @prompt + end + + def leave + @match_window.leave + end + + def unload + @match_window.unload + end + + private + + def show + @initial_window = $curwin + @initial_buffer = $curbuf + @match_window = MatchWindow.new \ + :prompt => @prompt, + :match_window_at_top => get_bool('g:CommandTMatchWindowAtTop'), + :match_window_reverse => get_bool('g:CommandTMatchWindowReverse') + @focus = @prompt + @prompt.focus + register_for_key_presses + clear # clears prompt and lists matches + end + + def set_up_max_height + @max_height = get_number('g:CommandTMaxHeight') || 0 + end + + def set_up_file_finder + @file_finder = CommandT::FileFinder.new nil, + :max_files => get_number('g:CommandTMaxFiles'), + :max_depth => get_number('g:CommandTMaxDepth'), + :always_show_dot_files => get_bool('g:CommandTAlwaysShowDotFiles'), + :never_show_dot_files => get_bool('g:CommandTNeverShowDotFiles'), + :scan_dot_directories => get_bool('g:CommandTScanDotDirectories') + end + + def exists? name + ::VIM::evaluate("exists(\"#{name}\")").to_i != 0 + end + + def get_number name + exists?(name) ? ::VIM::evaluate("#{name}").to_i : nil + end + + def get_bool name + exists?(name) ? ::VIM::evaluate("#{name}").to_i != 0 : nil + end + + def get_string name + exists?(name) ? ::VIM::evaluate("#{name}").to_s : nil + end + + # expect a string or a list of strings + def get_list_or_string name + return nil unless exists?(name) + list_or_string = ::VIM::evaluate("#{name}") + if list_or_string.kind_of?(Array) + list_or_string.map { |item| item.to_s } + else + list_or_string.to_s + 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' + else + 'e' + end + end + + def ensure_appropriate_window_selection + # normally we try to open the selection in the current window, but there + # is one exception: + # + # - we don't touch any "unlisted" buffer with buftype "nofile" (such as + # NERDTree or MiniBufExplorer); this is to avoid things like the "Not + # enough room" error which occurs when trying to open in a split in a + # shallow (potentially 1-line) buffer like MiniBufExplorer is current + # + # Other "unlisted" buffers, such as those with buftype "help" are treated + # normally. + initial = $curwin + while true do + break unless ::VIM::evaluate('&buflisted').to_i == 0 && + ::VIM::evaluate('&buftype').to_s == 'nofile' + ::VIM::command 'wincmd w' # try next window + break if $curwin == initial # have already tried all + end + end + + 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}" + end + + def map key, function, param = nil + ::VIM::command "noremap #{key} " \ + ":call CommandT#{function}(#{param})" + end + + def xterm? + !!(::VIM::evaluate('&term') =~ /\Axterm/) + end + + def vt100? + !!(::VIM::evaluate('&term') =~ /\Avt100/) + end + + def register_for_key_presses + # "normal" keys (interpreted literally) + numbers = ('0'..'9').to_a.join + lowercase = ('a'..'z').to_a.join + uppercase = lowercase.upcase + punctuation = '<>`@#~!"$%&/()=+*-_.,;:?\\\'{}[] ' # and space + (numbers + lowercase + uppercase + punctuation).each_byte do |b| + map "", 'HandleKey', b + end + + # "special" keys (overridable by settings) + { 'Backspace' => '', + 'Delete' => '', + 'AcceptSelection' => '', + 'AcceptSelectionSplit' => ['', ''], + 'AcceptSelectionTab' => '', + 'AcceptSelectionVSplit' => '', + 'ToggleFocus' => '', + 'Cancel' => ['', ''], + 'SelectNext' => ['', '', ''], + 'SelectPrev' => ['', '', ''], + 'Clear' => '', + 'CursorLeft' => ['', ''], + 'CursorRight' => ['', ''], + 'CursorEnd' => '', + 'CursorStart' => '' }.each do |key, value| + if override = get_list_or_string("g:CommandT#{key}Map") + [override].flatten.each do |mapping| + map mapping, key + end + else + [value].flatten.each do |mapping| + map mapping, key unless mapping == '' && (xterm? || vt100?) + end + end + end + end + + # Returns the desired maximum number of matches, based on available + # vertical space and the g:CommandTMaxHeight option. + def match_limit + limit = VIM::Screen.lines - 5 + limit = 1 if limit < 0 + limit = [limit, @max_height].min if @max_height > 0 + limit + end + + def list_matches + matches = @active_finder.sorted_matches_for @prompt.abbrev, :limit => match_limit + @match_window.matches = matches + end + end # class Controller +end # module commandT +ruby/command-t/extconf.rb [[[1 +32 +# Copyright 2010 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 'mkmf' + +def missing item + puts "couldn't find #{item} (required)" + exit 1 +end + +have_header('ruby.h') or missing('ruby.h') +create_makefile('ext') +ruby/command-t/finder/buffer_finder.rb [[[1 +35 +# Copyright 2010-2011 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/buffer_scanner' +require 'command-t/finder' + +module CommandT + class BufferFinder < Finder + def initialize + @scanner = BufferScanner.new + @matcher = Matcher.new @scanner, :always_show_dot_files => true + end + end # class BufferFinder +end # CommandT +ruby/command-t/finder/file_finder.rb [[[1 +35 +# Copyright 2010-2011 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/finder' +require 'command-t/scanner/file_scanner' + +module CommandT + class FileFinder < Finder + def initialize path = Dir.pwd, options = {} + @scanner = FileScanner.new path, options + @matcher = Matcher.new @scanner, options + end + end # class FileFinder +end # CommandT +ruby/command-t/finder.rb [[[1 +52 +# Copyright 2010-2011 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 + +module CommandT + # Encapsulates a Scanner instance (which builds up a list of available files + # in a directory) and a Matcher instance (which selects from that list based + # on a search string). + # + # Specialized subclasses use different kinds of scanners adapted for + # different kinds of search (files, buffers). + class Finder + def initialize path = Dir.pwd, options = {} + raise RuntimeError, 'Subclass responsibility' + end + + # Options: + # :limit (integer): limit the number of returned matches + def sorted_matches_for str, options = {} + @matcher.sorted_matches_for str, options + end + + def flush + @scanner.flush + end + + def path= path + @scanner.path = path + end + end # class Finder +end # CommandT +ruby/command-t/match_window.rb [[[1 +387 +# Copyright 2010-2011 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 'ostruct' +require 'command-t/settings' + +module CommandT + class MatchWindow + @@selection_marker = '> ' + @@marker_length = @@selection_marker.length + @@unselected_marker = ' ' * @@marker_length + @@buffer = nil + + def initialize options = {} + @prompt = options[:prompt] + @reverse_list = options[:match_window_reverse] + + # save existing window dimensions so we can restore them later + @windows = [] + (0..(::VIM::Window.count - 1)).each do |i| + window = OpenStruct.new :index => i, :height => ::VIM::Window[i].height + @windows << window + end + + # global settings (must manually save and restore) + @settings = Settings.new + ::VIM::set_option 'timeout' # ensure mappings timeout + ::VIM::set_option 'timeoutlen=0' # respond immediately to mappings + ::VIM::set_option 'nohlsearch' # don't highlight search strings + ::VIM::set_option 'noinsertmode' # don't make Insert mode the default + ::VIM::set_option 'noshowcmd' # don't show command info on last line + ::VIM::set_option 'report=9999' # don't show "X lines changed" reports + ::VIM::set_option 'sidescroll=0' # don't sidescroll in jumps + ::VIM::set_option 'sidescrolloff=0' # don't sidescroll automatically + ::VIM::set_option 'noequalalways' # don't auto-balance window sizes + + # show match window + split_location = options[:match_window_at_top] ? 'topleft' : 'botright' + if @@buffer # still have buffer from last time + ::VIM::command "silent! #{split_location} #{@@buffer.number}sbuffer" + raise "Can't re-open GoToFile buffer" unless $curbuf.number == @@buffer.number + $curwin.height = 1 + else # creating match window for first time and set it up + split_command = "silent! #{split_location} 1split GoToFile" + [ + split_command, + 'setlocal bufhidden=unload', # unload buf when no longer displayed + 'setlocal buftype=nofile', # buffer is not related to any file + 'setlocal nomodifiable', # prevent manual edits + 'setlocal noswapfile', # don't create a swapfile + 'setlocal nowrap', # don't soft-wrap + 'setlocal nonumber', # don't show line numbers + 'setlocal nolist', # don't use List mode (visible tabs etc) + 'setlocal foldcolumn=0', # don't show a fold column at side + 'setlocal foldlevel=99', # don't fold anything + 'setlocal nocursorline', # don't highlight line cursor is on + 'setlocal nospell', # spell-checking off + 'setlocal nobuflisted', # don't show up in the buffer list + 'setlocal textwidth=0' # don't hard-wrap (break long lines) + ].each { |command| ::VIM::command command } + + # sanity check: make sure the buffer really was created + raise "Can't find GoToFile buffer" unless $curbuf.name.match /GoToFile\z/ + @@buffer = $curbuf + end + + # syntax coloring + if VIM::has_syntax? + ::VIM::command "syntax match CommandTSelection \"^#{@@selection_marker}.\\+$\"" + ::VIM::command 'syntax match CommandTNoEntries "^-- NO MATCHES --$"' + ::VIM::command 'syntax match CommandTNoEntries "^-- NO SUCH FILE OR DIRECTORY --$"' + ::VIM::command 'highlight link CommandTSelection Visual' + ::VIM::command 'highlight link CommandTNoEntries Error' + ::VIM::evaluate 'clearmatches()' + + # hide cursor + @cursor_highlight = get_cursor_highlight + hide_cursor + end + + # perform cleanup using an autocmd to ensure we don't get caught out + # by some unexpected means of dismissing or leaving the Command-T window + # (eg. , etc) + ::VIM::command 'autocmd! * ' + ::VIM::command 'autocmd BufLeave ruby $command_t.leave' + ::VIM::command 'autocmd BufUnload ruby $command_t.unload' + + @has_focus = false + @selection = nil + @abbrev = '' + @window = $curwin + end + + def close + # Workaround for upstream bug in Vim 7.3 on some platforms + # + # On some platforms, $curbuf.number always returns 0. One workaround is + # to build Vim with --disable-largefile, but as this is producing lots of + # support requests, implement the following fallback to the buffer name + # instead, at least until upstream gets fixed. + # + # For more details, see: https://wincent.com/issues/1617 + if $curbuf.number == 0 + # use bwipeout as bunload fails if passed the name of a hidden buffer + ::VIM::command 'bwipeout! GoToFile' + @@buffer = nil + else + ::VIM::command "bunload! #{@@buffer.number}" + end + end + + def leave + close + unload + end + + def unload + restore_window_dimensions + @settings.restore + @prompt.dispose + show_cursor + end + + def add! char + @abbrev += char + end + + def backspace! + @abbrev.chop! + end + + def select_next + if @selection < @matches.length - 1 + @selection += 1 + print_match(@selection - 1) # redraw old selection (removes marker) + print_match(@selection) # redraw new selection (adds marker) + move_cursor_to_selected_line + else + # (possibly) loop or scroll + end + end + + def select_prev + if @selection > 0 + @selection -= 1 + print_match(@selection + 1) # redraw old selection (removes marker) + print_match(@selection) # redraw new selection (adds marker) + move_cursor_to_selected_line + else + # (possibly) loop or scroll + end + end + + def matches= matches + matches = matches.reverse if @reverse_list + if matches != @matches + @matches = matches + @selection = @reverse_list ? @matches.length - 1 : 0 + print_matches + move_cursor_to_selected_line + end + end + + def focus + unless @has_focus + @has_focus = true + if VIM::has_syntax? + ::VIM::command 'highlight link CommandTSelection Search' + end + end + end + + def unfocus + if @has_focus + @has_focus = false + if VIM::has_syntax? + ::VIM::command 'highlight link CommandTSelection Visual' + end + end + end + + def find char + # is this a new search or the continuation of a previous one? + now = Time.now + if @last_key_time.nil? or @last_key_time < (now - 0.5) + @find_string = char + else + @find_string += char + end + @last_key_time = now + + # see if there's anything up ahead that matches + @matches.each_with_index do |match, idx| + if match[0, @find_string.length].casecmp(@find_string) == 0 + old_selection = @selection + @selection = idx + print_match(old_selection) # redraw old selection (removes marker) + print_match(@selection) # redraw new selection (adds marker) + break + end + end + end + + # Returns the currently selected item as a String. + def selection + @matches[@selection] + end + + def print_no_such_file_or_directory + print_error 'NO SUCH FILE OR DIRECTORY' + end + + private + + def move_cursor_to_selected_line + # on some non-GUI terminals, the cursor doesn't hide properly + # so we move the cursor to prevent it from blinking away in the + # upper-left corner in a distracting fashion + @window.cursor = [@selection + 1, 0] + end + + def print_error msg + return unless VIM::Window.select(@window) + unlock + clear + @window.height = 1 + @@buffer[1] = "-- #{msg} --" + lock + end + + def restore_window_dimensions + # sort from tallest to shortest + @windows.sort! { |a, b| b.height <=> a.height } + + # starting with the tallest ensures that there are no constraints + # preventing windows on the side of vertical splits from regaining + # their original full size + @windows.each do |w| + # beware: window may be nil + window = ::VIM::Window[w.index] + window.height = w.height if window + end + end + + def match_text_for_idx idx + match = truncated_match @matches[idx] + if idx == @selection + prefix = @@selection_marker + suffix = padding_for_selected_match match + else + prefix = @@unselected_marker + suffix = '' + end + prefix + match + suffix + end + + # Print just the specified match. + def print_match idx + return unless VIM::Window.select(@window) + unlock + @@buffer[idx + 1] = match_text_for_idx idx + lock + end + + # Print all matches. + def print_matches + match_count = @matches.length + if match_count == 0 + print_error 'NO MATCHES' + else + return unless VIM::Window.select(@window) + unlock + clear + actual_lines = 1 + @window_width = @window.width # update cached value + max_lines = VIM::Screen.lines - 5 + max_lines = 1 if max_lines < 0 + actual_lines = match_count > max_lines ? max_lines : match_count + @window.height = actual_lines + (1..actual_lines).each do |line| + idx = line - 1 + if @@buffer.count >= line + @@buffer[line] = match_text_for_idx idx + else + @@buffer.append line - 1, match_text_for_idx(idx) + end + end + lock + end + end + + # Prepare padding for match text (trailing spaces) so that selection + # highlighting extends all the way to the right edge of the window. + def padding_for_selected_match str + len = str.length + if len >= @window_width - @@marker_length + '' + else + ' ' * (@window_width - @@marker_length - len) + end + end + + # Convert "really/long/path" into "really...path" based on available + # window width. + def truncated_match str + len = str.length + available_width = @window_width - @@marker_length + return str if len <= available_width + left = (available_width / 2) - 1 + right = (available_width / 2) - 2 + (available_width % 2) + str[0, left] + '...' + str[-right, right] + end + + def clear + # range = % (whole buffer) + # action = d (delete) + # register = _ (black hole register, don't record deleted text) + ::VIM::command 'silent %d _' + end + + def get_cursor_highlight + # as :highlight returns nothing and only prints, + # must redirect its output to a variable + ::VIM::command 'silent redir => g:command_t_cursor_highlight' + + # force 0 verbosity to ensure origin information isn't printed as well + ::VIM::command 'silent! 0verbose highlight Cursor' + ::VIM::command 'silent redir END' + + # there are 3 possible formats to check for, each needing to be + # transformed in a certain way in order to reapply the highlight: + # Cursor xxx guifg=bg guibg=fg -> :hi! Cursor guifg=bg guibg=fg + # Cursor xxx links to SomethingElse -> :hi! link Cursor SomethingElse + # Cursor xxx cleared -> :hi! clear Cursor + highlight = ::VIM::evaluate 'g:command_t_cursor_highlight' + if highlight =~ /^Cursor\s+xxx\s+links to (\w+)/ + "link Cursor #{$~[1]}" + elsif highlight =~ /^Cursor\s+xxx\s+cleared/ + 'clear Cursor' + elsif highlight =~ /Cursor\s+xxx\s+(.+)/ + "Cursor #{$~[1]}" + else # likely cause E411 Cursor highlight group not found + nil + end + end + + def hide_cursor + if @cursor_highlight + ::VIM::command 'highlight Cursor NONE' + end + end + + def show_cursor + if @cursor_highlight + ::VIM::command "highlight #{@cursor_highlight}" + end + end + + def lock + ::VIM::command 'setlocal nomodifiable' + end + + def unlock + ::VIM::command 'setlocal modifiable' + end + end +end +ruby/command-t/prompt.rb [[[1 +165 +# Copyright 2010 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. + +module CommandT + # Abuse the status line as a prompt. + class Prompt + attr_accessor :abbrev + + def initialize + @abbrev = '' # abbreviation entered so far + @col = 0 # cursor position + @has_focus = false + end + + # Erase whatever is displayed in the prompt line, + # effectively disposing of the prompt + def dispose + ::VIM::command 'echo' + ::VIM::command 'redraw' + end + + # Clear any entered text. + def clear! + @abbrev = '' + @col = 0 + redraw + end + + # Insert a character at (before) the current cursor position. + def add! char + left, cursor, right = abbrev_segments + @abbrev = left + char + cursor + right + @col += 1 + redraw + end + + # Delete a character to the left of the current cursor position. + def backspace! + if @col > 0 + left, cursor, right = abbrev_segments + @abbrev = left.chop! + cursor + right + @col -= 1 + redraw + end + end + + # Delete a character at the current cursor position. + def delete! + if @col < @abbrev.length + left, cursor, right = abbrev_segments + @abbrev = left + right + redraw + end + end + + def cursor_left + if @col > 0 + @col -= 1 + redraw + end + end + + def cursor_right + if @col < @abbrev.length + @col += 1 + redraw + end + end + + def cursor_end + if @col < @abbrev.length + @col = @abbrev.length + redraw + end + end + + def cursor_start + if @col != 0 + @col = 0 + redraw + end + end + + def redraw + if @has_focus + prompt_highlight = 'Comment' + normal_highlight = 'None' + cursor_highlight = 'Underlined' + else + prompt_highlight = 'NonText' + normal_highlight = 'NonText' + cursor_highlight = 'NonText' + end + left, cursor, right = abbrev_segments + components = [prompt_highlight, '>>', 'None', ' '] + components += [normal_highlight, left] unless left.empty? + components += [cursor_highlight, cursor] unless cursor.empty? + components += [normal_highlight, right] unless right.empty? + components += [cursor_highlight, ' '] if cursor.empty? + set_status *components + end + + def focus + unless @has_focus + @has_focus = true + redraw + end + end + + def unfocus + if @has_focus + @has_focus = false + redraw + end + end + + private + + # Returns the @abbrev string divided up into three sections, any of + # which may actually be zero width, depending on the location of the + # cursor: + # - left segment (to left of cursor) + # - cursor segment (character at cursor) + # - right segment (to right of cursor) + def abbrev_segments + left = @abbrev[0, @col] + cursor = @abbrev[@col, 1] + right = @abbrev[(@col + 1)..-1] || '' + [left, cursor, right] + end + + def set_status *args + # see ':help :echo' for why forcing a redraw here helps + # prevent the status line from getting inadvertantly cleared + # after our echo commands + ::VIM::command 'redraw' + while (highlight = args.shift) and (text = args.shift) do + text = VIM::escape_for_single_quotes text + ::VIM::command "echohl #{highlight}" + ::VIM::command "echon '#{text}'" + end + ::VIM::command 'echohl None' + end + end # class Prompt +end # module CommandT +ruby/command-t/scanner/buffer_scanner.rb [[[1 +42 +# Copyright 2010-2011 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/vim/path_utilities' +require 'command-t/scanner' + +module CommandT + # Returns a list of all open buffers. + class BufferScanner < Scanner + include VIM::PathUtilities + + def paths + (0..(::VIM::Buffer.count - 1)).map do |n| + buffer = ::VIM::Buffer[n] + if buffer.name # beware, may be nil + relative_path_under_working_directory buffer.name + end + end.compact + end + end # class BufferScanner +end # module CommandT +ruby/command-t/scanner/file_scanner.rb [[[1 +94 +# Copyright 2010-2011 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 + # Reads the current directory recursively for the paths to all regular files. + class FileScanner < Scanner + class FileLimitExceeded < ::RuntimeError; end + + def initialize path = Dir.pwd, options = {} + @path = path + @max_depth = options[:max_depth] || 15 + @max_files = options[:max_files] || 10_000 + @scan_dot_directories = options[:scan_dot_directories] || false + end + + def paths + return @paths unless @paths.nil? + begin + @paths = [] + @depth = 0 + @files = 0 + @prefix_len = @path.chomp('/').length + add_paths_for_directory @path, @paths + rescue FileLimitExceeded + end + @paths + end + + def flush + @paths = nil + end + + def path= str + if @path != str + @path = str + flush + end + end + + private + + def path_excluded? path + # first strip common prefix (@path) from path to match VIM's behavior + path = path[(@prefix_len + 1)..-1] + path = VIM::escape_for_single_quotes path + ::VIM::evaluate("empty(expand(fnameescape('#{path}')))").to_i == 1 + end + + def add_paths_for_directory dir, accumulator + Dir.foreach(dir) do |entry| + next if ['.', '..'].include?(entry) + path = File.join(dir, entry) + unless path_excluded?(path) + if File.file?(path) + @files += 1 + raise FileLimitExceeded if @files > @max_files + accumulator << path[@prefix_len + 1..-1] + elsif File.directory?(path) + next if @depth >= @max_depth + next if (entry.match(/\A\./) && !@scan_dot_directories) + @depth += 1 + add_paths_for_directory path, accumulator + @depth -= 1 + end + end + end + rescue Errno::EACCES + # skip over directories for which we don't have access + end + end # class FileScanner +end # module CommandT +ruby/command-t/scanner.rb [[[1 +28 +# Copyright 2010-2011 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' + +module CommandT + class Scanner; end +end # module CommandT +ruby/command-t/settings.rb [[[1 +77 +# Copyright 2010 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. + +module CommandT + # Convenience class for saving and restoring global settings. + class Settings + def initialize + save + end + + def save + @timeoutlen = get_number 'timeoutlen' + @report = get_number 'report' + @sidescroll = get_number 'sidescroll' + @sidescrolloff = get_number 'sidescrolloff' + @timeout = get_bool 'timeout' + @equalalways = get_bool 'equalalways' + @hlsearch = get_bool 'hlsearch' + @insertmode = get_bool 'insertmode' + @showcmd = get_bool 'showcmd' + end + + def restore + set_number 'timeoutlen', @timeoutlen + set_number 'report', @report + set_number 'sidescroll', @sidescroll + set_number 'sidescrolloff', @sidescrolloff + set_bool 'timeout', @timeout + set_bool 'equalalways', @equalalways + set_bool 'hlsearch', @hlsearch + set_bool 'insertmode', @insertmode + set_bool 'showcmd', @showcmd + end + + private + + def get_number setting + ::VIM::evaluate("&#{setting}").to_i + end + + def get_bool setting + ::VIM::evaluate("&#{setting}").to_i == 1 + end + + def set_number setting, value + ::VIM::set_option "#{setting}=#{value}" + end + + def set_bool setting, value + if value + ::VIM::set_option setting + else + ::VIM::set_option "no#{setting}" + end + end + end # class Settings +end # module CommandT +ruby/command-t/stub.rb [[[1 +46 +# Copyright 2010-2011 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. + +module CommandT + class Stub + @@load_error = ['command-t.vim could not load the C extension', + 'Please see INSTALLATION and TROUBLE-SHOOTING in the help', + 'For more information type: :help command-t'] + + def show_file_finder + warn *@@load_error + end + + def flush + warn *@@load_error + end + + private + + def warn *msg + ::VIM::command 'echohl WarningMsg' + msg.each { |m| ::VIM::command "echo '#{m}'" } + ::VIM::command 'echohl none' + end + end # class Stub +end # module CommandT +ruby/command-t/vim/path_utilities.rb [[[1 +40 +# Copyright 2010-2011 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' + +module CommandT + module VIM + module PathUtilities + + private + + def relative_path_under_working_directory path + # any path under the working directory will be specified as a relative + # path to improve the readability of the buffer list etc + pwd = File.expand_path(VIM::pwd) + '/' + path.index(pwd) == 0 ? path[pwd.length..-1] : path + end + end # module PathUtilities + end # module VIM +end # module CommandT +ruby/command-t/vim/screen.rb [[[1 +32 +# Copyright 2010 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. + +module CommandT + module VIM + module Screen + def self.lines + ::VIM::evaluate('&lines').to_i + end + end # module Screen + end # module VIM +end # module CommandT +ruby/command-t/vim/window.rb [[[1 +38 +# Copyright 2010 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. + +module CommandT + module VIM + class Window + def self.select window + return true if $curwin == window + initial = $curwin + while true do + ::VIM::command 'wincmd w' # cycle through windows + return true if $curwin == window # have selected desired window + return false if $curwin == initial # have already looped through all + end + end + end # class Window + end # module VIM +end # module CommandT +ruby/command-t/vim.rb [[[1 +43 +# Copyright 2010 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/screen' +require 'command-t/vim/window' + +module CommandT + module VIM + def self.has_syntax? + ::VIM::evaluate('has("syntax")').to_i != 0 + end + + def self.pwd + ::VIM::evaluate 'getcwd()' + end + + # Escape a string for safe inclusion in a Vim single-quoted string + # (single quotes escaped by doubling, everything else is literal) + def self.escape_for_single_quotes str + str.gsub "'", "''" + end + end # module VIM +end # module CommandT +ruby/command-t/ext.c [[[1 +65 +// Copyright 2010 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. + +#include "match.h" +#include "matcher.h" + +VALUE mCommandT = 0; // module CommandT +VALUE cCommandTMatch = 0; // class CommandT::Match +VALUE cCommandTMatcher = 0; // class CommandT::Matcher + +VALUE CommandT_option_from_hash(const char *option, VALUE hash) +{ + if (NIL_P(hash)) + return Qnil; + VALUE key = ID2SYM(rb_intern(option)); + if (rb_funcall(hash, rb_intern("has_key?"), 1, key) == Qtrue) + return rb_hash_aref(hash, key); + else + return Qnil; +} + +void Init_ext() +{ + // module CommandT + mCommandT = rb_define_module("CommandT"); + + // class CommandT::Match + cCommandTMatch = rb_define_class_under(mCommandT, "Match", rb_cObject); + + // methods + rb_define_method(cCommandTMatch, "initialize", CommandTMatch_initialize, -1); + rb_define_method(cCommandTMatch, "matches?", CommandTMatch_matches, 0); + rb_define_method(cCommandTMatch, "to_s", CommandTMatch_to_s, 0); + + // attributes + rb_define_attr(cCommandTMatch, "score", Qtrue, Qfalse); // reader: true, writer: false + + // class CommandT::Matcher + cCommandTMatcher = rb_define_class_under(mCommandT, "Matcher", rb_cObject); + + // methods + rb_define_method(cCommandTMatcher, "initialize", CommandTMatcher_initialize, -1); + rb_define_method(cCommandTMatcher, "sorted_matches_for", CommandTMatcher_sorted_matches_for, 2); + rb_define_method(cCommandTMatcher, "matches_for", CommandTMatcher_matches_for, 1); +} +ruby/command-t/match.c [[[1 +189 +// Copyright 2010 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. + +#include "match.h" +#include "ext.h" +#include "ruby_compat.h" + +// use a struct to make passing params during recursion easier +typedef struct +{ + char *str_p; // pointer to string to be searched + long str_len; // length of same + char *abbrev_p; // pointer to search string (abbreviation) + long abbrev_len; // length of same + double max_score_per_char; + int dot_file; // boolean: true if str is a dot-file + int always_show_dot_files; // boolean + int never_show_dot_files; // boolean +} matchinfo_t; + +double recursive_match(matchinfo_t *m, // sharable meta-data + long str_idx, // where in the path string to start + long abbrev_idx, // where in the search string to start + long last_idx, // location of last matched character + double score) // cumulative score so far +{ + double seen_score = 0; // remember best score seen via recursion + int dot_file_match = 0; // true if abbrev matches a dot-file + int dot_search = 0; // true if searching for a dot + + for (long i = abbrev_idx; i < m->abbrev_len; i++) + { + char c = m->abbrev_p[i]; + if (c == '.') + dot_search = 1; + int found = 0; + for (long j = str_idx; j < m->str_len; j++, str_idx++) + { + char d = m->str_p[j]; + if (d == '.') + { + if (j == 0 || m->str_p[j - 1] == '/') + { + m->dot_file = 1; // this is a dot-file + if (dot_search) // and we are searching for a dot + dot_file_match = 1; // so this must be a match + } + } + else if (d >= 'A' && d <= 'Z') + d += 'a' - 'A'; // add 32 to downcase + if (c == d) + { + found = 1; + dot_search = 0; + + // calculate score + double score_for_char = m->max_score_per_char; + long distance = j - last_idx; + if (distance > 1) + { + double factor = 1.0; + char last = m->str_p[j - 1]; + char curr = m->str_p[j]; // case matters, so get again + if (last == '/') + factor = 0.9; + else if (last == '-' || + last == '_' || + last == ' ' || + (last >= '0' && last <= '9')) + factor = 0.8; + else if (last >= 'a' && last <= 'z' && + curr >= 'A' && curr <= 'Z') + factor = 0.8; + else if (last == '.') + factor = 0.7; + else + // if no "special" chars behind char, factor diminishes + // as distance from last matched char increases + factor = (1.0 / distance) * 0.75; + score_for_char *= factor; + } + + if (++j < m->str_len) + { + // bump cursor one char to the right and + // use recursion to try and find a better match + double sub_score = recursive_match(m, j, i, last_idx, score); + if (sub_score > seen_score) + seen_score = sub_score; + } + + score += score_for_char; + last_idx = str_idx++; + break; + } + } + if (!found) + return 0.0; + } + if (m->dot_file) + { + if (m->never_show_dot_files || + (!dot_file_match && !m->always_show_dot_files)) + return 0.0; + } + return (score > seen_score) ? score : seen_score; +} + +// Match.new abbrev, string, options = {} +VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self) +{ + // process arguments: 2 mandatory, 1 optional + VALUE str, abbrev, options; + if (rb_scan_args(argc, argv, "21", &str, &abbrev, &options) == 2) + options = Qnil; + str = StringValue(str); + abbrev = StringValue(abbrev); // already downcased by caller + + // check optional options hash for overrides + VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options); + VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options); + + matchinfo_t m; + m.str_p = RSTRING_PTR(str); + m.str_len = RSTRING_LEN(str); + m.abbrev_p = RSTRING_PTR(abbrev); + m.abbrev_len = RSTRING_LEN(abbrev); + m.max_score_per_char = (1.0 / m.str_len + 1.0 / m.abbrev_len) / 2; + m.dot_file = 0; + m.always_show_dot_files = always_show_dot_files == Qtrue; + m.never_show_dot_files = never_show_dot_files == Qtrue; + + // calculate score + double score = 1.0; + if (m.abbrev_len == 0) // special case for zero-length search string + { + // filter out dot files + if (!m.always_show_dot_files) + { + for (long i = 0; i < m.str_len; i++) + { + char c = m.str_p[i]; + if (c == '.' && (i == 0 || m.str_p[i - 1] == '/')) + { + score = 0.0; + break; + } + } + } + } + else // normal case + score = recursive_match(&m, 0, 0, 0, 0.0); + + // clean-up and final book-keeping + rb_iv_set(self, "@score", rb_float_new(score)); + rb_iv_set(self, "@str", str); + return Qnil; +} + +VALUE CommandTMatch_matches(VALUE self) +{ + double score = NUM2DBL(rb_iv_get(self, "@score")); + return score > 0 ? Qtrue : Qfalse; +} + +VALUE CommandTMatch_to_s(VALUE self) +{ + return rb_iv_get(self, "@str"); +} +ruby/command-t/matcher.c [[[1 +164 +// Copyright 2010 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. + +#include /* for qsort() */ +#include /* for strcmp() */ +#include "matcher.h" +#include "ext.h" +#include "ruby_compat.h" + +// comparison function for use with qsort +int comp_alpha(const void *a, const void *b) +{ + VALUE a_val = *(VALUE *)a; + VALUE b_val = *(VALUE *)b; + ID to_s = rb_intern("to_s"); + + VALUE a_str = rb_funcall(a_val, to_s, 0); + VALUE b_str = rb_funcall(b_val, to_s, 0); + char *a_p = RSTRING_PTR(a_str); + long a_len = RSTRING_LEN(a_str); + char *b_p = RSTRING_PTR(b_str); + long b_len = RSTRING_LEN(b_str); + int order = 0; + if (a_len > b_len) + { + order = strncmp(a_p, b_p, b_len); + if (order == 0) + order = 1; // shorter string (b) wins + } + else if (a_len < b_len) + { + order = strncmp(a_p, b_p, a_len); + if (order == 0) + order = -1; // shorter string (a) wins + } + else + order = strncmp(a_p, b_p, a_len); + return order; +} + +// comparison function for use with qsort +int comp_score(const void *a, const void *b) +{ + VALUE a_val = *(VALUE *)a; + VALUE b_val = *(VALUE *)b; + ID score = rb_intern("score"); + double a_score = RFLOAT_VALUE(rb_funcall(a_val, score, 0)); + double b_score = RFLOAT_VALUE(rb_funcall(b_val, score, 0)); + if (a_score > b_score) + return -1; // a scores higher, a should appear sooner + else if (a_score < b_score) + return 1; // b scores higher, a should appear later + else + return comp_alpha(a, b); +} + +VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self) +{ + // process arguments: 1 mandatory, 1 optional + VALUE scanner, options; + if (rb_scan_args(argc, argv, "11", &scanner, &options) == 1) + options = Qnil; + if (NIL_P(scanner)) + rb_raise(rb_eArgError, "nil scanner"); + rb_iv_set(self, "@scanner", scanner); + + // check optional options hash for overrides + VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options); + if (always_show_dot_files != Qtrue) + always_show_dot_files = Qfalse; + VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options); + if (never_show_dot_files != Qtrue) + never_show_dot_files = Qfalse; + rb_iv_set(self, "@always_show_dot_files", always_show_dot_files); + rb_iv_set(self, "@never_show_dot_files", never_show_dot_files); + return Qnil; +} + +VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options) +{ + // process optional options hash + VALUE limit_option = CommandT_option_from_hash("limit", options); + + // get unsorted matches + VALUE matches = CommandTMatcher_matches_for(self, abbrev); + + abbrev = StringValue(abbrev); + if (RSTRING_LEN(abbrev) == 0 || + (RSTRING_LEN(abbrev) == 1 && RSTRING_PTR(abbrev)[0] == '.')) + // alphabetic order if search string is only "" or "." + qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_alpha); + else + // for all other non-empty search strings, sort by score + qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_score); + + // apply optional limit option + long limit = NIL_P(limit_option) ? 0 : NUM2LONG(limit_option); + if (limit == 0 || RARRAY_LEN(matches) < limit) + limit = RARRAY_LEN(matches); + + // will return an array of strings, not an array of Match objects + for (long i = 0; i < limit; i++) + { + VALUE str = rb_funcall(RARRAY_PTR(matches)[i], rb_intern("to_s"), 0); + RARRAY_PTR(matches)[i] = str; + } + + // trim off any items beyond the limit + if (limit < RARRAY_LEN(matches)) + (void)rb_funcall(matches, rb_intern("slice!"), 2, LONG2NUM(limit), + LONG2NUM(RARRAY_LEN(matches) - limit)); + return matches; +} + +VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev) +{ + if (NIL_P(abbrev)) + rb_raise(rb_eArgError, "nil abbrev"); + VALUE matches = rb_ary_new(); + VALUE scanner = rb_iv_get(self, "@scanner"); + VALUE always_show_dot_files = rb_iv_get(self, "@always_show_dot_files"); + VALUE never_show_dot_files = rb_iv_get(self, "@never_show_dot_files"); + VALUE options = Qnil; + if (always_show_dot_files == Qtrue) + { + options = rb_hash_new(); + rb_hash_aset(options, ID2SYM(rb_intern("always_show_dot_files")), always_show_dot_files); + } + else if (never_show_dot_files == Qtrue) + { + options = rb_hash_new(); + rb_hash_aset(options, ID2SYM(rb_intern("never_show_dot_files")), never_show_dot_files); + } + abbrev = rb_funcall(abbrev, rb_intern("downcase"), 0); + VALUE paths = rb_funcall(scanner, rb_intern("paths"), 0); + for (long i = 0, max = RARRAY_LEN(paths); i < max; i++) + { + VALUE path = RARRAY_PTR(paths)[i]; + VALUE match = rb_funcall(cCommandTMatch, rb_intern("new"), 3, path, abbrev, options); + if (rb_funcall(match, rb_intern("matches?"), 0) == Qtrue) + rb_funcall(matches, rb_intern("push"), 1, match); + } + return matches; +} +ruby/command-t/ext.h [[[1 +36 +// Copyright 2010 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. + +#include + +extern VALUE mCommandT; // module CommandT +extern VALUE cCommandTMatch; // class CommandT::Match +extern VALUE cCommandTMatcher; // class CommandT::Matcher + +// Encapsulates common pattern of checking for an option in an optional +// options hash. The hash itself may be nil, but an exception will be +// raised if it is not nil and not a hash. +VALUE CommandT_option_from_hash(const char *option, VALUE hash); + +// Debugging macro. +#define ruby_inspect(obj) rb_funcall(rb_mKernel, rb_intern("p"), 1, obj) +ruby/command-t/match.h [[[1 +29 +// Copyright 2010 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. + +#include + +extern VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self); +extern VALUE CommandTMatch_matches(VALUE self); +extern VALUE CommandTMatch_score(VALUE self); +extern VALUE CommandTMatch_to_s(VALUE self); +ruby/command-t/matcher.h [[[1 +30 +// Copyright 2010 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. + +#include + +extern VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self); +extern VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options); + +// most likely the function will be subsumed by the sorted_matcher_for function +extern VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev); +ruby/command-t/ruby_compat.h [[[1 +49 +// Copyright 2010 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. + +#include + +// for compatibility with older versions of Ruby which don't declare RSTRING_PTR +#ifndef RSTRING_PTR +#define RSTRING_PTR(s) (RSTRING(s)->ptr) +#endif + +// for compatibility with older versions of Ruby which don't declare RSTRING_LEN +#ifndef RSTRING_LEN +#define RSTRING_LEN(s) (RSTRING(s)->len) +#endif + +// for compatibility with older versions of Ruby which don't declare RARRAY_PTR +#ifndef RARRAY_PTR +#define RARRAY_PTR(a) (RARRAY(a)->ptr) +#endif + +// for compatibility with older versions of Ruby which don't declare RARRAY_LEN +#ifndef RARRAY_LEN +#define RARRAY_LEN(a) (RARRAY(a)->len) +#endif + +// for compatibility with older versions of Ruby which don't declare RFLOAT_VALUE +#ifndef RFLOAT_VALUE +#define RFLOAT_VALUE(f) (RFLOAT(f)->value) +#endif +ruby/command-t/depend [[[1 +24 +# Copyright 2010 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. + +CFLAGS += -std=c99 -Wall -Wextra -Wno-unused-parameter +doc/command-t.txt [[[1 +786 +*command-t.txt* Command-T plug-in for Vim *command-t* + +CONTENTS *command-t-contents* + + 1. Introduction |command-t-intro| + 2. Requirements |command-t-requirements| + 3. Installation |command-t-installation| + 3. Managing using Pathogen |command-t-pathogen| + 4. Trouble-shooting |command-t-trouble-shooting| + 5. Usage |command-t-usage| + 6. Commands |command-t-commands| + 7. Mappings |command-t-mappings| + 8. Options |command-t-options| + 9. Authors |command-t-authors| +10. Website |command-t-website| +11. Donations |command-t-donations| +12. License |command-t-license| +13. History |command-t-history| + + +INTRODUCTION *command-t-intro* + +The Command-T plug-in provides an extremely fast, intuitive mechanism for +opening files and buffers with a minimal number of keystrokes. It's named +"Command-T" because it is inspired by the "Go to File" window bound to +Command-T in TextMate. + +Files are selected by typing characters that appear in their paths, and are +ordered by an algorithm which knows that characters that appear in certain +locations (for example, immediately after a path separator) should be given +more weight. + +To search efficiently, especially in large projects, you should adopt a +"path-centric" rather than a "filename-centric" mentality. That is you should +think more about where the desired file is found rather than what it is +called. This means narrowing your search down by including some characters +from the upper path components rather than just entering characters from the +filename itself. + +Screencasts demonstrating the plug-in can be viewed at: + + https://wincent.com/products/command-t + + +REQUIREMENTS *command-t-requirements* + +The plug-in requires Vim compiled with Ruby support, a compatible Ruby +installation at the operating system level, and a C compiler to build +the Ruby extension. + + +1. Vim compiled with Ruby support + +You can check for Ruby support by launching Vim with the --version switch: + + vim --version + +If "+ruby" appears in the version information then your version of Vim has +Ruby support. + +Another way to check is to simply try using the :ruby command from within Vim +itself: + + :ruby 1 + +If your Vim lacks support you'll see an error message like this: + + E319: Sorry, the command is not available in this version + +The version of Vim distributed with Mac OS X does not include Ruby support, +while MacVim does; it is available from: + + http://github.com/b4winckler/macvim/downloads + +For Windows users, the Vim 7.2 executable available from www.vim.org does +include Ruby support, and is recommended over version 7.3 (which links against +Ruby 1.9, but apparently has some bugs that need to be resolved). + + +2. Ruby + +In addition to having Ruby support in Vim, your system itself must have a +compatible Ruby install. "Compatible" means the same version as Vim itself +links against. If you use a different version then Command-T is unlikely +to work (see TROUBLE-SHOOTING below). + +On Mac OS X Snow Leopard, the system comes with Ruby 1.8.7 and all recent +versions of MacVim (the 7.2 snapshots and 7.3) are linked against it. + +On Linux and similar platforms, the linked version of Ruby will depend on +your distribution. You can usually find this out by examining the +compilation and linking flags displayed by the |:version| command in Vim, and +by looking at the output of: + + :ruby puts RUBY_VERSION + +A suitable Ruby environment for Windows can be installed using the Ruby +1.8.7-p299 RubyInstaller available at: + + http://rubyinstaller.org/downloads/archives + +If using RubyInstaller be sure to download the installer executable, not the +7-zip archive. When installing mark the checkbox "Add Ruby executables to your +PATH" so that Vim can find them. + + +3. C compiler + +Part of Command-T is implemented in C as a Ruby extension for speed, allowing +it to work responsively even on directory hierarchies containing enormous +numbers of files. As such, a C compiler is required in order to build the +extension and complete the installation. + +On Mac OS X, this can be obtained by installing the Xcode Tools that come on +the Mac OS X install disc. + +On Windows, the RubyInstaller Development Kit can be used to conveniently +install the necessary tool chain: + + http://rubyinstaller.org/downloads/archives + +At the time of writing, the appropriate development kit for use with Ruby +1.8.7 is DevKit-3.4.5r3-20091110. + +To use the Development Kit extract the archive contents to your C:\Ruby +folder. + + +INSTALLATION *command-t-installation* + +Command-T is distributed as a "vimball" which means that it can be installed +by opening it in Vim and then sourcing it: + + :e command-t.vba + :so % + +The files will be installed in your |'runtimepath'|. To check where this is +you can issue: + + :echo &rtp + +The C extension must then be built, which can be done from the shell. If you +use a typical |'runtimepath'| then the files were installed inside ~/.vim and +you can build the extension with: + + cd ~/.vim/ruby/command-t + ruby extconf.rb + make + +Note: If you are an RVM user, you must perform the build using the same +version of Ruby that Vim itself is linked against. This will often be the +system Ruby, which can be selected before issuing the "make" command with: + + rvm use system + + +MANAGING USING PATHOGEN *command-t-pathogen* + +Pathogen is a plugin that allows you to maintain plugin installations in +separate, isolated subdirectories under the "bundle" directory in your +|'runtimepath'|. The following examples assume that you already have +Pathogen installed and configured, and that you are installing into +~/.vim/bundle. For more information about Pathogen, see: + + http://www.vim.org/scripts/script.php?script_id=2332 + +If you manage your entire ~/.vim folder using Git then you can add the +Command-T repository as a submodule: + + cd ~/.vim + git submodule add git://git.wincent.com/command-t.git bundle/command-t + git submodule init + +Or if you just wish to do a simple clone instead of using submodules: + + cd ~/.vim + git clone git://git.wincent.com/command-t.git bundle/command-t + +Once you have a local copy of the repository you can update it at any time +with: + + cd ~/.vim/bundle/command-t + git pull + +Or you can switch to a specific release with: + + cd ~/.vim/bundle/command-t + git checkout 0.8b + +After installing or updating you must build the extension: + + cd ~/.vim/bundle/command-t + rake make + +While the Vimball installation automatically generates the help tags, under +Pathogen it is necessary to do so explicitly from inside Vim: + + :call pathogen#helptags() + + +TROUBLE-SHOOTING *command-t-trouble-shooting* + +Most installation problems are caused by a mismatch between the version of +Ruby on the host operating system, and the version of Ruby that Vim itself +linked against at compile time. For example, if one is 32-bit and the other is +64-bit, or one is from the Ruby 1.9 series and the other is from the 1.8 +series, then the plug-in is not likely to work. + +As such, on Mac OS X, I recommend using the standard Ruby that comes with the +system (currently 1.8.7) along with the latest version of MacVim (currently +version 7.3). If you wish to use custom builds of Ruby or of MacVim (not +recommmended) then you will have to take extra care to ensure that the exact +same Ruby environment is in effect when building Ruby, Vim and the Command-T +extension. + +For Windows, the following combination is known to work: + + - Vim 7.2 from http://www.vim.org/download.php: + ftp://ftp.vim.org/pub/vim/pc/gvim72.exe + - Ruby 1.8.7-p299 from http://rubyinstaller.org/downloads/archives: + http://rubyforge.org/frs/download.php/71492/rubyinstaller-1.8.7-p299.exe + - DevKit 3.4.5r3-20091110 from http://rubyinstaller.org/downloads/archives: + http://rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z + +If a problem occurs the first thing you should do is inspect the output of: + + ruby extconf.rb + make + +During the installation, and: + + vim --version + +And compare the compilation and linker flags that were passed to the +extension and to Vim itself when they were built. If the Ruby-related +flags or architecture flags are different then it is likely that something +has changed in your Ruby environment and the extension may not work until +you eliminate the discrepancy. + + +USAGE *command-t-usage* + +Bring up the Command-T file window by typing: + + t + +This mapping is set up automatically for you, provided you do not already have +a mapping for t or |:CommandT|. You can also bring up the file window +by issuing the command: + + :CommandT + +A prompt will appear at the bottom of the screen along with a file window +showing all of the files in the current directory (as returned by the +|:pwd| command). + +For the most efficient file navigation within a project it's recommended that +you |:cd| into the root directory of your project when starting to work on it. +If you wish to open a file from outside of the project folder you can pass in +an optional path argument (relative or absolute) to |:CommandT|: + + :CommandT ../path/to/other/files + +Type letters in the prompt to narrow down the selection, showing only the +files whose paths contain those letters in the specified order. Letters do not +need to appear consecutively in a path in order for it to be classified as a +match. + +Once the desired file has been selected it can be opened by pressing . +(By default files are opened in the current window, but there are other +mappings that you can use to open in a vertical or horizontal split, or in +a new tab.) Note that if you have |'nohidden'| set and there are unsaved +changes in the current window when you press then opening in the current +window would fail; in this case Command-T will open the file in a new split. + +The following mappings are active when the prompt has focus: + + delete the character to the left of the cursor + delete the character at the cursor + move the cursor one character to the left + move the cursor one character to the left + move the cursor one character to the right + move the cursor one character to the right + move the cursor to the start (left) + move the cursor to the end (right) + clear the contents of the prompt + change focus to the file listing + +The following mappings are active when the file listing has focus: + + change focus to the prompt + +The following mappings are active when either the prompt or the file listing +has focus: + + open the selected file + open the selected file in a new split window + open the selected file in a new split window + open the selected file in a new vertical split window + open the selected file in a new tab + select next file in the file listing + select next file in the file listing + select next file in the file listing + select previous file in the file listing + select previous file in the file listing + select previous file in the file listing + cancel (dismisses file listing) + +The following is also available on terminals which support it: + + cancel (dismisses file listing) + +Note that the default mappings can be overriden by setting options in your +~/.vimrc file (see the OPTIONS section for a full list of available options). + +In addition, when the file listing has focus, typing a character will cause +the selection to jump to the first path which begins with that character. +Typing multiple characters consecutively can be used to distinguish between +paths which begin with the same prefix. + + +COMMANDS *command-t-commands* + + *:CommandT* +|:CommandT| Brings up the Command-T file window, starting in the + current working directory as returned by the|:pwd| + command. + + *:CommandTBuffer* +|:CommandTBuffer|Brings up the Command-T buffer window. + This works exactly like the standard file window, + except that the selection is limited to files that + you already have open in buffers. + + *:CommandTFlush* +|:CommandTFlush|Instructs the plug-in to flush its path cache, causing + the directory to be rescanned for new or deleted paths + the next time the file window is shown. In addition, all + configuration settings are re-evaluated, causing any + changes made to settings via the |:let| command to be picked + up. + + +MAPPINGS *command-t-mappings* + +By default Command-T comes with only two mappings: + + t bring up the Command-T file window + b bring up the Command-T buffer window + +However, Command-T won't overwrite a pre-existing mapping so if you prefer +to define different mappings use lines like these in your ~/.vimrc: + + nmap t :CommandT + nmap b :CommandTBuffer + +Replacing "t" or "b" with your mapping of choice. + +Note that in the case of MacVim you actually can map to Command-T (written +as in Vim) in your ~/.gvimrc file if you first unmap the existing menu +binding of Command-T to "New Tab": + + if has("gui_macvim") + macmenu &File.New\ Tab key= + map :CommandT + endif + +When the Command-T window is active a number of other additional mappings +become available for doing things like moving between and selecting matches. +These are fully described above in the USAGE section, and settings for +overriding the mappings are listed below under OPTIONS. + + +OPTIONS *command-t-options* + +A number of options may be set in your ~/.vimrc to influence the behaviour of +the plug-in. To set an option, you include a line like this in your ~/.vimrc: + + let g:CommandTMaxFiles=20000 + +To have Command-T pick up new settings immediately (that is, without having +to restart Vim) you can issue the |:CommandTFlush| command after making +changes via |:let|. + +Following is a list of all available options: + + *g:CommandTMaxFiles* + |g:CommandTMaxFiles| number (default 10000) + + The maximum number of files that will be considered when scanning the + current directory. Upon reaching this number scanning stops. This + limit applies only to file listings and is ignored for buffer + listings. + + *g:CommandTMaxDepth* + |g:CommandTMaxDepth| number (default 15) + + The maximum depth (levels of recursion) to be explored when scanning the + current directory. Any directories at levels beyond this depth will be + skipped. + + *g:CommandTMaxHeight* + |g:CommandTMaxHeight| number (default: 0) + + The maximum height in lines the match window is allowed to expand to. + If set to 0, the window will occupy as much of the available space as + needed to show matching entries. + + *g:CommandTAlwaysShowDotFiles* + |g:CommandTAlwaysShowDotFiles| boolean (default: 0) + + When showing the file listing Command-T will by default show dot-files + only if the entered search string contains a dot that could cause a + dot-file to match. When set to a non-zero value, this setting instructs + Command-T to always include matching dot-files in the match list + regardless of whether the search string contains a dot. See also + |g:CommandTNeverShowDotFiles|. Note that this setting only influences + the file listing; the buffer listing treats dot-files like any other + file. + + *g:CommandTNeverShowDotFiles* + |g:CommandTNeverShowDotFiles| boolean (default: 0) + + In the file listing, Command-T will by default show dot-files if the + entered search string contains a dot that could cause a dot-file to + match. When set to a non-zero value, this setting instructs Command-T to + never show dot-files under any circumstances. Note that it is + contradictory to set both this setting and + |g:CommandTAlwaysShowDotFiles| to true, and if you do so Vim will suffer + from headaches, nervous twitches, and sudden mood swings. This setting + has no effect in buffer listings, where dot files are treated like any + other file. + + *g:CommandTScanDotDirectories* + |g:CommandTScanDotDirectories| boolean (default: 0) + + Normally Command-T will not recurse into "dot-directories" (directories + whose names begin with a dot) while performing its initial scan. Set + this setting to a non-zero value to override this behavior and recurse. + Note that this setting is completely independent of the + |g:CommandTAlwaysShowDotFiles| and |g:CommandTNeverShowDotFiles| + settings; those apply only to the selection and display of matches + (after scanning has been performed), whereas + |g:CommandTScanDotDirectories| affects the behaviour at scan-time. + + Note also that even with this setting off you can still use Command-T to + open files inside a "dot-directory" such as ~/.vim, but you have to use + the |:cd| command to change into that directory first. For example: + + :cd ~/.vim + :CommandT + + *g:CommandTMatchWindowAtTop* + |g:CommandTMatchWindowAtTop| boolean (default: 0) + + When this setting is off (the default) the match window will appear at + the bottom so as to keep it near to the prompt. Turning it on causes the + match window to appear at the top instead. This may be preferable if you + want the best match (usually the first one) to appear in a fixed location + on the screen rather than moving as the number of matches changes during + typing. + + *g:CommandTMatchWindowReverse* + |g:CommandTMatchWindowReverse| boolean (default: 0) + + When this setting is off (the default) the matches will appear from + top to bottom with the topmost being selected. Turning it on causes the + matches to be reversed so the best match is at the bottom and the + initially selected match is the bottom most. This may be preferable if + you want the best match to appear in a fixed location on the screen + but still be near the prompt at the bottom. + +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 as the mapping for cancelling (dismissing) the Command-T +window, you would add the following to your ~/.vimrc: + + let g:CommandTCancelMap='' + +Multiple, alternative mappings may be specified using list syntax: + + let g:CommandTCancelMap=['', ''] + +Following is a list of all map settings and their defaults: + + Setting Default mapping(s) + + *g:CommandTBackspaceMap* + |g:CommandTBackspaceMap| + + *g:CommandTDeleteMap* + |g:CommandTDeleteMap| + + *g:CommandTAcceptSelectionMap* + |g:CommandTAcceptSelectionMap| + + *g:CommandTAcceptSelectionSplitMap* + |g:CommandTAcceptSelectionSplitMap| + + + *g:CommandTAcceptSelectionTabMap* + |g:CommandTAcceptSelectionTabMap| + + *g:CommandTAcceptSelectionVSplitMap* + |g:CommandTAcceptSelectionVSplitMap| + + *g:CommandTToggleFocusMap* + |g:CommandTToggleFocusMap| + + *g:CommandTCancelMap* + |g:CommandTCancelMap| + (not on all terminals) + + *g:CommandTSelectNextMap* + |g:CommandTSelectNextMap| + + + + *g:CommandTSelectPrevMap* + |g:CommandTSelectPrevMap| + + + + *g:CommandTClearMap* + |g:CommandTClearMap| + + *g:CommandTCursorLeftMap* + |g:CommandTCursorLeftMap| + + + *g:CommandTCursorRightMap* + |g:CommandTCursorRightMap| + + + *g:CommandTCursorEndMap* + |g:CommandTCursorEndMap| + + *g:CommandTCursorStartMap* + |g:CommandTCursorStartMap| + +In addition to the options provided by Command-T itself, some of Vim's own +settings can be used to control behavior: + + *command-t-wildignore* + |'wildignore'| string (default: '') + + Vim's |'wildignore'| setting is used to determine which files should be + excluded from listings. This is a comma-separated list of glob patterns. + It defaults to the empty string, but common settings include "*.o,*.obj" + (to exclude object files) or ".git,.svn" (to exclude SCM metadata + directories). For example: + + :set wildignore+=*.o,*.obj,.git + + A pattern such as "vendor/rails/**" would exclude all files and + subdirectories inside the "vendor/rails" directory (relative to + directory Command-T starts in). + + See the |'wildignore'| documentation for more information. + + +AUTHORS *command-t-authors* + +Command-T is written and maintained by Wincent Colaiuta . +Other contributors that have submitted patches include (in alphabetical +order): + + Daniel Hahler + Lucas de Vries + Matthew Todd + Mike Lundy + Scott Bronson + Steven Moazami + Sung Pae + Victor Hugo Borja + Zak Johnson + +As this was the first Vim plug-in I had ever written I was heavily influenced +by the design of the LustyExplorer plug-in by Stephen Bach, which I understand +is one of the largest Ruby-based Vim plug-ins to date. + +While the Command-T codebase doesn't contain any code directly copied from +LustyExplorer, I did use it as a reference for answers to basic questions (like +"How do you do 'X' in a Ruby-based Vim plug-in?"), and also copied some basic +architectural decisions (like the division of the code into Prompt, Settings +and MatchWindow classes). + +LustyExplorer is available from: + + http://www.vim.org/scripts/script.php?script_id=1890 + + +WEBSITE *command-t-website* + +The official website for Command-T is: + + https://wincent.com/products/command-t + +The latest release will always be available from there. + +Development in progress can be inspected via the project's Git repository +browser at: + + https://wincent.com/repos/command-t + +A copy of each release is also available from the official Vim scripts site +at: + + http://www.vim.org/scripts/script.php?script_id=3025 + +Bug reports should be submitted to the issue tracker at: + + https://wincent.com/issues + + +DONATIONS *command-t-donations* + +Command-T itself is free software released under the terms of the BSD license. +If you would like to support further development you can make a donation via +PayPal to win@wincent.com: + + https://wincent.com/products/command-t/donations + + +LICENSE *command-t-license* + +Copyright 2010-2011 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. + + +HISTORY *command-t-history* + +1.2.1 (30 April 2011) + +- Remove duplicate copy of the documentation that was causing "Duplicate tag" + errors +- Mitigate issue with distracting blinking cursor in non-GUI versions of Vim + (patch from Steven Moazami) + +1.2 (30 April 2011) + +- added |g:CommandTMatchWindowReverse| option, to reverse the order of items + in the match listing (patch from Steven Moazami) + +1.1b2 (26 March 2011) + +- fix a glitch in the release process; the plugin itself is unchanged since + 1.1b + +1.1b (26 March 2011) + +- add |:CommandTBuffer| command for quickly selecting among open buffers + +1.0.1 (5 January 2011) + +- work around bug when mapping |:CommandTFlush|, wherein the default mapping + for |:CommandT| would not be set up +- clean up when leaving the Command-T buffer via unexpected means (such as + with or similar) + +1.0 (26 November 2010) + +- make relative path simplification work on Windows + +1.0b (5 November 2010) + +- work around platform-specific Vim 7.3 bug seen by some users (wherein + Vim always falsely reports to Ruby that the buffer numbers is 0) +- re-use the buffer that is used to show the match listing, rather than + throwing it away and recreating it each time Command-T is shown; this + stops the buffer numbers from creeping up needlessly + +0.9 (8 October 2010) + +- use relative paths when opening files inside the current working directory + in order to keep buffer listings as brief as possible (patch from Matthew + Todd) + +0.8.1 (14 September 2010) + +- fix mapping issues for users who have set |'notimeout'| (patch from Sung + Pae) + +0.8 (19 August 2010) + +- overrides for the default mappings can now be lists of strings, allowing + multiple mappings to be defined for any given action +- t mapping only set up if no other map for |:CommandT| exists + (patch from Scott Bronson) +- prevent folds from appearing in the match listing +- tweaks to avoid the likelihood of "Not enough room" errors when trying to + open files +- watch out for "nil" windows when restoring window dimensions +- optimizations (avoid some repeated downcasing) +- move all Ruby files under the "command-t" subdirectory and avoid polluting + the "Vim" module namespace + +0.8b (11 July 2010) + +- large overhaul of the scoring algorithm to make the ordering of returned + results more intuitive; given the scope of the changes and room for + optimization of the new algorithm, this release is labelled as "beta" + +0.7 (10 June 2010) + +- handle more |'wildignore'| patterns by delegating to Vim's own |expand()| + function; with this change it is now viable to exclude patterns such as + 'vendor/rails/**' in addition to filename-only patterns like '*.o' and + '.git' (patch from Mike Lundy) +- always sort results alphabetically for empty search strings; this eliminates + filesystem-specific variations (patch from Mike Lundy) + +0.6 (28 April 2010) + +- |:CommandT| now accepts an optional parameter to specify the starting + directory, temporarily overriding the usual default of Vim's |:pwd| +- fix truncated paths when operating from root directory + +0.5.1 (11 April 2010) + +- fix for Ruby 1.9 compatibility regression introduced in 0.5 +- documentation enhancements, specifically targetted at Windows users + +0.5 (3 April 2010) + +- |:CommandTFlush| now re-evaluates settings, allowing changes made via |let| + to be picked up without having to restart Vim +- fix premature abort when scanning very deep directory hierarchies +- remove broken || key mapping on vt100 and xterm terminals +- provide settings for overriding default mappings +- minor performance optimization + +0.4 (27 March 2010) + +- add |g:CommandTMatchWindowAtTop| setting (patch from Zak Johnson) +- documentation fixes and enhancements +- internal refactoring and simplification + +0.3 (24 March 2010) + +- add |g:CommandTMaxHeight| setting for controlling the maximum height of the + match window (patch from Lucas de Vries) +- fix bug where |'list'| setting might be inappropriately set after dismissing + Command-T +- compatibility fix for different behaviour of "autoload" under Ruby 1.9.1 +- avoid "highlight group not found" warning when run under a version of Vim + that does not have syntax highlighting support +- open in split when opening normally would fail due to |'hidden'| and + |'modified'| values + +0.2 (23 March 2010) + +- compatibility fixes for compilation under Ruby 1.9 series +- compatibility fixes for compilation under Ruby 1.8.5 +- compatibility fixes for Windows and other non-UNIX platforms +- suppress "mapping already exists" message if t mapping is already + defined when plug-in is loaded +- exclude paths based on |'wildignore'| setting rather than a hardcoded + regular expression + +0.1 (22 March 2010) + +- initial public release + +------------------------------------------------------------------------------ +vim:tw=78:ft=help: +plugin/command-t.vim [[[1 +164 +" command-t.vim +" Copyright 2010-2011 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. + +if exists("g:command_t_loaded") + finish +endif +let g:command_t_loaded = 1 + +command CommandTBuffer call CommandTShowBufferFinder() +command -nargs=? -complete=dir CommandT call CommandTShowFileFinder() +command CommandTFlush call CommandTFlush() + +if !hasmapto(':CommandT') + silent! nmap t :CommandT +endif + +if !hasmapto(':CommandTBuffer') + silent! nmap b :CommandTBuffer +endif + +function s:CommandTRubyWarning() + echohl WarningMsg + echo "command-t.vim requires Vim to be compiled with Ruby support" + echo "For more information type: :help command-t" + echohl none +endfunction + +function s:CommandTShowBufferFinder() + if has('ruby') + ruby $command_t.show_buffer_finder + else + call s:CommandTRubyWarning() + endif +endfunction + +function s:CommandTShowFileFinder(arg) + if has('ruby') + ruby $command_t.show_file_finder + else + call s:CommandTRubyWarning() + endif +endfunction + +function s:CommandTFlush() + if has('ruby') + ruby $command_t.flush + else + call s:CommandTRubyWarning() + endif +endfunction + +if !has('ruby') + finish +endif + +function CommandTHandleKey(arg) + ruby $command_t.handle_key +endfunction + +function CommandTBackspace() + ruby $command_t.backspace +endfunction + +function CommandTDelete() + ruby $command_t.delete +endfunction + +function CommandTAcceptSelection() + ruby $command_t.accept_selection +endfunction + +function CommandTAcceptSelectionTab() + ruby $command_t.accept_selection :command => 'tabe' +endfunction + +function CommandTAcceptSelectionSplit() + ruby $command_t.accept_selection :command => 'sp' +endfunction + +function CommandTAcceptSelectionVSplit() + ruby $command_t.accept_selection :command => 'vs' +endfunction + +function CommandTToggleFocus() + ruby $command_t.toggle_focus +endfunction + +function CommandTCancel() + ruby $command_t.cancel +endfunction + +function CommandTSelectNext() + ruby $command_t.select_next +endfunction + +function CommandTSelectPrev() + ruby $command_t.select_prev +endfunction + +function CommandTClear() + ruby $command_t.clear +endfunction + +function CommandTCursorLeft() + ruby $command_t.cursor_left +endfunction + +function CommandTCursorRight() + ruby $command_t.cursor_right +endfunction + +function CommandTCursorEnd() + ruby $command_t.cursor_end +endfunction + +function CommandTCursorStart() + ruby $command_t.cursor_start +endfunction + +ruby << EOF + # require Ruby files + begin + # prepare controller + require 'command-t/vim' + require 'command-t/controller' + $command_t = CommandT::Controller.new + rescue LoadError + load_path_modified = false + ::VIM::evaluate('&runtimepath').to_s.split(',').each do |path| + lib = "#{path}/ruby" + if !$LOAD_PATH.include?(lib) and File.exist?(lib) + $LOAD_PATH << lib + load_path_modified = true + end + end + retry if load_path_modified + + # could get here if C extension was not compiled, or was compiled + # for the wrong architecture or Ruby version + require 'command-t/stub' + $command_t = CommandT::Stub.new + end +EOF diff --git a/vim/tmp/command_t/doc/command-t.txt b/vim/tmp/command_t/doc/command-t.txt new file mode 100644 index 0000000..65a64a3 --- /dev/null +++ b/vim/tmp/command_t/doc/command-t.txt @@ -0,0 +1,786 @@ +*command-t.txt* Command-T plug-in for Vim *command-t* + +CONTENTS *command-t-contents* + + 1. Introduction |command-t-intro| + 2. Requirements |command-t-requirements| + 3. Installation |command-t-installation| + 3. Managing using Pathogen |command-t-pathogen| + 4. Trouble-shooting |command-t-trouble-shooting| + 5. Usage |command-t-usage| + 6. Commands |command-t-commands| + 7. Mappings |command-t-mappings| + 8. Options |command-t-options| + 9. Authors |command-t-authors| +10. Website |command-t-website| +11. Donations |command-t-donations| +12. License |command-t-license| +13. History |command-t-history| + + +INTRODUCTION *command-t-intro* + +The Command-T plug-in provides an extremely fast, intuitive mechanism for +opening files and buffers with a minimal number of keystrokes. It's named +"Command-T" because it is inspired by the "Go to File" window bound to +Command-T in TextMate. + +Files are selected by typing characters that appear in their paths, and are +ordered by an algorithm which knows that characters that appear in certain +locations (for example, immediately after a path separator) should be given +more weight. + +To search efficiently, especially in large projects, you should adopt a +"path-centric" rather than a "filename-centric" mentality. That is you should +think more about where the desired file is found rather than what it is +called. This means narrowing your search down by including some characters +from the upper path components rather than just entering characters from the +filename itself. + +Screencasts demonstrating the plug-in can be viewed at: + + https://wincent.com/products/command-t + + +REQUIREMENTS *command-t-requirements* + +The plug-in requires Vim compiled with Ruby support, a compatible Ruby +installation at the operating system level, and a C compiler to build +the Ruby extension. + + +1. Vim compiled with Ruby support + +You can check for Ruby support by launching Vim with the --version switch: + + vim --version + +If "+ruby" appears in the version information then your version of Vim has +Ruby support. + +Another way to check is to simply try using the :ruby command from within Vim +itself: + + :ruby 1 + +If your Vim lacks support you'll see an error message like this: + + E319: Sorry, the command is not available in this version + +The version of Vim distributed with Mac OS X does not include Ruby support, +while MacVim does; it is available from: + + http://github.com/b4winckler/macvim/downloads + +For Windows users, the Vim 7.2 executable available from www.vim.org does +include Ruby support, and is recommended over version 7.3 (which links against +Ruby 1.9, but apparently has some bugs that need to be resolved). + + +2. Ruby + +In addition to having Ruby support in Vim, your system itself must have a +compatible Ruby install. "Compatible" means the same version as Vim itself +links against. If you use a different version then Command-T is unlikely +to work (see TROUBLE-SHOOTING below). + +On Mac OS X Snow Leopard, the system comes with Ruby 1.8.7 and all recent +versions of MacVim (the 7.2 snapshots and 7.3) are linked against it. + +On Linux and similar platforms, the linked version of Ruby will depend on +your distribution. You can usually find this out by examining the +compilation and linking flags displayed by the |:version| command in Vim, and +by looking at the output of: + + :ruby puts RUBY_VERSION + +A suitable Ruby environment for Windows can be installed using the Ruby +1.8.7-p299 RubyInstaller available at: + + http://rubyinstaller.org/downloads/archives + +If using RubyInstaller be sure to download the installer executable, not the +7-zip archive. When installing mark the checkbox "Add Ruby executables to your +PATH" so that Vim can find them. + + +3. C compiler + +Part of Command-T is implemented in C as a Ruby extension for speed, allowing +it to work responsively even on directory hierarchies containing enormous +numbers of files. As such, a C compiler is required in order to build the +extension and complete the installation. + +On Mac OS X, this can be obtained by installing the Xcode Tools that come on +the Mac OS X install disc. + +On Windows, the RubyInstaller Development Kit can be used to conveniently +install the necessary tool chain: + + http://rubyinstaller.org/downloads/archives + +At the time of writing, the appropriate development kit for use with Ruby +1.8.7 is DevKit-3.4.5r3-20091110. + +To use the Development Kit extract the archive contents to your C:\Ruby +folder. + + +INSTALLATION *command-t-installation* + +Command-T is distributed as a "vimball" which means that it can be installed +by opening it in Vim and then sourcing it: + + :e command-t.vba + :so % + +The files will be installed in your |'runtimepath'|. To check where this is +you can issue: + + :echo &rtp + +The C extension must then be built, which can be done from the shell. If you +use a typical |'runtimepath'| then the files were installed inside ~/.vim and +you can build the extension with: + + cd ~/.vim/ruby/command-t + ruby extconf.rb + make + +Note: If you are an RVM user, you must perform the build using the same +version of Ruby that Vim itself is linked against. This will often be the +system Ruby, which can be selected before issuing the "make" command with: + + rvm use system + + +MANAGING USING PATHOGEN *command-t-pathogen* + +Pathogen is a plugin that allows you to maintain plugin installations in +separate, isolated subdirectories under the "bundle" directory in your +|'runtimepath'|. The following examples assume that you already have +Pathogen installed and configured, and that you are installing into +~/.vim/bundle. For more information about Pathogen, see: + + http://www.vim.org/scripts/script.php?script_id=2332 + +If you manage your entire ~/.vim folder using Git then you can add the +Command-T repository as a submodule: + + cd ~/.vim + git submodule add git://git.wincent.com/command-t.git bundle/command-t + git submodule init + +Or if you just wish to do a simple clone instead of using submodules: + + cd ~/.vim + git clone git://git.wincent.com/command-t.git bundle/command-t + +Once you have a local copy of the repository you can update it at any time +with: + + cd ~/.vim/bundle/command-t + git pull + +Or you can switch to a specific release with: + + cd ~/.vim/bundle/command-t + git checkout 0.8b + +After installing or updating you must build the extension: + + cd ~/.vim/bundle/command-t + rake make + +While the Vimball installation automatically generates the help tags, under +Pathogen it is necessary to do so explicitly from inside Vim: + + :call pathogen#helptags() + + +TROUBLE-SHOOTING *command-t-trouble-shooting* + +Most installation problems are caused by a mismatch between the version of +Ruby on the host operating system, and the version of Ruby that Vim itself +linked against at compile time. For example, if one is 32-bit and the other is +64-bit, or one is from the Ruby 1.9 series and the other is from the 1.8 +series, then the plug-in is not likely to work. + +As such, on Mac OS X, I recommend using the standard Ruby that comes with the +system (currently 1.8.7) along with the latest version of MacVim (currently +version 7.3). If you wish to use custom builds of Ruby or of MacVim (not +recommmended) then you will have to take extra care to ensure that the exact +same Ruby environment is in effect when building Ruby, Vim and the Command-T +extension. + +For Windows, the following combination is known to work: + + - Vim 7.2 from http://www.vim.org/download.php: + ftp://ftp.vim.org/pub/vim/pc/gvim72.exe + - Ruby 1.8.7-p299 from http://rubyinstaller.org/downloads/archives: + http://rubyforge.org/frs/download.php/71492/rubyinstaller-1.8.7-p299.exe + - DevKit 3.4.5r3-20091110 from http://rubyinstaller.org/downloads/archives: + http://rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z + +If a problem occurs the first thing you should do is inspect the output of: + + ruby extconf.rb + make + +During the installation, and: + + vim --version + +And compare the compilation and linker flags that were passed to the +extension and to Vim itself when they were built. If the Ruby-related +flags or architecture flags are different then it is likely that something +has changed in your Ruby environment and the extension may not work until +you eliminate the discrepancy. + + +USAGE *command-t-usage* + +Bring up the Command-T file window by typing: + + t + +This mapping is set up automatically for you, provided you do not already have +a mapping for t or |:CommandT|. You can also bring up the file window +by issuing the command: + + :CommandT + +A prompt will appear at the bottom of the screen along with a file window +showing all of the files in the current directory (as returned by the +|:pwd| command). + +For the most efficient file navigation within a project it's recommended that +you |:cd| into the root directory of your project when starting to work on it. +If you wish to open a file from outside of the project folder you can pass in +an optional path argument (relative or absolute) to |:CommandT|: + + :CommandT ../path/to/other/files + +Type letters in the prompt to narrow down the selection, showing only the +files whose paths contain those letters in the specified order. Letters do not +need to appear consecutively in a path in order for it to be classified as a +match. + +Once the desired file has been selected it can be opened by pressing . +(By default files are opened in the current window, but there are other +mappings that you can use to open in a vertical or horizontal split, or in +a new tab.) Note that if you have |'nohidden'| set and there are unsaved +changes in the current window when you press then opening in the current +window would fail; in this case Command-T will open the file in a new split. + +The following mappings are active when the prompt has focus: + + delete the character to the left of the cursor + delete the character at the cursor + move the cursor one character to the left + move the cursor one character to the left + move the cursor one character to the right + move the cursor one character to the right + move the cursor to the start (left) + move the cursor to the end (right) + clear the contents of the prompt + change focus to the file listing + +The following mappings are active when the file listing has focus: + + change focus to the prompt + +The following mappings are active when either the prompt or the file listing +has focus: + + open the selected file + open the selected file in a new split window + open the selected file in a new split window + open the selected file in a new vertical split window + open the selected file in a new tab + select next file in the file listing + select next file in the file listing + select next file in the file listing + select previous file in the file listing + select previous file in the file listing + select previous file in the file listing + cancel (dismisses file listing) + +The following is also available on terminals which support it: + + cancel (dismisses file listing) + +Note that the default mappings can be overriden by setting options in your +~/.vimrc file (see the OPTIONS section for a full list of available options). + +In addition, when the file listing has focus, typing a character will cause +the selection to jump to the first path which begins with that character. +Typing multiple characters consecutively can be used to distinguish between +paths which begin with the same prefix. + + +COMMANDS *command-t-commands* + + *:CommandT* +|:CommandT| Brings up the Command-T file window, starting in the + current working directory as returned by the|:pwd| + command. + + *:CommandTBuffer* +|:CommandTBuffer|Brings up the Command-T buffer window. + This works exactly like the standard file window, + except that the selection is limited to files that + you already have open in buffers. + + *:CommandTFlush* +|:CommandTFlush|Instructs the plug-in to flush its path cache, causing + the directory to be rescanned for new or deleted paths + the next time the file window is shown. In addition, all + configuration settings are re-evaluated, causing any + changes made to settings via the |:let| command to be picked + up. + + +MAPPINGS *command-t-mappings* + +By default Command-T comes with only two mappings: + + t bring up the Command-T file window + b bring up the Command-T buffer window + +However, Command-T won't overwrite a pre-existing mapping so if you prefer +to define different mappings use lines like these in your ~/.vimrc: + + nmap t :CommandT + nmap b :CommandTBuffer + +Replacing "t" or "b" with your mapping of choice. + +Note that in the case of MacVim you actually can map to Command-T (written +as in Vim) in your ~/.gvimrc file if you first unmap the existing menu +binding of Command-T to "New Tab": + + if has("gui_macvim") + macmenu &File.New\ Tab key= + map :CommandT + endif + +When the Command-T window is active a number of other additional mappings +become available for doing things like moving between and selecting matches. +These are fully described above in the USAGE section, and settings for +overriding the mappings are listed below under OPTIONS. + + +OPTIONS *command-t-options* + +A number of options may be set in your ~/.vimrc to influence the behaviour of +the plug-in. To set an option, you include a line like this in your ~/.vimrc: + + let g:CommandTMaxFiles=20000 + +To have Command-T pick up new settings immediately (that is, without having +to restart Vim) you can issue the |:CommandTFlush| command after making +changes via |:let|. + +Following is a list of all available options: + + *g:CommandTMaxFiles* + |g:CommandTMaxFiles| number (default 10000) + + The maximum number of files that will be considered when scanning the + current directory. Upon reaching this number scanning stops. This + limit applies only to file listings and is ignored for buffer + listings. + + *g:CommandTMaxDepth* + |g:CommandTMaxDepth| number (default 15) + + The maximum depth (levels of recursion) to be explored when scanning the + current directory. Any directories at levels beyond this depth will be + skipped. + + *g:CommandTMaxHeight* + |g:CommandTMaxHeight| number (default: 0) + + The maximum height in lines the match window is allowed to expand to. + If set to 0, the window will occupy as much of the available space as + needed to show matching entries. + + *g:CommandTAlwaysShowDotFiles* + |g:CommandTAlwaysShowDotFiles| boolean (default: 0) + + When showing the file listing Command-T will by default show dot-files + only if the entered search string contains a dot that could cause a + dot-file to match. When set to a non-zero value, this setting instructs + Command-T to always include matching dot-files in the match list + regardless of whether the search string contains a dot. See also + |g:CommandTNeverShowDotFiles|. Note that this setting only influences + the file listing; the buffer listing treats dot-files like any other + file. + + *g:CommandTNeverShowDotFiles* + |g:CommandTNeverShowDotFiles| boolean (default: 0) + + In the file listing, Command-T will by default show dot-files if the + entered search string contains a dot that could cause a dot-file to + match. When set to a non-zero value, this setting instructs Command-T to + never show dot-files under any circumstances. Note that it is + contradictory to set both this setting and + |g:CommandTAlwaysShowDotFiles| to true, and if you do so Vim will suffer + from headaches, nervous twitches, and sudden mood swings. This setting + has no effect in buffer listings, where dot files are treated like any + other file. + + *g:CommandTScanDotDirectories* + |g:CommandTScanDotDirectories| boolean (default: 0) + + Normally Command-T will not recurse into "dot-directories" (directories + whose names begin with a dot) while performing its initial scan. Set + this setting to a non-zero value to override this behavior and recurse. + Note that this setting is completely independent of the + |g:CommandTAlwaysShowDotFiles| and |g:CommandTNeverShowDotFiles| + settings; those apply only to the selection and display of matches + (after scanning has been performed), whereas + |g:CommandTScanDotDirectories| affects the behaviour at scan-time. + + Note also that even with this setting off you can still use Command-T to + open files inside a "dot-directory" such as ~/.vim, but you have to use + the |:cd| command to change into that directory first. For example: + + :cd ~/.vim + :CommandT + + *g:CommandTMatchWindowAtTop* + |g:CommandTMatchWindowAtTop| boolean (default: 0) + + When this setting is off (the default) the match window will appear at + the bottom so as to keep it near to the prompt. Turning it on causes the + match window to appear at the top instead. This may be preferable if you + want the best match (usually the first one) to appear in a fixed location + on the screen rather than moving as the number of matches changes during + typing. + + *g:CommandTMatchWindowReverse* + |g:CommandTMatchWindowReverse| boolean (default: 0) + + When this setting is off (the default) the matches will appear from + top to bottom with the topmost being selected. Turning it on causes the + matches to be reversed so the best match is at the bottom and the + initially selected match is the bottom most. This may be preferable if + you want the best match to appear in a fixed location on the screen + but still be near the prompt at the bottom. + +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 as the mapping for cancelling (dismissing) the Command-T +window, you would add the following to your ~/.vimrc: + + let g:CommandTCancelMap='' + +Multiple, alternative mappings may be specified using list syntax: + + let g:CommandTCancelMap=['', ''] + +Following is a list of all map settings and their defaults: + + Setting Default mapping(s) + + *g:CommandTBackspaceMap* + |g:CommandTBackspaceMap| + + *g:CommandTDeleteMap* + |g:CommandTDeleteMap| + + *g:CommandTAcceptSelectionMap* + |g:CommandTAcceptSelectionMap| + + *g:CommandTAcceptSelectionSplitMap* + |g:CommandTAcceptSelectionSplitMap| + + + *g:CommandTAcceptSelectionTabMap* + |g:CommandTAcceptSelectionTabMap| + + *g:CommandTAcceptSelectionVSplitMap* + |g:CommandTAcceptSelectionVSplitMap| + + *g:CommandTToggleFocusMap* + |g:CommandTToggleFocusMap| + + *g:CommandTCancelMap* + |g:CommandTCancelMap| + (not on all terminals) + + *g:CommandTSelectNextMap* + |g:CommandTSelectNextMap| + + + + *g:CommandTSelectPrevMap* + |g:CommandTSelectPrevMap| + + + + *g:CommandTClearMap* + |g:CommandTClearMap| + + *g:CommandTCursorLeftMap* + |g:CommandTCursorLeftMap| + + + *g:CommandTCursorRightMap* + |g:CommandTCursorRightMap| + + + *g:CommandTCursorEndMap* + |g:CommandTCursorEndMap| + + *g:CommandTCursorStartMap* + |g:CommandTCursorStartMap| + +In addition to the options provided by Command-T itself, some of Vim's own +settings can be used to control behavior: + + *command-t-wildignore* + |'wildignore'| string (default: '') + + Vim's |'wildignore'| setting is used to determine which files should be + excluded from listings. This is a comma-separated list of glob patterns. + It defaults to the empty string, but common settings include "*.o,*.obj" + (to exclude object files) or ".git,.svn" (to exclude SCM metadata + directories). For example: + + :set wildignore+=*.o,*.obj,.git + + A pattern such as "vendor/rails/**" would exclude all files and + subdirectories inside the "vendor/rails" directory (relative to + directory Command-T starts in). + + See the |'wildignore'| documentation for more information. + + +AUTHORS *command-t-authors* + +Command-T is written and maintained by Wincent Colaiuta . +Other contributors that have submitted patches include (in alphabetical +order): + + Daniel Hahler + Lucas de Vries + Matthew Todd + Mike Lundy + Scott Bronson + Steven Moazami + Sung Pae + Victor Hugo Borja + Zak Johnson + +As this was the first Vim plug-in I had ever written I was heavily influenced +by the design of the LustyExplorer plug-in by Stephen Bach, which I understand +is one of the largest Ruby-based Vim plug-ins to date. + +While the Command-T codebase doesn't contain any code directly copied from +LustyExplorer, I did use it as a reference for answers to basic questions (like +"How do you do 'X' in a Ruby-based Vim plug-in?"), and also copied some basic +architectural decisions (like the division of the code into Prompt, Settings +and MatchWindow classes). + +LustyExplorer is available from: + + http://www.vim.org/scripts/script.php?script_id=1890 + + +WEBSITE *command-t-website* + +The official website for Command-T is: + + https://wincent.com/products/command-t + +The latest release will always be available from there. + +Development in progress can be inspected via the project's Git repository +browser at: + + https://wincent.com/repos/command-t + +A copy of each release is also available from the official Vim scripts site +at: + + http://www.vim.org/scripts/script.php?script_id=3025 + +Bug reports should be submitted to the issue tracker at: + + https://wincent.com/issues + + +DONATIONS *command-t-donations* + +Command-T itself is free software released under the terms of the BSD license. +If you would like to support further development you can make a donation via +PayPal to win@wincent.com: + + https://wincent.com/products/command-t/donations + + +LICENSE *command-t-license* + +Copyright 2010-2011 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. + + +HISTORY *command-t-history* + +1.2.1 (30 April 2011) + +- Remove duplicate copy of the documentation that was causing "Duplicate tag" + errors +- Mitigate issue with distracting blinking cursor in non-GUI versions of Vim + (patch from Steven Moazami) + +1.2 (30 April 2011) + +- added |g:CommandTMatchWindowReverse| option, to reverse the order of items + in the match listing (patch from Steven Moazami) + +1.1b2 (26 March 2011) + +- fix a glitch in the release process; the plugin itself is unchanged since + 1.1b + +1.1b (26 March 2011) + +- add |:CommandTBuffer| command for quickly selecting among open buffers + +1.0.1 (5 January 2011) + +- work around bug when mapping |:CommandTFlush|, wherein the default mapping + for |:CommandT| would not be set up +- clean up when leaving the Command-T buffer via unexpected means (such as + with or similar) + +1.0 (26 November 2010) + +- make relative path simplification work on Windows + +1.0b (5 November 2010) + +- work around platform-specific Vim 7.3 bug seen by some users (wherein + Vim always falsely reports to Ruby that the buffer numbers is 0) +- re-use the buffer that is used to show the match listing, rather than + throwing it away and recreating it each time Command-T is shown; this + stops the buffer numbers from creeping up needlessly + +0.9 (8 October 2010) + +- use relative paths when opening files inside the current working directory + in order to keep buffer listings as brief as possible (patch from Matthew + Todd) + +0.8.1 (14 September 2010) + +- fix mapping issues for users who have set |'notimeout'| (patch from Sung + Pae) + +0.8 (19 August 2010) + +- overrides for the default mappings can now be lists of strings, allowing + multiple mappings to be defined for any given action +- t mapping only set up if no other map for |:CommandT| exists + (patch from Scott Bronson) +- prevent folds from appearing in the match listing +- tweaks to avoid the likelihood of "Not enough room" errors when trying to + open files +- watch out for "nil" windows when restoring window dimensions +- optimizations (avoid some repeated downcasing) +- move all Ruby files under the "command-t" subdirectory and avoid polluting + the "Vim" module namespace + +0.8b (11 July 2010) + +- large overhaul of the scoring algorithm to make the ordering of returned + results more intuitive; given the scope of the changes and room for + optimization of the new algorithm, this release is labelled as "beta" + +0.7 (10 June 2010) + +- handle more |'wildignore'| patterns by delegating to Vim's own |expand()| + function; with this change it is now viable to exclude patterns such as + 'vendor/rails/**' in addition to filename-only patterns like '*.o' and + '.git' (patch from Mike Lundy) +- always sort results alphabetically for empty search strings; this eliminates + filesystem-specific variations (patch from Mike Lundy) + +0.6 (28 April 2010) + +- |:CommandT| now accepts an optional parameter to specify the starting + directory, temporarily overriding the usual default of Vim's |:pwd| +- fix truncated paths when operating from root directory + +0.5.1 (11 April 2010) + +- fix for Ruby 1.9 compatibility regression introduced in 0.5 +- documentation enhancements, specifically targetted at Windows users + +0.5 (3 April 2010) + +- |:CommandTFlush| now re-evaluates settings, allowing changes made via |let| + to be picked up without having to restart Vim +- fix premature abort when scanning very deep directory hierarchies +- remove broken || key mapping on vt100 and xterm terminals +- provide settings for overriding default mappings +- minor performance optimization + +0.4 (27 March 2010) + +- add |g:CommandTMatchWindowAtTop| setting (patch from Zak Johnson) +- documentation fixes and enhancements +- internal refactoring and simplification + +0.3 (24 March 2010) + +- add |g:CommandTMaxHeight| setting for controlling the maximum height of the + match window (patch from Lucas de Vries) +- fix bug where |'list'| setting might be inappropriately set after dismissing + Command-T +- compatibility fix for different behaviour of "autoload" under Ruby 1.9.1 +- avoid "highlight group not found" warning when run under a version of Vim + that does not have syntax highlighting support +- open in split when opening normally would fail due to |'hidden'| and + |'modified'| values + +0.2 (23 March 2010) + +- compatibility fixes for compilation under Ruby 1.9 series +- compatibility fixes for compilation under Ruby 1.8.5 +- compatibility fixes for Windows and other non-UNIX platforms +- suppress "mapping already exists" message if t mapping is already + defined when plug-in is loaded +- exclude paths based on |'wildignore'| setting rather than a hardcoded + regular expression + +0.1 (22 March 2010) + +- initial public release + +------------------------------------------------------------------------------ +vim:tw=78:ft=help: diff --git a/vim/tmp/command_t/plugin/command-t.vim b/vim/tmp/command_t/plugin/command-t.vim new file mode 100644 index 0000000..7ef6bcd --- /dev/null +++ b/vim/tmp/command_t/plugin/command-t.vim @@ -0,0 +1,164 @@ +" command-t.vim +" Copyright 2010-2011 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. + +if exists("g:command_t_loaded") + finish +endif +let g:command_t_loaded = 1 + +command CommandTBuffer call CommandTShowBufferFinder() +command -nargs=? -complete=dir CommandT call CommandTShowFileFinder() +command CommandTFlush call CommandTFlush() + +if !hasmapto(':CommandT') + silent! nmap t :CommandT +endif + +if !hasmapto(':CommandTBuffer') + silent! nmap b :CommandTBuffer +endif + +function s:CommandTRubyWarning() + echohl WarningMsg + echo "command-t.vim requires Vim to be compiled with Ruby support" + echo "For more information type: :help command-t" + echohl none +endfunction + +function s:CommandTShowBufferFinder() + if has('ruby') + ruby $command_t.show_buffer_finder + else + call s:CommandTRubyWarning() + endif +endfunction + +function s:CommandTShowFileFinder(arg) + if has('ruby') + ruby $command_t.show_file_finder + else + call s:CommandTRubyWarning() + endif +endfunction + +function s:CommandTFlush() + if has('ruby') + ruby $command_t.flush + else + call s:CommandTRubyWarning() + endif +endfunction + +if !has('ruby') + finish +endif + +function CommandTHandleKey(arg) + ruby $command_t.handle_key +endfunction + +function CommandTBackspace() + ruby $command_t.backspace +endfunction + +function CommandTDelete() + ruby $command_t.delete +endfunction + +function CommandTAcceptSelection() + ruby $command_t.accept_selection +endfunction + +function CommandTAcceptSelectionTab() + ruby $command_t.accept_selection :command => 'tabe' +endfunction + +function CommandTAcceptSelectionSplit() + ruby $command_t.accept_selection :command => 'sp' +endfunction + +function CommandTAcceptSelectionVSplit() + ruby $command_t.accept_selection :command => 'vs' +endfunction + +function CommandTToggleFocus() + ruby $command_t.toggle_focus +endfunction + +function CommandTCancel() + ruby $command_t.cancel +endfunction + +function CommandTSelectNext() + ruby $command_t.select_next +endfunction + +function CommandTSelectPrev() + ruby $command_t.select_prev +endfunction + +function CommandTClear() + ruby $command_t.clear +endfunction + +function CommandTCursorLeft() + ruby $command_t.cursor_left +endfunction + +function CommandTCursorRight() + ruby $command_t.cursor_right +endfunction + +function CommandTCursorEnd() + ruby $command_t.cursor_end +endfunction + +function CommandTCursorStart() + ruby $command_t.cursor_start +endfunction + +ruby << EOF + # require Ruby files + begin + # prepare controller + require 'command-t/vim' + require 'command-t/controller' + $command_t = CommandT::Controller.new + rescue LoadError + load_path_modified = false + ::VIM::evaluate('&runtimepath').to_s.split(',').each do |path| + lib = "#{path}/ruby" + if !$LOAD_PATH.include?(lib) and File.exist?(lib) + $LOAD_PATH << lib + load_path_modified = true + end + end + retry if load_path_modified + + # could get here if C extension was not compiled, or was compiled + # for the wrong architecture or Ruby version + require 'command-t/stub' + $command_t = CommandT::Stub.new + end +EOF diff --git a/vim/tmp/command_t/ruby/command-t/controller.rb b/vim/tmp/command_t/ruby/command-t/controller.rb new file mode 100644 index 0000000..29e61b6 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/controller.rb @@ -0,0 +1,317 @@ +# Copyright 2010-2011 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/finder/buffer_finder' +require 'command-t/finder/file_finder' +require 'command-t/match_window' +require 'command-t/prompt' +require 'command-t/vim/path_utilities' + +module CommandT + class Controller + include VIM::PathUtilities + + def initialize + @prompt = Prompt.new + @buffer_finder = CommandT::BufferFinder.new + set_up_file_finder + set_up_max_height + end + + def show_buffer_finder + @path = VIM::pwd + @active_finder = @buffer_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) + @file_finder.path = @path + @active_finder = @file_finder + show + rescue Errno::ENOENT + # probably a problem with the optional parameter + @match_window.print_no_such_file_or_directory + end + + def hide + @match_window.close + if VIM::Window.select @initial_window + if @initial_buffer.number == 0 + # upstream bug: buffer number misreported as 0 + # see: https://wincent.com/issues/1617 + ::VIM::command "silent b #{@initial_buffer.name}" + else + ::VIM::command "silent b #{@initial_buffer.number}" + end + end + end + + def flush + set_up_max_height + set_up_file_finder + end + + def handle_key + key = ::VIM::evaluate('a:arg').to_i.chr + if @focus == @prompt + @prompt.add! key + list_matches + else + @match_window.find key + end + end + + def backspace + if @focus == @prompt + @prompt.backspace! + list_matches + end + end + + def delete + if @focus == @prompt + @prompt.delete! + list_matches + end + end + + def accept_selection options = {} + selection = @match_window.selection + hide + open_selection(selection, options) unless selection.nil? + end + + def toggle_focus + @focus.unfocus # old focus + @focus = @focus == @prompt ? @match_window : @prompt + @focus.focus # new focus + end + + def cancel + hide + end + + def select_next + @match_window.select_next + end + + def select_prev + @match_window.select_prev + end + + def clear + @prompt.clear! + list_matches + end + + def cursor_left + @prompt.cursor_left if @focus == @prompt + end + + def cursor_right + @prompt.cursor_right if @focus == @prompt + end + + def cursor_end + @prompt.cursor_end if @focus == @prompt + end + + def cursor_start + @prompt.cursor_start if @focus == @prompt + end + + def leave + @match_window.leave + end + + def unload + @match_window.unload + end + + private + + def show + @initial_window = $curwin + @initial_buffer = $curbuf + @match_window = MatchWindow.new \ + :prompt => @prompt, + :match_window_at_top => get_bool('g:CommandTMatchWindowAtTop'), + :match_window_reverse => get_bool('g:CommandTMatchWindowReverse') + @focus = @prompt + @prompt.focus + register_for_key_presses + clear # clears prompt and lists matches + end + + def set_up_max_height + @max_height = get_number('g:CommandTMaxHeight') || 0 + end + + def set_up_file_finder + @file_finder = CommandT::FileFinder.new nil, + :max_files => get_number('g:CommandTMaxFiles'), + :max_depth => get_number('g:CommandTMaxDepth'), + :always_show_dot_files => get_bool('g:CommandTAlwaysShowDotFiles'), + :never_show_dot_files => get_bool('g:CommandTNeverShowDotFiles'), + :scan_dot_directories => get_bool('g:CommandTScanDotDirectories') + end + + def exists? name + ::VIM::evaluate("exists(\"#{name}\")").to_i != 0 + end + + def get_number name + exists?(name) ? ::VIM::evaluate("#{name}").to_i : nil + end + + def get_bool name + exists?(name) ? ::VIM::evaluate("#{name}").to_i != 0 : nil + end + + def get_string name + exists?(name) ? ::VIM::evaluate("#{name}").to_s : nil + end + + # expect a string or a list of strings + def get_list_or_string name + return nil unless exists?(name) + list_or_string = ::VIM::evaluate("#{name}") + if list_or_string.kind_of?(Array) + list_or_string.map { |item| item.to_s } + else + list_or_string.to_s + 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' + else + 'e' + end + end + + def ensure_appropriate_window_selection + # normally we try to open the selection in the current window, but there + # is one exception: + # + # - we don't touch any "unlisted" buffer with buftype "nofile" (such as + # NERDTree or MiniBufExplorer); this is to avoid things like the "Not + # enough room" error which occurs when trying to open in a split in a + # shallow (potentially 1-line) buffer like MiniBufExplorer is current + # + # Other "unlisted" buffers, such as those with buftype "help" are treated + # normally. + initial = $curwin + while true do + break unless ::VIM::evaluate('&buflisted').to_i == 0 && + ::VIM::evaluate('&buftype').to_s == 'nofile' + ::VIM::command 'wincmd w' # try next window + break if $curwin == initial # have already tried all + end + end + + 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}" + end + + def map key, function, param = nil + ::VIM::command "noremap #{key} " \ + ":call CommandT#{function}(#{param})" + end + + def xterm? + !!(::VIM::evaluate('&term') =~ /\Axterm/) + end + + def vt100? + !!(::VIM::evaluate('&term') =~ /\Avt100/) + end + + def register_for_key_presses + # "normal" keys (interpreted literally) + numbers = ('0'..'9').to_a.join + lowercase = ('a'..'z').to_a.join + uppercase = lowercase.upcase + punctuation = '<>`@#~!"$%&/()=+*-_.,;:?\\\'{}[] ' # and space + (numbers + lowercase + uppercase + punctuation).each_byte do |b| + map "", 'HandleKey', b + end + + # "special" keys (overridable by settings) + { 'Backspace' => '', + 'Delete' => '', + 'AcceptSelection' => '', + 'AcceptSelectionSplit' => ['', ''], + 'AcceptSelectionTab' => '', + 'AcceptSelectionVSplit' => '', + 'ToggleFocus' => '', + 'Cancel' => ['', ''], + 'SelectNext' => ['', '', ''], + 'SelectPrev' => ['', '', ''], + 'Clear' => '', + 'CursorLeft' => ['', ''], + 'CursorRight' => ['', ''], + 'CursorEnd' => '', + 'CursorStart' => '' }.each do |key, value| + if override = get_list_or_string("g:CommandT#{key}Map") + [override].flatten.each do |mapping| + map mapping, key + end + else + [value].flatten.each do |mapping| + map mapping, key unless mapping == '' && (xterm? || vt100?) + end + end + end + end + + # Returns the desired maximum number of matches, based on available + # vertical space and the g:CommandTMaxHeight option. + def match_limit + limit = VIM::Screen.lines - 5 + limit = 1 if limit < 0 + limit = [limit, @max_height].min if @max_height > 0 + limit + end + + def list_matches + matches = @active_finder.sorted_matches_for @prompt.abbrev, :limit => match_limit + @match_window.matches = matches + end + end # class Controller +end # module commandT diff --git a/vim/tmp/command_t/ruby/command-t/depend b/vim/tmp/command_t/ruby/command-t/depend new file mode 100644 index 0000000..bfa9552 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/depend @@ -0,0 +1,24 @@ +# Copyright 2010 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. + +CFLAGS += -std=c99 -Wall -Wextra -Wno-unused-parameter diff --git a/vim/tmp/command_t/ruby/command-t/ext.c b/vim/tmp/command_t/ruby/command-t/ext.c new file mode 100644 index 0000000..c5026cc --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/ext.c @@ -0,0 +1,65 @@ +// Copyright 2010 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. + +#include "match.h" +#include "matcher.h" + +VALUE mCommandT = 0; // module CommandT +VALUE cCommandTMatch = 0; // class CommandT::Match +VALUE cCommandTMatcher = 0; // class CommandT::Matcher + +VALUE CommandT_option_from_hash(const char *option, VALUE hash) +{ + if (NIL_P(hash)) + return Qnil; + VALUE key = ID2SYM(rb_intern(option)); + if (rb_funcall(hash, rb_intern("has_key?"), 1, key) == Qtrue) + return rb_hash_aref(hash, key); + else + return Qnil; +} + +void Init_ext() +{ + // module CommandT + mCommandT = rb_define_module("CommandT"); + + // class CommandT::Match + cCommandTMatch = rb_define_class_under(mCommandT, "Match", rb_cObject); + + // methods + rb_define_method(cCommandTMatch, "initialize", CommandTMatch_initialize, -1); + rb_define_method(cCommandTMatch, "matches?", CommandTMatch_matches, 0); + rb_define_method(cCommandTMatch, "to_s", CommandTMatch_to_s, 0); + + // attributes + rb_define_attr(cCommandTMatch, "score", Qtrue, Qfalse); // reader: true, writer: false + + // class CommandT::Matcher + cCommandTMatcher = rb_define_class_under(mCommandT, "Matcher", rb_cObject); + + // methods + rb_define_method(cCommandTMatcher, "initialize", CommandTMatcher_initialize, -1); + rb_define_method(cCommandTMatcher, "sorted_matches_for", CommandTMatcher_sorted_matches_for, 2); + rb_define_method(cCommandTMatcher, "matches_for", CommandTMatcher_matches_for, 1); +} diff --git a/vim/tmp/command_t/ruby/command-t/ext.h b/vim/tmp/command_t/ruby/command-t/ext.h new file mode 100644 index 0000000..89ff076 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/ext.h @@ -0,0 +1,36 @@ +// Copyright 2010 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. + +#include + +extern VALUE mCommandT; // module CommandT +extern VALUE cCommandTMatch; // class CommandT::Match +extern VALUE cCommandTMatcher; // class CommandT::Matcher + +// Encapsulates common pattern of checking for an option in an optional +// options hash. The hash itself may be nil, but an exception will be +// raised if it is not nil and not a hash. +VALUE CommandT_option_from_hash(const char *option, VALUE hash); + +// Debugging macro. +#define ruby_inspect(obj) rb_funcall(rb_mKernel, rb_intern("p"), 1, obj) diff --git a/vim/tmp/command_t/ruby/command-t/extconf.rb b/vim/tmp/command_t/ruby/command-t/extconf.rb new file mode 100644 index 0000000..58503b6 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/extconf.rb @@ -0,0 +1,32 @@ +# Copyright 2010 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 'mkmf' + +def missing item + puts "couldn't find #{item} (required)" + exit 1 +end + +have_header('ruby.h') or missing('ruby.h') +create_makefile('ext') diff --git a/vim/tmp/command_t/ruby/command-t/finder.rb b/vim/tmp/command_t/ruby/command-t/finder.rb new file mode 100644 index 0000000..a3d0b09 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/finder.rb @@ -0,0 +1,52 @@ +# Copyright 2010-2011 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 + +module CommandT + # Encapsulates a Scanner instance (which builds up a list of available files + # in a directory) and a Matcher instance (which selects from that list based + # on a search string). + # + # Specialized subclasses use different kinds of scanners adapted for + # different kinds of search (files, buffers). + class Finder + def initialize path = Dir.pwd, options = {} + raise RuntimeError, 'Subclass responsibility' + end + + # Options: + # :limit (integer): limit the number of returned matches + def sorted_matches_for str, options = {} + @matcher.sorted_matches_for str, options + end + + def flush + @scanner.flush + end + + def path= path + @scanner.path = path + end + end # class Finder +end # CommandT diff --git a/vim/tmp/command_t/ruby/command-t/finder/buffer_finder.rb b/vim/tmp/command_t/ruby/command-t/finder/buffer_finder.rb new file mode 100644 index 0000000..2319c24 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/finder/buffer_finder.rb @@ -0,0 +1,35 @@ +# Copyright 2010-2011 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/buffer_scanner' +require 'command-t/finder' + +module CommandT + class BufferFinder < Finder + def initialize + @scanner = BufferScanner.new + @matcher = Matcher.new @scanner, :always_show_dot_files => true + end + end # class BufferFinder +end # CommandT diff --git a/vim/tmp/command_t/ruby/command-t/finder/file_finder.rb b/vim/tmp/command_t/ruby/command-t/finder/file_finder.rb new file mode 100644 index 0000000..a9ed231 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/finder/file_finder.rb @@ -0,0 +1,35 @@ +# Copyright 2010-2011 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/finder' +require 'command-t/scanner/file_scanner' + +module CommandT + class FileFinder < Finder + def initialize path = Dir.pwd, options = {} + @scanner = FileScanner.new path, options + @matcher = Matcher.new @scanner, options + end + end # class FileFinder +end # CommandT diff --git a/vim/tmp/command_t/ruby/command-t/match.c b/vim/tmp/command_t/ruby/command-t/match.c new file mode 100644 index 0000000..e32fb0b --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/match.c @@ -0,0 +1,189 @@ +// Copyright 2010 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. + +#include "match.h" +#include "ext.h" +#include "ruby_compat.h" + +// use a struct to make passing params during recursion easier +typedef struct +{ + char *str_p; // pointer to string to be searched + long str_len; // length of same + char *abbrev_p; // pointer to search string (abbreviation) + long abbrev_len; // length of same + double max_score_per_char; + int dot_file; // boolean: true if str is a dot-file + int always_show_dot_files; // boolean + int never_show_dot_files; // boolean +} matchinfo_t; + +double recursive_match(matchinfo_t *m, // sharable meta-data + long str_idx, // where in the path string to start + long abbrev_idx, // where in the search string to start + long last_idx, // location of last matched character + double score) // cumulative score so far +{ + double seen_score = 0; // remember best score seen via recursion + int dot_file_match = 0; // true if abbrev matches a dot-file + int dot_search = 0; // true if searching for a dot + + for (long i = abbrev_idx; i < m->abbrev_len; i++) + { + char c = m->abbrev_p[i]; + if (c == '.') + dot_search = 1; + int found = 0; + for (long j = str_idx; j < m->str_len; j++, str_idx++) + { + char d = m->str_p[j]; + if (d == '.') + { + if (j == 0 || m->str_p[j - 1] == '/') + { + m->dot_file = 1; // this is a dot-file + if (dot_search) // and we are searching for a dot + dot_file_match = 1; // so this must be a match + } + } + else if (d >= 'A' && d <= 'Z') + d += 'a' - 'A'; // add 32 to downcase + if (c == d) + { + found = 1; + dot_search = 0; + + // calculate score + double score_for_char = m->max_score_per_char; + long distance = j - last_idx; + if (distance > 1) + { + double factor = 1.0; + char last = m->str_p[j - 1]; + char curr = m->str_p[j]; // case matters, so get again + if (last == '/') + factor = 0.9; + else if (last == '-' || + last == '_' || + last == ' ' || + (last >= '0' && last <= '9')) + factor = 0.8; + else if (last >= 'a' && last <= 'z' && + curr >= 'A' && curr <= 'Z') + factor = 0.8; + else if (last == '.') + factor = 0.7; + else + // if no "special" chars behind char, factor diminishes + // as distance from last matched char increases + factor = (1.0 / distance) * 0.75; + score_for_char *= factor; + } + + if (++j < m->str_len) + { + // bump cursor one char to the right and + // use recursion to try and find a better match + double sub_score = recursive_match(m, j, i, last_idx, score); + if (sub_score > seen_score) + seen_score = sub_score; + } + + score += score_for_char; + last_idx = str_idx++; + break; + } + } + if (!found) + return 0.0; + } + if (m->dot_file) + { + if (m->never_show_dot_files || + (!dot_file_match && !m->always_show_dot_files)) + return 0.0; + } + return (score > seen_score) ? score : seen_score; +} + +// Match.new abbrev, string, options = {} +VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self) +{ + // process arguments: 2 mandatory, 1 optional + VALUE str, abbrev, options; + if (rb_scan_args(argc, argv, "21", &str, &abbrev, &options) == 2) + options = Qnil; + str = StringValue(str); + abbrev = StringValue(abbrev); // already downcased by caller + + // check optional options hash for overrides + VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options); + VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options); + + matchinfo_t m; + m.str_p = RSTRING_PTR(str); + m.str_len = RSTRING_LEN(str); + m.abbrev_p = RSTRING_PTR(abbrev); + m.abbrev_len = RSTRING_LEN(abbrev); + m.max_score_per_char = (1.0 / m.str_len + 1.0 / m.abbrev_len) / 2; + m.dot_file = 0; + m.always_show_dot_files = always_show_dot_files == Qtrue; + m.never_show_dot_files = never_show_dot_files == Qtrue; + + // calculate score + double score = 1.0; + if (m.abbrev_len == 0) // special case for zero-length search string + { + // filter out dot files + if (!m.always_show_dot_files) + { + for (long i = 0; i < m.str_len; i++) + { + char c = m.str_p[i]; + if (c == '.' && (i == 0 || m.str_p[i - 1] == '/')) + { + score = 0.0; + break; + } + } + } + } + else // normal case + score = recursive_match(&m, 0, 0, 0, 0.0); + + // clean-up and final book-keeping + rb_iv_set(self, "@score", rb_float_new(score)); + rb_iv_set(self, "@str", str); + return Qnil; +} + +VALUE CommandTMatch_matches(VALUE self) +{ + double score = NUM2DBL(rb_iv_get(self, "@score")); + return score > 0 ? Qtrue : Qfalse; +} + +VALUE CommandTMatch_to_s(VALUE self) +{ + return rb_iv_get(self, "@str"); +} diff --git a/vim/tmp/command_t/ruby/command-t/match.h b/vim/tmp/command_t/ruby/command-t/match.h new file mode 100644 index 0000000..c3ce929 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/match.h @@ -0,0 +1,29 @@ +// Copyright 2010 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. + +#include + +extern VALUE CommandTMatch_initialize(int argc, VALUE *argv, VALUE self); +extern VALUE CommandTMatch_matches(VALUE self); +extern VALUE CommandTMatch_score(VALUE self); +extern VALUE CommandTMatch_to_s(VALUE self); diff --git a/vim/tmp/command_t/ruby/command-t/match_window.rb b/vim/tmp/command_t/ruby/command-t/match_window.rb new file mode 100644 index 0000000..f984287 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/match_window.rb @@ -0,0 +1,387 @@ +# Copyright 2010-2011 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 'ostruct' +require 'command-t/settings' + +module CommandT + class MatchWindow + @@selection_marker = '> ' + @@marker_length = @@selection_marker.length + @@unselected_marker = ' ' * @@marker_length + @@buffer = nil + + def initialize options = {} + @prompt = options[:prompt] + @reverse_list = options[:match_window_reverse] + + # save existing window dimensions so we can restore them later + @windows = [] + (0..(::VIM::Window.count - 1)).each do |i| + window = OpenStruct.new :index => i, :height => ::VIM::Window[i].height + @windows << window + end + + # global settings (must manually save and restore) + @settings = Settings.new + ::VIM::set_option 'timeout' # ensure mappings timeout + ::VIM::set_option 'timeoutlen=0' # respond immediately to mappings + ::VIM::set_option 'nohlsearch' # don't highlight search strings + ::VIM::set_option 'noinsertmode' # don't make Insert mode the default + ::VIM::set_option 'noshowcmd' # don't show command info on last line + ::VIM::set_option 'report=9999' # don't show "X lines changed" reports + ::VIM::set_option 'sidescroll=0' # don't sidescroll in jumps + ::VIM::set_option 'sidescrolloff=0' # don't sidescroll automatically + ::VIM::set_option 'noequalalways' # don't auto-balance window sizes + + # show match window + split_location = options[:match_window_at_top] ? 'topleft' : 'botright' + if @@buffer # still have buffer from last time + ::VIM::command "silent! #{split_location} #{@@buffer.number}sbuffer" + raise "Can't re-open GoToFile buffer" unless $curbuf.number == @@buffer.number + $curwin.height = 1 + else # creating match window for first time and set it up + split_command = "silent! #{split_location} 1split GoToFile" + [ + split_command, + 'setlocal bufhidden=unload', # unload buf when no longer displayed + 'setlocal buftype=nofile', # buffer is not related to any file + 'setlocal nomodifiable', # prevent manual edits + 'setlocal noswapfile', # don't create a swapfile + 'setlocal nowrap', # don't soft-wrap + 'setlocal nonumber', # don't show line numbers + 'setlocal nolist', # don't use List mode (visible tabs etc) + 'setlocal foldcolumn=0', # don't show a fold column at side + 'setlocal foldlevel=99', # don't fold anything + 'setlocal nocursorline', # don't highlight line cursor is on + 'setlocal nospell', # spell-checking off + 'setlocal nobuflisted', # don't show up in the buffer list + 'setlocal textwidth=0' # don't hard-wrap (break long lines) + ].each { |command| ::VIM::command command } + + # sanity check: make sure the buffer really was created + raise "Can't find GoToFile buffer" unless $curbuf.name.match /GoToFile\z/ + @@buffer = $curbuf + end + + # syntax coloring + if VIM::has_syntax? + ::VIM::command "syntax match CommandTSelection \"^#{@@selection_marker}.\\+$\"" + ::VIM::command 'syntax match CommandTNoEntries "^-- NO MATCHES --$"' + ::VIM::command 'syntax match CommandTNoEntries "^-- NO SUCH FILE OR DIRECTORY --$"' + ::VIM::command 'highlight link CommandTSelection Visual' + ::VIM::command 'highlight link CommandTNoEntries Error' + ::VIM::evaluate 'clearmatches()' + + # hide cursor + @cursor_highlight = get_cursor_highlight + hide_cursor + end + + # perform cleanup using an autocmd to ensure we don't get caught out + # by some unexpected means of dismissing or leaving the Command-T window + # (eg. , etc) + ::VIM::command 'autocmd! * ' + ::VIM::command 'autocmd BufLeave ruby $command_t.leave' + ::VIM::command 'autocmd BufUnload ruby $command_t.unload' + + @has_focus = false + @selection = nil + @abbrev = '' + @window = $curwin + end + + def close + # Workaround for upstream bug in Vim 7.3 on some platforms + # + # On some platforms, $curbuf.number always returns 0. One workaround is + # to build Vim with --disable-largefile, but as this is producing lots of + # support requests, implement the following fallback to the buffer name + # instead, at least until upstream gets fixed. + # + # For more details, see: https://wincent.com/issues/1617 + if $curbuf.number == 0 + # use bwipeout as bunload fails if passed the name of a hidden buffer + ::VIM::command 'bwipeout! GoToFile' + @@buffer = nil + else + ::VIM::command "bunload! #{@@buffer.number}" + end + end + + def leave + close + unload + end + + def unload + restore_window_dimensions + @settings.restore + @prompt.dispose + show_cursor + end + + def add! char + @abbrev += char + end + + def backspace! + @abbrev.chop! + end + + def select_next + if @selection < @matches.length - 1 + @selection += 1 + print_match(@selection - 1) # redraw old selection (removes marker) + print_match(@selection) # redraw new selection (adds marker) + move_cursor_to_selected_line + else + # (possibly) loop or scroll + end + end + + def select_prev + if @selection > 0 + @selection -= 1 + print_match(@selection + 1) # redraw old selection (removes marker) + print_match(@selection) # redraw new selection (adds marker) + move_cursor_to_selected_line + else + # (possibly) loop or scroll + end + end + + def matches= matches + matches = matches.reverse if @reverse_list + if matches != @matches + @matches = matches + @selection = @reverse_list ? @matches.length - 1 : 0 + print_matches + move_cursor_to_selected_line + end + end + + def focus + unless @has_focus + @has_focus = true + if VIM::has_syntax? + ::VIM::command 'highlight link CommandTSelection Search' + end + end + end + + def unfocus + if @has_focus + @has_focus = false + if VIM::has_syntax? + ::VIM::command 'highlight link CommandTSelection Visual' + end + end + end + + def find char + # is this a new search or the continuation of a previous one? + now = Time.now + if @last_key_time.nil? or @last_key_time < (now - 0.5) + @find_string = char + else + @find_string += char + end + @last_key_time = now + + # see if there's anything up ahead that matches + @matches.each_with_index do |match, idx| + if match[0, @find_string.length].casecmp(@find_string) == 0 + old_selection = @selection + @selection = idx + print_match(old_selection) # redraw old selection (removes marker) + print_match(@selection) # redraw new selection (adds marker) + break + end + end + end + + # Returns the currently selected item as a String. + def selection + @matches[@selection] + end + + def print_no_such_file_or_directory + print_error 'NO SUCH FILE OR DIRECTORY' + end + + private + + def move_cursor_to_selected_line + # on some non-GUI terminals, the cursor doesn't hide properly + # so we move the cursor to prevent it from blinking away in the + # upper-left corner in a distracting fashion + @window.cursor = [@selection + 1, 0] + end + + def print_error msg + return unless VIM::Window.select(@window) + unlock + clear + @window.height = 1 + @@buffer[1] = "-- #{msg} --" + lock + end + + def restore_window_dimensions + # sort from tallest to shortest + @windows.sort! { |a, b| b.height <=> a.height } + + # starting with the tallest ensures that there are no constraints + # preventing windows on the side of vertical splits from regaining + # their original full size + @windows.each do |w| + # beware: window may be nil + window = ::VIM::Window[w.index] + window.height = w.height if window + end + end + + def match_text_for_idx idx + match = truncated_match @matches[idx] + if idx == @selection + prefix = @@selection_marker + suffix = padding_for_selected_match match + else + prefix = @@unselected_marker + suffix = '' + end + prefix + match + suffix + end + + # Print just the specified match. + def print_match idx + return unless VIM::Window.select(@window) + unlock + @@buffer[idx + 1] = match_text_for_idx idx + lock + end + + # Print all matches. + def print_matches + match_count = @matches.length + if match_count == 0 + print_error 'NO MATCHES' + else + return unless VIM::Window.select(@window) + unlock + clear + actual_lines = 1 + @window_width = @window.width # update cached value + max_lines = VIM::Screen.lines - 5 + max_lines = 1 if max_lines < 0 + actual_lines = match_count > max_lines ? max_lines : match_count + @window.height = actual_lines + (1..actual_lines).each do |line| + idx = line - 1 + if @@buffer.count >= line + @@buffer[line] = match_text_for_idx idx + else + @@buffer.append line - 1, match_text_for_idx(idx) + end + end + lock + end + end + + # Prepare padding for match text (trailing spaces) so that selection + # highlighting extends all the way to the right edge of the window. + def padding_for_selected_match str + len = str.length + if len >= @window_width - @@marker_length + '' + else + ' ' * (@window_width - @@marker_length - len) + end + end + + # Convert "really/long/path" into "really...path" based on available + # window width. + def truncated_match str + len = str.length + available_width = @window_width - @@marker_length + return str if len <= available_width + left = (available_width / 2) - 1 + right = (available_width / 2) - 2 + (available_width % 2) + str[0, left] + '...' + str[-right, right] + end + + def clear + # range = % (whole buffer) + # action = d (delete) + # register = _ (black hole register, don't record deleted text) + ::VIM::command 'silent %d _' + end + + def get_cursor_highlight + # as :highlight returns nothing and only prints, + # must redirect its output to a variable + ::VIM::command 'silent redir => g:command_t_cursor_highlight' + + # force 0 verbosity to ensure origin information isn't printed as well + ::VIM::command 'silent! 0verbose highlight Cursor' + ::VIM::command 'silent redir END' + + # there are 3 possible formats to check for, each needing to be + # transformed in a certain way in order to reapply the highlight: + # Cursor xxx guifg=bg guibg=fg -> :hi! Cursor guifg=bg guibg=fg + # Cursor xxx links to SomethingElse -> :hi! link Cursor SomethingElse + # Cursor xxx cleared -> :hi! clear Cursor + highlight = ::VIM::evaluate 'g:command_t_cursor_highlight' + if highlight =~ /^Cursor\s+xxx\s+links to (\w+)/ + "link Cursor #{$~[1]}" + elsif highlight =~ /^Cursor\s+xxx\s+cleared/ + 'clear Cursor' + elsif highlight =~ /Cursor\s+xxx\s+(.+)/ + "Cursor #{$~[1]}" + else # likely cause E411 Cursor highlight group not found + nil + end + end + + def hide_cursor + if @cursor_highlight + ::VIM::command 'highlight Cursor NONE' + end + end + + def show_cursor + if @cursor_highlight + ::VIM::command "highlight #{@cursor_highlight}" + end + end + + def lock + ::VIM::command 'setlocal nomodifiable' + end + + def unlock + ::VIM::command 'setlocal modifiable' + end + end +end diff --git a/vim/tmp/command_t/ruby/command-t/matcher.c b/vim/tmp/command_t/ruby/command-t/matcher.c new file mode 100644 index 0000000..7cd8a3e --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/matcher.c @@ -0,0 +1,164 @@ +// Copyright 2010 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. + +#include /* for qsort() */ +#include /* for strcmp() */ +#include "matcher.h" +#include "ext.h" +#include "ruby_compat.h" + +// comparison function for use with qsort +int comp_alpha(const void *a, const void *b) +{ + VALUE a_val = *(VALUE *)a; + VALUE b_val = *(VALUE *)b; + ID to_s = rb_intern("to_s"); + + VALUE a_str = rb_funcall(a_val, to_s, 0); + VALUE b_str = rb_funcall(b_val, to_s, 0); + char *a_p = RSTRING_PTR(a_str); + long a_len = RSTRING_LEN(a_str); + char *b_p = RSTRING_PTR(b_str); + long b_len = RSTRING_LEN(b_str); + int order = 0; + if (a_len > b_len) + { + order = strncmp(a_p, b_p, b_len); + if (order == 0) + order = 1; // shorter string (b) wins + } + else if (a_len < b_len) + { + order = strncmp(a_p, b_p, a_len); + if (order == 0) + order = -1; // shorter string (a) wins + } + else + order = strncmp(a_p, b_p, a_len); + return order; +} + +// comparison function for use with qsort +int comp_score(const void *a, const void *b) +{ + VALUE a_val = *(VALUE *)a; + VALUE b_val = *(VALUE *)b; + ID score = rb_intern("score"); + double a_score = RFLOAT_VALUE(rb_funcall(a_val, score, 0)); + double b_score = RFLOAT_VALUE(rb_funcall(b_val, score, 0)); + if (a_score > b_score) + return -1; // a scores higher, a should appear sooner + else if (a_score < b_score) + return 1; // b scores higher, a should appear later + else + return comp_alpha(a, b); +} + +VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self) +{ + // process arguments: 1 mandatory, 1 optional + VALUE scanner, options; + if (rb_scan_args(argc, argv, "11", &scanner, &options) == 1) + options = Qnil; + if (NIL_P(scanner)) + rb_raise(rb_eArgError, "nil scanner"); + rb_iv_set(self, "@scanner", scanner); + + // check optional options hash for overrides + VALUE always_show_dot_files = CommandT_option_from_hash("always_show_dot_files", options); + if (always_show_dot_files != Qtrue) + always_show_dot_files = Qfalse; + VALUE never_show_dot_files = CommandT_option_from_hash("never_show_dot_files", options); + if (never_show_dot_files != Qtrue) + never_show_dot_files = Qfalse; + rb_iv_set(self, "@always_show_dot_files", always_show_dot_files); + rb_iv_set(self, "@never_show_dot_files", never_show_dot_files); + return Qnil; +} + +VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options) +{ + // process optional options hash + VALUE limit_option = CommandT_option_from_hash("limit", options); + + // get unsorted matches + VALUE matches = CommandTMatcher_matches_for(self, abbrev); + + abbrev = StringValue(abbrev); + if (RSTRING_LEN(abbrev) == 0 || + (RSTRING_LEN(abbrev) == 1 && RSTRING_PTR(abbrev)[0] == '.')) + // alphabetic order if search string is only "" or "." + qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_alpha); + else + // for all other non-empty search strings, sort by score + qsort(RARRAY_PTR(matches), RARRAY_LEN(matches), sizeof(VALUE), comp_score); + + // apply optional limit option + long limit = NIL_P(limit_option) ? 0 : NUM2LONG(limit_option); + if (limit == 0 || RARRAY_LEN(matches) < limit) + limit = RARRAY_LEN(matches); + + // will return an array of strings, not an array of Match objects + for (long i = 0; i < limit; i++) + { + VALUE str = rb_funcall(RARRAY_PTR(matches)[i], rb_intern("to_s"), 0); + RARRAY_PTR(matches)[i] = str; + } + + // trim off any items beyond the limit + if (limit < RARRAY_LEN(matches)) + (void)rb_funcall(matches, rb_intern("slice!"), 2, LONG2NUM(limit), + LONG2NUM(RARRAY_LEN(matches) - limit)); + return matches; +} + +VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev) +{ + if (NIL_P(abbrev)) + rb_raise(rb_eArgError, "nil abbrev"); + VALUE matches = rb_ary_new(); + VALUE scanner = rb_iv_get(self, "@scanner"); + VALUE always_show_dot_files = rb_iv_get(self, "@always_show_dot_files"); + VALUE never_show_dot_files = rb_iv_get(self, "@never_show_dot_files"); + VALUE options = Qnil; + if (always_show_dot_files == Qtrue) + { + options = rb_hash_new(); + rb_hash_aset(options, ID2SYM(rb_intern("always_show_dot_files")), always_show_dot_files); + } + else if (never_show_dot_files == Qtrue) + { + options = rb_hash_new(); + rb_hash_aset(options, ID2SYM(rb_intern("never_show_dot_files")), never_show_dot_files); + } + abbrev = rb_funcall(abbrev, rb_intern("downcase"), 0); + VALUE paths = rb_funcall(scanner, rb_intern("paths"), 0); + for (long i = 0, max = RARRAY_LEN(paths); i < max; i++) + { + VALUE path = RARRAY_PTR(paths)[i]; + VALUE match = rb_funcall(cCommandTMatch, rb_intern("new"), 3, path, abbrev, options); + if (rb_funcall(match, rb_intern("matches?"), 0) == Qtrue) + rb_funcall(matches, rb_intern("push"), 1, match); + } + return matches; +} diff --git a/vim/tmp/command_t/ruby/command-t/matcher.h b/vim/tmp/command_t/ruby/command-t/matcher.h new file mode 100644 index 0000000..6207e37 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/matcher.h @@ -0,0 +1,30 @@ +// Copyright 2010 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. + +#include + +extern VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self); +extern VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options); + +// most likely the function will be subsumed by the sorted_matcher_for function +extern VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev); diff --git a/vim/tmp/command_t/ruby/command-t/prompt.rb b/vim/tmp/command_t/ruby/command-t/prompt.rb new file mode 100644 index 0000000..743e873 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/prompt.rb @@ -0,0 +1,165 @@ +# Copyright 2010 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. + +module CommandT + # Abuse the status line as a prompt. + class Prompt + attr_accessor :abbrev + + def initialize + @abbrev = '' # abbreviation entered so far + @col = 0 # cursor position + @has_focus = false + end + + # Erase whatever is displayed in the prompt line, + # effectively disposing of the prompt + def dispose + ::VIM::command 'echo' + ::VIM::command 'redraw' + end + + # Clear any entered text. + def clear! + @abbrev = '' + @col = 0 + redraw + end + + # Insert a character at (before) the current cursor position. + def add! char + left, cursor, right = abbrev_segments + @abbrev = left + char + cursor + right + @col += 1 + redraw + end + + # Delete a character to the left of the current cursor position. + def backspace! + if @col > 0 + left, cursor, right = abbrev_segments + @abbrev = left.chop! + cursor + right + @col -= 1 + redraw + end + end + + # Delete a character at the current cursor position. + def delete! + if @col < @abbrev.length + left, cursor, right = abbrev_segments + @abbrev = left + right + redraw + end + end + + def cursor_left + if @col > 0 + @col -= 1 + redraw + end + end + + def cursor_right + if @col < @abbrev.length + @col += 1 + redraw + end + end + + def cursor_end + if @col < @abbrev.length + @col = @abbrev.length + redraw + end + end + + def cursor_start + if @col != 0 + @col = 0 + redraw + end + end + + def redraw + if @has_focus + prompt_highlight = 'Comment' + normal_highlight = 'None' + cursor_highlight = 'Underlined' + else + prompt_highlight = 'NonText' + normal_highlight = 'NonText' + cursor_highlight = 'NonText' + end + left, cursor, right = abbrev_segments + components = [prompt_highlight, '>>', 'None', ' '] + components += [normal_highlight, left] unless left.empty? + components += [cursor_highlight, cursor] unless cursor.empty? + components += [normal_highlight, right] unless right.empty? + components += [cursor_highlight, ' '] if cursor.empty? + set_status *components + end + + def focus + unless @has_focus + @has_focus = true + redraw + end + end + + def unfocus + if @has_focus + @has_focus = false + redraw + end + end + + private + + # Returns the @abbrev string divided up into three sections, any of + # which may actually be zero width, depending on the location of the + # cursor: + # - left segment (to left of cursor) + # - cursor segment (character at cursor) + # - right segment (to right of cursor) + def abbrev_segments + left = @abbrev[0, @col] + cursor = @abbrev[@col, 1] + right = @abbrev[(@col + 1)..-1] || '' + [left, cursor, right] + end + + def set_status *args + # see ':help :echo' for why forcing a redraw here helps + # prevent the status line from getting inadvertantly cleared + # after our echo commands + ::VIM::command 'redraw' + while (highlight = args.shift) and (text = args.shift) do + text = VIM::escape_for_single_quotes text + ::VIM::command "echohl #{highlight}" + ::VIM::command "echon '#{text}'" + end + ::VIM::command 'echohl None' + end + end # class Prompt +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/ruby_compat.h b/vim/tmp/command_t/ruby/command-t/ruby_compat.h new file mode 100644 index 0000000..e7960a2 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/ruby_compat.h @@ -0,0 +1,49 @@ +// Copyright 2010 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. + +#include + +// for compatibility with older versions of Ruby which don't declare RSTRING_PTR +#ifndef RSTRING_PTR +#define RSTRING_PTR(s) (RSTRING(s)->ptr) +#endif + +// for compatibility with older versions of Ruby which don't declare RSTRING_LEN +#ifndef RSTRING_LEN +#define RSTRING_LEN(s) (RSTRING(s)->len) +#endif + +// for compatibility with older versions of Ruby which don't declare RARRAY_PTR +#ifndef RARRAY_PTR +#define RARRAY_PTR(a) (RARRAY(a)->ptr) +#endif + +// for compatibility with older versions of Ruby which don't declare RARRAY_LEN +#ifndef RARRAY_LEN +#define RARRAY_LEN(a) (RARRAY(a)->len) +#endif + +// for compatibility with older versions of Ruby which don't declare RFLOAT_VALUE +#ifndef RFLOAT_VALUE +#define RFLOAT_VALUE(f) (RFLOAT(f)->value) +#endif diff --git a/vim/tmp/command_t/ruby/command-t/scanner.rb b/vim/tmp/command_t/ruby/command-t/scanner.rb new file mode 100644 index 0000000..5e5e3c9 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/scanner.rb @@ -0,0 +1,28 @@ +# Copyright 2010-2011 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' + +module CommandT + class Scanner; end +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/scanner/buffer_scanner.rb b/vim/tmp/command_t/ruby/command-t/scanner/buffer_scanner.rb new file mode 100644 index 0000000..aa85497 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/scanner/buffer_scanner.rb @@ -0,0 +1,42 @@ +# Copyright 2010-2011 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/vim/path_utilities' +require 'command-t/scanner' + +module CommandT + # Returns a list of all open buffers. + class BufferScanner < Scanner + include VIM::PathUtilities + + def paths + (0..(::VIM::Buffer.count - 1)).map do |n| + buffer = ::VIM::Buffer[n] + if buffer.name # beware, may be nil + relative_path_under_working_directory buffer.name + end + end.compact + end + end # class BufferScanner +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/scanner/file_scanner.rb b/vim/tmp/command_t/ruby/command-t/scanner/file_scanner.rb new file mode 100644 index 0000000..4ea15c8 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/scanner/file_scanner.rb @@ -0,0 +1,94 @@ +# Copyright 2010-2011 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 + # Reads the current directory recursively for the paths to all regular files. + class FileScanner < Scanner + class FileLimitExceeded < ::RuntimeError; end + + def initialize path = Dir.pwd, options = {} + @path = path + @max_depth = options[:max_depth] || 15 + @max_files = options[:max_files] || 10_000 + @scan_dot_directories = options[:scan_dot_directories] || false + end + + def paths + return @paths unless @paths.nil? + begin + @paths = [] + @depth = 0 + @files = 0 + @prefix_len = @path.chomp('/').length + add_paths_for_directory @path, @paths + rescue FileLimitExceeded + end + @paths + end + + def flush + @paths = nil + end + + def path= str + if @path != str + @path = str + flush + end + end + + private + + def path_excluded? path + # first strip common prefix (@path) from path to match VIM's behavior + path = path[(@prefix_len + 1)..-1] + path = VIM::escape_for_single_quotes path + ::VIM::evaluate("empty(expand(fnameescape('#{path}')))").to_i == 1 + end + + def add_paths_for_directory dir, accumulator + Dir.foreach(dir) do |entry| + next if ['.', '..'].include?(entry) + path = File.join(dir, entry) + unless path_excluded?(path) + if File.file?(path) + @files += 1 + raise FileLimitExceeded if @files > @max_files + accumulator << path[@prefix_len + 1..-1] + elsif File.directory?(path) + next if @depth >= @max_depth + next if (entry.match(/\A\./) && !@scan_dot_directories) + @depth += 1 + add_paths_for_directory path, accumulator + @depth -= 1 + end + end + end + rescue Errno::EACCES + # skip over directories for which we don't have access + end + end # class FileScanner +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/settings.rb b/vim/tmp/command_t/ruby/command-t/settings.rb new file mode 100644 index 0000000..c15016a --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/settings.rb @@ -0,0 +1,77 @@ +# Copyright 2010 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. + +module CommandT + # Convenience class for saving and restoring global settings. + class Settings + def initialize + save + end + + def save + @timeoutlen = get_number 'timeoutlen' + @report = get_number 'report' + @sidescroll = get_number 'sidescroll' + @sidescrolloff = get_number 'sidescrolloff' + @timeout = get_bool 'timeout' + @equalalways = get_bool 'equalalways' + @hlsearch = get_bool 'hlsearch' + @insertmode = get_bool 'insertmode' + @showcmd = get_bool 'showcmd' + end + + def restore + set_number 'timeoutlen', @timeoutlen + set_number 'report', @report + set_number 'sidescroll', @sidescroll + set_number 'sidescrolloff', @sidescrolloff + set_bool 'timeout', @timeout + set_bool 'equalalways', @equalalways + set_bool 'hlsearch', @hlsearch + set_bool 'insertmode', @insertmode + set_bool 'showcmd', @showcmd + end + + private + + def get_number setting + ::VIM::evaluate("&#{setting}").to_i + end + + def get_bool setting + ::VIM::evaluate("&#{setting}").to_i == 1 + end + + def set_number setting, value + ::VIM::set_option "#{setting}=#{value}" + end + + def set_bool setting, value + if value + ::VIM::set_option setting + else + ::VIM::set_option "no#{setting}" + end + end + end # class Settings +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/stub.rb b/vim/tmp/command_t/ruby/command-t/stub.rb new file mode 100644 index 0000000..6e8b074 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/stub.rb @@ -0,0 +1,46 @@ +# Copyright 2010-2011 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. + +module CommandT + class Stub + @@load_error = ['command-t.vim could not load the C extension', + 'Please see INSTALLATION and TROUBLE-SHOOTING in the help', + 'For more information type: :help command-t'] + + def show_file_finder + warn *@@load_error + end + + def flush + warn *@@load_error + end + + private + + def warn *msg + ::VIM::command 'echohl WarningMsg' + msg.each { |m| ::VIM::command "echo '#{m}'" } + ::VIM::command 'echohl none' + end + end # class Stub +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/vim.rb b/vim/tmp/command_t/ruby/command-t/vim.rb new file mode 100644 index 0000000..b4e40fc --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/vim.rb @@ -0,0 +1,43 @@ +# Copyright 2010 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/screen' +require 'command-t/vim/window' + +module CommandT + module VIM + def self.has_syntax? + ::VIM::evaluate('has("syntax")').to_i != 0 + end + + def self.pwd + ::VIM::evaluate 'getcwd()' + end + + # Escape a string for safe inclusion in a Vim single-quoted string + # (single quotes escaped by doubling, everything else is literal) + def self.escape_for_single_quotes str + str.gsub "'", "''" + end + end # module VIM +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/vim/path_utilities.rb b/vim/tmp/command_t/ruby/command-t/vim/path_utilities.rb new file mode 100644 index 0000000..8564300 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/vim/path_utilities.rb @@ -0,0 +1,40 @@ +# Copyright 2010-2011 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' + +module CommandT + module VIM + module PathUtilities + + private + + def relative_path_under_working_directory path + # any path under the working directory will be specified as a relative + # path to improve the readability of the buffer list etc + pwd = File.expand_path(VIM::pwd) + '/' + path.index(pwd) == 0 ? path[pwd.length..-1] : path + end + end # module PathUtilities + end # module VIM +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/vim/screen.rb b/vim/tmp/command_t/ruby/command-t/vim/screen.rb new file mode 100644 index 0000000..fb7ba33 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/vim/screen.rb @@ -0,0 +1,32 @@ +# Copyright 2010 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. + +module CommandT + module VIM + module Screen + def self.lines + ::VIM::evaluate('&lines').to_i + end + end # module Screen + end # module VIM +end # module CommandT diff --git a/vim/tmp/command_t/ruby/command-t/vim/window.rb b/vim/tmp/command_t/ruby/command-t/vim/window.rb new file mode 100644 index 0000000..1e53d56 --- /dev/null +++ b/vim/tmp/command_t/ruby/command-t/vim/window.rb @@ -0,0 +1,38 @@ +# Copyright 2010 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. + +module CommandT + module VIM + class Window + def self.select window + return true if $curwin == window + initial = $curwin + while true do + ::VIM::command 'wincmd w' # cycle through windows + return true if $curwin == window # have selected desired window + return false if $curwin == initial # have already looped through all + end + end + end # class Window + end # module VIM +end # module CommandT diff --git a/vim/tmp/conque/autoload/conque_term.vim b/vim/tmp/conque/autoload/conque_term.vim new file mode 100644 index 0000000..2780c7d --- /dev/null +++ b/vim/tmp/conque/autoload/conque_term.vim @@ -0,0 +1,1590 @@ +" FILE: plugin/conque_term.vim {{{ +" +" AUTHOR: Nico Raffo +" MODIFIED: 2010-05-27 +" VERSION: 1.1, for Vim 7.0 +" LICENSE: +" Conque - pty interaction in Vim +" Copyright (C) 2009-2010 Nico Raffo +" +" MIT License +" +" Permission is hereby granted, free of charge, to any person obtaining a copy +" of this software and associated documentation files (the "Software"), to deal +" in the Software without restriction, including without limitation the rights +" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +" copies of the Software, and to permit persons to whom the Software is +" furnished to do so, subject to the following conditions: +" +" The above copyright notice and this permission notice shall be included in +" all copies or substantial portions of the Software. +" +" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +" THE SOFTWARE. +" }}} + + +" ********************************************************************************************************** +" **** VIM FUNCTIONS *************************************************************************************** +" ********************************************************************************************************** + +" launch conque +function! conque_term#open(...) "{{{ + let command = get(a:000, 0, '') + let hooks = get(a:000, 1, []) + + " bare minimum validation + if has('python') != 1 + echohl WarningMsg | echomsg "Conque requires the Python interface to be installed" | echohl None + return 0 + endif + if empty(command) + echohl WarningMsg | echomsg "No command found" | echohl None + return 0 + else + let l:cargs = split(command, '\s') + if !executable(l:cargs[0]) + echohl WarningMsg | echomsg "Not an executable: " . l:cargs[0] | echohl None + return 0 + endif + endif + + " set buffer window options + let g:ConqueTerm_BufName = substitute(command, ' ', '\\ ', 'g') . "\\ -\\ " . g:ConqueTerm_Idx + call conque_term#set_buffer_settings(command, hooks) + let b:ConqueTerm_Var = 'ConqueTerm_' . g:ConqueTerm_Idx + let g:ConqueTerm_Var = 'ConqueTerm_' . g:ConqueTerm_Idx + let g:ConqueTerm_Idx += 1 + + " open command + try + let l:config = '{"color":' . string(g:ConqueTerm_Color) . ',"TERM":"' . g:ConqueTerm_TERM . '"}' + execute 'python ' . b:ConqueTerm_Var . ' = Conque()' + execute "python " . b:ConqueTerm_Var . ".open('" . conque_term#python_escape(command) . "', " . l:config . ")" + catch + echohl WarningMsg | echomsg "Unable to open command: " . command | echohl None + return 0 + endtry + + " set buffer mappings and auto commands + call conque_term#set_mappings('start') + + startinsert! + return 1 +endfunction "}}} + +" set buffer options +function! conque_term#set_buffer_settings(command, pre_hooks) "{{{ + + " optional hooks to execute, e.g. 'split' + for h in a:pre_hooks + sil exe h + endfor + sil exe "edit " . g:ConqueTerm_BufName + + " buffer settings + setlocal nocompatible " conque won't work in compatible mode + setlocal nopaste " conque won't work in paste mode + setlocal buftype=nofile " this buffer is not a file, you can't save it + setlocal nonumber " hide line numbers + setlocal foldcolumn=0 " reasonable left margin + setlocal nowrap " default to no wrap (esp with MySQL) + setlocal noswapfile " don't bother creating a .swp file + setlocal updatetime=50 " trigger cursorhold event after 50ms / XXX - global + setlocal scrolloff=0 " don't use buffer lines. it makes the 'clear' command not work as expected + setlocal sidescrolloff=0 " don't use buffer lines. it makes the 'clear' command not work as expected + setlocal sidescroll=1 " don't use buffer lines. it makes the 'clear' command not work as expected + setlocal foldmethod=manual " don't fold on {{{}}} and stuff + setlocal bufhidden=hide " when buffer is no longer displayed, don't wipe it out + setfiletype conque_term " useful + sil exe "setlocal syntax=" . g:ConqueTerm_Syntax + +endfunction " }}} + +" set key mappings and auto commands +function! conque_term#set_mappings(action) "{{{ + + " set action + if a:action == 'toggle' + if exists('b:conque_on') && b:conque_on == 1 + let l:action = 'stop' + echohl WarningMsg | echomsg "Terminal is paused" | echohl None + else + let l:action = 'start' + echohl WarningMsg | echomsg "Terminal is resumed" | echohl None + endif + else + let l:action = a:action + endif + + " if mappings are being removed, add 'un' + let map_modifier = 'nore' + if l:action == 'stop' + let map_modifier = 'un' + endif + + " remove all auto commands + if l:action == 'stop' + execute 'autocmd! ' . b:ConqueTerm_Var + + else + execute 'augroup ' . b:ConqueTerm_Var + + " handle unexpected closing of shell, passes HUP to parent and all child processes + execute 'autocmd ' . b:ConqueTerm_Var . ' BufUnload python ' . b:ConqueTerm_Var . '.proc.signal(1)' + + " check for resized/scrolled buffer when entering buffer + execute 'autocmd ' . b:ConqueTerm_Var . ' BufEnter python ' . b:ConqueTerm_Var . '.update_window_size()' + execute 'autocmd ' . b:ConqueTerm_Var . ' VimResized python ' . b:ConqueTerm_Var . '.update_window_size()' + + " set/reset updatetime on entering/exiting buffer + autocmd BufEnter set updatetime=50 + autocmd BufLeave set updatetime=2000 + + " check for resized/scrolled buffer when entering insert mode + " XXX - messed up since we enter insert mode at each updatetime + "execute 'autocmd InsertEnter python ' . b:ConqueTerm_Var . '.screen.align()' + + " read more output when this isn't the current buffer + if g:ConqueTerm_ReadUnfocused == 1 + execute 'autocmd ' . b:ConqueTerm_Var . ' CursorHold * call conque_term#read_all()' + endif + + " poll for more output + sil execute 'autocmd ' . b:ConqueTerm_Var . ' CursorHoldI python ' . b:ConqueTerm_Var . '.auto_read()' + endif + + " use F22 key to get more input + if l:action == 'start' + sil exe 'i' . map_modifier . 'map "\\"' + sil exe 'i' . map_modifier . 'map "\\"' + else + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + endif + + " map ASCII 1-31 + for c in range(1, 31) + " + if c == 27 + continue + endif + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(' . c . '))' + else + sil exe 'i' . map_modifier . 'map ' + endif + endfor + if l:action == 'start' + sil exe 'n' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(3))' + else + sil exe 'n' . map_modifier . 'map ' + endif + + " leave insert mode + if !exists('g:ConqueTerm_EscKey') || g:ConqueTerm_EscKey == '' + " use to send to terminal + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(27))' + else + sil exe 'i' . map_modifier . 'map ' + endif + else + " use to send to terminal + if l:action == 'start' + sil exe 'i' . map_modifier . 'map ' . g:ConqueTerm_EscKey . ' ' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(chr(27))' + else + sil exe 'i' . map_modifier . 'map ' . g:ConqueTerm_EscKey + sil exe 'i' . map_modifier . 'map ' + endif + endif + + " Map in insert mode + if exists('g:ConqueTerm_CWInsert') && g:ConqueTerm_CWInsert == 1 + inoremap j j + inoremap k k + inoremap h h + inoremap l l + inoremap w w + endif + + " map ASCII 33-127 + for i in range(33, 127) + " + if i == 124 + if l:action == 'start' + sil exe "i" . map_modifier . "map :python " . b:ConqueTerm_Var . ".write(chr(124))" + else + sil exe "i" . map_modifier . "map " + endif + continue + endif + if l:action == 'start' + sil exe "i" . map_modifier . "map " . nr2char(i) . " :python " . b:ConqueTerm_Var . ".write(chr(" . i . "))" + else + sil exe "i" . map_modifier . "map " . nr2char(i) + endif + endfor + + " map ASCII 128-255 + for i in range(128, 255) + if l:action == 'start' + sil exe "i" . map_modifier . "map " . nr2char(i) . " :python " . b:ConqueTerm_Var . ".write('" . nr2char(i) . "')" + else + sil exe "i" . map_modifier . "map " . nr2char(i) + endif + endfor + + " Special cases + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u0008")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(" ")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[A")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[B")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[C")' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . '.write(u"\u001b[D")' + else + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + sil exe 'i' . map_modifier . 'map ' + endif + + " send selected text into conque + if l:action == 'start' + sil exe 'v' . map_modifier . 'map :call conque_term#send_selected(visualmode())' + else + sil exe 'v' . map_modifier . 'map ' + endif + + " remap paste keys + if l:action == 'start' + sil exe 'n' . map_modifier . 'map p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + sil exe 'n' . map_modifier . 'map P :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + sil exe 'n' . map_modifier . 'map ]p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + sil exe 'n' . map_modifier . 'map [p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))a' + else + sil exe 'n' . map_modifier . 'map p' + sil exe 'n' . map_modifier . 'map P' + sil exe 'n' . map_modifier . 'map ]p' + sil exe 'n' . map_modifier . 'map [p' + endif + if has('gui_running') + if l:action == 'start' + sil exe 'i' . map_modifier . 'map :python ' . b:ConqueTerm_Var . ".write(vim.eval('@+'))a" + else + sil exe 'i' . map_modifier . 'map ' + endif + endif + + " disable other normal mode keys which insert text + if l:action == 'start' + sil exe 'n' . map_modifier . 'map r :echo "Replace mode disabled in shell."' + sil exe 'n' . map_modifier . 'map R :echo "Replace mode disabled in shell."' + sil exe 'n' . map_modifier . 'map c :echo "Change mode disabled in shell."' + sil exe 'n' . map_modifier . 'map C :echo "Change mode disabled in shell."' + sil exe 'n' . map_modifier . 'map s :echo "Change mode disabled in shell."' + sil exe 'n' . map_modifier . 'map S :echo "Change mode disabled in shell."' + else + sil exe 'n' . map_modifier . 'map r' + sil exe 'n' . map_modifier . 'map R' + sil exe 'n' . map_modifier . 'map c' + sil exe 'n' . map_modifier . 'map C' + sil exe 'n' . map_modifier . 'map s' + sil exe 'n' . map_modifier . 'map S' + endif + + " set conque as on or off + if l:action == 'start' + let b:conque_on = 1 + else + let b:conque_on = 0 + endif + + " map command to start stop the shell + if a:action == 'start' + nnoremap :call conque_term#set_mappings('toggle') + endif + +endfunction " }}} + + +" send selected text from another buffer +function! conque_term#send_selected(type) "{{{ + let reg_save = @@ + + " save user's sb settings + let sb_save = &switchbuf + set switchbuf=usetab + + " yank current selection + sil exe "normal! `<" . a:type . "`>y" + + " format yanked text + let @@ = substitute(@@, '^[\r\n]*', '', '') + let @@ = substitute(@@, '[\r\n]*$', '', '') + + " execute yanked text + sil exe ":sb " . g:ConqueTerm_BufName + sil exe 'python ' . g:ConqueTerm_Var . '.paste_selection()' + + " reset original values + let @@ = reg_save + sil exe 'set switchbuf=' . sb_save + + " scroll buffer left + startinsert! + normal 0zH +endfunction "}}} + +" read from all known conque buffers +function! conque_term#read_all() "{{{ + " don't run this if we're in a conque buffer + if exists('b:ConqueTerm_Var') + return + endif + + try + for i in range(1, g:ConqueTerm_Idx - 1) + execute 'python ConqueTerm_' . string(i) . '.read(1)' + endfor + catch + " probably a deleted buffer + endtry + + " restart updatetime + call feedkeys("f\e") +endfunction "}}} + +" util function to add enough \s to pass a string to python +function! conque_term#python_escape(input) "{{{ + let l:cleaned = a:input + let l:cleaned = substitute(l:cleaned, '\\', '\\\\', 'g') + let l:cleaned = substitute(l:cleaned, '\n', '\\n', 'g') + let l:cleaned = substitute(l:cleaned, '\r', '\\r', 'g') + let l:cleaned = substitute(l:cleaned, "'", "\\\\'", 'g') + return l:cleaned +endfunction "}}} + +" ********************************************************************************************************** +" **** PYTHON ********************************************************************************************** +" ********************************************************************************************************** + +if has('python') + +python << EOF + +import vim, re, time, math + +# CONFIG CONSTANTS {{{ + +CONQUE_CTL = { + 7:'bel', # bell + 8:'bs', # backspace + 9:'tab', # tab + 10:'nl', # new line + 13:'cr' # carriage return +} +# 11 : 'vt', # vertical tab +# 12 : 'ff', # form feed +# 14 : 'so', # shift out +# 15 : 'si' # shift in + +# Escape sequences +CONQUE_ESCAPE = { + 'm':'font', + 'J':'clear_screen', + 'K':'clear_line', + '@':'add_spaces', + 'A':'cursor_up', + 'B':'cursor_down', + 'C':'cursor_right', + 'D':'cursor_left', + 'G':'cursor_to_column', + 'H':'cursor', + 'P':'delete_chars', + 'f':'cursor', + 'g':'tab_clear', + 'r':'set_coords', + 'h':'set', + 'l':'reset' +} +# 'L':'insert_lines', +# 'M':'delete_lines', +# 'd':'cusor_vpos', + +# Alternate escape sequences, no [ +CONQUE_ESCAPE_PLAIN = { + 'D':'scroll_up', + 'E':'next_line', + 'H':'set_tab', + 'M':'scroll_down' +} +# 'N':'single_shift_2', +# 'O':'single_shift_3', +# '=':'alternate_keypad', +# '>':'numeric_keypad', +# '7':'save_cursor', +# '8':'restore_cursor', + +# Uber alternate escape sequences, with # or ? +CONQUE_ESCAPE_QUESTION = { + '1h':'new_line_mode', + '3h':'132_cols', + '4h':'smooth_scrolling', + '5h':'reverse_video', + '6h':'relative_origin', + '7h':'set_auto_wrap', + '8h':'set_auto_repeat', + '9h':'set_interlacing_mode', + '1l':'set_cursor_key', + '2l':'set_vt52', + '3l':'80_cols', + '4l':'set_jump_scrolling', + '5l':'normal_video', + '6l':'absolute_origin', + '7l':'reset_auto_wrap', + '8l':'reset_auto_repeat', + '9l':'reset_interlacing_mode' +} + +CONQUE_ESCAPE_HASH = { + '8':'screen_alignment_test' +} +# '3':'double_height_top', +# '4':'double_height_bottom', +# '5':'single_height_single_width', +# '6':'single_height_double_width', + +# Font codes {{{ +CONQUE_FONT = { + 0: {'description':'Normal (default)', 'attributes': {'cterm':'NONE','ctermfg':'NONE','ctermbg':'NONE','gui':'NONE','guifg':'NONE','guibg':'NONE'}, 'normal':True}, + 1: {'description':'Bold', 'attributes': {'cterm':'BOLD','gui':'BOLD'}, 'normal':False}, + 4: {'description':'Underlined', 'attributes': {'cterm':'UNDERLINE','gui':'UNDERLINE'}, 'normal':False}, + 5: {'description':'Blink (appears as Bold)', 'attributes': {'cterm':'BOLD','gui':'BOLD'}, 'normal':False}, + 7: {'description':'Inverse', 'attributes': {'cterm':'REVERSE','gui':'REVERSE'}, 'normal':False}, + 8: {'description':'Invisible (hidden)', 'attributes': {'ctermfg':'0','ctermbg':'0','guifg':'#000000','guibg':'#000000'}, 'normal':False}, + 22: {'description':'Normal (neither bold nor faint)', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 24: {'description':'Not underlined', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 25: {'description':'Steady (not blinking)', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 27: {'description':'Positive (not inverse)', 'attributes': {'cterm':'NONE','gui':'NONE'}, 'normal':True}, + 28: {'description':'Visible (not hidden)', 'attributes': {'ctermfg':'NONE','ctermbg':'NONE','guifg':'NONE','guibg':'NONE'}, 'normal':True}, + 30: {'description':'Set foreground color to Black', 'attributes': {'ctermfg':'16','guifg':'#000000'}, 'normal':False}, + 31: {'description':'Set foreground color to Red', 'attributes': {'ctermfg':'1','guifg':'#ff0000'}, 'normal':False}, + 32: {'description':'Set foreground color to Green', 'attributes': {'ctermfg':'2','guifg':'#00ff00'}, 'normal':False}, + 33: {'description':'Set foreground color to Yellow', 'attributes': {'ctermfg':'3','guifg':'#ffff00'}, 'normal':False}, + 34: {'description':'Set foreground color to Blue', 'attributes': {'ctermfg':'4','guifg':'#0000ff'}, 'normal':False}, + 35: {'description':'Set foreground color to Magenta', 'attributes': {'ctermfg':'5','guifg':'#990099'}, 'normal':False}, + 36: {'description':'Set foreground color to Cyan', 'attributes': {'ctermfg':'6','guifg':'#009999'}, 'normal':False}, + 37: {'description':'Set foreground color to White', 'attributes': {'ctermfg':'7','guifg':'#ffffff'}, 'normal':False}, + 39: {'description':'Set foreground color to default (original)', 'attributes': {'ctermfg':'NONE','guifg':'NONE'}, 'normal':True}, + 40: {'description':'Set background color to Black', 'attributes': {'ctermbg':'16','guibg':'#000000'}, 'normal':False}, + 41: {'description':'Set background color to Red', 'attributes': {'ctermbg':'1','guibg':'#ff0000'}, 'normal':False}, + 42: {'description':'Set background color to Green', 'attributes': {'ctermbg':'2','guibg':'#00ff00'}, 'normal':False}, + 43: {'description':'Set background color to Yellow', 'attributes': {'ctermbg':'3','guibg':'#ffff00'}, 'normal':False}, + 44: {'description':'Set background color to Blue', 'attributes': {'ctermbg':'4','guibg':'#0000ff'}, 'normal':False}, + 45: {'description':'Set background color to Magenta', 'attributes': {'ctermbg':'5','guibg':'#990099'}, 'normal':False}, + 46: {'description':'Set background color to Cyan', 'attributes': {'ctermbg':'6','guibg':'#009999'}, 'normal':False}, + 47: {'description':'Set background color to White', 'attributes': {'ctermbg':'7','guibg':'#ffffff'}, 'normal':False}, + 49: {'description':'Set background color to default (original).', 'attributes': {'ctermbg':'NONE','guibg':'NONE'}, 'normal':True}, + 90: {'description':'Set foreground color to Black', 'attributes': {'ctermfg':'8','guifg':'#000000'}, 'normal':False}, + 91: {'description':'Set foreground color to Red', 'attributes': {'ctermfg':'9','guifg':'#ff0000'}, 'normal':False}, + 92: {'description':'Set foreground color to Green', 'attributes': {'ctermfg':'10','guifg':'#00ff00'}, 'normal':False}, + 93: {'description':'Set foreground color to Yellow', 'attributes': {'ctermfg':'11','guifg':'#ffff00'}, 'normal':False}, + 94: {'description':'Set foreground color to Blue', 'attributes': {'ctermfg':'12','guifg':'#0000ff'}, 'normal':False}, + 95: {'description':'Set foreground color to Magenta', 'attributes': {'ctermfg':'13','guifg':'#990099'}, 'normal':False}, + 96: {'description':'Set foreground color to Cyan', 'attributes': {'ctermfg':'14','guifg':'#009999'}, 'normal':False}, + 97: {'description':'Set foreground color to White', 'attributes': {'ctermfg':'15','guifg':'#ffffff'}, 'normal':False}, + 100: {'description':'Set background color to Black', 'attributes': {'ctermbg':'8','guibg':'#000000'}, 'normal':False}, + 101: {'description':'Set background color to Red', 'attributes': {'ctermbg':'9','guibg':'#ff0000'}, 'normal':False}, + 102: {'description':'Set background color to Green', 'attributes': {'ctermbg':'10','guibg':'#00ff00'}, 'normal':False}, + 103: {'description':'Set background color to Yellow', 'attributes': {'ctermbg':'11','guibg':'#ffff00'}, 'normal':False}, + 104: {'description':'Set background color to Blue', 'attributes': {'ctermbg':'12','guibg':'#0000ff'}, 'normal':False}, + 105: {'description':'Set background color to Magenta', 'attributes': {'ctermbg':'13','guibg':'#990099'}, 'normal':False}, + 106: {'description':'Set background color to Cyan', 'attributes': {'ctermbg':'14','guibg':'#009999'}, 'normal':False}, + 107: {'description':'Set background color to White', 'attributes': {'ctermbg':'15','guibg':'#ffffff'}, 'normal':False} +} +# }}} + +# regular expression matching (almost) all control sequences +CONQUE_SEQ_REGEX = re.compile(ur"(\u001b\[?\??#?[0-9;]*[a-zA-Z@]|\u001b\][0-9];.*?\u0007|[\u0007-\u000f])", re.UNICODE) +CONQUE_SEQ_REGEX_CTL = re.compile(ur"^[\u0007-\u000f]$", re.UNICODE) +CONQUE_SEQ_REGEX_CSI = re.compile(ur"^\u001b\[", re.UNICODE) +CONQUE_SEQ_REGEX_TITLE = re.compile(ur"^\u001b\]", re.UNICODE) +CONQUE_SEQ_REGEX_HASH = re.compile(ur"^\u001b#", re.UNICODE) +CONQUE_SEQ_REGEX_ESC = re.compile(ur"^\u001b", re.UNICODE) + +# match table output +CONQUE_TABLE_OUTPUT = re.compile("^\s*\|\s.*\s\|\s*$|^\s*\+[=+-]+\+\s*$") + +# }}} + +################################################################################################### +class Conque: + + # CLASS PROPERTIES {{{ + + # screen object + screen = None + + # subprocess object + proc = None + + # terminal dimensions and scrolling region + columns = 80 # same as $COLUMNS + lines = 24 # same as $LINES + working_columns = 80 # can be changed by CSI ? 3 l/h + working_lines = 24 # can be changed by CSI r + + # top/bottom of the scroll region + top = 1 # relative to top of screen + bottom = 24 # relative to top of screen + + # cursor position + l = 1 # current cursor line + c = 1 # current cursor column + + # autowrap mode + autowrap = True + + # absolute coordinate mode + absolute_coords = True + + # tabstop positions + tabstops = [] + + # enable colors + enable_colors = True + + # color changes + color_changes = {} + + # color history + color_history = {} + + # don't wrap table output + unwrap_tables = True + + # wrap CUF/CUB around line breaks + wrap_cursor = False + + # }}} + + # constructor + def __init__(self): # {{{ + self.screen = ConqueScreen() + # }}} + + # start program and initialize this instance + def open(self, command, options): # {{{ + + # int vars + self.columns = vim.current.window.width + self.lines = vim.current.window.height + self.working_columns = vim.current.window.width + self.working_lines = vim.current.window.height + self.bottom = vim.current.window.height + + # init color + self.enable_colors = options['color'] + + # init tabstops + self.init_tabstops() + + # open command + self.proc = ConqueSubprocess() + self.proc.open(command, { 'TERM' : options['TERM'], 'CONQUE' : '1', 'LINES' : str(self.lines), 'COLUMNS' : str(self.columns)}) + # }}} + + # write to pty + def write(self, input): # {{{ + + + # check if window size has changed + self.update_window_size() + + # write and read + self.proc.write(input) + self.read(1) + # }}} + + # read from pty, and update buffer + def read(self, timeout = 1): # {{{ + # read from subprocess + output = self.proc.read(timeout) + # and strip null chars + output = output.replace(chr(0), '') + + if output == '': + return + + + + + + chunks = CONQUE_SEQ_REGEX.split(output) + + + + + + # don't go through all the csi regex if length is one (no matches) + if len(chunks) == 1: + + self.plain_text(chunks[0]) + + else: + for s in chunks: + if s == '': + continue + + + + + + + # Check for control character match {{{ + if CONQUE_SEQ_REGEX_CTL.match(s[0]): + + nr = ord(s[0]) + if nr in CONQUE_CTL: + getattr(self, 'ctl_' + CONQUE_CTL[nr])() + else: + + pass + # }}} + + # check for escape sequence match {{{ + elif CONQUE_SEQ_REGEX_CSI.match(s): + + if s[-1] in CONQUE_ESCAPE: + csi = self.parse_csi(s[2:]) + + getattr(self, 'csi_' + CONQUE_ESCAPE[s[-1]])(csi) + else: + + pass + # }}} + + # check for title match {{{ + elif CONQUE_SEQ_REGEX_TITLE.match(s): + + self.change_title(s[2], s[4:-1]) + # }}} + + # check for hash match {{{ + elif CONQUE_SEQ_REGEX_HASH.match(s): + + if s[-1] in CONQUE_ESCAPE_HASH: + getattr(self, 'hash_' + CONQUE_ESCAPE_HASH[s[-1]])() + else: + + pass + # }}} + + # check for other escape match {{{ + elif CONQUE_SEQ_REGEX_ESC.match(s): + + if s[-1] in CONQUE_ESCAPE_PLAIN: + getattr(self, 'esc_' + CONQUE_ESCAPE_PLAIN[s[-1]])() + else: + + pass + # }}} + + # else process plain text {{{ + else: + self.plain_text(s) + # }}} + + # set cursor position + self.screen.set_cursor(self.l, self.c) + + vim.command('redraw') + + + # }}} + + # for polling + def auto_read(self): # {{{ + self.read(1) + if self.c == 1: + vim.command('call feedkeys("\", "t")') + else: + vim.command('call feedkeys("\", "t")') + self.screen.set_cursor(self.l, self.c) + # }}} + + ############################################################################################### + # Plain text # {{{ + + def plain_text(self, input): + + current_line = self.screen[self.l] + + if len(current_line) < self.working_columns: + current_line = current_line + ' ' * (self.c - len(current_line)) + + # if line is wider than screen + if self.c + len(input) - 1 > self.working_columns: + # Table formatting hack + if self.unwrap_tables and CONQUE_TABLE_OUTPUT.match(input): + self.screen[self.l] = current_line[ : self.c - 1] + input + current_line[ self.c + len(input) - 1 : ] + self.apply_color(self.c, self.c + len(input)) + self.c += len(input) + return + + diff = self.c + len(input) - self.working_columns - 1 + # if autowrap is enabled + if self.autowrap: + self.screen[self.l] = current_line[ : self.c - 1] + input[ : -1 * diff ] + self.apply_color(self.c, self.working_columns) + self.ctl_nl() + self.ctl_cr() + remaining = input[ -1 * diff : ] + + self.plain_text(remaining) + else: + self.screen[self.l] = current_line[ : self.c - 1] + input[ : -1 * diff - 1 ] + input[-1] + self.apply_color(self.c, self.working_columns) + self.c = self.working_columns + + # no autowrap + else: + self.screen[self.l] = current_line[ : self.c - 1] + input + current_line[ self.c + len(input) - 1 : ] + self.apply_color(self.c, self.c + len(input)) + self.c += len(input) + + def apply_color(self, start, end): + + + # stop here if coloration is disabled + if not self.enable_colors: + return + + real_line = self.screen.get_real_line(self.l) + + # check for previous overlapping coloration + + to_del = [] + if self.color_history.has_key(real_line): + for i in range(len(self.color_history[real_line])): + syn = self.color_history[real_line][i] + + if syn['start'] >= start and syn['start'] < end: + + vim.command('syn clear ' + syn['name']) + to_del.append(i) + # outside + if syn['end'] > end: + + self.exec_highlight(real_line, end, syn['end'], syn['highlight']) + elif syn['end'] > start and syn['end'] <= end: + + vim.command('syn clear ' + syn['name']) + to_del.append(i) + # outside + if syn['start'] < start: + + self.exec_highlight(real_line, syn['start'], start, syn['highlight']) + + if len(to_del) > 0: + to_del.reverse() + for di in to_del: + del self.color_history[real_line][di] + + # if there are no new colors + if len(self.color_changes) == 0: + return + + highlight = '' + for attr in self.color_changes.keys(): + highlight = highlight + ' ' + attr + '=' + self.color_changes[attr] + + # execute the highlight + self.exec_highlight(real_line, start, end, highlight) + + def exec_highlight(self, real_line, start, end, highlight): + unique_key = str(self.proc.pid) + + syntax_name = 'EscapeSequenceAt_' + unique_key + '_' + str(self.l) + '_' + str(start) + '_' + str(len(self.color_history) + 1) + syntax_options = ' contains=ALLBUT,ConqueString,MySQLString,MySQLKeyword oneline' + syntax_region = 'syntax match ' + syntax_name + ' /\%' + str(real_line) + 'l\%>' + str(start - 1) + 'c.*\%<' + str(end + 1) + 'c/' + syntax_options + syntax_highlight = 'highlight ' + syntax_name + highlight + + vim.command(syntax_region) + vim.command(syntax_highlight) + + # add syntax name to history + if not self.color_history.has_key(real_line): + self.color_history[real_line] = [] + + self.color_history[real_line].append({'name':syntax_name, 'start':start, 'end':end, 'highlight':highlight}) + + # }}} + + ############################################################################################### + # Control functions {{{ + + def ctl_nl(self): + # if we're in a scrolling region, scroll instead of moving cursor down + if self.lines != self.working_lines and self.l == self.bottom: + del self.screen[self.top] + self.screen.insert(self.bottom, '') + elif self.l == self.bottom: + self.screen.append('') + else: + self.l += 1 + + self.color_changes = {} + + def ctl_cr(self): + self.c = 1 + + self.color_changes = {} + + def ctl_bs(self): + if self.c > 1: + self.c += -1 + + def ctl_bel(self): + print 'BELL' + + def ctl_tab(self): + # default tabstop location + ts = self.working_columns + + # check set tabstops + for i in range(self.c, len(self.tabstops)): + if self.tabstops[i]: + ts = i + 1 + break + + + + self.c = ts + + # }}} + + ############################################################################################### + # CSI functions {{{ + + def csi_font(self, csi): # {{{ + if not self.enable_colors: + return + + # defaults to 0 + if len(csi['vals']) == 0: + csi['vals'] = [0] + + # 256 xterm color foreground + if len(csi['vals']) == 3 and csi['vals'][0] == 38 and csi['vals'][1] == 5: + self.color_changes['ctermfg'] = str(csi['vals'][2]) + self.color_changes['guifg'] = '#' + self.xterm_to_rgb(csi['vals'][2]) + + # 256 xterm color background + elif len(csi['vals']) == 3 and csi['vals'][0] == 48 and csi['vals'][1] == 5: + self.color_changes['ctermbg'] = str(csi['vals'][2]) + self.color_changes['guibg'] = '#' + self.xterm_to_rgb(csi['vals'][2]) + + # 16 colors + else: + for val in csi['vals']: + if CONQUE_FONT.has_key(val): + + # ignore starting normal colors + if CONQUE_FONT[val]['normal'] and len(self.color_changes) == 0: + + continue + # clear color changes + elif CONQUE_FONT[val]['normal']: + + self.color_changes = {} + # save these color attributes for next plain_text() call + else: + + for attr in CONQUE_FONT[val]['attributes'].keys(): + if self.color_changes.has_key(attr) and (attr == 'cterm' or attr == 'gui'): + self.color_changes[attr] += ',' + CONQUE_FONT[val]['attributes'][attr] + else: + self.color_changes[attr] = CONQUE_FONT[val]['attributes'][attr] + # }}} + + def csi_clear_line(self, csi): # {{{ + + + # this escape defaults to 0 + if len(csi['vals']) == 0: + csi['val'] = 0 + + + + + # 0 means cursor right + if csi['val'] == 0: + self.screen[self.l] = self.screen[self.l][0 : self.c - 1] + + # 1 means cursor left + elif csi['val'] == 1: + self.screen[self.l] = ' ' * (self.c) + self.screen[self.l][self.c : ] + + # clear entire line + elif csi['val'] == 2: + self.screen[self.l] = '' + + # clear colors + if csi['val'] == 2 or (csi['val'] == 0 and self.c == 1): + real_line = self.screen.get_real_line(self.l) + if self.color_history.has_key(real_line): + for syn in self.color_history[real_line]: + vim.command('syn clear ' + syn['name']) + + + + # }}} + + def csi_cursor_right(self, csi): # {{{ + # we use 1 even if escape explicitly specifies 0 + if csi['val'] == 0: + csi['val'] = 1 + + + + + if self.wrap_cursor and self.c + csi['val'] > self.working_columns: + self.l += int(math.floor( (self.c + csi['val']) / self.working_columns )) + self.c = (self.c + csi['val']) % self.working_columns + return + + self.c = self.bound(self.c + csi['val'], 1, self.working_columns) + # }}} + + def csi_cursor_left(self, csi): # {{{ + # we use 1 even if escape explicitly specifies 0 + if csi['val'] == 0: + csi['val'] = 1 + + if self.wrap_cursor and csi['val'] >= self.c: + self.l += int(math.floor( (self.c - csi['val']) / self.working_columns )) + self.c = self.working_columns - (csi['val'] - self.c) % self.working_columns + return + + self.c = self.bound(self.c - csi['val'], 1, self.working_columns) + # }}} + + def csi_cursor_to_column(self, csi): # {{{ + self.c = self.bound(csi['val'], 1, self.working_columns) + # }}} + + def csi_cursor_up(self, csi): # {{{ + self.l = self.bound(self.l - csi['val'], self.top, self.bottom) + + self.color_changes = {} + # }}} + + def csi_cursor_down(self, csi): # {{{ + self.l = self.bound(self.l + csi['val'], self.top, self.bottom) + + self.color_changes = {} + # }}} + + def csi_clear_screen(self, csi): # {{{ + # default to 0 + if len(csi['vals']) == 0: + csi['val'] = 0 + + # 2 == clear entire screen + if csi['val'] == 2: + self.l = 1 + self.c = 1 + self.screen.clear() + + # 0 == clear down + elif csi['val'] == 0: + for l in range(self.bound(self.l + 1, 1, self.lines), self.lines + 1): + self.screen[l] = '' + + # clear end of current line + self.csi_clear_line(self.parse_csi('K')) + + # 1 == clear up + elif csi['val'] == 1: + for l in range(1, self.bound(self.l, 1, self.lines + 1)): + self.screen[l] = '' + + # clear beginning of current line + self.csi_clear_line(self.parse_csi('1K')) + + # clear coloration + if csi['val'] == 2 or csi['val'] == 0: + real_line = self.screen.get_real_line(self.l) + for line in self.color_history.keys(): + if line >= real_line: + for syn in self.color_history[line]: + vim.command('syn clear ' + syn['name']) + + self.color_changes = {} + # }}} + + def csi_delete_chars(self, csi): # {{{ + self.screen[self.l] = self.screen[self.l][ : self.c ] + self.screen[self.l][ self.c + csi['val'] : ] + # }}} + + def csi_add_spaces(self, csi): # {{{ + self.screen[self.l] = self.screen[self.l][ : self.c - 1] + ' ' * csi['val'] + self.screen[self.l][self.c : ] + # }}} + + def csi_cursor(self, csi): # {{{ + if len(csi['vals']) == 2: + new_line = csi['vals'][0] + new_col = csi['vals'][1] + else: + new_line = 1 + new_col = 1 + + if self.absolute_coords: + self.l = self.bound(new_line, 1, self.lines) + else: + self.l = self.bound(self.top + new_line - 1, self.top, self.bottom) + + self.c = self.bound(new_col, 1, self.working_columns) + if self.c > len(self.screen[self.l]): + self.screen[self.l] = self.screen[self.l] + ' ' * (self.c - len(self.screen[self.l])) + + # }}} + + def csi_set_coords(self, csi): # {{{ + if len(csi['vals']) == 2: + new_start = csi['vals'][0] + new_end = csi['vals'][1] + else: + new_start = 1 + new_end = vim.current.window.height + + self.top = new_start + self.bottom = new_end + self.working_lines = new_end - new_start + 1 + + # if cursor is outside scrolling region, reset it + if self.l < self.top: + self.l = self.top + elif self.l > self.bottom: + self.l = self.bottom + + self.color_changes = {} + # }}} + + def csi_tab_clear(self, csi): # {{{ + # this escape defaults to 0 + if len(csi['vals']) == 0: + csi['val'] = 0 + + + + if csi['val'] == 0: + self.tabstops[self.c - 1] = False + elif csi['val'] == 3: + for i in range(0, self.columns + 1): + self.tabstops[i] = False + # }}} + + def csi_set(self, csi): # {{{ + # 132 cols + if csi['val'] == 3: + self.csi_clear_screen(self.parse_csi('2J')) + self.working_columns = 132 + + # relative_origin + elif csi['val'] == 6: + self.absolute_coords = False + + # set auto wrap + elif csi['val'] == 7: + self.autowrap = True + + + self.color_changes = {} + # }}} + + def csi_reset(self, csi): # {{{ + # 80 cols + if csi['val'] == 3: + self.csi_clear_screen(self.parse_csi('2J')) + self.working_columns = 80 + + # absolute origin + elif csi['val'] == 6: + self.absolute_coords = True + + # reset auto wrap + elif csi['val'] == 7: + self.autowrap = False + + + self.color_changes = {} + # }}} + + # }}} + + ############################################################################################### + # ESC functions {{{ + + def esc_scroll_up(self): # {{{ + self.ctl_nl() + + self.color_changes = {} + # }}} + + def esc_next_line(self): # {{{ + self.ctl_nl() + self.c = 1 + # }}} + + def esc_set_tab(self): # {{{ + + if self.c <= len(self.tabstops): + self.tabstops[self.c - 1] = True + # }}} + + def esc_scroll_down(self): # {{{ + if self.l == self.top: + del self.screen[self.bottom] + self.screen.insert(self.top, '') + else: + self.l += -1 + + self.color_changes = {} + # }}} + + # }}} + + ############################################################################################### + # HASH functions {{{ + + def hash_screen_alignment_test(self): # {{{ + self.csi_clear_screen(self.parse_csi('2J')) + self.working_lines = self.lines + for l in range(1, self.lines + 1): + self.screen[l] = 'E' * self.working_columns + # }}} + + # }}} + + ############################################################################################### + # Random stuff {{{ + + def change_title(self, key, val): + + + if key == '0' or key == '2': + + vim.command('setlocal statusline=' + re.escape(val)) + + def paste(self): + self.write(vim.eval('@@')) + self.read(50) + + def paste_selection(self): + self.write(vim.eval('@@')) + + def update_window_size(self): + # resize if needed + if vim.current.window.width != self.columns or vim.current.window.height != self.lines: + + # reset all window size attributes to default + self.columns = vim.current.window.width + self.lines = vim.current.window.height + self.working_columns = vim.current.window.width + self.working_lines = vim.current.window.height + self.bottom = vim.current.window.height + + # reset screen object attributes + self.l = self.screen.reset_size(self.l) + + # reset tabstops + self.init_tabstops() + + + + # signal process that screen size has changed + self.proc.window_resize(self.lines, self.columns) + + def init_tabstops(self): + for i in range(0, self.columns + 1): + if i % 8 == 0: + self.tabstops.append(True) + else: + self.tabstops.append(False) + + # }}} + + ############################################################################################### + # Utility {{{ + + def parse_csi(self, s): # {{{ + attr = { 'key' : s[-1], 'flag' : '', 'val' : 1, 'vals' : [] } + + if len(s) == 1: + return attr + + full = s[0:-1] + + if full[0] == '?': + full = full[1:] + attr['flag'] = '?' + + if full != '': + vals = full.split(';') + for val in vals: + + val = re.sub("\D", "", val) + + if val != '': + attr['vals'].append(int(val)) + + if len(attr['vals']) == 1: + attr['val'] = int(attr['vals'][0]) + + return attr + # }}} + + def bound(self, val, min, max): # {{{ + if val > max: + return max + + if val < min: + return min + + return val + # }}} + + def xterm_to_rgb(self, color_code): # {{{ + if color_code < 16: + ascii_colors = ['000000', 'CD0000', '00CD00', 'CDCD00', '0000EE', 'CD00CD', '00CDCD', 'E5E5E5', + '7F7F7F', 'FF0000', '00FF00', 'FFFF00', '5C5CFF', 'FF00FF', '00FFFF', 'FFFFFF'] + return ascii_colors[color_code] + + elif color_code < 232: + cc = int(color_code) - 16 + + p1 = "%02x" % (math.floor(cc / 36) * (255/5)) + p2 = "%02x" % (math.floor((cc % 36) / 6) * (255/5)) + p3 = "%02x" % (math.floor(cc % 6) * (255/5)) + + return p1 + p2 + p3 + else: + grey_tone = "%02x" % math.floor((255/24) * (color_code - 232)) + return grey_tone + grey_tone + grey_tone + # }}} + + # }}} + + +import os, signal, pty, tty, select, fcntl, termios, struct + +################################################################################################### +class ConqueSubprocess: + + # process id + pid = 0 + + # stdout+stderr file descriptor + fd = None + + # constructor + def __init__(self): # {{{ + self.pid = 0 + # }}} + + # create the pty or whatever (whatever == windows) + def open(self, command, env = {}): # {{{ + command_arr = command.split() + executable = command_arr[0] + args = command_arr + + try: + self.pid, self.fd = pty.fork() + + except: + pass + + + # child proc, replace with command after altering terminal attributes + if self.pid == 0: + + # set requested environment variables + for k in env.keys(): + os.environ[k] = env[k] + + # set some attributes + try: + attrs = tty.tcgetattr(1) + attrs[0] = attrs[0] ^ tty.IGNBRK + attrs[0] = attrs[0] | tty.BRKINT | tty.IXANY | tty.IMAXBEL + attrs[2] = attrs[2] | tty.HUPCL + attrs[3] = attrs[3] | tty.ICANON | tty.ECHO | tty.ISIG | tty.ECHOKE + attrs[6][tty.VMIN] = 1 + attrs[6][tty.VTIME] = 0 + tty.tcsetattr(1, tty.TCSANOW, attrs) + except: + pass + + os.execvp(executable, args) + + # else master, do nothing + else: + pass + + # }}} + + # read from pty + # XXX - select.poll() doesn't work in OS X!!!!!!! + def read(self, timeout = 1): # {{{ + + output = '' + read_timeout = float(timeout) / 1000 + + try: + # what, no do/while? + while 1: + s_read, s_write, s_error = select.select( [ self.fd ], [], [], read_timeout) + + lines = '' + for s_fd in s_read: + try: + lines = os.read( self.fd, 32 ) + except: + pass + output = output + lines + + if lines == '': + break + except: + pass + + return output + # }}} + + # I guess this one's not bad + def write(self, input): # {{{ + try: + os.write(self.fd, input) + except: + pass + # }}} + + # signal process + def signal(self, signum): # {{{ + try: + os.kill(self.pid, signum) + except: + pass + # }}} + + # get process status + def get_status(self): #{{{ + + p_status = True + + try: + if os.waitpid( self.pid, os.WNOHANG )[0]: + p_status = False + except: + p_status = False + + return p_status + + # }}} + + # update window size in kernel, then send SIGWINCH to fg process + def window_resize(self, lines, columns): # {{{ + try: + fcntl.ioctl(self.fd, termios.TIOCSWINSZ, struct.pack("HHHH", lines, columns, 0, 0)) + os.kill(self.pid, signal.SIGWINCH) + except: + pass + + # }}} + + +################################################################################################### +# ConqueScreen is an extention of the vim.current.buffer object +# It restricts the working indices of the buffer object to the scroll region which pty is expecting +# It also uses 1-based indexes, to match escape sequence commands +# +# E.g.: +# s = ConqueScreen() +# ... +# s[5] = 'Set 5th line in terminal to this line' +# s.append('Add new line to terminal') +# s[5] = 'Since previous append() command scrolled the terminal down, this is a different line than first cb[5] call' +# + +import vim + +class ConqueScreen(object): + + # CLASS PROPERTIES {{{ + + # the buffer + buffer = None + + # screen and scrolling regions + screen_top = 1 + + # screen width + screen_width = 80 + screen_height = 80 + + # }}} + + def __init__(self): # {{{ + self.buffer = vim.current.buffer + + self.screen_top = 1 + self.screen_width = vim.current.window.width + self.screen_height = vim.current.window.height + # }}} + + ############################################################################################### + # List overload {{{ + def __len__(self): # {{{ + return len(self.buffer) + # }}} + + def __getitem__(self, key): # {{{ + real_line = self.get_real_idx(key) + + # if line is past buffer end, add lines to buffer + if real_line >= len(self.buffer): + for i in range(len(self.buffer), real_line + 1): + self.append(' ' * self.screen_width) + + return self.buffer[ real_line ] + # }}} + + def __setitem__(self, key, value): # {{{ + real_line = self.get_real_idx(key) + + # if line is past end of screen, append + if real_line == len(self.buffer): + self.buffer.append(value) + else: + self.buffer[ real_line ] = value + # }}} + + def __delitem__(self, key): # {{{ + del self.buffer[ self.screen_top + key - 2 ] + # }}} + + def append(self, value): # {{{ + if len(self.buffer) > self.screen_top + self.screen_height - 1: + self.buffer[len(self.buffer) - 1] = value + else: + self.buffer.append(value) + + if len(self.buffer) > self.screen_top + self.screen_height - 1: + self.screen_top += 1 + if vim.current.buffer.number == self.buffer.number: + vim.command('normal G') + # }}} + + def insert(self, line, value): # {{{ + + l = self.screen_top + line - 2 + self.buffer[l:l] = [ value ] + + # }}} + # }}} + + ############################################################################################### + # Util {{{ + def get_top(self): # {{{ + return self.screen_top + # }}} + + def get_real_idx(self, line): # {{{ + return (self.screen_top + line - 2) + # }}} + + def get_real_line(self, line): # {{{ + return (self.screen_top + line - 1) + # }}} + + def set_screen_width(self, width): # {{{ + self.screen_width = width + # }}} + + # }}} + + ############################################################################################### + def clear(self): # {{{ + self.buffer.append(' ') + vim.command('normal Gzt') + self.screen_top = len(self.buffer) + # }}} + + def set_cursor(self, line, column): # {{{ + # figure out line + real_line = self.screen_top + line - 1 + if real_line > len(self.buffer): + for l in range(len(self.buffer) - 1, real_line): + self.buffer.append('') + + # figure out column + real_column = column + if len(self.buffer[real_line - 1]) < real_column: + self.buffer[real_line - 1] = self.buffer[real_line - 1] + ' ' * (real_column - len(self.buffer[real_line - 1])) + + # python version is occasionally grumpy + try: + vim.current.window.cursor = (real_line, real_column - 1) + except: + vim.command('call cursor(' + str(real_line) + ', ' + str(real_column) + ')') + # }}} + + def reset_size(self, line): # {{{ + + + + + # save cursor line number + real_line = self.screen_top + line + + # reset screen size + self.screen_width = vim.current.window.width + self.screen_height = vim.current.window.height + self.screen_top = len(self.buffer) - vim.current.window.height + 1 + if self.screen_top < 1: + self.screen_top = 1 + + + # align bottom of buffer to bottom of screen + vim.command('normal ' + str(self.screen_height) + 'kG') + + # return new relative line number + return (real_line - self.screen_top) + # }}} + + def scroll_to_bottom(self): # {{{ + vim.current.window.cursor = (len(self.buffer) - 1, 1) + # }}} + + def align(self): # {{{ + # align bottom of buffer to bottom of screen + vim.command('normal ' + str(self.screen_height) + 'kG') + # }}} + + +EOF + +endif + diff --git a/vim/tmp/conque/doc/conque_term.txt b/vim/tmp/conque/doc/conque_term.txt new file mode 100644 index 0000000..ff8ca54 --- /dev/null +++ b/vim/tmp/conque/doc/conque_term.txt @@ -0,0 +1,156 @@ +*ConqueTerm* Plugin to run a shell in a buffer + +The ConqueTerm plugin will convert a buffer into a terminal emulator, allowing +you to run a shell or shell application in the buffer. + + *conque_term-usage* + +Type :ConqueTerm to launch an application in the current buffer. E.g. + + :ConqueTerm bash + :ConqueTerm mysql -h localhost -u joe_lunchbox Menu + :ConqueTerm man top + +Use :ConqueTermSplit or :ConqueTermVSplit to open Conque in a new horizontal +or vertical buffer. + +Keys pressed in insert mode will be sent to the shell, along with output from +the 'p' command in normal mode. + +Press the key twice to send a single to the shell. Pressing this +key once will leave insert mode like normal. + +Press in any buffer to send a visual selection to the shell. + + + *conque_term-settings* + +Set the following in your .vimrc (default values shown) + +" Enable colors. Setting this to 0 will make your terminal faster. +let g:ConqueTerm_Color = 1 + +" Set your terminal type. I strong recommend leaving this as vt100, +" however more features may be enabled with xterm. +let g:ConqueTerm_TERM = 'vt100' + +" Set buffer syntax. Conque has highlighting for MySQL, but not much else. +let g:ConqueTerm_Syntax = 'conque' + +" Continue updating shell when it's not the current, focused buffer +let g:ConqueTerm_ReadUnfocused = 1 + + + *conque_term-requirements* + +The following minimum requirements are needed to run Conque. Conque will not +run on Windows without a Cygwin-like environment. + + - Vim 7.1 + - Python 2.3 + - Supported operating systems: *nix, Mac, or Cygwin + +Tested on: + - Vim 7.2 / Python 2.6 / Ubuntu 9.10 (Gnome & GTK) + - Vim 7.2 / Python 2.6 / FreeBSD 8.0 (GTK) + - Vim 7.1 / Python 2.6 / FreeBSD 8.0 (GTK) + x Vim 7.0 / Python 2.6 / FreeBSD 8.0 (GTK) + * feedkeys() doesn't restart updatetime + - Vim 7.2 / Python 2.4 / OpenSolaris 2009.06 (Gnome) + - Vim 7.2 / Python 2.4 / CentOS 5.3 (no GUI) + - Vim 7.1 / Python 2.3 / RHEL 4 (no GUI) + - Vim 7.2 / Python 2.5 / Cygwin (Windows Vista 64b) + - MacVim 7.2 / Python 2.3 / OS X 10.6.2 + + *conque_term-bugs* + +The following are known limitations: + + - Font/color highlighting is imperfect and slow. If you don't care about + color in your shell, set g:ConqueTerm_Color = 0 in your .vimrc + - Conque only supports the extended ASCII character set for input, not utf-8. + - VT100 escape sequence support is not complete. + - Alt/Meta key support in Vim isn't great in general, and conque is no + exception. Pressing x or instead of works in + most cases. + + *conque_term-todo* + + - Fix pasting from named registers + - Polling unfucused conque buffers (Top explodes when window resizes) + - Enable graphics character set + - Consider supporting xterm escapes + - Improve color logic + - Find a solution to UTF-8 input (See InsertCharPre in Vim todo.txt) + - Find an alternative to updatetime polling (See Vim todo.txt) + - Find a graceful solution to Meta key input + - Windows support + (See PyConsole http://www.vim.org/scripts/script.php?script_id=1974) + - Always: look for performance improvements + + + *conque_term-contribute* + +The two contributions most in need are improvements to Vim itself. I currently +use hacks to simulate a key press event and repeating CursorHold event. The +Vim todo.txt document lists proposed improvements to give users this behavior +without hacks. Having a key press event should allow Conque to work with multi- +byte input. If you are a Vim developer, please consider prioritizing these two +items: + + - todo.txt (Autocommands, line ~3137) + 8 Add an event like CursorHold that is triggered repeatedly, not just + once after typing something. + + - todo.txt (Autocommands, proposed event list, line ~3189) + InsertCharPre - user typed character Insert mode, before inserting the + char. Pattern is matched with text before the cursor. Set v:char to the + character, can be changed. (not triggered when 'paste' is set). + +Bugs, suggestions and patches are all welcome. + +For more information visit http://conque.googlecode.com + +Check out the latest from svn at http://conque.googlecode.com/svn/trunk/ + + *conque_term-changelog* + + - 1.0 / 2010-02- + * Complete python rewrite + * Add support for ncurses based applications + * Add continuous polling, instead of using + * Improve speed + * Improve syntax highlighting + + - 0.6 / 2009-12-18 + * Fix GVim errors with non-english locale + * No functional changes + + - 0.5 / 2009-12-02 + * Various performance enhancements and bugfixes. + * Rewritten escape sequence processing + + - 0.4 / 2009-10-30 + * Improved history and tab completion + * Fix escape sequence formatting and improve highlighting + * Send selected text to shell from any buffer + * Add special handling of "vi" and "man" commands + * Improve error handling + * Add key mappings for + * Various bugfixes + + - 0.3 / 2009-10-13 + * Apply escape sequence coloring to output, e.g. ls --color + * Clean up syntax files for portability + * Fix several Vim 7.1 bugs + * Bugfixes for multiple shell buffers + * Add experimental shell folding option + + - 0.2 / 2009-10-01 + * Rewritten subprocess management module in python instead of c + * Added support for OS X, partial support for Windows + * Improved tab completion + + - 0.1 / 2009-09-03 + * Initial release + diff --git a/vim/tmp/conque/plugin/conque_term.vim b/vim/tmp/conque/plugin/conque_term.vim new file mode 100644 index 0000000..07f96e0 --- /dev/null +++ b/vim/tmp/conque/plugin/conque_term.vim @@ -0,0 +1,93 @@ +" FILE: plugin/conque_term.vim {{{ +" AUTHOR: Nico Raffo +" MODIFIED: 2010-05-27 +" VERSION: 1.1, for Vim 7.0 +" LICENSE: +" Conque - pty interaction in Vim +" Copyright (C) 2009-2010 Nico Raffo +" +" MIT License +" +" Permission is hereby granted, free of charge, to any person obtaining a copy +" of this software and associated documentation files (the "Software"), to deal +" in the Software without restriction, including without limitation the rights +" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +" copies of the Software, and to permit persons to whom the Software is +" furnished to do so, subject to the following conditions: +" +" The above copyright notice and this permission notice shall be included in +" all copies or substantial portions of the Software. +" +" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +" THE SOFTWARE. +" }}} + +" See docs/conque_term.txt for help or type :help conque_term + +if exists('g:ConqueTerm_Loaded') || v:version < 700 + finish +endif + +" ********************************************************************************************************** +" **** CONFIG ********************************************************************************************** +" ********************************************************************************************************** + +" Choose key mapping to leave insert mode {{{ +" If you choose something other than '', then will be sent to terminal +" Using a different key will usually fix Alt/Meta key issues +if !exists('g:ConqueTerm_EscKey') + let g:ConqueTerm_EscKey = '' +endif " }}} + +" Enable color. {{{ +" If your apps use a lot of color it will slow down the shell. +if !exists('g:ConqueTerm_Color') + let g:ConqueTerm_Color = 1 +endif " }}} + +" TERM environment setting {{{ +if !exists('g:ConqueTerm_TERM') + let g:ConqueTerm_TERM = 'vt100' +endif " }}} + +" Syntax for your buffer {{{ +if !exists('g:ConqueTerm_Syntax') + let g:ConqueTerm_Syntax = 'conque_term' +endif " }}} + +" Keep on updating the shell window after you've switched to another buffer {{{ +if !exists('g:ConqueTerm_ReadUnfocused') + let g:ConqueTerm_ReadUnfocused = 0 +endif " }}} + +" Use this regular expression to highlight prompt {{{ +if !exists('g:ConqueTerm_PromptRegex') + let g:ConqueTerm_PromptRegex = '^\w\+@[0-9A-Za-z_.-]\+:[0-9A-Za-z_./\~,:-]\+\$' +endif " }}} + +" Allow user to use keys to switch window in insert mode. {{{ +if !exists('g:ConqueTerm_CWInsert') + let g:ConqueTerm_CWInsert = 0 +endif " }}} + +" ********************************************************************************************************** +" **** Startup ********************************************************************************************* +" ********************************************************************************************************** + +" Startup {{{ + +let g:ConqueTerm_Loaded = 1 +let g:ConqueTerm_Idx = 1 + +command! -nargs=+ -complete=shellcmd ConqueTerm call conque_term#open() +command! -nargs=+ -complete=shellcmd ConqueTermSplit call conque_term#open(, ['belowright split']) +command! -nargs=+ -complete=shellcmd ConqueTermVSplit call conque_term#open(, ['belowright vsplit']) +command! -nargs=+ -complete=shellcmd ConqueTermTab call conque_term#open(, ['tabnew']) + +" }}} + diff --git a/vim/tmp/conque/syntax/conque_term.vim b/vim/tmp/conque/syntax/conque_term.vim new file mode 100644 index 0000000..7607913 --- /dev/null +++ b/vim/tmp/conque/syntax/conque_term.vim @@ -0,0 +1,75 @@ + +" ******************************************************************************************************************* +" MySQL ************************************************************************************************************* +" ******************************************************************************************************************* + +syn match MySQLTableHead "^ *|.*| *$" nextgroup=MySQLTableDivide contains=MySQLTableBar oneline skipwhite skipnl +syn match MySQLTableBody "^ *|.*| *$" nextgroup=MySQLTableBody,MySQLTableEnd contains=MySQLTableBar,MySQLNull,MySQLBool,MySQLNumber,MySQLStorageClass oneline skipwhite skipnl +syn match MySQLTableEnd "^ *+[+=-]\++ *$" oneline +syn match MySQLTableDivide "^ *+[+=-]\++ *$" nextgroup=MySQLTableBody oneline skipwhite skipnl +syn match MySQLTableStart "^ *+[+=-]\++ *$" nextgroup=MySQLTableHead oneline skipwhite skipnl +syn match MySQLNull " NULL " contained contains=MySQLTableBar +syn match MySQLStorageClass " PRI " contained +syn match MySQLStorageClass " MUL " contained +syn match MySQLStorageClass " UNI " contained +syn match MySQLStorageClass " CURRENT_TIMESTAMP " contained +syn match MySQLStorageClass " auto_increment " contained +syn match MySQLTableBar "|" contained +syn match MySQLNumber "|\? *\d\+ *|" contained contains=MySQLTableBar +syn match MySQLQueryStat "^\d\+ rows\? in set.*" oneline +syn match MySQLPromptLine "^.\?mysql> .*$" contains=MySQLKeyword,MySQLPrompt,MySQLString oneline +syn match MySQLPromptLine "^ -> .*$" contains=MySQLKeyword,MySQLPrompt,MySQLString oneline +syn match MySQLPrompt "^.\?mysql>" contained oneline +syn match MySQLPrompt "^ ->" contained oneline +syn case ignore +syn keyword MySQLKeyword select count max sum avg date show table tables status like as from left right outer inner join contained +syn keyword MySQLKeyword where group by having limit offset order desc asc show contained +syn case match +syn region MySQLString start=+'+ end=+'+ skip=+\\'+ contained oneline +syn region MySQLString start=+"+ end=+"+ skip=+\\"+ contained oneline +syn region MySQLString start=+`+ end=+`+ skip=+\\`+ contained oneline + +hi def link MySQLPrompt Identifier +hi def link MySQLTableHead Title +hi def link MySQLTableBody Normal +hi def link MySQLBool Boolean +hi def link MySQLStorageClass StorageClass +hi def link MySQLNumber Number +hi def link MySQLKeyword Keyword +hi def link MySQLString String + +" terms which have no reasonable default highlight group to link to +hi MySQLTableHead term=bold cterm=bold gui=bold +if &background == 'dark' + hi MySQLTableEnd term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLTableDivide term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLTableStart term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLTableBar term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLNull term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 + hi MySQLQueryStat term=NONE cterm=NONE gui=NONE ctermfg=238 guifg=#444444 +elseif &background == 'light' + hi MySQLTableEnd term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLTableDivide term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLTableStart term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLTableBar term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLNull term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e + hi MySQLQueryStat term=NONE cterm=NONE gui=NONE ctermfg=247 guifg=#9e9e9e +endif + + +" ******************************************************************************************************************* +" Bash ************************************************************************************************************** +" ******************************************************************************************************************* + +" Typical Prompt +silent execute "syn match ConquePromptLine '" . g:ConqueTerm_PromptRegex . ".*$' contains=ConquePrompt,ConqueString oneline" +silent execute "syn match ConquePrompt '" . g:ConqueTerm_PromptRegex . "' contained oneline" +hi def link ConquePrompt Identifier + +" Strings +syn region ConqueString start=+'+ end=+'+ skip=+\\'+ contained oneline +syn region ConqueString start=+"+ end=+"+ skip=+\\"+ contained oneline +syn region ConqueString start=+`+ end=+`+ skip=+\\`+ contained oneline +hi def link ConqueString String + +" vim: foldmethod=marker diff --git a/vim/tmp/conque_1.1.tar.gz b/vim/tmp/conque_1.1.tar.gz new file mode 100644 index 0000000..96f95b4 Binary files /dev/null and b/vim/tmp/conque_1.1.tar.gz differ diff --git a/vim/tmp/cucumber b/vim/tmp/cucumber new file mode 160000 index 0000000..2ef3e5a --- /dev/null +++ b/vim/tmp/cucumber @@ -0,0 +1 @@ +Subproject commit 2ef3e5a4876a4cd5ea83a0dcbf17f5c3edbf9de3 diff --git a/vim/tmp/endwise b/vim/tmp/endwise new file mode 160000 index 0000000..9a9d199 --- /dev/null +++ b/vim/tmp/endwise @@ -0,0 +1 @@ +Subproject commit 9a9d1994eaeae3f2f23da6bb71111782ab70276c diff --git a/vim/tmp/fugitive b/vim/tmp/fugitive new file mode 160000 index 0000000..201bdd0 --- /dev/null +++ b/vim/tmp/fugitive @@ -0,0 +1 @@ +Subproject commit 201bdd0eff4cd79847cf006f143deb62f8f97342 diff --git a/vim/tmp/gist-vim b/vim/tmp/gist-vim new file mode 160000 index 0000000..37e98ed --- /dev/null +++ b/vim/tmp/gist-vim @@ -0,0 +1 @@ +Subproject commit 37e98ed00e1262ef80d232a9f0e0529afd4ed6ce diff --git a/vim/tmp/git b/vim/tmp/git new file mode 160000 index 0000000..291cbe9 --- /dev/null +++ b/vim/tmp/git @@ -0,0 +1 @@ +Subproject commit 291cbe97f2c367f40360949f19b4fa8fb0740e9f diff --git a/vim/tmp/haml b/vim/tmp/haml new file mode 160000 index 0000000..de3e72a --- /dev/null +++ b/vim/tmp/haml @@ -0,0 +1 @@ +Subproject commit de3e72a384c9b1cc8707c9bc37cefc24d8484ebf diff --git a/vim/tmp/indent_object b/vim/tmp/indent_object new file mode 160000 index 0000000..78fffa6 --- /dev/null +++ b/vim/tmp/indent_object @@ -0,0 +1 @@ +Subproject commit 78fffa609b3e6b84ef01ee4c9aba6d7435d7b18e diff --git a/vim/tmp/irblack b/vim/tmp/irblack new file mode 160000 index 0000000..59622ca --- /dev/null +++ b/vim/tmp/irblack @@ -0,0 +1 @@ +Subproject commit 59622caff32a7925181ab139701fad3eee54ae51 diff --git a/vim/tmp/javascript b/vim/tmp/javascript new file mode 160000 index 0000000..9990a76 --- /dev/null +++ b/vim/tmp/javascript @@ -0,0 +1 @@ +Subproject commit 9990a767695c78a44611ce33fb2dbc25c83d8827 diff --git a/vim/tmp/markdown b/vim/tmp/markdown new file mode 160000 index 0000000..ae3a265 --- /dev/null +++ b/vim/tmp/markdown @@ -0,0 +1 @@ +Subproject commit ae3a2653f824bb9e969f462c5d77e035a518ea61 diff --git a/vim/tmp/nerdcommenter b/vim/tmp/nerdcommenter new file mode 160000 index 0000000..093e6b3 --- /dev/null +++ b/vim/tmp/nerdcommenter @@ -0,0 +1 @@ +Subproject commit 093e6b3f765b728c129a4271f1f34bb70e671f08 diff --git a/vim/tmp/nerdtree b/vim/tmp/nerdtree new file mode 160000 index 0000000..3bb112d --- /dev/null +++ b/vim/tmp/nerdtree @@ -0,0 +1 @@ +Subproject commit 3bb112d916a3e78f2e6528b869cdad1f7d826114 diff --git a/vim/tmp/puppet b/vim/tmp/puppet new file mode 160000 index 0000000..1f3b151 --- /dev/null +++ b/vim/tmp/puppet @@ -0,0 +1 @@ +Subproject commit 1f3b151b2d4eefc2f1d59c0d381d01d32d56eb50 diff --git a/vim/tmp/rails b/vim/tmp/rails new file mode 160000 index 0000000..d94405a --- /dev/null +++ b/vim/tmp/rails @@ -0,0 +1 @@ +Subproject commit d94405aae64ff10fc10a78807b5e9214c83c60df diff --git a/vim/tmp/rspec b/vim/tmp/rspec new file mode 160000 index 0000000..4e6e495 --- /dev/null +++ b/vim/tmp/rspec @@ -0,0 +1 @@ +Subproject commit 4e6e4956dd3f3ae58daf1087352951a2ba7137bf diff --git a/vim/tmp/scala b/vim/tmp/scala new file mode 160000 index 0000000..e3746cd --- /dev/null +++ b/vim/tmp/scala @@ -0,0 +1 @@ +Subproject commit e3746cd5703bedf1009c869e555a3b847b361701 diff --git a/vim/tmp/searchfold b/vim/tmp/searchfold new file mode 160000 index 0000000..f2b988c --- /dev/null +++ b/vim/tmp/searchfold @@ -0,0 +1 @@ +Subproject commit f2b988c592bc8989c2b9300f241ebb0aefde43e6 diff --git a/vim/tmp/snipmate b/vim/tmp/snipmate new file mode 160000 index 0000000..f5a75d0 --- /dev/null +++ b/vim/tmp/snipmate @@ -0,0 +1 @@ +Subproject commit f5a75d075d3c005ebe69e3f5e56cf99516e8aa3b diff --git a/vim/tmp/solarized b/vim/tmp/solarized new file mode 160000 index 0000000..528a59f --- /dev/null +++ b/vim/tmp/solarized @@ -0,0 +1 @@ +Subproject commit 528a59f26d12278698bb946f8fb82a63711eec21 diff --git a/vim/tmp/supertab b/vim/tmp/supertab new file mode 160000 index 0000000..80ec653 --- /dev/null +++ b/vim/tmp/supertab @@ -0,0 +1 @@ +Subproject commit 80ec6539e4139a2e0281a0f1e36d5038d55ad980 diff --git a/vim/tmp/surround b/vim/tmp/surround new file mode 160000 index 0000000..f6c9d3b --- /dev/null +++ b/vim/tmp/surround @@ -0,0 +1 @@ +Subproject commit f6c9d3beb2d11959d22b2555636aeb0c37e66aa1 diff --git a/vim/tmp/syntastic b/vim/tmp/syntastic new file mode 160000 index 0000000..cf6aa9a --- /dev/null +++ b/vim/tmp/syntastic @@ -0,0 +1 @@ +Subproject commit cf6aa9a4143704e0e3070302ffe593636d6e8cc9 diff --git a/vim/tmp/taglist b/vim/tmp/taglist new file mode 160000 index 0000000..53041fb --- /dev/null +++ b/vim/tmp/taglist @@ -0,0 +1 @@ +Subproject commit 53041fbc45398a9af631a20657e109707a455339 diff --git a/vim/tmp/textile b/vim/tmp/textile new file mode 160000 index 0000000..5d25629 --- /dev/null +++ b/vim/tmp/textile @@ -0,0 +1 @@ +Subproject commit 5d25629d066d01f3c9e0872ac18565afbb84a6dd diff --git a/vim/tmp/unimpaired b/vim/tmp/unimpaired new file mode 160000 index 0000000..1c9dcee --- /dev/null +++ b/vim/tmp/unimpaired @@ -0,0 +1 @@ +Subproject commit 1c9dcee02bc23dc5757c2c8f3cc2e4964ed1e636 diff --git a/vim/tmp/vim-coffee-script b/vim/tmp/vim-coffee-script new file mode 160000 index 0000000..dc16925 --- /dev/null +++ b/vim/tmp/vim-coffee-script @@ -0,0 +1 @@ +Subproject commit dc1692561461fd0b7642e05b03b7670974112eee diff --git a/vim/tmp/vividchalk b/vim/tmp/vividchalk new file mode 160000 index 0000000..c824c2a --- /dev/null +++ b/vim/tmp/vividchalk @@ -0,0 +1 @@ +Subproject commit c824c2a5c1d96a7d2ec2df6baf7231dcee621130 diff --git a/vim/tmp/zoomwin b/vim/tmp/zoomwin new file mode 160000 index 0000000..e7ee18e --- /dev/null +++ b/vim/tmp/zoomwin @@ -0,0 +1 @@ +Subproject commit e7ee18e2e7ed60509aa951cd34b57193fa14e5ab diff --git a/vim/vimrc b/vim/vimrc new file mode 100644 index 0000000..3941f22 --- /dev/null +++ b/vim/vimrc @@ -0,0 +1,158 @@ +set nocompatible + +set number +set ruler +syntax on + +" Set encoding +set encoding=utf-8 + +" Whitespace stuff +set nowrap +set tabstop=2 +set shiftwidth=2 +set softtabstop=2 +set expandtab +set list listchars=tab:\ \ ,trail:· + +" Searching +set hlsearch +set incsearch +set ignorecase +set smartcase + +" Tab completion +set wildmode=list:longest,list:full +set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/* + +" Status bar +set laststatus=2 + +" Without setting this, ZoomWin restores windows in a way that causes +" equalalways behavior to be triggered the next time CommandT is used. +" This is likely a bludgeon to solve some other issue, but it works +set noequalalways + +" NERDTree configuration +let NERDTreeIgnore=['\.pyc$', '\.rbc$', '\~$'] +map n :NERDTreeToggle + +" CTags +map rt :!ctags --extra=+f -R * +map :tnext + +" Remember last location in file +if has("autocmd") + au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") + \| exe "normal g'\"" | endif +endif + +function s:setupWrapping() + set wrap + set wrapmargin=2 + set textwidth=72 +endfunction + +function s:setupMarkup() + call s:setupWrapping() + map p :Hammer +endfunction + +" make uses real tabs +au FileType make set noexpandtab + +" Thorfile, Rakefile, Vagrantfile and Gemfile are Ruby +au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru} set ft=ruby + +" md, markdown, and mk are markdown and define buffer-local preview +au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup() + +" add json syntax highlighting +au BufNewFile,BufRead *.json set ft=javascript + +au BufRead,BufNewFile *.txt call s:setupWrapping() + +" make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ ) +au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79 + +" allow backspacing over everything in insert mode +set backspace=indent,eol,start + +" load the plugin and indent settings for the detected filetype +filetype plugin indent on + +" Opens an edit command with the path of the currently edited file filled in +" Normal mode: e +map e :e =expand("%:p:h") . "/" + +" Opens a tab edit command with the path of the currently edited file filled in +" Normal mode: t +map te :tabe =expand("%:p:h") . "/" + +" Inserts the path of the currently edited file into a command +" Command mode: Ctrl+P +cmap =expand("%:p:h") . "/" + +" Unimpaired configuration +" Bubble single lines +nmap [e +nmap ]e +" Bubble multiple lines +vmap [egv +vmap ]egv + +" Enable syntastic syntax checking +let g:syntastic_enable_signs=1 +let g:syntastic_quiet_warnings=1 + +" gist-vim defaults +if has("mac") + let g:gist_clip_command = 'pbcopy' +elseif has("unix") + let g:gist_clip_command = 'xclip -selection clipboard' +endif +let g:gist_detect_filetype = 1 +let g:gist_open_browser_after_post = 1 + +" Use modeline overrides +set modeline +set modelines=10 + +" Default color scheme +set t_Co=256 +color railscasts + +" Directories for swp files +set backupdir=~/.vim/backup +set directory=~/.vim/backup + +" Turn off jslint errors by default +let g:JSLintHighlightErrorLine = 0 + +" MacVIM shift+arrow-keys behavior (required in .vimrc) +let macvim_hig_shift_movement = 1 + +" % to bounce from do to end etc. +runtime! macros/matchit.vim + +" Show (partial) command in the status line +set showcmd + +" Include user's local vim config +if filereadable(expand("~/.vimrc.local")) + source ~/.vimrc.local +endif + +" Mapping for TagBar +nmap :TagbarToggle + +" Mapping for CommandTBuffer +map t :CtrlP +map T :CtrlPBuffer +map R :CtrlPClearCache + +" Color Column +set colorcolumn=81 + +" Add Pathogen +call pathogen#infect()