1
0
mirror of https://github.com/gryf/.vim.git synced 2026-02-01 23:45:50 +01:00

Added branch pathogen

This commit is contained in:
2012-02-13 21:19:34 +01:00
parent b989a7b269
commit 5047146e53
261 changed files with 5724 additions and 3107 deletions

38
bundle/ack/doc/ack.txt Normal file
View File

@@ -0,0 +1,38 @@
*ack.txt* Plugin that integrates ack with Vim
==============================================================================
Author: Antoine Imbert <antoine.imbert+ackvim@gmail.com> *ack-author*
License: Same terms as Vim itself (see |license|)
==============================================================================
INTRODUCTION *ack*
This plugin is a front for the Perl module App::Ack. Ack can be used as a
replacement for grep. This plugin will allow you to run ack from vim, and
shows the results in a split window.
:Ack [options] {pattern} [{directory}] *:Ack*
Search recursively in {directory} (which defaults to the current
directory) for the {pattern}. Behaves just like the |:grep| command, but
will open the |Quickfix| window for you.
:AckAdd [options] {pattern} [{directory}] *:AckAdd*
Just like |:Ack| + |:grepadd|. Appends the |quickfix| with the results
:LAck [options] {pattern} [{directory}] *:LAck*
Just like |:Ack| + |:lgrep|. Searches, but opens in |location-list|
:LAckAdd [options] {pattern} [{directory}] *:LAckAdd*
Just like |:Ack| + |:lgrepadd|. Searches, but appends results to
|location-list|
Files containing the search term will be listed in the split window, along
with the line number of the occurrence, once for each occurrence. <Enter> on
a line in this window will open the file, and place the cursor on the matching
line.
See http://search.cpan.org/~petdance/ack/ack for more information.

50
bundle/ack/plugin/ack.vim Normal file
View File

@@ -0,0 +1,50 @@
" NOTE: You must, of course, install the ack script
" in your path.
" On Ubuntu:
" sudo apt-get install ack-grep
" ln -s /usr/bin/ack-grep /usr/bin/ack
" With MacPorts:
" sudo port install p5-app-ack
let g:ackprg="ack\\ -H\\ --nocolor\\ --nogroup"
function! Ack(args)
let grepprg_bak=&grepprg
exec "set grepprg=" . g:ackprg
execute "silent! grep " . a:args
botright copen
let &grepprg=grepprg_bak
exec "redraw!"
endfunction
function! AckAdd(args)
let grepprg_bak=&grepprg
exec "set grepprg=" . g:ackprg
execute "silent! grepadd " . a:args
botright copen
let &grepprg=grepprg_bak
exec "redraw!"
endfunction
function! LAck(args)
let grepprg_bak=&grepprg
exec "set grepprg=" . g:ackprg
execute "silent! lgrep " . a:args
botright lopen
let &grepprg=grepprg_bak
exec "redraw!"
endfunction
function! LAckAdd(args)
let grepprg_bak=&grepprg
exec "set grepprg=" . g:ackprg
execute "silent! lgrepadd " . a:args
botright lopen
let &grepprg=grepprg_bak
exec "redraw!"
endfunction
command! -nargs=* -complete=file Ack call Ack(<q-args>)
command! -nargs=* -complete=file AckAdd call AckAdd(<q-args>)
command! -nargs=* -complete=file LAck call LAck(<q-args>)
command! -nargs=* -complete=file LAckAdd call LAckAdd(<q-args>)

View File

@@ -0,0 +1,268 @@
*buffergator.txt* Buffer indexing and navigation plugin.
===============================================================================
*buffergator* *buffergator-contents*
CONTENTS~
1. Introduction ........................... |buffergator-introduction|
2. Commands ............................... |buffergator-commands|
3. Key Mappings (Global) .................. |buffergator-global-keys|
4. Key Mappings (Buffer Catalog) .......... |buffergator-buffer-keys|
5. Key Mappings (Tab Page Catalog) ........ |buffergator-tabpage-keys|
5. Options and Settings ................... |buffergator-options|
===============================================================================
*buffergator-introduction*
INTRODUCTION~
Buffergator is a plugin for listing, navigating between, and selecting buffers
to edit. Upon invocation (using the command, ":BuffergatorOpen" or
"BuffergatorToggle", or the provided key mapping, "<Leader>b"), a "catalog" of
listed buffers are displayed in a separate new window split (vertical or
horizontal, based on user options; default = vertical). From this "buffer
catalog", a buffer can be selected and opened in an existing window, a new
window split (vertical or horizontal), or a new tab page.
Selected buffers can be "previewed", i.e. opened in a window or tab page, but
with focus remaining in the buffer catalog. Even better, you can "walk" up and
down the list of buffers shown in the catalog by using <C-N> (or <SPACE>) /
<C-P> (or <C-SPACE>). These keys select the next/previous buffer in succession,
respectively, opening it for preview without leaving the buffer catalog
viewer.
Buffergator also provides a way to list tab pages and buffers associated with
windows in tab pages (the "tab page catalog", which can be invoked using the
command ":BuffergatorTabsOpen" or the provided key mapping, "<Leader>t").
By default, Buffergator provides global key maps that invoke its main
commands: "<Leader>b" to open and "<Leader>B" to close the buffer catalog, and
"<Leader>t" to open and "<Leader>T" to close the tab page catalog. If you
prefer to map other keys, or do not want any keys mapped at all, set
"g:buffergator_suppress_keymaps" to 1 in your $VIMRUNTIME.
===============================================================================
*buffergator-commands*
COMMANDS~
These following commands are provided globally by Buffergator:
:BuffergatorOpen
Open the buffer catalog, or go to it if it is already open.
:BuffergatorClose
Close the buffer catalog if it is already open.
:BuffergatorToggle
Open the buffer catalog if it is closed, or close it if
it is already open.
:BuffergatorTabsOpen
Open the tab page catalog, or go to it if it is already open.
:BuffergatorTabsClose
Close the tab page catalog if it is already open.
:BuffergatorTabsToggle
Open the tab page catalog if it is closed, or close it if
it is already open.
===============================================================================
*buffergator-global-keys*
KEY MAPPINGS (GLOBAL)~
Unless "g:buffergator_suppress_keymaps" is set to 1, then the following
key mappings are defined:
<Leader>b Invokes ":BuffergatorOpen": open the buffer catalog, or go
to it if it is already open.
<Leader>B Invokes ":BuffergatorClose": close the buffer catalog.
<Leader>t Invokes ":BuffergatorTabsOpen": open the tab page catalog,
or go to it if it is already open.
<Leader>T Invokes ":BuffergatorTabsClose": close the tab page
catalog.
===============================================================================
*buffergator-buffer-keys*
KEY MAPPINGS (BUFFER CATALOG)~
Invoking Buffergator results in the listed buffers being displayed in a
special Buffergator window, which is referred to as a "buffer catalog viewer".
The following key mappings are available when in the viewer.
-------------------------------------------------------------------------------
Catalog Management~
cs Cycle through sort regimes.
cd Cycle through display regimes.
r Update (rebuild/refresh) index.
d Delete the selected buffer.
D Unconditionally delete the selected buffer.
x Wipe the selected buffer.
X Unconditionally wipe the selected buffer.
q Quit the index/catalog window.
-------------------------------------------------------------------------------
Open Selected Buffer~
The following keys all open the currently-selected buffer and switch focus to
it. If the key presses are preceded by a number, then the buffer with that
number will be selected and opened instead of the current buffer. The catalog
buffer will be closed if 'g:buffergator_autodismiss_on_select' evaluates to
true; otherwise it will be kept open.
<CR>, o Open the currently-selected buffer (or, if [count] is
given, buffer with number [count]), in previous window.
s Open the currently-selected buffer (or, if [count] is
given, buffer with number [count]), in a new vertical
split.
i Open the currently-selected buffer (or, if [count] is
given, buffer with number [count]), in a new split.
t Open the currently-selected buffer (or, if [count] is
given, buffer with number [count]), in a new tab page.
-------------------------------------------------------------------------------
Preview Selected Buffer~
The following keys all open the currently-selected buffer, but retain focus on
the catalog viewer. If the key presses are preceded by a number, than the
buffer with that number will be opened.
O, go Preview the currently-selected buffer (or, if [count] is
given, buffer with number [count]), in the previous
window.
S, gs Preview the currently-selected buffer (or, if [count] is
given, buffer with number [count]), is a new vertical
split.
I, gi Preview the currently-selected buffer (or, if [count] is
given, buffer with number [count]), in a new split
T Preview the currently-selected buffer (or, if [count] is
given, buffer with number [count]), in a new tab
page.
<SPACE>, <C-N> Go to the next buffer entry (or, if [count] is
given, buffer with number [count]), and preview it in the
previous window.
<C-SPACE>, <C-P> Go to the previous buffer entry (or, if [count] is
given, buffer with number [count]), and preview it in the
previous window.
-------------------------------------------------------------------------------
Go to Existing Viewport Showing Buffer~
The following keys will try to find the selected buffer in an existing
viewport (whether on the current tab page or another). If the key presses are
preceded by a number, then the buffer with that number will be the target
buffer.
eo If currently-selected buffer (or, if [count] is
given, buffer with number [count]), is showing in an existing
viewport on this or any other tab page, go it it;
otherwise show it in the previous window.
es If currently-selected buffer (or, if [count] is
given, buffer with number [count]), is showing in an existing
viewport on this or any other tab page, go it it;
otherwise show it in a new vertical split.
ei If currently-selected buffer (or, if [count] is
given, buffer with number [count]), is showing in an existing
viewport on this or any other tab page, go it it;
otherwise show it in a new horizontal split.
et If currently-selected buffer (or, if [count] is
given, buffer with number [count]), is showing in an existing
viewport on this or any other tab page, go it it;
otherwise show it in a new tab page.
E If currently-selected buffer (or, if [count] is
given, buffer with number [count]), is showing in an existing
viewport on this or any other tab page, go it it;
otherwise do nothing.
-------------------------------------------------------------------------------
Window Control~
A Zoom/unzoom window, expanding to full height (if
horizontally split) or full width (if vertically split)
===============================================================================
*buffergator-tabpage-keys*
KEY MAPPINGS (TAB PAGE CATALOG)~
-------------------------------------------------------------------------------
Catalog Management~
cd Cycle through display regimes.
r Update (rebuild/refresh) index.
q Quit the index/catalog window.
-------------------------------------------------------------------------------
Open Selected Tab Page or Tab Page Window~
The following keys all open the currently-selected tab page or window.
<CR>, o Open the currently-selected tab page or window.
<SPACE> Select the next tab page entry.
<C-SPACE> Select the previous tab page entry.
<C-N> Select the next tab page window entry.
<C-P> Select the previous tab page window entry.
-------------------------------------------------------------------------------
Window Control~
A Zoom/unzoom window, expanding to full height (if
horizontally split) or full width (if vertically split)
===============================================================================
*buffergator-options*
OPTIONS AND SETTINGS~
The following options can be used to customize the behavior of this plugin:
g:buffergator_viewport_split_policy~
Default: "L"
Determines how a new Buffergator window will be opened. Can be one of the
following values:
"L" : vertical left (full screen height)
"R" : vertical right (full screen height)
"T" : horizontal top (full screen width)
"B" : horizontal bottom (full screen width)
g:buffergator_autodismiss_on_select~
Default: 1
If true, then selection an entry with <CR> will close the catalog. Otherwise,
catalog stays open. Default is 1.
g:buffergator_autoexpand_on_split~
Default: 1
If true and running in GUI mode, then the application screen will be expanded
to accommodate the Buffergator window.
g:buffergator_split_size~
Default: 40
If greater than 0, this will be the width of the Buffergator window in any
vertical splitting mode, or its height in any horizontal splitting mode.
g:buffergator_sort_regime~
Default: "bufnum"
Sets the default sort regime for buffer listing:
"bufnum" : sort by buffer number [default]
"basename": sort by buffer file basename (followed by directory)
"filepath": sort by full buffer filepath
"extension": sort by buffer filename extension (followed by full
filepath)
"mru": sort by most recently used
g:buffergator_display_regime~
Default: "basename"
Sets the default sort regime for buffer listing:
"basename": display buffer basename first,
followed by directory [default]
"filepath": display full buffer filepath
"bufname": display buffer name
g:buffergator_suppress_keymaps~
Default: 0
If true, then Buffergator will not automatically map "<Leader>b" to
open the Buffergator catalog and "<Leader>B" to close it.
vim:tw=78:ts=8:ft=help:norl:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,141 @@
" Vim color file
"
" Author: Anthony Carapetis <anthony.carapetis@gmail.com>
"
" Note: Based on github's syntax highlighting theme
" Used Brian Mock's darkspectrum as a starting point/template
" Thanks to Ryan Heath for an easy list of some of the colours:
" http://rpheath.com/posts/356-github-theme-for-syntax-gem
hi clear
set background=light
if version > 580
" no guarantees for version 5.8 and below, but this makes it stop
" complaining
hi clear
if exists("syntax_on")
syntax reset
endif
endif
let g:colors_name="github"
hi Normal guifg=#000000 guibg=#F8F8FF
" {{{ Cursor
hi Cursor guibg=#444454 guifg=#F8F8FF
hi CursorLine guibg=#D8D8DD
hi CursorColumn guibg=#E8E8EE
" gryf: added colorcolumn highlight
hi ColorColumn guibg=#E8E8EE
" }}}
" {{{ Diff
hi DiffAdd guifg=#003300 guibg=#DDFFDD gui=none
hi DiffChange guibg=#ececec gui=none
hi DiffText guifg=#000033 guibg=#DDDDFF gui=none
hi DiffDelete guifg=#DDCCCC guibg=#FFDDDD gui=none
" }}}
" {{{ Folding / Line Numbering / Status Lines
hi Folded guibg=#ECECEC guifg=#808080 gui=bold
hi vimFold guibg=#ECECEC guifg=#808080 gui=bold
hi FoldColumn guibg=#ECECEC guifg=#808080 gui=bold
hi LineNr guifg=#959595 guibg=#ECECEC gui=bold
hi NonText guifg=#808080 guibg=#ECECEC
hi Folded guifg=#808080 guibg=#ECECEC gui=bold
hi FoldeColumn guifg=#808080 guibg=#ECECEC gui=bold
hi VertSplit guibg=#bbbbbb guifg=#bbbbbb gui=none
hi StatusLine guibg=#bbbbbb guifg=#404040 gui=bold
hi StatusLineNC guibg=#d4d4d4 guifg=#404040 gui=italic
" }}}
" {{{ Misc
hi ModeMsg guifg=#990000
hi MoreMsg guifg=#990000
hi Title guifg=#ef5939
hi WarningMsg guifg=#ef5939
hi SpecialKey guifg=#177F80 gui=italic
hi MatchParen guibg=#cdcdfd guifg=#000000
hi Underlined guifg=#000000 gui=underline
hi Directory guifg=#990000
" }}}
" {{{ Search, Visual, etc
hi Visual guifg=#FFFFFF guibg=#3465a4 gui=none
hi VisualNOS guifg=#FFFFFF guibg=#204a87 gui=none
hi IncSearch guibg=#cdcdfd guifg=#000000 gui=italic
hi Search guibg=#cdcdfd guifg=#000000 gui=italic
" }}}
" {{{ Syntax groups
hi Ignore guifg=#808080
hi Identifier guifg=#0086B3
hi PreProc guifg=#A0A0A0 gui=bold
hi Comment guifg=#999988
hi Constant guifg=#177F80 gui=none
hi String guifg=#D81745
hi Function guifg=#990000 gui=bold
hi Statement guifg=#000000 gui=bold
hi Type guifg=#445588 gui=bold
hi Number guifg=#1C9898
hi Todo guifg=#FFFFFF guibg=#990000 gui=bold
hi Special guifg=#159828 gui=bold
hi rubySymbol guifg=#960B73
hi Error guibg=#f8f8ff guifg=#ff1100 gui=undercurl
hi Todo guibg=#f8f8ff guifg=#ff1100 gui=underline
hi Label guifg=#000000 gui=bold
hi StorageClass guifg=#000000 gui=bold
hi Structure guifg=#000000 gui=bold
hi TypeDef guifg=#000000 gui=bold
" }}}
" {{{ Completion menus
hi WildMenu guifg=#7fbdff guibg=#425c78 gui=none
hi Pmenu guibg=#808080 guifg=#ffffff gui=bold
hi PmenuSel guibg=#cdcdfd guifg=#000000 gui=italic
hi PmenuSbar guibg=#000000 guifg=#444444
hi PmenuThumb guibg=#aaaaaa guifg=#aaaaaa
" }}}
" {{{ Spelling
hi spellBad guisp=#fcaf3e
hi spellCap guisp=#73d216
hi spellRare guisp=#fcaf3e
hi spellLocal guisp=#729fcf
" }}}
" {{{ Aliases
hi link cppSTL Function
hi link cppSTLType Type
hi link Character Number
hi link htmlTag htmlEndTag
"hi link htmlTagName htmlTag
hi link htmlLink Underlined
hi link pythonFunction Identifier
hi link Question Type
hi link CursorIM Cursor
hi link VisualNOS Visual
hi link xmlTag Identifier
hi link xmlTagName Identifier
hi link shDeref Identifier
hi link shVariable Function
hi link rubySharpBang Special
hi link perlSharpBang Special
hi link schemeFunc Statement
"hi link shSpecialVariables Constant
"hi link bashSpecialVariables Constant
" }}}
" {{{ Tabs (non-gui0
hi TabLine guifg=#404040 guibg=#dddddd gui=none
hi TabLineFill guifg=#404040 guibg=#dddddd gui=none
hi TabLineSel guifg=#404040 gui=bold
" }}}
"
" vim: sw=4 ts=4 foldmethod=marker

View File

@@ -0,0 +1,218 @@
" Vim color file
" Name: inkpot.vim
" Maintainer: Ciaran McCreesh <ciaran.mccreesh@googlemail.com>
" Homepage: http://github.com/ciaranm/inkpot/
"
" This should work in the GUI, rxvt-unicode (88 colour mode) and xterm (256
" colour mode). It won't work in 8/16 colour terminals.
"
" To use a black background, :let g:inkpot_black_background = 1
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let colors_name = "inkpot"
" map a urxvt cube number to an xterm-256 cube number
fun! <SID>M(a)
return strpart("0135", a:a, 1) + 0
endfun
" map a urxvt colour to an xterm-256 colour
fun! <SID>X(a)
if &t_Co == 88
return a:a
else
if a:a == 8
return 237
elseif a:a < 16
return a:a
elseif a:a > 79
return 232 + (3 * (a:a - 80))
else
let l:b = a:a - 16
let l:x = l:b % 4
let l:y = (l:b / 4) % 4
let l:z = (l:b / 16)
return 16 + <SID>M(l:x) + (6 * <SID>M(l:y)) + (36 * <SID>M(l:z))
endif
endif
endfun
if ! exists("g:inkpot_black_background")
let g:inkpot_black_background = 0
endif
if has("gui_running")
if ! g:inkpot_black_background
hi Normal gui=NONE guifg=#cfbfad guibg=#1e1e27
else
hi Normal gui=NONE guifg=#cfbfad guibg=#000000
endif
hi CursorLine guibg=#2e2e37
" gryf: added colorcolumn highlight
hi ColorColumn guibg=#2e2e37
hi IncSearch gui=BOLD guifg=#303030 guibg=#cd8b60
hi Search gui=NONE guifg=#303030 guibg=#ad7b57
hi ErrorMsg gui=BOLD guifg=#ffffff guibg=#ce4e4e
hi WarningMsg gui=BOLD guifg=#ffffff guibg=#ce8e4e
hi ModeMsg gui=BOLD guifg=#7e7eae guibg=NONE
hi MoreMsg gui=BOLD guifg=#7e7eae guibg=NONE
hi Question gui=BOLD guifg=#ffcd00 guibg=NONE
hi StatusLine gui=BOLD guifg=#b9b9b9 guibg=#3e3e5e
hi User1 gui=BOLD guifg=#00ff8b guibg=#3e3e5e
hi User2 gui=BOLD guifg=#7070a0 guibg=#3e3e5e
hi StatusLineNC gui=NONE guifg=#b9b9b9 guibg=#3e3e5e
hi VertSplit gui=NONE guifg=#b9b9b9 guibg=#3e3e5e
hi WildMenu gui=BOLD guifg=#eeeeee guibg=#6e6eaf
hi MBENormal guifg=#cfbfad guibg=#2e2e3f
hi MBEChanged guifg=#eeeeee guibg=#2e2e3f
hi MBEVisibleNormal guifg=#cfcfcd guibg=#4e4e8f
hi MBEVisibleChanged guifg=#eeeeee guibg=#4e4e8f
hi DiffText gui=NONE guifg=#ffffcd guibg=#4a2a4a
hi DiffChange gui=NONE guifg=#ffffcd guibg=#306b8f
hi DiffDelete gui=NONE guifg=#ffffcd guibg=#6d3030
hi DiffAdd gui=NONE guifg=#ffffcd guibg=#306d30
hi Cursor gui=NONE guifg=#404040 guibg=#8b8bff
hi lCursor gui=NONE guifg=#404040 guibg=#8fff8b
hi CursorIM gui=NONE guifg=#404040 guibg=#8b8bff
hi Folded gui=NONE guifg=#cfcfcd guibg=#4b208f
hi FoldColumn gui=NONE guifg=#8b8bcd guibg=#2e2e2e
hi Directory gui=NONE guifg=#00ff8b guibg=NONE
hi LineNr gui=NONE guifg=#8b8bcd guibg=#2e2e2e
hi NonText gui=BOLD guifg=#8b8bcd guibg=NONE
hi SpecialKey gui=BOLD guifg=#ab60ed guibg=NONE
hi Title gui=BOLD guifg=#af4f4b guibg=NONE
hi Visual gui=NONE guifg=#eeeeee guibg=#4e4e8f
hi Comment gui=NONE guifg=#cd8b00 guibg=NONE
hi Constant gui=NONE guifg=#ffcd8b guibg=NONE
hi String gui=NONE guifg=#ffcd8b guibg=#404040
hi Error gui=NONE guifg=#ffffff guibg=#6e2e2e
hi Identifier gui=NONE guifg=#ff8bff guibg=NONE
hi Ignore gui=NONE
hi Number gui=NONE guifg=#f0ad6d guibg=NONE
hi PreProc gui=NONE guifg=#409090 guibg=NONE
hi Special gui=NONE guifg=#c080d0 guibg=NONE
hi SpecialChar gui=NONE guifg=#c080d0 guibg=#404040
hi Statement gui=NONE guifg=#808bed guibg=NONE
hi Todo gui=BOLD guifg=#303030 guibg=#d0a060
hi Type gui=NONE guifg=#ff8bff guibg=NONE
hi Underlined gui=BOLD guifg=#df9f2d guibg=NONE
hi TaglistTagName gui=BOLD guifg=#808bed guibg=NONE
hi perlSpecialMatch gui=NONE guifg=#c080d0 guibg=#404040
hi perlSpecialString gui=NONE guifg=#c080d0 guibg=#404040
hi cSpecialCharacter gui=NONE guifg=#c080d0 guibg=#404040
hi cFormat gui=NONE guifg=#c080d0 guibg=#404040
hi doxygenBrief gui=NONE guifg=#fdab60 guibg=NONE
hi doxygenParam gui=NONE guifg=#fdd090 guibg=NONE
hi doxygenPrev gui=NONE guifg=#fdd090 guibg=NONE
hi doxygenSmallSpecial gui=NONE guifg=#fdd090 guibg=NONE
hi doxygenSpecial gui=NONE guifg=#fdd090 guibg=NONE
hi doxygenComment gui=NONE guifg=#ad7b20 guibg=NONE
hi doxygenSpecial gui=NONE guifg=#fdab60 guibg=NONE
hi doxygenSpecialMultilineDesc gui=NONE guifg=#ad600b guibg=NONE
hi doxygenSpecialOnelineDesc gui=NONE guifg=#ad600b guibg=NONE
if v:version >= 700
hi Pmenu gui=NONE guifg=#eeeeee guibg=#4e4e8f
hi PmenuSel gui=BOLD guifg=#eeeeee guibg=#2e2e3f
hi PmenuSbar gui=BOLD guifg=#eeeeee guibg=#6e6eaf
hi PmenuThumb gui=BOLD guifg=#eeeeee guibg=#6e6eaf
hi SpellBad gui=undercurl guisp=#cc6666
hi SpellRare gui=undercurl guisp=#cc66cc
hi SpellLocal gui=undercurl guisp=#cccc66
hi SpellCap gui=undercurl guisp=#66cccc
hi MatchParen gui=NONE guifg=#cfbfad guibg=#4e4e8f
endif
else
if ! g:inkpot_black_background
exec "hi Normal cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(80)
else
exec "hi Normal cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(16)
endif
exec "hi IncSearch cterm=BOLD ctermfg=" . <SID>X(80) . " ctermbg=" . <SID>X(73)
exec "hi Search cterm=NONE ctermfg=" . <SID>X(80) . " ctermbg=" . <SID>X(52)
exec "hi ErrorMsg cterm=BOLD ctermfg=" . <SID>X(16) . " ctermbg=" . <SID>X(48)
exec "hi WarningMsg cterm=BOLD ctermfg=" . <SID>X(16) . " ctermbg=" . <SID>X(68)
exec "hi ModeMsg cterm=BOLD ctermfg=" . <SID>X(38) . " ctermbg=" . "NONE"
exec "hi MoreMsg cterm=BOLD ctermfg=" . <SID>X(38) . " ctermbg=" . "NONE"
exec "hi Question cterm=BOLD ctermfg=" . <SID>X(52) . " ctermbg=" . "NONE"
exec "hi StatusLine cterm=BOLD ctermfg=" . <SID>X(85) . " ctermbg=" . <SID>X(81)
exec "hi User1 cterm=BOLD ctermfg=" . <SID>X(28) . " ctermbg=" . <SID>X(81)
exec "hi User2 cterm=BOLD ctermfg=" . <SID>X(39) . " ctermbg=" . <SID>X(81)
exec "hi StatusLineNC cterm=NONE ctermfg=" . <SID>X(84) . " ctermbg=" . <SID>X(81)
exec "hi VertSplit cterm=NONE ctermfg=" . <SID>X(84) . " ctermbg=" . <SID>X(81)
exec "hi WildMenu cterm=BOLD ctermfg=" . <SID>X(87) . " ctermbg=" . <SID>X(38)
exec "hi MBENormal ctermfg=" . <SID>X(85) . " ctermbg=" . <SID>X(81)
exec "hi MBEChanged ctermfg=" . <SID>X(87) . " ctermbg=" . <SID>X(81)
exec "hi MBEVisibleNormal ctermfg=" . <SID>X(85) . " ctermbg=" . <SID>X(82)
exec "hi MBEVisibleChanged ctermfg=" . <SID>X(87) . " ctermbg=" . <SID>X(82)
exec "hi DiffText cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(34)
exec "hi DiffChange cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(17)
exec "hi DiffDelete cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(32)
exec "hi DiffAdd cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(20)
exec "hi Folded cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(35)
exec "hi FoldColumn cterm=NONE ctermfg=" . <SID>X(39) . " ctermbg=" . <SID>X(80)
exec "hi Directory cterm=NONE ctermfg=" . <SID>X(28) . " ctermbg=" . "NONE"
exec "hi LineNr cterm=NONE ctermfg=" . <SID>X(39) . " ctermbg=" . <SID>X(80)
exec "hi NonText cterm=BOLD ctermfg=" . <SID>X(39) . " ctermbg=" . "NONE"
exec "hi SpecialKey cterm=BOLD ctermfg=" . <SID>X(55) . " ctermbg=" . "NONE"
exec "hi Title cterm=BOLD ctermfg=" . <SID>X(48) . " ctermbg=" . "NONE"
exec "hi Visual cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(38)
exec "hi Comment cterm=NONE ctermfg=" . <SID>X(52) . " ctermbg=" . "NONE"
exec "hi Constant cterm=NONE ctermfg=" . <SID>X(73) . " ctermbg=" . "NONE"
exec "hi String cterm=NONE ctermfg=" . <SID>X(73) . " ctermbg=" . <SID>X(81)
exec "hi Error cterm=NONE ctermfg=" . <SID>X(79) . " ctermbg=" . <SID>X(32)
exec "hi Identifier cterm=NONE ctermfg=" . <SID>X(53) . " ctermbg=" . "NONE"
exec "hi Ignore cterm=NONE"
exec "hi Number cterm=NONE ctermfg=" . <SID>X(69) . " ctermbg=" . "NONE"
exec "hi PreProc cterm=NONE ctermfg=" . <SID>X(25) . " ctermbg=" . "NONE"
exec "hi Special cterm=NONE ctermfg=" . <SID>X(55) . " ctermbg=" . "NONE"
exec "hi SpecialChar cterm=NONE ctermfg=" . <SID>X(55) . " ctermbg=" . <SID>X(81)
exec "hi Statement cterm=NONE ctermfg=" . <SID>X(27) . " ctermbg=" . "NONE"
exec "hi Todo cterm=BOLD ctermfg=" . <SID>X(16) . " ctermbg=" . <SID>X(57)
exec "hi Type cterm=NONE ctermfg=" . <SID>X(71) . " ctermbg=" . "NONE"
exec "hi Underlined cterm=BOLD ctermfg=" . <SID>X(77) . " ctermbg=" . "NONE"
exec "hi TaglistTagName cterm=BOLD ctermfg=" . <SID>X(39) . " ctermbg=" . "NONE"
if v:version >= 700
exec "hi Pmenu cterm=NONE ctermfg=" . <SID>X(87) . " ctermbg=" . <SID>X(82)
exec "hi PmenuSel cterm=BOLD ctermfg=" . <SID>X(87) . " ctermbg=" . <SID>X(38)
exec "hi PmenuSbar cterm=BOLD ctermfg=" . <SID>X(87) . " ctermbg=" . <SID>X(39)
exec "hi PmenuThumb cterm=BOLD ctermfg=" . <SID>X(87) . " ctermbg=" . <SID>X(39)
exec "hi SpellBad cterm=NONE ctermbg=" . <SID>X(32)
exec "hi SpellRare cterm=NONE ctermbg=" . <SID>X(33)
exec "hi SpellLocal cterm=NONE ctermbg=" . <SID>X(36)
exec "hi SpellCap cterm=NONE ctermbg=" . <SID>X(21)
exec "hi MatchParen cterm=NONE ctermbg=" . <SID>X(14) . "ctermfg=" . <SID>X(25)
endif
endif
" vim: set et :

View File

@@ -0,0 +1,213 @@
" ir_black color scheme
" More at: http://blog.infinitered.com/entries/show/8
" ********************************************************************************
" Standard colors used in all ir_black themes:
" Note, x:x:x are RGB values
"
" normal: #f6f3e8
"
" string: #A8FF60 168:255:96
" string inner (punc, code, etc): #00A0A0 0:160:160
" number: #FF73FD 255:115:253
" comments: #7C7C7C 124:124:124
" keywords: #96CBFE 150:203:254
" operators: white
" class: #FFFFB6 255:255:182
" method declaration name: #FFD2A7 255:210:167
" regular expression: #E9C062 233:192:98
" regexp alternate: #FF8000 255:128:0
" regexp alternate 2: #B18A3D 177:138:61
" variable: #C6C5FE 198:197:254
"
" Misc colors:
" red color (used for whatever): #FF6C60 255:108:96
" light red: #FFB6B0 255:182:176
"
" brown: #E18964 good for special
"
" lightpurpleish: #FFCCFF
"
" Interface colors:
" background color: black
" cursor (where underscore is used): #FFA560 255:165:96
" cursor (where block is used): white
" visual selection: #1D1E2C
" current line: #151515 21:21:21
" search selection: #07281C 7:40:28
" line number: #3D3D3D 61:61:61
" ********************************************************************************
" The following are the preferred 16 colors for your terminal
" Colors Bright Colors
" Black #4E4E4E #7C7C7C
" Red #FF6C60 #FFB6B0
" Green #A8FF60 #CEFFAB
" Yellow #FFFFB6 #FFFFCB
" Blue #96CBFE #FFFFCB
" Magenta #FF73FD #FF9CFE
" Cyan #C6C5FE #DFDFFE
" White #EEEEEE #FFFFFF
" ********************************************************************************
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let colors_name = "ir_black"
"hi Example guifg=NONE guibg=NONE gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
" General colors
hi Normal guifg=#f6f3e8 guibg=black gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
hi NonText guifg=#070707 guibg=black gui=NONE ctermfg=black ctermbg=NONE cterm=NONE
hi Cursor guifg=black guibg=white gui=NONE ctermfg=black ctermbg=white cterm=reverse
hi LineNr guifg=#3D3D3D guibg=black gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE
hi VertSplit guifg=#202020 guibg=#202020 gui=NONE ctermfg=darkgray ctermbg=darkgray cterm=NONE
hi StatusLine guifg=#CCCCCC guibg=#202020 gui=italic ctermfg=white ctermbg=darkgray cterm=NONE
hi StatusLineNC guifg=black guibg=#202020 gui=NONE ctermfg=blue ctermbg=darkgray cterm=NONE
hi Folded guifg=#a0a8b0 guibg=#384048 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
hi Title guifg=#f6f3e8 guibg=NONE gui=bold ctermfg=NONE ctermbg=NONE cterm=NONE
hi Visual guifg=NONE guibg=#262D51 gui=NONE ctermfg=NONE ctermbg=darkgray cterm=NONE
hi SpecialKey guifg=#808080 guibg=#343434 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
hi WildMenu guifg=green guibg=yellow gui=NONE ctermfg=black ctermbg=yellow cterm=NONE
hi PmenuSbar guifg=black guibg=white gui=NONE ctermfg=black ctermbg=white cterm=NONE
"hi Ignore guifg=gray guibg=black gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
hi Error guifg=NONE guibg=NONE gui=undercurl ctermfg=white ctermbg=red cterm=NONE guisp=#FF6C60 " undercurl color
hi ErrorMsg guifg=white guibg=#FF6C60 gui=BOLD ctermfg=white ctermbg=red cterm=NONE
hi WarningMsg guifg=white guibg=#FF6C60 gui=BOLD ctermfg=white ctermbg=red cterm=NONE
" Message displayed in lower left, such as --INSERT--
hi ModeMsg guifg=black guibg=#C6C5FE gui=BOLD ctermfg=black ctermbg=cyan cterm=BOLD
if version >= 700 " Vim 7.x specific colors
hi CursorLine guifg=NONE guibg=#121212 gui=NONE ctermfg=NONE ctermbg=NONE cterm=BOLD
hi CursorColumn guifg=NONE guibg=#121212 gui=NONE ctermfg=NONE ctermbg=NONE cterm=BOLD
hi ColorColumn guifg=NONE guibg=#121212 gui=NONE ctermfg=NONE ctermbg=NONE cterm=BOLD
hi MatchParen guifg=#f6f3e8 guibg=#857b6f gui=BOLD ctermfg=white ctermbg=darkgray cterm=NONE
hi Pmenu guifg=#f6f3e8 guibg=#444444 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
hi PmenuSel guifg=#000000 guibg=#cae682 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
hi Search guifg=NONE guibg=NONE gui=underline ctermfg=NONE ctermbg=NONE cterm=underline
endif
" Syntax highlighting
hi Comment guifg=#7C7C7C guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE
hi String guifg=#A8FF60 guibg=NONE gui=NONE ctermfg=green ctermbg=NONE cterm=NONE
hi Number guifg=#FF73FD guibg=NONE gui=NONE ctermfg=magenta ctermbg=NONE cterm=NONE
hi Keyword guifg=#96CBFE guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE
hi PreProc guifg=#96CBFE guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE
hi Conditional guifg=#6699CC guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE " if else end
hi Todo guifg=#8f8f8f guibg=NONE gui=NONE ctermfg=red ctermbg=NONE cterm=NONE
hi Constant guifg=#99CC99 guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE
hi Identifier guifg=#C6C5FE guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE
hi Function guifg=#FFD2A7 guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE
hi Type guifg=#FFFFB6 guibg=NONE gui=NONE ctermfg=yellow ctermbg=NONE cterm=NONE
hi Statement guifg=#6699CC guibg=NONE gui=NONE ctermfg=lightblue ctermbg=NONE cterm=NONE
hi Special guifg=#E18964 guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE
hi Delimiter guifg=#00A0A0 guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE
hi Operator guifg=white guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE
hi link Character Constant
hi link Boolean Constant
hi link Float Number
hi link Repeat Statement
hi link Label Statement
hi link Exception Statement
hi link Include PreProc
hi link Define PreProc
hi link Macro PreProc
hi link PreCondit PreProc
hi link StorageClass Type
hi link Structure Type
hi link Typedef Type
hi link Tag Special
hi link SpecialChar Special
hi link SpecialComment Special
hi link Debug Special
" Special for Ruby
hi rubyRegexp guifg=#B18A3D guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE
hi rubyRegexpDelimiter guifg=#FF8000 guibg=NONE gui=NONE ctermfg=brown ctermbg=NONE cterm=NONE
hi rubyEscape guifg=white guibg=NONE gui=NONE ctermfg=cyan ctermbg=NONE cterm=NONE
hi rubyInterpolationDelimiter guifg=#00A0A0 guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE
hi rubyControl guifg=#6699CC guibg=NONE gui=NONE ctermfg=blue ctermbg=NONE cterm=NONE "and break, etc
"hi rubyGlobalVariable guifg=#FFCCFF guibg=NONE gui=NONE ctermfg=lightblue ctermbg=NONE cterm=NONE "yield
hi rubyStringDelimiter guifg=#336633 guibg=NONE gui=NONE ctermfg=lightgreen ctermbg=NONE cterm=NONE
"rubyInclude
"rubySharpBang
"rubyAccess
"rubyPredefinedVariable
"rubyBoolean
"rubyClassVariable
"rubyBeginEnd
"rubyRepeatModifier
"hi link rubyArrayDelimiter Special " [ , , ]
"rubyCurlyBlock { , , }
hi link rubyClass Keyword
hi link rubyModule Keyword
hi link rubyKeyword Keyword
hi link rubyOperator Operator
hi link rubyIdentifier Identifier
hi link rubyInstanceVariable Identifier
hi link rubyGlobalVariable Identifier
hi link rubyClassVariable Identifier
hi link rubyConstant Type
" Special for Java
" hi link javaClassDecl Type
hi link javaScopeDecl Identifier
hi link javaCommentTitle javaDocSeeTag
hi link javaDocTags javaDocSeeTag
hi link javaDocParam javaDocSeeTag
hi link javaDocSeeTagParam javaDocSeeTag
hi javaDocSeeTag guifg=#CCCCCC guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE
hi javaDocSeeTag guifg=#CCCCCC guibg=NONE gui=NONE ctermfg=darkgray ctermbg=NONE cterm=NONE
"hi javaClassDecl guifg=#CCFFCC guibg=NONE gui=NONE ctermfg=white ctermbg=NONE cterm=NONE
" Special for XML
hi link xmlTag Keyword
hi link xmlTagName Conditional
hi link xmlEndTag Identifier
" Special for HTML
hi link htmlTag Keyword
hi link htmlTagName Conditional
hi link htmlEndTag Identifier
" Special for Javascript
hi link javaScriptNumber Number
" Special for Python
"hi link pythonEscape Keyword
" Special for CSharp
hi link csXmlTag Keyword
" Special for PHP

View File

@@ -0,0 +1,491 @@
" Vim color file
"
" " __ _ _ _ "
" " \ \ ___| | |_ _| |__ ___ __ _ _ __ ___ "
" " \ \/ _ \ | | | | | _ \ / _ \/ _ | _ \/ __| "
" " /\_/ / __/ | | |_| | |_| | __/ |_| | | | \__ \ "
" " \___/ \___|_|_|\__ |____/ \___|\____|_| |_|___/ "
" " \___/ "
"
" "A colorful, dark color scheme for Vim."
"
" File: jellybeans.vim
" Maintainer: NanoTech <http://nanotech.nanotechcorp.net/>
" Version: 1.5
" Last Change: January 15th, 2012
" Contributors: Daniel Herbert <http://pocket-ninja.com/>,
" Henry So, Jr. <henryso@panix.com>,
" David Liang <bmdavll at gmail dot com>,
" Rich Healey (richoH),
" Andrew Wong (w0ng)
"
" Copyright (c) 2009-2012 NanoTech
"
" 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.
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let colors_name = "jellybeans"
if has("gui_running") || &t_Co == 88 || &t_Co == 256
let s:low_color = 0
else
let s:low_color = 1
endif
" Color approximation functions by Henry So, Jr. and David Liang {{{
" Added to jellybeans.vim by Daniel Herbert
" returns an approximate grey index for the given grey level
fun! s:grey_number(x)
if &t_Co == 88
if a:x < 23
return 0
elseif a:x < 69
return 1
elseif a:x < 103
return 2
elseif a:x < 127
return 3
elseif a:x < 150
return 4
elseif a:x < 173
return 5
elseif a:x < 196
return 6
elseif a:x < 219
return 7
elseif a:x < 243
return 8
else
return 9
endif
else
if a:x < 14
return 0
else
let l:n = (a:x - 8) / 10
let l:m = (a:x - 8) % 10
if l:m < 5
return l:n
else
return l:n + 1
endif
endif
endif
endfun
" returns the actual grey level represented by the grey index
fun! s:grey_level(n)
if &t_Co == 88
if a:n == 0
return 0
elseif a:n == 1
return 46
elseif a:n == 2
return 92
elseif a:n == 3
return 115
elseif a:n == 4
return 139
elseif a:n == 5
return 162
elseif a:n == 6
return 185
elseif a:n == 7
return 208
elseif a:n == 8
return 231
else
return 255
endif
else
if a:n == 0
return 0
else
return 8 + (a:n * 10)
endif
endif
endfun
" returns the palette index for the given grey index
fun! s:grey_color(n)
if &t_Co == 88
if a:n == 0
return 16
elseif a:n == 9
return 79
else
return 79 + a:n
endif
else
if a:n == 0
return 16
elseif a:n == 25
return 231
else
return 231 + a:n
endif
endif
endfun
" returns an approximate color index for the given color level
fun! s:rgb_number(x)
if &t_Co == 88
if a:x < 69
return 0
elseif a:x < 172
return 1
elseif a:x < 230
return 2
else
return 3
endif
else
if a:x < 75
return 0
else
let l:n = (a:x - 55) / 40
let l:m = (a:x - 55) % 40
if l:m < 20
return l:n
else
return l:n + 1
endif
endif
endif
endfun
" returns the actual color level for the given color index
fun! s:rgb_level(n)
if &t_Co == 88
if a:n == 0
return 0
elseif a:n == 1
return 139
elseif a:n == 2
return 205
else
return 255
endif
else
if a:n == 0
return 0
else
return 55 + (a:n * 40)
endif
endif
endfun
" returns the palette index for the given R/G/B color indices
fun! s:rgb_color(x, y, z)
if &t_Co == 88
return 16 + (a:x * 16) + (a:y * 4) + a:z
else
return 16 + (a:x * 36) + (a:y * 6) + a:z
endif
endfun
" returns the palette index to approximate the given R/G/B color levels
fun! s:color(r, g, b)
" get the closest grey
let l:gx = s:grey_number(a:r)
let l:gy = s:grey_number(a:g)
let l:gz = s:grey_number(a:b)
" get the closest color
let l:x = s:rgb_number(a:r)
let l:y = s:rgb_number(a:g)
let l:z = s:rgb_number(a:b)
if l:gx == l:gy && l:gy == l:gz
" there are two possibilities
let l:dgr = s:grey_level(l:gx) - a:r
let l:dgg = s:grey_level(l:gy) - a:g
let l:dgb = s:grey_level(l:gz) - a:b
let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
let l:dr = s:rgb_level(l:gx) - a:r
let l:dg = s:rgb_level(l:gy) - a:g
let l:db = s:rgb_level(l:gz) - a:b
let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
if l:dgrey < l:drgb
" use the grey
return s:grey_color(l:gx)
else
" use the color
return s:rgb_color(l:x, l:y, l:z)
endif
else
" only one possibility
return s:rgb_color(l:x, l:y, l:z)
endif
endfun
" returns the palette index to approximate the 'rrggbb' hex string
fun! s:rgb(rgb)
let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
return s:color(l:r, l:g, l:b)
endfun
" sets the highlighting for the given group
fun! s:X(group, fg, bg, attr, lcfg, lcbg)
if s:low_color
let l:fge = empty(a:lcfg)
let l:bge = empty(a:lcbg)
if !l:fge && !l:bge
exec "hi ".a:group." ctermfg=".a:lcfg." ctermbg=".a:lcbg
elseif !l:fge && l:bge
exec "hi ".a:group." ctermfg=".a:lcfg." ctermbg=NONE"
elseif l:fge && !l:bge
exec "hi ".a:group." ctermfg=NONE ctermbg=".a:lcbg
endif
else
let l:fge = empty(a:fg)
let l:bge = empty(a:bg)
if !l:fge && !l:bge
exec "hi ".a:group." guifg=#".a:fg." guibg=#".a:bg." ctermfg=".s:rgb(a:fg)." ctermbg=".s:rgb(a:bg)
elseif !l:fge && l:bge
exec "hi ".a:group." guifg=#".a:fg." guibg=NONE ctermfg=".s:rgb(a:fg)." ctermbg=NONE"
elseif l:fge && !l:bge
exec "hi ".a:group." guifg=NONE guibg=#".a:bg." ctermfg=NONE ctermbg=".s:rgb(a:bg)
endif
endif
if a:attr == ""
exec "hi ".a:group." gui=none cterm=none"
else
let noitalic = join(filter(split(a:attr, ","), "v:val !=? 'italic'"), ",")
if empty(noitalic)
let noitalic = "none"
endif
exec "hi ".a:group." gui=".a:attr." cterm=".noitalic
endif
endfun
" }}}
call s:X("Normal","e8e8d3","151515","","White","")
set background=dark
if !exists("g:jellybeans_use_lowcolor_black") || g:jellybeans_use_lowcolor_black
let s:termBlack = "Black"
else
let s:termBlack = "Grey"
endif
if version >= 700
call s:X("CursorLine","","1c1c1c","","",s:termBlack)
call s:X("CursorColumn","","1c1c1c","","",s:termBlack)
call s:X("MatchParen","ffffff","80a090","bold","","DarkCyan")
call s:X("TabLine","000000","b0b8c0","italic","",s:termBlack)
call s:X("TabLineFill","9098a0","","","",s:termBlack)
call s:X("TabLineSel","000000","f0f0f0","italic,bold",s:termBlack,"White")
" Auto-completion
call s:X("Pmenu","ffffff","606060","","White",s:termBlack)
call s:X("PmenuSel","101010","eeeeee","",s:termBlack,"White")
endif
call s:X("Visual","","404040","","",s:termBlack)
call s:X("Cursor","","b0d0f0","","","")
call s:X("LineNr","605958","151515","none",s:termBlack,"")
call s:X("Comment","888888","","italic","Grey","")
call s:X("Todo","808080","","bold","White",s:termBlack)
call s:X("StatusLine","000000","dddddd","italic","","White")
call s:X("StatusLineNC","ffffff","403c41","italic","White","Black")
call s:X("VertSplit","777777","403c41","",s:termBlack,s:termBlack)
call s:X("WildMenu","f0a0c0","302028","","Magenta","")
call s:X("Folded","a0a8b0","384048","italic",s:termBlack,"")
call s:X("FoldColumn","535D66","1f1f1f","","",s:termBlack)
call s:X("SignColumn","777777","333333","","",s:termBlack)
call s:X("ColorColumn","","000000","","",s:termBlack)
call s:X("Title","70b950","","bold","Green","")
call s:X("Constant","cf6a4c","","","Red","")
call s:X("Special","799d6a","","","Green","")
call s:X("Delimiter","668799","","","Grey","")
call s:X("String","99ad6a","","","Green","")
call s:X("StringDelimiter","556633","","","DarkGreen","")
call s:X("Identifier","c6b6ee","","","LightCyan","")
call s:X("Structure","8fbfdc","","","LightCyan","")
call s:X("Function","fad07a","","","Yellow","")
call s:X("Statement","8197bf","","","DarkBlue","")
call s:X("PreProc","8fbfdc","","","LightBlue","")
hi! link Operator Normal
call s:X("Type","ffb964","","","Yellow","")
call s:X("NonText","606060","151515","",s:termBlack,"")
call s:X("SpecialKey","444444","1c1c1c","",s:termBlack,"")
call s:X("Search","f0a0c0","302028","underline","Magenta","")
call s:X("Directory","dad085","","","Yellow","")
call s:X("ErrorMsg","","902020","","","DarkRed")
hi! link Error ErrorMsg
hi! link MoreMsg Special
call s:X("Question","65C254","","","Green","")
" Spell Checking
call s:X("SpellBad","","902020","underline","","DarkRed")
call s:X("SpellCap","","0000df","underline","","Blue")
call s:X("SpellRare","","540063","underline","","DarkMagenta")
call s:X("SpellLocal","","2D7067","underline","","Green")
" Diff
hi! link diffRemoved Constant
hi! link diffAdded String
" VimDiff
call s:X("DiffAdd","D2EBBE","437019","","White","DarkGreen")
call s:X("DiffDelete","40000A","700009","","DarkRed","DarkRed")
call s:X("DiffChange","","2B5B77","","White","DarkBlue")
call s:X("DiffText","8fbfdc","000000","reverse","Yellow","")
" PHP
hi! link phpFunctions Function
call s:X("StorageClass","c59f6f","","","Red","")
hi! link phpSuperglobal Identifier
hi! link phpQuoteSingle StringDelimiter
hi! link phpQuoteDouble StringDelimiter
hi! link phpBoolean Constant
hi! link phpNull Constant
hi! link phpArrayPair Operator
" Ruby
hi! link rubySharpBang Comment
call s:X("rubyClass","447799","","","DarkBlue","")
call s:X("rubyIdentifier","c6b6fe","","","Cyan","")
hi! link rubyConstant Type
hi! link rubyFunction Function
call s:X("rubyInstanceVariable","c6b6fe","","","Cyan","")
call s:X("rubySymbol","7697d6","","","Blue","")
hi! link rubyGlobalVariable rubyInstanceVariable
hi! link rubyModule rubyClass
call s:X("rubyControl","7597c6","","","Blue","")
hi! link rubyString String
hi! link rubyStringDelimiter StringDelimiter
hi! link rubyInterpolationDelimiter Identifier
call s:X("rubyRegexpDelimiter","540063","","","Magenta","")
call s:X("rubyRegexp","dd0093","","","DarkMagenta","")
call s:X("rubyRegexpSpecial","a40073","","","Magenta","")
call s:X("rubyPredefinedIdentifier","de5577","","","Red","")
" JavaScript
hi! link javaScriptValue Constant
hi! link javaScriptRegexpString rubyRegexp
" CoffeeScript
hi! link coffeeRegExp javaScriptRegexpString
" Lua
hi! link luaOperator Conditional
" C
hi! link cOperator Constant
" Objective-C/Cocoa
hi! link objcClass Type
hi! link cocoaClass objcClass
hi! link objcSubclass objcClass
hi! link objcSuperclass objcClass
hi! link objcDirective rubyClass
hi! link objcStatement Constant
hi! link cocoaFunction Function
hi! link objcMethodName Identifier
hi! link objcMethodArg Normal
hi! link objcMessageName Identifier
" Debugger.vim
call s:X("DbgCurrent","DEEBFE","345FA8","","White","DarkBlue")
call s:X("DbgBreakPt","","4F0037","","","DarkMagenta")
" vim-indent-guides
if !exists("g:indent_guides_auto_colors")
let g:indent_guides_auto_colors = 0
endif
call s:X("IndentGuidesOdd","","202020","","","")
call s:X("IndentGuidesEven","","1c1c1c","","","")
" Plugins, etc.
hi! link TagListFileName Directory
call s:X("PreciseJumpTarget","B9ED67","405026","","White","Green")
" Manual overrides for 256-color terminals. Dark colors auto-map badly.
if !s:low_color
hi StatusLineNC ctermbg=235
hi Folded ctermbg=236
hi FoldColumn ctermbg=234
hi SignColumn ctermbg=236
hi CursorColumn ctermbg=234
hi CursorLine ctermbg=234
hi SpecialKey ctermbg=234
hi NonText ctermbg=233
hi LineNr ctermbg=233
hi DiffText ctermfg=81
hi Normal ctermbg=233
hi DbgBreakPt ctermbg=53
endif
" delete functions {{{
delf s:X
delf s:rgb
delf s:color
delf s:rgb_color
delf s:rgb_level
delf s:rgb_number
delf s:grey_color
delf s:grey_level
delf s:grey_number
" }}}

View File

@@ -0,0 +1,259 @@
" Lucius vim color file
" Maintainer: Jonathan Filip <jfilip1024@gmail.com>
" Version: 6.1.0
hi clear
if exists("syntax_on")
syntax reset
endif
let colors_name="lucius"
" Summary:
" Color scheme with dark and light versions (GUI and 256 color terminal).
" Description:
" This color scheme was originally created by combining my favorite parts of
" the following color schemes:
"
" * oceandeep (vimscript #368)
" * peaksea (vimscript #760)
" * wombat (vimscript #1778)
" * moria (vimscript #1464)
" * zenburn (vimscript #415)
"
" Version 6+ has been revamped a bit from the original color scheme. If you
" prefer the old style, or the 'blue' version, use the 5Final release. Version
" 6+ only has a light and dark version. The new version tries to unify some of
" the colors and also adds more contrast between text and interface.
"
" The color scheme is dark, by default. You can change this by setting the
" g:lucius_style variable to "light" or "dark". Once the color scheme is
" loaded, you can use the commands "LuciusLight" or "LuciusDark" to change
" schemes quickly.
"
" Screenshots of the new version (6+):
"
" * Dark: http://i.imgur.com/IzYcB.png
" * Light: http://i.imgur.com/kfJcm.png
"
" Screenshots of the old versions (5Final):
"
" * Dark: http://i.imgur.com/z0bDr.png
" * Light: http://i.imgur.com/BXDiv.png
" * Blue: http://i.imgur.com/Ea1Gq.png
"
" colorsupport.vim (vimscript #2682) is used to help with mapping the GUI
" settings to the 256 terminal colors.
"
" This color scheme also has custom colors defined for the following plugins:
"
" * vimwiki (vimscript #2226)
" * tagbar (vimscript #3465)
"
" Installation:
" Copy the file to your vim colors directory and then do :colorscheme lucius.
set background=dark
if exists("g:lucius_style")
if g:lucius_style == "light"
set background=light
endif
else
let g:lucius_style="dark"
endif
" set colorcolumn=21,37,53,68,86,100
if g:lucius_style == "dark" || g:lucius_style == "blue"
hi Normal guifg=#e0e0e0 guibg=#202020 ctermfg=253 ctermbg=234 gui=none cterm=none
if g:lucius_style == "blue"
hi Normal guibg=#002b36
endif
hi Comment guifg=#707070 guibg=NONE ctermfg=240 ctermbg=NONE gui=none cterm=none
hi Constant guifg=#e0e090 guibg=NONE ctermfg=187 ctermbg=NONE gui=none cterm=none
hi BConstant guifg=#e0e090 guibg=NONE ctermfg=187 ctermbg=NONE gui=bold cterm=bold
hi Identifier guifg=#c0e0a0 guibg=NONE ctermfg=150 ctermbg=NONE gui=none cterm=none
hi BIdentifier guifg=#c0e0a0 guibg=NONE ctermfg=150 ctermbg=NONE gui=bold cterm=bold
hi Statement guifg=#80d0f0 guibg=NONE ctermfg=74 ctermbg=NONE gui=none cterm=none
hi BStatement guifg=#80d0f0 guibg=NONE ctermfg=74 ctermbg=NONE gui=bold cterm=bold
hi PreProc guifg=#a0e0d0 guibg=NONE ctermfg=115 ctermbg=NONE gui=none cterm=none
hi BPreProc guifg=#a0e0d0 guibg=NONE ctermfg=115 ctermbg=NONE gui=bold cterm=bold
hi Type guifg=#a0d0e0 guibg=NONE ctermfg=116 ctermbg=NONE gui=none cterm=none
hi BType guifg=#a0d0e0 guibg=NONE ctermfg=116 ctermbg=NONE gui=bold cterm=bold
hi Special guifg=#c0a0d0 guibg=NONE ctermfg=182 ctermbg=NONE gui=none cterm=none
hi BSpecial guifg=#c0a0d0 guibg=NONE ctermfg=182 ctermbg=NONE gui=bold cterm=bold
" == Text Markup ==
hi Underlined guifg=fg guibg=NONE ctermfg=fg ctermbg=NONE gui=underline cterm=underline
hi Error guifg=#e07070 guibg=#503030 ctermfg=167 ctermbg=236 gui=none cterm=none
hi Todo guifg=#e0e090 guibg=#505000 ctermfg=186 ctermbg=NONE gui=none cterm=none
hi MatchParen guifg=bg guibg=#c0e070 ctermfg=bg ctermbg=192 gui=none cterm=bold
hi NonText guifg=#405060 guibg=NONE ctermfg=24 ctermbg=NONE gui=none cterm=none
hi SpecialKey guifg=#406050 guibg=NONE ctermfg=23 ctermbg=NONE gui=none cterm=none
hi Title guifg=#50b0d0 guibg=NONE ctermfg=74 ctermbg=NONE gui=bold cterm=bold
" == Text Selection ==
hi Cursor guifg=bg guibg=fg ctermfg=bg ctermbg=fg gui=none cterm=none
hi CursorIM guifg=bg guibg=fg ctermfg=bg ctermbg=fg gui=none cterm=none
hi CursorColumn guifg=NONE guibg=#484848 ctermfg=NONE ctermbg=237 gui=none cterm=none
hi CursorLine guifg=NONE guibg=#484848 ctermfg=NONE ctermbg=237 gui=none cterm=none
hi Visual guifg=NONE guibg=#205070 ctermfg=NONE ctermbg=24 gui=none cterm=none
hi VisualNOS guifg=fg guibg=NONE ctermfg=fg ctermbg=NONE gui=underline cterm=underline
hi IncSearch guifg=bg guibg=#50d0d0 ctermfg=bg ctermbg=116 gui=none cterm=none
hi Search guifg=bg guibg=#e0a020 ctermfg=bg ctermbg=214 gui=none cterm=none
" == UI ==
hi Pmenu guifg=#000000 guibg=#b0b0b0 ctermfg=bg ctermbg=252 gui=none cterm=none
hi PmenuSel guifg=#e0e0e0 guibg=#205070 ctermfg=fg ctermbg=24 gui=none cterm=none
hi PMenuSbar guifg=bg guibg=#b0b0b0 ctermfg=bg ctermbg=254 gui=none cterm=none
hi PMenuThumb guifg=NONE guibg=#808080 ctermfg=fg ctermbg=244 gui=none cterm=none
hi StatusLine guifg=bg guibg=#b0b0b0 ctermfg=bg ctermbg=252 gui=bold cterm=bold
hi StatusLineNC guifg=#404040 guibg=#b0b0b0 ctermfg=240 ctermbg=252 gui=none cterm=none
hi TabLine guifg=bg guibg=#b0b0b0 ctermfg=bg ctermbg=252 gui=none cterm=none
hi TabLineFill guifg=#404040 guibg=#b0b0b0 ctermfg=240 ctermbg=252 gui=none cterm=none
hi TabLineSel guifg=#e0e0e0 guibg=#205070 ctermfg=fg ctermbg=24 gui=bold cterm=bold
hi VertSplit guifg=#606060 guibg=#b0b0b0 ctermfg=245 ctermbg=252 gui=none cterm=none
hi Folded guifg=bg guibg=#808080 ctermfg=bg ctermbg=246 gui=none cterm=none
hi FoldColumn guifg=bg guibg=#808080 ctermfg=bg ctermbg=246 gui=none cterm=none
" == Spelling =="{{{
hi SpellBad guisp=#ee0000 ctermfg=fg ctermbg=160 gui=undercurl cterm=undercurl
hi SpellCap guisp=#eeee00 ctermfg=bg ctermbg=226 gui=undercurl cterm=undercurl
hi SpellRare guisp=#ffa500 ctermfg=bg ctermbg=214 gui=undercurl cterm=undercurl
hi SpellLocal guisp=#ffa500 ctermfg=bg ctermbg=214 gui=undercurl cterm=undercurl"}}}
" == Diff ==
hi DiffAdd guifg=fg guibg=#405040 ctermfg=fg ctermbg=22 gui=none cterm=none
hi DiffChange guifg=fg guibg=#605040 ctermfg=fg ctermbg=58 gui=none cterm=none
hi DiffDelete guifg=fg guibg=#504040 ctermfg=fg ctermbg=52 gui=none cterm=none
hi DiffText guifg=#e0b050 guibg=#605040 ctermfg=220 ctermbg=58 gui=bold cterm=bold
" == Misc ==
hi Directory guifg=#b0d0a0 guibg=NONE ctermfg=151 ctermbg=NONE gui=none cterm=none
hi ErrorMsg guifg=#ee0000 guibg=NONE ctermfg=196 ctermbg=NONE gui=none cterm=none
hi SignColumn guifg=#a0b0b0 guibg=#282828 ctermfg=145 ctermbg=233 gui=none cterm=none
hi LineNr guifg=bg guibg=#808080 ctermfg=bg ctermbg=246 gui=none cterm=none
hi MoreMsg guifg=#60c0d0 guibg=NONE ctermfg=117 ctermbg=NONE gui=none cterm=none
hi ModeMsg guifg=fg guibg=NONE ctermfg=fg ctermbg=NONE gui=none cterm=none
hi Question guifg=fg guibg=NONE ctermfg=fg ctermbg=NONE gui=none cterm=none
hi WarningMsg guifg=#e07060 guibg=NONE ctermfg=173 ctermbg=NONE gui=none cterm=none
hi WildMenu guifg=NONE guibg=#205070 ctermfg=NONE ctermbg=24 gui=none cterm=none
hi ColorColumn guifg=NONE guibg=#484038 ctermfg=NONE ctermbg=101 gui=none cterm=none
hi Ignore guifg=bg ctermfg=bg
elseif g:lucius_style == "light"
hi Normal guifg=#000000 guibg=#ffffff ctermfg=16 ctermbg=231 gui=none cterm=none
hi Comment guifg=#909090 guibg=NONE ctermfg=246 ctermbg=NONE gui=none cterm=none
hi Constant guifg=#a05000 guibg=NONE ctermfg=130 ctermbg=NONE gui=none cterm=none
hi BConstant guifg=#a05000 guibg=NONE ctermfg=130 ctermbg=NONE gui=bold cterm=bold
hi Identifier guifg=#008000 guibg=NONE ctermfg=22 ctermbg=NONE gui=none cterm=none
hi BIdentifier guifg=#008000 guibg=NONE ctermfg=22 ctermbg=NONE gui=bold cterm=bold
hi Statement guifg=#0040c0 guibg=NONE ctermfg=19 ctermbg=NONE gui=none cterm=none
hi BStatement guifg=#0040c0 guibg=NONE ctermfg=19 ctermbg=NONE gui=bold cterm=bold
hi PreProc guifg=#009080 guibg=NONE ctermfg=30 ctermbg=NONE gui=none cterm=none
hi BPreProc guifg=#009080 guibg=NONE ctermfg=30 ctermbg=NONE gui=bold cterm=bold
hi Type guifg=#0070a0 guibg=NONE ctermfg=25 ctermbg=NONE gui=none cterm=none
hi BType guifg=#0070a0 guibg=NONE ctermfg=25 ctermbg=NONE gui=bold cterm=bold
hi Special guifg=#800080 guibg=NONE ctermfg=5 ctermbg=NONE gui=none cterm=none
hi BSpecial guifg=#800080 guibg=NONE ctermfg=5 ctermbg=NONE gui=bold cterm=bold
" == Text Markup ==
hi Underlined guifg=fg guibg=NONE ctermfg=fg ctermbg=NONE gui=underline cterm=underline
hi Error guifg=#c02620 guibg=#f0c6c0 ctermfg=1 ctermbg=181 gui=none cterm=none
hi Todo guifg=#504000 guibg=#f6f080 ctermfg=58 ctermbg=228 gui=none cterm=none
hi MatchParen guifg=NONE guibg=#40d0d0 ctermfg=NONE ctermbg=80 gui=none cterm=none
hi NonText guifg=#b0c0d0 guibg=NONE ctermfg=146 ctermbg=NONE gui=none cterm=none
hi SpecialKey guifg=#b0d0c0 guibg=NONE ctermfg=151 ctermbg=NONE gui=none cterm=none
hi Title guifg=#0060a0 guibg=NONE ctermfg=26 ctermbg=NONE gui=bold cterm=bold
" == Text Selection ==
hi Cursor guifg=bg guibg=#505050 ctermfg=bg ctermbg=239 gui=none cterm=none
hi CursorIM guifg=bg guibg=#505050 ctermfg=bg ctermbg=239 gui=none cterm=none
hi CursorColumn guifg=NONE guibg=#e8e8e8 ctermfg=NONE ctermbg=254 gui=none cterm=none
hi CursorLine guifg=NONE guibg=#e8e8e8 ctermfg=NONE ctermbg=254 gui=none cterm=none
hi Visual guifg=NONE guibg=#b0d0f0 ctermfg=NONE ctermbg=153 gui=none cterm=none
hi VisualNOS guifg=fg guibg=NONE ctermfg=fg ctermbg=NONE gui=underline cterm=underline
hi IncSearch guifg=#000000 guibg=#90d0d0 ctermfg=fg ctermbg=116 gui=none cterm=none
hi Search guifg=#000000 guibg=#f0b060 ctermfg=fg ctermbg=215 gui=none cterm=none
" == UI ==
hi Pmenu guifg=bg guibg=#505050 ctermfg=231 ctermbg=239 gui=none cterm=none
hi PmenuSel guifg=#000000 guibg=#c0e0ff ctermfg=16 ctermbg=153 gui=none cterm=none
hi PMenuSbar guifg=bg guibg=#404040 ctermfg=231 ctermbg=238 gui=none cterm=none
hi PMenuThumb guifg=#000000 guibg=#a0a0a0 ctermfg=16 ctermbg=247 gui=none cterm=none
hi StatusLine guifg=bg guibg=#505050 ctermfg=231 ctermbg=239 gui=bold cterm=bold
hi StatusLineNC guifg=#e0e0e0 guibg=#505050 ctermfg=254 ctermbg=239 gui=none cterm=none
hi TabLine guifg=bg guibg=#505050 ctermfg=231 ctermbg=239 gui=none cterm=none
hi TabLineFill guifg=#a0a0a0 guibg=#505050 ctermfg=247 ctermbg=239 gui=none cterm=none
hi TabLineSel guifg=#000000 guibg=#c0e0ff ctermfg=16 ctermbg=153 gui=none cterm=none
hi VertSplit guifg=#868686 guibg=#505050 ctermfg=102 ctermbg=239 gui=none cterm=none
hi Folded guifg=bg guibg=#a0a0a0 ctermfg=231 ctermbg=247 gui=none cterm=none
hi FoldColumn guifg=bg guibg=#a0a0a0 ctermfg=231 ctermbg=247 gui=none cterm=none
" == Spelling ==
hi SpellBad guisp=#ee0000 ctermbg=210 gui=undercurl cterm=undercurl
hi SpellCap guisp=#eeee00 ctermbg=227 gui=undercurl cterm=undercurl
hi SpellRare guisp=#ffa500 ctermbg=221 gui=undercurl cterm=undercurl
hi SpellLocal guisp=#ffa500 ctermbg=221 gui=undercurl cterm=undercurl
" == Diff ==
hi DiffAdd guifg=fg guibg=#d0e0d0 ctermfg=fg ctermbg=151 gui=none cterm=none
hi DiffChange guifg=fg guibg=#e0d6c0 ctermfg=fg ctermbg=187 gui=none cterm=none
hi DiffDelete guifg=fg guibg=#f0d0d0 ctermfg=fg ctermbg=181 gui=none cterm=none
hi DiffText guifg=#d05000 guibg=#e0d6c0 ctermfg=160 ctermbg=187 gui=bold cterm=bold
" == Misc ==
hi Directory guifg=#008000 guibg=NONE ctermfg=29 ctermbg=NONE gui=none cterm=none
hi ErrorMsg guifg=#a00000 guibg=NONE ctermfg=124 ctermbg=NONE gui=none cterm=none
hi SignColumn guifg=#708090 guibg=#f8f8f8 ctermfg=66 ctermbg=231 gui=none cterm=none
hi LineNr guifg=bg guibg=#a0a0a0 ctermfg=231 ctermbg=247 gui=none cterm=none
hi MoreMsg guifg=#2060c0 guibg=NONE ctermfg=4 ctermbg=NONE gui=none cterm=none
hi ModeMsg guifg=#000000 guibg=NONE ctermfg=16 ctermbg=NONE gui=none cterm=none
hi Question guifg=fg guibg=NONE ctermfg=NONE ctermbg=NONE gui=none cterm=none
hi WarningMsg guifg=#b03000 guibg=NONE ctermfg=9 ctermbg=NONE gui=none cterm=none
hi WildMenu guifg=#000000 guibg=#c0e0ff ctermfg=16 ctermbg=153 gui=none cterm=none
hi ColorColumn guifg=NONE guibg=#f0f0e0 ctermfg=NONE ctermbg=230 gui=none cterm=none
hi Ignore guifg=bg ctermfg=bg
endif
" == Vimwiki Colors ==
hi link VimwikiHeader1 BIdentifier
hi link VimwikiHeader2 BPreProc
hi link VimwikiHeader3 BStatement
hi link VimwikiHeader4 BSpecial
hi link VimwikiHeader5 BConstant
hi link VimwikiHeader6 BType
" == Tagbar Colors ==
hi link TagbarAccessPublic Constant
hi link TagbarAccessProtected Type
hi link TagbarAccessPrivate PreProc
" == Commands ==
command! LuciusLight let g:lucius_style = "light" | colorscheme lucius
command! LuciusDark let g:lucius_style = "dark" | colorscheme lucius
command! LuciusBlue let g:lucius_style = "blue" | colorscheme lucius

View File

@@ -0,0 +1,205 @@
" 'sorcerer.vim' -- Vim color scheme.
" Maintainer: Jeet Sukumaran
" Based on 'Mustang' by Henrique C. Alves (hcarvalhoalves@gmail.com),
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let colors_name = "sorcerer"
" GUI Colors {{{1
" ============================================================================
hi Normal guifg=#c2c2b0 guibg=#222222 gui=NONE
hi ColorColumn guifg=NONE guibg=#1c1c1c
hi Cursor guifg=NONE guibg=#626262 gui=NONE
hi CursorColumn guibg=#2d2d2d
hi CursorLine guibg=#2d2d2d
hi DiffAdd guifg=#000000 guibg=#3cb371 gui=NONE
hi DiffDelete guifg=#000000 guibg=#aa4450 gui=NONE
hi DiffChange guifg=#000000 guibg=#4f94cd gui=NONE
hi DiffText guifg=#000000 guibg=#8ee5ee gui=NONE
hi Directory guifg=#1e90ff guibg=bg gui=NONE
hi ErrorMsg guifg=#ff6a6a guibg=NONE gui=bold
hi FoldColumn guifg=#68838b guibg=#4B4B4B gui=bold
hi Folded guifg=#406060 guibg=#232c2c gui=NONE
hi IncSearch guifg=#ffffff guibg=#ff4500 gui=bold
hi LineNr guifg=#686858 guibg=#000000 gui=NONE
hi MatchParen guifg=#fff000 guibg=#000000 gui=bold
hi ModeMsg guifg=#000000 guibg=#00ff00 gui=bold
hi MoreMsg guifg=#2e8b57 guibg=bg gui=bold
hi NonText guifg=#404050 guibg=bg gui=NONE
hi Pmenu guifg=#ffffff guibg=#444444
hi PmenuSel guifg=#000000 guibg=#b1d631
" hi PmenuSbar guifg=#ffffff guibg=#c1cdc1 gui=NONE
" hi PmenuThumb guifg=#ffffff guibg=#838b83 gui=NONE
hi Question guifg=#00ee00 guibg=NONE gui=bold
hi Search guifg=#000000 guibg=#d6e770 gui=bold
hi SignColumn guifg=#ffffff guibg=#cdcdb4 gui=NONE
hi SpecialKey guifg=#505060 guibg=NONE gui=NONE
hi SpellBad guisp=#ee2c2c gui=undercurl
hi SpellCap guisp=#0000ff gui=undercurl
hi SpellLocal guisp=#008b8b gui=undercurl
hi SpellRare guisp=#ff00ff gui=undercurl
hi StatusLine guifg=#000000 guibg=#808070 gui=bold
hi StatusLineNC guifg=#000000 guibg=#404c4c gui=italic
hi VertSplit guifg=#404c4c guibg=#404c4c gui=NONE
hi TabLine guifg=fg guibg=#d3d3d3 gui=underline
hi TabLineFill guifg=fg guibg=bg gui=reverse
hi TabLineSel guifg=fg guibg=bg gui=bold
hi Title guifg=#528b8b guibg=NONE gui=bold
hi Visual guifg=#000000 guibg=#6688aa gui=NONE
hi WarningMsg guifg=#ee9a00 guibg=bg gui=NONE
hi WildMenu guifg=#000000 guibg=#87ceeb gui=NONE
" Syntax highlighting
hi Comment guifg=#707670 gui=italic
hi Boolean guifg=#ff9800 gui=NONE
hi String guifg=#779b70 gui=NONE
hi Identifier guifg=#9ebac2 gui=NONE
hi Function guifg=#faf4c6 gui=NONE
hi Type guifg=#7e8aa2 gui=NONE
hi Statement guifg=#90b0d1 gui=NONE
hi Keyword guifg=#90b0d1 gui=NONE
hi Constant guifg=#ff9800 gui=NONE
hi Number guifg=#cc8800 gui=NONE
hi Special guifg=#719611 gui=NONE
hi PreProc guifg=#528b8b gui=NONE
hi Todo guifg=#8f6f8f guibg=#202020 gui=italic,underline,bold
" Diff
hi diffOldFile guifg=#88afcb guibg=NONE gui=italic
hi diffNewFile guifg=#88afcb guibg=NONE gui=italic
hi diffFile guifg=#88afcb guibg=NONE gui=italic
hi diffLine guifg=#88afcb guibg=NONE gui=italic
hi link diffSubname diffLine
hi diffAdded guifg=#3cb371 guibg=NONE gui=NONE
hi diffRemoved guifg=#aa4450 guibg=NONE gui=NONE
hi diffChanged guifg=#4f94cd guibg=NONE gui=NONE
hi link diffOnly Constant
hi link diffIdentical Constant
hi link diffDiffer Constant
hi link diffBDiffer Constant
hi link diffIsA Constant
hi link diffNoEOL Constant
hi link diffCommon Constant
hi link diffComment Constant
" Python
hi pythonException guifg=#90b0d1 guibg=NONE gui=NONE
hi pythonExClass guifg=#996666 guibg=NONE gui=NONE
hi pythonDecorator guifg=#888555 guibg=NONE gui=NONE
hi link pythonDecoratorFunction pythonDecorator
" 1}}}
" 256 Colors {{{1
" ============================================================================
hi Normal cterm=NONE ctermbg=235 ctermfg=145
hi ColorColumn cterm=NONE ctermbg=16 ctermfg=fg
hi Cursor cterm=NONE ctermbg=241 ctermfg=fg
hi CursorColumn cterm=NONE ctermbg=16 ctermfg=fg
hi CursorLine cterm=NONE ctermbg=236 ctermfg=fg
hi DiffAdd cterm=NONE ctermbg=71 ctermfg=16
hi DiffDelete cterm=NONE ctermbg=124 ctermfg=16
hi DiffChange cterm=NONE ctermbg=68 ctermfg=16
hi DiffText cterm=NONE ctermbg=117 ctermfg=16
hi Directory cterm=NONE ctermbg=234 ctermfg=33
hi ErrorMsg cterm=bold ctermbg=bg ctermfg=203
hi FoldColumn cterm=bold ctermbg=239 ctermfg=66
hi Folded cterm=NONE ctermbg=16 ctermfg=60
hi IncSearch cterm=bold ctermbg=202 ctermfg=231
hi LineNr cterm=NONE ctermbg=16 ctermfg=59
hi MatchParen cterm=bold ctermbg=16 ctermfg=226
hi ModeMsg cterm=bold ctermbg=46 ctermfg=16
hi MoreMsg cterm=bold ctermbg=234 ctermfg=29
hi NonText cterm=NONE ctermbg=bg ctermfg=59
hi Pmenu cterm=NONE ctermbg=238 ctermfg=231
hi PmenuSbar cterm=NONE ctermbg=250 ctermfg=fg
hi PmenuSel cterm=NONE ctermbg=149 ctermfg=16
hi Question cterm=bold ctermbg=bg ctermfg=46
hi Search cterm=bold ctermbg=185 ctermfg=16
hi SignColumn cterm=NONE ctermbg=187 ctermfg=231
hi SpecialKey cterm=NONE ctermbg=bg ctermfg=59
hi SpellBad cterm=undercurl ctermbg=bg ctermfg=196
hi SpellCap cterm=undercurl ctermbg=bg ctermfg=21
hi SpellLocal cterm=undercurl ctermbg=bg ctermfg=30
hi SpellRare cterm=undercurl ctermbg=bg ctermfg=201
hi StatusLine cterm=bold ctermbg=101 ctermfg=16
hi StatusLineNC cterm=NONE ctermbg=102 ctermfg=16
hi VertSplit cterm=NONE ctermbg=102 ctermfg=102
hi TabLine cterm=bold ctermbg=102 ctermfg=16
hi TabLineFill cterm=NONE ctermbg=102 ctermfg=16
hi TabLineSel cterm=bold ctermbg=16 ctermfg=59
hi Title cterm=bold ctermbg=bg ctermfg=66
hi Visual cterm=NONE ctermbg=67 ctermfg=16
hi WarningMsg cterm=NONE ctermbg=234 ctermfg=208
hi WildMenu cterm=NONE ctermbg=116 ctermfg=16
hi Comment cterm=NONE ctermbg=bg ctermfg=65
hi Boolean cterm=NONE ctermbg=bg ctermfg=208
hi String cterm=NONE ctermbg=bg ctermfg=101
hi Identifier cterm=NONE ctermbg=bg ctermfg=145
hi Function cterm=NONE ctermbg=bg ctermfg=230
hi Type cterm=NONE ctermbg=bg ctermfg=103
hi Statement cterm=NONE ctermbg=bg ctermfg=110
hi Keyword cterm=NONE ctermbg=bg ctermfg=110
hi Constant cterm=NONE ctermbg=bg ctermfg=208
hi Number cterm=NONE ctermbg=bg ctermfg=172
hi Special cterm=NONE ctermbg=bg ctermfg=64
hi PreProc cterm=NONE ctermbg=bg ctermfg=66
hi Todo cterm=bold,underline ctermbg=234 ctermfg=96
hi diffOldFile cterm=NONE ctermbg=bg ctermfg=67
hi diffNewFile cterm=NONE ctermbg=bg ctermfg=67
hi diffFile cterm=NONE ctermbg=bg ctermfg=67
hi diffLine cterm=NONE ctermbg=bg ctermfg=67
hi diffAdded cterm=NONE ctermfg=bg ctermfg=71
hi diffRemoved cterm=NONE ctermfg=bg ctermfg=124
hi diffChanged cterm=NONE ctermfg=bg ctermfg=68
hi link diffSubname diffLine
hi link diffOnly Constant
hi link diffIdentical Constant
hi link diffDiffer Constant
hi link diffBDiffer Constant
hi link diffIsA Constant
hi link diffNoEOL Constant
hi link diffCommon Constant
hi link diffComment Constant
hi pythonClass cterm=NONE ctermbg=bg ctermfg=fg
hi pythonDecorator cterm=NONE ctermbg=bg ctermfg=101
hi pythonExClass cterm=NONE ctermbg=bg ctermfg=95
hi pythonException cterm=NONE ctermbg=bg ctermfg=110
hi pythonFunc cterm=NONE ctermbg=bg ctermfg=fg
hi pythonFuncParams cterm=NONE ctermbg=bg ctermfg=fg
hi pythonKeyword cterm=NONE ctermbg=bg ctermfg=fg
hi pythonParam cterm=NONE ctermbg=bg ctermfg=fg
hi pythonRawEscape cterm=NONE ctermbg=bg ctermfg=fg
hi pythonSuperclasses cterm=NONE ctermbg=bg ctermfg=fg
hi pythonSync cterm=NONE ctermbg=bg ctermfg=fg
hi Conceal cterm=NONE ctermbg=248 ctermfg=252
hi Error cterm=NONE ctermbg=196 ctermfg=231
hi Ignore cterm=NONE ctermbg=bg ctermfg=234
hi InsertModeCursorLine cterm=NONE ctermbg=16 ctermfg=fg
hi NormalModeCursorLine cterm=NONE ctermbg=235 ctermfg=fg
hi PmenuThumb cterm=reverse ctermbg=bg ctermfg=fg
hi StatusLineAlert cterm=NONE ctermbg=160 ctermfg=231
hi StatusLineUnalert cterm=NONE ctermbg=238 ctermfg=144
hi Test cterm=NONE ctermbg=bg ctermfg=fg
hi Underlined cterm=underline ctermbg=bg ctermfg=111
hi VisualNOS cterm=bold,underline ctermbg=bg ctermfg=fg
hi cCursor cterm=reverse ctermbg=bg ctermfg=fg
hi iCursor cterm=NONE ctermbg=210 ctermfg=16
hi lCursor cterm=NONE ctermbg=145 ctermfg=234
hi nCursor cterm=NONE ctermbg=46 ctermfg=16
hi vCursor cterm=NONE ctermbg=201 ctermfg=16
" 1}}}

View File

@@ -0,0 +1,43 @@
" Vim color file
" Maintainer: Ian Langworth
" Last Change: 2004 Dec 24
" Email: <langworth.com>
" Color settings inspired by BBEdit for Mac OS, plus I liked
" the low-contrast comments from the 'oceandeep' colorscheme
set background=light
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name="tolerable"
hi Cursor guifg=white guibg=darkgreen
hi Normal gui=none guifg=black guibg=white
hi NonText gui=none guifg=orange guibg=white
hi Statement gui=none guifg=blue
hi Special gui=none guifg=red
hi Constant gui=none guifg=darkred
hi Comment gui=none guifg=#555555
hi Preproc gui=none guifg=darkcyan
hi Type gui=none guifg=darkmagenta
hi Identifier gui=none guifg=darkgreen
hi Title gui=none guifg=black
hi StatusLine gui=none guibg=#333333 guifg=white
hi StatusLineNC gui=none guibg=#333333 guifg=white
hi VertSplit gui=none guibg=#333333 guifg=white
hi Visual gui=none guibg=green guifg=black
hi Search gui=none guibg=yellow
hi Directory gui=none guifg=darkblue
hi WarningMsg gui=none guifg=red
hi Error gui=none guifg=white guibg=red
hi Todo gui=none guifg=black guibg=yellow
hi MoreMsg gui=none
hi ModeMsg gui=none

View File

@@ -0,0 +1,85 @@
"
" Vim colour file
"
" Maintainer: Vy-Shane Sin Fat <shane@node.mu>
" Version: 1.2
"
" This colour file is meant for GUI use.
"
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name="vydark"
hi Normal guifg=#bbbbbb guibg=#282828
hi Title guifg=white
hi Cursor guibg=#ffffff
hi LineNr guifg=#444455 guibg=#292929
hi Visual guibg=#555555
hi NonText guifg=#292929 guibg=#292929
hi StatusLine guifg=#bbbbbb guibg=#353535 gui=none
hi StatusLineNC guifg=#777777 guibg=#353535 gui=none
hi VertSplit guifg=#353535 guibg=#353535 gui=none
hi ModeMsg guifg=#99dd99 guibg=#394439 gui=none
hi ErrorMsg guifg=#222222 guibg=#ff8888 gui=none
hi Error guifg=#ffaaaa guibg=#333333 gui=none
hi Folded guifg=#666677 guibg=#242424
" Vim 7.x specific
if version >= 700
hi MatchParen guibg=#364836 gui=none
hi Pmenu guifg=#bbbbbb guibg=#444444 gui=none
hi PmenuSel guifg=#222222 guibg=#99bbdd gui=none
hi PmenuSbar guifg=#494949 guibg=#494949 gui=bold
hi PmenuThumb guifg=#666666 guibg=#666666 gui=bold
hi Search guifg=#dddd99 guibg=#444433 gui=none
hi IncSearch guifg=#eeeeaa guibg=#666633 gui=bold
hi CursorLine guibg=#353535 gui=none
hi ColorColumn guibg=#252525
hi SpellBad guisp=#774444
hi SpellCap guisp=#774444
hi SpellLocal guisp=#774444
hi SpellRare guisp=#774444
endif
" Syntax highlighting
hi Comment guifg=#666677 gui=none
hi Todo guifg=#8888aa guibg=#303030 gui=italic
hi Operator guifg=#bbbbbb gui=none
hi Identifier guifg=#bbbbbb gui=none
hi Statement guifg=#bbbbbb gui=none
hi Type guifg=#99bbcc gui=none
hi Constant guifg=#88cc99 gui=none
hi Conditional guifg=#99bbcc gui=none
hi Delimiter guifg=#99bbdd gui=none
hi PreProc guifg=#88ddcc gui=none
hi Special guifg=#99dd99 gui=bold
hi Keyword guifg=#bbbbbb gui=none
hi link Function Normal
hi link Character Constant
hi link String Constant
hi link Boolean Constant
hi link Number Constant
hi link Float Number
hi link Repeat Conditional
hi link Label Statement
hi link Exception Statement
hi link Include Normal
hi link Define Type
hi link Macro PreProc
hi link PreCondit PreProc
hi link StorageClass Type
hi link Structure Type
hi link Typedef Type
hi link Tag Special
hi link SpecialChar Special
hi link SpecialComment Special
hi link Debug Special

View File

@@ -0,0 +1,81 @@
"
" Vim colour file
"
" Maintainer: Vy-Shane Sin Fat <shane@node.mu>
" Version: 1.4
"
" This colour file is meant for GUI use.
"
set background=light
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name="vylight"
hi Normal guifg=#111111 guibg=white
hi Title guifg=black guibg=white
hi Cursor guibg=#FF7311
hi LineNr guifg=#bebebe guibg=#f8f8f8
hi Visual guibg=#bbddff
hi NonText guifg=#fafafa guibg=#fafafa
hi StatusLine guifg=#222222 guibg=#eeeeee gui=none
hi StatusLineNC guifg=#888888 guibg=#eeeeee gui=none
hi VertSplit guifg=#eeeeee guibg=#eeeeee gui=none
hi ModeMsg guifg=black guibg=#bbddff gui=none
hi ErrorMsg guifg=black guibg=#ffbbbb gui=none
hi Error guifg=#bb3355 guibg=white gui=none
hi Folded guifg=#999999 guibg=#fafafa
" Vim 7.x specific
if version >= 700
hi MatchParen guibg=#ccffdd gui=none
hi Pmenu guifg=#60656f guibg=#f0f5ff gui=none
hi PmenuSel guifg=white guibg=#3585ef gui=bold
hi PmenuSbar guifg=#d0d5dd guibg=#e0e5ee gui=bold
hi PmenuThumb guifg=#e0e5ee guibg=#c0c5dd gui=bold
hi Search guibg=#fcfcaa gui=none
hi IncSearch guibg=#ffff33 gui=bold
hi CursorLine guibg=#f1faff
hi ColorColumn guibg=#fafafa
endif
" Syntax highlighting
hi Comment guifg=#777777 gui=none
hi Todo guifg=#446644 guibg=#ddeecc gui=italic
hi Operator guifg=#1a1a1a gui=none
hi Identifier guifg=#1a1a1a gui=none
hi Statement guifg=#1a1a1a gui=none
hi Type guifg=#0050b0 gui=none
hi Constant guifg=#204070 gui=none
hi Conditional guifg=#006633 gui=none
hi Delimiter guifg=#1a1a1a gui=none
hi PreProc guifg=#006633 gui=none
hi Special guifg=#006633 gui=none
hi Keyword guifg=#007050 gui=none
hi link Function Normal
hi link Character Constant
hi link String Constant
hi link Boolean Constant
hi link Number Constant
hi link Float Number
hi link Repeat Conditional
hi link Label Statement
hi link Exception Statement
hi link Include Normal
hi link Define PreProc
hi link Macro PreProc
hi link PreCondit PreProc
hi link StorageClass Type
hi link Structure Type
hi link Typedef Type
hi link Tag Special
hi link SpecialChar Special
hi link SpecialComment Special
hi link Debug Special

View File

@@ -0,0 +1,362 @@
" Vim color file
" Maintainer: David Liang (bmdavll at gmail dot com)
" Last Change: 2010-09-13
"
" wombat256.vim - a modified version of Wombat by Lars Nielsen that also
" works on xterms with 88 or 256 colors. The algorithm for approximating the
" GUI colors with the xterm palette is from desert256.vim by Henry So Jr.
set background=dark
if version > 580
hi clear
if exists("syntax_on")
syntax reset
endif
endif
let g:colors_name = "wombat256grf"
if !has("gui_running") && &t_Co != 88 && &t_Co != 256
finish
endif
" functions {{{
" returns an approximate grey index for the given grey level
fun <SID>grey_number(x)
if &t_Co == 88
if a:x < 23
return 0
elseif a:x < 69
return 1
elseif a:x < 103
return 2
elseif a:x < 127
return 3
elseif a:x < 150
return 4
elseif a:x < 173
return 5
elseif a:x < 196
return 6
elseif a:x < 219
return 7
elseif a:x < 243
return 8
else
return 9
endif
else
if a:x < 14
return 0
else
let l:n = (a:x - 8) / 10
let l:m = (a:x - 8) % 10
if l:m < 5
return l:n
else
return l:n + 1
endif
endif
endif
endfun
" returns the actual grey level represented by the grey index
fun <SID>grey_level(n)
if &t_Co == 88
if a:n == 0
return 0
elseif a:n == 1
return 46
elseif a:n == 2
return 92
elseif a:n == 3
return 115
elseif a:n == 4
return 139
elseif a:n == 5
return 162
elseif a:n == 6
return 185
elseif a:n == 7
return 208
elseif a:n == 8
return 231
else
return 255
endif
else
if a:n == 0
return 0
else
return 8 + (a:n * 10)
endif
endif
endfun
" returns the palette index for the given grey index
fun <SID>grey_color(n)
if &t_Co == 88
if a:n == 0
return 16
elseif a:n == 9
return 79
else
return 79 + a:n
endif
else
if a:n == 0
return 16
elseif a:n == 25
return 231
else
return 231 + a:n
endif
endif
endfun
" returns an approximate color index for the given color level
fun <SID>rgb_number(x)
if &t_Co == 88
if a:x < 69
return 0
elseif a:x < 172
return 1
elseif a:x < 230
return 2
else
return 3
endif
else
if a:x < 75
return 0
else
let l:n = (a:x - 55) / 40
let l:m = (a:x - 55) % 40
if l:m < 20
return l:n
else
return l:n + 1
endif
endif
endif
endfun
" returns the actual color level for the given color index
fun <SID>rgb_level(n)
if &t_Co == 88
if a:n == 0
return 0
elseif a:n == 1
return 139
elseif a:n == 2
return 205
else
return 255
endif
else
if a:n == 0
return 0
else
return 55 + (a:n * 40)
endif
endif
endfun
" returns the palette index for the given R/G/B color indices
fun <SID>rgb_color(x, y, z)
if &t_Co == 88
return 16 + (a:x * 16) + (a:y * 4) + a:z
else
return 16 + (a:x * 36) + (a:y * 6) + a:z
endif
endfun
" returns the palette index to approximate the given R/G/B color levels
fun <SID>color(r, g, b)
" get the closest grey
let l:gx = <SID>grey_number(a:r)
let l:gy = <SID>grey_number(a:g)
let l:gz = <SID>grey_number(a:b)
" get the closest color
let l:x = <SID>rgb_number(a:r)
let l:y = <SID>rgb_number(a:g)
let l:z = <SID>rgb_number(a:b)
if l:gx == l:gy && l:gy == l:gz
" there are two possibilities
let l:dgr = <SID>grey_level(l:gx) - a:r
let l:dgg = <SID>grey_level(l:gy) - a:g
let l:dgb = <SID>grey_level(l:gz) - a:b
let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
let l:dr = <SID>rgb_level(l:gx) - a:r
let l:dg = <SID>rgb_level(l:gy) - a:g
let l:db = <SID>rgb_level(l:gz) - a:b
let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
if l:dgrey < l:drgb
" use the grey
return <SID>grey_color(l:gx)
else
" use the color
return <SID>rgb_color(l:x, l:y, l:z)
endif
else
" only one possibility
return <SID>rgb_color(l:x, l:y, l:z)
endif
endfun
" returns the palette index to approximate the 'rrggbb' hex string
fun <SID>rgb(rgb)
let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
return <SID>color(l:r, l:g, l:b)
endfun
" sets the highlighting for the given group
fun <SID>X(group, fg, bg, attr)
if a:fg != ""
exec "hi ".a:group." guifg=#".a:fg." ctermfg=".<SID>rgb(a:fg)
endif
if a:bg != ""
exec "hi ".a:group." guibg=#".a:bg." ctermbg=".<SID>rgb(a:bg)
endif
if a:attr != ""
if a:attr == 'italic'
exec "hi ".a:group." gui=".a:attr." cterm=none"
else
exec "hi ".a:group." gui=".a:attr." cterm=".a:attr
endif
endif
endfun
" }}}
" italic only in gui and only where font is not fixed-misc!
if has("gui_running") && &guifont !~ "Fixed"
let s:italic = "italic"
else
let s:italic = "none"
endif
" X(fg, bg, attr)
call <SID>X("Normal", "dddddd", "242424", "none")
call <SID>X("NonText", "4c4c36", "", "none")
call <SID>X("Cursor", "222222", "ecee90", "none")
call <SID>X("CursorLine", "", "32322e", "none")
call <SID>X("CursorColumn", "", "2d2d2d", "")
"CursorIM
"Question
"IncSearch
call <SID>X("Search", "444444", "ffab4b", "")
call <SID>X("MatchParen", "ecee90", "857b6f", "bold")
call <SID>X("SpecialKey", "6c6c6c", "2d2d2d", "none")
call <SID>X("Visual", "", "26512D", "none")
call <SID>X("LineNr", "857b6f", "121212", "none")
call <SID>X("SignColumn", "", "121212", "none")
call <SID>X("Folded", "a0a8b0", "404048", "none")
call <SID>X("Title", "f6f3e8", "", "bold")
call <SID>X("VertSplit", "444444", "444444", "none")
call <SID>X("StatusLine", "f6f3e8", "444444", s:italic)
call <SID>X("StatusLineNC", "857b6f", "444444", "none")
"Scrollbar
"Tooltip
"Menu
"WildMenu
call <SID>X("Pmenu", "f6f3e8", "444444", "")
call <SID>X("PmenuSel", "121212", "caeb82", "")
call <SID>X("WarningMsg", "ff0000", "", "")
"ErrorMsg
"ModeMsg
"MoreMsg
"Directory
"DiffAdd
"DiffChange
"DiffDelete
"DiffText
" syntax highlighting
call <SID>X("Number", "e5786d", "", "none")
call <SID>X("Constant", "e5786d", "", "none")
call <SID>X("String", "95e454", "", s:italic)
call <SID>X("Comment", "99968b", "", s:italic)
call <SID>X("Identifier", "caeb82", "", "none")
call <SID>X("Keyword", "87afff", "", "none")
call <SID>X("Statement", "87afff", "", "none")
call <SID>X("Function", "caeb82", "", "none")
call <SID>X("PreProc", "e5786d", "", "none")
call <SID>X("Type", "caeb82", "", "none")
call <SID>X("Special", "ffdead", "", "none")
call <SID>X("Todo", "857b6f", "", s:italic)
"Underlined
"Error
"Ignore
hi! link VisualNOS Visual
hi! link FoldColumn Folded
hi! link TabLineSel StatusLine
hi! link TabLineFill StatusLineNC
hi! link TabLine StatusLineNC
call <SID>X("TabLineSel", "f6f3e8", "", "none")
" Python Highlighting for python.vim
"call <SID>X("pythonCoding", "ff0086", "", "none")
"call <SID>X("pythonRun", "ff0086", "", "none")
"call <SID>X("pythonBuiltinObji", "2b6ba2", "", "bold")
"call <SID>X("pythonBuiltinFunc", "2b6ba2", "", "bold")
"call <SID>X("pythonException", "ee0000", "", "bold")
"call <SID>X("pythonExClass", "66cd66", "", "bold")
"call <SID>X("pythonSpaceError", "270000", "", "none")
"call <SID>X("pythonDocTest", "2f5f49", "", "none")
"call <SID>X("pythonDocTest2", "3b916a", "", "none")
"call <SID>X("pythonFunction", "ee0000", "", "bold")
"call <SID>X("pythonClass", "ff0086", "", "bold")
call <SID>X("ShowMarksHLl", "ab8042", "121212", "bold")
"call <SID>X("ShowMarksHLu", "ab4242", "121212", "bold")
call <SID>X("ShowMarksHLu", "aaab42", "121212", "bold")
call <SID>X("ShowMarksHLo", "42ab47", "121212", "bold")
call <SID>X("ShowMarksHLm", "aaab42", "121212", "bold")
" Diff colors
"call <SID>X("DiffAdd", "", "1d1d50", "bold")
"call <SID>X("DiffText", "", "9f1e1e", "bold")
"call <SID>X("DiffDelete", "", "1d5050", "bold")
"call <SID>X("DiffChange", "", "4c1c4c", "bold")
call <SID>X("DiffAdd", "", "646464", "bold")
call <SID>X("DiffText", "", "bf5f00", "bold")
call <SID>X("DiffDelete", "343434", "101010", "bold")
call <SID>X("DiffChange", "", "424242", "bold")
" DiffAdd xxx term=bold ctermbg=4
" DiffChange xxx term=bold ctermbg=5
" DiffDelete xxx term=bold ctermfg=12 ctermbg=6
" DiffText xxx term=reverse cterm=bold ctermbg=9
" VIm 7.3 features
call <SID>X("ColorColumn", "", "32322e", "")
if ! has('gui_running')
" spell, make it underline, and less bright colors. only for terminal
call <SID>X("SpellBad", "", "880000", "underline")
call <SID>X("SpellCap", "", "000088", "underline")
call <SID>X("SpellRare", "", "880088", "underline")
call <SID>X("SpellLocal", "", "008888", "underline")
endif
" delete functions {{{
delf <SID>X
delf <SID>rgb
delf <SID>color
delf <SID>rgb_color
delf <SID>rgb_level
delf <SID>rgb_number
delf <SID>grey_color
delf <SID>grey_level
delf <SID>grey_number
" }}}
" vim:set ts=4 sw=4 noet fdm=marker:

View File

@@ -0,0 +1,561 @@
" Vim color file
" Maintainer: Jani Nurminen <slinky@iki.fi>
" Last Change: $Id: zenburn.vim,v 2.21 2011/04/26 12:13:41 slinky Exp slinky $
" URL: http://slinky.imukuppi.org/zenburnpage/
" License: GNU GPL <http://www.gnu.org/licenses/gpl.html>
"
" Nothing too fancy, just some alien fruit salad to keep you in the zone.
" This syntax file was designed to be used with dark environments and
" low light situations. Of course, if it works during a daybright office, go
" ahead :)
"
" Owes heavily to other Vim color files! With special mentions
" to "BlackDust", "Camo" and "Desert".
"
" To install, copy to ~/.vim/colors directory.
"
" Alternatively, you can use Vimball installation:
" vim zenburn.vba
" :so %
" :q
"
" For details, see :help vimball
"
" After installation, use it with :colorscheme zenburn.
" See also :help syntax
"
" Credits:
" - Jani Nurminen - original Zenburn, maintainer
" - Steve Hall & Cream posse - higher-contrast Visual selection
" - Kurt Maier - 256 color console coloring, low and high contrast toggle,
" bug fixing
" - Charlie - spotted too bright StatusLine in non-high contrast mode
" - Pablo Castellazzi - CursorLine fix for 256 color mode
" - Tim Smith - force dark background
" - John Gabriele - spotted bad Ignore-group handling
" - Zac Thompson - spotted invisible NonText in low contrast mode
" - Christophe-Marie Duquesne - suggested making a Vimball,
" suggested support for ctags_highlighting.vim
" - Andrew Wagner - noted the CursorColumn bug (guifg was unintentionally set),
" unify CursorColumn colour
" - Martin Langasek - clarify the license, whitespace fixes
" - Marcin Szamotulski - support autocomplete for Zenburn configuration
" parameters
" - Clayton Parker (claytron) - Convinced by Kurt Maier to use Zenburn. Point
" out issues with LineNr, fix directory styles, and their usage in MacVim.
" - Paweł Piekarski - Spotted bad FoldColumn and TabLine. Made better
" FoldColumn colors, fixed TabLine colors.
"
" CONFIGURABLE PARAMETERS:
"
" You can use the default (don't set any parameters), or you can
" set some parameters to tweak the Zenburn colours.
"
" To use them, put them into your .vimrc file before loading the color scheme,
" example:
" let g:zenburn_high_Contrast=1
" colors zenburn
"
" You can also do ":let g:zenburn" then hit Ctrl-d or Tab to scroll through the
" list of configurable parameters.
"
" * You can now set a darker background for bright environments. To activate, use:
" contrast Zenburn, use:
"
" let g:zenburn_high_Contrast = 1
"
" * For example, Vim help files uses the Ignore-group for the pipes in tags
" like "|somelink.txt|". By default, the pipes are not visible, as they
" map to Ignore group. If you wish to enable coloring of the Ignore group,
" set the following parameter to 1. Warning, it might make some syntax files
" look strange.
"
" let g:zenburn_color_also_Ignore = 1
"
" * To get more contrast to the Visual selection, use
"
" let g:zenburn_alternate_Visual = 1
"
" Note: this is enabled only if the old-style Visual
" if used, see g:zenburn_old_Visual
"
" * To use alternate colouring for Error message, use
"
" let g:zenburn_alternate_Error = 1
"
" * The new default for Include is a duller orange. To use the original
" colouring for Include, use
"
" let g:zenburn_alternate_Include = 1
"
" * Work-around to a Vim bug, it seems to misinterpret ctermfg and 234 and 237
" as light values, and sets background to light for some people. If you have
" this problem, use:
"
" let g:zenburn_force_dark_Background = 1
"
" * By default the CursorColumn is of a lighter colour. I find it more readable
" that way, but some people may want to align it with the darker CursorLine
" color, for visual uniformity. To do so, use:
"
" let g:zenburn_unified_CursorColumn = 1
"
" Note: you can ignore this unless you use
" ":set cursorline cursorcolumn", since otherwise the effect won't be
" seen.
"
" * New (dark) Visual coloring has been introduced.
" The dark Visual is more aligned with the rest of the colour scheme,
" especially if you use line numbers. If you wish to use the
" old Visual coloring, use
"
" let g:zenburn_old_Visual = 1
"
" Default is to use the new Visual.
"
" * EXPERIMENTAL FEATURE: Zenburn will automatically detect if you
" have ctags_highlighting.vim (by Al Budden,
" http://www.vim.org/scripts/script.php?script_id=2646) enabled, and
" will set sensible highlight links. Nothing will happen if you do
" not have ctags_highlighting.vim. If you do not want this feature, you can
" override the check with:
"
" let g:zenburn_disable_ctags_highlighting_support = 1
"
" NOTE:
"
" * To turn the parameter(s) back to defaults, use UNLET or set them to 0:
"
" unlet g:zenburn_alternate_Include
" or
" let g:zenburn_alternate_Include = 0
"
"
" That's it, enjoy!
"
" TODO
" - Visual alternate color is broken? Try GVim >= 7.0.66 if you have trouble
" - IME colouring (CursorIM)
" Set defaults, but keep any parameters already set by the user
if ! exists("g:zenburn_high_Contrast")
let g:zenburn_high_Contrast = 0
endif
if ! exists("g:zenburn_color_also_Ignore")
let g:zenburn_color_also_Ignore = 0
endif
if ! exists("g:zenburn_alternate_Error")
let g:zenburn_alternate_Error = 0
endif
if ! exists("g:zenburn_force_dark_Background")
let g:zenburn_force_dark_Background = 0
endif
if ! exists("g:zenburn_alternate_Visual")
let g:zenburn_alternate_Visual = 0
endif
if ! exists("g:zenburn_alternate_Include")
let g:zenburn_alternate_Include = 0
endif
if ! exists("g:zenburn_unified_CursorColumn")
let g:zenburn_unified_CursorColumn = 0
endif
if ! exists("g:zenburn_old_Visual")
let g:zenburn_old_Visual = 0
endif
if ! exists("g:zenburn_disable_ctags_highlighting_support")
" enabled by default
let g:zenburn_disable_ctags_highlighting_support = 0
endif
" -----------------------------------------------
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name="zenburn"
" check for ctags-highlighting
if exists("g:loaded_ctags_highlighting") && g:loaded_ctags_highlighting && ! g:zenburn_disable_ctags_highlighting_support
" internal
let _zenburn_ctags = 1
endif
hi Boolean guifg=#dca3a3
hi Character guifg=#dca3a3 gui=bold
hi Comment guifg=#7f9f7f gui=italic
hi Conditional guifg=#f0dfaf gui=bold
hi Constant guifg=#dca3a3 gui=bold
hi Cursor guifg=#000d18 guibg=#8faf9f gui=bold
hi Debug guifg=#bca3a3 gui=bold
hi Define guifg=#ffcfaf gui=bold
hi Delimiter guifg=#8f8f8f
hi DiffAdd guifg=#709080 guibg=#313c36 gui=bold
hi DiffChange guibg=#333333
hi DiffDelete guifg=#333333 guibg=#464646
hi DiffText guifg=#ecbcbc guibg=#41363c gui=bold
hi Directory guifg=#9fafaf gui=bold
hi ErrorMsg guifg=#80d4aa guibg=#2f2f2f gui=bold
hi Exception guifg=#c3bf9f gui=bold
hi Float guifg=#c0bed1
hi FoldColumn guifg=#93b3a3 guibg=#3f4040
hi Folded guifg=#93b3a3 guibg=#3f4040
hi Function guifg=#efef8f
hi Identifier guifg=#efdcbc
hi IncSearch guibg=#f8f893 guifg=#385f38
hi Keyword guifg=#f0dfaf gui=bold
hi Label guifg=#dfcfaf gui=underline
hi Macro guifg=#ffcfaf gui=bold
hi ModeMsg guifg=#ffcfaf gui=none
hi MoreMsg guifg=#ffffff gui=bold
hi Number guifg=#8cd0d3
hi Operator guifg=#f0efd0
hi PreCondit guifg=#dfaf8f gui=bold
hi PreProc guifg=#ffcfaf gui=bold
hi Question guifg=#ffffff gui=bold
hi Repeat guifg=#ffd7a7 gui=bold
hi Search guifg=#ffffe0 guibg=#284f28
hi SpecialChar guifg=#dca3a3 gui=bold
hi SpecialComment guifg=#82a282 gui=bold
hi Special guifg=#cfbfaf
hi SpecialKey guifg=#9ece9e
hi Statement guifg=#e3ceab gui=none
hi StatusLine guifg=#313633 guibg=#ccdc90
hi StatusLineNC guifg=#2e3330 guibg=#88b090
hi StorageClass guifg=#c3bf9f gui=bold
hi String guifg=#cc9393
hi Structure guifg=#efefaf gui=bold
hi Tag guifg=#e89393 gui=bold
hi Title guifg=#efefef gui=bold
hi Todo guifg=#dfdfdf guibg=bg gui=bold
hi Typedef guifg=#dfe4cf gui=bold
hi Type guifg=#dfdfbf gui=bold
hi Underlined guifg=#dcdccc gui=underline
hi VertSplit guifg=#2e3330 guibg=#688060
hi VisualNOS guifg=#333333 guibg=#f18c96 gui=bold,underline
hi WarningMsg guifg=#ffffff guibg=#333333 gui=bold
hi WildMenu guibg=#2c302d guifg=#cbecd0 gui=underline
hi SpellBad guisp=#bc6c4c guifg=#dc8c6c
hi SpellCap guisp=#6c6c9c guifg=#8c8cbc
hi SpellRare guisp=#bc6c9c guifg=#bc8cbc
hi SpellLocal guisp=#7cac7c guifg=#9ccc9c
" Entering Kurt zone
if &t_Co > 255
hi Boolean ctermfg=181
hi Character ctermfg=181 cterm=bold
hi Comment ctermfg=108
hi Conditional ctermfg=223 cterm=bold
hi Constant ctermfg=181 cterm=bold
hi Cursor ctermfg=233 ctermbg=109 cterm=bold
hi Debug ctermfg=181 cterm=bold
hi Define ctermfg=223 cterm=bold
hi Delimiter ctermfg=245
hi DiffAdd ctermfg=66 ctermbg=237 cterm=bold
hi DiffChange ctermbg=236
hi DiffDelete ctermfg=236 ctermbg=238
hi DiffText ctermfg=217 ctermbg=237 cterm=bold
hi Directory ctermfg=109 cterm=bold
hi ErrorMsg ctermfg=115 ctermbg=236 cterm=bold
hi Exception ctermfg=249 cterm=bold
hi Float ctermfg=251
hi Function ctermfg=228
hi Identifier ctermfg=223
hi IncSearch ctermbg=228 ctermfg=238
hi Keyword ctermfg=223 cterm=bold
hi Label ctermfg=187 cterm=underline
hi LineNr ctermfg=248 ctermbg=233
hi Macro ctermfg=223 cterm=bold
hi ModeMsg ctermfg=223 cterm=none
hi MoreMsg ctermfg=15 cterm=bold
hi Number ctermfg=116
hi Operator ctermfg=230
hi PreCondit ctermfg=180 cterm=bold
hi PreProc ctermfg=223 cterm=bold
hi Question ctermfg=15 cterm=bold
hi Repeat ctermfg=223 cterm=bold
hi Search ctermfg=230 ctermbg=236
hi SpecialChar ctermfg=181 cterm=bold
hi SpecialComment ctermfg=108 cterm=bold
hi Special ctermfg=181
hi SpecialKey ctermfg=151
hi Statement ctermfg=187 ctermbg=234 cterm=none
hi StatusLine ctermfg=236 ctermbg=186
hi StatusLineNC ctermfg=235 ctermbg=108
hi StorageClass ctermfg=249 cterm=bold
hi String ctermfg=174
hi Structure ctermfg=229 cterm=bold
hi Tag ctermfg=181 cterm=bold
hi Title ctermfg=7 ctermbg=234 cterm=bold
hi Todo ctermfg=108 ctermbg=234 cterm=bold
hi Typedef ctermfg=253 cterm=bold
hi Type ctermfg=187 cterm=bold
hi Underlined ctermfg=188 ctermbg=234 cterm=bold
hi VertSplit ctermfg=236 ctermbg=65
hi VisualNOS ctermfg=236 ctermbg=210 cterm=bold
hi WarningMsg ctermfg=15 ctermbg=236 cterm=bold
hi WildMenu ctermbg=236 ctermfg=194 cterm=bold
" spellchecking, always "bright" background
hi SpellLocal ctermfg=14 ctermbg=237
hi SpellBad ctermfg=9 ctermbg=237
hi SpellCap ctermfg=12 ctermbg=237
hi SpellRare ctermfg=13 ctermbg=237
" pmenu
hi PMenu ctermfg=248 ctermbg=0
hi PMenuSel ctermfg=223 ctermbg=235
if exists("g:zenburn_high_Contrast") && g:zenburn_high_Contrast
hi Normal ctermfg=188 ctermbg=234
hi NonText ctermfg=238
if exists("g:zenburn_color_also_Ignore") && g:zenburn_color_also_Ignore
hi Ignore ctermfg=238
endif
" hc mode, darker CursorLine, default 236
hi CursorLine ctermbg=233 cterm=none
if exists("g:zenburn_unified_CursorColumn") && g:zenburn_unified_CursorColumn
hi CursorColumn ctermbg=233 cterm=none
else
hi CursorColumn ctermbg=235 cterm=none
endif
else
hi Normal ctermfg=188 ctermbg=237
hi Cursor ctermbg=109
hi diffadd ctermbg=237
hi diffdelete ctermbg=238
hi difftext ctermbg=237
hi errormsg ctermbg=237
hi incsearch ctermbg=228
hi linenr ctermbg=235
hi search ctermbg=238
hi statement ctermbg=237
hi statusline ctermbg=144
hi statuslinenc ctermbg=108
hi title ctermbg=237
hi todo ctermbg=237
hi underlined ctermbg=237
hi vertsplit ctermbg=65
hi visualnos ctermbg=210
hi warningmsg ctermbg=236
hi wildmenu ctermbg=236
hi NonText ctermfg=240
if exists("g:zenburn_color_also_Ignore") && g:zenburn_color_also_Ignore
hi Ignore ctermfg=240
endif
" normal mode, lighter CursorLine
hi CursorLine ctermbg=238 cterm=none
if exists("g:zenburn_unified_CursorColumn") && g:zenburn_unified_CursorColumn
hi CursorColumn ctermbg=238 cterm=none
else
hi CursorColumn ctermbg=239 cterm=none
endif
endif
if exists("g:zenburn_alternate_Error") && g:zenburn_alternate_Error
" use more jumpy Error
hi Error ctermfg=210 ctermbg=52 gui=bold
else
" default is something more zenburn-compatible
hi Error ctermfg=228 ctermbg=95 gui=bold
endif
endif
if exists("g:zenburn_force_dark_Background") && g:zenburn_force_dark_Background
" Force dark background, because of a bug in VIM: VIM sets background
" automatically during "hi Normal ctermfg=X"; it misinterprets the high
" value (234 or 237 above) as a light color, and wrongly sets background to
" light. See ":help highlight" for details.
set background=dark
endif
if exists("g:zenburn_high_Contrast") && g:zenburn_high_Contrast
" use new darker background
hi Normal guifg=#dcdccc guibg=#1f1f1f
hi CursorLine guibg=#121212 gui=bold
if exists("g:zenburn_unified_CursorColumn") && g:zenburn_unified_CursorColumn
hi CursorColumn guibg=#121212 gui=bold
else
hi CursorColumn guibg=#2b2b2b
endif
hi Pmenu guibg=#242424 guifg=#ccccbc
hi PMenuSel guibg=#353a37 guifg=#ccdc90 gui=bold
hi PmenuSbar guibg=#2e3330 guifg=#000000
hi PMenuThumb guibg=#a0afa0 guifg=#040404
hi MatchParen guifg=#f0f0c0 guibg=#383838 gui=bold
hi SignColumn guifg=#9fafaf guibg=#181818 gui=bold
hi TabLineFill guifg=#cfcfaf guibg=#181818 gui=bold
hi TabLineSel guifg=#efefef guibg=#1c1c1b gui=bold
hi TabLine guifg=#b6bf98 guibg=#181818 gui=bold
hi NonText guifg=#404040 gui=bold
hi LineNr guifg=#9fafaf guibg=#161616
else
" Original, lighter background
hi Normal guifg=#dcdccc guibg=#3f3f3f
hi CursorLine guibg=#434443
if exists("g:zenburn_unified_CursorColumn") && g:zenburn_unified_CursorColumn
hi CursorColumn guibg=#434343
else
hi CursorColumn guibg=#4f4f4f
endif
hi Pmenu guibg=#2c2e2e guifg=#9f9f9f
hi PMenuSel guibg=#242424 guifg=#d0d0a0 gui=bold
hi PmenuSbar guibg=#2e3330 guifg=#000000
hi PMenuThumb guibg=#a0afa0 guifg=#040404
hi MatchParen guifg=#b2b2a0 guibg=#2e2e2e gui=bold
hi SignColumn guifg=#9fafaf guibg=#343434 gui=bold
hi TabLineFill guifg=#cfcfaf guibg=#353535 gui=bold
hi TabLineSel guifg=#efefef guibg=#3a3a39 gui=bold
hi TabLine guifg=#b6bf98 guibg=#353535 gui=bold
hi NonText guifg=#5b605e gui=bold
hi LineNr guifg=#9fafaf guibg=#262626
endif
if exists("g:zenburn_old_Visual") && g:zenburn_old_Visual
if exists("g:zenburn_alternate_Visual") && g:zenburn_alternate_Visual
" Visual with more contrast, thanks to Steve Hall & Cream posse
" gui=none fixes weird highlight problem in at least GVim 7.0.66, thanks to Kurt Maier
hi Visual guifg=#000000 guibg=#71d3b4 gui=none
hi VisualNOS guifg=#000000 guibg=#71d3b4 gui=none
else
" use default visual
hi Visual guifg=#233323 guibg=#71d3b4 gui=none
hi VisualNOS guifg=#233323 guibg=#71d3b4 gui=none
endif
else
" new Visual style
if exists("g:zenburn_high_Contrast") && g:zenburn_high_Contrast
" high contrast
"hi Visual guibg=#304a3d
"hi VisualNos guibg=#304a3d
"TODO no nice greenish in console, 65 is closest. use full black instead,
"although i like the green..!
hi Visual guibg=#0f0f0f
hi VisualNos guibg=#0f0f0f
if &t_Co > 255
hi Visual ctermbg=0
endif
else
" low contrast
hi Visual guibg=#2f2f2f
hi VisualNOS guibg=#2f2f2f
if &t_Co > 255
hi Visual ctermbg=235
hi VisualNOS ctermbg=235
endif
endif
endif
if exists("g:zenburn_alternate_Error") && g:zenburn_alternate_Error
" use more jumpy Error
hi Error guifg=#e37170 guibg=#664040 gui=bold
else
" default is something more zenburn-compatible
hi Error guifg=#e37170 guibg=#3d3535 gui=none
endif
if exists("g:zenburn_alternate_Include") && g:zenburn_alternate_Include
" original setting
hi Include guifg=#ffcfaf gui=bold
else
" new, less contrasted one
hi Include guifg=#dfaf8f gui=bold
endif
if exists("g:zenburn_color_also_Ignore") && g:zenburn_color_also_Ignore
" color the Ignore groups
" note: if you get strange coloring for your files, turn this off (unlet)
hi Ignore guifg=#545a4f
endif
" new tabline and fold column
if exists("g:zenburn_high_Contrast") && g:zenburn_high_Contrast
hi FoldColumn guibg=#161616
hi Folded guibg=#161616
hi TabLine guifg=#88b090 guibg=#313633 gui=none
hi TabLineSel guifg=#ccd990 guibg=#222222
hi TabLineFill guifg=#88b090 guibg=#313633 gui=none
hi SpecialKey guibg=#242424
if &t_Co > 255
hi FoldColumn ctermbg=233 ctermfg=109
hi Folded ctermbg=233 ctermfg=109
hi TabLine ctermbg=236 ctermfg=108 cterm=none
hi TabLineSel ctermbg=235 ctermfg=186 cterm=bold
hi TabLineFill ctermbg=236 ctermfg=236
endif
else
hi FoldColumn guibg=#333333
hi Folded guibg=#333333
hi TabLine guifg=#d0d0b8 guibg=#222222 gui=none
hi TabLineSel guifg=#f0f0b0 guibg=#333333 gui=bold
hi TabLineFill guifg=#dccdcc guibg=#101010 gui=none
hi SpecialKey guibg=#444444
if &t_Co > 255
hi FoldColumn ctermbg=236 ctermfg=109
hi Folded ctermbg=236 ctermfg=109
hi TabLine ctermbg=235 ctermfg=187 cterm=none
hi TabLineSel ctermbg=236 ctermfg=229 cterm=bold
hi TabLineFill ctermbg=233 ctermfg=233
endif
endif
" EXPERIMENTAL ctags_highlighting support
" link/set sensible defaults here;
"
" For now I mostly link to subset of Zenburn colors, the linkage is based
" on appearance, not semantics. In later versions I might define more new colours.
"
" HELP NEEDED to make this work properly.
if exists("_zenburn_ctags") && _zenburn_ctags
" Highlighter seems to think a lot of things are global variables even
" though they're not. Example: python method-local variable is
" coloured as a global variable. They should not be global, since
" they're not visible outside the method.
" If this is some very bright colour group then things look bad.
hi link CTagsGlobalVariable Identifier
hi CTagsClass guifg=#acd0b3
if &t_Co > 255
hi CTagsClass ctermfg=115
endif
hi link CTagsImport Statement
hi link CTagsMember Function
hi link CTagsGlobalConstant Constant
" These do not yet have support, I can't get them to appear
hi link EnumerationValue Float
hi link EnumerationName Identifier
hi link DefinedName WarningMsg
hi link LocalVariable WarningMsg
hi link Structure WarningMsg
hi link Union WarningMsg
endif
" TODO check for more obscure syntax groups that they're ok

View File

@@ -0,0 +1,14 @@
" Vim compiler file
" Compiler: Javascript Lint
if exists("current_compiler")
finish
endif
let current_compiler = "jsl"
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
CompilerSet makeprg=jsl\ -nologo\ -nofilelisting\ -nosummary\ -nocontext\ -process\ %
CompilerSet errorformat=%f(%l):\ %m

View File

@@ -0,0 +1,12 @@
" Vim compiler file for Python
" Compiler: Static code checking tool for Python
" Maintainer: Roman 'gryf' Dobosz
" Last Change: 2010-09-12
" Version: 1.0
if exists("current_compiler")
finish
endif
let current_compiler = "pylint"
CompilerSet makeprg=$HOME/.vim/bin/pylint_parseable.py\ %
CompilerSet efm=%f:\ %t:\ %l:\ %c:\ %m,%f:\ %t:\ %l:\ %m

View File

@@ -0,0 +1,10 @@
" Vim compiler file
" Compiler: pdf creator out of LaTeX files using rubber
if exists("current_compiler")
finish
endif
let current_compiler = "rubber"
CompilerSet makeprg=rubber\ -d\ %
"CompilerSet efm=%f:%l:\ [%t]%m,%f:%l:%m

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,231 @@
" Fold routines for python code, version 3.2
" Source: http://www.vim.org/scripts/script.php?script_id=2527
" Last Change: 2009 Feb 25
" Author: Jurjen Bos
" Bug fixes and helpful comments: Grissiom, David Froger, Andrew McNabb
" Principles:
" - a def/class starts a fold
" a line with indent less than the previous def/class ends a fold
" empty lines and comment lines are linked to the previous fold
" comment lines outside a def/class are never folded
" other lines outside a def/class are folded together as a group
" for algorithm, see bottom of script
" - optionally, you can get empty lines between folds, see (***)
" - another option is to ignore non-python files see (**)
" - you can also modify the def/class check,
" allowing for multiline def and class definitions see (*)
" Note for vim 7 users:
" Vim 6 line numbers always take 8 columns, while vim 7 has a numberwidth variable
" you can change the 8 below to &numberwidth if you have vim 7,
" this is only really useful when you plan to use more than 8 columns (i.e. never)
" Note for masochists trying to read this:
" I wanted to keep the functions short, so I replaced occurences of
" if condition
" statement
" by
" if condition | statement
" wherever I found that useful
" (*)
" class definitions are supposed to ontain a colon on the same line.
" function definitions are *not* required to have a colon, to allow for multiline defs.
" I you disagree, use instead of the pattern '^\s*\(class\s.*:\|def\s\)'
" to enforce : for defs: '^\s*\(class\|def\)\s.*:'
" you'll have to do this in two places.
let s:defpat = '^\s*\(@\|class\s.*:\|def\s\)'
" (**) Ignore non-python files
" Commented out because some python files are not recognized by Vim
"if &filetype != 'python'
" finish
"endif
setlocal foldmethod=expr
setlocal foldexpr=GetPythonFold(v:lnum)
setlocal foldtext=PythonFoldText()
function! PythonFoldText()
let fs = v:foldstart
while getline(fs) =~ '^\s*@' | let fs = nextnonblank(fs + 1)
endwhile
let line = getline(fs)
let nnum = nextnonblank(fs + 1)
let nextline = getline(nnum)
"get the document string: next line is ''' or """
if nextline =~ "^\\s\\+[\"']\\{3}\\s*$"
let line = line . " " . matchstr(getline(nextnonblank(nnum + 1)), '^\s*\zs.*\ze$')
"next line starts with qoutes, and has text
elseif nextline =~ "^\\s\\+[\"']\\{1,3}"
let line = line." ".matchstr(nextline, "^\\s\\+[\"']\\{1,3}\\zs.\\{-}\\ze['\"]\\{0,3}$")
elseif nextline =~ '^\s\+pass\s*$'
let line = line . ' pass'
endif
"compute the width of the visible part of the window (see Note above)
let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0)
let size = 1 + v:foldend - v:foldstart
"compute expansion string
let spcs = '................'
while strlen(spcs) < w | let spcs = spcs . spcs
endwhile
"expand tabs (mail me if you have tabstop>10)
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
return strpart(line.spcs, 0, w-strlen(size)-7).'.'.size.' lines'
endfunction
function! GetBlockIndent(lnum)
" Auxiliary function; determines the indent level of the surrounding def/class
" "global" lines are level 0, first def &shiftwidth, and so on
" scan backwards for class/def that is shallower or equal
let ind = 100
let p = a:lnum+1
while indent(p) >= 0
let p = p - 1
" skip empty and comment lines
if getline(p) =~ '^$\|^\s*#' | continue
" zero-level regular line
elseif indent(p) == 0 | return 0
" skip deeper or equal lines
elseif indent(p) >= ind || getline(p) =~ '^$\|^\s*#' | continue
" indent is strictly less at this point: check for def/class
elseif getline(p) =~ s:defpat && getline(p) !~ '^\s*@'
" level is one more than this def/class
return indent(p) + &shiftwidth
endif
" shallower line that is neither class nor def: continue search at new level
let ind = indent(p)
endwhile
"beginning of file
return 0
endfunction
" Clever debug code, use as: call PrintIfCount(n,"Line: ".a:lnum.", value: ".x)
let s:counter=0
function! PrintIfCount(n,t)
"Print text the nth time this function is called
let s:counter = s:counter+1
if s:counter==a:n | echo a:t
endif
endfunction
function! GetPythonFold(lnum)
" Determine folding level in Python source (see "higher foldlevel theory" below)
let line = getline(a:lnum)
let ind = indent(a:lnum)
" Case D***: class and def start a fold
" If previous line is @, it is not the first
if line =~ s:defpat && getline(prevnonblank(a:lnum-1)) !~ '^\s*@'
" let's see if this range of 0 or more @'s end in a class/def
let n = a:lnum
while getline(n) =~ '^\s*@' | let n = nextnonblank(n + 1)
endwhile
" yes, we have a match: this is the first of a real def/class with decorators
if getline(n) =~ s:defpat
return ">".(ind/&shiftwidth+1)
endif
" Case E***: empty lines fold with previous
" (***) change '=' to -1 if you want empty lines/comment out of a fold
elseif line == '' | return '='
endif
" now we need the indent from previous
let p = prevnonblank(a:lnum-1)
while p>0 && getline(p) =~ '^\s*#' | let p = prevnonblank(p-1)
endwhile
let pind = indent(p)
" If previous was definition: count as one level deeper
if getline(p) =~ s:defpat && getline(prevnonblank(a:lnum - 1)) !~ '^\s*@'
let pind = pind + &shiftwidth
" if begin of file: take zero
elseif p==0 | let pind = 0
endif
" Case S*=* and C*=*: indent equal
if ind>0 && ind==pind | return '='
" Case S*>* and C*>*: indent increase
elseif ind>pind | return '='
" All cases with 0 indent
elseif ind==0
" Case C*=0*: separate global code blocks
if pind==0 && line =~ '^#' | return 0
" Case S*<0* and S*=0*: global code
elseif line !~'^#'
" Case S*<0*: new global statement if/while/for/try/with
if 0<pind && line!~'^else\s*:\|^except.*:\|^elif.*:\|^finally\s*:' | return '>1'
" Case S*=0*, after level 0 comment
elseif 0==pind && getline(prevnonblank(a:lnum-1)) =~ '^\s*#' | return '>1'
" Case S*=0*, other, stay 1
else | return '='
endif
endif
" Case C*<0= and C*<0<: compute next indent
let n = nextnonblank(a:lnum+1)
while n>0 && getline(n) =~'^\s*#' | let n = nextnonblank(n+1)
endwhile
" Case C*<0=: split definitions
if indent(n)==0 | return 0
" Case C*<0<: shallow comment
else | return -1
end
endif
" now we really need to compute the actual fold indent
" do the hard computation
let blockindent = GetBlockIndent(a:lnum)
" Case SG<* and CG<*: global code, level 1
if blockindent==0 | return 1
endif
" now we need the indent from next
let n = nextnonblank(a:lnum+1)
while n>0 && getline(n) =~'^\s*#' | let n = nextnonblank(n+1)
endwhile
let nind = indent(n)
" Case CR<= and CR<>
"if line !~ '^\s*#' | call PrintIfCount(4,"Line: ".a:lnum.", blockindent: ".blockindent.", n: ".n.", nind: ".nind.", p: ".p.", pind: ".pind)
endif
if line =~ '^\s*#' && ind>=nind | return -1
" Case CR<<: return next indent
elseif line =~ '^\s*#' | return nind / &shiftwidth
" Case SR<*: return actual indent
else | return blockindent / &shiftwidth
endif
endfunction
" higher foldlevel theory
" There are five kinds of statements: S (code), D (def/class), E (empty), C (comment)
" Note that a decorator statement (beginning with @) counts as definition,
" but that of a sequence of @,@,@,def only the first one counts
" This means that a definiion only counts if not preceded by a decorator
" There are two kinds of folds: R (regular), G (global statements)
" There are five indent situations with respect to the previous non-emtpy non-comment line:
" > (indent), < (dedent), = (same); < and = combine with 0 (indent is zero)
" Note: if the previous line is class/def, its indent is interpreted as one higher
" There are three indent situations with respect to the next (non-E non-C) line:
" > (dedent), < (indent), = (same)
" Situations (in order of the script):
" stat fold prev next
" SDEC RG ><=00 ><=
" D * * * begin fold level if previous is not @: '>'.ind/&sw+1
" E * * * keep with previous: '='
" S * = * stays the same: '='
" C * = * combine with previous: '='
" S * > * stays the same: '='
" C * > * combine with previous: '='
" C * =0 * separate blocks: 0
" S * <0 * becomes new level 1: >1 (except except/else: 1)
" S * =0 * stays 1: '=' (after level 0 comment: '>1')
" C * <0 = split definitions: 0
" C * <0 < shallow comment: -1
" C * <0 > [never occurs]
" S G < * global, not the first: 1
" C G < * indent isn't 0: 1
" C R < = foldlevel as computed for next line: -1
" C R < > foldlevel as computed for next line: -1
" S R < * compute foldlevel the hard way: use function
" C R < < foldlevel as computed for this line: use function

View File

@@ -0,0 +1,111 @@
"pydoc.vim: pydoc integration for vim
"performs searches and can display the documentation of python modules
"Author: André Kelpe <efeshundertelf at googlemail dot com>
"Author: Romain Chossart <romainchossat at gmail dot com>
"Author: Matthias Vogelgesang
"http://www.vim.org/scripts/script.php?script_id=910
"This plugin integrates the pydoc into vim. You can view the
"documentation of a module by using :Pydoc foo.bar.baz or search
"a word (uses pydoc -k) in the documentation by typing PydocSearch
"foobar. You can also view the documentation of the word under the
"cursor by pressing <leader>pw or the WORD (see :help WORD) by pressing
"<leader>pW. "This is very useful if you want to jump to a module which was found by
"PydocSearch. To have a browser like feeling you can use u and CTRL-R to
"go back and forward, just like editing normal text.
"If you want to use the script and pydoc is not in your PATH, just put a
"line like
" let g:pydoc_cmd = \"/usr/bin/pydoc" (without the backslash!!)
"in your .vimrc
"pydoc.vim is free software, you can redistribute or modify
"it under the terms of the GNU General Public License Version 2 or any
"later Version (see http://www.gnu.org/copyleft/gpl.html for details).
"Please feel free to contact me.
set switchbuf=useopen
function! ShowPyDoc(name, type)
if !exists('g:pydoc_cmd')
let g:pydoc_cmd = 'pydoc'
endif
if bufloaded("__doc__") >0
let l:buf_is_new = 0
else
let l:buf_is_new = 1
endif
if bufnr("__doc__") >0
execute "sb __doc__"
else
execute 'split __doc__'
endif
setlocal noswapfile
set buftype=nofile
setlocal modifiable
normal ggdG
" remove function/method arguments
let s:name2 = substitute(a:name, '(.*', '', 'g' )
" remove all colons
let s:name2 = substitute(s:name2, ':', '', 'g' )
if a:type==1
execute "silent read ! " . g:pydoc_cmd . " " . s:name2
else
execute "silent read ! " . g:pydoc_cmd . " -k " . s:name2
endif
setlocal nomodified
set filetype=man
normal 1G
if !exists('g:pydoc_wh')
let g:pydoc_wh = 10
end
resize -999
execute "silent resize +" . g:pydoc_wh
if !exists('g:pydoc_highlight')
let g:pydoc_highlight = 1
endif
if g:pydoc_highlight == 1
call Highlight(s:name2)
endif
let l:line = getline(2)
if l:line =~ "^no Python documentation found for.*$"
if l:buf_is_new
execute "bd!"
else
normal u
endif
redraw
echohl WarningMsg | echo l:line | echohl None
endif
endfunction
"highlighting
function! Highlight(name)
execute "sb __doc__"
set filetype=man
"syn on
execute 'syntax keyword pydoc '.a:name
hi pydoc gui=reverse
endfunction
"mappings
au FileType python,man map <buffer> <leader>pw :call ShowPyDoc('<C-R><C-W>', 1)<CR>
au FileType python,man map <buffer> <leader>pW :call ShowPyDoc('<C-R><C-A>', 1)<CR>
au FileType python,man map <buffer> <leader>pk :call ShowPyDoc('<C-R><C-W>', 0)<CR>
au FileType python,man map <buffer> <leader>pK :call ShowPyDoc('<C-R><C-A>', 0)<CR>
" remap the K (or 'help') key
nnoremap <silent> <buffer> K :call ShowPyDoc(expand("<cword>"), 1)<CR>
"commands
command! -nargs=1 Pydoc :call ShowPyDoc('<args>', 1)
command! -nargs=* PydocSearch :call ShowPyDoc('<args>', 0)

View File

@@ -0,0 +1,82 @@
pyflakes-vim
============
A Vim plugin for checking Python code on the fly.
PyFlakes catches common Python errors like mistyping a variable name or
accessing a local before it is bound, and also gives warnings for things like
unused imports.
pyflakes-vim uses the output from PyFlakes to highlight errors in your code.
To locate errors quickly, use quickfix_ commands like :cc.
Make sure to check vim.org_ for the latest updates.
.. _pyflakes.vim: http://www.vim.org/scripts/script.php?script_id=2441
.. _vim.org: http://www.vim.org/scripts/script.php?script_id=2441
.. _quickfix: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix
Quick Installation
------------------
1. Make sure your ``.vimrc`` has::
filetype on " enables filetype detection
filetype plugin on " enables filetype specific plugins
2. Download the latest release_.
3. If you're using pathogen_, unzip the contents of ``pyflakes-vim.zip`` into
its own bundle directory, i.e. into ``~/.vim/bundle/pyflakes-vim/``.
Otherwise unzip ``pyflakes.vim`` and the ``pyflakes`` directory into
``~/.vim/ftplugin/python`` (or somewhere similar on your
`runtime path`_ that will be sourced for Python files).
.. _release: http://www.vim.org/scripts/script.php?script_id=2441
.. _pathogen: http://www.vim.org/scripts/script.php?script_id=2332
.. _runtime path: http://vimdoc.sourceforge.net/htmldoc/options.html#'runtimepath'
Running from source
-------------------
If you're running pyflakes-vim "from source," you'll need the PyFlakes library
on your PYTHONPATH somewhere. (It is included in the vim.org zipfile.) I recommend
getting my PyFlakes_ fork, which retains column number information, giving more
specific error locations.
.. _vim.org: http://www.vim.org/scripts/script.php?script_id=2441
.. _PyFlakes: http://github.com/kevinw/pyflakes
Hacking
-------
::
git clone git://github.com/kevinw/pyflakes-vim.git
cd pyflakes-vim
git clone git://github.com/kevinw/pyflakes.git
Options
-------
Set this option to you vimrc file to disable quickfix support::
let g:pyflakes_use_quickfix = 0
The value is set to 1 by default.
TODO
----
* signs_ support (show warning and error icons to left of the buffer area)
* configuration variables
* parse or intercept useful output from the warnings module
.. _signs: http://www.vim.org/htmldoc/sign.html
Changelog
---------
Please see http://www.vim.org/scripts/script.php?script_id=2441 for a history of
all changes.

View File

@@ -0,0 +1,321 @@
" pyflakes.vim - A script to highlight Python code on the fly with warnings
" from Pyflakes, a Python lint tool.
"
" Place this script and the accompanying pyflakes directory in
" .vim/ftplugin/python.
"
" See README for additional installation and information.
"
" Thanks to matlib.vim for ideas/code on interactive linting.
"
" Maintainer: Kevin Watters <kevin.watters@gmail.com>
" Version: 0.1
if exists("b:did_pyflakes_plugin")
finish " only load once
else
let b:did_pyflakes_plugin = 1
endif
if !exists('g:pyflakes_builtins')
let g:pyflakes_builtins = []
endif
if !exists("b:did_python_init")
let b:did_python_init = 0
if !has('python')
echoerr "Error: the pyflakes.vim plugin requires Vim to be compiled with +python"
finish
endif
if !exists('g:pyflakes_use_quickfix')
let g:pyflakes_use_quickfix = 1
endif
python << EOF
import vim
import os.path
import sys
if sys.version_info[:2] < (2, 5):
raise AssertionError('Vim must be compiled with Python 2.5 or higher; you have ' + sys.version)
# get the directory this script is in: the pyflakes python module should be installed there.
scriptdir = os.path.join(os.path.dirname(vim.eval('expand("<sfile>")')), 'pyflakes')
sys.path.insert(0, scriptdir)
import ast
from pyflakes import checker, messages
from operator import attrgetter
import re
class loc(object):
def __init__(self, lineno, col=None):
self.lineno = lineno
self.col_offset = col
class SyntaxError(messages.Message):
message = 'could not compile: %s'
def __init__(self, filename, lineno, col, message):
messages.Message.__init__(self, filename, loc(lineno, col))
self.message_args = (message,)
class blackhole(object):
write = flush = lambda *a, **k: None
def check(buffer):
filename = buffer.name
contents = buffer[:]
# shebang usually found at the top of the file, followed by source code encoding marker.
# assume everything else that follows is encoded in the encoding.
encoding_found = False
for n, line in enumerate(contents):
if n >= 2:
break
elif re.match(r'#.*coding[:=]\s*([-\w.]+)', line):
contents = ['']*(n+1) + contents[n+1:]
break
contents = '\n'.join(contents) + '\n'
vimenc = vim.eval('&encoding')
if vimenc:
contents = contents.decode(vimenc)
builtins = set(['__file__'])
try:
builtins.update(set(eval(vim.eval('string(g:pyflakes_builtins)'))))
except Exception:
pass
try:
# TODO: use warnings filters instead of ignoring stderr
old_stderr, sys.stderr = sys.stderr, blackhole()
try:
tree = ast.parse(contents, filename or '<unknown>')
finally:
sys.stderr = old_stderr
except:
try:
value = sys.exc_info()[1]
lineno, offset, line = value[1][1:]
except IndexError:
lineno, offset, line = 1, 0, ''
if line and line.endswith("\n"):
line = line[:-1]
return [SyntaxError(filename, lineno, offset, str(value))]
else:
# pyflakes looks to _MAGIC_GLOBALS in checker.py to see which
# UndefinedNames to ignore
old_globals = getattr(checker,' _MAGIC_GLOBALS', [])
checker._MAGIC_GLOBALS = set(old_globals) | builtins
w = checker.Checker(tree, filename)
checker._MAGIC_GLOBALS = old_globals
w.messages.sort(key = attrgetter('lineno'))
return w.messages
def vim_quote(s):
return s.replace("'", "''")
EOF
let b:did_python_init = 1
endif
if !b:did_python_init
finish
endif
au BufLeave <buffer> call s:ClearPyflakes()
au BufEnter <buffer> call s:RunPyflakes()
au InsertLeave <buffer> call s:RunPyflakes()
au InsertEnter <buffer> call s:RunPyflakes()
au BufWritePost <buffer> call s:RunPyflakes()
au CursorHold <buffer> call s:RunPyflakes()
au CursorHoldI <buffer> call s:RunPyflakes()
au CursorHold <buffer> call s:GetPyflakesMessage()
au CursorMoved <buffer> call s:GetPyflakesMessage()
if !exists("*s:PyflakesUpdate")
function s:PyflakesUpdate()
silent call s:RunPyflakes()
call s:GetPyflakesMessage()
endfunction
endif
" Call this function in your .vimrc to update PyFlakes
if !exists(":PyflakesUpdate")
command PyflakesUpdate :call s:PyflakesUpdate()
endif
" Hook common text manipulation commands to update PyFlakes
" TODO: is there a more general "text op" autocommand we could register
" for here?
noremap <buffer><silent> dd dd:PyflakesUpdate<CR>
noremap <buffer><silent> dw dw:PyflakesUpdate<CR>
noremap <buffer><silent> u u:PyflakesUpdate<CR>
noremap <buffer><silent> <C-R> <C-R>:PyflakesUpdate<CR>
" WideMsg() prints [long] message up to (&columns-1) length
" guaranteed without "Press Enter" prompt.
if !exists("*s:WideMsg")
function s:WideMsg(msg)
let x=&ruler | let y=&showcmd
set noruler noshowcmd
redraw
echo strpart(a:msg, 0, &columns-1)
let &ruler=x | let &showcmd=y
endfun
endif
if !exists("*s:GetQuickFixStackCount")
function s:GetQuickFixStackCount()
let l:stack_count = 0
try
silent colder 9
catch /E380:/
endtry
try
for i in range(9)
silent cnewer
let l:stack_count = l:stack_count + 1
endfor
catch /E381:/
return l:stack_count
endtry
endfunction
endif
if !exists("*s:ActivatePyflakesQuickFixWindow")
function s:ActivatePyflakesQuickFixWindow()
try
silent colder 9 " go to the bottom of quickfix stack
catch /E380:/
endtry
if s:pyflakes_qf > 0
try
exe "silent cnewer " . s:pyflakes_qf
catch /E381:/
echoerr "Could not activate Pyflakes Quickfix Window."
endtry
endif
endfunction
endif
if !exists("*s:RunPyflakes")
function s:RunPyflakes()
highlight link PyFlakes SpellBad
if exists("b:cleared")
if b:cleared == 0
silent call s:ClearPyflakes()
let b:cleared = 1
endif
else
let b:cleared = 1
endif
let b:matched = []
let b:matchedlines = {}
let b:qf_list = []
let b:qf_window_count = -1
python << EOF
for w in check(vim.current.buffer):
vim.command('let s:matchDict = {}')
vim.command("let s:matchDict['lineNum'] = " + str(w.lineno))
vim.command("let s:matchDict['message'] = '%s'" % vim_quote(w.message % w.message_args))
vim.command("let b:matchedlines[" + str(w.lineno) + "] = s:matchDict")
vim.command("let l:qf_item = {}")
vim.command("let l:qf_item.bufnr = bufnr('%')")
vim.command("let l:qf_item.filename = expand('%')")
vim.command("let l:qf_item.lnum = %s" % str(w.lineno))
vim.command("let l:qf_item.text = '%s'" % vim_quote(w.message % w.message_args))
vim.command("let l:qf_item.type = 'E'")
if getattr(w, 'col', None) is None or isinstance(w, SyntaxError):
# without column information, just highlight the whole line
# (minus the newline)
vim.command(r"let s:mID = matchadd('PyFlakes', '\%" + str(w.lineno) + r"l\n\@!')")
else:
# with a column number, highlight the first keyword there
vim.command(r"let s:mID = matchadd('PyFlakes', '^\%" + str(w.lineno) + r"l\_.\{-}\zs\k\+\k\@!\%>" + str(w.col) + r"c')")
vim.command("let l:qf_item.vcol = 1")
vim.command("let l:qf_item.col = %s" % str(w.col + 1))
vim.command("call add(b:matched, s:matchDict)")
vim.command("call add(b:qf_list, l:qf_item)")
EOF
if g:pyflakes_use_quickfix == 1
if exists("s:pyflakes_qf")
" if pyflakes quickfix window is already created, reuse it
call s:ActivatePyflakesQuickFixWindow()
call setqflist(b:qf_list, 'r')
else
" one pyflakes quickfix window for all buffer
call setqflist(b:qf_list, '')
let s:pyflakes_qf = s:GetQuickFixStackCount()
endif
endif
let b:cleared = 0
endfunction
end
" keep track of whether or not we are showing a message
let b:showing_message = 0
if !exists("*s:GetPyflakesMessage")
function s:GetPyflakesMessage()
let s:cursorPos = getpos(".")
" Bail if RunPyflakes hasn't been called yet.
if !exists('b:matchedlines')
return
endif
" if there's a message for the line the cursor is currently on, echo
" it to the console
if has_key(b:matchedlines, s:cursorPos[1])
let s:pyflakesMatch = get(b:matchedlines, s:cursorPos[1])
call s:WideMsg(s:pyflakesMatch['message'])
let b:showing_message = 1
return
endif
" otherwise, if we're showing a message, clear it
if b:showing_message == 1
echo
let b:showing_message = 0
endif
endfunction
endif
if !exists('*s:ClearPyflakes')
function s:ClearPyflakes()
let s:matches = getmatches()
for s:matchId in s:matches
if s:matchId['group'] == 'PyFlakes'
call matchdelete(s:matchId['id'])
endif
endfor
let b:matched = []
let b:matchedlines = {}
let b:cleared = 1
endfunction
endif

View File

@@ -0,0 +1,21 @@
Copyright (c) 2005 Divmod, Inc., http://www.divmod.com/
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.

View File

@@ -0,0 +1,29 @@
0.4.0 (2009-11-25):
- Fix reporting for certain SyntaxErrors which lack line number
information.
- Check for syntax errors more rigorously.
- Support checking names used with the class decorator syntax in versions
of Python which have it.
- Detect local variables which are bound but never used.
- Handle permission errors when trying to read source files.
- Handle problems with the encoding of source files.
- Support importing dotted names so as not to incorrectly report them as
redefined unused names.
- Support all forms of the with statement.
- Consider static `__all__` definitions and avoid reporting unused names
if the names are listed there.
- Fix incorrect checking of class names with respect to the names of their
bases in the class statement.
- Support the `__path__` global in `__init__.py`.
0.3.0 (2009-01-30):
- Display more informative SyntaxError messages.
- Don't hang flymake with unmatched triple quotes (only report a single
line of source for a multiline syntax error).
- Recognize __builtins__ as a defined name.
- Improve pyflakes support for python versions 2.3-2.5
- Support for if-else expressions and with statements.
- Warn instead of error on non-existant file paths.
- Check for __future__ imports after other statements.
- Add reporting for some types of import shadowing.
- Improve reporting of unbound locals

View File

@@ -0,0 +1,4 @@
#!/usr/bin/python
from pyflakes.scripts.pyflakes import main
main()

View File

@@ -0,0 +1,2 @@
__version__ = '0.4.0'

View File

@@ -0,0 +1,625 @@
# -*- test-case-name: pyflakes -*-
# (c) 2005-2010 Divmod, Inc.
# See LICENSE file for details
import __builtin__
import os.path
import _ast
from pyflakes import messages
# utility function to iterate over an AST node's children, adapted
# from Python 2.6's standard ast module
try:
import ast
iter_child_nodes = ast.iter_child_nodes
except (ImportError, AttributeError):
def iter_child_nodes(node, astcls=_ast.AST):
"""
Yield all direct child nodes of *node*, that is, all fields that are nodes
and all items of fields that are lists of nodes.
"""
for name in node._fields:
field = getattr(node, name, None)
if isinstance(field, astcls):
yield field
elif isinstance(field, list):
for item in field:
yield item
class Binding(object):
"""
Represents the binding of a value to a name.
The checker uses this to keep track of which names have been bound and
which names have not. See L{Assignment} for a special type of binding that
is checked with stricter rules.
@ivar used: pair of (L{Scope}, line-number) indicating the scope and
line number that this binding was last used
"""
def __init__(self, name, source):
self.name = name
self.source = source
self.used = False
def __str__(self):
return self.name
def __repr__(self):
return '<%s object %r from line %r at 0x%x>' % (self.__class__.__name__,
self.name,
self.source.lineno,
id(self))
class UnBinding(Binding):
'''Created by the 'del' operator.'''
class Importation(Binding):
"""
A binding created by an import statement.
@ivar fullName: The complete name given to the import statement,
possibly including multiple dotted components.
@type fullName: C{str}
"""
def __init__(self, name, source):
self.fullName = name
name = name.split('.')[0]
super(Importation, self).__init__(name, source)
class Argument(Binding):
"""
Represents binding a name as an argument.
"""
class Assignment(Binding):
"""
Represents binding a name with an explicit assignment.
The checker will raise warnings for any Assignment that isn't used. Also,
the checker does not consider assignments in tuple/list unpacking to be
Assignments, rather it treats them as simple Bindings.
"""
class FunctionDefinition(Binding):
pass
class ExportBinding(Binding):
"""
A binding created by an C{__all__} assignment. If the names in the list
can be determined statically, they will be treated as names for export and
additional checking applied to them.
The only C{__all__} assignment that can be recognized is one which takes
the value of a literal list containing literal strings. For example::
__all__ = ["foo", "bar"]
Names which are imported and not otherwise used but appear in the value of
C{__all__} will not have an unused import warning reported for them.
"""
def names(self):
"""
Return a list of the names referenced by this binding.
"""
names = []
if isinstance(self.source, _ast.List):
for node in self.source.elts:
if isinstance(node, _ast.Str):
names.append(node.s)
return names
class Scope(dict):
importStarred = False # set to True when import * is found
def __repr__(self):
return '<%s at 0x%x %s>' % (self.__class__.__name__, id(self), dict.__repr__(self))
def __init__(self):
super(Scope, self).__init__()
class ClassScope(Scope):
pass
class FunctionScope(Scope):
"""
I represent a name scope for a function.
@ivar globals: Names declared 'global' in this function.
"""
def __init__(self):
super(FunctionScope, self).__init__()
self.globals = {}
class ModuleScope(Scope):
pass
# Globally defined names which are not attributes of the __builtin__ module.
_MAGIC_GLOBALS = ['__file__', '__builtins__']
class Checker(object):
"""
I check the cleanliness and sanity of Python code.
@ivar _deferredFunctions: Tracking list used by L{deferFunction}. Elements
of the list are two-tuples. The first element is the callable passed
to L{deferFunction}. The second element is a copy of the scope stack
at the time L{deferFunction} was called.
@ivar _deferredAssignments: Similar to C{_deferredFunctions}, but for
callables which are deferred assignment checks.
"""
nodeDepth = 0
traceTree = False
def __init__(self, tree, filename='(none)'):
self._deferredFunctions = []
self._deferredAssignments = []
self.dead_scopes = []
self.messages = []
self.filename = filename
self.scopeStack = [ModuleScope()]
self.futuresAllowed = True
self.handleChildren(tree)
self._runDeferred(self._deferredFunctions)
# Set _deferredFunctions to None so that deferFunction will fail
# noisily if called after we've run through the deferred functions.
self._deferredFunctions = None
self._runDeferred(self._deferredAssignments)
# Set _deferredAssignments to None so that deferAssignment will fail
# noisly if called after we've run through the deferred assignments.
self._deferredAssignments = None
del self.scopeStack[1:]
self.popScope()
self.check_dead_scopes()
def deferFunction(self, callable):
'''
Schedule a function handler to be called just before completion.
This is used for handling function bodies, which must be deferred
because code later in the file might modify the global scope. When
`callable` is called, the scope at the time this is called will be
restored, however it will contain any new bindings added to it.
'''
self._deferredFunctions.append((callable, self.scopeStack[:]))
def deferAssignment(self, callable):
"""
Schedule an assignment handler to be called just after deferred
function handlers.
"""
self._deferredAssignments.append((callable, self.scopeStack[:]))
def _runDeferred(self, deferred):
"""
Run the callables in C{deferred} using their associated scope stack.
"""
for handler, scope in deferred:
self.scopeStack = scope
handler()
def scope(self):
return self.scopeStack[-1]
scope = property(scope)
def popScope(self):
self.dead_scopes.append(self.scopeStack.pop())
def check_dead_scopes(self):
"""
Look at scopes which have been fully examined and report names in them
which were imported but unused.
"""
for scope in self.dead_scopes:
export = isinstance(scope.get('__all__'), ExportBinding)
if export:
all = scope['__all__'].names()
if os.path.split(self.filename)[1] != '__init__.py':
# Look for possible mistakes in the export list
undefined = set(all) - set(scope)
for name in undefined:
self.report(
messages.UndefinedExport,
scope['__all__'].source,
name)
else:
all = []
# Look for imported names that aren't used.
for importation in scope.itervalues():
if isinstance(importation, Importation):
if not importation.used and importation.name not in all:
self.report(
messages.UnusedImport,
importation.source,
importation.name)
def pushFunctionScope(self):
self.scopeStack.append(FunctionScope())
def pushClassScope(self):
self.scopeStack.append(ClassScope())
def report(self, messageClass, *args, **kwargs):
self.messages.append(messageClass(self.filename, *args, **kwargs))
def handleChildren(self, tree):
for node in iter_child_nodes(tree):
self.handleNode(node, tree)
def isDocstring(self, node):
"""
Determine if the given node is a docstring, as long as it is at the
correct place in the node tree.
"""
return isinstance(node, _ast.Str) or \
(isinstance(node, _ast.Expr) and
isinstance(node.value, _ast.Str))
def handleNode(self, node, parent):
node.parent = parent
if self.traceTree:
print ' ' * self.nodeDepth + node.__class__.__name__
self.nodeDepth += 1
if self.futuresAllowed and not \
(isinstance(node, _ast.ImportFrom) or self.isDocstring(node)):
self.futuresAllowed = False
nodeType = node.__class__.__name__.upper()
try:
handler = getattr(self, nodeType)
handler(node)
finally:
self.nodeDepth -= 1
if self.traceTree:
print ' ' * self.nodeDepth + 'end ' + node.__class__.__name__
def ignore(self, node):
pass
# "stmt" type nodes
RETURN = DELETE = PRINT = WHILE = IF = WITH = RAISE = TRYEXCEPT = \
TRYFINALLY = ASSERT = EXEC = EXPR = handleChildren
CONTINUE = BREAK = PASS = ignore
# "expr" type nodes
BOOLOP = BINOP = UNARYOP = IFEXP = DICT = SET = YIELD = COMPARE = \
CALL = REPR = ATTRIBUTE = SUBSCRIPT = LIST = TUPLE = handleChildren
NUM = STR = ELLIPSIS = ignore
# "slice" type nodes
SLICE = EXTSLICE = INDEX = handleChildren
# expression contexts are node instances too, though being constants
LOAD = STORE = DEL = AUGLOAD = AUGSTORE = PARAM = ignore
# same for operators
AND = OR = ADD = SUB = MULT = DIV = MOD = POW = LSHIFT = RSHIFT = \
BITOR = BITXOR = BITAND = FLOORDIV = INVERT = NOT = UADD = USUB = \
EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore
# additional node types
COMPREHENSION = EXCEPTHANDLER = KEYWORD = handleChildren
def addBinding(self, loc, value, reportRedef=True):
'''Called when a binding is altered.
- `loc` is the location (an object with lineno and optionally
col_offset attributes) of the statement responsible for the change
- `value` is the optional new value, a Binding instance, associated
with the binding; if None, the binding is deleted if it exists.
- if `reportRedef` is True (default), rebinding while unused will be
reported.
'''
if (isinstance(self.scope.get(value.name), FunctionDefinition)
and isinstance(value, FunctionDefinition)):
self.report(messages.RedefinedFunction,
loc, value.name, self.scope[value.name].source)
if not isinstance(self.scope, ClassScope):
for scope in self.scopeStack[::-1]:
existing = scope.get(value.name)
if (isinstance(existing, Importation)
and not existing.used
and (not isinstance(value, Importation) or value.fullName == existing.fullName)
and reportRedef):
self.report(messages.RedefinedWhileUnused,
loc, value.name, scope[value.name].source)
if isinstance(value, UnBinding):
try:
del self.scope[value.name]
except KeyError:
self.report(messages.UndefinedName, loc, value.name)
else:
self.scope[value.name] = value
def GLOBAL(self, node):
"""
Keep track of globals declarations.
"""
if isinstance(self.scope, FunctionScope):
self.scope.globals.update(dict.fromkeys(node.names))
def LISTCOMP(self, node):
# handle generators before element
for gen in node.generators:
self.handleNode(gen, node)
self.handleNode(node.elt, node)
GENERATOREXP = SETCOMP = LISTCOMP
# dictionary comprehensions; introduced in Python 2.7
def DICTCOMP(self, node):
for gen in node.generators:
self.handleNode(gen, node)
self.handleNode(node.key, node)
self.handleNode(node.value, node)
def FOR(self, node):
"""
Process bindings for loop variables.
"""
vars = []
def collectLoopVars(n):
if isinstance(n, _ast.Name):
vars.append(n.id)
elif isinstance(n, _ast.expr_context):
return
else:
for c in iter_child_nodes(n):
collectLoopVars(c)
collectLoopVars(node.target)
for varn in vars:
if (isinstance(self.scope.get(varn), Importation)
# unused ones will get an unused import warning
and self.scope[varn].used):
self.report(messages.ImportShadowedByLoopVar,
node, varn, self.scope[varn].source)
self.handleChildren(node)
def NAME(self, node):
"""
Handle occurrence of Name (which can be a load/store/delete access.)
"""
# Locate the name in locals / function / globals scopes.
if isinstance(node.ctx, (_ast.Load, _ast.AugLoad)):
# try local scope
importStarred = self.scope.importStarred
try:
self.scope[node.id].used = (self.scope, node)
except KeyError:
pass
else:
return
# try enclosing function scopes
for scope in self.scopeStack[-2:0:-1]:
importStarred = importStarred or scope.importStarred
if not isinstance(scope, FunctionScope):
continue
try:
scope[node.id].used = (self.scope, node)
except KeyError:
pass
else:
return
# try global scope
importStarred = importStarred or self.scopeStack[0].importStarred
try:
self.scopeStack[0][node.id].used = (self.scope, node)
except KeyError:
if ((not hasattr(__builtin__, node.id))
and node.id not in _MAGIC_GLOBALS
and not importStarred):
if (os.path.basename(self.filename) == '__init__.py' and
node.id == '__path__'):
# the special name __path__ is valid only in packages
pass
else:
self.report(messages.UndefinedName, node, node.id)
elif isinstance(node.ctx, (_ast.Store, _ast.AugStore)):
# if the name hasn't already been defined in the current scope
if isinstance(self.scope, FunctionScope) and node.id not in self.scope:
# for each function or module scope above us
for scope in self.scopeStack[:-1]:
if not isinstance(scope, (FunctionScope, ModuleScope)):
continue
# if the name was defined in that scope, and the name has
# been accessed already in the current scope, and hasn't
# been declared global
if (node.id in scope
and scope[node.id].used
and scope[node.id].used[0] is self.scope
and node.id not in self.scope.globals):
# then it's probably a mistake
self.report(messages.UndefinedLocal,
scope[node.id].used[1],
node.id,
scope[node.id].source)
break
if isinstance(node.parent,
(_ast.For, _ast.comprehension, _ast.Tuple, _ast.List)):
binding = Binding(node.id, node)
elif (node.id == '__all__' and
isinstance(self.scope, ModuleScope)):
binding = ExportBinding(node.id, node.parent.value)
else:
binding = Assignment(node.id, node)
if node.id in self.scope:
binding.used = self.scope[node.id].used
self.addBinding(node, binding)
elif isinstance(node.ctx, _ast.Del):
if isinstance(self.scope, FunctionScope) and \
node.id in self.scope.globals:
del self.scope.globals[node.id]
else:
self.addBinding(node, UnBinding(node.id, node))
else:
# must be a Param context -- this only happens for names in function
# arguments, but these aren't dispatched through here
raise RuntimeError(
"Got impossible expression context: %r" % (node.ctx,))
def FUNCTIONDEF(self, node):
# the decorators attribute is called decorator_list as of Python 2.6
if hasattr(node, 'decorators'):
for deco in node.decorators:
self.handleNode(deco, node)
else:
for deco in node.decorator_list:
self.handleNode(deco, node)
self.addBinding(node, FunctionDefinition(node.name, node))
self.LAMBDA(node)
def LAMBDA(self, node):
for default in node.args.defaults:
self.handleNode(default, node)
def runFunction():
args = []
def addArgs(arglist):
for arg in arglist:
if isinstance(arg, _ast.Tuple):
addArgs(arg.elts)
else:
if arg.id in args:
self.report(messages.DuplicateArgument,
node, arg.id)
args.append(arg.id)
self.pushFunctionScope()
addArgs(node.args.args)
# vararg/kwarg identifiers are not Name nodes
if node.args.vararg:
args.append(node.args.vararg)
if node.args.kwarg:
args.append(node.args.kwarg)
for name in args:
self.addBinding(node, Argument(name, node), reportRedef=False)
if isinstance(node.body, list):
# case for FunctionDefs
for stmt in node.body:
self.handleNode(stmt, node)
else:
# case for Lambdas
self.handleNode(node.body, node)
def checkUnusedAssignments():
"""
Check to see if any assignments have not been used.
"""
for name, binding in self.scope.iteritems():
if (not binding.used and not name in self.scope.globals
and isinstance(binding, Assignment)):
self.report(messages.UnusedVariable,
binding.source, name)
self.deferAssignment(checkUnusedAssignments)
self.popScope()
self.deferFunction(runFunction)
def CLASSDEF(self, node):
"""
Check names used in a class definition, including its decorators, base
classes, and the body of its definition. Additionally, add its name to
the current scope.
"""
# decorator_list is present as of Python 2.6
for deco in getattr(node, 'decorator_list', []):
self.handleNode(deco, node)
for baseNode in node.bases:
self.handleNode(baseNode, node)
self.pushClassScope()
for stmt in node.body:
self.handleNode(stmt, node)
self.popScope()
self.addBinding(node, Binding(node.name, node))
def ASSIGN(self, node):
self.handleNode(node.value, node)
for target in node.targets:
self.handleNode(target, node)
def AUGASSIGN(self, node):
# AugAssign is awkward: must set the context explicitly and visit twice,
# once with AugLoad context, once with AugStore context
node.target.ctx = _ast.AugLoad()
self.handleNode(node.target, node)
self.handleNode(node.value, node)
node.target.ctx = _ast.AugStore()
self.handleNode(node.target, node)
def IMPORT(self, node):
for alias in node.names:
name = alias.asname or alias.name
importation = Importation(name, node)
self.addBinding(node, importation)
def IMPORTFROM(self, node):
if node.module == '__future__':
if not self.futuresAllowed:
self.report(messages.LateFutureImport, node,
[n.name for n in node.names])
else:
self.futuresAllowed = False
for alias in node.names:
if alias.name == '*':
self.scope.importStarred = True
self.report(messages.ImportStarUsed, node, node.module)
continue
name = alias.asname or alias.name
importation = Importation(name, node)
if node.module == '__future__':
importation.used = (self.scope, node)
self.addBinding(node, importation)

View File

@@ -0,0 +1,96 @@
# (c) 2005 Divmod, Inc. See LICENSE file for details
class Message(object):
message = ''
message_args = ()
def __init__(self, filename, loc, use_column=True):
self.filename = filename
self.lineno = loc.lineno
self.col = getattr(loc, 'col_offset', None) if use_column else None
def __str__(self):
return '%s:%s: %s' % (self.filename, self.lineno, self.message % self.message_args)
class UnusedImport(Message):
message = '%r imported but unused'
def __init__(self, filename, loc, name):
Message.__init__(self, filename, loc, use_column=False)
self.message_args = (name,)
class RedefinedWhileUnused(Message):
message = 'redefinition of unused %r from line %r'
def __init__(self, filename, loc, name, orig_loc):
Message.__init__(self, filename, loc)
self.message_args = (name, orig_loc.lineno)
class ImportShadowedByLoopVar(Message):
message = 'import %r from line %r shadowed by loop variable'
def __init__(self, filename, loc, name, orig_loc):
Message.__init__(self, filename, loc)
self.message_args = (name, orig_loc.lineno)
class ImportStarUsed(Message):
message = "'from %s import *' used; unable to detect undefined names"
def __init__(self, filename, loc, modname):
Message.__init__(self, filename, loc)
self.message_args = (modname,)
class UndefinedName(Message):
message = 'undefined name %r'
def __init__(self, filename, loc, name):
Message.__init__(self, filename, loc)
self.message_args = (name,)
class UndefinedExport(Message):
message = 'undefined name %r in __all__'
def __init__(self, filename, loc, name):
Message.__init__(self, filename, loc)
self.message_args = (name,)
class UndefinedLocal(Message):
message = "local variable %r (defined in enclosing scope on line %r) referenced before assignment"
def __init__(self, filename, loc, name, orig_loc):
Message.__init__(self, filename, loc)
self.message_args = (name, orig_loc.lineno)
class DuplicateArgument(Message):
message = 'duplicate argument %r in function definition'
def __init__(self, filename, loc, name):
Message.__init__(self, filename, loc)
self.message_args = (name,)
class RedefinedFunction(Message):
message = 'redefinition of function %r from line %r'
def __init__(self, filename, loc, name, orig_loc):
Message.__init__(self, filename, loc)
self.message_args = (name, orig_loc.lineno)
class LateFutureImport(Message):
message = 'future import(s) %r after other statements'
def __init__(self, filename, loc, names):
Message.__init__(self, filename, loc)
self.message_args = (names,)
class UnusedVariable(Message):
"""
Indicates that a variable has been explicity assigned to but not actually
used.
"""
message = 'local variable %r is assigned to but never used'
def __init__(self, filename, loc, names):
Message.__init__(self, filename, loc)
self.message_args = (names,)

View File

@@ -0,0 +1,90 @@
"""
Implementation of the command-line I{pyflakes} tool.
"""
import sys
import os
import _ast
checker = __import__('pyflakes.checker').checker
def check(codeString, filename):
"""
Check the Python source given by C{codeString} for flakes.
@param codeString: The Python source to check.
@type codeString: C{str}
@param filename: The name of the file the source came from, used to report
errors.
@type filename: C{str}
@return: The number of warnings emitted.
@rtype: C{int}
"""
# First, compile into an AST and handle syntax errors.
try:
tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
except SyntaxError, value:
msg = value.args[0]
(lineno, offset, text) = value.lineno, value.offset, value.text
# If there's an encoding problem with the file, the text is None.
if text is None:
# Avoid using msg, since for the only known case, it contains a
# bogus message that claims the encoding the file declared was
# unknown.
print >> sys.stderr, "%s: problem decoding source" % (filename, )
else:
line = text.splitlines()[-1]
if offset is not None:
offset = offset - (len(text) - len(line))
print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg)
print >> sys.stderr, line
if offset is not None:
print >> sys.stderr, " " * offset, "^"
return 1
else:
# Okay, it's syntactically valid. Now check it.
w = checker.Checker(tree, filename)
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
for warning in w.messages:
print warning
return len(w.messages)
def checkPath(filename):
"""
Check the given path, printing out any warnings detected.
@return: the number of warnings printed
"""
try:
return check(file(filename, 'U').read() + '\n', filename)
except IOError, msg:
print >> sys.stderr, "%s: %s" % (filename, msg.args[1])
return 1
def main():
warnings = 0
args = sys.argv[1:]
if args:
for arg in args:
if os.path.isdir(arg):
for dirpath, dirnames, filenames in os.walk(arg):
for filename in filenames:
if filename.endswith('.py'):
warnings += checkPath(os.path.join(dirpath, filename))
else:
warnings += checkPath(arg)
else:
warnings += check(sys.stdin.read(), '<stdin>')
raise SystemExit(warnings > 0)

View File

@@ -0,0 +1,27 @@
import textwrap
import _ast
from twisted.trial import unittest
from pyflakes import checker
class Test(unittest.TestCase):
def flakes(self, input, *expectedOutputs, **kw):
ast = compile(textwrap.dedent(input), "<test>", "exec",
_ast.PyCF_ONLY_AST)
w = checker.Checker(ast, **kw)
outputs = [type(o) for o in w.messages]
expectedOutputs = list(expectedOutputs)
outputs.sort()
expectedOutputs.sort()
self.assert_(outputs == expectedOutputs, '''\
for input:
%s
expected outputs:
%s
but got:
%s''' % (input, repr(expectedOutputs), '\n'.join([str(o) for o in w.messages])))
return w

View File

@@ -0,0 +1,673 @@
from sys import version_info
from pyflakes import messages as m
from pyflakes.test import harness
class Test(harness.Test):
def test_unusedImport(self):
self.flakes('import fu, bar', m.UnusedImport, m.UnusedImport)
self.flakes('from baz import fu, bar', m.UnusedImport, m.UnusedImport)
def test_aliasedImport(self):
self.flakes('import fu as FU, bar as FU', m.RedefinedWhileUnused, m.UnusedImport)
self.flakes('from moo import fu as FU, bar as FU', m.RedefinedWhileUnused, m.UnusedImport)
def test_usedImport(self):
self.flakes('import fu; print fu')
self.flakes('from baz import fu; print fu')
def test_redefinedWhileUnused(self):
self.flakes('import fu; fu = 3', m.RedefinedWhileUnused)
self.flakes('import fu; del fu', m.RedefinedWhileUnused)
self.flakes('import fu; fu, bar = 3', m.RedefinedWhileUnused)
self.flakes('import fu; [fu, bar] = 3', m.RedefinedWhileUnused)
def test_redefinedByFunction(self):
self.flakes('''
import fu
def fu():
pass
''', m.RedefinedWhileUnused)
def test_redefinedInNestedFunction(self):
"""
Test that shadowing a global name with a nested function definition
generates a warning.
"""
self.flakes('''
import fu
def bar():
def baz():
def fu():
pass
''', m.RedefinedWhileUnused, m.UnusedImport)
def test_redefinedByClass(self):
self.flakes('''
import fu
class fu:
pass
''', m.RedefinedWhileUnused)
def test_redefinedBySubclass(self):
"""
If an imported name is redefined by a class statement which also uses
that name in the bases list, no warning is emitted.
"""
self.flakes('''
from fu import bar
class bar(bar):
pass
''')
def test_redefinedInClass(self):
"""
Test that shadowing a global with a class attribute does not produce a
warning.
"""
self.flakes('''
import fu
class bar:
fu = 1
print fu
''')
def test_usedInFunction(self):
self.flakes('''
import fu
def fun():
print fu
''')
def test_shadowedByParameter(self):
self.flakes('''
import fu
def fun(fu):
print fu
''', m.UnusedImport)
self.flakes('''
import fu
def fun(fu):
print fu
print fu
''')
def test_newAssignment(self):
self.flakes('fu = None')
def test_usedInGetattr(self):
self.flakes('import fu; fu.bar.baz')
self.flakes('import fu; "bar".fu.baz', m.UnusedImport)
def test_usedInSlice(self):
self.flakes('import fu; print fu.bar[1:]')
def test_usedInIfBody(self):
self.flakes('''
import fu
if True: print fu
''')
def test_usedInIfConditional(self):
self.flakes('''
import fu
if fu: pass
''')
def test_usedInElifConditional(self):
self.flakes('''
import fu
if False: pass
elif fu: pass
''')
def test_usedInElse(self):
self.flakes('''
import fu
if False: pass
else: print fu
''')
def test_usedInCall(self):
self.flakes('import fu; fu.bar()')
def test_usedInClass(self):
self.flakes('''
import fu
class bar:
bar = fu
''')
def test_usedInClassBase(self):
self.flakes('''
import fu
class bar(object, fu.baz):
pass
''')
def test_notUsedInNestedScope(self):
self.flakes('''
import fu
def bleh():
pass
print fu
''')
def test_usedInFor(self):
self.flakes('''
import fu
for bar in range(9):
print fu
''')
def test_usedInForElse(self):
self.flakes('''
import fu
for bar in range(10):
pass
else:
print fu
''')
def test_redefinedByFor(self):
self.flakes('''
import fu
for fu in range(2):
pass
''', m.RedefinedWhileUnused)
def test_shadowedByFor(self):
"""
Test that shadowing a global name with a for loop variable generates a
warning.
"""
self.flakes('''
import fu
fu.bar()
for fu in ():
pass
''', m.ImportShadowedByLoopVar)
def test_shadowedByForDeep(self):
"""
Test that shadowing a global name with a for loop variable nested in a
tuple unpack generates a warning.
"""
self.flakes('''
import fu
fu.bar()
for (x, y, z, (a, b, c, (fu,))) in ():
pass
''', m.ImportShadowedByLoopVar)
def test_usedInReturn(self):
self.flakes('''
import fu
def fun():
return fu
''')
def test_usedInOperators(self):
self.flakes('import fu; 3 + fu.bar')
self.flakes('import fu; 3 % fu.bar')
self.flakes('import fu; 3 - fu.bar')
self.flakes('import fu; 3 * fu.bar')
self.flakes('import fu; 3 ** fu.bar')
self.flakes('import fu; 3 / fu.bar')
self.flakes('import fu; 3 // fu.bar')
self.flakes('import fu; -fu.bar')
self.flakes('import fu; ~fu.bar')
self.flakes('import fu; 1 == fu.bar')
self.flakes('import fu; 1 | fu.bar')
self.flakes('import fu; 1 & fu.bar')
self.flakes('import fu; 1 ^ fu.bar')
self.flakes('import fu; 1 >> fu.bar')
self.flakes('import fu; 1 << fu.bar')
def test_usedInAssert(self):
self.flakes('import fu; assert fu.bar')
def test_usedInSubscript(self):
self.flakes('import fu; fu.bar[1]')
def test_usedInLogic(self):
self.flakes('import fu; fu and False')
self.flakes('import fu; fu or False')
self.flakes('import fu; not fu.bar')
def test_usedInList(self):
self.flakes('import fu; [fu]')
def test_usedInTuple(self):
self.flakes('import fu; (fu,)')
def test_usedInTry(self):
self.flakes('''
import fu
try: fu
except: pass
''')
def test_usedInExcept(self):
self.flakes('''
import fu
try: fu
except: pass
''')
def test_redefinedByExcept(self):
self.flakes('''
import fu
try: pass
except Exception, fu: pass
''', m.RedefinedWhileUnused)
def test_usedInRaise(self):
self.flakes('''
import fu
raise fu.bar
''')
def test_usedInYield(self):
self.flakes('''
import fu
def gen():
yield fu
''')
def test_usedInDict(self):
self.flakes('import fu; {fu:None}')
self.flakes('import fu; {1:fu}')
def test_usedInParameterDefault(self):
self.flakes('''
import fu
def f(bar=fu):
pass
''')
def test_usedInAttributeAssign(self):
self.flakes('import fu; fu.bar = 1')
def test_usedInKeywordArg(self):
self.flakes('import fu; fu.bar(stuff=fu)')
def test_usedInAssignment(self):
self.flakes('import fu; bar=fu')
self.flakes('import fu; n=0; n+=fu')
def test_usedInListComp(self):
self.flakes('import fu; [fu for _ in range(1)]')
self.flakes('import fu; [1 for _ in range(1) if fu]')
def test_redefinedByListComp(self):
self.flakes('import fu; [1 for fu in range(1)]', m.RedefinedWhileUnused)
def test_usedInTryFinally(self):
self.flakes('''
import fu
try: pass
finally: fu
''')
self.flakes('''
import fu
try: fu
finally: pass
''')
def test_usedInWhile(self):
self.flakes('''
import fu
while 0:
fu
''')
self.flakes('''
import fu
while fu: pass
''')
def test_usedInGlobal(self):
self.flakes('''
import fu
def f(): global fu
''', m.UnusedImport)
def test_usedInBackquote(self):
self.flakes('import fu; `fu`')
def test_usedInExec(self):
self.flakes('import fu; exec "print 1" in fu.bar')
def test_usedInLambda(self):
self.flakes('import fu; lambda: fu')
def test_shadowedByLambda(self):
self.flakes('import fu; lambda fu: fu', m.UnusedImport)
def test_usedInSliceObj(self):
self.flakes('import fu; "meow"[::fu]')
def test_unusedInNestedScope(self):
self.flakes('''
def bar():
import fu
fu
''', m.UnusedImport, m.UndefinedName)
def test_methodsDontUseClassScope(self):
self.flakes('''
class bar:
import fu
def fun(self):
fu
''', m.UnusedImport, m.UndefinedName)
def test_nestedFunctionsNestScope(self):
self.flakes('''
def a():
def b():
fu
import fu
''')
def test_nestedClassAndFunctionScope(self):
self.flakes('''
def a():
import fu
class b:
def c(self):
print fu
''')
def test_importStar(self):
self.flakes('from fu import *', m.ImportStarUsed)
def test_packageImport(self):
"""
If a dotted name is imported and used, no warning is reported.
"""
self.flakes('''
import fu.bar
fu.bar
''')
def test_unusedPackageImport(self):
"""
If a dotted name is imported and not used, an unused import warning is
reported.
"""
self.flakes('import fu.bar', m.UnusedImport)
def test_duplicateSubmoduleImport(self):
"""
If a submodule of a package is imported twice, an unused import warning
and a redefined while unused warning are reported.
"""
self.flakes('''
import fu.bar, fu.bar
fu.bar
''', m.RedefinedWhileUnused)
self.flakes('''
import fu.bar
import fu.bar
fu.bar
''', m.RedefinedWhileUnused)
def test_differentSubmoduleImport(self):
"""
If two different submodules of a package are imported, no duplicate
import warning is reported for the package.
"""
self.flakes('''
import fu.bar, fu.baz
fu.bar, fu.baz
''')
self.flakes('''
import fu.bar
import fu.baz
fu.bar, fu.baz
''')
def test_assignRHSFirst(self):
self.flakes('import fu; fu = fu')
self.flakes('import fu; fu, bar = fu')
self.flakes('import fu; [fu, bar] = fu')
self.flakes('import fu; fu += fu')
def test_tryingMultipleImports(self):
self.flakes('''
try:
import fu
except ImportError:
import bar as fu
''')
test_tryingMultipleImports.todo = ''
def test_nonGlobalDoesNotRedefine(self):
self.flakes('''
import fu
def a():
fu = 3
return fu
fu
''')
def test_functionsRunLater(self):
self.flakes('''
def a():
fu
import fu
''')
def test_functionNamesAreBoundNow(self):
self.flakes('''
import fu
def fu():
fu
fu
''', m.RedefinedWhileUnused)
def test_ignoreNonImportRedefinitions(self):
self.flakes('a = 1; a = 2')
def test_importingForImportError(self):
self.flakes('''
try:
import fu
except ImportError:
pass
''')
test_importingForImportError.todo = ''
def test_importedInClass(self):
'''Imports in class scope can be used through self'''
self.flakes('''
class c:
import i
def __init__(self):
self.i
''')
test_importedInClass.todo = 'requires evaluating attribute access'
def test_futureImport(self):
'''__future__ is special'''
self.flakes('from __future__ import division')
self.flakes('''
"docstring is allowed before future import"
from __future__ import division
''')
def test_futureImportFirst(self):
"""
__future__ imports must come before anything else.
"""
self.flakes('''
x = 5
from __future__ import division
''', m.LateFutureImport)
self.flakes('''
from foo import bar
from __future__ import division
bar
''', m.LateFutureImport)
class TestSpecialAll(harness.Test):
"""
Tests for suppression of unused import warnings by C{__all__}.
"""
def test_ignoredInFunction(self):
"""
An C{__all__} definition does not suppress unused import warnings in a
function scope.
"""
self.flakes('''
def foo():
import bar
__all__ = ["bar"]
''', m.UnusedImport, m.UnusedVariable)
def test_ignoredInClass(self):
"""
An C{__all__} definition does not suppress unused import warnings in a
class scope.
"""
self.flakes('''
class foo:
import bar
__all__ = ["bar"]
''', m.UnusedImport)
def test_warningSuppressed(self):
"""
If a name is imported and unused but is named in C{__all__}, no warning
is reported.
"""
self.flakes('''
import foo
__all__ = ["foo"]
''')
def test_unrecognizable(self):
"""
If C{__all__} is defined in a way that can't be recognized statically,
it is ignored.
"""
self.flakes('''
import foo
__all__ = ["f" + "oo"]
''', m.UnusedImport)
self.flakes('''
import foo
__all__ = [] + ["foo"]
''', m.UnusedImport)
def test_unboundExported(self):
"""
If C{__all__} includes a name which is not bound, a warning is emitted.
"""
self.flakes('''
__all__ = ["foo"]
''', m.UndefinedExport)
# Skip this in __init__.py though, since the rules there are a little
# different.
for filename in ["foo/__init__.py", "__init__.py"]:
self.flakes('''
__all__ = ["foo"]
''', filename=filename)
def test_usedInGenExp(self):
"""
Using a global in a generator expression results in no warnings.
"""
self.flakes('import fu; (fu for _ in range(1))')
self.flakes('import fu; (1 for _ in range(1) if fu)')
def test_redefinedByGenExp(self):
"""
Re-using a global name as the loop variable for a generator
expression results in a redefinition warning.
"""
self.flakes('import fu; (1 for fu in range(1))', m.RedefinedWhileUnused)
def test_usedAsDecorator(self):
"""
Using a global name in a decorator statement results in no warnings,
but using an undefined name in a decorator statement results in an
undefined name warning.
"""
self.flakes('''
from interior import decorate
@decorate
def f():
return "hello"
''')
self.flakes('''
from interior import decorate
@decorate('value')
def f():
return "hello"
''')
self.flakes('''
@decorate
def f():
return "hello"
''', m.UndefinedName)
class Python26Tests(harness.Test):
"""
Tests for checking of syntax which is valid in PYthon 2.6 and newer.
"""
if version_info < (2, 6):
skip = "Python 2.6 required for class decorator tests."
def test_usedAsClassDecorator(self):
"""
Using an imported name as a class decorator results in no warnings,
but using an undefined name as a class decorator results in an
undefined name warning.
"""
self.flakes('''
from interior import decorate
@decorate
class foo:
pass
''')
self.flakes('''
from interior import decorate
@decorate("foo")
class bar:
pass
''')
self.flakes('''
@decorate
class foo:
pass
''', m.UndefinedName)

View File

@@ -0,0 +1,575 @@
# (c) 2005-2010 Divmod, Inc.
# See LICENSE file for details
"""
Tests for various Pyflakes behavior.
"""
from sys import version_info
from pyflakes import messages as m
from pyflakes.test import harness
class Test(harness.Test):
def test_duplicateArgs(self):
self.flakes('def fu(bar, bar): pass', m.DuplicateArgument)
def test_localReferencedBeforeAssignment(self):
self.flakes('''
a = 1
def f():
a; a=1
f()
''', m.UndefinedName)
test_localReferencedBeforeAssignment.todo = 'this requires finding all assignments in the function body first'
def test_redefinedFunction(self):
"""
Test that shadowing a function definition with another one raises a
warning.
"""
self.flakes('''
def a(): pass
def a(): pass
''', m.RedefinedFunction)
def test_redefinedClassFunction(self):
"""
Test that shadowing a function definition in a class suite with another
one raises a warning.
"""
self.flakes('''
class A:
def a(): pass
def a(): pass
''', m.RedefinedFunction)
def test_functionDecorator(self):
"""
Test that shadowing a function definition with a decorated version of
that function does not raise a warning.
"""
self.flakes('''
from somewhere import somedecorator
def a(): pass
a = somedecorator(a)
''')
def test_classFunctionDecorator(self):
"""
Test that shadowing a function definition in a class suite with a
decorated version of that function does not raise a warning.
"""
self.flakes('''
class A:
def a(): pass
a = classmethod(a)
''')
def test_unaryPlus(self):
'''Don't die on unary +'''
self.flakes('+1')
def test_undefinedBaseClass(self):
"""
If a name in the base list of a class definition is undefined, a
warning is emitted.
"""
self.flakes('''
class foo(foo):
pass
''', m.UndefinedName)
def test_classNameUndefinedInClassBody(self):
"""
If a class name is used in the body of that class's definition and
the name is not already defined, a warning is emitted.
"""
self.flakes('''
class foo:
foo
''', m.UndefinedName)
def test_classNameDefinedPreviously(self):
"""
If a class name is used in the body of that class's definition and
the name was previously defined in some other way, no warning is
emitted.
"""
self.flakes('''
foo = None
class foo:
foo
''')
def test_comparison(self):
"""
If a defined name is used on either side of any of the six comparison
operators, no warning is emitted.
"""
self.flakes('''
x = 10
y = 20
x < y
x <= y
x == y
x != y
x >= y
x > y
''')
def test_identity(self):
"""
If a deefined name is used on either side of an identity test, no
warning is emitted.
"""
self.flakes('''
x = 10
y = 20
x is y
x is not y
''')
def test_containment(self):
"""
If a defined name is used on either side of a containment test, no
warning is emitted.
"""
self.flakes('''
x = 10
y = 20
x in y
x not in y
''')
def test_loopControl(self):
"""
break and continue statements are supported.
"""
self.flakes('''
for x in [1, 2]:
break
''')
self.flakes('''
for x in [1, 2]:
continue
''')
def test_ellipsis(self):
"""
Ellipsis in a slice is supported.
"""
self.flakes('''
[1, 2][...]
''')
def test_extendedSlice(self):
"""
Extended slices are supported.
"""
self.flakes('''
x = 3
[1, 2][x,:]
''')
class TestUnusedAssignment(harness.Test):
"""
Tests for warning about unused assignments.
"""
def test_unusedVariable(self):
"""
Warn when a variable in a function is assigned a value that's never
used.
"""
self.flakes('''
def a():
b = 1
''', m.UnusedVariable)
def test_assignToGlobal(self):
"""
Assigning to a global and then not using that global is perfectly
acceptable. Do not mistake it for an unused local variable.
"""
self.flakes('''
b = 0
def a():
global b
b = 1
''')
def test_assignToMember(self):
"""
Assigning to a member of another object and then not using that member
variable is perfectly acceptable. Do not mistake it for an unused
local variable.
"""
# XXX: Adding this test didn't generate a failure. Maybe not
# necessary?
self.flakes('''
class b:
pass
def a():
b.foo = 1
''')
def test_assignInForLoop(self):
"""
Don't warn when a variable in a for loop is assigned to but not used.
"""
self.flakes('''
def f():
for i in range(10):
pass
''')
def test_assignInListComprehension(self):
"""
Don't warn when a variable in a list comprehension is assigned to but
not used.
"""
self.flakes('''
def f():
[None for i in range(10)]
''')
def test_generatorExpression(self):
"""
Don't warn when a variable in a generator expression is assigned to but not used.
"""
self.flakes('''
def f():
(None for i in range(10))
''')
def test_assignmentInsideLoop(self):
"""
Don't warn when a variable assignment occurs lexically after its use.
"""
self.flakes('''
def f():
x = None
for i in range(10):
if i > 2:
return x
x = i * 2
''')
def test_tupleUnpacking(self):
"""
Don't warn when a variable included in tuple unpacking is unused. It's
very common for variables in a tuple unpacking assignment to be unused
in good Python code, so warning will only create false positives.
"""
self.flakes('''
def f():
(x, y) = 1, 2
''')
def test_listUnpacking(self):
"""
Don't warn when a variable included in list unpacking is unused.
"""
self.flakes('''
def f():
[x, y] = [1, 2]
''')
def test_closedOver(self):
"""
Don't warn when the assignment is used in an inner function.
"""
self.flakes('''
def barMaker():
foo = 5
def bar():
return foo
return bar
''')
def test_doubleClosedOver(self):
"""
Don't warn when the assignment is used in an inner function, even if
that inner function itself is in an inner function.
"""
self.flakes('''
def barMaker():
foo = 5
def bar():
def baz():
return foo
return bar
''')
class Python25Test(harness.Test):
"""
Tests for checking of syntax only available in Python 2.5 and newer.
"""
if version_info < (2, 5):
skip = "Python 2.5 required for if-else and with tests"
def test_ifexp(self):
"""
Test C{foo if bar else baz} statements.
"""
self.flakes("a = 'moo' if True else 'oink'")
self.flakes("a = foo if True else 'oink'", m.UndefinedName)
self.flakes("a = 'moo' if True else bar", m.UndefinedName)
def test_withStatementNoNames(self):
"""
No warnings are emitted for using inside or after a nameless C{with}
statement a name defined beforehand.
"""
self.flakes('''
from __future__ import with_statement
bar = None
with open("foo"):
bar
bar
''')
def test_withStatementSingleName(self):
"""
No warnings are emitted for using a name defined by a C{with} statement
within the suite or afterwards.
"""
self.flakes('''
from __future__ import with_statement
with open('foo') as bar:
bar
bar
''')
def test_withStatementAttributeName(self):
"""
No warnings are emitted for using an attribute as the target of a
C{with} statement.
"""
self.flakes('''
from __future__ import with_statement
import foo
with open('foo') as foo.bar:
pass
''')
def test_withStatementSubscript(self):
"""
No warnings are emitted for using a subscript as the target of a
C{with} statement.
"""
self.flakes('''
from __future__ import with_statement
import foo
with open('foo') as foo[0]:
pass
''')
def test_withStatementSubscriptUndefined(self):
"""
An undefined name warning is emitted if the subscript used as the
target of a C{with} statement is not defined.
"""
self.flakes('''
from __future__ import with_statement
import foo
with open('foo') as foo[bar]:
pass
''', m.UndefinedName)
def test_withStatementTupleNames(self):
"""
No warnings are emitted for using any of the tuple of names defined by
a C{with} statement within the suite or afterwards.
"""
self.flakes('''
from __future__ import with_statement
with open('foo') as (bar, baz):
bar, baz
bar, baz
''')
def test_withStatementListNames(self):
"""
No warnings are emitted for using any of the list of names defined by a
C{with} statement within the suite or afterwards.
"""
self.flakes('''
from __future__ import with_statement
with open('foo') as [bar, baz]:
bar, baz
bar, baz
''')
def test_withStatementComplicatedTarget(self):
"""
If the target of a C{with} statement uses any or all of the valid forms
for that part of the grammar (See
U{http://docs.python.org/reference/compound_stmts.html#the-with-statement}),
the names involved are checked both for definedness and any bindings
created are respected in the suite of the statement and afterwards.
"""
self.flakes('''
from __future__ import with_statement
c = d = e = g = h = i = None
with open('foo') as [(a, b), c[d], e.f, g[h:i]]:
a, b, c, d, e, g, h, i
a, b, c, d, e, g, h, i
''')
def test_withStatementSingleNameUndefined(self):
"""
An undefined name warning is emitted if the name first defined by a
C{with} statement is used before the C{with} statement.
"""
self.flakes('''
from __future__ import with_statement
bar
with open('foo') as bar:
pass
''', m.UndefinedName)
def test_withStatementTupleNamesUndefined(self):
"""
An undefined name warning is emitted if a name first defined by a the
tuple-unpacking form of the C{with} statement is used before the
C{with} statement.
"""
self.flakes('''
from __future__ import with_statement
baz
with open('foo') as (bar, baz):
pass
''', m.UndefinedName)
def test_withStatementSingleNameRedefined(self):
"""
A redefined name warning is emitted if a name bound by an import is
rebound by the name defined by a C{with} statement.
"""
self.flakes('''
from __future__ import with_statement
import bar
with open('foo') as bar:
pass
''', m.RedefinedWhileUnused)
def test_withStatementTupleNamesRedefined(self):
"""
A redefined name warning is emitted if a name bound by an import is
rebound by one of the names defined by the tuple-unpacking form of a
C{with} statement.
"""
self.flakes('''
from __future__ import with_statement
import bar
with open('foo') as (bar, baz):
pass
''', m.RedefinedWhileUnused)
def test_withStatementUndefinedInside(self):
"""
An undefined name warning is emitted if a name is used inside the
body of a C{with} statement without first being bound.
"""
self.flakes('''
from __future__ import with_statement
with open('foo') as bar:
baz
''', m.UndefinedName)
def test_withStatementNameDefinedInBody(self):
"""
A name defined in the body of a C{with} statement can be used after
the body ends without warning.
"""
self.flakes('''
from __future__ import with_statement
with open('foo') as bar:
baz = 10
baz
''')
def test_withStatementUndefinedInExpression(self):
"""
An undefined name warning is emitted if a name in the I{test}
expression of a C{with} statement is undefined.
"""
self.flakes('''
from __future__ import with_statement
with bar as baz:
pass
''', m.UndefinedName)
self.flakes('''
from __future__ import with_statement
with bar as bar:
pass
''', m.UndefinedName)
class Python27Test(harness.Test):
"""
Tests for checking of syntax only available in Python 2.7 and newer.
"""
if version_info < (2, 7):
skip = "Python 2.7 required for dict/set comprehension tests"
def test_dictComprehension(self):
"""
Dict comprehensions are properly handled.
"""
self.flakes('''
a = {1: x for x in range(10)}
''')
def test_setComprehensionAndLiteral(self):
"""
Set comprehensions are properly handled.
"""
self.flakes('''
a = {1, 2, 3}
b = {x for x in range(10)}
''')

View File

@@ -0,0 +1,185 @@
"""
Tests for L{pyflakes.scripts.pyflakes}.
"""
import sys
from StringIO import StringIO
from twisted.python.filepath import FilePath
from twisted.trial.unittest import TestCase
from pyflakes.scripts.pyflakes import checkPath
def withStderrTo(stderr, f):
"""
Call C{f} with C{sys.stderr} redirected to C{stderr}.
"""
(outer, sys.stderr) = (sys.stderr, stderr)
try:
return f()
finally:
sys.stderr = outer
class CheckTests(TestCase):
"""
Tests for L{check} and L{checkPath} which check a file for flakes.
"""
def test_missingTrailingNewline(self):
"""
Source which doesn't end with a newline shouldn't cause any
exception to be raised nor an error indicator to be returned by
L{check}.
"""
fName = self.mktemp()
FilePath(fName).setContent("def foo():\n\tpass\n\t")
self.assertFalse(checkPath(fName))
def test_checkPathNonExisting(self):
"""
L{checkPath} handles non-existing files.
"""
err = StringIO()
count = withStderrTo(err, lambda: checkPath('extremo'))
self.assertEquals(err.getvalue(), 'extremo: No such file or directory\n')
self.assertEquals(count, 1)
def test_multilineSyntaxError(self):
"""
Source which includes a syntax error which results in the raised
L{SyntaxError.text} containing multiple lines of source are reported
with only the last line of that source.
"""
source = """\
def foo():
'''
def bar():
pass
def baz():
'''quux'''
"""
# Sanity check - SyntaxError.text should be multiple lines, if it
# isn't, something this test was unprepared for has happened.
def evaluate(source):
exec source
exc = self.assertRaises(SyntaxError, evaluate, source)
self.assertTrue(exc.text.count('\n') > 1)
sourcePath = FilePath(self.mktemp())
sourcePath.setContent(source)
err = StringIO()
count = withStderrTo(err, lambda: checkPath(sourcePath.path))
self.assertEqual(count, 1)
self.assertEqual(
err.getvalue(),
"""\
%s:8: invalid syntax
'''quux'''
^
""" % (sourcePath.path,))
def test_eofSyntaxError(self):
"""
The error reported for source files which end prematurely causing a
syntax error reflects the cause for the syntax error.
"""
source = "def foo("
sourcePath = FilePath(self.mktemp())
sourcePath.setContent(source)
err = StringIO()
count = withStderrTo(err, lambda: checkPath(sourcePath.path))
self.assertEqual(count, 1)
self.assertEqual(
err.getvalue(),
"""\
%s:1: unexpected EOF while parsing
def foo(
^
""" % (sourcePath.path,))
def test_nonDefaultFollowsDefaultSyntaxError(self):
"""
Source which has a non-default argument following a default argument
should include the line number of the syntax error. However these
exceptions do not include an offset.
"""
source = """\
def foo(bar=baz, bax):
pass
"""
sourcePath = FilePath(self.mktemp())
sourcePath.setContent(source)
err = StringIO()
count = withStderrTo(err, lambda: checkPath(sourcePath.path))
self.assertEqual(count, 1)
self.assertEqual(
err.getvalue(),
"""\
%s:1: non-default argument follows default argument
def foo(bar=baz, bax):
""" % (sourcePath.path,))
def test_nonKeywordAfterKeywordSyntaxError(self):
"""
Source which has a non-keyword argument after a keyword argument should
include the line number of the syntax error. However these exceptions
do not include an offset.
"""
source = """\
foo(bar=baz, bax)
"""
sourcePath = FilePath(self.mktemp())
sourcePath.setContent(source)
err = StringIO()
count = withStderrTo(err, lambda: checkPath(sourcePath.path))
self.assertEqual(count, 1)
self.assertEqual(
err.getvalue(),
"""\
%s:1: non-keyword arg after keyword arg
foo(bar=baz, bax)
""" % (sourcePath.path,))
def test_permissionDenied(self):
"""
If the a source file is not readable, this is reported on standard
error.
"""
sourcePath = FilePath(self.mktemp())
sourcePath.setContent('')
sourcePath.chmod(0)
err = StringIO()
count = withStderrTo(err, lambda: checkPath(sourcePath.path))
self.assertEquals(count, 1)
self.assertEquals(
err.getvalue(), "%s: Permission denied\n" % (sourcePath.path,))
def test_misencodedFile(self):
"""
If a source file contains bytes which cannot be decoded, this is
reported on stderr.
"""
source = u"""\
# coding: ascii
x = "\N{SNOWMAN}"
""".encode('utf-8')
sourcePath = FilePath(self.mktemp())
sourcePath.setContent(source)
err = StringIO()
count = withStderrTo(err, lambda: checkPath(sourcePath.path))
self.assertEquals(count, 1)
self.assertEquals(
err.getvalue(), "%s: problem decoding source\n" % (sourcePath.path,))

View File

@@ -0,0 +1,265 @@
from _ast import PyCF_ONLY_AST
from twisted.trial.unittest import TestCase
from pyflakes import messages as m, checker
from pyflakes.test import harness
class Test(harness.Test):
def test_undefined(self):
self.flakes('bar', m.UndefinedName)
def test_definedInListComp(self):
self.flakes('[a for a in range(10) if a]')
def test_functionsNeedGlobalScope(self):
self.flakes('''
class a:
def b():
fu
fu = 1
''')
def test_builtins(self):
self.flakes('range(10)')
def test_magicGlobalsFile(self):
"""
Use of the C{__file__} magic global should not emit an undefined name
warning.
"""
self.flakes('__file__')
def test_magicGlobalsBuiltins(self):
"""
Use of the C{__builtins__} magic global should not emit an undefined
name warning.
"""
self.flakes('__builtins__')
def test_magicGlobalsName(self):
"""
Use of the C{__name__} magic global should not emit an undefined name
warning.
"""
self.flakes('__name__')
def test_magicGlobalsPath(self):
"""
Use of the C{__path__} magic global should not emit an undefined name
warning, if you refer to it from a file called __init__.py.
"""
self.flakes('__path__', m.UndefinedName)
self.flakes('__path__', filename='package/__init__.py')
def test_globalImportStar(self):
'''Can't find undefined names with import *'''
self.flakes('from fu import *; bar', m.ImportStarUsed)
def test_localImportStar(self):
'''A local import * still allows undefined names to be found in upper scopes'''
self.flakes('''
def a():
from fu import *
bar
''', m.ImportStarUsed, m.UndefinedName)
def test_unpackedParameter(self):
'''Unpacked function parameters create bindings'''
self.flakes('''
def a((bar, baz)):
bar; baz
''')
def test_definedByGlobal(self):
'''"global" can make an otherwise undefined name in another function defined'''
self.flakes('''
def a(): global fu; fu = 1
def b(): fu
''')
test_definedByGlobal.todo = ''
def test_globalInGlobalScope(self):
"""
A global statement in the global scope is ignored.
"""
self.flakes('''
global x
def foo():
print x
''', m.UndefinedName)
def test_del(self):
'''del deletes bindings'''
self.flakes('a = 1; del a; a', m.UndefinedName)
def test_delGlobal(self):
'''del a global binding from a function'''
self.flakes('''
a = 1
def f():
global a
del a
a
''')
def test_delUndefined(self):
'''del an undefined name'''
self.flakes('del a', m.UndefinedName)
def test_globalFromNestedScope(self):
'''global names are available from nested scopes'''
self.flakes('''
a = 1
def b():
def c():
a
''')
def test_laterRedefinedGlobalFromNestedScope(self):
"""
Test that referencing a local name that shadows a global, before it is
defined, generates a warning.
"""
self.flakes('''
a = 1
def fun():
a
a = 2
return a
''', m.UndefinedLocal)
def test_laterRedefinedGlobalFromNestedScope2(self):
"""
Test that referencing a local name in a nested scope that shadows a
global declared in an enclosing scope, before it is defined, generates
a warning.
"""
self.flakes('''
a = 1
def fun():
global a
def fun2():
a
a = 2
return a
''', m.UndefinedLocal)
def test_intermediateClassScopeIgnored(self):
"""
If a name defined in an enclosing scope is shadowed by a local variable
and the name is used locally before it is bound, an unbound local
warning is emitted, even if there is a class scope between the enclosing
scope and the local scope.
"""
self.flakes('''
def f():
x = 1
class g:
def h(self):
a = x
x = None
print x, a
print x
''', m.UndefinedLocal)
def test_doubleNestingReportsClosestName(self):
"""
Test that referencing a local name in a nested scope that shadows a
variable declared in two different outer scopes before it is defined
in the innermost scope generates an UnboundLocal warning which
refers to the nearest shadowed name.
"""
exc = self.flakes('''
def a():
x = 1
def b():
x = 2 # line 5
def c():
x
x = 3
return x
return x
return x
''', m.UndefinedLocal).messages[0]
self.assertEqual(exc.message_args, ('x', 5))
def test_laterRedefinedGlobalFromNestedScope3(self):
"""
Test that referencing a local name in a nested scope that shadows a
global, before it is defined, generates a warning.
"""
self.flakes('''
def fun():
a = 1
def fun2():
a
a = 1
return a
return a
''', m.UndefinedLocal)
def test_nestedClass(self):
'''nested classes can access enclosing scope'''
self.flakes('''
def f(foo):
class C:
bar = foo
def f(self):
return foo
return C()
f(123).f()
''')
def test_badNestedClass(self):
'''free variables in nested classes must bind at class creation'''
self.flakes('''
def f():
class C:
bar = foo
foo = 456
return foo
f()
''', m.UndefinedName)
def test_definedAsStarArgs(self):
'''star and double-star arg names are defined'''
self.flakes('''
def f(a, *b, **c):
print a, b, c
''')
def test_definedInGenExp(self):
"""
Using the loop variable of a generator expression results in no
warnings.
"""
self.flakes('(a for a in xrange(10) if a)')
class NameTests(TestCase):
"""
Tests for some extra cases of name handling.
"""
def test_impossibleContext(self):
"""
A Name node with an unrecognized context results in a RuntimeError being
raised.
"""
tree = compile("x = 10", "<test>", "exec", PyCF_ONLY_AST)
# Make it into something unrecognizable.
tree.body[0].targets[0].ctx = object()
self.assertRaises(RuntimeError, checker.Checker, tree)

View File

@@ -0,0 +1,28 @@
#!/usr/bin/python
# (c) 2005-2009 Divmod, Inc. See LICENSE file for details
from distutils.core import setup
setup(
name="pyflakes",
license="MIT",
version="0.4.0",
description="passive checker of Python programs",
author="Phil Frost",
maintainer="Moe Aboulkheir",
maintainer_email="moe@divmod.com",
url="http://www.divmod.org/trac/wiki/DivmodPyflakes",
packages=["pyflakes", "pyflakes.scripts", "pyflakes.test"],
scripts=["bin/pyflakes"],
long_description="""Pyflakes is program to analyze Python programs and detect various errors. It
works by parsing the source file, not importing it, so it is safe to use on
modules with side effects. It's also much faster.""",
classifiers=[
"Development Status :: 6 - Mature",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Topic :: Software Development",
"Topic :: Utilities",
])

View File

@@ -0,0 +1,58 @@
setlocal cinkeys-=0#
setlocal indentkeys-=0#
setlocal foldlevel=100
setlocal foldmethod=indent
setlocal list
setlocal noautoindent
setlocal smartindent
setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class,with
setlocal smarttab
set wildignore+=*.pyc
inoremap # X<BS>#
"set ofu=syntaxcomplete#Complete
"autocmd FileType python setlocal omnifunc=pysmell#Complete
let python_highlight_all=1
"I don't want to have pyflakes errors in qfix, it interfering with Pep8/Pylint
let g:pyflakes_use_quickfix = 0
"Load views for py files
autocmd BufWinLeave *.py mkview
autocmd BufWinEnter *.py silent loadview
compiler pylint
finish "end here. all below is just for the record.
" Pylint function, which can be optionally mapped to some keys. Currently
" not used.
if !exists('*<SID>runPyLint')
function <SID>runPyLint()
echohl Statement
echo "Running pylint (ctrl-c to cancel) ..."
echohl Normal
:Pylint
endfunction
endif
if !exists('*<SID>PyLintBuf')
function <SID>PyLintBuf()
echohl Statement
echo "Running pylint (ctrl-c to cancel) ..."
echohl Normal
let file = expand('%:p')
let cmd = 'pylint --reports=n --output-format=text "' . file . '"'
if has('win32') || has('win64')
let cmd = 'cmd /c "' . cmd . '"'
endif
exec "bel silent new " . file . ".lint"
exec "silent! read! " . cmd
endfunction
endif

View File

@@ -0,0 +1,135 @@
" File: pep8_fn.vim
" Author: Roman 'gryf' Dobosz (gryf73 at gmail.com)
" Version: 1.0
" Last Modified: 2010-09-12
" Description: {{{
"
" Overview
" --------
" This plugin provides functionality to static checks for python files
" regarding PEP8 guidance[1] as ":Pep8" command.
"
" This function does not use pep8[2] command line utility, but relies on pep8
" module.
"
" This script uses python, therefore VIm should be compiled with python
" support. You can check it by issuing ":version" command, and search for
" "+python" inside features list.
"
" Couple of ideas was taken from pyflakes.vim[3] plugin.
"
" Installation
" ------------
" 1. Copy the pep8_fn.vim file to the $HOME/.vim/ftplugin/python or
" $HOME/vimfiles/ftplugin/python or $VIM/vimfiles/ftplugin/python
" directory. If python directory doesn't exists, it should be created.
" Refer to the following Vim help topics for more information about Vim
" plugins:
" :help add-plugin
" :help add-global-plugin
" :help runtimepath
" 2. It should be possible to import pep8 from python interpreter (it should
" report no error):
" >>> import pep8
" >>>
" If there are errors, install pep8 first. Simplest way to do it, is to
" use easy_install[4] shell command as a root:
" # easy_install pep8
" 3. Restart Vim.
" 4. You can now use the ":Pep8" which will examine current python buffer
" and open quickfix buffer with errors if any.
"
" [1] http://www.python.org/dev/peps/pep-0008/
" [2] http://pypi.python.org/pypi/pep8
" [3] http://www.vim.org/scripts/script.php?script_id=2441
" [4] http://pypi.python.org/pypi/setuptools
"
" }}}
if exists("b:did_pep8_plugin")
finish " only load once
else
let b:did_pep8_plugin = 1
endif
if !exists("g:pep8_exclude")
let g:pep8_exclude = []
endif
if !exists("b:did_pep8_init")
let b:did_pep8_init = 0
if !has('python')
echoerr "pep8_fn.vim plugin requires Vim to be compiled with +python"
finish
endif
python << EOF
import vim
import sys
from StringIO import StringIO
try:
import pep8
except ImportError:
raise AssertionError('Error: pep8_fn.vim requires module pep8')
class VImPep8(object):
def __init__(self):
self.fname = vim.current.buffer.name
self.bufnr = vim.current.buffer.number
self.output = []
self.exclude_list = vim.eval("g:pep8_exclude")
def reporter(self, lnum, col, text, check):
self.output.append([lnum, col, text])
def run(self):
pep8.process_options(['-r', vim.current.buffer.name])
checker = pep8.Checker(vim.current.buffer.name)
checker.report_error = self.reporter
checker.check_all()
self.process_output()
def process_output(self):
vim.command('call setqflist([])')
qf_list = []
qf_dict = {}
for line in self.output:
skip = False
for exclude_pattern in self.exclude_list:
if exclude_pattern in line[2]:
skip = True
break
if skip:
continue
qf_dict['bufnr'] = self.bufnr
qf_dict['lnum'] = line[0]
qf_dict['col'] = line[1]
qf_dict['text'] = line[2]
qf_dict['type'] = line[2][0]
qf_list.append(qf_dict)
qf_dict = {}
self.output = []
vim.command('call setqflist(%s)' % str(qf_list))
if qf_list:
vim.command('copen')
EOF
let b:did_pep8_init = 1
endif
if !exists('*s:Pep8')
function s:Pep8()
python << EOF
VImPep8().run()
EOF
endfunction
endif
if !exists(":Pep8")
command Pep8 call s:Pep8()
endif

View File

@@ -0,0 +1,146 @@
" File: pylint_fn.vim
" Author: Roman 'gryf' Dobosz (gryf73 at gmail.com)
" Version: 1.0
" Last Modified: 2010-09-11
"
" Description: " {{{
"
" Overview
" --------
" This plugin provides ":Pylint" command, which put pylint result into quickfix
" buffer. This function does not uses pylint[1] command line utility, only
" python pylint.lint module is used instead. So it makes the pylint
" egg/package required for running this script.
"
" This script uses python, therefore VIm should be compiled with python
" support. You can check it by issuing ":version" command, and search for
" "+python" inside features list.
"
" Couple of ideas was taken from pyflakes.vim[2] plugin.
"
" Installation
" ------------
" 1. Copy the pylint_fn.vim file to the $HOME/.vim/ftplugin/python or
" $HOME/vimfiles/ftplugin/python or $VIM/vimfiles/ftplugin/python
" directory. If python directory doesn't exists, it should be created.
" Refer to the following Vim help topics for more information about Vim
" plugins:
" :help add-plugin
" :help add-global-plugin
" :help runtimepath
" 2. It should be possible to import pylint from python interpreter (it should
" report no error):
" >>> import pylint
" >>>
" If there are errors, install pylint first. Simplest way to do it, is to
" use easy_install[3] shell command as a root:
" # easy_install pylint
" 3. Restart Vim.
" 4. You can now use the ":Pylint" which will examine current python buffer
" and open quickfix buffer with errors if any.
"
" [1] http://www.logilab.org/project/pylint
" [2] http://www.vim.org/scripts/script.php?script_id=2441
" [3] http://pypi.python.org/pypi/setuptools
" }}}
if exists("b:did_pylint_plugin")
finish " only load once
else
let b:did_pylint_plugin = 1
endif
if !exists("b:did_pylint_init")
let b:did_pylint_init = 0
if !has('python')
echoerr "Error: pylint_fn.vim requires Vim to be compiled with +python"
finish
endif
python << EOF
import vim
import sys
from StringIO import StringIO
try:
from pylint import lint
from pylint.reporters.text import TextReporter
except ImportError:
raise AssertionError('Pylint is required for this plugin')
class VImPylint(object):
sys_stderr = sys.stderr
dummy_stderr = StringIO()
conf_msg = 'No config file found, using default configuration\n'
@classmethod
def run(self):
"""execute pylint and fill the quickfix"""
# clear QF window
vim.command('call setqflist([])')
# args
args = ['-rn', # display only the messages instead of full report
'-iy', # Include message's id in output
vim.current.buffer.name]
buf = StringIO() # file-like buffer, instead of stdout
reporter = TextReporter(buf)
sys.stderr = self.dummy_stderr
lint.Run(args, reporter=reporter, exit=False)
sys.stderr = self.sys_stderr
self.dummy_stderr.seek(0)
error_list = self.dummy_stderr.readlines()
self.dummy_stderr.truncate(0)
if error_list and self.conf_msg in error_list:
error_list.remove(self.conf_msg)
if error_list:
raise Exception(''.join(error_list))
buf.seek(0)
bufnr = vim.current.buffer.number
code_line = {}
error_list = []
carriage_re = re.compile(r'\s*\^+$')
error_re = re.compile(r'^([C,R,W,E,F].+):\s+?([0-9]+):?.*:\s(.*)$')
for line in buf:
line = line.rstrip() # remove trailing newline character
if error_re.match(line):
if code_line:
code_line['bufnr'] = bufnr
error_list.append(code_line)
code_line = {}
code_line['type'], code_line['lnum'], code_line['text'] = \
error_re.match(line).groups()
if carriage_re.match(line) and code_line:
code_line['col'] = carriage_re.match(line).group().find('^') \
+ 1
vim.command('call setqflist(%s)' % str(error_list))
if error_list:
vim.command('copen')
EOF
let b:did_pylint_init = 1
endif
if !exists('*s:Pylint')
function s:Pylint()
python << EOF
VImPylint.run()
EOF
endfunction
endif
if !exists(":Pylint")
command Pylint call s:Pylint()
endif

View File

@@ -0,0 +1,447 @@
" -*- vim -*-
" FILE: python_fn.vim
" LAST MODIFICATION: 2008-08-28 8:19pm
" (C) Copyright 2001-2005 Mikael Berthe <bmikael@lists.lilotux.net>
" Maintained by Jon Franklin <jvfranklin@gmail.com>
" Version: 1.13
" USAGE:
"
" Save this file to $VIMFILES/ftplugin/python.vim. You can have multiple
" python ftplugins by creating $VIMFILES/ftplugin/python and saving your
" ftplugins in that directory. If saving this to the global ftplugin
" directory, this is the recommended method, since vim ships with an
" ftplugin/python.vim file already.
" You can set the global variable "g:py_select_leading_comments" to 0
" if you don't want to select comments preceding a declaration (these
" are usually the description of the function/class).
" You can set the global variable "g:py_select_trailing_comments" to 0
" if you don't want to select comments at the end of a function/class.
" If these variables are not defined, both leading and trailing comments
" are selected.
" Example: (in your .vimrc) "let g:py_select_leading_comments = 0"
" You may want to take a look at the 'shiftwidth' option for the
" shift commands...
"
" REQUIREMENTS:
" vim (>= 7)
"
" Shortcuts:
" ]t -- Jump to beginning of block
" ]e -- Jump to end of block
" ]v -- Select (Visual Line Mode) block
" ]< -- Shift block to left
" ]> -- Shift block to right
" ]# -- Comment selection
" ]u -- Uncomment selection
" ]c -- Select current/previous class
" ]d -- Select current/previous function
" ]<up> -- Jump to previous line with the same/lower indentation
" ]<down> -- Jump to next line with the same/lower indentation
" Only do this when not done yet for this buffer
if exists("b:loaded_py_ftplugin")
finish
endif
let b:loaded_py_ftplugin = 1
map ]t :PBoB<CR>
vmap ]t :<C-U>PBOB<CR>m'gv``
map ]e :PEoB<CR>
vmap ]e :<C-U>PEoB<CR>m'gv``
map ]v ]tV]e
map ]< ]tV]e<
vmap ]< <
map ]> ]tV]e>
vmap ]> >
map ]# :call PythonCommentSelection()<CR>
vmap ]# :call PythonCommentSelection()<CR>
map ]u :call PythonUncommentSelection()<CR>
vmap ]u :call PythonUncommentSelection()<CR>
" gryf: change mapping for class selection
map ]C :call PythonSelectObject("class")<CR>
map ]d :call PythonSelectObject("function")<CR>
map ]<up> :call PythonNextLine(-1)<CR>
map ]<down> :call PythonNextLine(1)<CR>
" You may prefer use <s-up> and <s-down>... :-)
" jump to previous class
map ]J :call PythonDec("class", -1)<CR>
vmap ]J :call PythonDec("class", -1)<CR>
" jump to next class
map ]j :call PythonDec("class", 1)<CR>
vmap ]j :call PythonDec("class", 1)<CR>
" jump to previous function
map ]F :call PythonDec("function", -1)<CR>
vmap ]F :call PythonDec("function", -1)<CR>
" jump to next function
map ]f :call PythonDec("function", 1)<CR>
vmap ]f :call PythonDec("function", 1)<CR>
" Menu entries
nmenu <silent> &Python.Update\ IM-Python\ Menu
\:call UpdateMenu()<CR>
nmenu &Python.-Sep1- :
nmenu <silent> &Python.Beginning\ of\ Block<Tab>[t
\]t
nmenu <silent> &Python.End\ of\ Block<Tab>]e
\]e
nmenu &Python.-Sep2- :
nmenu <silent> &Python.Shift\ Block\ Left<Tab>]<
\]<
vmenu <silent> &Python.Shift\ Block\ Left<Tab>]<
\]<
nmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
\]>
vmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
\]>
nmenu &Python.-Sep3- :
vmenu <silent> &Python.Comment\ Selection<Tab>]#
\]#
nmenu <silent> &Python.Comment\ Selection<Tab>]#
\]#
vmenu <silent> &Python.Uncomment\ Selection<Tab>]u
\]u
nmenu <silent> &Python.Uncomment\ Selection<Tab>]u
\]u
nmenu &Python.-Sep4- :
nmenu <silent> &Python.Previous\ Class<Tab>]J
\]J
nmenu <silent> &Python.Next\ Class<Tab>]j
\]j
nmenu <silent> &Python.Previous\ Function<Tab>]F
\]F
nmenu <silent> &Python.Next\ Function<Tab>]f
\]f
nmenu &Python.-Sep5- :
nmenu <silent> &Python.Select\ Block<Tab>]v
\]v
nmenu <silent> &Python.Select\ Function<Tab>]d
\]d
nmenu <silent> &Python.Select\ Class<Tab>]c
\]c
nmenu &Python.-Sep6- :
nmenu <silent> &Python.Previous\ Line\ wrt\ indent<Tab>]<up>
\]<up>
nmenu <silent> &Python.Next\ Line\ wrt\ indent<Tab>]<down>
\]<down>
:com! PBoB execute "normal ".PythonBoB(line('.'), -1, 1)."G"
:com! PEoB execute "normal ".PythonBoB(line('.'), 1, 1)."G"
:com! UpdateMenu call UpdateMenu()
" Go to a block boundary (-1: previous, 1: next)
" If force_sel_comments is true, 'g:py_select_trailing_comments' is ignored
function! PythonBoB(line, direction, force_sel_comments)
let ln = a:line
let ind = indent(ln)
let mark = ln
let indent_valid = strlen(getline(ln))
let ln = ln + a:direction
if (a:direction == 1) && (!a:force_sel_comments) &&
\ exists("g:py_select_trailing_comments") &&
\ (!g:py_select_trailing_comments)
let sel_comments = 0
else
let sel_comments = 1
endif
while((ln >= 1) && (ln <= line('$')))
if (sel_comments) || (match(getline(ln), "^\\s*#") == -1)
if (!indent_valid)
let indent_valid = strlen(getline(ln))
let ind = indent(ln)
let mark = ln
else
if (strlen(getline(ln)))
if (indent(ln) < ind)
break
endif
let mark = ln
endif
endif
endif
let ln = ln + a:direction
endwhile
return mark
endfunction
" Go to previous (-1) or next (1) class/function definition
function! PythonDec(obj, direction)
if (a:obj == "class")
let objregexp = "^\\s*class\\s\\+[a-zA-Z0-9_]\\+"
\ . "\\s*\\((\\([a-zA-Z0-9_,. \\t\\n]\\)*)\\)\\=\\s*:"
else
let objregexp = "^\\s*def\\s\\+[a-zA-Z0-9_]\\+\\s*(\\_[^:#]*)\\s*:"
endif
let flag = "W"
if (a:direction == -1)
let flag = flag."b"
endif
let res = search(objregexp, flag)
endfunction
" Comment out selected lines
" commentString is inserted in non-empty lines, and should be aligned with
" the block
function! PythonCommentSelection() range
let commentString = "#"
let cl = a:firstline
let ind = 1000 " I hope nobody use so long lines! :)
" Look for smallest indent
while (cl <= a:lastline)
if strlen(getline(cl))
let cind = indent(cl)
let ind = ((ind < cind) ? ind : cind)
endif
let cl = cl + 1
endwhile
if (ind == 1000)
let ind = 1
else
let ind = ind + 1
endif
let cl = a:firstline
execute ":".cl
" Insert commentString in each non-empty line, in column ind
while (cl <= a:lastline)
if strlen(getline(cl))
execute "normal ".ind."|i".commentString
endif
execute "normal \<Down>"
let cl = cl + 1
endwhile
endfunction
" Uncomment selected lines
function! PythonUncommentSelection() range
" commentString could be different than the one from CommentSelection()
" For example, this could be "# \\="
let commentString = "#"
let cl = a:firstline
while (cl <= a:lastline)
let ul = substitute(getline(cl),
\"\\(\\s*\\)".commentString."\\(.*\\)$", "\\1\\2", "")
call setline(cl, ul)
let cl = cl + 1
endwhile
endfunction
" Select an object ("class"/"function")
function! PythonSelectObject(obj)
" Go to the object declaration
normal $
call PythonDec(a:obj, -1)
let beg = line('.')
if !exists("g:py_select_leading_comments") || (g:py_select_leading_comments)
let decind = indent(beg)
let cl = beg
while (cl>1)
let cl = cl - 1
if (indent(cl) == decind) && (getline(cl)[decind] == "#")
let beg = cl
else
break
endif
endwhile
endif
if (a:obj == "class")
let eod = "\\(^\\s*class\\s\\+[a-zA-Z0-9_]\\+\\s*"
\ . "\\((\\([a-zA-Z0-9_,. \\t\\n]\\)*)\\)\\=\\s*\\)\\@<=:"
else
let eod = "\\(^\\s*def\\s\\+[a-zA-Z0-9_]\\+\\s*(\\_[^:#]*)\\s*\\)\\@<=:"
endif
" Look for the end of the declaration (not always the same line!)
call search(eod, "")
" Is it a one-line definition?
if match(getline('.'), "^\\s*\\(#.*\\)\\=$", col('.')) == -1
let cl = line('.')
execute ":".beg
execute "normal V".cl."G"
else
" Select the whole block
execute "normal \<Down>"
let cl = line('.')
execute ":".beg
execute "normal V".PythonBoB(cl, 1, 0)."G"
endif
endfunction
" Jump to the next line with the same (or lower) indentation
" Useful for moving between "if" and "else", for example.
function! PythonNextLine(direction)
let ln = line('.')
let ind = indent(ln)
let indent_valid = strlen(getline(ln))
let ln = ln + a:direction
while((ln >= 1) && (ln <= line('$')))
if (!indent_valid) && strlen(getline(ln))
break
else
if (strlen(getline(ln)))
if (indent(ln) <= ind)
break
endif
endif
endif
let ln = ln + a:direction
endwhile
execute "normal ".ln."G"
endfunction
function! UpdateMenu()
" delete menu if it already exists, then rebuild it.
" this is necessary in case you've got multiple buffers open
" a future enhancement to this would be to make the menu aware of
" all buffers currently open, and group classes and functions by buffer
if exists("g:menuran")
aunmenu IM-Python
endif
let restore_fe = &foldenable
set nofoldenable
" preserve disposition of window and cursor
let cline=line('.')
let ccol=col('.') - 1
norm H
let hline=line('.')
" create the menu
call MenuBuilder()
" restore disposition of window and cursor
exe "norm ".hline."Gzt"
let dnscroll=cline-hline
exe "norm ".dnscroll."j".ccol."l"
let &foldenable = restore_fe
endfunction
function! MenuBuilder()
norm gg0
let currentclass = -1
let classlist = []
let parentclass = ""
while line(".") < line("$")
" search for a class or function
if match ( getline("."), '^\s*class\s\+[_a-zA-Z].*\|^\s*def\s\+[_a-zA-Z].*' ) != -1
norm ^
let linenum = line('.')
let indentcol = col('.')
norm "nye
let classordef=@n
norm w"nywge
let objname=@n
let parentclass = FindParentClass(classlist, indentcol)
if classordef == "class"
call AddClass(objname, linenum, parentclass)
else " this is a function
call AddFunction(objname, linenum, parentclass)
endif
" We actually created a menu, so lets set the global variable
let g:menuran=1
call RebuildClassList(classlist, [objname, indentcol], classordef)
endif " line matched
norm j
endwhile
endfunction
" classlist contains the list of nested classes we are in.
" in most cases it will be empty or contain a single class
" but where a class is nested within another, it will contain 2 or more
" this function adds or removes classes from the list based on indentation
function! RebuildClassList(classlist, newclass, classordef)
let i = len(a:classlist) - 1
while i > -1
if a:newclass[1] <= a:classlist[i][1]
call remove(a:classlist, i)
endif
let i = i - 1
endwhile
if a:classordef == "class"
call add(a:classlist, a:newclass)
endif
endfunction
" we found a class or function, determine its parent class based on
" indentation and what's contained in classlist
function! FindParentClass(classlist, indentcol)
let i = 0
let parentclass = ""
while i < len(a:classlist)
if a:indentcol <= a:classlist[i][1]
break
else
if len(parentclass) == 0
let parentclass = a:classlist[i][0]
else
let parentclass = parentclass.'\.'.a:classlist[i][0]
endif
endif
let i = i + 1
endwhile
return parentclass
endfunction
" add a class to the menu
function! AddClass(classname, lineno, parentclass)
if len(a:parentclass) > 0
let classstring = a:parentclass.'\.'.a:classname
else
let classstring = a:classname
endif
exe 'menu IM-Python.classes.'.classstring.' :call <SID>JumpToAndUnfold('.a:lineno.')<CR>'
endfunction
" add a function to the menu, grouped by member class
function! AddFunction(functionname, lineno, parentclass)
if len(a:parentclass) > 0
let funcstring = a:parentclass.'.'.a:functionname
else
let funcstring = a:functionname
endif
exe 'menu IM-Python.functions.'.funcstring.' :call <SID>JumpToAndUnfold('.a:lineno.')<CR>'
endfunction
function! s:JumpToAndUnfold(line)
" Go to the right line
execute 'normal '.a:line.'gg'
" Check to see if we are in a fold
let lvl = foldlevel(a:line)
if lvl != 0
" and if so, then expand the fold out, other wise, ignore this part.
execute 'normal 15zo'
endif
endfunction
"" This one will work only on vim 6.2 because of the try/catch expressions.
" function! s:JumpToAndUnfoldWithExceptions(line)
" try
" execute 'normal '.a:line.'gg15zo'
" catch /^Vim\((\a\+)\)\=:E490:/
" " Do nothing, just consume the error
" endtry
"endfunction
" vim:set et sts=2 sw=2:

View File

@@ -0,0 +1,763 @@
" File: pythonhelper.vim
" Author: Michal Vitecek <fuf-at-mageo-dot-cz>
" Version: 0.83
" Last Modified: Jan 4, 2010
"
" Overview
" --------
" Vim script to help moving around in larger Python source files. It displays
" current class, method or function the cursor is placed in on the status
" line for every python file. It's more clever than Yegappan Lakshmanan's
" taglist.vim because it takes into account indetation and comments to
" determine what tag the cursor is placed in.
"
" Requirements
" ------------
" This script needs only VIM compiled with Python interpreter. It doesn't rely
" on exuberant ctags utility. You can determine whether your VIM has Python
" support by issuing command :ver and looking for +python in the list of
" features.
"
" Installation
" ------------
" 1. Make sure your Vim has python feature on (+python). If not, you will need
" to recompile it with --with-pythoninterp option to the configure script
" 2. Copy script pythonhelper.vim to the $HOME/.vim/plugin directory
" 3. Run Vim and open any python file.
"
python << EOS
# import of required modules {{{
import re
import sys
import time
import traceback
import vim
# }}}
# global dictionaries of tags and their line numbers, keys are buffer numbers {{{
TAGS = {}
TAGLINENUMBERS = {}
BUFFERTICKS = {}
# }}}
# class PythonTag() {{{
class PythonTag(object):
# DOC {{{
"""A simple storage class representing a python tag.
"""
# }}}
# STATIC VARIABLES {{{
# possible tag types {{{
TT_CLASS = 0
TT_METHOD = 1
TT_FUNCTION = 2
# }}}
# tag type names {{{
TAG_TYPE_NAME = {
TT_CLASS : "class",
TT_METHOD : "method",
TT_FUNCTION : "function",
}
# }}}
# }}}
# METHODS {{{
def __init__(self, type, name, fullName, lineNumber, indentLevel):
# DOC {{{
"""Initializes instances of PythonTag().
Parameters
type -- tag type
name -- short tag name
fullName -- full tag name (in dotted notation)
lineNumber -- line number on which the tag starts
indentLevel -- indentation level of the tag
"""
# }}}
# CODE {{{
# remember the settings {{{
self.type = type
self.name = name
self.fullName = fullName
self.lineNumber = lineNumber
self.indentLevel = indentLevel
# }}}
# }}}
def __str__(self):
# DOC {{{
"""Returns a string representation of the tag.
"""
# }}}
# CODE {{{
return "%s (%s) [%s, %u, %u]" % (self.name, PythonTag.TAG_TYPE_NAME[self.type],
self.fullName, self.lineNumber, self.indentLevel,)
# }}}
__repr__ = __str__
# }}}
# }}}
# class SimplePythonTagsParser() {{{
class SimplePythonTagsParser(object):
# DOC {{{
"""Provides a simple python tag parser.
"""
# }}}
# STATIC VARIABLES {{{
# how many chars a single tab represents (visually)
TABSIZE = 8
# regexp used to extract indentation and strip comments
COMMENTS_INDENT_RE = re.compile('([ \t]*)([^\n#]*).*')
# regexp used to extract a class name
CLASS_RE = re.compile('class[ \t]+([^(:]+).*')
# regexp used to extract a method or function name
METHOD_RE = re.compile('def[ \t]+([^(]+).*')
# }}}
# METHODS {{{
def __init__(self, source):
# DOC {{{
"""Initializes instances of SimplePythonTagsParser().
Parameters
source -- source for which the tags will be generated. It must
provide callable method readline (i.e. as file objects do).
"""
# }}}
# CODE {{{
# make sure source has readline() method {{{
if ((hasattr(source, 'readline') == 0) or
(callable(source.readline) == 0)):
raise AttributeError("Source must have callable readline method.")
# }}}
# remember what the source is
self.source = source
# }}}
def getTags(self):
# DOC {{{
"""Determines all the tags for the buffer. Returns a tuple in format
(tagLineNumbers, tags,).
"""
# }}}
# CODE {{{
# initialize the resulting list of the tag line numbers and the tag information {{{
tagLineNumbers = []
tags = {}
# }}}
# initalize local auxiliary variables {{{
tagsStack = []
lineNumber = 0
# }}}
# go through all the lines in the source and localize all python tags in it {{{
while 1:
# get next line
line = self.source.readline()
# finish if this is the end of the source {{{
if (line == ''):
break
# }}}
# increase the line number
lineNumber += 1
# extract the line indentation characters and its content {{{
lineMatch = self.COMMENTS_INDENT_RE.match(line)
lineContent = lineMatch.group(2)
# }}}
# handle the class tag {{{
# match for the class tag
tagMatch = self.CLASS_RE.match(lineContent)
# if the class tag has been found, store some information on it {{{
if (tagMatch):
currentTag = self.getPythonTag(tagsStack, lineNumber, lineMatch.group(1),
tagMatch.group(1), self.tagClassTypeDecidingMethod)
tagLineNumbers.append(lineNumber)
tags[lineNumber] = currentTag
# }}}
# }}}
# handle the function/method/none tag {{{
else:
# match for the method/function tag
tagMatch = self.METHOD_RE.match(lineContent)
# if the method/function tag has been found, store some information on it {{{
if (tagMatch):
currentTag = self.getPythonTag(tagsStack, lineNumber, lineMatch.group(1),
tagMatch.group(1), self.tagFunctionTypeDecidingMethod)
tagLineNumbers.append(lineNumber)
tags[lineNumber] = currentTag
# }}}
# }}}
# }}}
# return the tags data for the source
return (tagLineNumbers, tags,)
# }}}
def getParentTag(self, tagsStack):
# DOC {{{
"""Returns the parent/enclosing tag (instance of PythonTag()) from the
specified tag list. If no such parent tag exists, returns None.
Parameters
tagsStack -- list (stack) of currently open PythonTag() instances
"""
# }}}
# CODE {{{
# determine the parent tag {{{
if (len(tagsStack)):
parentTag = tagsStack[-1]
else:
parentTag = None
# }}}
# return the tag
return parentTag
# }}}
def computeIndentationLevel(indentChars):
# DOC {{{
"""Computes the indentation level from the specified string.
Parameters
indentChars -- white space before any other character on line
"""
# }}}
# CODE {{{
# initialize the indentation level
indentLevel = 0
# compute the indentation level (expand tabs) {{{
for char in indentChars:
if (char == '\t'):
indentLevel += SimplePythonTagsParser.TABSIZE
else:
indentLevel += 1
# }}}
# return the computed indentation level
return indentLevel
# }}}
computeIndentationLevel = staticmethod(computeIndentationLevel)
def getPythonTag(self, tagsStack, lineNumber, indentChars, tagName, tagTypeDecidingMethod):
# DOC {{{
"""Returns instance of PythonTag() based on the specified data.
Parameters
tagsStack -- list (stack) of tags currently active. Note: Modified
in this method!
lineNumber -- current line number
indentChars -- characters making up the indentation level of the
current tag
tagName -- short name of the current tag
tagTypeDecidingMethod -- reference to method that is called to
determine the type of the current tag
"""
# }}}
# CODE {{{
# compute the indentation level
indentLevel = self.computeIndentationLevel(indentChars)
# get the parent tag
parentTag = self.getParentTag(tagsStack)
# handle an enclosed tag {{{
while (parentTag):
# if the indent level of the parent tag is greater than of the current tag, use parent tag of the parent tag {{{
if (parentTag.indentLevel >= indentLevel):
del tagsStack[-1]
# }}}
# otherwise we have all information on the current tag and can return it {{{
else:
# create the tag
tag = PythonTag(tagTypeDecidingMethod(parentTag.type), tagName, "%s.%s" % (parentTag.fullName, tagName,), lineNumber, indentLevel)
# break the loop
break
# }}}
# use parent tag of the parent tag
parentTag = self.getParentTag(tagsStack)
# }}}
# handle a top-indent level tag {{{
else:
# create the tag
tag = PythonTag(tagTypeDecidingMethod(None), tagName, tagName, lineNumber, indentLevel)
# }}}
# add the tag to the list of tags
tagsStack.append(tag)
# return the tag
return tag
# }}}
def tagClassTypeDecidingMethod(self, parentTagType):
# DOC {{{
"""Returns tag type of the current tag based on its previous tag (super
tag) for classes.
Parameters
parentTagType -- type of the enclosing/parent tag
"""
# }}}
# CODE {{{
# is always class no matter what
return PythonTag.TT_CLASS
# }}}
def tagFunctionTypeDecidingMethod(self, parentTagType):
# DOC {{{
"""Returns tag type of the current tag based on its previous tag (super
tag) for functions/methods.
Parameters
parentTagType -- type of the enclosing/parent tag
"""
# }}}
# CODE {{{
if (parentTagType == PythonTag.TT_CLASS):
return PythonTag.TT_METHOD
else:
return PythonTag.TT_FUNCTION
# }}}
# }}}
# }}}
# class VimReadlineBuffer() {{{
class VimReadlineBuffer(object):
# DOC {{{
"""A simple wrapper class around vim's buffer that provides readline
method.
"""
# }}}
# METHODS {{{
def __init__(self, vimBuffer):
# DOC {{{
"""Initializes instances of VimReadlineBuffer().
Parameters
vimBuffer -- VIM's buffer
"""
# }}}
# CODE {{{
# remember the settings
self.vimBuffer = vimBuffer
# initialize instance attributes {{{
self.currentLine = -1
self.bufferLines = len(vimBuffer)
# }}}
# }}}
def readline(self):
# DOC {{{
"""Returns next line from the buffer. If all the buffer has been read,
returns empty string.
"""
# }}}
# CODE {{{
# increase the current line counter
self.currentLine += 1
# notify end of file if we reached beyond the last line {{{
if (self.currentLine == self.bufferLines):
return ''
# }}}
# return the line with an added newline (vim stores the lines without it)
return "%s\n" % (self.vimBuffer[self.currentLine],)
# }}}
# }}}
# }}}
def getNearestLineIndex(row, tagLineNumbers):
# DOC {{{
"""Returns the index of line in 'tagLineNumbers' list that is nearest to the
specified cursor row.
Parameters
row -- current cursor row
tagLineNumbers -- list of tags' line numbers (ie. their position)
"""
# }}}
# CODE {{{
# initialize local auxiliary variables {{{
nearestLineNumber = -1
nearestLineIndex = -1
# }}}
# go through all tag line numbers and find the one nearest to the specified row {{{
for lineIndex, lineNumber in enumerate(tagLineNumbers):
# if the current line is nearer the current cursor position, take it {{{
if (nearestLineNumber < lineNumber <= row):
nearestLineNumber = lineNumber
nearestLineIndex = lineIndex
# }}}
# if we've got past the current cursor position, let's end the search {{{
if (lineNumber >= row):
break
# }}}
# }}}
# return index of the line with the nearest tag
return nearestLineIndex
# }}}
def getTags(bufferNumber, changedTick):
# DOC {{{
"""Reads the tags for the specified buffer number. Returns a tuple
(taglinenumber[buffer], tags[buffer],).
Parameters
bufferNumber -- number of the current buffer
changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time
"""
# }}}
# CODE {{{
# define global variables
global TAGLINENUMBERS, TAGS, BUFFERTICKS
# return immediately if there's no need to update the tags {{{
if (BUFFERTICKS.get(bufferNumber, None) == changedTick):
return (TAGLINENUMBERS[bufferNumber], TAGS[bufferNumber],)
# }}}
# get the tags {{{
simpleTagsParser = SimplePythonTagsParser(VimReadlineBuffer(vim.current.buffer))
tagLineNumbers, tags = simpleTagsParser.getTags()
# }}}
# update the global variables {{{
TAGS[bufferNumber] = tags
TAGLINENUMBERS[bufferNumber] = tagLineNumbers
BUFFERTICKS[bufferNumber] = changedTick
# }}}
# return the tuple (tagLineNumbers, tags,)
return (tagLineNumbers, tags,)
# }}}
def findTag(bufferNumber, changedTick):
# DOC {{{
"""Tries to find the best tag for the current cursor position.
Parameters
bufferNumber -- number of the current buffer
changedTick -- ever increasing number used to tell if the buffer has
been modified since the last time
"""
# }}}
# CODE {{{
# try to find the best tag {{{
try:
# get the tags data for the current buffer
tagLineNumbers, tags = getTags(bufferNumber, changedTick)
# link to vim's internal data {{{
currentBuffer = vim.current.buffer
currentWindow = vim.current.window
row, col = currentWindow.cursor
# }}}
# get the index of the nearest line
nearestLineIndex = getNearestLineIndex(row, tagLineNumbers)
# if any line was found, try to find if the tag is appropriate {{{
# (ie. the cursor can be below the last tag but on a code that has nothing
# to do with the tag, because it's indented differently, in such case no
# appropriate tag has been found.)
while (nearestLineIndex > -1):
# get the line number of the nearest tag
nearestLineNumber = tagLineNumbers[nearestLineIndex]
# walk through all the lines in range (nearestTagLine, cursorRow) {{{
for lineNumber in xrange(nearestLineNumber + 1, row):
# get the current line
line = currentBuffer[lineNumber]
# count the indentation of the line, if it's lower than the tag's, the tag is invalid {{{
if (len(line)):
# initialize local auxiliary variables {{{
lineStart = 0
i = 0
# }}}
# compute the indentation of the line {{{
while ((i < len(line)) and (line[i].isspace())):
# move the start of the line code {{{
if (line[i] == '\t'):
lineStart += SimplePythonTagsParser.TABSIZE
else:
lineStart += 1
# }}}
# go to the next character on the line
i += 1
# }}}
# if the line contains only spaces, skip it {{{
if (i == len(line)):
continue
# }}}
# if the next character is a '#' (python comment), skip the line {{{
if (line[i] == '#'):
continue
# }}}
# if the line's indentation starts before or at the nearest tag's one, the tag is invalid {{{
if (lineStart <= tags[nearestLineNumber].indentLevel):
nearestLineIndex -= 1
break
# }}}
# }}}
# }}}
# the tag is appropriate, so use it {{{
else:
break
# }}}
# }}}
# no appropriate tag has been found {{{
else:
nearestLineNumber = -1
# }}}
# describe the cursor position (what tag the cursor is on) {{{
# reset the description
tagDescription = ""
# if an appropriate tag has been found, set the description accordingly {{{
if (nearestLineNumber > -1):
tagInfo = tags[nearestLineNumber]
tagDescription = "[in %s (%s)]" % (tagInfo.fullName, PythonTag.TAG_TYPE_NAME[tagInfo.type],)
# }}}
# }}}
# update the variable for the status line so it get updated with the new description
vim.command("let w:PHStatusLine=\"%s\"" % (tagDescription,))
# }}}
# handle possible exceptions {{{
except Exception:
# bury into the traceback {{{
ec, ei, tb = sys.exc_info()
while (tb != None):
if (tb.tb_next == None):
break
tb = tb.tb_next
# }}}
# spit out the error {{{
print "ERROR: %s %s %s:%u" % (ec.__name__, ei, tb.tb_frame.f_code.co_filename, tb.tb_lineno,)
time.sleep(0.5)
# }}}
# }}}
# }}}
def deleteTags(bufferNumber):
# DOC {{{
"""Removes tags data for the specified buffer number.
Parameters
bufferNumber -- number of the buffer
"""
# }}}
# CODE {{{
# define global variables
global TAGS, TAGLINENUMBERS, BUFFERTICKS
# try to delete the tags for the buffer {{{
try:
del TAGS[bufferNumber]
del TAGLINENUMBERS[bufferNumber]
del BUFFERTICKS[bufferNumber]
except:
pass
# }}}
# }}}
EOS
" VIM functions {{{
function! PHCursorHold()
" only python is supported {{{
if (!exists('b:current_syntax') || (b:current_syntax != 'python'))
let w:PHStatusLine = ''
return
endif
" }}}
" call python function findTag() with the current buffer number and changed ticks
execute 'python findTag(' . expand("<abuf>") . ', ' . b:changedtick . ')'
endfunction
function! PHBufferDelete()
" set PHStatusLine for this window to empty string
let w:PHStatusLine = ""
" call python function deleteTags() with the cur
execute 'python deleteTags(' . expand("<abuf>") . ')'
endfunction
function! TagInStatusLine()
" return value of w:PHStatusLine in case it's set
if (exists("w:PHStatusLine"))
return w:PHStatusLine
" otherwise just return empty string
else
return ""
endif
endfunction
function! PHPreviousClassMethod()
call search('^[ \t]*\(class\|def\)\>', 'bw')
endfunction
function! PHNextClassMethod()
call search('^[ \t]*\(class\|def\)\>', 'w')
endfunction
function! PHPreviousClass()
call search('^[ \t]*class\>', 'bw')
endfunction
function! PHNextClass()
call search('^[ \t]*class\>', 'w')
endfunction
function! PHPreviousMethod()
call search('^[ \t]*def\>', 'bw')
endfunction
function! PHNextMethod()
call search('^[ \t]*def\>', 'w')
endfunction
" }}}
" event binding, vim customizing {{{
" autocommands binding
autocmd CursorHold * call PHCursorHold()
autocmd CursorHoldI * call PHCursorHold()
autocmd BufDelete * silent call PHBufferDelete()
" time that determines after how long time of no activity the CursorHold event
" is fired up
set updatetime=1000
" color of the current tag in the status line (bold cyan on black)
" gryf: i don't like coloring apart from current colorscheme. keep it simple.
"highlight User1 gui=bold guifg=cyan guibg=black
" color of the modified flag in the status line (bold black on red)
" gryf: i don't like coloring apart from current colorscheme. keep it simple.
"highlight User2 gui=bold guifg=black guibg=red
" the status line will be displayed for every window
set laststatus=2
" set the status line to display some useful information
"set stl=%-f%r\ %2*%m%*\ \ \ \ %1*%{TagInStatusLine()}%*%=[%l:%c]\ \ \ \ [buf\ %n]
" gryf: I like my status bar. Don't change it. Just add information.
setlocal statusline=%<%F\ \ \ %{TagInStatusLine()}\ %h%m%r%=%(%l,%c%V%)\ %3p%%
" }}}
" vim:foldmethod=marker

View File

@@ -0,0 +1,16 @@
" Some common settings for all reSt files
setlocal textwidth=80
setlocal makeprg=rst2html.py\ \"%\"\ \"%:p:r.html\"
setlocal spell
setlocal smartindent
setlocal autoindent
setlocal formatoptions=tcq "set VIms default
let g:blogger_login="gryf73"
let g:blogger_name="rdobosz"
let g:blogger_browser=1
let g:blogger_stylesheets=["css/widget_css_2_bundle.css", "css/style_custom.css", "css/style_blogger.css", "css/wombat_pygments.css", "css/lucius_pygments.css"]
let g:blogger_pygments_class="wombat"
map <F6> :PreviewBlogArticle<cr>
map <F7> :SendBlogArticle<cr>

View File

@@ -0,0 +1,29 @@
function! WordFrequency() range
let all = split(join(getline(a:firstline, a:lastline)), '\k\+')
let frequencies = {}
for word in all
let frequencies[word] = get(frequencies, word, 0) + 1
endfor
new
setlocal buftype=nofile bufhidden=hide noswapfile tabstop=4
for [key,value] in items(frequencies)
call append('$', value."\t".key)
endfor
sort i
endfunction
command! -range=% WordFrequency <line1>,<line2>call WordFrequency()
function! CreateDict() range
let all = split(join(getline(a:firstline, a:lastline)), '[^A-Za-zęóąśłżźćńĘÓĄŚŁŻŹĆŃ]\+')
let frequencies = {}
for word in all
let frequencies[word] = get(frequencies, word, 0) + 1
endfor
new
setlocal buftype=nofile bufhidden=hide noswapfile
for [key,value] in items(frequencies)
call append('$', key)
endfor
sort i
endfunction
command! -range=% CreateDict <line1>,<line2>call CreateDict()

View File

@@ -0,0 +1,8 @@
set nolist
set tabstop=4
set autoindent
"set foldmethod=manual
set noexpandtab
set shiftwidth=4
set noexpandtab
set list

View File

@@ -0,0 +1,4 @@
set nolist
set nosmartindent
set autoindent
set foldmethod=manual

View File

@@ -0,0 +1,2 @@
compiler rubber
map <F5> :make<cr>

View File

@@ -0,0 +1,4 @@
set nolist
set nosmartindent
set autoindent
set foldmethod=manual

View File

@@ -0,0 +1,220 @@
:Author: Roman Dobosz, gryf73 at gmail com
=============
vimblogger_ft
=============
vimblogger_ft is a simple reStructuredText_ to Blogger interface through VIm_.
As the name suggest it is a filetype plugin, which helps to create blog
articles in rsST format and send them to blog site. It also provides commands
for preview in browser and delete articles.
Requirements
------------
Module for communication was written in Python. So, VIm has to be
compiled with ``+python``.
Other requirements:
- Python (tested with version 2.6, should work also in others)
- gdata_
- docutils_
- Pygments_ (optional)
- Blogger account
Install
-------
Download_, edit the vba with VIm and type::
:so %
Or, clone this repository and put files in your ``~/.vim`` directory.
Usage
-----
This plugin is targeting for people, who has blogger account, want to
use VIm for creating blog articles and don't really likes to manually do
this in html.
Before starting writing a post, at least ``g:blogger_name`` and
``g:blogger_login`` has to be set up in ``.vimrc``. Next, an article has to
be written using standard reST markup, ``:Title:`` added (not required,
but it's nice to have some title for a blog entry). Now,
``:PreviewBlogArticle`` can be used for saving generated HTML page into
the file of the same name as reST file. Please note, that it'll silently
overwrite existing file, because it is treated as a temporary file.
When article is done, ``:SendBlogArticle`` will send it to the server.
Output provided by ``:PreviewBlogArticle`` without any
css stylesheet will look pretty raw, so it is generally good idea to
grab stylesheets from blog itself, and tweak it a little, and add to
list in ``g:blogger_stylesheets``. They will be automatically linked to
generated preview file.
Unfortunately, this script has several limitations, like it is
impossible to use multiple blogs or edit existing articles without reST
source files. It has to be somehow converted to reStructuredText, id of
an article added to ``:Id:`` docinfo item and then updated. Id of an
article is available through blogger account - every action for each
post listed on Posting->Edit Posts has URL with query string item
postID, for example::
http://www.blogger.com/post-edit.g?blogID=9876&postID=12345
See plugin documentation for configuration.
Commands
--------
#. ``:PreviewBlogArticle`` - Generate article in HTML format, save it to the
file with te same name as a reST source with .html extension in the same
directory, and optionally opens it in browser. No connection to the blogger
is performed.
#. ``:SendBlogArticle`` -
Generate partial HTML document, which holds article, from current
reST buffer and send it to the blog.
See reST document structure below for further description.
#. ``:DeleteBlogArticle`` -
Display list of articles, and lets user choose one (or none) of them
to perform deletions.
reST document structure
-----------------------
It is assumed, that following template will be used::
:Id:
:Title: Title for the blog article
:Date:
:Modified:
:Tags: some, tags
Penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla
facilisis massa ut massa. Sed nisi purus, malesuada eu, porta vulputate,
suscipit auctor, nunc. Vestibulum convallis, augue eu luctus malesuada,
mi ante mattis odio, ac venenatis neque sem vitae nisi.
.. more
heading
-------
**Congue** mi, quis posuere augue nulla a augue. Pellentesque sed est.
Mauris cursus urna id lectus. Integer dignissim feugiat eros. Sed tempor
volutpat dolor. Vestibulum vel lectus nec mauris semper adipiscing.
Aliquam tincidunt enim sit amet tellus. Sed mauris nulla, semper
tincidunt, luctus a, sodales eget, leo. Sed ligula augue, cursus et.
reST document (optionally) starts with *docinfo* section (first several
lines, that are starting from ":" character) separaded from other
content with one empty line.
Docinfo items holds article attributes, and are updated automatically
every each of upload to blogger, which is triggered by
":SendBlogArticle" command.
- **:Id:** - Holds article id on blogger side. If not defined, new article
will be created (even if there is already existing one with the very same
content). If wrong Id is entered (or an Id of deleted article),
exception will be raised, and no action on blogger side will be
performed.
- **:Title:** - Holds article title. Can be changed when ``:Id:`` is obtained.
- **:Date:** - This is published date in RFC 3339
http://www.ietf.org/rfc/rfc3339.txt format. If empty on first
upload, it will be set to current date. Can be set/changed to
desired date.
- **:Modified:** - This is read-only item, which store modification date
which happens on blogger side.
- **:Tags:** - Comma separated list of tags (Labels). Can be empty.
All other items are ignored.
After docinfo block, article body should be placed using markup for
reStructuredText.
Note, that ``.. more`` will became HTML comment ``<!-- more -->`` which will
prevent from displaying entire post on the bloggers front page, but will
not have any visible effect during preview in browser.
Pygments code highlighting
--------------------------
Additionally, if Pygments is installed, there is ``sourcecode`` directive,
simple syntax highlighter using Pygments module. Very simple usage for Python
code could be as follows::
.. sourcecode:: python
import vim
print vim.current.buffer.name
Note, that ``sourcecode`` directive requires argument with the name of the
lexer to use. If wrong/non existent lexer is provided, it will fall back to
*text* lexer. For more information about available lexers, please refer to
Pygments documentation.
Directive ``sourcecode`` supports two options: ``:linenos:`` and
``:cssclass:``.
``:linenos:`` takes zero or one argument - if no arguments is provided, line
numbers will be visible starting form 1. Provided integer will be the number
of the first line.
``:cssclass:`` can be use for changing default class name for block of code.
Default class can be changed by appropriate option for plugin (see
documentation), and defaults to "highlight".
It is possible to use VIm colorschemes like desert (which is distributed with
VIm), Zenburn_, Lucius_, Wombat_, inkpot_ or any other with Pygments.
Assuming, that colorscheme *desert* should be used, there are two steps to
achive it.
First, python module containing Pygments *Style* class has to be generated.
There is apropriate convertion tool in Pygments distribution -
``scripts/vim2pygments.py``. Uage is simple as::
python Pygments/scripts/vim2pygments.py [path/to/vim/colors]/desert.vim > desert.py
Which will create new python module ``desert.py`` containing class
``DessertStyle``.
To generate CSS stylesheet, it's enough to::
python rst2blogger/scripts/style2css.py desert.py -c VimDesert > desert.css
VimDesert is the name of the class, which passed as an argument to
``:cssclass:`` option of directive ``sourceocode``. It will be used as a main
CSS class for code top ``<div>`` element. So, above example will looks like
this::
.. sourcecode:: python
:cssclass: VimDesert
import vim
print vim.current.buffer.name
Note: All headings for generated HTML by ``:SendBlogArticle`` will be
shifted by 3, so the first heading will become <h3>, second <h4> and so
on, to fit into blogger template (well, most of them). Remember, that
HTML allow up to 6 level of headings, while reST doesn't have this
limitation.
.. _VIm: http://www.vim.org
.. _gdata: http://code.google.com/p/gdata-python-client
.. _docutils: http://docutils.sourceforge.net
.. _Pygments: http://pygments.org
.. _reStructuredText: http://docutils.sourceforge.net/rst.html
.. _Download: http://www.vim.org/scripts/script.php?script_id=3367
.. _Zenburn: http://www.vim.org/scripts/script.php?script_id=415
.. _inkpot: http://www.vim.org/scripts/script.php?script_id=1143
.. _Lucius: http://www.vim.org/scripts/script.php?script_id=2536
.. _Wombat: http://www.vim.org/scripts/script.php?script_id=1778

View File

@@ -0,0 +1,282 @@
*vimblogger_ft.txt* reStructuredText to Blogger interface
Author: Roman Dobosz, gryf73 at gmail com
Simple interface to create blog articles in rsST format. It provides
commands for preview in browser, post and delete articles.
-----------------------------------------------------------------------
Requirements~
Module for communication was written in Python. So, VIm has to be
compiled with +python.
Other requirements:
- Python (tested with version 2.6, should work also in others)
- gdata http://code.google.com/p/gdata-python-client
- docutils http://docutils.sourceforge.net
- Pygments http://pygments.org (optional)
- Blogger account
-----------------------------------------------------------------------
Install~
Edit the vba file and type: >
:so %
========================================================================
Usage~
This plugin is targeting for people, who has blogger account, want to
use VIm for creating blog articles and don't really likes to manually do
this in html.
Before starting writing a post, at least |g:blogger_name| and
|g:blogger_login| has to be set up in |.vimrc|. Next, an article has to
be written using standard reST markup, |:Title:| added (not required,
but it's nice to have some title for a blog entry). Now,
|:PreviewBlogArticle| can be used for saving generated HTML page into
the file of the same name as reST file. Please note, that it'll silently
overwrite existing file, because it is treated as a temporary file.
When article is done, |:SendBlogArticle| will send it to the server.
Output provided by |:PreviewBlogArticle| without any
css stylesheet will look pretty raw, so it is generally good idea to
grab stylesheets from blog itself, tweak it a little, and add to list
in |g:blogger_stylesheets|. They will be automatically linked to
generated preview file.
Unfortunately, this script has several limitations, like it is
impossible to use multiple blogs or edit existing articles without reST
source files. It has to be somehow converted to reStructuredText, id of
an article added to |:Id:| docinfo item and then updated. Id of an
article is available through blogger account - every action for each
post listed on Posting->Edit Posts has URL with query string item
postID, for example:
>
http://www.blogger.com/post-edit.g?blogID=9876&postID=12345
<
-----------------------------------------------------------------------
Options~
*g:blogger_browser*
g:blogger_browser (default: 0)
If set to 1 output file from :PreviewBlogArticle will be opened in
browser (used webbrowser Python module)
*g:blogger_name*
g:blogger_name (default: "")
This is blog name, which is part of the URL, and user was obligated
to enter it during blog creation. If in doubt, check first part od
the URL of the blog, just after 'http://'. Note, that blog name may
differ from the blog title, but also could be the same.
*g:blogger_login*
g:blogger_login (default: "")
Google login name, usually gmail address.
*g:blogger_pass*
g:blogger_pass (default: "")
Password. If set to empty string, user will be asked for it every
time if any blogger connectivity is performed.
*g:blogger_draft*
g:blogger_draft (default: 1)
By default, don't publish articles immediately, just save it on the
service. If set to 0, article will be published.
*g:blogger_maxarticles*
g:blogger_maxarticles (default: 0)
Number of displayed articles during deletion. 0 means all. Any
positive number will display only that numbers of articles on list.
*g:blogger_confirm_del*
g:blogger_confirm_del (default: 1)
Confirm every deletion. If set to 0, suppress the confirmation.
*g:blogger_stylesheets*
g:blogger_stylesheets (default: [])
List of relative paths (relative to generated HTML document) of CSS
stylesheets, used only for article preview in HTML document. Usually
one wanted to save stylesheets from his own blog, so that article
can be displayed almost in the same way as in blog.
*g:blogger_pygments_class*
g:blogger_pygments_class (default: "")
Name of default CSS class for usage with Pygments. When not
provided or empty, it'll use defaults from Pygments: "highlight".
========================================================================
Commands~
*:PreviewBlogArticle*
Generate article in HTML format, save it to the file with te same
name as a reST source with .html extension in the same directory,
and optionally opens it in browser. No connection to the blogger is
performed.
*:SendBlogArticle*
Generate partial HTML document, which holds article, from current
reST buffer and send it to the blog.
See reST document structure below for further description.
*:DeleteBlogArticle*
Display list of articles, and lets user choose one (or none) of them
to perform deletions.
========================================================================
reST document structure~
It is assumed, that following template will be used:
>
:Id:
:Title: Title for the blog article
:Date:
:Modified:
:Tags: some, tags
Penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Nulla facilisis massa ut massa. Sed nisi purus, malesuada eu, porta
vulputate, suscipit auctor, nunc. Vestibulum convallis, augue eu luctus
malesuada, mi ante mattis odio, ac venenatis neque sem vitae nisi.
.. more
heading
-------
**Congue** mi, quis posuere augue nulla a augue. Pellentesque sed est.
Mauris cursus urna id lectus. Integer dignissim feugiat eros. Sed
tempor volutpat dolor. Vestibulum vel lectus nec mauris semper
adipiscing.
Aliquam tincidunt enim sit amet tellus. Sed mauris nulla, semper
tincidunt, luctus a, sodales eget, leo. Sed ligula augue, cursus et.
<
reST document (optionally) starts with *docinfo* section (first several
lines, that are starting from ":" character) separaded from other
content with one empty line.
Docinfo items holds article attributes, and are updated automatically
every each of upload to blogger, which is triggered by
":SendBlogArticle" command.
*:Id:*
Holds article id on blogger side. If not defined, new article will
be created (even if there is already existing one with the very same
content). If wrong Id is entered (or an Id of deleted article),
exception will be raised, and no action on blogger side will be
performed.
*:Title:*
Holds article title. Can be changed when |:Id:| is obtained.
*:Date:*
This is published date in RFC 3339
http://www.ietf.org/rfc/rfc3339.txt format. If empty on first
upload, it will be set to current date. Can be set/changed to
desired date.
*:Modified:*
This is read-only item, which store modification date which happens
on blogger side.
*:Tags:*
Comma separated list of tags (Labels). Can be empty.
All other items are ignored.
After docinfo block, article body should be placed using markup for
reStructuredText.
Note, that `.. more' will became HTML comment `<!-- more -->' which will
prevent from displaying entire post on the bloggers front page, but will
not have any visible effect during preview in browser.
========================================================================
Pygments code highlighting~
Additionally, if Pygments is installed, there is ``sourcecode``
directive, simple syntax highlighter using Pygments module. Very simple
usage for Python code could be as follows:
>
.. sourcecode:: python
import vim
print vim.current.buffer.name
<
Note, that `sourcecode' directive requires argument with the name of the
lexer to use. If wrong/non existent lexer is provided, it will fall back
to `text' lexer. For more information about available lexers, please
refer to Pygments documentation.
Directive `sourcecode' supports two options: `:linenos:' and
`:cssclass:'.
`:linenos:' takes zero or one argument - if no arguments is provided,
line numbers will be visible starting form 1. Provided integer will be
the number of the first line.
`:cssclass:' can be use for changing default class name for block of
code. Default class can be changed by appropriate option for plugin
(see documentation), and defaults to "highlight".
It is possible to use VIm colorschemes like desert (which is distributed
with VIm), Zenburn, Lucius, Wombat, inkpot or any other with Pygments.
Assuming, that colorscheme `desert' should be used, there are two steps
to achive it.
First, python module containing Pygments `Style' class has to be
generated. There is appropriate conversion tool in Pygments
distribution - `scripts/vim2pygments.py'. Uage is simple as:
>
python Pygments/scripts/vim2pygments.py \
path/to/vim/colors/desert.vim > desert.py
<
Which will create new python module ``desert.py`` containing class
`DessertStyle`'.
To generate CSS stylesheet, it's enough to:
>
python rst2blogger/scripts/style2css.py desert.py \
-c VimDesert > desert.css
<
VimDesert is the name of the class, which passed as an argument to
`:cssclass:' option of directive `sourceocode'. It will be used as a
main CSS class for code top `<div>' element. So, above example will
looks like this:
>
.. sourcecode:: python
:cssclass: VimDesert
import vim
print vim.current.buffer.name
<
Note: All headings for generated HTML by |:SendBlogArticle| will be
shifted by 3, so the first heading will become <h3>, second <h4> and so
on, to fit into blogger template (well, most of them). Remember, that
HTML allow up to 6 level of headings, while reST doesn't have this
limitation.
========================================================================
Changelog~
0.2 Pygments sourcecode directive improvements
0.1 First release
vim:tw=72:fo=tcq2:isk=!-~,^*,^|,^":ts=8:ft=help:norl:

View File

@@ -0,0 +1 @@
# module rst2blogger

View File

@@ -0,0 +1,214 @@
"""
File: blogger.py
Author: Roman 'gryf' Dobosz
Description: This is blogger activity connected module. It is using gdata[1]
blogger module to provide add/modify/delete articles interface.
[1] http://code.google.com/p/gdata-python-client
"""
import datetime
import re
import atom
from gdata.blogger.client import BloggerClient, BLOG_POST_URL
from gdata.blogger.data import BlogPost
class VimBlogger(object):
"""
Communicate with blogger through gdata.blogger modules
"""
DATE_PATTERN = re.compile(r"^(\d{4}-\d{2}-\d{2})"
"T(\d{2}:\d{2}:\d{2})(\.\d{3})?[+-]"
"(\d{2}:\d{2})$")
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
TZ_FORMAT = "%H:%M"
def __init__(self, blogname, login, password):
"""
Initialization.
"""
self.draft = True
self.blog_id = None
self.blog = None
self.client = BloggerClient()
self._authorize(login, password)
self.feed = self.client.get_blogs()
self._set_blog(blogname)
def get_articles(self, maxarticles=0):
"""
Return list of articles
"""
feed = self.client.get_posts(self.blog_id)
posts = []
for index, entry in enumerate(feed.entry):
if maxarticles and index >= maxarticles:
break
posts.append((entry.get_post_id(),
entry.title.text,
self._extract_date(entry.published.text)))
return posts
def create_article(self, html_doc, attrs=None):
"""
Create new article
html_doc is content of the article in HTML format, without headers,
preamble, doctype and body tags.
attrs is a dictionary that should hold title, date and tags.
return BlogPost object
"""
if not attrs:
attrs = {}
title = 'title' in attrs and attrs['title'] or ""
title = atom.data.Title(text=title, type="text")
html_doc = atom.data.Content(text=html_doc, type="html")
new_post = BlogPost(title=title, content=html_doc)
if 'tags' in attrs and attrs['tags']:
for tag in attrs['tags'].split(','):
new_post.add_label(tag.strip())
if 'date' in attrs and attrs['date'] and \
self._check_date(attrs['date']):
new_post.published = atom.data.Published(text=attrs['date'])
if self.draft:
new_post.control = atom.data.Control(\
draft=atom.data.Draft(text='yes'))
return self.client.post(new_post, BLOG_POST_URL % self.blog_id)
def update_article(self, html_doc, attrs):
"""
Update article.
html_doc is content of the article in HTML format, without headers,
preamble, doctype and body tags.
attrs is a dictionary that should hold title, date and tags.
return BlogPost object
"""
if "id" not in attrs:
raise Exception("Post Id not found in attributes!")
post = self._get_post(attrs['id'])
post.content = atom.data.Content(text=html_doc, type="html")
# update published date
if 'date' in attrs and attrs['date'] and \
self._check_date(attrs['date']):
post.published = atom.data.Published(text=attrs['date'])
if 'title' in attrs and attrs['title']:
post.title = atom.data.Title(text=attrs['title'], type="text")
#
# update tag list
if 'tags' in attrs:
tags = [tag.strip() for tag in attrs['tags'].split(',')]
for index, label in enumerate(post.category):
if label.term not in tags:
del(post.category[index])
for tag in tags:
self._add_tag(post, tag.strip())
return self.client.update(post)
def delete_article(self, post_id):
"""
Delete selected article
"""
if not post_id:
return "No article id provided"
post = self._get_post(post_id)
self.client.delete(post)
return None
def _get_post(self, post_id):
"""
Return post with specified ID
"""
post_href = self.blog.get_post_link().href
return self.client.get_feed(post_href + "/%s" % post_id,
desired_class=BlogPost)
def _add_tag(self, post, tag):
"""
post - BlogPost object
tag - string with tag/label to add
"""
for label in post.category:
if label.term == tag:
return
post.add_label(tag)
def _extract_date(self, date_string, time=False):
"""
Extract date from the string and optionally time
"""
if not self.DATE_PATTERN.match(date_string):
return False
if not time:
return self.DATE_PATTERN.match(date_string).groups()[0]
groups = self.DATE_PATTERN.match(date_string).groups()
return groups[0] + " " + groups[1]
def _check_date(self, date):
"""
Parse date as RFC 3339 format, for example:
2010-11-30T21:06:48.678+01:00
or
2010-11-30T21:06:48+01:00
Returns true, if date is acceptable, false otherwise
"""
if not self.DATE_PATTERN.match(date):
return False
groups = self.DATE_PATTERN.match(date).groups()
_date = groups[0]
_time = groups[1]
_tz = len(groups) == 3 and groups[2] or groups[3]
try:
datetime.datetime.strptime(_date, self.DATE_FORMAT)
datetime.datetime.strptime(_time, self.TIME_FORMAT)
datetime.datetime.strptime(_tz, self.TZ_FORMAT)
except ValueError:
return False
return True
def _authorize(self, login, password):
"""
Try to authorize in Google service.
Authorization is kept in client object. In case of wrong credentials,
exception is thrown.
"""
source = 'Vim rst2blogger interface'
service = 'blogger'
self.client.client_login(login,
password,
source=source,
service=service)
def _set_blog(self, blogname):
"""
Set correct blog, as defined in blogname
"""
for blog in self.feed.entry:
if blog.get_blog_name() == blogname:
self.blog_id = blog.get_blog_id()
self.blog = blog
break

View File

@@ -0,0 +1,214 @@
# vim: fileencoding=utf8
"""
File: main.py
Author: Roman 'gryf' Dobosz
Description: main file to provide fuctionality between vim and moudles rest
and blogger
"""
import webbrowser
from xml.dom import minidom
from xml.parsers.expat import ExpatError
import vim
from rst2blogger.rest import blogPreview, blogArticleString
try:
from rst2blogger.rest import register
except ImportError:
pass
from rst2blogger.blogger import VimBlogger
class Rst2Blogger(object):
"""
Provide convenient way to communicate between vim and blogger through reST
"""
def __init__(self):
vim.command('call setqflist([])')
self.buff = vim.current.buffer
self.docinfo_len = 0
self._set_docinfo_len()
self.login = vim.eval("g:blogger_login")
self.password = vim.eval("g:blogger_pass")
self.blogname = vim.eval("g:blogger_name")
self.buffer_encoding = vim.eval("&fileencoding")
self.vim_encoding = vim.eval("&encoding")
self.draft = int(vim.eval("g:blogger_draft"))
self.maxarticles = int(vim.eval("g:blogger_maxarticles"))
self.confirm_del = int(vim.eval("g:blogger_confirm_del"))
self.stylesheets = vim.eval("g:blogger_stylesheets")
self.pygments_class = vim.eval("g:blogger_pygments_class")
try:
register(self.pygments_class)
except NameError:
pass
def preview(self):
"""
Generate HTML Blogger article preview and (optionally) display it in
systems' web browser
"""
bufcontent = "\n".join(self.buff)
name = self.buff.name
name = name[:-4] + ".html"
html = blogPreview(bufcontent, self.stylesheets)
self._open_qf(self._check_html(html))
output_file = open(name, "w")
output_file.write(html)
output_file.close()
if vim.eval("g:blogger_browser"):
webbrowser.open(name)
return "Generated HTML has been opened in browser"
else:
return "Generated HTML has been written to %s" % name
def post(self):
"""
Do post article
"""
bufcontent = "\n".join(self.buff)
html, attrs = blogArticleString(bufcontent)
parse_msg = self._check_html(html, True)
if parse_msg:
self._open_qf(parse_msg)
return "There are errors in generated document"
if not self.password:
self.password = \
vim.eval('inputsecret("Enter your gmail password: ")')
blog = VimBlogger(self.blogname, self.login, self.password)
blog.draft = self.draft > 0
if 'id' in attrs and attrs['id']:
post = blog.update_article(html, attrs=attrs)
msg = unicode("Article '%s' has been updated" % post.title.text)
msg = msg.encode(self.vim_encoding)
else:
post = blog.create_article(html, attrs=attrs)
msg = "New article with id %s has been created" % \
post.get_post_id()
for item, value in (('id', post.get_post_id()),
('date', post.published.text),
('title', post.title.text),
('modified', post.updated.text),
('tags',
", ".join([cat.term for cat in post.category]))):
self._update_docinfo(item, value)
return msg
def delete(self):
"""
Get list of articles, display it to the user, make him choose one and
delete
"""
if not self.password:
self.password = \
vim.eval('inputsecret("Enter your gmail password: ")')
blog = VimBlogger(self.blogname, self.login, self.password)
posts = blog.get_articles(self.maxarticles)
msg = u"inputlist(["
for index, entries in enumerate(posts):
line = "%2d %s %s" % (index + 1,
entries[1],
entries[2])
msg += u'"' + line.replace('"', '\\"') + u'",'
msg = msg[:-1]
msg += u"])"
msg = unicode(msg).encode(self.vim_encoding)
choice = int(vim.eval(msg))
if choice:
art = posts[choice - 1]
msg = 'confirm("You are about to delete article \'%s\'. '
msg += 'Are you sure?"'
msg = unicode(msg % art[1]).encode(self.vim_encoding)
msg += ', "&No\n&Yes")'
if self.confirm_del:
choice = int(vim.eval(msg))
else:
choice = 2
if choice == 2:
blog.delete_article(art[0])
return "Article deleted"
return "No articles deleted"
def _update_docinfo(self, attr, val):
"""
Update current buffer with attributes value
"""
val = unicode(":%s: %s" % (attr.capitalize(), val))
val = val.encode(self.buffer_encoding)
if not self.docinfo_len:
self.buff.append(val, 0)
return
for num, line in enumerate(self.buff[:self.docinfo_len]):
if ':%s:' % attr in line.lower() and line.startswith(":"):
self.buff[num] = val
return
self.buff.append(val, 0)
self.docinfo_len += 1
def _set_docinfo_len(self):
"""
Set docinfo_len, which means number of lines from the beginning of the
buffer to the first empty line.
"""
for num, line in enumerate(self.buff):
if line and line.startswith(':'):
continue
elif not line:
self.docinfo_len = num
break
else:
self.docinfo_len = 0
break
def _open_qf(self, msg):
"""
Open VIm QuickFix window with message, if argument msg is non empty
string.
"""
if msg:
msg1 = "There are problems reported by XML parser:"
msg2 = "Check generated html for errors."
vim.command('call setqflist([{"text": "%s"}, {"text": "%s"}, '
'{"text": "%s"}])' % (msg1, msg, msg2))
vim.command('copen')
def _check_html(self, html, add_container=False):
"""
Check HTML generated document, by simply use minidom parser
If add_container is set to True, entire document is wrapped inside
additional div
returns empty string if parses succeed, else exception message.
"""
# minidom doesn't understand html entities like '&nbsp;' For checking
# purpose it is perfectly ok, to switch them with '&amp;'
html = html.replace("&nbsp;", "&amp;")
if add_container:
html = "<div>" + html + "</div>"
message = ""
try:
minidom.parseString(html)
except ExpatError as ex:
message = str(ex)
return message

View File

@@ -0,0 +1,330 @@
"""
File: rest.py
Author: Roman 'gryf' Dobosz
Description: This module is responsible for conversion between reST and HTML
with some goods added.
"""
import re
from docutils import core
from docutils import nodes
from docutils.parsers.rst import directives, Directive
from docutils.writers.html4css1 import Writer, HTMLTranslator
try:
from pygments import highlight
from pygments.lexers import get_lexer_by_name, TextLexer
from pygments.formatters import HtmlFormatter
def register(cssclass=None):
if cssclass:
Pygments.cssclass = cssclass
directives.register_directive('sourcecode', Pygments)
def _positive_int_or_1(argument):
"""
Converts the argument into an integer. Returns positive integer. In
case of integers smaller than 1, returns 1. In case of None, returns
1.
"""
if argument is None:
return 1
retval = 1
try:
retval = int(argument)
except ValueError:
pass
if retval < 1:
return 1
return retval
class Pygments(Directive):
"""
Source code syntax highlighting.
"""
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec = {'linenos': _positive_int_or_1,
'cssclass': directives.unchanged_required}
has_content = True
cssclass = None
def run(self):
self.assert_has_content()
try:
lexer = get_lexer_by_name(self.arguments[0])
except ValueError:
# no lexer found - use the text one instead of an exception
lexer = TextLexer()
# take an arbitrary option if more than one is given
kwargs = {'full': False,
'noclasses': False}
if self.options and 'linenos' in self.options:
kwargs['linenos'] = 'inline'
kwargs['linenostart'] = self.options['linenos']
if Pygments.cssclass:
kwargs['cssclass'] = Pygments.cssclass
if self.options and 'cssclass' in self.options:
kwargs['cssclass'] = self.options['cssclass']
formatter = HtmlFormatter(**kwargs)
parsed = highlight(u'\n'.join(self.content), lexer, formatter)
return [nodes.raw('', parsed, format='html')]
register()
except ImportError:
pass
class Attrs(object):
ATTRS = {}
class CustomHTMLTranslator(HTMLTranslator):
"""
Base class for reST files translations.
There are couple of customizations for docinfo fields behaviour and
abbreviations and acronyms.
"""
def __init__(self, document):
"""
Set some nice defaults for articles translations
"""
HTMLTranslator.__init__(self, document)
self.initial_header_level = 4
def visit_section(self, node):
"""
Don't affect document, just keep track of the section levels
"""
self.section_level += 1
def depart_section(self, node):
self.section_level -= 1
def visit_meta(self, node):
pass
def depart_meta(self, node):
pass
def visit_document(self, node):
pass
def depart_document(self, node):
pass
def depart_docinfo(self, node):
"""
Reset body, remove unnecessary content.
"""
self.body = []
def visit_date(self, node):
pass
def depart_date(self, node):
pass
def visit_literal(self, node):
"""
This is almos the same as the original one from HTMLTranslator class.
The only difference is in used HTML tag: it uses 'code' instead of
'tt'
"""
self.body.append(self.starttag(node, 'code', ''))
text = node.astext()
for token in self.words_and_spaces.findall(text):
if token.strip():
# Protect text like "--an-option" and the regular expression
# ``[+]?(\d+(\.\d*)?|\.\d+)`` from bad line wrapping
if self.sollbruchstelle.search(token):
self.body.append('<span class="pre">%s</span>'
% self.encode(token))
else:
self.body.append(self.encode(token))
elif token in ('\n', ' '):
# Allow breaks at whitespace:
self.body.append(token)
else:
# Protect runs of multiple spaces; the last space can wrap:
self.body.append('&nbsp;' * (len(token) - 1) + ' ')
self.body.append('</code>')
# Content already processed:
raise nodes.SkipNode
def visit_acronym(self, node):
"""
Define missing acronym HTML tag
"""
node_text = node.children[0].astext()
node_text = node_text.replace('\n', ' ')
patt = re.compile(r'^(.+)\s<(.+)>')
if patt.match(node_text):
node.children[0] = nodes.Text(patt.match(node_text).groups()[0])
self.body.append(\
self.starttag(node, 'acronym',
'', title=patt.match(node_text).groups()[1]))
else:
self.body.append(self.starttag(node, 'acronym', ''))
def visit_abbreviation(self, node):
"""
Define missing abbr HTML tag
"""
node_text = node.children[0].astext()
node_text = node_text.replace('\n', ' ')
patt = re.compile(r'^(.+)\s<(.+)>')
if patt.match(node_text):
node.children[0] = nodes.Text(patt.match(node_text).groups()[0])
self.body.append(\
self.starttag(node, 'abbr',
'', title=patt.match(node_text).groups()[1]))
else:
self.body.append(self.starttag(node, 'abbr', ''))
class NoHeaderHTMLTranslator(CustomHTMLTranslator):
"""
Special subclass for generating only body of an article
"""
def __init__(self, document):
"""
Remove all needless parts of HTML document.
"""
CustomHTMLTranslator.__init__(self, document)
self.head = []
self.meta = []
self.head_prefix = ['', '', '', '', '']
self.body_prefix = []
self.body_suffix = []
self.stylesheet = []
self.generator = ('')
def visit_field(self, node):
"""
Harvest docinfo fields and store it in global dictionary.
"""
key, val = [n.astext() for n in node]
Attrs.ATTRS[key.lower()] = val.strip()
def visit_date(self, node):
"""
Store published date in global dictionary.
"""
Attrs.ATTRS['date'] = node.astext()
class PreviewHTMLTranslator(CustomHTMLTranslator):
"""
Class for display article in the browser as a preview.
"""
CSS = []
def __init__(self, document):
"""
Alter levels for the heading tags, define custom, blog specific
stylesheets. Note, that style_custom is present only locally to adjust
way of display the page
"""
CustomHTMLTranslator.__init__(self, document)
self.initial_header_level = 1
self.section_level = 1
# order of css files is important
self.default_stylesheets = PreviewHTMLTranslator.CSS
self.stylesheet = [self.stylesheet_link % self.encode(css) \
for css in self.default_stylesheets]
self.body_ = []
def depart_docinfo(self, node):
"""
Overwrite body with some custom one. body_ will hold the first heading
with title of the document.
"""
self.body = self.body_
def visit_field(self, node):
"""
Make title visible as a heading
"""
key, node_ = [n.astext() for n in node]
key = key.lower()
if key == 'title':
self.head.append('<title>%s</title>\n' % self.encode(node_))
self.body_.append('<h1 class="post-title entry-title">'
'<a href="#">%s</a></h1>\n' % self.encode(node_))
class BlogBodyWriter(Writer):
"""
Custom Writer class for generating HTML partial with the article
"""
def __init__(self):
Writer.__init__(self)
self.translator_class = NoHeaderHTMLTranslator
def translate(self):
self.document.settings.output_encoding = "utf-8"
Writer.translate(self)
class BlogPreviewWriter(Writer):
"""
Custom Writer class for generating full HTML of the article
"""
def __init__(self, stylesheets=None):
Writer.__init__(self)
if not stylesheets:
stylesheets = []
self.translator_class = PreviewHTMLTranslator
self.translator_class.CSS = stylesheets
def translate(self):
self.document.settings.output_encoding = "utf-8"
Writer.translate(self)
def blogPreview(string, stylesheets=None):
"""
Returns full HTML of the article.
string argument is an article in reST
"""
if not stylesheets:
stylesheets = []
html_output = core.publish_string(string,
writer=BlogPreviewWriter(stylesheets))
html_output = html_output.strip()
html_output = html_output.replace("<!-- more -->", "\n<!-- more -->\n")
return html_output
def blogArticleString(string):
"""
Returns partial HTML of the article, and attribute dictionary
string argument is an article in reST
"""
# reset ATTRS
Attrs.ATTRS = {}
html_output = core.publish_string(string, writer=BlogBodyWriter())
html_output = html_output.strip()
html_output = html_output.replace("<!-- more -->", "\n<!-- more -->\n")
attrs = {}
for key in Attrs.ATTRS:
if Attrs.ATTRS[key]:
attrs[key] = Attrs.ATTRS[key]
return html_output, attrs

View File

@@ -0,0 +1,73 @@
#!/usr/bin/env python
"""
Generate CSS stylesheet out of provided Style class module, which is an output
from the vim2pygments.py[1] script.
That stylesheet (with any necessary, additional modifications) can be used
with vimblogger_ft[2] VIm plugin, but also for general pygments usage.
Usage:
style2css <module>
[1] vim2pygments is part of the Pygments module, and can be found in scripts
directory of the Pygments <http://pygments.org> distribution.
[2] <http://www.vim.org/scripts/script.php?script_id=3367>
"""
import optparse
import os
from pygments.formatters import HtmlFormatter
class Pygments2CSS(object):
def __init__(self, modulefn, cssclass):
self.style_class = None
self.cssclass = cssclass
if not self.cssclass.startswith("."):
self.cssclass = "." + self.cssclass
mod = os.path.splitext(os.path.basename(modulefn))[0]
try:
module = __import__("%s" % mod)
except ImportError:
print('Error: %s should be in PYTHONPATH or current'
' directory, and should contain valid Style derived'
' class' % modulefn)
raise
for item in dir(module):
if item != 'Style' and item.endswith('Style'):
self.style_class = getattr(module, item)
break
else:
raise ValueError("Error: Wrong module?")
def out(self):
formatter = HtmlFormatter(style=self.style_class)
print "%s { background-color: %s }" % \
(self.cssclass, self.style_class.background_color)
for line in formatter.get_style_defs().split("\n"):
print "%s" % self.cssclass, line
if __name__ == "__main__":
parser = optparse.OptionParser("usage: %prog [options] stylefile.py\n"
"Where stylefile.py is a product of the"
" vim2pygments.py script Pygments "
"distribution.")
parser.add_option("-c", "--class",
dest="cssclass",
type="str",
help="Main CSS class name. Defaults to 'syntax'",
default="syntax")
(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("stylefile.py is required")
if not (os.path.exists(args[0]) and os.path.isfile(args[0])):
parser.error("%s not found" % args[0])
p2css = Pygments2CSS(args[0], options.cssclass)
p2css.out()

View File

@@ -0,0 +1 @@
# module rst2blogger.tests

View File

@@ -0,0 +1,267 @@
# vim: set fileencoding=utf-8
import sys
import os
from datetime import datetime
from tempfile import mkstemp
LOGIN = "John"
PASS = "secret"
REST_ARTICLE = u""":Title: Title — This is a test
:Date: 2010-12-12T12:36:36+01:00
:Tags: this is a test, Blogger, rest
.. meta::
:description: meta are completely ignored in blogger parsers
`Amet`, convallis sollicitudin, commodo a, purus. Nulla vitae eros a diam
blandit **mollis**. Proin luctus ``ls --color ~/`` feugiat eros.
.. more
Pellentesque habitant morbi tristique senectus et *netus* et malesuada fames
ac turpis egestas. Duis ultricies urna: ``easy_install pygments``. Etiam enim
urna, pharetra suscipit, varius et, congue quis, odio. Donec `NES <Nintendo
Entertainment System>`:acronym: lobortis, elit bibendum euismod faucibus,
velit nibh egestas libero, vitae pellentesque elit augue ut massa.
test empty `acronym`:acronym: and `abbrev`:abbreviation:
Section 1
---------
Nulla consequat erat at massa. Vivamus id mi. Morbi purus enim, dapibus a,
facilisis non, tincidunt at, enim. Vestibulum ante ipsum primis in faucibus
orci luctus et ultrices posuere cubilia Curae; `WTF? <What the
fcuk?>`:abbreviation: Duis imperdiet eleifend arcu. Cras magna ligula,
consequat at, tempor non, posuere.
Subsection 1.1
..............
.. sourcecode:: python
import vim
print vim.current.buffer.name
.. sourcecode:: unknown_lexer
Cras dignissim vulputate metus.
Phasellus eu quam. Quisque interdum cursus purus. In.
End.
"""
class Eval(object):
"""
Communication class
"""
value = ""
blog = None
gdata_delete = 0
class Dummy(sys.__class__):
"""
Dummy class, for faking modules and other objects, not directly needed
"""
def __getattr__(self, attrname):
""" The dummy class should have no attribute """
if attrname == 'util':
return Dummy("util")
return None
# fake vim module.
sys.modules["vim"] = Dummy("vim")
class MockBuffer(list):
"""
Vim buffer-like class
"""
def append(self, val, line=None):
"""
Override append method to mimic vim.buffer append behaviour
"""
if line is None:
super(MockBuffer, self).append(val)
else:
super(MockBuffer, self).insert(line, val)
class Mock(object):
"""
Generic all-purpose mock class
"""
pass
import vim
vim.command = lambda x: None
vim.current = Mock()
vim.current.buffer = MockBuffer(REST_ARTICLE.split("\n"))
fdesc, vim.current.buffer.name = mkstemp()
vim.current.buffer.name += ".rst"
os.close(fdesc) # close descriptor, only filename is needed
def mock_vim_eval(string):
ints = ("g:blogger_draft", "g:blogger_maxarticles",
"g:blogger_confirm_del")
if string in ints:
return "0"
elif string == "g:blogger_stylesheets":
return []
else:
return Eval.value
vim.eval = mock_vim_eval
class MockBlog(object):
"""
Mock blog class
"""
def __init__(self, name, id):
self.name = name
self.id = id
def get_blog_name(self):
return self.name
def get_blog_id(self):
return self.id
def get_post_link(self):
link = Mock()
link.href = "http://www.mock.org"
return link
def get_post_id(self):
return self.id
class MockPost(object):
"""
Mock class imitating posts
"""
def __init__(self):
self.category = Mock()
self.category = []
self.id = None
self.title = Mock()
self.title.text = ""
self.published = Mock()
self.published.text = ""
def add_label(self, label):
item = Mock()
item.term = label
self.category.append(item)
def get_post_id(self):
return self.id
class MockBlogFeed(object):
"""
Mock class for feed objects
"""
def __init__(self, *args, **kwargs):
self.entry = []
if Eval.blog:
for bid, bname in {1: 'one', 3: 'test', 7: 'blog_name'}.items():
blog = MockBlog(bname, bid)
self.entry.append(blog)
class MockPostFeed(object):
"""
Mock class for feed objects
"""
def __init__(self, *args, **kwargs):
self.entry = []
from atom.data import Id, Updated
from gdata.blogger.client import BloggerClient
BloggerClient.get_blogs = lambda x: MockBlogFeed()
from gdata.client import BadAuthentication
def mock_client_login(self, login, password, source=None, service=None):
"""
Mock method for client login.
"""
if login != LOGIN or password != PASS:
raise BadAuthentication("Incorrect username or password")
BloggerClient.client_login = mock_client_login
def mock_client_post(self, post, url=None):
"""
Mimic post method
"""
if Eval.value == 10:
return None
new_id = Id(text='1234567890')
post.id = new_id
date = datetime.utcnow()
milli = str(date.microsecond)[:3]
date = date.strftime("%Y-%m-%dT%H:%M:%S")
date = date + ".%s+00:00" % milli
post.updated = Updated(text=date)
return post
BloggerClient.post = mock_client_post
BloggerClient.update = mock_client_post
def mock_client_delete(self, post):
"""
Mock delete method
"""
if not post:
raise AttributeError("%s object has no attribute 'etag'" % type(post))
if Eval.gdata_delete:
return "404 Mock"
return None
BloggerClient.delete = mock_client_delete
def mock_client_get_posts(self, blog_id):
"""
Mock get_posts method
"""
posts = (('title1', 1, "2000-01-01T00:04:00.001+01:00"),
('title2', 2, "2001-01-01T00:02:19.001+01:00"),
('title3', 3, "2002-01-01T00:01:00.001+01:00"),
('title4', 4, "2006-01-01T00:02:00.001+02:00"))
feed = MockPostFeed()
for p in posts:
a = MockPost()
a.id = p[1]
a.title.text = p[0]
a.published.text = p[2]
feed.entry.append(a)
return feed
BloggerClient.get_posts = mock_client_get_posts
def mock_client_get_feed(self, uri, desired_class=None):
"""
Mock get_feed method
"""
post = MockPost()
post.add_label('test1')
return post
BloggerClient.get_feed = mock_client_get_feed
from gdata.blogger.data import BlogPost
def mock_get_post_id(self):
return self.id.text
BlogPost.get_post_id = mock_get_post_id

View File

@@ -0,0 +1,514 @@
import os
import sys
import unittest
this_dir = os.path.dirname(os.path.abspath(__file__))
this_dir = os.path.abspath(os.path.join(this_dir, "../.."))
sys.path.insert(0, this_dir)
from rst2blogger.tests import shared
from rst2blogger.blogger import VimBlogger
class TestCheckDates(unittest.TestCase):
"""
Tests for method VimBlogger._check_date
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimb = VimBlogger(None, shared.LOGIN, shared.PASS)
def test_happy_case_CET(self):
"""
Test on good date string on Central and East Europe
"""
date = "2000-01-01T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
def test_happy_case_HST(self):
"""
Test on good date string on Hawaii Time Zone
"""
date = "2000-01-01T00:00:00.001-10:00"
self.assertTrue(self.vimb._check_date(date))
def test_happy_case_GMT(self):
"""
Test UTC date string
"""
date = "2000-01-01T00:00:00.001-00:00"
self.assertTrue(self.vimb._check_date(date))
def test_without_milliseconds(self):
"""
Test on date string without milliseconds
"""
date = "2000-01-01T00:00:00+01:00"
self.assertTrue(self.vimb._check_date(date))
def test_wrong_tz_format(self):
"""
Test date with wrong timezone format (hour have no leading 0)
"""
date = "2000-01-01T00:00:00.001+1:00"
self.assertFalse(self.vimb._check_date(date))
# Test date with wrong timezone format (minute have only one digit)
date = "2000-01-01T00:00:00.001+01:0"
self.assertFalse(self.vimb._check_date(date))
# Test date with wrong timezone format (hours and minutes hasn't been
# separated by colon)
date = "2000-01-01T00:00:00.001+0100"
self.assertFalse(self.vimb._check_date(date))
def test_wrong_milliseconds(self):
"""
Test date with wrong format of milliseconds (.01 instead of .010)
"""
date = "2000-01-01T00:00:00.01+01:00"
self.assertFalse(self.vimb._check_date(date))
# Test date with wrong format of milliseconds (.1 instead of .100)
date = "2000-01-01T00:00:00.1+01:00"
self.assertFalse(self.vimb._check_date(date))
# Test date with spolied format (dot for milliseconds, but no digits)
date = "2000-01-01T00:00:00.+01:00"
self.assertFalse(self.vimb._check_date(date))
def test_good_milliseconds(self):
"""
Test date with correct format of milliseconds
"""
date = "2000-01-01T00:00:00.000+01:00"
self.assertTrue(self.vimb._check_date(date), date + " is incorrect")
date = "2000-01-01T00:00:00.999+01:00"
self.assertTrue(self.vimb._check_date(date), date + " is incorrect")
def test_wrong_hours(self):
"""
Test date with wrong hours value
"""
date = "2000-01-01T24:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
def test_good_hours(self):
"""
Test date with correct hours values
"""
date = "2000-01-01T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date), date + " is incorrect")
date = "2000-01-01T23:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date), date + " is incorrect")
def test_wrong_minutes(self):
"""
Test date with wrong minutes value
"""
date = "2000-01-01T00:60:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "2000-01-01T00:000:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "2000-01-01T00:1:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
def test_good_minutes(self):
"""
Test date with correct minutes values
"""
date = "2000-01-01T00:01:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
date = "2000-01-01T00:59:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
def test_wrong_seconds(self):
"""
Test date with wrong seconds value
"""
date = "2000-01-01T00:00:60.001+01:00"
self.assertFalse(self.vimb._check_date(date))
def test_good_seconds(self):
"""
Test date with good seconds values
"""
for second in range(60):
date = "2000-01-01T00:00:%0.2d.001+01:00" % second
self.assertTrue(self.vimb._check_date(date))
def test_wrong_days(self):
"""
Test date with incorrect days (january has always 31 days, no month
has lower number than 1)
"""
date = "2000-01-32T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "2000-01-00T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
def test_good_days(self):
"""
Test date with correct days (january has always 31 days)
"""
date = "2000-01-01T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
date = "2000-01-31T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
def test_wrong_month(self):
"""
Test date with wrong month
"""
date = "2000-00-01T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "2000-13-01T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "2000-1-01T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "2000-001-01T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
def test_good_month(self):
"""
Test date with correct months
"""
date = "2000-01-01T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
date = "2000-12-01T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
def test_wrong_year(self):
"""
Test date with wrong year
"""
date = "0000-01-01T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "10000-01-01T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
date = "900-01-01T00:00:00.001+01:00"
self.assertFalse(self.vimb._check_date(date))
def test_good_year(self):
"""
Test date with correct years
"""
date = "0001-01-01T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
date = "9999-01-01T00:00:00.001+01:00"
self.assertTrue(self.vimb._check_date(date))
class TestAuthorize(unittest.TestCase):
"""
Test method VimBlogger._authorize
"""
def setUp(self):
"""
Create VimBlogger object (with good credentials, yes :>)
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
def test_happy_case(self):
"""
Try to login with good credentials
"""
self.assertTrue(self.vimob._authorize(shared.LOGIN,
shared.PASS) is None)
def test_wrong_login(self):
"""
Try to login with wrong login
"""
self.assertRaises(shared.BadAuthentication, self.vimob._authorize,
'joe', shared.PASS)
def test_wrong_pass(self):
"""
Try to login with wrong password
"""
self.assertRaises(shared.BadAuthentication, self.vimob._authorize,
'joe', shared.PASS)
class TestAddTag(unittest.TestCase):
"""
Test method VimBlogger._add_tag
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
self.post = shared.MockPost()
def test_add_tag(self):
"""
Add items to existing categories. List should be uniq.
"""
self.vimob._add_tag(self.post, 'item')
self.assertTrue(len(self.post.category) == 1)
# Item number should not change on the same label
self.vimob._add_tag(self.post, 'item')
self.assertTrue(len(self.post.category) == 1)
self.vimob._add_tag(self.post, 'item2')
self.assertTrue(len(self.post.category) == 2)
class TestExtractDate(unittest.TestCase):
"""
Test method VimBlogger._extract_date
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
def test_extract_date(self):
"""
Date should be already verified by _check_date method, so only
extraction is tested
"""
date = "2000-01-01T00:00:00.001-10:00"
# wrong scenario
self.assertFalse(self.vimob._extract_date('wrong_date_string'))
# only date should be returned
self.assertEqual(self.vimob._extract_date(date), "2000-01-01")
# date and time should be returned
self.assertEqual(self.vimob._extract_date(date, True),
"2000-01-01 00:00:00")
class TestGetPost(unittest.TestCase):
"""
Test method VimBlogger._get_post
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
self.vimob.blog = shared.Mock()
link = shared.Mock()
link.href = "mock.com"
link.feed = shared.Mock()
self.vimob.blog.get_post_link = lambda: link
def test_get_post(self):
"""
Nothing really to test here. Maybe in the future :)
"""
result = self.vimob._get_post('1234')
self.assertEqual(type(result), shared.MockPost)
class TestSetBlog(unittest.TestCase):
"""
Test method VimBlogger._set_blog
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
for bid, bname in {1: 'one', 3: 'test', 7: 'blog_name'}.items():
blog = shared.MockBlog(bname, bid)
self.vimob.feed.entry.append(blog)
def test_set_blog(self):
"""
Test setting a blog
"""
self.vimob._set_blog("no_valid_blog_name")
self.assertEqual(self.vimob.blog_id, None)
self.assertEqual(self.vimob.blog, None)
self.vimob._set_blog("blog_name")
self.assertEqual(self.vimob.blog_id, 7)
self.assertEqual(self.vimob.blog.get_blog_name(), 'blog_name')
self.vimob._set_blog("test")
self.assertEqual(self.vimob.blog_id, 3)
self.assertEqual(self.vimob.blog.get_blog_name(), 'test')
self.vimob._set_blog("one")
self.assertEqual(self.vimob.blog_id, 1)
self.assertEqual(self.vimob.blog.get_blog_name(), 'one')
class TestCreateArticle(unittest.TestCase):
"""
Test method VimBlogger.create_article
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
def test_create_simple_article(self):
"""
Test creation of article with minimum requirements
"""
html = "<p>article</p>"
post = self.vimob.create_article(html)
self.vimob.draft = True
self.assertEqual(post.id.text, '1234567890')
self.assertEqual(post.content.text, html)
self.assertEqual(post.published, None)
self.assertTrue(post.updated is not None)
self.assertEqual(post.title.text, "")
self.assertEqual(post.category, [])
self.assertEqual(post.control.draft.text, "yes")
def test_create_article(self):
"""
Test creation of article with full attrs
"""
html = u"<p>article \xe2\x80\x94 article</p>"
labels = "tag with spaces|vim|python|blogger".split("|")
attrs = {"title": u'Title \xe2\x80\x94 title',
"tags": ", ".join(labels),
"date": "2010-12-10T14:18:32+00:00"}
self.vimob.draft = False
post = self.vimob.create_article(html, attrs)
self.assertEqual(post.id.text, '1234567890')
self.assertEqual(post.content.text, html)
self.assertEqual(post.published.text, attrs['date'])
self.assertTrue(post.updated is not None)
self.assertEqual(post.title.text, attrs['title'])
self.assertEqual(len(post.category), 4)
for label in post.category:
self.assertTrue(label.term in labels)
del(labels[labels.index(label.term)])
self.assertEqual(post.control, None)
class TestDeleteArticle(unittest.TestCase):
"""
Test method VimBlogger.create_article
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
for bid, bname in {1: 'one', 3: 'test', 7: 'blog_name'}.items():
blog = shared.MockBlog(bname, bid)
self.vimob.feed.entry.append(blog)
self.vimob._set_blog('test')
def test_delete_non_existing_article(self):
"""
Test removing article without id
"""
self.assertEqual(self.vimob.delete_article(None),
"No article id provided")
def test_delete_article(self):
"""
Test removing article
"""
html = u"<p>article \xe2\x80\x94 article</p>"
labels = "tag with spaces|vim|python|blogger".split("|")
attrs = {"title": u'Title \xe2\x80\x94 title',
"tags": ", ".join(labels),
"date": "2010-12-10T14:18:32+00:00"}
self.vimob.draft = False
post = self.vimob.create_article(html, attrs)
self.assertEqual(self.vimob.delete_article(post.id.text), None)
class TestGetArticles(unittest.TestCase):
"""
Test method VimBlogger.get_articles
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
def test_get_articles(self):
"""
Test removing article without id
"""
articles = self.vimob.get_articles()
self.assertEqual(len(articles), 4)
articles = self.vimob.get_articles(maxarticles=2)
self.assertEqual(len(articles), 2)
class TestUpdateArticle(unittest.TestCase):
"""
Test method VimBlogger.update_article
"""
def setUp(self):
"""
Create VimBlogger object
"""
self.vimob = VimBlogger(None, shared.LOGIN, shared.PASS)
for bid, bname in {1: 'one', 3: 'test', 7: 'blog_name'}.items():
blog = shared.MockBlog(bname, bid)
self.vimob.feed.entry.append(blog)
self.vimob._set_blog('test')
def test_wrong_argument_types(self):
"""
Test update_article method with wrong argument types
"""
self.assertRaises(TypeError, self.vimob.update_article, None, None)
def test_no_id_in_attrs(self):
"""
Test update_article method with no id in attrs
"""
self.assertRaises(Exception, self.vimob.update_article,
'<p>update</p>', [])
def test_update(self):
"""
Test update_article method with no id in attrs
"""
attrs = {'id': 1234567890, 'title': 'update',
'date': '2001-01-01T00:02:19.001+01:00',
'tags': "tag1, tag2, tag3"}
post = self.vimob.update_article('<p>update</p>', attrs)
self.assertEqual(post.title.text, 'update')
self.assertEqual(post.id.text, '1234567890')
self.assertEqual(post.content.text, '<p>update</p>')
self.assertTrue(post.updated.text is not None)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,295 @@
# vim: set fileencoding=utf-8
import os
import sys
import unittest
import webbrowser
webbrowser.open = lambda x: None
this_dir = os.path.dirname(os.path.abspath(__file__))
this_dir = os.path.abspath(os.path.join(this_dir, "../.."))
sys.path.insert(0, this_dir)
from rst2blogger.tests.shared import LOGIN, PASS, Eval, MockBuffer
from rst2blogger.main import Rst2Blogger
from gdata.client import BadAuthentication
class TestRst2Blogger(unittest.TestCase):
"""
Tests for vim - rest - blogger interface
"""
def setUp(self):
"""
Create Rst2Blogger object
"""
self.obj = Rst2Blogger()
def test_object_creation(self):
"""
Create Rst2Blogger object and test it.
"""
self.assertTrue(self.obj is not None)
self.assertEqual(self.obj.docinfo_len, 3)
self.assertEqual(self.obj.login, "")
self.assertEqual(self.obj.password, "")
self.assertEqual(self.obj.blogname, "")
self.assertEqual(self.obj.buffer_encoding, "")
self.assertEqual(self.obj.vim_encoding, "")
self.assertEqual(self.obj.maxarticles, 0)
self.assertEqual(self.obj.draft, 0)
self.assertEqual(self.obj.confirm_del, 0)
self.assertEqual(self.obj.stylesheets, [])
class TestRst2BloggerSetDocinfoLen(unittest.TestCase):
"""
Test _set_docinfo_len method on different docinfo configurations
"""
def setUp(self):
"""
Create Rst2Blogger object
"""
self.obj = Rst2Blogger()
def test_set_docinfo_len(self):
"""
Test with no defined docinfo
"""
self.obj.buff = self.obj.buff[4:]
self.obj._set_docinfo_len()
self.assertEqual(self.obj.docinfo_len, 0)
def test_set_docinfo_len2(self):
"""
Test with one docinfo entry
"""
self.obj.buff = self.obj.buff[:1] + [''] + self.obj.buff[4:]
self.obj._set_docinfo_len()
self.assertEqual(self.obj.docinfo_len, 1)
def test_set_docinfo_len3(self):
"""
Test with wrong docinfo definition
"""
self.obj.buff = self.obj.buff[:1] + self.obj.buff[4:]
self.obj._set_docinfo_len()
self.assertEqual(self.obj.docinfo_len, 0)
class TestCheckHtml(unittest.TestCase):
"""
Check HTML parser
"""
def setUp(self):
"""
Create Rst2Blogger object
"""
self.obj = Rst2Blogger()
def test_check_html1(self):
"""
Parse (generated) html string, should return empty string
"""
html = "<html><head><title>test</title></head><body></body></html>"
self.assertEqual(self.obj._check_html(html), "")
self.assertEqual(self.obj._check_html(html, True), "")
def test_check_html2(self):
"""
Parse html fragment string
"""
html = "<p>first paragraph</p><p>another paragraph</p>"
self.assertEqual(self.obj._check_html(html),
"junk after document element: line 1, column 22")
self.assertEqual(self.obj._check_html(html, True), "")
def test_check_html3(self):
"""
Parse wrong html string (crossed tags)
"""
html = "<p>first paragraph<b></p>another paragraph</b>"
self.assertEqual(self.obj._check_html(html),
"mismatched tag: line 1, column 23")
self.assertEqual(self.obj._check_html(html, True),
"mismatched tag: line 1, column 28")
class TestRst2BloggerDelete(unittest.TestCase):
"""
Test delete method
"""
def setUp(self):
"""
Create Rst2Blogger object
"""
self.obj = Rst2Blogger()
self.obj.login = LOGIN
self.obj.password = PASS
self.obj.blogname = "test"
self.obj.vim_encoding = "utf-8"
def test_delete_without_password(self):
"""
Delete article, while password is incorrect/nonexistend
"""
self.obj.password = ""
self.assertRaises(BadAuthentication, self.obj.delete)
def test_delete(self):
"""
Delete article. Set confirmation attribute.
"""
self.obj.confirm_del = 1
Eval.value = 2 # set choice to answer "Y" for confirmation
Eval.blog = "test"
self.assertEqual(self.obj.delete(), "Article deleted")
def test_delete2(self):
"""
Delete article. Set confirmation attribute. Refuse to delete.
"""
self.obj.confirm_del = 1
Eval.value = 1 # set choice to answer "N" for confirmation
Eval.blog = "test"
self.assertEqual(self.obj.delete(), "No articles deleted")
def test_delete3(self):
"""
Delete article. Unset confirmation attribute. Delete returns something
else then None.
"""
Eval.value = 2
Eval.blog = "test"
Eval.gdata_delete = 1
self.assertEqual(self.obj.delete(), "Article deleted")
class TestRst2BloggerPost(unittest.TestCase):
"""
Test post method
"""
def setUp(self):
"""
Create Rst2Blogger object
"""
self.obj = Rst2Blogger()
self.obj.login = LOGIN
self.obj.password = PASS
self.obj.blogname = "test"
self.obj.vim_encoding = "utf-8"
self.obj.buffer_encoding = "utf-8"
# create copy of the buffer list and assign copy to the buff attribute
self._rest = MockBuffer(self.obj.buff[:])
self.obj.buff = self._rest
def test_without_password(self):
"""
Post article, while password is incorrect/nonexistend
"""
self.obj.password = ""
self.assertRaises(BadAuthentication, self.obj.post)
def test_with_wrong_data(self):
"""
Try to post not well formed html
"""
self.obj.buff.append('')
self.obj.buff.append('.. raw:: html')
self.obj.buff.append('')
self.obj.buff.append(' <p>foo<b>bar</p>baz</b>')
self.obj.buff.append('')
self.obj.post()
self.assertEqual(self.obj.post(),
'There are errors in generated document')
def test_post_create(self):
"""
Try to post well formed html, as a new article
"""
self.assertEqual(self.obj.post(),
'New article with id 1234567890 has been created')
def test_post_update(self):
"""
Try to post well formed html, as a new article
"""
self.obj.buff.append(':Id: 1234567890', 0)
self.assertEqual(self.obj.post(),
"Article 'Title \xe2\x80\x94 This is a test' "
"has been updated")
class TestRst2BloggerUpdateDocinfo(unittest.TestCase):
"""
Test _update_docinfo
"""
def setUp(self):
"""
Create Rst2Blogger object
"""
self.obj = Rst2Blogger()
self.obj.login = LOGIN
self.obj.password = PASS
self.obj.blogname = "test"
self.obj.vim_encoding = "utf-8"
self.obj.buffer_encoding = "utf-8"
# create copy of the buffer list and assign copy to the buff attribute
self._rest = MockBuffer(self.obj.buff[:])
self.obj.buff = self._rest
def test_with_empty_docinfo(self):
"""
Try to post not well formed html
"""
self.obj.buff = MockBuffer(self.obj.buff[4:])
self.obj.docinfo_len = 0
self.obj._update_docinfo('title', 'title2')
class TestRst2BloggerPreview(unittest.TestCase):
"""
Test preview
"""
def setUp(self):
"""
Create Rst2Blogger object
"""
self.obj = Rst2Blogger()
self.obj.login = LOGIN
self.obj.password = PASS
self.obj.blogname = "test"
def tearDown(self):
"""
Remove leftovers in fs
"""
try:
os.unlink(self.obj.buff.name[:-4])
except OSError:
pass
try:
os.unlink(self.obj.buff.name[:-4] + ".html")
except OSError:
pass
def test_preview_open_in_browser(self):
"""
Try to post not well formed html
"""
Eval.value = 1
self.assertEqual(self.obj.preview(),
'Generated HTML has been opened in browser')
def test_preview_save_to_file(self):
"""
Try to post not well formed html
"""
Eval.value = 0
name = self.obj.buff.name[:-4] + ".html"
self.assertEqual(self.obj.preview(),
"Generated HTML has been written to %s" % name)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,201 @@
# vim: set fileencoding=utf-8
import os
import sys
import unittest
import re
this_dir = os.path.dirname(os.path.abspath(__file__))
this_dir = os.path.abspath(os.path.join(this_dir, "../.."))
sys.path.insert(0, this_dir)
from rst2blogger.rest import blogArticleString, blogPreview
from rst2blogger.tests.shared import REST_ARTICLE
LINENOS1 = """
.. sourcecode:: python
:linenos:
import vim
print vim.current.buffer.name
"""
LINENOS2 = """
.. sourcecode:: python
:linenos: -1
import vim
print vim.current.buffer.name
"""
LINENOS3 = """
.. sourcecode:: python
:linenos: 0
import vim
print vim.current.buffer.name
"""
LINENOS4 = """
.. sourcecode:: python
:linenos: 12
import vim
print vim.current.buffer.name
"""
LINENOS5 = """
.. sourcecode:: python
:linenos: this is wrong
import vim
print vim.current.buffer.name
"""
CSSCLASS1 = """
.. sourcecode:: python
:cssclass:
import vim
print vim.current.buffer.name
"""
CSSCLASS2 = """
.. sourcecode:: python
:cssclass: Dessert256
import vim
print vim.current.buffer.name
"""
class TestBlogPreview(unittest.TestCase):
"""
Test generating HTML out of prepared reST text. It tests only for some
aspects of the entire thing, because it is not intendend to test all of
reST directives.
"""
def test_content(self):
"""
Simple case, check output
"""
html_out = blogPreview(REST_ARTICLE)
self.assertTrue(len(html_out) > 0)
self.assertTrue("<html" in html_out)
self.assertTrue("</html>" in html_out)
self.assertTrue("<?xml version=\"1.0\" encoding=\"utf-8\"" in
html_out)
self.assertTrue("\n\n<!-- more -->\n\n" in html_out)
self.assertTrue("<title>Title — This is a test</title>" in html_out)
self.assertTrue('type="text/css"' not in html_out)
self.assertTrue(re.search(r"<h1.*><a href=\"#\">Title — This is a"
" test</a></h1>", html_out))
self.assertTrue(re.search(r"<h2>Section 1</h2>", html_out))
self.assertTrue(re.search(r"<h3>Subsection 1.1</h3>", html_out))
self.assertTrue("description" not in html_out)
def test_stylesheets(self):
"""
Test output for stylesheets
"""
html_out = blogPreview(REST_ARTICLE, ["css/style1.css",
"css/blogger1.css"])
self.assertTrue('type="text/css"' in html_out)
match = re.search(r'<link rel="stylesheet" '
'href=".*" type="text/css" />', html_out)
self.assertTrue(match is not None)
self.assertEqual(len(match.span()), 2)
class TestBlogArticleString(unittest.TestCase):
"""
Test blogArticleString function, wich should return part of html and
dictionary with attributes.
"""
def test_blogArticleString(self):
html_out, attrs = blogArticleString(REST_ARTICLE)
self.assertEqual(len(attrs), 3)
self.assertTrue(len(html_out) > 0)
self.assertTrue("<html" not in html_out)
self.assertTrue("</html>" not in html_out)
self.assertTrue("<?xml version=\"1.0\" encoding=\"utf-8\"" not in
html_out)
self.assertTrue("\n\n<!-- more -->\n\n" in html_out)
self.assertTrue("<title>Title — This is a test</title>" not in
html_out)
self.assertTrue('type="text/css"' not in html_out)
self.assertTrue(re.search(r"<h4>Section 1</h4>", html_out))
self.assertTrue(re.search(r"<h5>Subsection 1.1</h5>", html_out))
self.assertTrue("description" not in html_out)
self.assertEqual(attrs['title'], u"Title — This is a test")
self.assertEqual(attrs['date'], "2010-12-12T12:36:36+01:00")
self.assertEqual(attrs['tags'], "this is a test, Blogger, rest")
class TestBlogArticlePytgments(unittest.TestCase):
"""
Test cases for sourcecode directive
"""
def test_linenos_no_args(self):
"""
Test linenos option with no additional arguments
"""
html_out, _ = blogArticleString(LINENOS1)
self.assertTrue('<pre><span class="lineno">1</span>' in html_out)
def test_linenos_with_arg1(self):
"""
Test linenos option with correct argument type but wrong value.
Should count from 1 in this case.
"""
html_out, _ = blogArticleString(LINENOS2)
self.assertTrue('<pre><span class="lineno">1</span>' in html_out)
def test_linenos_with_arg2(self):
"""
Test linenos option with correct argument type but wrong value.
Should count from 1 in this case.
"""
html_out, _ = blogArticleString(LINENOS3)
self.assertTrue('<pre><span class="lineno">1</span>' in html_out)
def test_linenos_with_arg3(self):
"""
Test linenos option with correct argument type and correct value.
Should count from 1 in this case.
"""
html_out, _ = blogArticleString(LINENOS4)
self.assertTrue('<pre><span class="lineno">12</span>' in html_out)
def test_linenos_with_wrong_arg(self):
"""
Test linenos option with wrong argument type. Should count from 1.
"""
html_out, _ = blogArticleString(LINENOS5)
self.assertTrue('<pre><span class="lineno">1</span>' in html_out)
def test_cssclass_failure(self):
"""
Test cssclass option with no arguments. Should complain with system
message.
"""
html_out, _ = blogArticleString(CSSCLASS1)
self.assertTrue('System Message: ERROR/3' in html_out)
def test_cssclass_correct(self):
"""
Test cssclass option with Dessert256 as an argument. Should be used as
a main div CSS class.
"""
html_out, _ = blogArticleString(CSSCLASS2)
self.assertTrue('<div class="Dessert256">' in html_out)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,75 @@
" reST to blogger vim interface.
" Provide some convinient commands for creating preview from the reST file
" and to send articles to blog.
" VERSION: 0.2
if exists("b:did_rst_plugin")
finish " load only once
else
let b:did_blogger_plugin = 1
endif
if exists(':PreviewBlogArticle')
finish
endif
if !exists("g:blogger_browser")
let g:blogger_browser = 0
endif
if !exists("g:blogger_name")
let g:blogger_name = ""
endif
if !exists("g:blogger_login")
let g:blogger_login= ""
endif
if !exists("g:blogger_pass")
let g:blogger_pass = ""
endif
if !exists("g:blogger_draft")
let g:blogger_draft = 1
endif
if !exists("g:blogger_maxarticles")
let g:blogger_maxarticles = 0
endif
if !exists("g:blogger_confirm_del")
let g:blogger_confirm_del = 1
endif
if !exists("g:blogger_stylesheets")
let g:blogger_stylesheets = []
endif
if !exists("g:blogger_pygments_class")
let g:blogger_pygments_class = ""
endif
python << EOF
import os
import sys
import vim
scriptdir = os.path.dirname(vim.eval('expand("<sfile>")'))
sys.path.insert(0, scriptdir)
# Will raise exception, if one of required moudles is missing
from rst2blogger.main import Rst2Blogger
EOF
if !exists(":PreviewBlogArticle")
command PreviewBlogArticle py print Rst2Blogger().preview()
endif
if !exists(":SendBlogArticle")
command SendBlogArticle py print Rst2Blogger().post()
endif
if !exists(":DeleteBlogArticle")
command DeleteBlogArticle py print Rst2Blogger().delete()
endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,163 @@
"=============================================================================
" Copyright (c) 2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#bookmarkdir#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#bookmarkdir#getSwitchOrder()
return g:fuf_bookmarkdir_switchOrder
endfunction
"
function fuf#bookmarkdir#getEditableDataNames()
return ['items']
endfunction
"
function fuf#bookmarkdir#renewCache()
endfunction
"
function fuf#bookmarkdir#requiresOnCommandPre()
return 0
endfunction
"
function fuf#bookmarkdir#onInit()
call fuf#defineLaunchCommand('FufBookmarkDir', s:MODE_NAME, '""', [])
command! -bang -narg=? FufBookmarkDirAdd call s:bookmark(<q-args>)
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
let s:OPEN_TYPE_DELETE = -1
"
function s:bookmark(word)
let item = {
\ 'time' : localtime(),
\ }
let item.path = l9#inputHl('Question', '[fuf] Directory to bookmark:',
\ fnamemodify(getcwd(), ':p:~'), 'dir')
if item.path !~ '\S'
call fuf#echoWarning('Canceled')
return
endif
let item.word = l9#inputHl('Question', '[fuf] Bookmark as:',
\ fnamemodify(getcwd(), ':p:~'))
if item.word !~ '\S'
call fuf#echoWarning('Canceled')
return
endif
let items = fuf#loadDataFile(s:MODE_NAME, 'items')
call insert(items, item)
call fuf#saveDataFile(s:MODE_NAME, 'items', items)
endfunction
"
function s:findItem(items, word)
for item in a:items
if item.word ==# a:word
return item
endif
endfor
return {}
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_bookmarkdir_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return 0
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return []
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
if a:mode ==# s:OPEN_TYPE_DELETE
let items = fuf#loadDataFile(s:MODE_NAME, 'items')
call filter(items, 'v:val.word !=# a:word')
call fuf#saveDataFile(s:MODE_NAME, 'items', items)
let self.reservedMode = self.getModeName()
return
else
let item = s:findItem(fuf#loadDataFile(s:MODE_NAME, 'items'), a:word)
if !empty(item)
execute ':cd ' . fnameescape(item.path)
endif
endif
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
call fuf#defineKeyMappingInHandler(g:fuf_bookmarkdir_keyDelete,
\ 'onCr(' . s:OPEN_TYPE_DELETE . ')')
let self.items = fuf#loadDataFile(s:MODE_NAME, 'items')
call map(self.items, 'fuf#makeNonPathItem(v:val.word, strftime(g:fuf_timeFormat, v:val.time))')
call fuf#mapToSetSerialIndex(self.items, 1)
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,199 @@
"=============================================================================
" Copyright (c) 2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#bookmarkfile#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#bookmarkfile#getSwitchOrder()
return g:fuf_bookmarkfile_switchOrder
endfunction
"
function fuf#bookmarkfile#getEditableDataNames()
return ['items']
endfunction
"
function fuf#bookmarkfile#renewCache()
endfunction
"
function fuf#bookmarkfile#requiresOnCommandPre()
return 0
endfunction
"
function fuf#bookmarkfile#onInit()
call fuf#defineLaunchCommand('FufBookmarkFile', s:MODE_NAME, '""', [])
command! -bang -narg=? FufBookmarkFileAdd call s:bookmarkHere(<q-args>)
command! -bang -narg=0 -range FufBookmarkFileAddAsSelectedText call s:bookmarkHere(l9#getSelectedText())
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
let s:OPEN_TYPE_DELETE = -1
" opens a:path and jumps to the line matching to a:pattern from a:lnum within
" a:range. if not found, jumps to a:lnum.
function s:jumpToBookmark(path, mode, pattern, lnum)
call fuf#openFile(a:path, a:mode, g:fuf_reuseWindow)
call cursor(s:getMatchingLineNumber(getline(1, '$'), a:pattern, a:lnum), 0)
normal! zvzz
endfunction
"
function s:getMatchingLineNumber(lines, pattern, lnumBegin)
let l = min([a:lnumBegin, len(a:lines)])
for [l0, l1] in map(range(0, g:fuf_bookmarkfile_searchRange),
\ '[l + v:val, l - v:val]')
if l0 <= len(a:lines) && a:lines[l0 - 1] =~# a:pattern
return l0
elseif l1 >= 0 && a:lines[l1 - 1] =~# a:pattern
return l1
endif
endfor
return l
endfunction
"
function s:getLinePattern(lnum)
return '\C\V\^' . escape(getline(a:lnum), '\') . '\$'
endfunction
"
function s:bookmarkHere(word)
if !empty(&buftype) || expand('%') !~ '\S'
call fuf#echoWarning('Can''t bookmark this buffer.')
return
endif
let item = {
\ 'word' : (a:word =~# '\S' ? substitute(a:word, '\n', ' ', 'g')
\ : pathshorten(expand('%:p:~')) . '|' . line('.') . '| ' . getline('.')),
\ 'path' : expand('%:p'),
\ 'lnum' : line('.'),
\ 'pattern' : s:getLinePattern(line('.')),
\ 'time' : localtime(),
\ }
let item.word = l9#inputHl('Question', '[fuf] Bookmark as:', item.word)
if item.word !~ '\S'
call fuf#echoWarning('Canceled')
return
endif
let items = fuf#loadDataFile(s:MODE_NAME, 'items')
call insert(items, item)
call fuf#saveDataFile(s:MODE_NAME, 'items', items)
endfunction
"
function s:findItem(items, word)
for item in a:items
if item.word ==# a:word
return item
endif
endfor
return {}
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_bookmarkfile_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
let item = s:findItem(fuf#loadDataFile(s:MODE_NAME, 'items'), a:word)
let lines = fuf#getFileLines(item.path)
if empty(lines)
return []
endif
let index = s:getMatchingLineNumber(lines, item.pattern, item.lnum) - 1
return fuf#makePreviewLinesAround(
\ lines, [index], a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
if a:mode ==# s:OPEN_TYPE_DELETE
let items = fuf#loadDataFile(s:MODE_NAME, 'items')
call filter(items, 'v:val.word !=# a:word')
call fuf#saveDataFile(s:MODE_NAME, 'items', items)
let self.reservedMode = self.getModeName()
return
else
let item = s:findItem(fuf#loadDataFile(s:MODE_NAME, 'items'), a:word)
if !empty(item)
call s:jumpToBookmark(item.path, a:mode, item.pattern, item.lnum)
endif
endif
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
call fuf#defineKeyMappingInHandler(g:fuf_bookmarkfile_keyDelete,
\ 'onCr(' . s:OPEN_TYPE_DELETE . ')')
let self.items = fuf#loadDataFile(s:MODE_NAME, 'items')
call map(self.items, 'fuf#makeNonPathItem(v:val.word, strftime(g:fuf_timeFormat, v:val.time))')
call fuf#mapToSetSerialIndex(self.items, 1)
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,189 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#buffer#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#buffer#getSwitchOrder()
return g:fuf_buffer_switchOrder
endfunction
"
function fuf#buffer#getEditableDataNames()
return []
endfunction
"
function fuf#buffer#renewCache()
endfunction
"
function fuf#buffer#requiresOnCommandPre()
return 0
endfunction
"
function fuf#buffer#onInit()
call fuf#defineLaunchCommand('FufBuffer', s:MODE_NAME, '""', [])
augroup fuf#buffer
autocmd!
autocmd BufEnter * call s:updateBufTimes()
autocmd BufWritePost * call s:updateBufTimes()
augroup END
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
let s:OPEN_TYPE_DELETE = -1
let s:bufTimes = {}
"
function s:updateBufTimes()
let s:bufTimes[bufnr('%')] = localtime()
endfunction
"
function s:makeItem(nr)
let fname = (empty(bufname(a:nr))
\ ? '[No Name]'
\ : fnamemodify(bufname(a:nr), ':p:~:.'))
let time = (exists('s:bufTimes[a:nr]') ? s:bufTimes[a:nr] : 0)
let item = fuf#makePathItem(fname, strftime(g:fuf_timeFormat, time), 0)
let item.index = a:nr
let item.bufNr = a:nr
let item.time = time
let item.abbrPrefix = s:getBufIndicator(a:nr) . ' '
return item
endfunction
"
function s:getBufIndicator(bufNr)
if !getbufvar(a:bufNr, '&modifiable')
return '[-]'
elseif getbufvar(a:bufNr, '&modified')
return '[+]'
elseif getbufvar(a:bufNr, '&readonly')
return '[R]'
else
return ' '
endif
endfunction
"
function s:compareTimeDescending(i1, i2)
return a:i1.time == a:i2.time ? 0 : a:i1.time > a:i2.time ? -1 : +1
endfunction
"
function s:findItem(items, word)
for item in a:items
if item.word ==# a:word
return item
endif
endfor
return {}
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_buffer_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
let item = s:findItem(self.items, a:word)
if empty(item)
return []
endif
return fuf#makePreviewLinesForFile(item.bufNr, a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
" not use bufnr(a:word) in order to handle unnamed buffer
let item = s:findItem(self.items, a:word)
if empty(item)
" do nothing
elseif a:mode ==# s:OPEN_TYPE_DELETE
execute item.bufNr . 'bdelete'
let self.reservedMode = self.getModeName()
else
call fuf#openBuffer(item.bufNr, a:mode, g:fuf_reuseWindow)
endif
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
call fuf#defineKeyMappingInHandler(g:fuf_buffer_keyDelete,
\ 'onCr(' . s:OPEN_TYPE_DELETE . ')')
let self.items = range(1, bufnr('$'))
call filter(self.items, 'buflisted(v:val) && v:val != self.bufNrPrev && v:val != bufnr("%")')
call map(self.items, 's:makeItem(v:val)')
if g:fuf_buffer_mruOrder
call sort(self.items, 's:compareTimeDescending')
call fuf#mapToSetSerialIndex(self.items, 1)
endif
let self.items = fuf#mapToSetAbbrWithSnippedWordAsPath(self.items)
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,300 @@
"=============================================================================
" Copyright (c) 2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#buffertag#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#buffertag#getSwitchOrder()
return g:fuf_buffertag_switchOrder
endfunction
"
function fuf#buffertag#getEditableDataNames()
return []
endfunction
"
function fuf#buffertag#renewCache()
let s:tagItemsCache = {}
let s:tagDataCache = {}
endfunction
"
function fuf#buffertag#requiresOnCommandPre()
return 0
endfunction
"
function fuf#buffertag#onInit()
call fuf#defineLaunchCommand('FufBufferTag', s:MODE_NAME, '""',
\ [['g:fuf_buffertag_forAll', 0]])
call fuf#defineLaunchCommand('FufBufferTagAll', s:MODE_NAME, '""',
\ [['g:fuf_buffertag_forAll', 1]])
call fuf#defineLaunchCommand('FufBufferTagWithCursorWord', s:MODE_NAME,
\ 'expand(''<cword>'')', [['g:fuf_buffertag_forAll', 0]])
call fuf#defineLaunchCommand('FufBufferTagAllWithCursorWord', s:MODE_NAME,
\ 'expand(''<cword>'')', [['g:fuf_buffertag_forAll', 1]])
call fuf#defineLaunchCommand('FufBufferTagWithSelectedText', s:MODE_NAME,
\ 'l9#getSelectedText()', [['g:fuf_buffertag_forAll', 0]])
call fuf#defineLaunchCommand('FufBufferTagAllWithSelectedText', s:MODE_NAME,
\ 'l9#getSelectedText()', [['g:fuf_buffertag_forAll', 1]])
call l9#defineVariableDefault('g:fuf_buffertag_forAll', 0) " private option
" the following settings originate from taglist.vim
call l9#defineVariableDefault('g:fuf_buffertag__asm' , '--language-force=asm --asm-types=dlmt')
call l9#defineVariableDefault('g:fuf_buffertag__aspperl' , '--language-force=asp --asp-types=fsv')
call l9#defineVariableDefault('g:fuf_buffertag__aspvbs' , '--language-force=asp --asp-types=fsv')
call l9#defineVariableDefault('g:fuf_buffertag__awk' , '--language-force=awk --awk-types=f')
call l9#defineVariableDefault('g:fuf_buffertag__beta' , '--language-force=beta --beta-types=fsv')
call l9#defineVariableDefault('g:fuf_buffertag__c' , '--language-force=c --c-types=dgsutvf')
call l9#defineVariableDefault('g:fuf_buffertag__cpp' , '--language-force=c++ --c++-types=nvdtcgsuf')
call l9#defineVariableDefault('g:fuf_buffertag__cs' , '--language-force=c# --c#-types=dtncEgsipm')
call l9#defineVariableDefault('g:fuf_buffertag__cobol' , '--language-force=cobol --cobol-types=dfgpPs')
call l9#defineVariableDefault('g:fuf_buffertag__eiffel' , '--language-force=eiffel --eiffel-types=cf')
call l9#defineVariableDefault('g:fuf_buffertag__erlang' , '--language-force=erlang --erlang-types=drmf')
call l9#defineVariableDefault('g:fuf_buffertag__expect' , '--language-force=tcl --tcl-types=cfp')
call l9#defineVariableDefault('g:fuf_buffertag__fortran' , '--language-force=fortran --fortran-types=pbceiklmntvfs')
call l9#defineVariableDefault('g:fuf_buffertag__html' , '--language-force=html --html-types=af')
call l9#defineVariableDefault('g:fuf_buffertag__java' , '--language-force=java --java-types=pcifm')
call l9#defineVariableDefault('g:fuf_buffertag__javascript', '--language-force=javascript --javascript-types=f')
call l9#defineVariableDefault('g:fuf_buffertag__lisp' , '--language-force=lisp --lisp-types=f')
call l9#defineVariableDefault('g:fuf_buffertag__lua' , '--language-force=lua --lua-types=f')
call l9#defineVariableDefault('g:fuf_buffertag__make' , '--language-force=make --make-types=m')
call l9#defineVariableDefault('g:fuf_buffertag__pascal' , '--language-force=pascal --pascal-types=fp')
call l9#defineVariableDefault('g:fuf_buffertag__perl' , '--language-force=perl --perl-types=clps')
call l9#defineVariableDefault('g:fuf_buffertag__php' , '--language-force=php --php-types=cdvf')
call l9#defineVariableDefault('g:fuf_buffertag__python' , '--language-force=python --python-types=cmf')
call l9#defineVariableDefault('g:fuf_buffertag__rexx' , '--language-force=rexx --rexx-types=s')
call l9#defineVariableDefault('g:fuf_buffertag__ruby' , '--language-force=ruby --ruby-types=cfFm')
call l9#defineVariableDefault('g:fuf_buffertag__scheme' , '--language-force=scheme --scheme-types=sf')
call l9#defineVariableDefault('g:fuf_buffertag__sh' , '--language-force=sh --sh-types=f')
call l9#defineVariableDefault('g:fuf_buffertag__csh' , '--language-force=sh --sh-types=f')
call l9#defineVariableDefault('g:fuf_buffertag__zsh' , '--language-force=sh --sh-types=f')
call l9#defineVariableDefault('g:fuf_buffertag__slang' , '--language-force=slang --slang-types=nf')
call l9#defineVariableDefault('g:fuf_buffertag__sml' , '--language-force=sml --sml-types=ecsrtvf')
call l9#defineVariableDefault('g:fuf_buffertag__sql' , '--language-force=sql --sql-types=cFPrstTvfp')
call l9#defineVariableDefault('g:fuf_buffertag__tcl' , '--language-force=tcl --tcl-types=cfmp')
call l9#defineVariableDefault('g:fuf_buffertag__vera' , '--language-force=vera --vera-types=cdefgmpPtTvx')
call l9#defineVariableDefault('g:fuf_buffertag__verilog' , '--language-force=verilog --verilog-types=mcPertwpvf')
call l9#defineVariableDefault('g:fuf_buffertag__vim' , '--language-force=vim --vim-types=avf')
call l9#defineVariableDefault('g:fuf_buffertag__yacc' , '--language-force=yacc --yacc-types=l')
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:parseTagLine(line)
" tag W:\Win32\SRC7\NCSIM\NCVW32\CUBEFACE.H /^#define CUBEFACE_H$/;" macro line:4
let fields = matchlist(a:line, '\v^([^\t]+)\t(.+)\t\/\^(.+)\$\/\;\"\t(.+)\tline\:(\d+)')
if empty(fields)
return {}
endif
return {
\ 'tag' : fields[1],
\ 'fname' : fields[2],
\ 'pattern': fields[3],
\ 'kind' : fields[4],
\ 'lnum' : str2nr(fields[5]),
\ }
endfunction
"
let s:TEMP_VARIABLES_GROUP = expand('<sfile>:p')
"
function s:getFileType(bufNr)
let ft = getbufvar(a:bufNr, '&filetype')
if !empty(ft) || bufloaded(a:bufNr)
return ft
endif
let ft = getbufvar(a:bufNr, 'fuf_buffertag_filetype')
if !empty(ft)
return ft
endif
call l9#tempvariables#set(s:TEMP_VARIABLES_GROUP, '&eventignore', 'FileType')
call l9#tempvariables#set(s:TEMP_VARIABLES_GROUP, '&filetype', &filetype)
" from taglist.vim
execute 'doautocmd filetypedetect BufRead ' . bufname(a:bufNr)
let ft = &filetype
call l9#tempvariables#end(s:TEMP_VARIABLES_GROUP)
call setbufvar(a:bufNr, 'fuf_buffertag_filetype', ft)
return ft
endfunction
"
function s:makeCtagsCmd(bufNr)
let ft = s:getFileType(a:bufNr)
if !exists('g:fuf_buffertag__{ft}')
return ''
endif
"
let cmd = join([g:fuf_buffertag_ctagsPath,
\ '-f - --sort=no --excmd=pattern --fields=nKs',
\ g:fuf_buffertag__{ft},
\ shellescape(fnamemodify(bufname(a:bufNr), ':p'))])
return cmd
endfunction
"
function s:getTagItems(bufNr)
let cmd = s:makeCtagsCmd(a:bufNr)
if empty(cmd)
return []
elseif !exists('s:tagItemsCache[cmd]') ||
\ s:tagItemsCache[cmd].time < getftime(expand(bufname(a:bufNr)))
let items = split(system(cmd), "\n")
if v:shell_error
call fuf#echoError([cmd] + items)
throw "Command error"
endif
call map(items, 's:parseTagLine(v:val)')
call filter(items, '!empty(v:val)')
let s:tagItemsCache[cmd] = {
\ 'time' : localtime(),
\ 'items' : items,
\ }
endif
return s:tagItemsCache[cmd].items
endfunction
"
function s:makeItem(tag, itemMap)
let menu = fnamemodify(a:itemMap[a:tag][0].fname, ':t')
\ . ' [' . a:itemMap[a:tag][0].kind . ']'
if len(a:itemMap[a:tag]) > 1
let menu .= ' (' . len(a:itemMap[a:tag]) . ')'
endif
let item = fuf#makeNonPathItem(a:tag, menu)
return item
endfunction
"
function s:getTagData(bufNrs)
let key = join([0] + sort(copy(a:bufNrs)), "\n")
let bufNames = map(copy(a:bufNrs), 'bufname(v:val)')
if !exists('s:tagDataCache[key]') ||
\ fuf#countModifiedFiles(bufNames, s:tagDataCache[key].time) > 0
let itemMap = {}
for item in l9#concat(map(copy(a:bufNrs), 's:getTagItems(v:val)'))
if !exists('itemMap[item.tag]')
let itemMap[item.tag] = []
endif
call add(itemMap[item.tag], item)
endfor
let items = sort(keys(itemMap))
call map(items, 's:makeItem(v:val, itemMap)')
call fuf#mapToSetSerialIndex(items, 1)
call map(items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
let s:tagDataCache[key] = {
\ 'time' : localtime(),
\ 'itemMap': itemMap,
\ 'items' : items,
\ }
endif
return [s:tagDataCache[key].items, s:tagDataCache[key].itemMap]
endfunction
"
function s:jumpToTag(item, mode)
call fuf#openFile(a:item.fname, a:mode, g:fuf_reuseWindow)
call cursor(a:item.lnum, 1)
normal! zvzz
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_buffertag_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return 0
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return []
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
if !exists('self.itemMap[a:word][0]')
call fuf#echoError('Definition not found:' . a:word)
return
elseif len(self.itemMap[a:word]) == 1
let i = 0
else
let list = map(fuf#mapToSetSerialIndex(copy(self.itemMap[a:word]), 1),
\ 'printf(" %2d: %s|%d| [%s] %s",v:val.index, fnamemodify(v:val.fname, ":~:."), v:val.lnum, v:val.kind, v:val.pattern)')
let i = inputlist(['Select a definition of "' . a:word . '":'] + list) - 1
endif
if 0 <= i && i < len(self.itemMap[a:word])
call s:jumpToTag(self.itemMap[a:word][i], a:mode)
endif
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
if g:fuf_buffertag_forAll
let bufNrs = filter(range(1, bufnr('$')), 'buflisted(v:val)')
else
let bufNrs = [self.bufNrPrev]
endif
let [self.items, self.itemMap] = s:getTagData(bufNrs)
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,137 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#callbackfile#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#callbackfile#getSwitchOrder()
return -1
endfunction
"
function fuf#callbackfile#getEditableDataNames()
return []
endfunction
"
function fuf#callbackfile#renewCache()
let s:cache = {}
endfunction
"
function fuf#callbackfile#requiresOnCommandPre()
return 0
endfunction
"
function fuf#callbackfile#onInit()
endfunction
"
function fuf#callbackfile#launch(initialPattern, partialMatching, prompt, exclude, listener)
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
let s:exclude = a:exclude
let s:listener = a:listener
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:enumItems(dir)
let key = getcwd() . g:fuf_ignoreCase . s:exclude . "\n" . a:dir
if !exists('s:cache[key]')
let s:cache[key] = fuf#enumExpandedDirsEntries(a:dir, s:exclude)
if isdirectory(a:dir)
call insert(s:cache[key], fuf#makePathItem(a:dir . '.', '', 0))
endif
call fuf#mapToSetSerialIndex(s:cache[key], 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:cache[key])
endif
return s:cache[key]
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(s:prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return a:enteredPattern =~# '[^/\\]$'
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPathTail',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
let items = copy(s:enumItems(fuf#splitPath(a:patternPrimary).head))
return filter(items, 'bufnr("^" . v:val.word . "$") != self.bufNrPrev')
endfunction
"
function s:handler.onOpen(word, mode)
call s:listener.onComplete(a:word, a:mode)
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
endfunction
"
function s:handler.onModeLeavePost(opened)
if !a:opened && exists('s:listener.onAbort()')
call s:listener.onAbort()
endif
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,139 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#callbackitem#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#callbackitem#getSwitchOrder()
return -1
endfunction
"
function fuf#callbackitem#getEditableDataNames()
return []
endfunction
"
function fuf#callbackitem#renewCache()
endfunction
"
function fuf#callbackitem#requiresOnCommandPre()
return 0
endfunction
"
function fuf#callbackitem#onInit()
endfunction
"
function fuf#callbackitem#launch(initialPattern, partialMatching, prompt, listener, items, forPath)
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
let s:listener = a:listener
let s:forPath = a:forPath
let s:items = copy(a:items)
if s:forPath
call map(s:items, 'fuf#makePathItem(v:val, "", 1)')
call fuf#mapToSetSerialIndex(s:items, 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:items)
else
call map(s:items, 'fuf#makeNonPathItem(v:val, "")')
call fuf#mapToSetSerialIndex(s:items, 1)
call map(s:items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
endif
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(s:prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
if s:forPath
return g:fuf_previewHeight
endif
return 0
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
let parser = (s:forPath
\ ? 's:interpretPrimaryPatternForPath'
\ : 's:interpretPrimaryPatternForNonPath')
return fuf#makePatternSet(a:patternBase, parser, self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
if s:forPath
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
endif
return []
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:items
endfunction
"
function s:handler.onOpen(word, mode)
call s:listener.onComplete(a:word, a:mode)
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
endfunction
"
function s:handler.onModeLeavePost(opened)
if !a:opened && exists('s:listener.onAbort()')
call s:listener.onAbort()
endif
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,172 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#changelist#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#changelist#getSwitchOrder()
return g:fuf_changelist_switchOrder
endfunction
"
function fuf#changelist#getEditableDataNames()
return []
endfunction
"
function fuf#changelist#renewCache()
endfunction
"
function fuf#changelist#requiresOnCommandPre()
return 0
endfunction
"
function fuf#changelist#onInit()
call fuf#defineLaunchCommand('FufChangeList', s:MODE_NAME, '""', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:getChangesLines()
redir => result
:silent changes
redir END
return split(result, "\n")
endfunction
"
function s:parseChangesLine(line)
" return matchlist(a:line, '^\(.\)\s\+\(\d\+\)\s\(.*\)$')
let elements = matchlist(a:line, '\v^(.)\s*(\d+)\s+(\d+)\s+(\d+)\s*(.*)$')
if empty(elements)
return {}
endif
return {
\ 'prefix': elements[1],
\ 'count' : elements[2],
\ 'lnum' : elements[3],
\ 'text' : printf('|%d:%d|%s', elements[3], elements[4], elements[5]),
\ }
endfunction
"
function s:makeItem(line)
let parsed = s:parseChangesLine(a:line)
if empty(parsed)
return {}
endif
let item = fuf#makeNonPathItem(parsed.text, '')
let item.abbrPrefix = parsed.prefix
let item.lnum = parsed.lnum
return item
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_changelist_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
let items = filter(copy(self.items), 'v:val.word ==# a:word')
if empty(items)
return []
endif
let lines = fuf#getFileLines(self.bufNrPrev)
return fuf#makePreviewLinesAround(
\ lines, [items[0].lnum - 1], a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#prejump(a:mode)
let older = 0
for line in reverse(s:getChangesLines())
if stridx(line, '>') == 0
let older = 1
endif
let parsed = s:parseChangesLine(line)
if !empty(parsed) && parsed.text ==# a:word
if parsed.count != 0
execute 'normal! ' . parsed.count . (older ? 'g;' : 'g,') . 'zvzz'
endif
break
endif
endfor
endfunction
"
function s:handler.onModeEnterPre()
let self.items = s:getChangesLines()
endfunction
"
function s:handler.onModeEnterPost()
call map(self.items, 's:makeItem(v:val)')
call filter(self.items, '!empty(v:val)')
call reverse(self.items)
call fuf#mapToSetSerialIndex(self.items, 1)
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,199 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#coveragefile#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#coveragefile#getSwitchOrder()
return g:fuf_coveragefile_switchOrder
endfunction
"
function fuf#coveragefile#getEditableDataNames()
return ['coverages']
endfunction
"
function fuf#coveragefile#renewCache()
let s:cache = {}
endfunction
"
function fuf#coveragefile#requiresOnCommandPre()
return 0
endfunction
"
function fuf#coveragefile#onInit()
call fuf#defineLaunchCommand('FufCoverageFile', s:MODE_NAME, '""', [])
call l9#defineVariableDefault('g:fuf_coveragefile_name', '') " private option
command! -bang -narg=0 FufCoverageFileRegister call s:registerCoverage()
command! -bang -narg=? FufCoverageFileChange call s:changeCoverage(<q-args>)
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:enumItems()
let key = join([getcwd(), g:fuf_ignoreCase, g:fuf_coveragefile_exclude,
\ g:fuf_coveragefile_globPatterns], "\n")
if !exists('s:cache[key]')
let s:cache[key] = l9#concat(map(copy(g:fuf_coveragefile_globPatterns),
\ 'fuf#glob(v:val)'))
call filter(s:cache[key], 'filereadable(v:val)') " filter out directories
call map(s:cache[key], 'fuf#makePathItem(fnamemodify(v:val, ":~:."), "", 0)')
if len(g:fuf_coveragefile_exclude)
call filter(s:cache[key], 'v:val.word !~ g:fuf_coveragefile_exclude')
endif
call fuf#mapToSetSerialIndex(s:cache[key], 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:cache[key])
endif
return s:cache[key]
endfunction
"
function s:registerCoverage()
let patterns = []
while 1
let pattern = l9#inputHl('Question', '[fuf] Glob pattern for coverage (<Esc> and end):',
\ '', 'file')
if pattern !~ '\S'
break
endif
call add(patterns, pattern)
endwhile
if empty(patterns)
call fuf#echoWarning('Canceled')
return
endif
echo '[fuf] patterns: ' . string(patterns)
let name = l9#inputHl('Question', '[fuf] Coverage name:')
if name !~ '\S'
call fuf#echoWarning('Canceled')
return
endif
let coverages = fuf#loadDataFile(s:MODE_NAME, 'coverages')
call insert(coverages, {'name': name, 'patterns': patterns})
call fuf#saveDataFile(s:MODE_NAME, 'coverages', coverages)
endfunction
"
function s:createChangeCoverageListener()
let listener = {}
function listener.onComplete(name, method)
call s:changeCoverage(a:name)
endfunction
return listener
endfunction
"
function s:changeCoverage(name)
let coverages = fuf#loadDataFile(s:MODE_NAME, 'coverages')
if a:name !~ '\S'
let names = map(copy(coverages), 'v:val.name')
call fuf#callbackitem#launch('', 0, '>Coverage>', s:createChangeCoverageListener(), names, 0)
return
else
let name = a:name
endif
call filter(coverages, 'v:val.name ==# name')
if empty(coverages)
call fuf#echoError('Coverage not found: ' . name)
return
endif
call fuf#setOneTimeVariables(
\ ['g:fuf_coveragefile_globPatterns', coverages[0].patterns],
\ ['g:fuf_coveragefile_name' , a:name]
\ )
FufCoverageFile
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
let nameString = (empty(g:fuf_coveragefile_name) ? ''
\ : '[' . g:fuf_coveragefile_name . ']')
return fuf#formatPrompt(g:fuf_coveragefile_prompt, self.partialMatching,
\ nameString)
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
" NOTE: Comparing filenames is faster than bufnr('^' . fname . '$')
let bufNamePrev = fnamemodify(bufname(self.bufNrPrev), ':~:.')
let self.items = copy(s:enumItems())
call filter(self.items, 'v:val.word !=# bufNamePrev')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,132 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#dir#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#dir#getSwitchOrder()
return g:fuf_dir_switchOrder
endfunction
"
function fuf#dir#getEditableDataNames()
return []
endfunction
"
function fuf#dir#renewCache()
let s:cache = {}
endfunction
"
function fuf#dir#requiresOnCommandPre()
return 0
endfunction
"
function fuf#dir#onInit()
call fuf#defineLaunchCommand('FufDir' , s:MODE_NAME, '""', [])
call fuf#defineLaunchCommand('FufDirWithFullCwd' , s:MODE_NAME, 'fnamemodify(getcwd(), '':p'')', [])
call fuf#defineLaunchCommand('FufDirWithCurrentBufferDir', s:MODE_NAME, 'expand(''%:~:.'')[:-1-len(expand(''%:~:.:t''))]', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:enumItems(dir)
let key = getcwd() . g:fuf_ignoreCase . g:fuf_dir_exclude . "\n" . a:dir
if !exists('s:cache[key]')
let s:cache[key] = fuf#enumExpandedDirsEntries(a:dir, g:fuf_dir_exclude)
call filter(s:cache[key], 'v:val.word =~# ''[/\\]$''')
if isdirectory(a:dir)
call insert(s:cache[key], fuf#makePathItem(a:dir . '.', '', 0))
endif
call fuf#mapToSetSerialIndex(s:cache[key], 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:cache[key])
endif
return s:cache[key]
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_dir_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return a:enteredPattern =~# '[^/\\]$'
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPathTail',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesAround(
\ fuf#glob(fnamemodify(a:word, ':p') . '*'),
\ [], a:count, self.getPreviewHeight())
return
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:enumItems(fuf#splitPath(a:patternPrimary).head)
endfunction
"
function s:handler.onOpen(word, mode)
execute ':cd ' . fnameescape(a:word)
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,139 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#file#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#file#getSwitchOrder()
return g:fuf_file_switchOrder
endfunction
"
function fuf#file#getEditableDataNames()
return []
endfunction
"
function fuf#file#renewCache()
let s:cache = {}
endfunction
"
function fuf#file#requiresOnCommandPre()
return 0
endfunction
"
function fuf#file#onInit()
call fuf#defineLaunchCommand('FufFile' , s:MODE_NAME, '""', [])
call fuf#defineLaunchCommand('FufFileWithFullCwd' , s:MODE_NAME, 'fnamemodify(getcwd(), '':p'')', [])
call fuf#defineLaunchCommand('FufFileWithCurrentBufferDir', s:MODE_NAME, 'expand(''%:~:.'')[:-1-len(expand(''%:~:.:t''))]', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:enumItems(dir)
let key = join([getcwd(), g:fuf_ignoreCase, g:fuf_file_exclude, a:dir], "\n")
if !exists('s:cache[key]')
let s:cache[key] = fuf#enumExpandedDirsEntries(a:dir, g:fuf_file_exclude)
call fuf#mapToSetSerialIndex(s:cache[key], 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:cache[key])
endif
return s:cache[key]
endfunction
"
function s:enumNonCurrentItems(dir, bufNrPrev, cache)
let key = a:dir . 'AVOIDING EMPTY KEY'
if !exists('a:cache[key]')
" NOTE: Comparing filenames is faster than bufnr('^' . fname . '$')
let bufNamePrev = bufname(a:bufNrPrev)
let a:cache[key] =
\ filter(copy(s:enumItems(a:dir)), 'v:val.word !=# bufNamePrev')
endif
return a:cache[key]
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_file_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return a:enteredPattern =~# '[^/\\]$'
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPathTail',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:enumNonCurrentItems(
\ fuf#splitPath(a:patternPrimary).head, self.bufNrPrev, self.cache)
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
let self.cache = {}
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,123 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#givencmd#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#givencmd#getSwitchOrder()
return -1
endfunction
"
function fuf#givencmd#getEditableDataNames()
return []
endfunction
"
function fuf#givencmd#renewCache()
endfunction
"
function fuf#givencmd#requiresOnCommandPre()
return 0
endfunction
"
function fuf#givencmd#onInit()
endfunction
"
function fuf#givencmd#launch(initialPattern, partialMatching, prompt, items)
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
let s:items = copy(a:items)
call map(s:items, 'fuf#makeNonPathItem(v:val, "")')
call fuf#mapToSetSerialIndex(s:items, 1)
call map(s:items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(s:prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return 0
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return []
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:items
endfunction
"
function s:handler.onOpen(word, mode)
if a:word[0] =~# '[:/?]'
call histadd(a:word[0], a:word[1:])
endif
call feedkeys(a:word . "\<CR>", 'n')
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,123 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#givendir#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#givendir#getSwitchOrder()
return -1
endfunction
"
function fuf#givendir#getEditableDataNames()
return []
endfunction
"
function fuf#givendir#renewCache()
endfunction
"
function fuf#givendir#requiresOnCommandPre()
return 0
endfunction
"
function fuf#givendir#onInit()
endfunction
"
function fuf#givendir#launch(initialPattern, partialMatching, prompt, items)
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
let s:items = map(copy(a:items), 'substitute(v:val, ''[/\\]\?$'', "", "")')
let s:items = map(s:items, 'fuf#makePathItem(v:val, "", 0)')
call fuf#mapToSetSerialIndex(s:items, 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:items)
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(s:prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesAround(
\ fuf#glob(fnamemodify(a:word, ':p') . '*'),
\ [], a:count, self.getPreviewHeight())
return
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:items
endfunction
"
function s:handler.onOpen(word, mode)
execute ':cd ' . fnameescape(a:word)
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,121 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#givenfile#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#givenfile#getSwitchOrder()
return -1
endfunction
"
function fuf#givenfile#getEditableDataNames()
return []
endfunction
"
function fuf#givenfile#renewCache()
endfunction
"
function fuf#givenfile#requiresOnCommandPre()
return 0
endfunction
"
function fuf#givenfile#onInit()
endfunction
"
function fuf#givenfile#launch(initialPattern, partialMatching, prompt, items)
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
let s:items = map(copy(a:items), 'fuf#makePathItem(v:val, "", 0)')
call fuf#mapToSetSerialIndex(s:items, 1)
call map(s:items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(s:prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:items
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,198 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#help#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#help#getSwitchOrder()
return g:fuf_help_switchOrder
endfunction
"
function fuf#help#getEditableDataNames()
return []
endfunction
"
function fuf#help#renewCache()
let s:cache = {}
endfunction
"
function fuf#help#requiresOnCommandPre()
return 0
endfunction
"
function fuf#help#onInit()
call fuf#defineLaunchCommand('FufHelp' , s:MODE_NAME, '""', [])
call fuf#defineLaunchCommand('FufHelpWithCursorWord', s:MODE_NAME, 'expand(''<cword>'')', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:getCurrentHelpTagFiles()
let prefix = 'doc' . l9#getPathSeparator()
let tagFiles = split(globpath(&runtimepath, prefix . 'tags' ), "\n")
\ + split(globpath(&runtimepath, prefix . 'tags-??'), "\n")
return sort(map(tagFiles, 'fnamemodify(v:val, ":p")'))
endfunction
"
function s:parseHelpTagEntry(line, tagFile)
let elements = split(a:line, "\t")
if len(elements) != 3 || elements[0][0] ==# '!'
return {}
endif
let suffix = matchstr(a:tagFile, '-\zs..$')
if empty(suffix)
let suffix = '@en'
else
let suffix = '@' . suffix
endif
let dir = fnamemodify(a:tagFile, ':h') . l9#getPathSeparator()
return {
\ 'word' : elements[0] . suffix,
\ 'path' : dir . elements[1],
\ 'pattern': elements[2][1:],
\ }
endfunction
"
function s:getHelpTagEntries(tagFile)
let names = map(l9#readFile(a:tagFile), 's:parseHelpTagEntry(v:val, a:tagFile)')
return filter(names, '!empty(v:val)')
endfunction
"
function s:parseHelpTagFiles(tagFiles, key)
let cacheName = 'cache-' . l9#hash224(a:key)
let cacheTime = fuf#getDataFileTime(s:MODE_NAME, cacheName)
if cacheTime != -1 && fuf#countModifiedFiles(a:tagFiles, cacheTime) == 0
return fuf#loadDataFile(s:MODE_NAME, cacheName)
endif
let items = l9#unique(l9#concat(map(copy(a:tagFiles), 's:getHelpTagEntries(v:val)')))
let items = map(items, 'extend(v:val, fuf#makeNonPathItem(v:val.word, ""))')
call fuf#mapToSetSerialIndex(items, 1)
let items = map(items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
call fuf#saveDataFile(s:MODE_NAME, cacheName, items)
return items
endfunction
"
function s:enumHelpTags(tagFiles)
if !len(a:tagFiles)
return []
endif
let key = join([g:fuf_ignoreCase] + a:tagFiles, "\n")
if !exists('s:cache[key]') || fuf#countModifiedFiles(a:tagFiles, s:cache[key].time)
let s:cache[key] = {
\ 'time' : localtime(),
\ 'items' : s:parseHelpTagFiles(a:tagFiles, key)
\ }
endif
return s:cache[key].items
endfunction
"
function s:getMatchingIndex(lines, pattern)
if empty(a:pattern)
return -1
endif
for i in range(len(a:lines))
if stridx(a:lines[i], a:pattern) >= 0
return i
endif
endfor
return -1
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_help_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
let items = filter(copy(s:enumHelpTags(self.tagFiles)), 'v:val.word ==# a:word')
if empty(items)
return []
endif
let lines = fuf#getFileLines(items[0].path)
let index = s:getMatchingIndex(lines, items[0].pattern)
return [items[0].path . ':'] + fuf#makePreviewLinesAround(
\ lines, (index < 0 ? [] : [index]), a:count, self.getPreviewHeight() - 1)
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:enumHelpTags(self.tagFiles)
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#openHelp(a:word, a:mode)
endfunction
"
function s:handler.onModeEnterPre()
let self.tagFiles = s:getCurrentHelpTagFiles()
endfunction
"
function s:handler.onModeEnterPost()
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,182 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#jumplist#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#jumplist#getSwitchOrder()
return g:fuf_jumplist_switchOrder
endfunction
"
function fuf#jumplist#getEditableDataNames()
return []
endfunction
"
function fuf#jumplist#renewCache()
endfunction
"
function fuf#jumplist#requiresOnCommandPre()
return 0
endfunction
"
function fuf#jumplist#onInit()
call fuf#defineLaunchCommand('FufJumpList', s:MODE_NAME, '""', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:getJumpsLines()
redir => result
:silent jumps
redir END
return split(result, "\n")
endfunction
"
function s:parseJumpsLine(line, bufnrPrev)
"return matchlist(a:line, '^\(.\)\s\+\(\d\+\)\s\(.*\)$')
let elements = matchlist(a:line, '\v^(.)\s*(\d+)\s+(\d+)\s+(\d+)\s*(.*)$')
if empty(elements)
return {}
endif
let linePrevBuffer = join(getbufline(a:bufnrPrev, elements[3]))
if stridx(linePrevBuffer, elements[5]) >= 0
let fname = bufname(a:bufnrPrev)
let text = elements[5]
else
let fname = elements[5]
let text = join(getbufline('^' . elements[5] . '$', elements[3]))
endif
return {
\ 'prefix': elements[1],
\ 'count' : elements[2],
\ 'lnum' : elements[3],
\ 'fname' : fname,
\ 'text' : printf('%s|%d:%d|%s', fname, elements[3], elements[4], text),
\ }
endfunction
"
function s:makeItem(line, bufnrPrev)
let parsed = s:parseJumpsLine(a:line, a:bufnrPrev)
if empty(parsed)
return {}
endif
let item = fuf#makeNonPathItem(parsed.text, '')
let item.abbrPrefix = parsed.prefix
let item.lnum = parsed.lnum
let item.fname = parsed.fname
return item
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_jumplist_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
let items = filter(copy(self.items), 'v:val.word ==# a:word')
if empty(items)
return []
endif
let lines = fuf#getFileLines(items[0].fname)
return fuf#makePreviewLinesAround(
\ lines, [items[0].lnum - 1], a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#prejump(a:mode)
let older = 0
for line in reverse(s:getJumpsLines())
if stridx(line, '>') == 0
let older = 1
endif
let parsed = s:parseJumpsLine(line, self.bufNrPrev)
if !empty(parsed) && parsed.text ==# a:word
if parsed.count != 0
execute 'normal! ' . parsed.count . (older ? "\<C-o>" : "\<C-i>") . 'zvzz'
endif
break
endif
endfor
endfunction
"
function s:handler.onModeEnterPre()
let self.items = s:getJumpsLines()
endfunction
"
function s:handler.onModeEnterPost()
call map(self.items, 's:makeItem(v:val, self.bufNrPrev)')
call filter(self.items, '!empty(v:val)')
call reverse(self.items)
call fuf#mapToSetSerialIndex(self.items, 1)
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,135 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#line#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#line#getSwitchOrder()
return g:fuf_line_switchOrder
endfunction
"
function fuf#line#getEditableDataNames()
return []
endfunction
"
function fuf#line#renewCache()
endfunction
"
function fuf#line#requiresOnCommandPre()
return 0
endfunction
"
function fuf#line#onInit()
call fuf#defineLaunchCommand('FufLine', s:MODE_NAME, '""', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
let s:OPEN_TYPE_DELETE = -1
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_line_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
let items = filter(copy(self.items), 'v:val.word ==# a:word')
if empty(items)
return []
endif
let lines = fuf#getFileLines(self.bufNrPrev)
return fuf#makePreviewLinesAround(
\ lines, [items[0].index - 1], a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#prejump(a:mode)
call filter(self.items, 'v:val.word ==# a:word')
if empty(self.items)
return
execute 'cc ' . self.items[0].index
endif
call cursor(self.items[0].index, 0)
normal! zvzz
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
let tab = repeat(' ', getbufvar(self.bufNrPrev, '&tabstop'))
let self.items = getbufline(self.bufNrPrev, 1, '$')
let lnumFormat = '%' . len(string(len(self.items) + 1)) . 'd|'
for i in range(len(self.items))
let self.items[i] = printf(lnumFormat, i + 1)
\ . substitute(self.items[i], "\t", tab, 'g')
endfor
call map(self.items, 'fuf#makeNonPathItem(v:val, "")')
call fuf#mapToSetSerialIndex(self.items, 1)
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 0)')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,134 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#mrucmd#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#mrucmd#getSwitchOrder()
return g:fuf_mrucmd_switchOrder
endfunction
"
function fuf#mrucmd#getEditableDataNames()
return ['items']
endfunction
"
function fuf#mrucmd#renewCache()
endfunction
"
function fuf#mrucmd#requiresOnCommandPre()
return 1
endfunction
"
function fuf#mrucmd#onInit()
call fuf#defineLaunchCommand('FufMruCmd', s:MODE_NAME, '""', [])
endfunction
"
function fuf#mrucmd#onCommandPre(cmd)
if getcmdtype() =~# '^[:/?]'
call s:updateInfo(a:cmd)
endif
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:updateInfo(cmd)
let items = fuf#loadDataFile(s:MODE_NAME, 'items')
let items = fuf#updateMruList(
\ items, { 'word' : a:cmd, 'time' : localtime() },
\ g:fuf_mrucmd_maxItem, g:fuf_mrucmd_exclude)
call fuf#saveDataFile(s:MODE_NAME, 'items', items)
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_mrucmd_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return 0
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return []
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
call s:updateInfo(a:word)
call histadd(a:word[0], a:word[1:])
call feedkeys(a:word . "\<CR>", 'n')
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
let self.items = fuf#loadDataFile(s:MODE_NAME, 'items')
call map(self.items, 'fuf#makeNonPathItem(v:val.word, strftime(g:fuf_timeFormat, v:val.time))')
call fuf#mapToSetSerialIndex(self.items, 1)
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,234 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#mrufile#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#mrufile#getSwitchOrder()
return g:fuf_mrufile_switchOrder
endfunction
"
function fuf#mrufile#getEditableDataNames()
return ['items', 'itemdirs']
endfunction
"
function fuf#mrufile#renewCache()
let s:cache = {}
let s:aroundCache = {}
endfunction
"
function fuf#mrufile#requiresOnCommandPre()
return 0
endfunction
"
function fuf#mrufile#onInit()
call fuf#defineLaunchCommand('FufMruFile', s:MODE_NAME, '""', [])
call fuf#defineLaunchCommand('FufMruFileInCwd', s:MODE_NAME,
\ '""', [['g:fuf_mrufile_underCwd', 1]])
call l9#defineVariableDefault('g:fuf_mrufile_underCwd', 0) " private option
call l9#defineVariableDefault('g:fuf_mrufile_searchAroundLevel', -1) " private option
augroup fuf#mrufile
autocmd!
autocmd BufEnter * call s:updateData()
autocmd BufWritePost * call s:updateData()
augroup END
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
let s:OPEN_TYPE_EXPAND = -1
"
function s:updateData()
if !empty(&buftype) || !filereadable(expand('%'))
return
endif
let items = fuf#loadDataFile(s:MODE_NAME, 'items')
let items = fuf#updateMruList(
\ items, { 'word' : expand('%:p'), 'time' : localtime() },
\ g:fuf_mrufile_maxItem, g:fuf_mrufile_exclude)
call fuf#saveDataFile(s:MODE_NAME, 'items', items)
call s:removeItemFromCache(expand('%:p'))
let itemDirs = fuf#loadDataFile(s:MODE_NAME, 'itemdirs')
let itemDirs = fuf#updateMruList(
\ itemDirs, { 'word' : expand('%:p:h') },
\ g:fuf_mrufile_maxItemDir, g:fuf_mrufile_exclude)
call fuf#saveDataFile(s:MODE_NAME, 'itemdirs', itemDirs)
endfunction
"
function s:removeItemFromCache(word)
for items in values(s:cache)
if exists('items[a:word]')
unlet items[a:word]
endif
endfor
endfunction
" returns empty value if invalid item
function s:formatItemUsingCache(item)
if a:item.word !~ '\S'
return {}
endif
if !exists('s:cache[a:item.word]')
if filereadable(a:item.word)
let s:cache[a:item.word] = fuf#makePathItem(
\ fnamemodify(a:item.word, ':p:~'), strftime(g:fuf_timeFormat, a:item.time), 0)
else
let s:cache[a:item.word] = {}
endif
endif
return s:cache[a:item.word]
endfunction
"
function s:expandSearchDir(dir, level)
let dirs = [a:dir]
let dirPrev = a:dir
for i in range(a:level)
let dirPrev = l9#concatPaths([dirPrev, '*'])
call add(dirs, dirPrev)
endfor
let dirPrev = a:dir
for i in range(a:level)
let dirPrevPrev = dirPrev
let dirPrev = fnamemodify(dirPrev, ':h')
if dirPrevPrev ==# dirPrev
break
endif
call add(dirs, dirPrev)
endfor
return dirs
endfunction
"
function s:listAroundFiles(dir)
if !exists('s:aroundCache[a:dir]')
let s:aroundCache[a:dir] = [a:dir] +
\ fuf#glob(l9#concatPaths([a:dir, '*' ])) +
\ fuf#glob(l9#concatPaths([a:dir, '.*']))
call filter(s:aroundCache[a:dir], 'filereadable(v:val)')
call map(s:aroundCache[a:dir], 'fuf#makePathItem(fnamemodify(v:val, ":~"), "", 0)')
if len(g:fuf_mrufile_exclude)
call filter(s:aroundCache[a:dir], 'v:val.word !~ g:fuf_mrufile_exclude')
endif
endif
return s:aroundCache[a:dir]
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
let cwdString = (g:fuf_mrufile_underCwd ? '[CWD]' : '')
let levelString = (g:fuf_mrufile_searchAroundLevel < 0 ? ''
\ : '[Around:' . g:fuf_mrufile_searchAroundLevel . ']')
return fuf#formatPrompt(g:fuf_mrufile_prompt, self.partialMatching, cwdString . levelString)
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
if a:mode ==# s:OPEN_TYPE_EXPAND
let nextLevel = (self.searchAroundLevel < 0 ? 0 : self.searchAroundLevel + 1)
call fuf#setOneTimeVariables(['g:fuf_mrufile_searchAroundLevel', nextLevel])
let self.reservedMode = self.getModeName()
return
else
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
endif
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
let self.searchAroundLevel = g:fuf_mrufile_searchAroundLevel
call fuf#defineKeyMappingInHandler(g:fuf_mrufile_keyExpand,
\ 'onCr(' . s:OPEN_TYPE_EXPAND . ')')
if self.searchAroundLevel < 0
let self.items = fuf#loadDataFile(s:MODE_NAME, 'items')
call map(self.items, 's:formatItemUsingCache(v:val)')
else
let self.items = fuf#loadDataFile(s:MODE_NAME, 'itemdirs')
call map(self.items, 's:expandSearchDir(v:val.word, g:fuf_mrufile_searchAroundLevel)')
let self.items = l9#concat(self.items)
let self.items = l9#unique(self.items)
call map(self.items, 's:listAroundFiles(v:val)')
let self.items = l9#concat(self.items)
endif
" NOTE: Comparing filenames is faster than bufnr('^' . fname . '$')
let bufNamePrev = fnamemodify(bufname(self.bufNrPrev), ':p:~')
call filter(self.items, '!empty(v:val) && v:val.word !=# bufNamePrev')
if g:fuf_mrufile_underCwd
let cwd = fnamemodify(getcwd(), ':p:~')
call filter(self.items, 'stridx(v:val.word, cwd) == 0')
endif
call fuf#mapToSetSerialIndex(self.items, 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(self.items)
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,154 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#quickfix#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#quickfix#getSwitchOrder()
return g:fuf_quickfix_switchOrder
endfunction
"
function fuf#quickfix#getEditableDataNames()
return []
endfunction
"
function fuf#quickfix#renewCache()
endfunction
"
function fuf#quickfix#requiresOnCommandPre()
return 0
endfunction
"
function fuf#quickfix#onInit()
call fuf#defineLaunchCommand('FufQuickfix', s:MODE_NAME, '""', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:getJumpsLines()
redir => result
:silent jumps
redir END
return split(result, "\n")
endfunction
"
function s:parseJumpsLine(line)
return matchlist(a:line, '^\(.\)\s\+\(\d\+\)\s\(.*\)$')
endfunction
"
function s:makeItem(qfItem)
if !a:qfItem.valid
return {}
endif
let item = fuf#makeNonPathItem(
\ printf('%s|%d:%d|%s', bufname(a:qfItem.bufnr), a:qfItem.lnum,
\ a:qfItem.col, matchstr(a:qfItem.text, '\s*\zs.*\S'))
\ , '')
let item.bufnr = a:qfItem.bufnr
let item.lnum = a:qfItem.lnum
return item
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_quickfix_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
let items = filter(copy(self.items), 'v:val.word ==# a:word')
if empty(items)
return []
endif
let lines = fuf#getFileLines(items[0].bufnr)
return fuf#makePreviewLinesAround(
\ lines, [items[0].lnum - 1], a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#prejump(a:mode)
call filter(self.items, 'v:val.word ==# a:word')
if !empty(self.items)
execute 'cc ' . self.items[0].index
endif
endfunction
"
function s:handler.onModeEnterPre()
endfunction
"
function s:handler.onModeEnterPost()
let self.items = getqflist()
call map(self.items, 's:makeItem(v:val)')
call fuf#mapToSetSerialIndex(self.items, 1)
call filter(self.items, 'exists("v:val.word")')
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,178 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#tag#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#tag#getSwitchOrder()
return g:fuf_tag_switchOrder
endfunction
"
function fuf#tag#getEditableDataNames()
return []
endfunction
"
function fuf#tag#renewCache()
let s:cache = {}
endfunction
"
function fuf#tag#requiresOnCommandPre()
return 0
endfunction
"
function fuf#tag#onInit()
call fuf#defineLaunchCommand('FufTag' , s:MODE_NAME, '""', [])
call fuf#defineLaunchCommand('FufTagWithCursorWord', s:MODE_NAME, 'expand(''<cword>'')', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:getTagNames(tagFile)
let names = map(l9#readFile(a:tagFile), 'matchstr(v:val, ''^[^!\t][^\t]*'')')
return filter(names, 'v:val =~# ''\S''')
endfunction
"
function s:parseTagFiles(tagFiles, key)
let cacheName = 'cache-' . l9#hash224(a:key)
let cacheTime = fuf#getDataFileTime(s:MODE_NAME, cacheName)
if cacheTime != -1 && fuf#countModifiedFiles(a:tagFiles, cacheTime) == 0
return fuf#loadDataFile(s:MODE_NAME, cacheName)
endif
let items = l9#unique(l9#concat(map(copy(a:tagFiles), 's:getTagNames(v:val)')))
let items = map(items, 'fuf#makeNonPathItem(v:val, "")')
call fuf#mapToSetSerialIndex(items, 1)
let items = map(items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
call fuf#saveDataFile(s:MODE_NAME, cacheName, items)
return items
endfunction
"
function s:enumTags(tagFiles)
if !len(a:tagFiles)
return []
endif
let key = join([g:fuf_ignoreCase] + a:tagFiles, "\n")
if !exists('s:cache[key]') || fuf#countModifiedFiles(a:tagFiles, s:cache[key].time)
let s:cache[key] = {
\ 'time' : localtime(),
\ 'items' : s:parseTagFiles(a:tagFiles, key)
\ }
endif
return s:cache[key].items
endfunction
"
function s:getMatchingIndex(lines, cmd)
if a:cmd !~# '\D'
return str2nr(a:cmd)
endif
let pattern = matchstr(a:cmd, '^\/\^\zs.*\ze\$\/$')
if empty(pattern)
return -1
endif
for i in range(len(a:lines))
if a:lines[i] ==# pattern
return i
endif
endfor
return -1
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_tag_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
\ self.partialMatching)
endfunction
" 'cmd' is '/^hoge hoge$/' or line number
function s:handler.makePreviewLines(word, count)
let tags = taglist('^' . a:word . '$')
if empty(tags)
return []
endif
let i = a:count % len(tags)
let title = printf('(%d/%d) %s', i + 1, len(tags), tags[i].filename)
let lines = fuf#getFileLines(tags[i].filename)
let index = s:getMatchingIndex(lines, tags[i].cmd)
return [title] + fuf#makePreviewLinesAround(
\ lines, (index < 0 ? [] : [index]), 0, self.getPreviewHeight() - 1)
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return s:enumTags(self.tagFiles)
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#openTag(a:word, a:mode)
endfunction
"
function s:handler.onModeEnterPre()
let self.tagFiles = fuf#getCurrentTagFiles()
endfunction
"
function s:handler.onModeEnterPost()
let &l:tags = join(self.tagFiles, ',')
endfunction
"
function s:handler.onModeLeavePost(opened)
let &l:tags = ''
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

View File

@@ -0,0 +1,159 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
"=============================================================================
" LOAD GUARD {{{1
if !l9#guardScriptLoading(expand('<sfile>:p'), 0, 0, [])
finish
endif
" }}}1
"=============================================================================
" GLOBAL FUNCTIONS {{{1
"
function fuf#taggedfile#createHandler(base)
return a:base.concretize(copy(s:handler))
endfunction
"
function fuf#taggedfile#getSwitchOrder()
return g:fuf_taggedfile_switchOrder
endfunction
"
function fuf#taggedfile#getEditableDataNames()
return []
endfunction
"
function fuf#taggedfile#renewCache()
let s:cache = {}
endfunction
"
function fuf#taggedfile#requiresOnCommandPre()
return 0
endfunction
"
function fuf#taggedfile#onInit()
call fuf#defineLaunchCommand('FufTaggedFile', s:MODE_NAME, '""', [])
endfunction
" }}}1
"=============================================================================
" LOCAL FUNCTIONS/VARIABLES {{{1
let s:MODE_NAME = expand('<sfile>:t:r')
"
function s:getTaggedFileList(tagfile)
execute 'cd ' . fnamemodify(a:tagfile, ':h')
let result = map(l9#readFile(a:tagfile), 'matchstr(v:val, ''^[^!\t][^\t]*\t\zs[^\t]\+'')')
call map(l9#readFile(a:tagfile), 'fnamemodify(v:val, ":p")')
cd -
call map(l9#readFile(a:tagfile), 'fnamemodify(v:val, ":~:.")')
return filter(result, 'v:val =~# ''[^/\\ ]$''')
endfunction
"
function s:parseTagFiles(tagFiles, key)
let cacheName = 'cache-' . l9#hash224(a:key)
let cacheTime = fuf#getDataFileTime(s:MODE_NAME, cacheName)
if cacheTime != -1 && fuf#countModifiedFiles(a:tagFiles, cacheTime) == 0
return fuf#loadDataFile(s:MODE_NAME, cacheName)
endif
let items = l9#unique(l9#concat(map(copy(a:tagFiles), 's:getTaggedFileList(v:val)')))
call map(items, 'fuf#makePathItem(v:val, "", 0)')
call fuf#mapToSetSerialIndex(items, 1)
call fuf#mapToSetAbbrWithSnippedWordAsPath(items)
call fuf#saveDataFile(s:MODE_NAME, cacheName, items)
return items
endfunction
"
function s:enumTaggedFiles(tagFiles)
if !len(a:tagFiles)
return []
endif
let key = join([getcwd(), g:fuf_ignoreCase] + a:tagFiles, "\n")
if !exists('s:cache[key]') || fuf#countModifiedFiles(a:tagFiles, s:cache[key].time)
let s:cache[key] = {
\ 'time' : localtime(),
\ 'items' : s:parseTagFiles(a:tagFiles, key)
\ }
endif
return s:cache[key].items
endfunction
" }}}1
"=============================================================================
" s:handler {{{1
let s:handler = {}
"
function s:handler.getModeName()
return s:MODE_NAME
endfunction
"
function s:handler.getPrompt()
return fuf#formatPrompt(g:fuf_taggedfile_prompt, self.partialMatching, '')
endfunction
"
function s:handler.getPreviewHeight()
return g:fuf_previewHeight
endfunction
"
function s:handler.isOpenable(enteredPattern)
return 1
endfunction
"
function s:handler.makePatternSet(patternBase)
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
\ self.partialMatching)
endfunction
"
function s:handler.makePreviewLines(word, count)
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
endfunction
"
function s:handler.getCompleteItems(patternPrimary)
return self.items
endfunction
"
function s:handler.onOpen(word, mode)
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
endfunction
"
function s:handler.onModeEnterPre()
let self.tagFiles = fuf#getCurrentTagFiles()
endfunction
"
function s:handler.onModeEnterPost()
" NOTE: Comparing filenames is faster than bufnr('^' . fname . '$')
let bufNamePrev = fnamemodify(bufname(self.bufNrPrev), ':p:~:.')
" NOTE: Don't do this in onModeEnterPre()
" because that should return in a short time.
let self.items = copy(s:enumTaggedFiles(self.tagFiles))
call filter(self.items, 'v:val.word !=# bufNamePrev')
endfunction
"
function s:handler.onModeLeavePost(opened)
endfunction
" }}}1
"=============================================================================
" vim: set fdm=marker:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,158 @@
"=============================================================================
" Copyright (c) 2007-2010 Takeshi NISHIDA
"
" GetLatestVimScripts: 1984 1 :AutoInstall: FuzzyFinder
"=============================================================================
" LOAD GUARD {{{1
try
if !l9#guardScriptLoading(expand('<sfile>:p'), 702, 101, [])
finish
endif
catch /E117/
echoerr '***** L9 library must be installed! *****'
finish
endtry
" }}}1
"=============================================================================
" LOCAL FUNCTIONS {{{1
"
function s:initialize()
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_modesDisable' , [ 'mrufile', 'mrucmd', ])
call l9#defineVariableDefault('g:fuf_keyOpen' , '<CR>')
call l9#defineVariableDefault('g:fuf_keyOpenSplit' , '<C-j>')
call l9#defineVariableDefault('g:fuf_keyOpenVsplit' , '<C-k>')
call l9#defineVariableDefault('g:fuf_keyOpenTabpage' , '<C-l>')
call l9#defineVariableDefault('g:fuf_keyPreview' , '<C-@>')
call l9#defineVariableDefault('g:fuf_keyNextMode' , '<C-t>')
call l9#defineVariableDefault('g:fuf_keyPrevMode' , '<C-y>')
call l9#defineVariableDefault('g:fuf_keyPrevPattern' , '<C-s>')
call l9#defineVariableDefault('g:fuf_keyNextPattern' , '<C-_>')
call l9#defineVariableDefault('g:fuf_keySwitchMatching', '<C-\><C-\>')
call l9#defineVariableDefault('g:fuf_dataDir' , '~/.vim-fuf-data')
call l9#defineVariableDefault('g:fuf_abbrevMap' , {})
call l9#defineVariableDefault('g:fuf_patternSeparator' , ';')
call l9#defineVariableDefault('g:fuf_promptHighlight' , 'Question')
call l9#defineVariableDefault('g:fuf_ignoreCase' , 1)
call l9#defineVariableDefault('g:fuf_splitPathMatching', 1)
call l9#defineVariableDefault('g:fuf_fuzzyRefining' , 0)
call l9#defineVariableDefault('g:fuf_smartBs' , 1)
call l9#defineVariableDefault('g:fuf_reuseWindow' , 1)
call l9#defineVariableDefault('g:fuf_timeFormat' , '(%Y-%m-%d %H:%M:%S)')
call l9#defineVariableDefault('g:fuf_learningLimit' , 100)
call l9#defineVariableDefault('g:fuf_enumeratingLimit' , 50)
call l9#defineVariableDefault('g:fuf_maxMenuWidth' , 78)
call l9#defineVariableDefault('g:fuf_previewHeight' , 0)
call l9#defineVariableDefault('g:fuf_autoPreview' , 0)
call l9#defineVariableDefault('g:fuf_useMigemo' , 0)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_buffer_prompt' , '>Buffer[]>')
call l9#defineVariableDefault('g:fuf_buffer_switchOrder', 10)
call l9#defineVariableDefault('g:fuf_buffer_mruOrder' , 1)
call l9#defineVariableDefault('g:fuf_buffer_keyDelete' , '<C-]>')
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_file_prompt' , '>File[]>')
call l9#defineVariableDefault('g:fuf_file_switchOrder', 20)
call l9#defineVariableDefault('g:fuf_file_exclude' , '\v\~$|\.(o|exe|dll|bak|orig|sw[po])$|(^|[/\\])\.(hg|git|bzr)($|[/\\])')
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_coveragefile_prompt' , '>CoverageFile[]>')
call l9#defineVariableDefault('g:fuf_coveragefile_switchOrder', 30)
call l9#defineVariableDefault('g:fuf_coveragefile_exclude' , '\v\~$|\.(o|exe|dll|bak|orig|sw[po])$|(^|[/\\])\.(hg|git|bzr)($|[/\\])')
call l9#defineVariableDefault('g:fuf_coveragefile_globPatterns', ['**/.*', '**/*'])
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_dir_prompt' , '>Dir[]>')
call l9#defineVariableDefault('g:fuf_dir_switchOrder', 40)
call l9#defineVariableDefault('g:fuf_dir_exclude' , '\v(^|[/\\])\.(hg|git|bzr)($|[/\\])')
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_mrufile_prompt' , '>MRU-File[]>')
call l9#defineVariableDefault('g:fuf_mrufile_switchOrder', 50)
call l9#defineVariableDefault('g:fuf_mrufile_exclude' , '\v\~$|\.(o|exe|dll|bak|orig|sw[po])$|^(\/\/|\\\\|\/mnt\/|\/media\/)')
call l9#defineVariableDefault('g:fuf_mrufile_maxItem' , 200)
call l9#defineVariableDefault('g:fuf_mrufile_maxItemDir' , 50)
call l9#defineVariableDefault('g:fuf_mrufile_keyExpand' , '<C-]>')
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_mrucmd_prompt' , '>MRU-Cmd[]>')
call l9#defineVariableDefault('g:fuf_mrucmd_switchOrder', 60)
call l9#defineVariableDefault('g:fuf_mrucmd_exclude' , '^$')
call l9#defineVariableDefault('g:fuf_mrucmd_maxItem' , 200)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_bookmarkfile_prompt' , '>Bookmark-File[]>')
call l9#defineVariableDefault('g:fuf_bookmarkfile_switchOrder', 70)
call l9#defineVariableDefault('g:fuf_bookmarkfile_searchRange', 400)
call l9#defineVariableDefault('g:fuf_bookmarkfile_keyDelete' , '<C-]>')
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_bookmarkdir_prompt' , '>Bookmark-Dir[]>')
call l9#defineVariableDefault('g:fuf_bookmarkdir_switchOrder', 80)
call l9#defineVariableDefault('g:fuf_bookmarkdir_keyDelete' , '<C-]>')
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_tag_prompt' , '>Tag[]>')
call l9#defineVariableDefault('g:fuf_tag_switchOrder', 90)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_buffertag_prompt' , '>Buffer-Tag[]>')
call l9#defineVariableDefault('g:fuf_buffertag_switchOrder', 100)
call l9#defineVariableDefault('g:fuf_buffertag_ctagsPath' , 'ctags')
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_taggedfile_prompt' , '>Tagged-File[]>')
call l9#defineVariableDefault('g:fuf_taggedfile_switchOrder', 110)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_jumplist_prompt' , '>Jump-List[]>')
call l9#defineVariableDefault('g:fuf_jumplist_switchOrder', 120)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_changelist_prompt' , '>Change-List[]>')
call l9#defineVariableDefault('g:fuf_changelist_switchOrder', 130)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_quickfix_prompt' , '>Quickfix[]>')
call l9#defineVariableDefault('g:fuf_quickfix_switchOrder', 140)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_line_prompt' , '>Line[]>')
call l9#defineVariableDefault('g:fuf_line_switchOrder', 150)
"---------------------------------------------------------------------------
call l9#defineVariableDefault('g:fuf_help_prompt' , '>Help[]>')
call l9#defineVariableDefault('g:fuf_help_switchOrder', 160)
"---------------------------------------------------------------------------
command! -bang -narg=0 FufEditDataFile call fuf#editDataFile()
command! -bang -narg=0 FufRenewCache call s:renewCachesOfAllModes()
"---------------------------------------------------------------------------
call fuf#addMode('buffer')
call fuf#addMode('file')
call fuf#addMode('coveragefile')
call fuf#addMode('dir')
call fuf#addMode('mrufile')
call fuf#addMode('mrucmd')
call fuf#addMode('bookmarkfile')
call fuf#addMode('bookmarkdir')
call fuf#addMode('tag')
call fuf#addMode('buffertag')
call fuf#addMode('taggedfile')
call fuf#addMode('jumplist')
call fuf#addMode('changelist')
call fuf#addMode('quickfix')
call fuf#addMode('line')
call fuf#addMode('help')
call fuf#addMode('givenfile')
call fuf#addMode('givendir')
call fuf#addMode('givencmd')
call fuf#addMode('callbackfile')
call fuf#addMode('callbackitem')
"---------------------------------------------------------------------------
endfunction
"
function s:renewCachesOfAllModes()
for m in fuf#getModeNames()
call fuf#{m}#renewCache()
endfor
endfunction
" }}}1
"=============================================================================
" INITIALIZATION {{{1
call s:initialize()
" }}}1
"=============================================================================
" vim: set fdm=marker:

5
bundle/git_taglisttoo/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
*.pyc
*.swp
*.vba
tags
/build

View File

@@ -0,0 +1,11 @@
SHELL=/bin/bash
all: dist
dist:
@rm taglisttoo.vba 2> /dev/null || true
@vim -c 'r! git ls-files autoload doc plugin' \
-c '$$,$$d _' -c '%MkVimball taglisttoo.vba .' -c 'q!'
clean:
@rm -R build 2> /dev/null || true

View File

@@ -0,0 +1,50 @@
.. Copyright (c) 2005 - 2010, Eric Van Dewoestine
All rights reserved.
Redistribution and use of this software in source and binary forms, with
or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* 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.
* Neither the name of Eric Van Dewoestine nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission of
Eric Van Dewoestine.
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 OWNER 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.
TaglistToo is a vim plugin which provides an outline, or taglist, of a source
file in a separate window allowing you to quickly get an overview of the file
you are working on and to quickly jump to class definitions, methods,
functions, etc.
TaglistToo is very similar to the very popular taglist.vim_ written by Yegappan
Lakshmanan, but with a focus on being extensible and customizable. TaglistToo
provides hooks allowing you to format the taglist content per file type and to
also write code to parse file types not supported well or at all by ctags.
Please note that TaglistToo requires that vim be compiled with python support
and that you have `exuberant ctags`_ installed.
Please see the vim help file for full documentation.
.. _exuberant ctags: http://ctags.sourceforge.net/
.. _taglist.vim: http://www.vim.org/scripts/script.php?script_id=273

View File

@@ -0,0 +1,241 @@
"""
Copyright (c) 2005 - 2012, Eric Van Dewoestine
All rights reserved.
Redistribution and use of this software in source and binary forms, with
or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* 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.
* Neither the name of Eric Van Dewoestine nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission of
Eric Van Dewoestine.
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 OWNER 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.
"""
import os
import re
import subprocess
import tempfile
import vim
def ctags(lang, types, filename):
ctags = vim.eval('g:Tlist_Ctags_Cmd')
debug = vim.eval('g:Tlist_Debug') != '0'
startupinfo = None
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
if hasattr(subprocess, '_subprocess'):
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
else:
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
stdoutfile = tempfile.TemporaryFile()
stderrfile = tempfile.TemporaryFile()
try:
args = [
ctags,
'-f', '-',
'--format=2',
'--excmd=pattern',
'--extra=',
'--fields=kns',
'--fields=-afiKlmSzt',
'--sort=no',
'--language-force=%s' % lang,
'--%s-types=%s' % (lang, types),
filename,
]
if debug:
print ' '.join(args)
process = subprocess.Popen(
args,
stdout=stdoutfile,
stderr=stderrfile,
stdin=subprocess.PIPE,
startupinfo=startupinfo,
)
retcode = process.wait()
if retcode != 0:
stderrfile.seek(0)
return (retcode, stderrfile.read())
stdoutfile.seek(0)
return (retcode, stdoutfile.read())
finally:
stdoutfile.close()
stderrfile.close()
def jsctags(filename):
jsctags = vim.eval('g:Tlist_JSctags_Cmd')
debug = vim.eval('g:Tlist_Debug') != '0'
startupinfo = None
if os.name == 'nt':
startupinfo = subprocess.STARTUPINFO()
if hasattr(subprocess, '_subprocess'):
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
else:
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
temp = tempfile.mkstemp()[1]
try:
args = [jsctags, '-o', temp, filename]
if debug:
print ' '.join(args)
process = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
startupinfo=startupinfo,
)
retcode = process.wait()
if retcode != 0:
return (retcode, process.communicate()[1].strip())
return (retcode, open(temp).read())
finally:
os.unlink(temp)
def parse(filename, settings, patterns):
types = settings['tags']
f = open(filename, 'r')
contents = f.read()
f.close()
for i, info in enumerate(patterns):
flags = re.DOTALL | re.MULTILINE
if len(info) > 3:
if info[3] == 'i':
flags |= re.IGNORECASE
info = info[:3]
patterns[i] = info
try:
info[1] = re.compile(info[1], flags)
except:
print 'Failed to parse pattern: %s' % info[1]
raise
offsets = FileOffsets.compile(filename)
results = []
for ptype, regex, group in patterns:
for match in regex.finditer(contents):
start = match.start()
end = match.end()
line = offsets.offsetToLineColumn(start)[0]
col = 1
if group.isdigit():
name = match.group(int(group))
else:
matched = contents[start:end]
name = regex.sub(group, matched)
first = offsets.getLineStart(line)
last = offsets.getLineEnd(offsets.offsetToLineColumn(end)[0])
pattern = contents[first:last]
# pattern cannot span lines
if '\n' in pattern:
lines = pattern.split('\n')
for i, l in enumerate(lines):
if name in l:
pattern = l
line += i
col = l.index(name) + 1
break
# still multiline, so just use the first one
if '\n' in pattern:
pattern = lines[0]
elif name in pattern:
col = pattern.index(name) + 1
# remove ctrl-Ms
pattern = pattern.replace('\r', '')
results.append({
'type': ptype,
'type_name': types.get(ptype, ptype),
'name': name,
'pattern': '^%s$' % pattern,
'line': line,
'column': col,
})
return results
class FileOffsets(object):
def __init__(self):
self.offsets = []
@staticmethod
def compile(filename):
offsets = FileOffsets()
offsets.compileOffsets(filename)
return offsets;
def compileOffsets(self, filename):
f = file(filename, 'r')
try:
self.offsets.append(0);
offset = 0;
for line in f:
offset += len(line)
self.offsets.append(offset)
finally:
f.close()
def offsetToLineColumn(self, offset):
if offset <= 0:
return [1, 1]
bot = -1
top = len(self.offsets) - 1
while (top - bot) > 1:
mid = (top + bot) / 2
if self.offsets[mid] < offset:
bot = mid
else:
top = mid
if self.offsets[top] > offset:
top -= 1
line = top + 1
column = 1 + offset - self.offsets[top]
return [line, column]
def getLineStart(self, line):
return self.offsets[line - 1]
def getLineEnd(self, line):
if len(self.offsets) == line:
return self.offsets[len(self.offsets) - 1]
return self.offsets[line] - 1;

View File

@@ -0,0 +1,48 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2005 - 2011, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Parse(file, settings) {{{
function! taglisttoo#lang#ant#Parse(file, settings)
return taglisttoo#util#Parse(a:file, a:settings, [
\ ['p', "<project\\s+(?:[^>]*)name\\s*=\\s*['\"](.*?)['\"]", 1],
\ ['i', "<import\\s+(?:[^>]*)file\\s*=\\s*['\"](.*?)['\"]", 1],
\ ['t', "<target\\s+(?:[^>]*)name\\s*=\\s*['\"](.*?)['\"]", 1],
\ ['r', "<property\\s+(?:[^>]*)name\\s*=\\s*['\"](.*?)['\"]", 1],
\ ])
endfunction " }}}
" vim:ft=vim:fdm=marker

View File

@@ -0,0 +1,118 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2011 - 2012, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Parse(file, settings) {{{
function! taglisttoo#lang#cpp#Parse(file, settings)
let tags = taglisttoo#util#ParseCtags(a:file, a:settings)
let types = {}
for [t, n] in items(a:settings.tags)
let types[n] = t
endfor
let parents = []
let seen = []
let index = 0
for tag in tags
if tag.parent != '' && index(seen, tag.parent) == -1
call add(seen, tag.parent)
let type_name = substitute(tag.parent, '^\(.\{-}\):.*', '\1', '')
if !has_key(types, type_name)
continue
endif
let type = types[type_name]
let name = substitute(tag.parent, '^.\{-}:\(.*\)', '\1', '')
let parts = split(name, '::')
let name = parts[-1]
let parent_name = ''
let parent_filter = 'v:val.name == name'
" single level nesting, so we can use the type to see if parent exists
if len(parts) == 1
let parent_filter .= ' && v:val.type == type'
" multi level nesting, so rely we can't use the type
else
let parent_name = join(parts[:-2], '::')
let parent_filter .= ' && v:val.parent =~ "^.\\{-}:" . parent_name . "$"'
endif
" check if the parent already exists
let exists = filter(copy(tags), parent_filter)
if len(exists) == 0
let parent = {}
let parent_path = ''
" the parent we are injecting has a parent, so construct its parent
" path
if parent_name != ''
let parent_list = filter(copy(tags), 'v:val.name == parent_name')
if len(parent_list) == 1
let parent = parent_list[0]
let parent_parent = substitute(parent.parent, '^.\{-}:\(.*\)', '\1', '')
if parent_parent != ''
let parent_parent .= '::'
endif
let parent_type = a:settings.tags[parent.type]
let parent_path = parent_type . ':' . parent_parent . parent.name
endif
endif
" injected parent before the first child occurance, taking into
" account any previously injected parents
let insert_index = len(parents) + index
call add(parents, [insert_index, {
\ 'name': name,
\ 'line': -1,
\ 'type': type,
\ 'type_name': type_name,
\ 'pattern': '',
\ 'parent': parent_path
\ }])
endif
endif
let index += 1
endfor
for [idx, parent] in parents
call insert(tags, parent, idx)
endfor
return tags
endfunction " }}}
" vim:ft=vim:fdm=marker

View File

@@ -0,0 +1,45 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2005 - 2011, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Parse(file, settings) {{{
function! taglisttoo#lang#dtd#Parse(file, settings)
return taglisttoo#util#Parse(a:file, a:settings, [
\ ['e', '^\s*<!ELEMENT\s+(.*?)(\s|\s*$)', 1],
\ ])
endfunction " }}}
" vim:ft=vim:fdm=marker

View File

@@ -0,0 +1,46 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2005 - 2011, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Parse(file, settings) {{{
function! taglisttoo#lang#html#Parse(file, settings)
return taglisttoo#util#Parse(a:file, a:settings, [
\ ['a', "<a\\s+[^>]*?name=['\"](.*?)['\"]", 1],
\ ['i', "<([a-z]*?)\\s+[^>]*?id=['\"](.*?)['\"]", '\1 \2'],
\ ])
endfunction " }}}
" vim:ft=vim:fdm=marker

View File

@@ -0,0 +1,47 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2005 - 2011, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Parse(file, settings) {{{
function! taglisttoo#lang#htmldjango#Parse(file, settings)
return taglisttoo#util#Parse(a:file, a:settings, [
\ ['a', "<a\\s+[^>]*?name=['\"](.*?)['\"]", 1],
\ ['i', "<([a-z]*?)\\s+[^>]*?id=['\"](.*?)['\"]", '\1 \2'],
\ ['b', '\{%?\s*block\s+(\w+)', 1],
\ ])
endfunction " }}}
" vim:ft=vim:fdm=marker

View File

@@ -0,0 +1,52 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2005 - 2012, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Parse(file, settings) {{{
function! taglisttoo#lang#htmljinja#Parse(file, settings)
let prefix = '{%-?'
if exists('b:jinja_line_statement_prefix')
let prefix = '(?:' . prefix . '|' . b:jinja_line_statement_prefix . ')'
endif
return taglisttoo#util#Parse(a:file, a:settings, [
\ ['a', "<a\\s+[^>]*?name=['\"](.*?)['\"]", 1],
\ ['i', "<([a-z]*?)\\s+[^>]*?id=['\"](.*?)['\"]", '\1 \2'],
\ ['b', prefix . '\s*block\s+(\w+)', 1],
\ ['m', prefix . '\s*macro\s+(\w+)\s*\(', 1],
\ ])
endfunction " }}}
" vim:ft=vim:fdm=marker

View File

@@ -0,0 +1,153 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2005 - 2011, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Global Variabls {{{
if !exists('g:TaglistTooJSctags')
let g:TaglistTooJSctags = 1
endif
" }}}
function! taglisttoo#lang#javascript#Parse(file, settings) " {{{
if g:TaglistTooJSctags && !exists('g:Tlist_JSctags_Cmd')
if executable('jsctags')
let g:Tlist_JSctags_Cmd = 'jsctags'
elseif executable('javascripttags')
let g:Tlist_JSctags_Cmd = 'javascripttags'
endif
endif
if !g:TaglistTooJSctags || !exists('g:Tlist_JSctags_Cmd')
return s:ParseRegex(a:file, a:settings)
endif
return s:ParseJSctags(a:file, a:settings)
endfunction " }}}
function! s:ParseJSctags(file, settings) " {{{
python << PYTHONEOF
retcode, result = taglisttoo.jsctags(vim.eval('a:file'))
vim.command('let retcode = %i' % retcode)
vim.command("let result = '%s'" % result.replace("'", "''"))
PYTHONEOF
if retcode
call taglisttoo#util#EchoError('jsctags failed with error code: ' . retcode)
return
endif
if has('win32') || has('win64') || has('win32unix')
let result = substitute(result, "\<c-m>\n", '\n', 'g')
endif
let results = split(result, '\n')
while len(results) && results[0] =~ '^!_'
call remove(results, 0)
endwhile
let types = keys(a:settings.tags)
let parsed_results = []
for result in results
" some results use <lnum>G;" (e.g. 1956G;") as the pattern... skip those
" for now since taglist expects actual patterns.
if result !~ '\t\/\^'
continue
endif
let pre = substitute(result, '\(.\{-}\)\t\/\^.*', '\1', '')
let pattern = substitute(result, '.\{-}\(\/\^.*\/;"\).*', '\1', '')
let post = substitute(result, '.\{-}\/\^.*\/;"\t', '', '')
let [name, filename] = split(pre, '\t')
let parts = split(post, '\t')
let [type, line_str] = parts[:1]
exec 'let line = ' . substitute(line_str, 'lineno:', '', '')
let pattern = substitute(pattern, '^/\(.*\)/;"$', '\1', '')
let jstypes = filter(copy(parts), 'v:val =~ "^type:"')
let namespaces = filter(copy(parts), 'v:val =~ "^namespace:"')
let jstype = len(jstypes) ? substitute(jstypes[0], '^type:', '', '') : ''
let ns = len(namespaces) ? substitute(namespaces[0], '^namespace:', '', '') : ''
call add(parsed_results, {
\ 'type': type,
\ 'name': name,
\ 'pattern': pattern,
\ 'line': line,
\ 'namespace': ns,
\ 'jstype': jstype,
\ })
endfor
return parsed_results
endfunction " }}}
function! s:ParseRegex(file, settings) " {{{
let patterns = []
" Match Objects/Classes
call add(patterns, ['o', '([A-Za-z0-9_.]+)\s*=\s*\{(\s*[^}]|$)', 1])
" prototype.js has Object.extend to extend existing objects.
call add(patterns, ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*Object\.extend\s*\(', 1])
call add(patterns, ['o', '\bObject\.extend\s*\(\b([A-Z][A-Za-z0-9_.]+)\s*,\s*\{', 1])
" mootools uses 'new Class'
call add(patterns, ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*new\s+Class\s*\(', 1])
" firebug uses extend
call add(patterns, ['o', '(?:var\s+)?\b([A-Z][A-Za-z0-9_.]+)\s*=\s*extend\s*\(', 1])
" vimperator uses function MyClass ()
call add(patterns, ['o', 'function\s+\b([A-Z][A-Za-z0-9_.]+)\s*\(', 1])
" vimperator uses var = (function()
call add(patterns, ['o', '([A-Za-z0-9_.]+)\s*=\s*\(function\s*\(', 1])
" Match Functions
call add(patterns, ['f', '\bfunction\s+([a-zA-Z0-9_.\$]+?)\s*\(', 1])
call add(patterns, ['f', '([a-zA-Z0-9_.\$]+?)\s*=\s*function\s*\(', 1])
call add(patterns, ['f', "\\[[\"']([A-Za-z0-9_]+)[\"']\\]\\s*=\\s*function\\s*\\(", 1])
" Match Members
call add(patterns, ['f', '\b([a-zA-Z0-9_.\$]+?)\s*:\s*function\s*\(', 1])
let tags = taglisttoo#util#Parse(a:file, a:settings, patterns)
call taglisttoo#util#SetNestedParents(
\ a:settings.tags, tags, ['o', 'f', 'm'], '{', '}')
return tags
endfunction " }}}
" vim:ft=vim:fdm=marker

View File

@@ -0,0 +1,43 @@
" Author: Eric Van Dewoestine
"
" License: {{{
" Copyright (c) 2005 - 2011, Eric Van Dewoestine
" All rights reserved.
"
" Redistribution and use of this software in source and binary forms, with
" or without modification, are permitted provided that the following
" conditions are met:
"
" * Redistributions of source code must retain the above
" copyright notice, this list of conditions and the
" following disclaimer.
"
" * 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.
"
" * Neither the name of Eric Van Dewoestine nor the names of its
" contributors may be used to endorse or promote products derived from
" this software without specific prior written permission of
" Eric Van Dewoestine.
"
" 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 OWNER 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.
" }}}
" Parse(file, settings) {{{
function! taglisttoo#lang#jproperties#Parse(file, settings)
return taglisttoo#util#Parse(a:file, a:settings, [['p', '^\s*([^#]+?)\s*=', 1]])
endfunction " }}}
" vim:ft=vim:fdm=marker

Some files were not shown because too many files have changed in this diff Show More