├── .gitignore ├── README.mkd ├── autoload └── unite │ ├── filters │ ├── outline_formatter.vim │ └── outline_matcher_glob.vim │ └── sources │ ├── outline.vim │ └── outline │ ├── defaults │ ├── arduino.vim │ ├── asciidoc.vim │ ├── changelog.vim │ ├── coffee.vim │ ├── conf.vim │ ├── cpp.vim │ ├── cs.vim │ ├── css.vim │ ├── dosini.vim │ ├── elm.vim │ ├── go.vim │ ├── godoc.vim │ ├── haskell.vim │ ├── hatena.vim │ ├── help.vim │ ├── html.vim │ ├── java.vim │ ├── javascript.vim │ ├── lisp.vim │ ├── lua.vim │ ├── magma.vim │ ├── man.vim │ ├── markdown.vim │ ├── perl.vim │ ├── php.vim │ ├── pir.vim │ ├── pony.vim │ ├── pug.vim │ ├── python.vim │ ├── review.vim │ ├── rst.vim │ ├── ruby.vim │ ├── ruby │ │ └── rspec.vim │ ├── rust.vim │ ├── sass.vim │ ├── scala.vim │ ├── scheme.vim │ ├── scss.vim │ ├── sh.vim │ ├── swift.vim │ ├── tex.vim │ ├── textile.vim │ ├── typescript.vim │ ├── unittest.vim │ └── vim.vim │ ├── misc │ └── wzmemo_text.vim │ ├── modules │ ├── base.vim │ ├── ctags.vim │ ├── file_cache.vim │ ├── tree.vim │ └── util.vim │ └── util.vim └── doc ├── .gitignore ├── unite-outline.jax └── unite-outline.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /README.mkd: -------------------------------------------------------------------------------- 1 | # unite-outline 2 | 3 | Note: I am Shougo(unite plugin author). This plugin created by h1mesuke 4 | originally. He is great VimL programmer. But he has not maintained this 5 | plugin in several years. And I cannot contact with him. So I have maintained 6 | it instead. To add features to this plugin is hard. I cannot extend it. Pull 7 | requests are well come. 8 | 9 | ## Introduction 10 | 11 | unite-outline is a [unite.vim](https://github.com/Shougo/unite.vim)'s source 12 | which provides your Vim's buffer with the outline view. It parses the current 13 | buffer's content and extracts headings from the buffer. And then it shows the 14 | list of the headings using unite.vim's interface. When you select a heading 15 | from the list, you can jump to the corresponding location in the buffer. 16 | 17 | The methods for extracting headings can be implemented for each individual 18 | filetypes. You can customize them as you like with Vim script and can also 19 | create new ones for unsupported filetypes. 20 | 21 | ## Install 22 | 23 | Install the distributed files into your Vim script directory which is usually 24 | $HOME/.vim, or $HOME/vimfiles on Windows. 25 | 26 | You can show the heading list of the current buffer with ":Unite outline" 27 | command if you succeeded the installation (and unite-outline supports the 28 | filetype of the buffer). 29 | 30 | ### C, C++, Java, etc 31 | 32 | * Exuberant Ctags (Required) 33 | http://ctags.sourceforge.net/ 34 | 35 | ## Usage 36 | 37 | To show the heading list of the current buffer, execute |:Unite| command with 38 | "outline" as a source parameter. 39 | 40 | :Unite outline 41 | 42 | unite-outline parses the current buffer's content and extracts headings from 43 | the buffer. And then it shows the list of the headings with unite.vim's 44 | interface. When you select a heading from the list, you can jump to the 45 | corresponding location of the buffer. 46 | 47 | See :help unite-outline for more details. 48 | 49 | ## Extending 50 | 51 | The easiest way to extend this plugin is if your language is supported by 52 | ctags. If this is the case, add an entry to the lang_info dictionary in: 53 | 54 | ./autoload/unite/sources/outline/modules/ctags.vim 55 | 56 | The --ctags-options field in the dictionary gets passed to ctags and specifies 57 | the things ctags will report, the other fields control how unite-outline 58 | organizines the items that ctags returns. 59 | 60 | Finally, add an outline_info dictionary in a file named after your filetype: 61 | 62 | ./autoload/unite/sources/outline/defaults/{FILETYPE}.vim 63 | 64 | See the other filetypes already in autoload/unite/sources/outline/defaults 65 | for examples of what those files look like. Good luck! 66 | 67 | ## Screenshots 68 | 69 | See [unite-outline's wiki](https://github.com/h1mesuke/unite-outline/wiki). 70 | 71 | -------------------------------------------------------------------------------- /autoload/unite/filters/outline_formatter.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/filters/outline_formatter.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " Version : 0.5.1 6 | " License : MIT license {{{ 7 | " 8 | " Permission is hereby granted, free of charge, to any person obtaining 9 | " a copy of this software and associated documentation files (the 10 | " "Software"), to deal in the Software without restriction, including 11 | " without limitation the rights to use, copy, modify, merge, publish, 12 | " distribute, sublicense, and/or sell copies of the Software, and to 13 | " permit persons to whom the Software is furnished to do so, subject to 14 | " the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included 17 | " in all copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | " }}} 27 | "============================================================================= 28 | 29 | let s:save_cpo = &cpo 30 | set cpo&vim 31 | 32 | function! unite#filters#outline_formatter#define() abort 33 | return s:formatter 34 | endfunction 35 | 36 | let s:Util = unite#sources#outline#import('Util') 37 | 38 | let s:BLANK = { 39 | \ 'word': '', 40 | \ 'source': 'outline', 41 | \ 'kind' : 'common', 42 | \ 'is_dummy': 1, 43 | \ } 44 | 45 | let s:formatter = { 46 | \ 'name' : 'outline_formatter', 47 | \ 'description': 'view formatter for outline tree', 48 | \ } 49 | 50 | function! s:formatter.filter(candidates, unite_context) abort 51 | if empty(a:candidates) | return a:candidates | endif 52 | 53 | let bufnr = a:unite_context.source__outline_source_bufnr 54 | let context = unite#sources#outline#get_outline_data(bufnr, 'context') 55 | 56 | " Insert blanks for readability. 57 | let candidates = s:insert_blanks(a:candidates, context) 58 | 59 | " Turbo Jump 60 | if len(a:candidates) < 10 61 | let matches = filter(copy(a:candidates), 'v:val.is_matched') 62 | if len(matches) == 1 " Bingo! 63 | let bingo = copy(matches[0]) 64 | if bingo != a:candidates[0] 65 | " Prepend a copy of the only one matched heading to the narrowing 66 | " results for jumping to its position with one . 67 | let bingo.abbr = substitute(bingo.abbr, '^ \=', '!', '') 68 | let candidates = [bingo, s:BLANK] + candidates 69 | endif 70 | endif 71 | endif 72 | return candidates 73 | endfunction 74 | 75 | function! s:insert_blanks(candidates, context) abort 76 | let oinfo = a:context.outline_info 77 | if a:context.extracted_by !=# 'filetype' || 78 | \ (empty(oinfo.heading_groups) && !has_key(oinfo, 'need_blank_between')) 79 | return a:candidates 80 | endif 81 | 82 | if !has_key(oinfo, 'need_blank_between') 83 | " Use the default implementation. 84 | let oinfo.need_blank_between = function('s:need_blank_between') 85 | endif 86 | let candidates = [] 87 | let prev_sibling = {} | let prev_level = 0 88 | let memo = {} | " for memoization 89 | for cand in a:candidates 90 | if cand.source__heading_level <= prev_level && 91 | \ oinfo.need_blank_between(prev_sibling[cand.source__heading_level], cand, memo) 92 | call add(candidates, s:BLANK) 93 | endif 94 | call add(candidates, cand) 95 | let prev_sibling[cand.source__heading_level] = cand 96 | let prev_level = cand.source__heading_level 97 | endfor 98 | return candidates 99 | endfunction 100 | 101 | function! s:need_blank_between(cand1, cand2, memo) dict 102 | return (a:cand1.source__heading_group != a:cand2.source__heading_group || 103 | \ a:cand1.source__has_marked_child || a:cand2.source__has_marked_child) 104 | endfunction 105 | 106 | let &cpo = s:save_cpo 107 | unlet s:save_cpo 108 | -------------------------------------------------------------------------------- /autoload/unite/filters/outline_matcher_glob.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/filters/outline_matcher_glob.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " Version : 0.5.1 6 | " License : MIT license {{{ 7 | " 8 | " Permission is hereby granted, free of charge, to any person obtaining 9 | " a copy of this software and associated documentation files (the 10 | " "Software"), to deal in the Software without restriction, including 11 | " without limitation the rights to use, copy, modify, merge, publish, 12 | " distribute, sublicense, and/or sell copies of the Software, and to 13 | " permit persons to whom the Software is furnished to do so, subject to 14 | " the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included 17 | " in all copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | " }}} 27 | "============================================================================= 28 | 29 | let s:save_cpo = &cpo 30 | set cpo&vim 31 | 32 | function! unite#filters#outline_matcher_glob#define() abort 33 | return s:matcher 34 | endfunction 35 | 36 | let s:Tree = unite#sources#outline#import('Tree') 37 | 38 | let s:matcher = { 39 | \ 'name' : 'outline_matcher_glob', 40 | \ 'description': 'glob matcher for outline tree', 41 | \ } 42 | 43 | " Derived from: 44 | " unite/autoload/filters/matcher_glob.vim 45 | " 46 | function! s:matcher.filter(candidates, unite_context) abort 47 | if empty(a:candidates) | return a:candidates | endif 48 | 49 | call s:Tree.List.reset_marks(a:candidates) 50 | 51 | if a:unite_context.input == '' 52 | return a:candidates 53 | endif 54 | 55 | for input in split(a:unite_context.input, '\\\@ 4 | " Updated : 2018-08-22 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Arduino 12 | " Version: 0.0.2 13 | 14 | function! unite#sources#outline#defaults#arduino#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading' : '^\s*\%(void\|command_data_t\|serial_data_t\|middle_data_t\)\>', 25 | \ 26 | \ 'heading_groups': { 27 | \ 'function' : ['function'], 28 | \ }, 29 | \ 30 | \ 'not_match_patterns': [ 31 | \ s:Util.shared_pattern('*', 'parameter_list'), 32 | \ ], 33 | \ 34 | \ 'highlight_rules': [ 35 | \ { 'name' : 'comment', 36 | \ 'pattern': "'/[/*].*'" }, 37 | \ { 'name' : 'function', 38 | \ 'pattern': '/\h\w*\ze\s*(/' }, 39 | \ { 'name' : 'parameter_list', 40 | \ 'pattern': '/(.*)/' }, 41 | \ ], 42 | \} 43 | 44 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 45 | let h_lnum = a:context.heading_lnum 46 | let level = s:Util.get_indent_level(a:context, h_lnum) 47 | let heading = { 48 | \ 'word' : a:heading_line, 49 | \ 'level': level, 50 | \ 'type' : 'generic', 51 | \ } 52 | 53 | if heading.word =~ '^\s*void\>' 54 | " Function 55 | let heading.type = 'function' 56 | let heading.word = substitute(heading.word, '\ 0 52 | return heading 53 | else 54 | return {} 55 | endif 56 | endfunction 57 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/changelog.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/changelog.vim 3 | " Author : sgur 4 | " Maintainer : h1mesuke 5 | " Updated : 2012-01-11 6 | " 7 | " Licensed under the MIT license: 8 | " http://www.opensource.org/licenses/mit-license.php 9 | " 10 | "============================================================================= 11 | 12 | " Default outline info for ChangeLog 13 | " Version: 0.0.2 14 | 15 | function! unite#sources#outline#defaults#changelog#outline_info() abort 16 | return s:outline_info 17 | endfunction 18 | 19 | "--------------------------------------- 20 | " Sub Patterns 21 | 22 | let s:pat_date = '\(\S.*\)\=\d\+[-:]\d\+[-:]\d\+' 23 | let s:pat_item = '\s\+\*\s\+' 24 | 25 | "----------------------------------------------------------------------------- 26 | " Outline Info 27 | 28 | let s:outline_info = { 29 | \ 'heading': '^\(' . s:pat_date . '\|' . s:pat_item . '\)', 30 | \ 31 | \ 'highlight_rules': [ 32 | \ { 'name' : 'level_1', 33 | \ 'pattern' : '/' . s:pat_date . '.*/' }, 34 | \ ], 35 | \} 36 | 37 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 38 | let heading = { 39 | \ 'word' : a:heading_line, 40 | \ 'level': 0, 41 | \ 'type' : 'generic', 42 | \ } 43 | 44 | if a:heading_line =~ '^' . s:pat_date 45 | let heading.level = 1 46 | elseif a:heading_line =~ '^' . s:pat_item 47 | let heading.level = 2 48 | endif 49 | 50 | if heading.level > 0 51 | return heading 52 | else 53 | return {} 54 | endif 55 | endfunction 56 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/coffee.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File: autoload/unite/sources/outline/defaults/coffee.vim 3 | " Author: Jens Himmelreich 4 | " Version: 0.1.0 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | "============================================================================= 9 | let s:Util = unite#sources#outline#import('Util') 10 | let s:MaxLevel = 4 11 | 12 | let s:class = '\%(class\)' 13 | let s:function = '\%(\w\+.*[-=]>\)' 14 | let s:export = '\%(\%(module\.\)\?exports\)' 15 | 16 | let s:heading = '^\s\{,' . s:MaxLevel . '}\%(' . s:class . '\|' . s:function . '\|' . s:export .'\)' 17 | 18 | let s:outline_info = { 19 | \ 'heading': s:heading 20 | \ } 21 | 22 | function! unite#sources#outline#defaults#coffee#outline_info() abort 23 | return s:outline_info 24 | endfunction 25 | 26 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 27 | let h_lnum = a:context.heading_lnum 28 | let level = s:Util.get_indent_level(a:context, h_lnum) 29 | let heading = { 30 | \ 'word' : a:heading_line, 31 | \ 'level': level, 32 | \ 'type' : 'generic', 33 | \ } 34 | return heading 35 | endfunction 36 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/conf.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/conf.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Conf files 12 | " Version: 0.0.5 13 | 14 | function! unite#sources#outline#defaults#conf#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': s:Util.shared_pattern('sh', 'heading-1'), 25 | \ 26 | \ 'skip': { 27 | \ 'header': s:Util.shared_pattern('sh', 'header'), 28 | \ }, 29 | \} 30 | 31 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 32 | let heading = { 33 | \ 'word' : a:heading_line, 34 | \ 'level': 0, 35 | \ 'type' : 'generic', 36 | \ } 37 | 38 | if a:which ==# 'heading-1' 39 | let m_lnum = a:context.matched_lnum 40 | let heading.type = 'comment' 41 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum, 4) 42 | endif 43 | 44 | if heading.level > 0 45 | return heading 46 | else 47 | return {} 48 | endif 49 | endfunction 50 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/cpp.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/cpp.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for C++ 12 | " Version: 0.2.0 13 | 14 | function! unite#sources#outline#defaults#cpp#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Ctags = unite#sources#outline#import('Ctags') 19 | let s:Util = unite#sources#outline#import('Util') 20 | 21 | "----------------------------------------------------------------------------- 22 | " Outline Info 23 | 24 | let s:outline_info = { 25 | \ 'heading_groups': { 26 | \ 'namespace': ['namespace'], 27 | \ 'type' : ['class', 'enum', 'struct', 'typedef'], 28 | \ 'function' : ['function', 'macro'], 29 | \ }, 30 | \ 31 | \ 'not_match_patterns': [ 32 | \ s:Util.shared_pattern('*', 'parameter_list'), 33 | \ ' => .*', 34 | \ ], 35 | \ 36 | \ 'highlight_rules': [ 37 | \ { 'name' : 'parameter_list', 38 | \ 'pattern': '/\%(=> .*\)\@ .*\)\@.*\|\h\w*\)\ze\s*(/' }, 43 | \ { 'name' : 'macro', 44 | \ 'pattern': '/\h\w*\ze .*=> /' }, 45 | \ { 'name' : 'expanded', 46 | \ 'pattern': '/ => \zs.*/' }, 47 | \ { 'name' : 'id', 48 | \ 'pattern': '/ \zs#\d\+/' }, 49 | \ ], 50 | \} 51 | 52 | function! s:outline_info.extract_headings(context) abort 53 | return s:Ctags.extract_headings(a:context) 54 | endfunction 55 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/cs.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/cs.vim 3 | " Author : ssteinbach ssteinbach@github.com 4 | " Updated : 2014-02-08 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for C# 12 | " Version: 0.2.0 13 | 14 | function! unite#sources#outline#defaults#cs#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Ctags = unite#sources#outline#import('Ctags') 19 | let s:Util = unite#sources#outline#import('Util') 20 | 21 | "----------------------------------------------------------------------------- 22 | " Outline Info 23 | 24 | let s:outline_info = { 25 | \ 'heading_groups': { 26 | \ 'namespace': ['namespace'], 27 | \ 'type' : ['class', 'enum', 'struct', 'typedef'], 28 | \ 'function' : ['function', 'macro'], 29 | \ }, 30 | \ 31 | \ 'not_match_patterns': [ 32 | \ s:Util.shared_pattern('*', 'parameter_list'), 33 | \ ], 34 | \ 35 | \ 'highlight_rules': [ 36 | \ { 'name' : 'parameter_list', 37 | \ 'pattern': '/(.*)/' }, 38 | \ { 'name' : 'type', 39 | \ 'pattern': '/\S\+\ze\%( #\d\+\)\= : \%(class\|enum\|struct\|typedef\)/' }, 40 | \ { 'name' : 'function', 41 | \ 'pattern': '/\%(=> .*\)\@.*\|\h\w*\)\ze\s*(/' }, 42 | \ { 'name' : 'macro', 43 | \ 'pattern': '/\h\w*\ze .*=> /' }, 44 | \ { 'name' : 'expanded', 45 | \ 'pattern': '/ => \zs.*/' }, 46 | \ { 'name' : 'id', 47 | \ 'pattern': '/ \zs#\d\+/' }, 48 | \ ], 49 | \} 50 | 51 | function! s:outline_info.extract_headings(context) abort 52 | return s:Ctags.extract_headings(a:context) 53 | endfunction 54 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/css.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/css.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for CSS 12 | " Version: 0.0.3 13 | 14 | function! unite#sources#outline#defaults#css#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': s:Util.shared_pattern('c', 'heading-1'), 25 | \ 26 | \ 'skip': { 27 | \ 'header': { 28 | \ 'leading': '^@charset', 29 | \ 'block' : s:Util.shared_pattern('c', 'header'), 30 | \ }, 31 | \ }, 32 | \} 33 | 34 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 35 | let heading = { 36 | \ 'word' : a:heading_line, 37 | \ 'level': 0, 38 | \ 'type' : 'generic', 39 | \ } 40 | 41 | if a:which ==# 'heading-1' 42 | let m_lnum = a:context.matched_lnum 43 | let heading.type = 'comment' 44 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum, 4) 45 | endif 46 | 47 | if heading.level > 0 48 | return heading 49 | else 50 | return {} 51 | endif 52 | endfunction 53 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/dosini.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/dosini.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Windows INI files 12 | " Version: 0.0.2 13 | 14 | function! unite#sources#outline#defaults#dosini#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | "----------------------------------------------------------------------------- 19 | " Outline Info 20 | 21 | let s:outline_info = { 22 | \ 'heading': '^\s*\[[^\]]\+\]', 23 | \ } 24 | 25 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 26 | let heading = { 27 | \ 'word' : a:heading_line, 28 | \ 'level': 1, 29 | \ 'type' : 'generic', 30 | \ } 31 | return heading 32 | endfunction 33 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/elm.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File: autoload/unite/sources/outline/defaults/elm.vim 3 | " Author: aiya000 4 | " Updated: 2017-11-15 5 | " Version: 0.1.0 6 | " Referred To: 7 | " - https://github.com/kbsymanz/ctags-elm 8 | " 9 | " Licensed under the MIT license: 10 | " http://www.opensource.org/licenses/mit-license.php 11 | " 12 | " MIT License {{{ 13 | " 14 | " Copyright (c) 2016 Kurt Symanzik 15 | " 16 | " Permission is hereby granted, free of charge, to any person obtaining a copy 17 | " of this software and associated documentation files (the "Software"), to deal 18 | " in the Software without restriction, including without limitation the rights 19 | " to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 | " copies of the Software, and to permit persons to whom the Software is 21 | " furnished to do so, subject to the following conditions: 22 | " 23 | " The above copyright notice and this permission notice shall be included in all 24 | " copies or substantial portions of the Software. 25 | " 26 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | " OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | " SOFTWARE. 33 | " }}} 34 | " 35 | "============================================================================= 36 | 37 | function! unite#sources#outline#defaults#elm#outline_info() abort 38 | return s:outline_info 39 | endfunction 40 | 41 | let s:Ctags = unite#sources#outline#import('Ctags') 42 | 43 | let s:outline_info = {} 44 | 45 | function! s:outline_info.extract_headings(context) abort 46 | return s:Ctags.extract_headings(a:context) 47 | endfunction 48 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/go.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/go.vim 3 | " Author : rhysd 4 | " Updated : 2014-05-31 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Go 12 | 13 | function! unite#sources#outline#defaults#go#outline_info() abort 14 | return s:outline_info 15 | endfunction 16 | 17 | let s:Util = unite#sources#outline#import('Util') 18 | 19 | let s:outline_info = { 20 | \ 'heading-1': s:Util.shared_pattern('c', 'heading-1'), 21 | \ 'heading' : '^\s*\%(func\s\+.*{\|type\s\+\h\w*\s\+\%(struct\|interface\)\=\)', 22 | \ 'skip' : { 23 | \ 'header' : s:Util.shared_pattern('c', 'header'), 24 | \ }, 25 | \ 'highlight_rules' : [ 26 | \ { 27 | \ 'name' : 'comment', 28 | \ 'pattern' : '/\/\/.*/', 29 | \ }, 30 | \ { 31 | \ 'name' : 'function', 32 | \ 'pattern' : '/\%(([^)]*)\s\+\)\=\zs\h\w*\ze\s*([^)]*) : function/', 33 | \ }, 34 | \ { 35 | \ 'name' : 'interface', 36 | \ 'pattern' : '/\h\w*\ze : interface/', 37 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 38 | \ }, 39 | \ { 40 | \ 'name' : 'struct', 41 | \ 'pattern' : '/\h\w*\ze : struct/', 42 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 43 | \ }, 44 | \ { 45 | \ 'name' : 'type', 46 | \ 'pattern' : '/\h\w*\ze : type/', 47 | \ }, 48 | \ ], 49 | \ } 50 | 51 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 52 | let type = 'generic' 53 | let level = 0 54 | 55 | if a:which ==# 'heading-1' && a:heading_line =~# '^\s*//' 56 | let m_lnum = a:context.matched_lnum 57 | let type = 'comment' 58 | let level = s:Util.get_comment_heading_level(a:context, m_lnum) 59 | let word = a:heading_line 60 | elseif a:which ==# 'heading' && a:heading_line =~# '^\s*type' 61 | let matches = matchlist(a:heading_line, '^\s*\zstype\s\+\(\h\w*\)\s\+\([[:alpha:][\]_][[:alnum:][\]_]*\)') 62 | if matches[2] =~# '\%(interface\|struct\)' 63 | let type = matches[2] 64 | let word = matches[1] . ' : ' . matches[2] 65 | else 66 | let type = 'type' 67 | let word = matches[1] . ' : type' 68 | endif 69 | let level = s:Util.get_indent_level(a:context, a:context.heading_lnum) 70 | elseif a:which ==# 'heading' && a:heading_line =~# '^\s*func' 71 | let type = 'function' 72 | let word = matchstr(a:heading_line, '^\s*func\s\+\zs\%(([^)]*)\s\+\)\=\h\w*\s*([^)]*)') . ' : function' 73 | let level = s:Util.get_indent_level(a:context, a:context.heading_lnum) 74 | endif 75 | 76 | if level > 0 77 | let heading = { 78 | \ 'word' : word, 79 | \ 'level': level, 80 | \ 'type' : type, 81 | \ } 82 | else 83 | let heading = {} 84 | endif 85 | 86 | return heading 87 | endfunction 88 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/godoc.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/go.vim 3 | " Author : rhysd 4 | " Updated : 2015-04-25 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Go 12 | 13 | function! unite#sources#outline#defaults#godoc#outline_info() abort 14 | return s:outline_info 15 | endfunction 16 | 17 | let s:Util = unite#sources#outline#import('Util') 18 | 19 | let s:outline_info = { 20 | \ 'heading' : '^\%(\u[[:upper:] ]*\|\%(package\|func\|type\|var\|const\)\s\+.\+\|)\|\s\+\h\w*\s\+=\s\+.*\)$', 21 | \ 'end' : '^\s*)\s*$', 22 | \ 'highlight_rules' : [ 23 | \ { 24 | \ 'name' : 'title', 25 | \ 'pattern' : '/\<\u\+\>/', 26 | \ 'highlight' : 'Title', 27 | \ }, 28 | \ { 29 | \ 'name' : 'function', 30 | \ 'pattern' : '/\%(([^)]*)\s\+\)\=\zs\h\w*\ze\s*([^)]*) : function/', 31 | \ }, 32 | \ { 33 | \ 'name' : 'type', 34 | \ 'pattern' : '/\<\h\w*\ze : \%(interface\|struct\|type\)\>/', 35 | \ }, 36 | \ { 37 | \ 'name' : 'variable', 38 | \ 'pattern' : '/\<\h\w*\ze : \%(variable\|constant\)/', 39 | \ 'highlight' : 'Identifier', 40 | \ }, 41 | \ { 42 | \ 'name' : 'keyword', 43 | \ 'pattern' : '/\<\%(function\|type\|struct\|interface\|variable\|package\|constant\)\>/', 44 | \ 'highlight' : 'Keyword', 45 | \ }, 46 | \ { 47 | \ 'name' : 'package', 48 | \ 'pattern' : '/\<\h\w*\ze : package\>/', 49 | \ 'highlight' : 'PreProc', 50 | \ }, 51 | \ ], 52 | \ } 53 | 54 | let s:parsing_block = '' 55 | 56 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 57 | if a:which !=# 'heading' 58 | return {} 59 | endif 60 | 61 | if a:heading_line =~# '^\u[[:upper:] ]*$' 62 | return {'word' : a:heading_line, 'type' : 'title', 'level' : 1} 63 | endif 64 | 65 | if s:parsing_block !=# '' && a:heading_line =~# '^\s\+\h\w* =' 66 | let type = s:parsing_block 67 | let word = matchstr(a:heading_line, '^\s\+\(\h\w*\)') . ' : ' . type 68 | return {'type' : type, 'word' : word, 'level' : 2} 69 | endif 70 | 71 | if a:heading_line ==# ')' 72 | let s:parsing_block = '' 73 | return {} 74 | endif 75 | 76 | if a:heading_line =~# '^type\>' 77 | let matches = matchlist(a:heading_line, '^type\s\+\(\h\w*\)\s\+\([[:alpha:][\]_][[:alnum:][\]_]*\)') 78 | if matches[2] =~# '^\%(interface\|struct\)$' 79 | let type = matches[2] 80 | let word = matches[1] . ' : ' . matches[2] 81 | else 82 | let type = 'type' 83 | let word = matches[1] . ' : type' 84 | endif 85 | elseif a:heading_line =~# '^func\>' 86 | let type = 'function' 87 | let word = matchstr(a:heading_line, '^func\s\+\zs\%(([^)]*)\s\+\)\=\h\w*\s*([^)]*)') . ' : function' 88 | elseif a:heading_line =~# '^var\>' 89 | if a:heading_line =~# '($' 90 | let s:parsing_block = 'variable' 91 | return {} 92 | endif 93 | let type = 'variable' 94 | let word = matchstr(a:heading_line, '^var\s\+\zs\h\w*') . ' : variable' 95 | elseif a:heading_line =~# '^const\>' 96 | if a:heading_line =~# '($' 97 | let s:parsing_block = 'constant' 98 | return {} 99 | endif 100 | let type = 'constant' 101 | let word = matchstr(a:heading_line, '^const\s\+\zs\h\w*') . ' : constant' 102 | elseif a:heading_line =~# '^package\>' 103 | let type = 'package' 104 | let word = matchstr(a:heading_line, '^package\s\+\zs\h\w*') . ' : package' 105 | else 106 | return {} 107 | endif 108 | 109 | return {'word' : word, 'level' : 2, 'type' : type} 110 | endfunction 111 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/haskell.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File: autoload/unite/sources/outline/defaults/haskell.vim 3 | " Author: igrep 4 | " Updated: 2013-01-03 5 | " Version: 0.1.1 6 | " TODO: 7 | " - support hspec, lhs, haddock, etc. 8 | " - how to handle comments? 9 | " Referred To: 10 | " - http://www.cs.utep.edu/cheon/cs3360/pages/haskell-syntax.html 11 | " - http://www.sampou.org/haskell/report-revised-j/syntax-iso.html 12 | " - http://www.haskell.org/haskellwiki/Keywords 13 | " 14 | " Licensed under the MIT license: 15 | " http://www.opensource.org/licenses/mit-license.php 16 | " 17 | "============================================================================= 18 | 19 | let s:declaration = '\%(module\|data\|type\|newtype\|class\|instance\)' 20 | " starts with lowercase or an parenthesis 21 | let s:signature = '\%([a-z(].*::\)' 22 | 23 | let s:heading = '^\%(' . s:declaration . '\|' . s:signature .'\)' 24 | 25 | " Don't need to skip line comment. 26 | " Because the header starts with '^' 27 | let s:skip = { 'block': ['{-', '-}'] } 28 | 29 | let s:outline_info = { 30 | \ 'heading': s:heading, 31 | \ 'skip': s:skip 32 | \ } 33 | 34 | function! unite#sources#outline#defaults#haskell#outline_info() abort 35 | return s:outline_info 36 | endfunction 37 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/hatena.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/hatena.vim 3 | " Author : aereal 4 | " Updated : 2012-12-20 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Hatena annotation 12 | " Version: 0.0.1 13 | 14 | function! unite#sources#outline#defaults#hatena#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:outline_info = { 19 | \ 'heading' : '^\*\+', 20 | \ } 21 | 22 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 23 | let heading = { 24 | \ 'word' : a:heading_line, 25 | \ 'level': strlen(matchstr(a:heading_line, '^*\+')), 26 | \ 'type' : 'generic', 27 | \ } 28 | 29 | if a:which ==# 'heading' 30 | let heading.level = strlen(matchstr(a:heading_line, '^*\+')) 31 | let heading.word = substitute(heading.word, '^\*\+\s*', '', '') 32 | let heading.word = substitute(heading.word, '\s*\*\+\s*$', '', '') 33 | endif 34 | 35 | if heading.level > 0 36 | let heading.word = substitute(heading.word, '\s*]*>\s*\%(\s*\)\=$', '', '') 37 | return heading 38 | else 39 | return {} 40 | endif 41 | endfunction 42 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/help.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/help.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Vim Help 12 | " Version: 0.1.2 13 | 14 | function! unite#sources#outline#defaults#help#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | " HEADING SAMPLES: 21 | " 22 | "== Level 1 23 | " 24 | " ========================================================================== 25 | " Heading 26 | " 27 | "== Level 2 28 | " 29 | " -------------------------------------------------------------------------- 30 | " Heading 31 | " 32 | "== Level 3 33 | " 34 | " 1.1 Heading 35 | " 36 | "== Level 4-1 37 | " 38 | " HEADING *tag* 39 | " 40 | "== Level 4-2 41 | " 42 | " HEADING ~ 43 | " *tag* 44 | 45 | "--------------------------------------- 46 | " Sub Patterns 47 | 48 | let s:pat_section_nr = '\d\+\.\d\+\s\+\S' 49 | let s:pat_upper_word = '\u[[:upper:][:digit:]_]\+\>' 50 | let s:pat_helptag = '\*[^*]\+\*' 51 | 52 | "----------------------------------------------------------------------------- 53 | " Outline Info 54 | 55 | let s:outline_info = { 56 | \ 'heading-1': '^[-=]\{10,}\s*$', 57 | \ 'heading' : '^\%(' . s:pat_section_nr . '\|' . 58 | \ s:pat_upper_word . '.*\%(' . s:pat_helptag . '\|\~\)\)', 59 | \ } 60 | 61 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 62 | let heading = { 63 | \ 'word' : a:heading_line, 64 | \ 'level': 0, 65 | \ 'type' : 'generic', 66 | \ } 67 | 68 | let lines = a:context.lines 69 | 70 | if a:which ==# 'heading-1' 71 | let m_lnum = a:context.matched_lnum 72 | if a:matched_line =~ '^=' 73 | let heading.level = 1 74 | elseif a:matched_line =~ '^-' && lines[m_lnum-1] !~ '\S' 75 | let heading.level = 2 76 | endif 77 | elseif a:which ==# 'heading' 78 | let h_lnum = a:context.heading_lnum 79 | if a:heading_line =~ '^' . s:pat_section_nr 80 | if a:heading_line =~ '\~\s*$' 81 | let heading.level = 3 82 | endif 83 | elseif a:heading_line =~ s:pat_helptag || 84 | \ s:Util.neighbor_match(a:context, h_lnum, s:pat_helptag) 85 | let heading.level = 4 86 | endif 87 | endif 88 | 89 | if heading.level > 0 90 | let heading.word = s:normalize_heading_word(heading.word) 91 | if heading.word =~? '^Contents\s*$' 92 | let heading.level = 1 93 | endif 94 | return heading 95 | else 96 | return {} 97 | endif 98 | endfunction 99 | 100 | function! s:normalize_heading_word(word) abort 101 | let word = substitute(a:word, '\%(\~\|{{{\d\=\)\s*$', '', '') 102 | let word = substitute(word, s:pat_helptag, '', 'g') 103 | if word !~ '\l' 104 | let word = s:Util.String.capitalize(word, 'g') 105 | endif 106 | return word 107 | endfunction 108 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/html.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/html.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for HTML 12 | " Version: 0.0.8 13 | 14 | function! unite#sources#outline#defaults#html#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "--------------------------------------- 21 | " Patterns 22 | 23 | let s:heading_tags = ['head', 'body', 'h\([1-6]\)'] 24 | let s:heading_pattern = '\c<\(' . join(s:heading_tags, '\|') . '\)\>[^>]*>' 25 | 26 | "----------------------------------------------------------------------------- 27 | " Outline Info 28 | 29 | let s:outline_info = { 30 | \ 'heading': s:heading_pattern, 31 | \ 32 | \ 'highlight_rules': [ 33 | \ { 'name' : 'level_1', 34 | \ 'pattern': '/H1\. .*/' }, 35 | \ { 'name' : 'level_2', 36 | \ 'pattern': '/H2\. .*/' }, 37 | \ { 'name' : 'level_3', 38 | \ 'pattern': '/H3\. .*/' }, 39 | \ { 'name' : 'level_4', 40 | \ 'pattern': '/H4\. .*/' }, 41 | \ { 'name' : 'level_5', 42 | \ 'pattern': '/H5\. .*/' }, 43 | \ { 'name' : 'level_6', 44 | \ 'pattern': '/H6\. .*/' }, 45 | \ ], 46 | \} 47 | 48 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 49 | let heading = { 50 | \ 'word' : a:heading_line, 51 | \ 'level': 0, 52 | \ 'type' : 'generic', 53 | \ } 54 | 55 | let matches = matchlist(a:heading_line, s:heading_pattern) 56 | let tag = matches[1] 57 | if tag =~? '^\%(head\|body\)$' 58 | let heading.level = 1 59 | let heading.word = substitute(tag, '^\(.\)', '\u\1', '') 60 | else 61 | let level = str2nr(matches[2]) 62 | let heading.level = level + 1 63 | let heading.word = 'H' . level . '. ' . s:get_text_content(level, a:context) 64 | endif 65 | 66 | if heading.level > 0 67 | return heading 68 | else 69 | return {} 70 | endif 71 | endfunction 72 | 73 | function! s:get_text_content(level, context) abort 74 | let h_lnum = a:context.heading_lnum 75 | let text = s:Util.join_to(a:context, h_lnum, ']*>') 76 | let text = substitute(text, '\n', '', 'g') 77 | let text = substitute(text, '<[[:alpha:]/][^>]*>', '', 'g') 78 | return text 79 | endfunction 80 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/java.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/java.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Java 12 | " Version: 0.1.6 13 | 14 | function! unite#sources#outline#defaults#java#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Ctags = unite#sources#outline#import('Ctags') 19 | let s:Util = unite#sources#outline#import('Util') 20 | 21 | "----------------------------------------------------------------------------- 22 | " Outline Info 23 | 24 | let s:outline_info = { 25 | \ 'heading_groups': { 26 | \ 'package': ['package'], 27 | \ 'type' : ['interface', 'class', 'enum'], 28 | \ 'method' : ['method'], 29 | \ }, 30 | \ 31 | \ 'not_match_patterns': [ 32 | \ s:Util.shared_pattern('*', 'parameter_list'), 33 | \ ], 34 | \ 35 | \ 'highlight_rules': [ 36 | \ { 'name' : 'package', 37 | \ 'pattern': '/\S\+\ze : package/' }, 38 | \ { 'name' : 'type', 39 | \ 'pattern': '/\S\+\ze : \%(interface\|class\|enum\)/' }, 40 | \ { 'name' : 'method', 41 | \ 'pattern': '/\h\w*\ze\s*(/' }, 42 | \ { 'name' : 'parameter_list', 43 | \ 'pattern': '/(.*)/' }, 44 | \ ], 45 | \} 46 | 47 | function! s:outline_info.extract_headings(context) abort 48 | return s:Ctags.extract_headings(a:context) 49 | endfunction 50 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/javascript.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/javascript.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Contributed by hamaco 7 | " 8 | " Licensed under the MIT license: 9 | " http://www.opensource.org/licenses/mit-license.php 10 | " 11 | "============================================================================= 12 | 13 | " Default outline info for JavaScript 14 | " Version: 0.1.1 15 | 16 | " TODO: Use jsctags for much better heading list! 17 | 18 | function! unite#sources#outline#defaults#javascript#outline_info() abort 19 | return s:outline_info 20 | endfunction 21 | 22 | let s:Util = unite#sources#outline#import('Util') 23 | 24 | "--------------------------------------- 25 | " Sub Patterns 26 | 27 | let s:pat_indent = '\<\h\w*\>' 28 | 29 | let s:pat_assign = '\%(\%(var\|let\|const\)\s\+\)\=\(' . s:pat_indent . '\%(\.' . s:pat_indent . '\)*\)\s*=' 30 | " NOTE: This sub pattern contains 1 capture; 1:lvalue 31 | 32 | let s:pat_label = '\(' . s:pat_indent . '\)\s*:' 33 | " NOTE: This sub pattern contains 1 capture; 1:label 34 | 35 | let s:pat_rvalue = '\(function\s*(\([^)]*\))\|(\(.*\))\s*{\|\s*{\|\(\w\+\)\s*(\(.*\))\s*{\)' 36 | " NOTE: This sub pattern contains 2 captures; 1:rvalue [, 2:arg_list] 37 | 38 | let s:pat_def = '\%(\%(export\s\+\%(default\s\+\)\=\)\=function\>\)' 39 | 40 | let s:pat_es6_class = '^\s*\%(export\s\+\%(default\s\+\)\=\)\=class\s\+\(\S\+\)\s*{$' 41 | " NOTE: This sub pattern contains 1 capture; 1:className 42 | 43 | let s:pat_es6_method = '^\s*\(\%(static\s\+\)\?\w\+\)\s*(\([^)]*\))\s*{$' 44 | " NOTE: This sub pattern contains 2 capture; 1:methodName [, 2:arg_list] 45 | 46 | "----------------------------------------------------------------------------- 47 | " Outline Info 48 | 49 | let s:outline_info = { 50 | \ 'heading-1': s:Util.shared_pattern('cpp', 'heading-1'), 51 | \ 'heading' : '^\s*\%(' . s:pat_def . '\|' . 52 | \ '\%(' . 53 | \ '\%(export\s\+\%(default\s\+\)\=\)\=class\s\+\(\S\+\)\s\+\%(extends\s\+\w\+\)\?\|\s*\%(static\s\+\)\?\w\+\s*\|' . s:pat_assign . '\|' . s:pat_label . 54 | \ '\)\s*' . s:pat_rvalue . '\)', 55 | \ 56 | \ 'skip': { 57 | \ 'header': s:Util.shared_pattern('cpp', 'header'), 58 | \ }, 59 | \ 60 | \ 'not_match_patterns': [ 61 | \ s:Util.shared_pattern('*', 'parameter_list'), 62 | \ ], 63 | \} 64 | 65 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 66 | let h_lnum = a:context.heading_lnum 67 | " Level 1 to 3 are reserved for comment headings. 68 | let level = s:Util.get_indent_level(a:context, h_lnum) + 3 69 | let heading = { 70 | \ 'word' : a:heading_line, 71 | \ 'level': level, 72 | \ 'type' : 'generic', 73 | \ } 74 | 75 | if a:which == 'heading-1' && s:Util._cpp_is_in_comment(a:heading_line, a:matched_line) 76 | let m_lnum = a:context.matched_lnum 77 | let heading.type = 'comment' 78 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum) 79 | 80 | elseif a:which ==# 'heading' 81 | 82 | let matched_list = matchlist(a:heading_line, 83 | \ '^\s*' . s:pat_def . '\s\+\(' . s:pat_indent . '\)\s*(\(.*\))') 84 | if len(matched_list) > 0 85 | " function Foo(...) -> Foo(...) 86 | " function foo(...) -> foo(...) 87 | let [func_name, arg_list] = matched_list[1:2] 88 | let heading.word = func_name . '(' . arg_list . ')' 89 | endif 90 | 91 | let matched_list = matchlist(a:heading_line, 92 | \ '^\s*\%(' . s:pat_assign . '\|' . s:pat_label . '\)\s*' . s:pat_rvalue) 93 | if len(matched_list) > 0 94 | let [lvalue, label, rvalue, arg_list] = matched_list[1:4] 95 | if lvalue =~ '\S' 96 | " Assign 97 | if lvalue =~ '\.' 98 | " Property 99 | let prop_chain = split(lvalue, '\.') 100 | let prop_name = prop_chain[-1] 101 | if rvalue =~ '^f' 102 | if prop_name =~ '^\u' 103 | " Foo.Bar = function(...) -> Foo.Bar(...) 104 | let heading.word = lvalue . '(' . arg_list . ')' 105 | else 106 | " Foo.bar = function(...) -> bar(...) 107 | "let heading.level += 1 108 | let heading.word = prop_name . '(' . arg_list . ')' 109 | endif 110 | else 111 | if match(prop_chain, '^\u') >= 0 112 | " Foo.Bar = { -> Foo.Bar 113 | " Foo.bar = { -> Foo.bar 114 | let heading.word = lvalue 115 | else 116 | " foo.bar = { 117 | let heading.level = 0 118 | endif 119 | endif 120 | elseif lvalue =~ '^\u' 121 | " Variale 122 | if rvalue =~ '^f' 123 | " var Foo = function(...) -> Foo(...) 124 | let heading.word = lvalue . '(' . arg_list . ')' 125 | else 126 | " var Foo = { -> Foo 127 | let heading.word = lvalue 128 | endif 129 | else 130 | " var foo = ... 131 | let heading.level = 0 132 | endif 133 | else 134 | " Label 135 | if rvalue =~ '^f' 136 | " foo: function(...) -> foo(...) 137 | let heading.word = label . '(' . arg_list . ')' 138 | else 139 | " foo: { 140 | let heading.level = 0 141 | endif 142 | endif 143 | else 144 | let matched_list = matchlist(a:heading_line, s:pat_es6_class) 145 | if len(matched_list) > 0 146 | let heading.level = 1 147 | let heading.word = 'class ' . matched_list[1] 148 | else 149 | let heading.level = 2 150 | let matched_list = matchlist(a:heading_line, s:pat_es6_method) 151 | if len(matched_list) > 0 152 | if match(a:heading_line, '^\s*\%(for\|if\|while\|switch\)\>') != -1 153 | let heading.level = 0 154 | else 155 | let [func_name, arg_list] = matched_list[1:2] 156 | let heading.word = func_name . '(' . arg_list . ')' 157 | endif 158 | endif 159 | endif 160 | endif 161 | endif 162 | 163 | if heading.level > 0 164 | return heading 165 | else 166 | return {} 167 | endif 168 | endfunction 169 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/lisp.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/lisp.vim 3 | " Author : adolenc 4 | " Updated : 2016-04-08 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | function! unite#sources#outline#defaults#lisp#outline_info() abort 12 | return s:outline_info 13 | endfunction 14 | 15 | let s:Util = unite#sources#outline#import('Util') 16 | 17 | "----------------------------------------------------------------------------- 18 | " Outline Info 19 | 20 | let s:DEF_PATTERN = '\(\S*:\)\?def\S*' 21 | let s:FEATURE_PATTERN = '#\(+\|-\)\(([^)]\+)\|\S[^(]*\)' 22 | 23 | let s:outline_info = { 24 | \ 'heading' : '^' . s:FEATURE_PATTERN . '\s*(\|^(\|^\s*(' . s:DEF_PATTERN, 25 | \ 26 | \ 'skip': { 27 | \ 'header': '^;', 28 | \ 'block': ['^\s*"', '[^\\]"'], 29 | \ }, 30 | \ 31 | \ 'not_match_patterns': [ 32 | \ s:Util.shared_pattern('*', 'parameter_list'), 33 | \ ], 34 | \ 35 | \ 'heading_groups': { 36 | \ 'function' : ['defun', 'defmacro', 'defgeneric', 'defmethod'], 37 | \ 'variable' : ['defvar', 'defparameter', 'defconstant'], 38 | \ 'type' : ['defclass', 'defstruct', 'define-condition', 'deftype'], 39 | \ 'method-combination' : ['define-method-combination'], 40 | \ 'compiler-macro' : ['define-compiler-macro'], 41 | \ 'package' : ['defpackage'], 42 | \ }, 43 | \ 44 | \ 'highlight_rules': [ 45 | \ { 'name' : 'function', 46 | \ 'pattern' : '/ [^ ]* \zs.*/' }, 47 | \ { 'name' : 'type', 48 | \ 'pattern' : '/' . s:DEF_PATTERN . '/' }, 49 | \ { 'name' : 'special', 50 | \ 'pattern' : '/.*:: toplevel form/' }, 51 | \ ], 52 | \} 53 | 54 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 55 | let first_form = s:remove_feature_check(a:heading_line) 56 | let heading = { 57 | \ 'word' : s:splice_form(first_form), 58 | \ 'level': s:Util.get_indent_level(a:context, a:context.heading_lnum), 59 | \ 'type' : matchstr(first_form, '^\s*(\zs\S\+\ze'), 60 | \ } 61 | let form_args = matchstr(heading.word, '^\S\+\s\+\zs.*') 62 | 63 | " Whether we are checking a def* or a top-level form, fix the heading by 64 | " appending appropriate type information after `::'. 65 | if heading.type =~ '^' . s:DEF_PATTERN 66 | let heading.word = heading.type . ' ' . s:add_ldots(form_args) 67 | else 68 | let heading.word = s:add_ldots(heading.word) . ' :: toplevel form' 69 | endif 70 | return heading 71 | endfunction 72 | 73 | function! s:count_occurences(char, string) abort 74 | " Count number of occurences of {char} in {string}. 75 | return len(split(a:string, a:char, 1)) - 1 76 | endfunction 77 | 78 | function! s:has_balanced_chars(line, open, close) abort 79 | " Check whether {line} has balanced {open} and {close} characters. 80 | " Actually just fake it by checking if they appear same number of times 81 | let n_open_chars = s:count_occurences(a:open, a:line) 82 | if a:open == a:close 83 | return (n_open_chars % 2) == 0 84 | endif 85 | let n_close_chars = s:count_occurences(a:close, a:line) 86 | return n_open_chars == n_close_chars 87 | endfunction 88 | 89 | function! s:splice_form(line) abort 90 | " Remove the outermost parentheses from {line}. 91 | if s:has_balanced_chars(a:line, '(', ')') 92 | return matchstr(a:line, '^\s*(\zs.*\ze)\s*$') 93 | else 94 | return matchstr(a:line, '^\s*(\zs.*') 95 | endif 96 | endfunction 97 | 98 | function! s:remove_feature_check(line) abort 99 | " Remove the (#+|#-)[feature] expression from {line} if it exists. 100 | return matchstr(a:line, '^\(' . s:FEATURE_PATTERN . '\)\?\zs.*') 101 | endfunction 102 | 103 | function! s:add_ldots(line) abort 104 | " Add `...' to the end of {line} in case it has unbalanced parentheses or 105 | " quotes. 106 | if !s:has_balanced_chars(a:line, '(', ')') || !s:has_balanced_chars(a:line, '"', '"') 107 | return a:line . ' ...' 108 | endif 109 | return a:line 110 | endfunction 111 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/lua.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/lua.vim 3 | " Author : meryngii 4 | " Updated : 2013-03-31 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | function! unite#sources#outline#defaults#lua#outline_info() abort 12 | return s:outline_info 13 | endfunction 14 | 15 | let s:Util = unite#sources#outline#import('Util') 16 | 17 | "----------------------------------------------------------------------------- 18 | " Outline Info 19 | 20 | let s:outline_info = { 21 | \ 'heading' : '^\s*\%(local\s\+\)\=function\s\+\h', 22 | \ 'skip' : { 23 | \ 'block' : ['--\[\[', '--\]\]'], 24 | \ }, 25 | \ 'highlight_rules': [ 26 | \ { 'name' : 'comment', 27 | \ 'pattern' : '/--.*/' }, 28 | \ { 'name' : 'function', 29 | \ 'pattern' : '/\h\w*/' }, 30 | \ { 'name' : '_after_colon', 31 | \ 'pattern' : '/ : \h\w*/', 32 | \ 'highlight': unite#sources#outline#get_highlight('normal') }, 33 | \ ] 34 | \} 35 | 36 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 37 | let h_lnum = a:context.heading_lnum 38 | let level = s:Util.get_indent_level(a:context, h_lnum) 39 | 40 | let heading = { 41 | \ 'word' : a:heading_line, 42 | \ 'level': level, 43 | \ 'type' : 'generic', 44 | \ } 45 | 46 | let suffix = '' 47 | if heading.word =~ '\' 48 | let suffix = ' : local' 49 | end 50 | 51 | let heading.word = substitute(heading.word, '^\s*\%(local\s\+\)\=function\s\+', '', '') . suffix 52 | 53 | return heading 54 | endfunction 55 | 56 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/magma.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/magma.vim 3 | " Author : Sebastian Jambor 4 | " Updated : 2015-05-27 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Magma files 12 | " Version: 0.1.0 13 | 14 | function! unite#sources#outline#defaults#magma#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | " From the Magma handbook (http://magma.maths.usyd.edu.au/magma/handbook/): 24 | " Identifiers (names for user variables, functions etc.) must begin with a 25 | " letter, and this letter may be followed by any combination of letters or 26 | " digits, provided that the name is not a reserved word (see the chapter on 27 | " reserved words a complete list). In this definition the underscore _ is 28 | " treated as a letter. 29 | let s:identifierRegex = '\h[0-9a-zA-Z_]*' 30 | 31 | let s:outline_info = { 32 | \ 'heading': '\%(\\|\\|\\)', 33 | \ 'highlight_rules': [ 34 | \ { 35 | \ 'name' : 'type', 36 | \ 'pattern' : '/\\|\\|\/' 37 | \ }, 38 | \ { 39 | \ 'name' : 'function', 40 | \ 'pattern' : '/ ' . s:identifierRegex . '\ze (/' 41 | \ }, 42 | \ { 43 | \ 'name' : 'parameter_list', 44 | \ 'pattern' : '/(.*)/', 45 | \ }, 46 | \ ], 47 | \} 48 | 49 | function! s:strip(input_string) abort 50 | return substitute(a:input_string, '^\s*\(.\{-}\)\s*$', '\1', '') 51 | endfunction 52 | 53 | function! s:outline_info.create_heading( 54 | \which, heading_line, matched_line, context) 55 | let heading = { 56 | \ 'word' : a:heading_line, 57 | \ 'level' : 1, 58 | \ 'type' : 'function', 59 | \} 60 | 61 | if a:heading_line =~ '^\s*\%\(\\|\\|\\)' 62 | " function () 63 | " or 64 | " procedure () 65 | " or 66 | " intrinsic () 67 | let type = matchstr(a:heading_line, 68 | \'\%\(\\|\\|\\)') 69 | let func_name = matchstr(a:heading_line, 70 | \'^\s*' . type . '\s*\zs' . s:identifierRegex . '\ze\s*(') 71 | elseif a:heading_line =~ ':=\s*\%\(\\|\\)' 72 | " := function() 73 | " or 74 | " := procedure() 75 | let type = matchstr(a:heading_line, '\%\(\\|\\)') 76 | let func_name = matchstr(a:heading_line, 77 | \'^\s*\zs' . s:identifierRegex . '\ze\s*:=') 78 | else 79 | return {} 80 | endif 81 | 82 | " handle parameter lists which are spread over multiple lines; 83 | " ignore parameter lists which are spread over more than 20 lines 84 | let paramstarts = a:context.heading_lnum 85 | let paramends = a:context.heading_lnum 86 | while !(a:context.lines[paramends] =~ ')') && paramends - paramstarts < 20 87 | \&& paramends < len(a:context.lines) - 1 88 | let paramends += 1 89 | endwhile 90 | let paramline = join( 91 | \map(a:context.lines[paramstarts : paramends], 's:strip(v:val)')) 92 | 93 | let arg_list = matchstr(paramline, '(\zs.*\ze)') 94 | 95 | let heading.word = type . ' ' . func_name . ' (' . arg_list . ')' 96 | 97 | return heading 98 | endfunction 99 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/man.vim: -------------------------------------------------------------------------------- 1 | " ------------- - ------------------------------------------------------------ 2 | " File : autoload/unite/sources/outline/defaults/man.vim 3 | " Author : Zhao Cai 4 | " Email : caizhaoff@gmail.com 5 | " URL : 6 | " Version : 0.1 7 | " Date Created : Wed 25 Jul 2012 03:28:54 PM EDT 8 | " Last Modified : Thu 09 Aug 2012 02:39:40 AM EDT 9 | " 10 | " Licensed under the MIT license: 11 | " http://www.opensource.org/licenses/mit-license.php 12 | " ------------- - ------------------------------------------------------------ 13 | 14 | 15 | "--------------------------------------- 16 | " Sub Patterns 17 | 18 | let s:man_section_heading = '[a-zA-Z][a-zA-Z -_]*[a-zA-Z]' 19 | let s:man_sub_heading_leading_space = '\s\{3\}' 20 | let s:man_sub_heading = s:man_sub_heading_leading_space . s:man_section_heading 21 | 22 | "----------------------------------------------------------------------------- 23 | " Outline Info 24 | " 25 | " Assume: (no syntax callback from unite-outline) 26 | " unite#get_current_unite().abbr_head == 3 27 | " 28 | let s:outline_info = { 29 | \ 'heading': '^\(' . s:man_section_heading . '\|' . s:man_sub_heading . '\)$', 30 | \ 31 | \ 'highlight_rules': [ 32 | \ { 'name' : 'H1', 33 | \ 'pattern' : '/\%3c' . s:man_section_heading . '/', 34 | \ 'highlight' : 'htmlH1', 35 | \ }, 36 | \ { 'name' : 'H2', 37 | \ 'pattern' : '/\%3c\s\+' . s:man_section_heading . '/', 38 | \ 'highlight' : 'htmlH2' 39 | \ }, 40 | \ ], 41 | \} 42 | 43 | 44 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 45 | 46 | let heading = { 47 | \ 'word' : a:heading_line, 48 | \ 'level': 0, 49 | \ 'type' : 'generic', 50 | \ } 51 | 52 | if a:heading_line =~ '^' . s:man_section_heading . '$' 53 | let heading.level = 1 54 | elseif a:heading_line =~ '^' . s:man_sub_heading . '$' 55 | let heading.level = 2 56 | endif 57 | 58 | if heading.level > 0 59 | return heading 60 | else 61 | return {} 62 | endif 63 | endfunction 64 | 65 | 66 | " Default outline info for man files 67 | 68 | function! unite#sources#outline#defaults#man#outline_info() abort 69 | return s:outline_info 70 | endfunction 71 | 72 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/markdown.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/markdown.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Markdown 12 | " Version: 0.0.5 13 | 14 | function! unite#sources#outline#defaults#markdown#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | "----------------------------------------------------------------------------- 19 | " Outline Info 20 | 21 | let s:outline_info = { 22 | \ 'heading' : '^#\+', 23 | \ 'heading+1': '^[-=]\+$', 24 | \ 'skip': {'block': ['^\s*```.*$', '^\s*```$']}, 25 | \ } 26 | 27 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 28 | let heading = { 29 | \ 'word' : a:heading_line, 30 | \ 'level': 0, 31 | \ 'type' : 'generic', 32 | \ } 33 | 34 | if a:which ==# 'heading' 35 | let heading.level = strlen(matchstr(a:heading_line, '^#\+')) 36 | let heading.word = substitute(heading.word, '^#\+\s*', '', '') 37 | let heading.word = substitute(heading.word, '\s*#\+\s*$', '', '') 38 | elseif a:which ==# 'heading+1' 39 | if a:matched_line =~ '^=' 40 | let heading.level = 1 41 | else 42 | let heading.level = 2 43 | endif 44 | endif 45 | 46 | if heading.level > 0 47 | let heading.word = substitute(heading.word, '\s*]*>\s*\%(\s*\)\=$', '', '') 48 | return heading 49 | else 50 | return {} 51 | endif 52 | endfunction 53 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/perl.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/perl.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Perl 12 | " Version: 0.1.0 13 | 14 | function! unite#sources#outline#defaults#perl#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': s:Util.shared_pattern('sh', 'heading-1'), 25 | \ 'heading' : '^\%(\s*\%(sub\s\+\h\|subtest\s\+["'']\?\h\|\%(package\|BEGIN\|CHECK\|INIT\|END\)\>\)\|__\%(DATA\|END\)__$\)', 26 | \ 27 | \ 'skip': { 28 | \ 'header': s:Util.shared_pattern('sh', 'header'), 29 | \ 'block' : ['^=\%(cut\)\@!\w\+', '^=cut'], 30 | \ }, 31 | \ 32 | \ 'highlight_rules': [ 33 | \ { 'name' : 'comment', 34 | \ 'pattern' : '/#.*/' }, 35 | \ { 'name' : 'sub', 36 | \ 'pattern' : '/\h\w*/', 37 | \ 'highlight': unite#sources#outline#get_highlight('function') }, 38 | \ { 'name' : 'subtest', 39 | \ 'pattern' : '/\h\w*/', 40 | \ 'highlight': unite#sources#outline#get_highlight('normal') }, 41 | \ { 'name' : 'block', 42 | \ 'pattern' : '/\<\%(BEGIN\|CHECK\|INIT\|END\|__\%(DATA\|END\)__\)\>/', 43 | \ 'highlight': unite#sources#outline#get_highlight('special') }, 44 | \ { 'name' : 'package', 45 | \ 'pattern' : '/\S\+\ze : package/', 46 | \ 'highlight': unite#sources#outline#get_highlight('type') }, 47 | \ { 'name' : '_after_colon', 48 | \ 'pattern' : '/ : \h\w*/', 49 | \ 'highlight': unite#sources#outline#get_highlight('normal') }, 50 | \ ], 51 | \} 52 | 53 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 54 | let h_lnum = a:context.heading_lnum 55 | " Level 1 to 3 are reserved for comment headings. 56 | let level = s:Util.get_indent_level(a:context, h_lnum) + 3 57 | let heading = { 58 | \ 'word' : a:heading_line, 59 | \ 'level': level, 60 | \ 'type' : 'generic', 61 | \ } 62 | 63 | if a:which == 'heading-1' && a:heading_line =~ '^\s*#' 64 | let m_lnum = a:context.matched_lnum 65 | let heading.type = 'comment' 66 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum) 67 | elseif a:which == 'heading' 68 | if a:heading_line =~ '^\s*package\>' 69 | let heading.word = substitute(heading.word, ';\s*$', '', '') 70 | let heading.word = substitute(heading.word, '^\s*\zspackage\s\+', '', '') . ' : package' 71 | else 72 | let heading.word = substitute(heading.word, '\\s*q\?[''"]\(.*\)[''"]\s.*$', '\1 : subtest', '') 73 | let heading.word = substitute(heading.word, '\', '', '') 74 | let heading.word = substitute(heading.word, '\s*{.*$', '', '') 75 | let heading.level += 1 76 | endif 77 | endif 78 | return heading 79 | endfunction 80 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/php.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/php.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Contributed by hamaco 7 | " 8 | " Licensed under the MIT license: 9 | " http://www.opensource.org/licenses/mit-license.php 10 | " 11 | "============================================================================= 12 | 13 | " Default outline info for PHP 14 | " Version: 0.1.2 15 | 16 | function! unite#sources#outline#defaults#php#outline_info() abort 17 | return s:outline_info 18 | endfunction 19 | 20 | let s:Util = unite#sources#outline#import('Util') 21 | 22 | "--------------------------------------- 23 | " Sub Pattern 24 | 25 | let s:pat_type = '\%(interface\|class\|trait\|function\)\>' 26 | 27 | "----------------------------------------------------------------------------- 28 | " Outline Info 29 | 30 | let s:outline_info = { 31 | \ 'heading-1': s:Util.shared_pattern('cpp', 'heading-1'), 32 | \ 'heading' : '^\s*\%(\h\w*\s\+\)*' . s:pat_type, 33 | \ 34 | \ 'skip': { 35 | \ 'header': { 36 | \ 'leading': '^\%(' 80 | " Interface 81 | let heading.type = 'interface' 82 | let heading.word = matchstr(heading.word, '\zs\' 84 | " Class 85 | let heading.type = 'class' 86 | let heading.word = matchstr(heading.word, '\zs\' 88 | " Trait 89 | let heading.type = 'trait' 90 | let heading.word = matchstr(heading.word, '\zs\' 96 | let heading.word = '+ ' . heading.word 97 | elseif modifiers =~ '^\s*protected\>' 98 | let heading.word = '# ' . heading.word 99 | elseif modifiers =~ '^\s*private\>' 100 | let heading.word = '- ' . heading.word 101 | elseif heading.level > 3 102 | let heading.word = substitute(heading.word, '\%(&\|\h\)\@=', '+ ', '') 103 | endif 104 | let heading.word = substitute(heading.word, '\S\zs(', ' (', '') 105 | endif 106 | " Append modifiers. 107 | let modifiers = substitute(modifiers, '\%(public\|protected\|private\)', '', 'g') 108 | if modifiers !~ '^\s*$' 109 | let heading.word .= ' <' . join(split(modifiers, '\s\+'), ',') . '>' 110 | endif 111 | endif 112 | return heading 113 | endfunction 114 | 115 | function! s:outline_info.need_blank_between(cand1, cand2, memo) abort 116 | if a:cand1.source__heading_group == 'function' && a:cand2.source__heading_group == 'function' 117 | " Don't insert a blank between two sibling functions. 118 | return 0 119 | else 120 | return (a:cand1.source__heading_group != a:cand2.source__heading_group || 121 | \ a:cand1.source__has_marked_child || a:cand2.source__has_marked_child) 122 | endif 123 | endfunction 124 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/pir.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/pir.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for PIR 12 | " Version: 0.0.3 (draft) 13 | 14 | function! unite#sources#outline#defaults#pir#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': s:Util.shared_pattern('sh', 'heading-1'), 25 | \ 'heading' : '^\.sub\>', 26 | \ 27 | \ 'skip': { 28 | \ 'header': s:Util.shared_pattern('sh', 'header'), 29 | \ 'block' : ['^=\%(cut\)\@!\w\+', '^=cut'], 30 | \ }, 31 | \} 32 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/pony.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/pony.vim 3 | " Author : locksfree 4 | " Updated : 2016-07-17 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Pony 12 | " Version: 0.1.0 13 | 14 | function! unite#sources#outline#defaults#pony#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "--------------------------------------- 21 | " Sub Pattern 22 | 23 | let s:pat_type = '\%(interface\|be\|type\|class\|trait\|actor\|fun\|new\|primitive\)\>' 24 | let s:pat_typename = '\%(iso\|trn\|ref\|tag\|val\|box\)\?\s*\zs\h\%(\w\+\)' 25 | 26 | "----------------------------------------------------------------------------- 27 | " Outline Info 28 | 29 | let s:outline_info = { 30 | \ 'heading' : '^\s*\%(\h\w*\s\+\)*' . s:pat_type, 31 | \ 32 | \ 'heading_groups': { 33 | \ 'type' : ['type', 'interface', 'class', 'trait', 'actor', 'primitive'], 34 | \ 'function' : ['fun', 'new', 'be'], 35 | \ }, 36 | \ 'not_match_patterns': [ 37 | \ s:Util.shared_pattern('*', 'parameter_list'), 38 | \ ], 39 | \ 40 | \ 'highlight_rules': [ 41 | \ { 'name' : 'type', 42 | \ 'pattern': '/\S\+\ze : \%(interface\|class\|trait\|actor\|type\|primitive\)/' }, 43 | \ { 'name' : 'function', 44 | \ 'pattern': '/\(new\|be\|fun\)/' }, 45 | \ { 'name' : 'parameter_list', 46 | \ 'pattern': '/(.*)/' }, 47 | \ ], 48 | \} 49 | 50 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 51 | let h_lnum = a:context.heading_lnum 52 | let level = s:Util.get_indent_level(a:context, h_lnum) 53 | let heading = { 54 | \ 'word' : a:heading_line, 55 | \ 'level': level, 56 | \ 'type' : 'generic', 57 | \ } 58 | 59 | if a:which ==# 'heading' 60 | let heading.word = substitute(heading.word, '\s*{.*$', '', '') 61 | 62 | let heading_type = '' 63 | if heading.word =~# '^\s*interface\>' 64 | let heading_type = 'interface' 65 | elseif heading.word =~# '^\s*class\>' 66 | let heading_type = 'class' 67 | elseif heading.word =~# '^\s*trait\>' 68 | let heading_type = 'trait' 69 | elseif heading.word =~# '^\s*actor\>' 70 | let heading_type = 'actor' 71 | elseif heading.word =~# '^\s*type\>' 72 | let heading_type = 'type' 73 | elseif heading.word =~# '^\s*primitive\>' 74 | let heading_type = 'primitive' 75 | endif 76 | if heading_type !=# '' 77 | let heading.type = 'type' 78 | let heading.level = 1 79 | endif 80 | 81 | if heading.type !=# 'generic' 82 | let name = matchstr(heading.word, '\zs\<' . heading_type . '\s\+' . s:pat_typename) 83 | if len(name) > 0 84 | let heading.word = name . ' : ' . heading_type 85 | else 86 | let heading.word = '' 87 | let heading.type = 'generic' 88 | end 89 | end 90 | 91 | if heading.word =~# '^\s*\%(fun\|be\|new\)\>' 92 | " Function / Behaviour / Constructor 93 | let heading.type = 'function' 94 | let heading.level = 2 95 | let fun_type = matchstr(heading.word, '\%(fun\|be\|new\)') 96 | 97 | " There might be a receiver capability, we need to get it if it is there 98 | let receiver_capa = matchstr(heading.word, '\%(fun\|be\|new\)\s\+\%(ref\|box\|trn\|iso\|val\|tag\)') 99 | let receiver_capa = matchstr(receiver_capa, '\%(ref\|box\|trn\|iso\|val\|tag\)', '') 100 | if len(receiver_capa) > 0 101 | let receiver_capa = '[' . receiver_capa . '] ' 102 | endif 103 | 104 | " There might be a return type, we need to get it if it is there 105 | let return_type = matchstr(heading.word, '[\)]\s*\:\%([^>]\+\)\%([=][>]\|$\)') 106 | if len(return_type) > 0 107 | let return_type = matchstr(return_type, ':.*', '') 108 | let return_type = substitute(return_type, '\%(^\s\+\|\s\+$\)', '', 'g') 109 | 110 | " The line may end with the start/full body starting with => or 111 | " simply stop mid way $ 112 | if len(matchstr(return_type, '[=][>]')) > 0 113 | let return_type = return_type[1:-4] 114 | else 115 | let return_type = return_type[1:-2] 116 | endif 117 | let return_type = ' : ' . substitute(return_type, '\%(^\s\+\|\s\+$\)', '', 'g') 118 | endif 119 | 120 | " Let's extract the name 121 | let name = matchstr(heading.word, '\zs\<' . fun_type . '\(\s\+\zs\h\w*\)\+') 122 | 123 | " Let's indicate the visibility (+ or -) for package or public 124 | let prefix = '+ ' 125 | if len(matchstr(name, '^\s*[_]')) > 0 126 | let prefix = '- ' 127 | end 128 | 129 | let heading.word = prefix . fun_type . ' ' . receiver_capa . name . '(...)' . return_type 130 | endif 131 | 132 | " For anything but a function, we need to put the visibility 133 | if heading.type !=# 'function' && heading.type !=# 'generic' 134 | let prefix = '+ ' 135 | if len(matchstr(heading.word, '^\s*[_]')) > 0 136 | let prefix = '- ' 137 | endif 138 | let heading.word = prefix . heading.word 139 | endif 140 | 141 | if len(substitute(heading.word, '\%(^\s\+\|\s\+$\)', '', 'g')) == 0 || heading.type ==# 'generic' 142 | let heading = {} 143 | endif 144 | endif 145 | 146 | return heading 147 | endfunction 148 | 149 | function! s:outline_info.need_blank_between(cand1, cand2, memo) abort 150 | if a:cand1.source__heading_type ==# 'function' && a:cand2.source__heading_type ==# 'function' 151 | " Don't insert a blank between two sibling functions. 152 | return 0 153 | else 154 | return a:cand1.source__has_marked_child || a:cand2.source__has_marked_child 155 | endif 156 | endfunction 157 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/pug.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File: autoload/unite/sources/outline/defaults/pug.vim 3 | " Author: Jens Himmelreich 4 | " Version: 0.1.0 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | "============================================================================= 9 | let s:Util = unite#sources#outline#import('Util') 10 | let s:MaxLevel = 4 11 | 12 | let s:heading = '^\s\{,' . s:MaxLevel . '}\S\+' 13 | 14 | let s:outline_info = { 15 | \ 'heading': s:heading 16 | \ } 17 | 18 | function! unite#sources#outline#defaults#pug#outline_info() abort 19 | return s:outline_info 20 | endfunction 21 | 22 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 23 | let h_lnum = a:context.heading_lnum 24 | let level = s:Util.get_indent_level(a:context, h_lnum) 25 | let heading = { 26 | \ 'word' : a:heading_line, 27 | \ 'level': level, 28 | \ 'type' : 'generic', 29 | \ } 30 | return heading 31 | endfunction 32 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/python.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/python.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Python 12 | " Version: 0.2.0 13 | 14 | function! unite#sources#outline#defaults#python#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading' : '^\s*\%(class\|\%(async\s\+\)\=def\)\>', 25 | \ 26 | \ 'skip': { 27 | \ 'header': s:Util.shared_pattern('sh', 'header'), 28 | \ 'block' : ['r\="""', '\\\@' 60 | " Class 61 | let heading.type = 'class' 62 | let heading.word = matchstr(heading.word, '^\s*class\s\+\zs\h\w*') . ' : class' 63 | elseif heading.word =~ '^\s*\%(async\s\+\)\=def\>' 64 | " Function 65 | let heading.type = 'function' 66 | let heading.word = substitute(heading.word, '\<\%(async\s\+\)\=def\s*', '', '') 67 | let heading.word = substitute(heading.word, '\S\zs(', ' (', '') 68 | let heading.word = substitute(heading.word, '\%(:\|#\).*$', '', '') 69 | endif 70 | return heading 71 | endfunction 72 | 73 | function! s:outline_info.need_blank_between(cand1, cand2, memo) abort 74 | if a:cand1.source__heading_group == 'function' && a:cand2.source__heading_group == 'function' 75 | " Don't insert a blank between two sibling functions. 76 | return 0 77 | else 78 | return (a:cand1.source__heading_group != a:cand2.source__heading_group || 79 | \ a:cand1.source__has_marked_child || a:cand2.source__has_marked_child) 80 | endif 81 | endfunction 82 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/review.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/review.vim 3 | " Author : AKAMATSU Yuki 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for ReVIEW 12 | " Version: 0.0.2 13 | 14 | function! unite#sources#outline#defaults#review#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | "----------------------------------------------------------------------------- 19 | " Outline Info 20 | 21 | let s:outline_info = { 22 | \ 'heading': '^=\+', 23 | \ } 24 | 25 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 26 | let heading = { 27 | \ 'word' : substitute(a:heading_line, '^=\+\s*', '', ''), 28 | \ 'level': strlen(matchstr(a:heading_line, '^=\+')), 29 | \ 'type' : 'generic', 30 | \ } 31 | if heading.word !~ '^\[/' 32 | return heading 33 | else 34 | return {} 35 | endif 36 | endfunction 37 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/rst.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/rst.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for reStructuredText 12 | " Version: 0.0.3 13 | 14 | function! unite#sources#outline#defaults#rst#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | "----------------------------------------------------------------------------- 19 | " Outline Info 20 | 21 | let s:outline_info = { 22 | \ 'heading+1': '^[[:punct:]]\{4,}$', 23 | \ } 24 | 25 | function! s:outline_info.before(context) abort 26 | let s:adornment_levels = {} 27 | let s:adornment_id = 2 28 | endfunction 29 | 30 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 31 | let heading = { 32 | \ 'word' : a:heading_line, 33 | \ 'level': 0, 34 | \ 'type' : 'generic', 35 | \ } 36 | 37 | let lines = a:context.lines 38 | let h_lnum = a:context.heading_lnum 39 | 40 | " Check the matching strictly. 41 | if a:matched_line =~ '^\([[:punct:]]\)\1\{3,}$' 42 | if h_lnum > 1 && lines[h_lnum - 1] == a:matched_line 43 | " Title 44 | let heading.level = 1 45 | else 46 | " Sections 47 | let adchar = a:matched_line[0] 48 | if !has_key(s:adornment_levels, adchar) 49 | let s:adornment_levels[adchar] = s:adornment_id 50 | let s:adornment_id += 1 51 | endif 52 | let heading.level = s:adornment_levels[adchar] 53 | endif 54 | endif 55 | 56 | if heading.level > 0 57 | return heading 58 | else 59 | return {} 60 | endif 61 | endfunction 62 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/ruby.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/ruby.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Ruby 12 | " Version: 0.1.5 13 | 14 | function! unite#sources#outline#defaults#ruby#outline_info(...) abort 15 | if a:0 16 | " Redirect to DSL's outline info. 17 | let context = a:1 18 | let path = context.buffer.path 19 | if path =~ '_spec\.rb$' 20 | " RSpec 21 | return 'ruby/rspec' 22 | endif 23 | endif 24 | return s:outline_info 25 | endfunction 26 | 27 | let s:Util = unite#sources#outline#import('Util') 28 | 29 | "----------------------------------------------------------------------------- 30 | " Outline Info 31 | 32 | let s:outline_info = { 33 | \ 'heading-1': s:Util.shared_pattern('sh', 'heading-1'), 34 | \ 'heading_keywords': [ 35 | \ 'module', 'class', 'protected', 'private', 36 | \ 'def', '[mc]\=attr_\(accessor\|reader\|writer\)', 'alias', 37 | \ 'BEGIN', 'END', '__END__', 38 | \ ], 39 | \ 40 | \ 'skip': { 41 | \ 'header': s:Util.shared_pattern('sh', 'header'), 42 | \ 'block' : ['^=begin', '^=end'], 43 | \ }, 44 | \ 45 | \ 'heading_groups': { 46 | \ 'type' : ['module', 'class'], 47 | \ 'method': ['method'], 48 | \ }, 49 | \ 50 | \ 'not_match_patterns': [ 51 | \ s:Util.shared_pattern('*', 'parameter_list'), 52 | \ ], 53 | \ 54 | \ 'highlight_rules': [ 55 | \ { 'name' : 'comment', 56 | \ 'pattern' : '/#.*/' }, 57 | \ { 'name' : 'method', 58 | \ 'pattern' : '/:\@\)\@![_[:alnum:]=\[\]<>!?.]\+/' }, 59 | \ { 'name' : 'type', 60 | \ 'pattern' : '/\S\+\ze : \%(module\|class\)/' }, 61 | \ { 'name' : 'eigen_class', 62 | \ 'pattern' : '/\/', 66 | \ 'highlight': unite#sources#outline#get_highlight('special') }, 67 | \ { 'name' : 'meta_method', 68 | \ 'pattern' : '/\' 77 | endfunction 78 | 79 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 80 | let word = a:heading_line 81 | let type = 'generic' 82 | let level = 0 83 | 84 | if a:which == 'heading-1' && a:heading_line =~ '^\s*#' 85 | let m_lnum = a:context.matched_lnum 86 | let type = 'comment' 87 | let level = s:Util.get_comment_heading_level(a:context, m_lnum) 88 | 89 | elseif a:which == 'heading' 90 | let h_lnum = a:context.heading_lnum 91 | let level = s:Util.get_indent_level(a:context, h_lnum) + 3 92 | " NOTE: Level 1 to 3 are reserved for toplevel comment headings. 93 | 94 | let matches = matchlist(a:heading_line, self.heading) 95 | let keyword = matches[1] 96 | let type = keyword 97 | 98 | if keyword == 'module' || keyword == 'class' 99 | if word =~ '\s\+<<\s\+' 100 | " Eigen-class 101 | else 102 | " Module, Class 103 | let word = substitute(matchstr(word, '^\s*\%(module\|class\)\s\+\zs\h\%(\w\|\s*::\s*\)*'),'\s*','','g') . ' : ' . keyword 104 | endif 105 | elseif keyword == 'protected' || keyword == 'private' 106 | " Accessibility 107 | let indented = 0 108 | for idx in range(1, 5) 109 | let line = get(a:context.lines, h_lnum + idx, '') 110 | if line =~ '\S' 111 | let indented = level < s:Util.get_indent_level(a:context, h_lnum + idx) + 3 112 | break 113 | endif 114 | endfor 115 | if !indented 116 | let level = 0 117 | endif 118 | elseif keyword == 'def' 119 | if word =~ '#{' 120 | " Meta-method 121 | else 122 | " Method 123 | let type = 'method' 124 | let word = substitute(word, '\.*', '', '') 133 | let word = substitute(word, '\s*:', ' ', 'g') . ' : ' . access 134 | elseif keyword == 'alias' 135 | " Alias 136 | let type = 'method' 137 | let word = substitute(word, '\ \2', '') 139 | elseif keyword =~ '^\%(BEGIN\|END\)$' 140 | " BEGIN, END 141 | let word = substitute(word, '\s*{.*$', '', '') 142 | else 143 | " __END__ 144 | endif 145 | let word = substitute(word, '\%(;\|#{\@!\).*$', '', '') 146 | endif 147 | 148 | if level > 0 149 | let heading = { 150 | \ 'word' : word, 151 | \ 'level': level, 152 | \ 'type' : type, 153 | \ } 154 | else 155 | let heading = {} 156 | endif 157 | return heading 158 | endfunction 159 | 160 | function! s:outline_info.fold_ruby_block(context, lnum) abort 161 | let line = a:context.lines[a:lnum] 162 | let indent = matchlist(line, '^\(\s*\)')[1] 163 | let line = s:Util.join_to(a:context, a:lnum, indent . '%\(end\>\|}\)') 164 | let line = substitute(line, '\s*\n\s*', '; ', 'g') 165 | let line = substitute(substitute(line, 'do;', '{', ''), '; end', ' }', '') 166 | return line 167 | endfunction 168 | 169 | function! s:outline_info.need_blank_between(cand1, cand2, memo) abort 170 | if a:cand1.source__heading_group == 'method' && a:cand2.source__heading_group == 'method' 171 | " Don't insert a blank between two sibling methods. 172 | return 0 173 | else 174 | return (a:cand1.source__heading_group != a:cand2.source__heading_group || 175 | \ a:cand1.source__has_marked_child || a:cand2.source__has_marked_child) 176 | endif 177 | endfunction 178 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/ruby/rspec.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/ruby/rspec.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Contributed by kenchan 7 | " 8 | " Licensed under the MIT license: 9 | " http://www.opensource.org/licenses/mit-license.php 10 | " 11 | "============================================================================= 12 | 13 | " Default outline info for Ruby/RSpec 14 | " Version: 0.1.2 15 | 16 | function! unite#sources#outline#defaults#ruby#rspec#outline_info() abort 17 | return s:outline_info 18 | endfunction 19 | 20 | let s:Util = unite#sources#outline#import('Util') 21 | 22 | "----------------------------------------------------------------------------- 23 | " Outline Info 24 | 25 | " Inherit Ruby's outline info. 26 | let s:super = unite#sources#outline#get_outline_info('ruby', 1, 1) 27 | 28 | let s:outline_info = deepcopy(s:super) 29 | call extend(s:outline_info, { 30 | \ 'super': s:super, 31 | \ 32 | \ 'rspec_heading_keywords': [ 33 | \ 'shared\=_\%(as\|context\|examples\%(_for\)\=\)', 34 | \ 'describe', 'context', 'before', 'after', 'let!\=', 35 | \ 'subject\%(\s*\%(do\|{\)\)\@=', 'it\%(_\w\+\|s\)\=', 'specify', 36 | \ ], 37 | \ 38 | \ 'not_match_patterns': [ 39 | \ '^\s*\%(let!\=\)\@!\S\+\s*\zs([^)]*)', 40 | \ ], 41 | \ 42 | \ 'rspec_highlight_rules': [ 43 | \ { 'name' : 'shared_context', 44 | \ 'pattern' : '/\.*/', 45 | \ 'highlight': unite#sources#outline#get_highlight('rspec_shared_context', 'level_1') }, 46 | \ { 'name' : 'behavior', 47 | \ 'pattern' : '/\<\%(describe\|context\)\>.*/', 48 | \ 'highlight': unite#sources#outline#get_highlight('rspec_behaviour', 'level_1') }, 49 | \ { 'name' : 'hook', 50 | \ 'pattern' : '/\<\%(before\|after\)\>.*/', 51 | \ 'highlight': unite#sources#outline#get_highlight('rspec_hook', 'level_3') }, 52 | \ { 'name' : 'let', 53 | \ 'pattern' : '/\.*/', 54 | \ 'highlight': unite#sources#outline#get_highlight('rspec_let', 'level_3') }, 55 | \ { 'name' : 'subject', 56 | \ 'pattern' : '/\.*/', 57 | \ 'highlight': unite#sources#outline#get_highlight('rspec_subject', 'level_2') }, 58 | \ { 'name' : 'example', 59 | \ 'pattern' : '/\<\%(it\%(_\w\+\|s\)\=\|specify\)\>.*/', 60 | \ 'highlight': unite#sources#outline#get_highlight('rspec_example', 'level_2') }, 61 | \ ], 62 | \}) 63 | 64 | function! s:outline_info.initialize() abort 65 | let self.rspec_heading = '^\s*\(' . join(self.rspec_heading_keywords, '\|') . '\)\>' 66 | let self.heading_keywords += self.rspec_heading_keywords 67 | let self.highlight_rules += self.rspec_highlight_rules 68 | call call(self.super.initialize, [], self) 69 | endfunction 70 | 71 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 72 | let word = a:heading_line 73 | let type = 'generic' 74 | let level = 0 75 | 76 | if a:which == 'heading' && a:heading_line =~ self.rspec_heading 77 | let h_lnum = a:context.heading_lnum 78 | let level = s:Util.get_indent_level(a:context, h_lnum) + 3 79 | " NOTE: Level 1 to 3 are reserved for toplevel comment headings. 80 | 81 | let type = 'rspec' 82 | let word = substitute(word, '\s*\%(do\|{\)\%(\s*|[^|]*|\)\=\s*$', '', '') 83 | "let word = substitute(word, '\%(;\|#{\@!\).*$', '', '') 84 | 85 | if word =~ '^\s*\%(subject\|it\)\s*$' 86 | let word = self.fold_ruby_block(a:context, h_lnum) 87 | endif 88 | endif 89 | 90 | if level > 0 91 | let heading = { 92 | \ 'word' : word, 93 | \ 'level': level, 94 | \ 'type' : type, 95 | \ } 96 | else 97 | let heading = call(self.super.create_heading, 98 | \ [a:which, a:heading_line, a:matched_line, a:context], self.super) 99 | endif 100 | return heading 101 | endfunction 102 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/rust.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/rust.vim 3 | " Author : OliverUv 4 | " Updated : 2017-10-26 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Rust 12 | " Version: 0.0.1 13 | 14 | " Assumes that you have added these lines to your ctags configuration: 15 | " https://github.com/rust-lang/rust/blob/master/src/etc/ctags.rust 16 | " (Tested with commit aede1c73bd2e5540bb62216bff23362e9d8b55a9) 17 | 18 | function! unite#sources#outline#defaults#rust#outline_info() abort 19 | return s:outline_info 20 | endfunction 21 | 22 | let s:Ctags = unite#sources#outline#import('Ctags') 23 | let s:Util = unite#sources#outline#import('Util') 24 | 25 | "----------------------------------------------------------------------------- 26 | " Outline Info 27 | 28 | let s:outline_info = { 29 | \ 'highlight_rules': [ 30 | \ { 'name' : 'macro', 31 | \ 'pattern': '/\S\+\ze : macros/' }, 32 | \ { 'name' : 'id', 33 | \ 'pattern': '/.\+\ze : impls/' }, 34 | \ { 'name' : 'level_3', 35 | \ 'pattern': '/\S\+\ze : trait/' }, 36 | \ { 'name' : 'type', 37 | \ 'pattern': '/\S\+\ze : \%(types\|structure names\)/' }, 38 | \ { 'name' : 'function', 39 | \ 'pattern': '/\S\+\ze : function/' }, 40 | \ { 'name' : 'level_4', 41 | \ 'pattern': '/\S\+\ze : const/' }, 42 | \ ], 43 | \} 44 | 45 | function! s:outline_info.extract_headings(context) abort 46 | return s:Ctags.extract_headings(a:context) 47 | endfunction 48 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/sass.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/sass.vim 3 | " Author : roylez 4 | " Updated : 2015-05-07 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for SASS 12 | " Version: 0.0.1 13 | 14 | function! unite#sources#outline#defaults#sass#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': s:Util.shared_pattern('cpp', 'heading-1'), 25 | \ 'header' : '^//|^/\*', 26 | \} 27 | 28 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 29 | let heading = { 30 | \ 'word' : a:heading_line, 31 | \ 'level': 0, 32 | \ 'type' : 'generic', 33 | \ } 34 | 35 | if a:which ==# 'heading-1' 36 | let m_lnum = a:context.matched_lnum 37 | let heading.type = 'comment' 38 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum, 4) 39 | endif 40 | 41 | if heading.level > 0 42 | return heading 43 | else 44 | return {} 45 | endif 46 | endfunction 47 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/scala.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/scala.vim 3 | " Author : thinca 4 | " Updated : 2012-01-11 5 | " 6 | " License : Creative Commons Attribution 2.1 Japan License 7 | " 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Scala 12 | " Version: 0.1.3 13 | 14 | let g:unite_source_outline_scala_show_all_declarations = 15 | \ get(g:, 'unite_source_outline_scala_show_all_declarations', 0) 16 | 17 | function! unite#sources#outline#defaults#scala#outline_info() abort 18 | return s:outline_info 19 | endfunction 20 | 21 | let s:Util = unite#sources#outline#import('Util') 22 | 23 | "--------------------------------------- 24 | " Sub Pattern 25 | 26 | let s:pat_def_prefix='\%(\h\w*\(\[[^\]]\+]\)\?\s\+\)*' 27 | if g:unite_source_outline_scala_show_all_declarations 28 | let s:pat_def='\<\%(class\|object\|trait\|def\|var\|val\|type\)\>' 29 | else 30 | let s:pat_def='\<\%(class\|object\|trait\|def\)\>' 31 | endif 32 | let s:pat_bol='^\s*' 33 | 34 | let s:pat_heading = s:pat_bol.s:pat_def_prefix.'\zs'.s:pat_def 35 | 36 | "----------------------------------------------------------------------------- 37 | " Outline Info 38 | 39 | let s:outline_info = { 40 | \ 'heading-1': s:Util.shared_pattern('cpp', 'heading-1'), 41 | \ 'heading' : s:pat_heading, 42 | \ 43 | \ 'skip': { 44 | \ 'header': s:Util.shared_pattern('cpp', 'header'), 45 | \ }, 46 | \ 47 | \ 'not_match_patterns': [ 48 | \ s:pat_bol.s:pat_def_prefix.s:pat_def.'\s\+[^[:space:](\[:]\+\zs.\*', 49 | \ s:Util.shared_pattern('*', 'after_lparen'), 50 | \ s:Util.shared_pattern('*', 'after_colon'), 51 | \ ], 52 | \ 'highlight_rules': [ 53 | \ {'name': 'def', 'pattern': '/'.s:pat_def_prefix.s:pat_def.'/', 'highlight': 'Comment'}, 54 | \ {'name': 'args', 'pattern': '/\%([\[({]\|\<\%(extends\|with\)\>\).*/', 'highlight': 'Comment'}, 55 | \ ] 56 | \} 57 | 58 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 59 | let h_lnum = a:context.heading_lnum 60 | " Level 1 to 3 are reserved for comment headings. 61 | let level = s:Util.get_indent_level(a:context, h_lnum) + 3 62 | let heading = { 63 | \ 'word' : a:heading_line, 64 | \ 'level': level, 65 | \ 'type' : 'generic', 66 | \ } 67 | 68 | if a:which == 'heading-1' && s:Util._cpp_is_in_comment(a:heading_line, a:matched_line) 69 | let m_lnum = a:context.matched_lnum 70 | let heading.type = 'comment' 71 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum) 72 | elseif a:which == 'heading' 73 | let heading.type = matchstr(a:matched_line, s:pat_heading) 74 | let heading.word = matchstr(a:heading_line, '^.\{-}\ze\%(\s\+=\%(\s.*\)\?\|\s*{\s*\)\?$') 75 | endif 76 | return heading 77 | endfunction 78 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/scheme.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/scheme.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Scheme 12 | " Version: 0.0.6 (draft) 13 | 14 | function! unite#sources#outline#defaults#scheme#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': '^\s*;\+\s*[-=]\{10,}\s*$', 25 | \ 'heading' : '^\s*(define\>', 26 | \ 27 | \ 'skip': { 'header': '^;' }, 28 | \} 29 | 30 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 31 | let heading = { 32 | \ 'word' : a:heading_line, 33 | \ 'level': 0, 34 | \ 'type' : 'generic', 35 | \ } 36 | 37 | if a:which ==# 'heading-1' && a:heading_line =~ '^\s*;' 38 | let m_lnum = a:context.matched_lnum 39 | let heading.type = 'comment' 40 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum, 5) 41 | elseif a:which ==# 'heading' 42 | let heading.level = 4 43 | endif 44 | 45 | if heading.level > 0 46 | return heading 47 | else 48 | return {} 49 | endif 50 | endfunction 51 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/scss.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/scss.vim 3 | " Author : roylez 4 | " Updated : 2015-05-07 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for SCSS 12 | " Version: 0.0.1 13 | 14 | function! unite#sources#outline#defaults#scss#outline_info() abort 15 | return unite#sources#outline#defaults#css#outline_info() 16 | endfunction 17 | 18 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/sh.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/sh.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Shell script 12 | " Version: 0.1.0 13 | 14 | function! unite#sources#outline#defaults#sh#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': s:Util.shared_pattern('sh', 'heading-1'), 25 | \ 'heading' : '^\s*\%(\w\+\s*()\|function\>\)', 26 | \ 27 | \ 'skip': { 28 | \ 'header': s:Util.shared_pattern('sh', 'header'), 29 | \ }, 30 | \ 31 | \ 'highlight_rules': [ 32 | \ { 'name' : 'comment', 33 | \ 'pattern' : '/#.*/' }, 34 | \ { 'name' : 'function', 35 | \ 'pattern' : '/\h\w*/' }, 36 | \ ], 37 | \} 38 | 39 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 40 | let heading = { 41 | \ 'word' : a:heading_line, 42 | \ 'level': 0, 43 | \ 'type' : 'generic', 44 | \ } 45 | 46 | if a:which ==# 'heading-1' && a:heading_line =~ '^\s*#' 47 | let m_lnum = a:context.matched_lnum 48 | let heading.type = 'comment' 49 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum, 5) 50 | elseif a:which ==# 'heading' 51 | let heading.level = 4 52 | let heading.type = 'function' 53 | let heading.word = substitute(heading.word, '\s*\((.*)\s*\)\={.*$', '', '') 54 | endif 55 | 56 | if heading.level > 0 57 | return heading 58 | else 59 | return {} 60 | endif 61 | endfunction 62 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/swift.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/go.vim 3 | " Author : rhysd 4 | " Updated : 2014-06-07 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Apple Swift 12 | 13 | function! unite#sources#outline#defaults#swift#outline_info() abort 14 | return s:outline_info 15 | endfunction 16 | 17 | let s:Util = unite#sources#outline#import('Util') 18 | 19 | let s:outline_info = { 20 | \ 'heading-1': s:Util.shared_pattern('c', 'heading-1'), 21 | \ 'heading' : '\%(\<\%(typealias\|func\|enum\|case\|struct\|class\|protocol\|subscript\|init\|deinit\|extension\|operator\)\>\|^}\)', 22 | \ 'skip' : { 23 | \ 'header' : s:Util.shared_pattern('c', 'header'), 24 | \ }, 25 | \ 'highlight_rules' : [ 26 | \ { 27 | \ 'name' : 'comment', 28 | \ 'pattern' : '/\/\/.*/', 29 | \ }, 30 | \ { 31 | \ 'name' : 'typealias', 32 | \ 'pattern' : '/\h\w*\ze : type\>/', 33 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 34 | \ }, 35 | \ { 36 | \ 'name' : 'function', 37 | \ 'pattern' : '/.*\ze : func\>/', 38 | \ }, 39 | \ { 40 | \ 'name' : 'enum', 41 | \ 'pattern' : '/\h\w* : enum\>/', 42 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 43 | \ }, 44 | \ { 45 | \ 'name' : 'case', 46 | \ 'pattern' : '/\/', 52 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 53 | \ }, 54 | \ { 55 | \ 'name' : 'class', 56 | \ 'pattern' : '/\S*\ze : class\>/', 57 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 58 | \ }, 59 | \ { 60 | \ 'name' : 'protocol', 61 | \ 'pattern' : '/\h\w*\ze : protocol\>/', 62 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 63 | \ }, 64 | \ { 65 | \ 'name' : 'subscript', 66 | \ 'pattern' : '/\/', 67 | \ 'highlight' : unite#sources#outline#get_highlight('function'), 68 | \ }, 69 | \ { 70 | \ 'name' : 'init', 71 | \ 'pattern' : '/\/', 72 | \ 'highlight' : unite#sources#outline#get_highlight('function'), 73 | \ }, 74 | \ { 75 | \ 'name' : 'deinit', 76 | \ 'pattern' : '/\/', 77 | \ 'highlight' : unite#sources#outline#get_highlight('function'), 78 | \ }, 79 | \ { 80 | \ 'name' : 'extension', 81 | \ 'pattern' : '/[^:]\+\ze : extension/', 82 | \ 'highlight' : unite#sources#outline#get_highlight('type'), 83 | \ }, 84 | \ { 85 | \ 'name' : 'operator', 86 | \ 'pattern' : '/\S\+\ze : operator/', 87 | \ 'highlight' : unite#sources#outline#get_highlight('function'), 88 | \ }, 89 | \ ], 90 | \ } 91 | 92 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 93 | let type = 'generic' 94 | let level = 0 95 | 96 | if a:which ==# 'heading-1' && a:heading_line =~# '^\s*//' 97 | let m_lnum = a:context.matched_lnum 98 | let type = 'comment' 99 | let word = a:heading_line 100 | let level = s:Util.get_comment_heading_level(a:context, m_lnum) 101 | elseif a:which ==# 'heading' && a:heading_line =~# '\' 102 | let type = 'typealias' 103 | let word = substitute(matchstr(a:heading_line, '\' 106 | let type = 'function' 107 | let word = substitute(matchstr(a:heading_line, '\' 110 | let type = 'enum' 111 | let word = substitute(matchstr(a:heading_line, '\' 114 | let type = 'case' 115 | let word = substitute(matchstr(a:heading_line, '\' 118 | let type = 'class' 119 | let word = substitute(matchstr(a:heading_line, '\' 122 | let type = 'struct' 123 | let word = substitute(matchstr(a:heading_line, '\' 126 | let type = 'protocol' 127 | let word = substitute(matchstr(a:heading_line, '\' 138 | let type = 'extension' 139 | let word = substitute(matchstr(a:heading_line, '\' 142 | let type = 'operator' 143 | let word = substitute(matchstr(a:heading_line, '\ 0 148 | let heading = { 149 | \ 'word' : word, 150 | \ 'level': level, 151 | \ 'type' : type, 152 | \ } 153 | else 154 | let heading = {} 155 | endif 156 | 157 | return heading 158 | endfunction 159 | 160 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/tex.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/tex.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for TeX 12 | " Version: 0.1.1 13 | 14 | function! unite#sources#outline#defaults#tex#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading': '^\s*\\\%(title\|part\|chapter\|\%(sub\)\{,2}section\|label\|bibliography\|begin{thebibliography}\){', 25 | \ 'highlight_rules': [ 26 | \ { 27 | \ 'name' : 'type', 28 | \ 'pattern' : '/[0-9\.]\+/' 29 | \ }, 30 | \ { 31 | \ 'name' : 'special', 32 | \ 'pattern' : '/.*\ze (label)/' 33 | \ }, 34 | \ { 35 | \ 'name' : 'comment', 36 | \ 'pattern' : '/(label)/' 37 | \ }, 38 | \ ], 39 | \ 'is_volatile': 1, 40 | \} 41 | 42 | let s:unit_level_map = { 43 | \ 'title' : 1, 44 | \ 'part' : 2, 45 | \ 'chapter' : 3, 46 | \ 'section' : 4, 47 | \ 'subsection' : 5, 48 | \ 'subsubsection': 6, 49 | \ 'label' : 7, 50 | \ } 51 | 52 | function! s:outline_info.before(context) abort 53 | let s:unit_count = map(copy(s:unit_level_map), '0') 54 | let s:bib_level = 7 55 | endfunction 56 | 57 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 58 | let heading = { 59 | \ 'word' : a:heading_line, 60 | \ 'level': 0, 61 | \ 'type' : 'generic', 62 | \ } 63 | 64 | let h_lnum = a:context.heading_lnum 65 | if a:heading_line =~ '^\s*\\\%(begin{thebibliography}\|bibliography\){' 66 | " Bibliography 67 | let heading.level = s:bib_level 68 | let bib_label = s:Util.neighbor_matchstr(a:context, h_lnum, 69 | \ '\\renewcommand{\\bibname}{\zs.*\ze}\s*\%(%.*\)\?$', 3) 70 | let heading.word = (empty(bib_label) ? "Bibliography" : bib_label) 71 | else 72 | " Parts, Chapters, Sections, etc 73 | let unit = matchstr(a:heading_line, '^\s*\\\zs\w\+\ze{') 74 | let s:unit_count[unit] += 1 75 | if unit ==# 'chapter' 76 | let s:unit_count['section'] = 0 77 | let s:unit_count['subsection'] = 0 78 | let s:unit_count['subsubsection'] = 0 79 | elseif unit ==# 'section' 80 | let s:unit_count['subsection'] = 0 81 | let s:unit_count['subsubsection'] = 0 82 | elseif unit ==# 'subsection' 83 | let s:unit_count['subsubsection'] = 0 84 | endif 85 | 86 | let heading.level = s:unit_level_map[unit] 87 | if 1 < heading.level && heading.level < s:bib_level 88 | let s:bib_level = heading.level 89 | endif 90 | let heading.word = s:normalize_heading_word( 91 | \ s:Util.join_to(a:context, h_lnum, '}\s*\%(%.*\)\?$'), unit) 92 | endif 93 | 94 | if heading.level > 0 95 | return heading 96 | else 97 | return {} 98 | endif 99 | endfunction 100 | 101 | function! s:normalize_heading_word(word, unit) abort 102 | let word = substitute(a:word, '\\\\\n', '', 'g') 103 | let word = matchstr(word, '^\s*\\\w\+{\zs.*\ze}\s*\%(%.*\)\?$') 104 | let word = s:unit_seqnr_prefix(a:unit) . word 105 | if a:unit ==# 'label' 106 | let word .= ' (label)' 107 | endif 108 | return word 109 | endfunction 110 | 111 | function! s:unit_seqnr_prefix(unit) abort 112 | let seqnr = [] 113 | 114 | if a:unit ==# 'part' 115 | let seqnr = [s:Util.String.nr2roman(s:unit_count.part)] 116 | elseif a:unit ==# 'chapter' 117 | let seqnr = [s:unit_count.chapter] 118 | elseif a:unit ==# 'section' 119 | if s:unit_count.chapter > 0 120 | let seqnr = [s:unit_count.chapter, s:unit_count.section] 121 | elseif a:unit ==# 'section' 122 | let seqnr = [s:unit_count.section] 123 | endif 124 | elseif a:unit ==# 'subsection' 125 | if s:unit_count.chapter > 0 126 | let seqnr = [s:unit_count.chapter, s:unit_count.section, s:unit_count.subsection] 127 | else 128 | let seqnr = [s:unit_count.section, s:unit_count.subsection] 129 | endif 130 | elseif a:unit ==# 'subsubsection' 131 | if s:unit_count.chapter == 0 132 | let seqnr = [s:unit_count.section, s:unit_count.subsection, s:unit_count.subsubsection] 133 | endif 134 | endif 135 | let prefix = join(seqnr, '.') 136 | let prefix .= (!empty(prefix) ? " " : "") 137 | return prefix 138 | endfunction 139 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/textile.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/textile.vim 3 | " Author : basyura 4 | " Maintainer : h1mesuke 5 | " Updated : 2012-01-11 6 | " 7 | " Licensed under the MIT license: 8 | " http://www.opensource.org/licenses/mit-license.php 9 | " 10 | "============================================================================= 11 | 12 | " Default outline info for Textile 13 | " Version: 0.0.2 14 | 15 | function! unite#sources#outline#defaults#textile#outline_info() abort 16 | return s:outline_info 17 | endfunction 18 | 19 | "----------------------------------------------------------------------------- 20 | " Outline Info 21 | 22 | let s:outline_info = { 23 | \ 'heading': '^h[1-6]\.\s', 24 | \ } 25 | 26 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 27 | let heading = { 28 | \ 'word' : substitute(a:heading_line, '^h[1-6]\.\s\+', '', ''), 29 | \ 'level': str2nr(matchstr(a:heading_line, '^h\zs[1-6]\ze\.\s')), 30 | \ 'type' : 'generic', 31 | \ } 32 | return heading 33 | endfunction 34 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/typescript.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/typescript.vim 3 | " Author : prabirshrestha 4 | " Updated : 2015-02-15 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Typescript 12 | " Version: 0.0.1 13 | 14 | " Download typescript ctags at https://github.com/jb55/typescript-ctags 15 | 16 | function! unite#sources#outline#defaults#typescript#outline_info() abort 17 | return s:outline_info 18 | endfunction 19 | 20 | let s:Ctags = unite#sources#outline#import('Ctags') 21 | let s:Util = unite#sources#outline#import('Util') 22 | 23 | "----------------------------------------------------------------------------- 24 | " Outline Info 25 | 26 | let s:outline_info = { 27 | \ 'heading_groups': { 28 | \ 'type' : ['modules', 'classes', 'enums', 'interfaces'], 29 | \ 'method' : ['functions', 'varlambdas'], 30 | \ }, 31 | \ 32 | \ 'highlight_rules': [ 33 | \ { 'name' : 'type', 34 | \ 'pattern': '/\S\+\ze : \%(module\|interface\|class\|enum\)/' }, 35 | \ { 'name' : 'method', 36 | \ 'pattern': '/\h\w*\ze\s*(/' }, 37 | \ ], 38 | \} 39 | 40 | function! s:outline_info.extract_headings(context) abort 41 | return s:Ctags.extract_headings(a:context) 42 | endfunction 43 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/unittest.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/unittest.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for UnitTest results 12 | " Version: 0.0.5 13 | 14 | " h1mesuke/vim-unittest - GitHub 15 | " https://github.com/h1mesuke/vim-unittest 16 | 17 | function! unite#sources#outline#defaults#unittest#outline_info() abort 18 | return s:outline_info 19 | endfunction 20 | 21 | "----------------------------------------------------------------------------- 22 | " Outline Info 23 | 24 | let s:outline_info = { 25 | \ 'is_volatile': 1, 26 | \ 27 | \ 'heading-1': '^[-=]\{10,}', 28 | \ 'heading' : '^\s*\d\+) \%(Failure\|Error\): ', 29 | \} 30 | 31 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 32 | let heading = { 33 | \ 'word' : a:heading_line, 34 | \ 'level': 0, 35 | \ 'type' : 'generic', 36 | \ } 37 | 38 | if a:which ==# 'heading-1' 39 | if a:matched_line =~ '^=' || a:heading_line =~ '^\d\+ tests,' 40 | let heading.level = 1 41 | elseif a:matched_line =~ '^-' 42 | let heading.level = 2 43 | endif 44 | elseif a:which ==# 'heading' 45 | let heading.level = 3 46 | endif 47 | 48 | if heading.level > 0 49 | return heading 50 | else 51 | return {} 52 | endif 53 | endfunction 54 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/defaults/vim.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/defaults/vim.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Vim script 12 | " Version: 0.1.5 13 | 14 | function! unite#sources#outline#defaults#vim#outline_info() abort 15 | return s:outline_info 16 | endfunction 17 | 18 | let s:Util = unite#sources#outline#import('Util') 19 | 20 | "----------------------------------------------------------------------------- 21 | " Outline Info 22 | 23 | let s:outline_info = { 24 | \ 'heading-1': '^\s*"\s*[-=]\{10,}\s*$', 25 | \ 'heading' : '^\%(augroup\s\+\%(END\>\)\@!\|\s*fu\%[nction]!\= \)', 26 | \ 27 | \ 'skip': { 'header': '^"' }, 28 | \ 29 | \ 'not_match_patterns': [ 30 | \ s:Util.shared_pattern('*', 'parameter_list'), 31 | \ ], 32 | \ 33 | \ 'highlight_rules': [ 34 | \ { 'name' : 'comment', 35 | \ 'pattern' : '/".*/' }, 36 | \ { 'name' : 'augroup', 37 | \ 'pattern' : '/\S\+\ze : augroup/', 38 | \ 'highlight': unite#sources#outline#get_highlight('type') }, 39 | \ { 'name' : 'function', 40 | \ 'pattern' : '/\S\+\ze\s*(/' }, 41 | \ { 'name' : 'parameter_list', 42 | \ 'pattern' : '/(.*)/' }, 43 | \ ], 44 | \} 45 | 46 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 47 | let heading = { 48 | \ 'word' : a:heading_line, 49 | \ 'level': 0, 50 | \ 'type' : 'generic', 51 | \ } 52 | 53 | if a:which ==# 'heading-1' && a:heading_line =~ '^\s*"' 54 | let m_lnum = a:context.matched_lnum 55 | let heading.type = 'comment' 56 | let heading.level = s:Util.get_comment_heading_level(a:context, m_lnum, 5) 57 | elseif a:which ==# 'heading' 58 | let heading.level = 4 59 | if heading.word =~ '^augroup ' 60 | let heading.type = 'augroup' 61 | let heading.word = substitute(heading.word, '^augroup\s\+', '', '') . ' : augroup' 62 | else 63 | let heading.type = 'function' 64 | let heading.word = substitute(heading.word, '^\s*fu\%[nction]!\=', '', '') 65 | let heading.word = substitute(heading.word, '\S\zs(', ' (', '') 66 | endif 67 | endif 68 | 69 | if heading.level > 0 70 | let heading.word = substitute(heading.word, '"\=\s*{{{\d\=\s*$', '', '') 71 | return heading 72 | else 73 | return {} 74 | endif 75 | endfunction 76 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/misc/wzmemo_text.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/sources/outline/text.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " 6 | " Licensed under the MIT license: 7 | " http://www.opensource.org/licenses/mit-license.php 8 | " 9 | "============================================================================= 10 | 11 | " Default outline info for Text (WzMemo style) 12 | " Version: 0.0.2 13 | 14 | " USAGE: 15 | " 1. Copy this file to '~/.vim/autoload/unite/sources/outline' 16 | " 2. Rename this file to 'text.vim' 17 | " 18 | " If needed: 19 | " 3. Make a ftdetect file for text filetype at '~/.vim/ftdetect/text.vim' 20 | " and write this: 21 | " 22 | " autocmd BufRead,BufNewFile *.txt set filetype=text 23 | 24 | function! unite#sources#outline#defaults#text#outline_info() abort 25 | return s:outline_info 26 | endfunction 27 | 28 | let s:outline_info = { 29 | \ 'heading' : '^\.\+', 30 | \ } 31 | 32 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) abort 33 | let level = strlen(matchstr(a:heading_line, '^\.\+')) 34 | let heading = { 35 | \ 'word' : substitute(a:heading_line, '^\.\+\s*', '', ''), 36 | \ 'level': level, 37 | \ 'type' : 'generic', 38 | \ } 39 | return heading 40 | endfunction 41 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/modules/base.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/source/outline/modules/base.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " Version : 0.5.1 6 | " License : MIT license {{{ 7 | " 8 | " Permission is hereby granted, free of charge, to any person obtaining 9 | " a copy of this software and associated documentation files (the 10 | " "Software"), to deal in the Software without restriction, including 11 | " without limitation the rights to use, copy, modify, merge, publish, 12 | " distribute, sublicense, and/or sell copies of the Software, and to 13 | " permit persons to whom the Software is furnished to do so, subject to 14 | " the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included 17 | " in all copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | " }}} 27 | "============================================================================= 28 | 29 | let s:save_cpo = &cpo 30 | set cpo&vim 31 | 32 | function! unite#sources#outline#modules#base#new(name, sid) abort 33 | let module = copy(s:Module) 34 | let module.__name__ = a:name 35 | let module.__prefix__ = a:sid . a:name . '_' 36 | " => 10_Fizz_ 37 | return module 38 | endfunction 39 | 40 | "----------------------------------------------------------------------------- 41 | 42 | let s:Module = {} 43 | 44 | function! s:Module_bind(func_name) dict 45 | let self[a:func_name] = function(self.__prefix__ . a:func_name) 46 | endfunction 47 | let s:Module.__bind__ = function('s:Module_bind') 48 | let s:Module.function = s:Module.__bind__ | " syntax sugar 49 | 50 | let &cpo = s:save_cpo 51 | unlet s:save_cpo 52 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/modules/ctags.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/source/outline/lib/ctags.vim 3 | " Author : h1mesuke 4 | " Shougo Matsushita 5 | " Updated : 2012-01-11 6 | " Version : 0.5.1 7 | " License : MIT license {{{ 8 | " 9 | " Permission is hereby granted, free of charge, to any person obtaining 10 | " a copy of this software and associated documentation files (the 11 | " "Software"), to deal in the Software without restriction, including 12 | " without limitation the rights to use, copy, modify, merge, publish, 13 | " distribute, sublicense, and/or sell copies of the Software, and to 14 | " permit persons to whom the Software is furnished to do so, subject to 15 | " the following conditions: 16 | " 17 | " The above copyright notice and this permission notice shall be included 18 | " in all copies or substantial portions of the Software. 19 | " 20 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | " }}} 28 | "============================================================================= 29 | 30 | let s:save_cpo = &cpo 31 | set cpo&vim 32 | 33 | 34 | function! unite#sources#outline#modules#ctags#import() abort 35 | return s:Ctags 36 | endfunction 37 | 38 | "----------------------------------------------------------------------------- 39 | 40 | let s:Tree = unite#sources#outline#import('Tree') 41 | let s:Util = unite#sources#outline#import('Util') 42 | let s:Process = unite#util#get_vital().import('Process') 43 | 44 | function! s:get_SID() abort 45 | return matchstr(expand(''), '\d\+_') 46 | endfunction 47 | let s:SID = s:get_SID() 48 | delfunction s:get_SID 49 | 50 | " Ctags module provides a function to extract headings from a file using the Exuberant 51 | " Ctags. It executes the Ctags and parses its output and build a tree of 52 | " headings. 53 | " 54 | let s:Ctags = unite#sources#outline#modules#base#new('Ctags', s:SID) 55 | 56 | " Find the Exuberant Ctags and identify its binary name. If not found, returns 57 | " empty String. 58 | " 59 | function! s:find_exuberant_ctags() abort 60 | let ctags_exe_names = [ 61 | \ 'ctags-exuberant', 62 | \ 'exctags', 63 | \ 'ctags', 64 | \ 'tags', 65 | \ ] 66 | if exists('g:unite_source_outline_ctags_program') 67 | \ && g:unite_source_outline_ctags_program != '' 68 | let ctags_exe_names = 69 | \ [unite#util#substitute_path_separator( 70 | \ g:unite_source_outline_ctags_program)] 71 | \ + ctags_exe_names 72 | endif 73 | for ctags in ctags_exe_names 74 | if executable(ctags) 75 | " Make sure it is Exuberant or Universal ctags. 76 | let ctags_out = unite#util#system(ctags . ' --version') 77 | if ctags_out =~? '\<\%(Exuberant\|Universal\) Ctags\>' 78 | return ctags 79 | endif 80 | endif 81 | endfor 82 | 83 | call unite#print_error("unite-outline: ctags is not found.") 84 | 85 | return '' 86 | endfunction 87 | 88 | let s:Ctags.exe = s:find_exuberant_ctags() 89 | let s:Ctags.lang_info = {} 90 | 91 | " Returns True if the Exuberant Ctags is available. 92 | " 93 | function! s:Ctags_exists() abort 94 | return !empty(s:Ctags.exe) 95 | endfunction 96 | let s:Ctags.exists = function('s:Ctags_exists') 97 | 98 | " Returns True if the Exuberant Ctags supports {filetype}. 99 | " 100 | function! s:Ctags_supports(filetype) abort 101 | if !has_key(s:Ctags.lang_info, a:filetype) 102 | return 0 103 | else 104 | let lang_info = s:Ctags.lang_info[a:filetype] 105 | let ctags_out = unite#util#system(s:Ctags.exe . ' --list-languages') 106 | return index(split(ctags_out, "\"), lang_info.name, 1) >= 0 107 | endif 108 | endfunction 109 | let s:Ctags.supports = function('s:Ctags_supports') 110 | 111 | " Executes the Ctags and returns a List of tag objects. 112 | " 113 | function! s:execute_ctags(context) abort 114 | " Write the current content of the buffer to a temporary file. 115 | let input = join(a:context.lines[1:], "\") 116 | let input = s:Process.iconv(input, &encoding, &termencoding) 117 | let temp_file = tempname() 118 | if unite#util#is_sudo() || 119 | \ writefile(split(input, "\"), temp_file) == -1 120 | call unite#util#print_message( 121 | \ "[unite-outline] Couldn't make a temporary file at " . temp_file) 122 | return [] 123 | endif 124 | " NOTE: If the auto-update is enabled, the buffer may have been changed 125 | " since the last write. Because the user expects the headings to be 126 | " extracted from the buffer which he/she is watching now, we need to process 127 | " the buffer's content not its file's content. 128 | 129 | let filetype = a:context.buffer.filetype 130 | " Assemble the command-line. 131 | let lang_info = s:Ctags.lang_info[filetype] 132 | let opts = ' -f - --excmd=number --fields=afiKmsSzt --sort=no --append=no' 133 | let opts .= " --language-force=\"" . lang_info.name . "\" " 134 | let opts .= lang_info.ctags_options 135 | 136 | let path = s:Util.Path.normalize(temp_file) 137 | let path = s:Util.String.shellescape(path) 138 | 139 | let cmdline = s:Ctags.exe . opts . path 140 | 141 | " Execute the Ctags. 142 | let ctags_out = unite#util#system(cmdline) 143 | let status = unite#util#get_last_status() 144 | if status != 0 145 | call unite#print_message( 146 | \ "[unite-outline] ctags failed with status " . status . ".") 147 | return [] 148 | endif 149 | 150 | " Delete the used temporary file. 151 | if delete(temp_file) != 0 152 | call unite#print_error( 153 | \ "unite-outline: Couldn't delete a temporary file: " . temp_file) 154 | endif 155 | 156 | let tag_lines = split(ctags_out, "\") 157 | try 158 | " Convert tag lines into tag objects. 159 | let tags = map(tag_lines, 's:create_tag(v:val, lang_info)') 160 | call filter(tags, '!empty(v:val)') 161 | return tags 162 | catch 163 | " The first line of the output often contains a hint of an error. 164 | throw tag_lines[0] 165 | endtry 166 | endfunction 167 | 168 | " Creates a tag object from a tag line. If the line is not a tag line, for 169 | " example, a warning message from the standard error, returns an empty 170 | " Dictionary. 171 | " 172 | " TAG FILE FORMAT: 173 | " 174 | " tag_line 175 | " := tag_namefile_nameex_cmd;"{extension_fields} 176 | " 177 | " extension_fields 178 | " := key:valuekey:value... 179 | " 180 | function! s:create_tag(tag_line, lang_info) abort 181 | let fields = split(a:tag_line, "\") 182 | if len(fields) < 3 183 | " The line doesn't seem a tag line, so ignore it. 184 | " Example: ctags: Warning: {message} 185 | return {} 186 | endif 187 | let tag = {} 188 | let tag.name = fields[0] 189 | let tag.lnum = str2nr(fields[2]) 190 | for ext_fld in fields[3:-1] 191 | let [key, value] = matchlist(ext_fld, '^\([^:]\+\):\(.*\)$')[1:2] 192 | let tag[key] = value 193 | endfor 194 | for scope_kind in a:lang_info.scope_kinds 195 | if has_key(tag, scope_kind) 196 | let tag.scope_kind = scope_kind 197 | let tag.scope = tag[scope_kind] 198 | endif 199 | endfor 200 | if has_key(tag, 'scope') 201 | let tag.qualified_name = tag.scope . a:lang_info.scope_delim . tag.name 202 | else 203 | let tag.qualified_name = tag.name 204 | endif 205 | return tag 206 | endfunction 207 | 208 | " Extract headings from the context buffer's file using the Ctags and then 209 | " returns a tree of the headings. 210 | " 211 | function! s:Ctags_extract_headings(context) abort 212 | let filetype = a:context.buffer.filetype 213 | if !s:Ctags_exists() 214 | call unite#print_message("[unite-outline] Sorry, Exuberant Ctags required.") 215 | return [] 216 | elseif !s:Ctags_supports(filetype) 217 | call unite#print_message("[unite-outline] " . 218 | \ "Sorry, your ctags doesn't support " . filetype) 219 | return [] 220 | endif 221 | 222 | " Execute the Ctags and get a List of tag objects. 223 | let tags = s:execute_ctags(a:context) 224 | 225 | let lang_info = s:Ctags.lang_info[filetype] 226 | let scope_kinds_pattern = '^\%(' . join(lang_info.scope_kinds, '\|') . '\)$' 227 | let scope_table = {} 228 | 229 | " Tag name counter 230 | let s:counter = {} 231 | 232 | " Build a heading tree processing a List of tag objects. 233 | let root = s:Tree.new() 234 | for tag in tags 235 | " Create a heading from the tag object. 236 | if has_key(lang_info, 'create_heading') 237 | let heading = lang_info.create_heading(tag, a:context) 238 | else 239 | let heading = s:create_heading(tag, a:context) 240 | endif 241 | if empty(heading) | continue | endif 242 | 243 | " Remove extra spaces to normalize the parameter list. 244 | let heading.word = substitute(substitute(heading.word, '(\s*', '(', ''), '\s*)', ')', '') 245 | 246 | if tag.kind =~# scope_kinds_pattern 247 | " The heading has its scope, in other words, it is able to have child 248 | " headings. To append its children that come after to it, register it to 249 | " the table. 250 | " Example: a class, a module, etc 251 | if !has_key(scope_table, tag.qualified_name) 252 | let scope_table[tag.qualified_name] = heading 253 | elseif has_key(scope_table[tag.qualified_name], '__pseudo__') 254 | " Replace the pseudo heading with the actual one. 255 | let heading.children = scope_table[tag.qualified_name].children 256 | let scope_table[tag.qualified_name] = heading 257 | endif 258 | endif 259 | 260 | if has_key(tag, 'scope') 261 | " Group_A: The heading belongs to a scope, in other words, it has 262 | " a parent heading. 263 | " Example: a method in class, an inner class, etc 264 | if !has_key(scope_table, tag.scope) 265 | " If the parent heading hasn't registered to the table yet, create 266 | " a pseudo heading as a place holder. 267 | let pseudo_heading = s:create_pseudo_heading(tag) 268 | let scope_table[tag.scope] = pseudo_heading 269 | endif 270 | " Prepend a symbol character (+, #, -) to show the accessibility to the 271 | " heading word. 272 | let heading.word = s:get_tag_access_mark(tag) . heading.word 273 | call s:Tree.append_child(scope_table[tag.scope], heading) 274 | else 275 | " Group_B: The heading belongs to the toplevel. 276 | call s:Tree.append_child(root, heading) 277 | endif 278 | endfor 279 | unlet! s:counter 280 | 281 | " Merge orphaned pseudo headings. 282 | let pseudo_headings = filter(values(scope_table), 'has_key(v:val, "__pseudo__")') 283 | if len(pseudo_headings) > 0 284 | for heading in pseudo_headings 285 | call s:Tree.append_child(root, heading) 286 | endfor 287 | call s:Util.List.sort_by_lnum(root.children) 288 | endif 289 | return root 290 | endfunction 291 | let s:Ctags.extract_headings = function('s:Ctags_extract_headings') 292 | 293 | " Creates a heading from {tag}. 294 | " 295 | function! s:create_heading(tag, context) abort 296 | let line = a:context.lines[a:tag.lnum] 297 | let heading = { 298 | \ 'word' : a:tag.name, 299 | \ 'type' : a:tag.kind, 300 | \ "lnum" : a:tag.lnum, 301 | \ } 302 | if has_key(a:tag, 'signature') 303 | let heading.word .= ' ' . a:tag.signature 304 | else 305 | let heading.word .= ' : ' . a:tag.kind 306 | endif 307 | if has_key(a:tag, 'implementation') 308 | let heading.word .= ' <' . a:tag.implementation . '>' 309 | endif 310 | return heading 311 | endfunction 312 | 313 | " Creates a pseudo heading from {tag}. 314 | " Pseudo headings are the headings whose tags don't exists actually because 315 | " maybe they belong to the other files. 316 | " 317 | function! s:create_pseudo_heading(tag) abort 318 | let heading = { 319 | \ 'word' : '(' . a:tag.scope . ') : ' . a:tag.scope_kind, 320 | \ 'type' : a:tag.scope_kind, 321 | \ 'lnum' : a:tag.lnum, 322 | \ '__pseudo__': 1, 323 | \ } 324 | return heading 325 | endfunction 326 | 327 | " Gets a full parameter list from the context buffer's line. 328 | " 329 | function! s:get_param_list(context, lnum) abort 330 | let line = s:Util.join_to_rparen(a:context, a:lnum) 331 | return matchstr(line, '([^)]*)') 332 | endfunction 333 | 334 | " Returns a symbol character (+, #, -) to show the accessibility of {tag}. 335 | " 336 | let s:OOP_ACCESS_MARKS = { 337 | \ 'public' : '+', 338 | \ 'protected': '#', 339 | \ 'private' : '-' 340 | \ } 341 | function! s:get_tag_access_mark(tag) abort 342 | let access = has_key(a:tag, 'access') ? a:tag.access : 'unknown' 343 | return get(s:OOP_ACCESS_MARKS, access, '_') . ' ' 344 | endfunction 345 | 346 | " Count up {tag}'s name and returns an ID suffix (#2, #3, ...) for {tag}. 347 | " If the {tag} is the first one that has the name, returns empty String. 348 | " 349 | function! s:get_tag_id(tag) abort 350 | let name = a:tag.qualified_name 351 | if has_key(a:tag, 'signature') 352 | let name .= a:tag.signature 353 | endif 354 | if has_key(s:counter, name) 355 | let s:counter[name] += 1 356 | return ' #' . s:counter[name] 357 | else 358 | let s:counter[name] = 1 359 | return '' 360 | endif 361 | endfunction 362 | 363 | " TODO: Specifying ctags's -I option from some variable. 364 | "----------------------------------------------------------------------------- 365 | " C/C++ 366 | " 367 | " [c] classes 368 | " [d] macro definitions 369 | " [e] enumerators (values inside an enumeration) 370 | " [f] function definitions 371 | " [g] enumeration names 372 | " l local variables 373 | " [m] class, struct, and union members 374 | " [n] namespaces 375 | " [p] function prototypes, pure virtual functions 376 | " [s] structure names 377 | " [t] typedefs 378 | " [u] union names 379 | " v variable definitions 380 | " x external and forward variable declarations 381 | " 382 | let s:Ctags.lang_info.cpp = { 383 | \ 'name': 'C++', 384 | \ 'ctags_options': ' --c++-kinds=cdefgmnstup ', 385 | \ 'scope_kinds' : ['namespace', 'class', 'struct', 'enum'], 386 | \ 'scope_delim' : '::', 387 | \ } 388 | function! s:Ctags.lang_info.cpp.create_heading(tag, context) abort 389 | let line = a:context.lines[a:tag.lnum] 390 | let heading = { 391 | \ 'word' : a:tag.name, 392 | \ 'type' : a:tag.kind, 393 | \ 'lnum' : a:tag.lnum, 394 | \ } 395 | let ignore = 0 396 | if heading.type ==# 'function' 397 | " Function 398 | if a:tag.name =~# '^[[:upper:]_]\{3,}$' 399 | " Application of a macro was incorrectly parsed as a function 400 | " definition. 401 | let ignore = 1 402 | elseif has_key(a:tag, 'signature') 403 | let heading.word .= ' ' . a:tag.signature 404 | else 405 | let heading.word .= ' ' . s:get_param_list(a:context, a:tag.lnum) 406 | endif 407 | let heading.word .= s:get_tag_id(a:tag) 408 | elseif heading.type ==# 'macro' 409 | " Macro 410 | if line =~# '#undef\>' 411 | let ignore = 1 412 | else 413 | " Append its parameter list if exists. 414 | if line =~# a:tag.name . '(' 415 | let heading.word .= ' ' . s:get_param_list(a:context, a:tag.lnum) 416 | endif 417 | " Append what the macro will be expanded to. 418 | let heading.word .= s:get_tag_id(a:tag) . 419 | \ ' => ' . s:get_expanded(a:context, a:tag.lnum, a:tag.name) 420 | endif 421 | else 422 | " Otehrs 423 | let heading.word .= s:get_tag_id(a:tag) . ' : ' . a:tag.kind 424 | endif 425 | if has_key(a:tag, 'implementation') 426 | let heading.word .= ' <' . a:tag.implementation . '>' 427 | endif 428 | return ignore ? {} : heading 429 | endfunction 430 | 431 | function! s:get_expanded(context, lnum, macro) abort 432 | let line = a:context.lines[a:lnum] 433 | let expanded = matchstr(line, a:macro . '\%(([^)]*)\)\=\s\+\zs.*') 434 | let lnum = a:lnum + 1 435 | while strlen(expanded) < 10 && expanded =~ '\\\s*$' 436 | let expanded .= substitute(a:context.lines[lnum], '^\s*', ' ', '') 437 | let lnum += 1 438 | endwhile 439 | let expanded = substitute(expanded, '\\\s*$', ' ...', '') 440 | let expanded = substitute(expanded, '\s*\\\s*', ' ', 'g') 441 | return expanded 442 | endfunction 443 | 444 | let s:Ctags.lang_info.c = copy(s:Ctags.lang_info.cpp) 445 | call extend(s:Ctags.lang_info.c, { 446 | \ 'name': 'C', 447 | \ 'ctags_options': ' --c-kinds=cdfgnstu ' 448 | \ }, 'force') 449 | 450 | let s:Ctags.lang_info.cs = { 451 | \ 'name': 'C#', 452 | \ 'ctags_options': " '--C#-kinds=cdgnsmt' ", 453 | \ 'scope_kinds' : ['namespace', 'class', 'enum'], 454 | \ 'scope_delim' : '.', 455 | \ } 456 | 457 | let s:Ctags.lang_info.rust = { 458 | \ 'name': 'Rust', 459 | \ 'ctags_options': '', 460 | \ 'scope_kinds' : [], 461 | \ } 462 | 463 | let s:Ctags.lang_info.typescript = { 464 | \ 'name': 'typescript', 465 | \ 'ctags_options': '', 466 | \ 'scope_kinds' : ['modules', 'classes', 'interfaces', 'enums', 'functions', 'varlambdas'], 467 | \ } 468 | 469 | let s:Ctags.lang_info.elm = { 470 | \ 'name': 'Elm', 471 | \ 'ctags_options': '', 472 | \ 'scope_kinds' : ['function', 'constant', 'port', 'type', 'type-alias'], 473 | \ } 474 | 475 | "----------------------------------------------------------------------------- 476 | " Java 477 | " 478 | " [c] classes 479 | " e enum constants 480 | " f fields 481 | " [g] enum types 482 | " [i] interfaces 483 | " l local variables 484 | " [m] methods 485 | " [p] packages 486 | " 487 | let s:Ctags.lang_info.java = { 488 | \ 'name': 'Java', 489 | \ 'ctags_options': ' --java-kinds=cgimp ', 490 | \ 'scope_kinds' : ['interface', 'class', 'enum'], 491 | \ 'scope_delim' : '.', 492 | \ } 493 | 494 | let &cpo = s:save_cpo 495 | unlet s:save_cpo 496 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/modules/file_cache.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/source/outline/_cache.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " Version : 0.5.1 6 | " License : MIT license {{{ 7 | " 8 | " Permission is hereby granted, free of charge, to any person obtaining 9 | " a copy of this software and associated documentation files (the 10 | " "Software"), to deal in the Software without restriction, including 11 | " without limitation the rights to use, copy, modify, merge, publish, 12 | " distribute, sublicense, and/or sell copies of the Software, and to 13 | " permit persons to whom the Software is furnished to do so, subject to 14 | " the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included 17 | " in all copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | " }}} 27 | "============================================================================= 28 | 29 | let s:save_cpo = &cpo 30 | set cpo&vim 31 | 32 | function! unite#sources#outline#modules#file_cache#import(dir) abort 33 | let s:FileCache.DIR = a:dir 34 | return s:FileCache 35 | endfunction 36 | 37 | "----------------------------------------------------------------------------- 38 | 39 | let s:Util = unite#sources#outline#import('Util') 40 | 41 | function! s:get_SID() abort 42 | return matchstr(expand(''), '\d\+_') 43 | endfunction 44 | let s:SID = s:get_SID() 45 | delfunction s:get_SID 46 | 47 | " FileCache module provides functions to access and manage the cache data 48 | " stored in files on the local filesystem. 49 | " 50 | let s:FileCache = unite#sources#outline#modules#base#new('FileCache', s:SID) 51 | 52 | if get(g:, 'unite_source_outline_debug', 0) 53 | let s:FileCache.CLEANUP_FILE_COUNT = 10 54 | let s:FileCache.CLEANUP_RATE = 1 55 | let s:FileCache.EXPIRES = 60 56 | else 57 | let s:FileCache.CLEANUP_FILE_COUNT = 300 58 | let s:FileCache.CLEANUP_RATE = 10 59 | let s:FileCache.EXPIRES = 60 * 60 * 24 * 30 60 | endif 61 | 62 | " Returns True if the cached data associated with buffer {bufnr} is available. 63 | " 64 | function! s:FileCache_has(bufnr) dict 65 | let path = s:get_buffer_path(a:bufnr) 66 | return s:cache_file_exists(path) 67 | endfunction 68 | call s:FileCache.function('has') 69 | 70 | " Returns True if the cache file associated with file {path} exists. 71 | " 72 | function! s:cache_file_exists(path) abort 73 | return (s:cache_dir_exists() && filereadable(s:get_cache_file_path(a:path))) 74 | endfunction 75 | 76 | " Returns True if the cache directory exists. 77 | " 78 | function! s:cache_dir_exists() abort 79 | if isdirectory(s:FileCache.DIR) 80 | return 1 81 | elseif unite#util#is_sudo() 82 | call unite#util#print_error("unite-outline: Couldn't create the cache directory.") 83 | return isdirectory(s:FileCache.DIR) 84 | else 85 | try 86 | call mkdir(iconv(s:FileCache.DIR, &encoding, &termencoding), 'p') 87 | catch 88 | call unite#util#print_error("unite-outline: Couldn't create the cache directory.") 89 | endtry 90 | return isdirectory(s:FileCache.DIR) 91 | endif 92 | endfunction 93 | 94 | " Returns a full pathname of the file opened at the buffer {bufnr}. 95 | " 96 | function! s:get_buffer_path(bufnr) abort 97 | return fnamemodify(bufname(a:bufnr), ':p') 98 | endfunction 99 | 100 | " Returns a full pathname of the cache file for the file {path}. 101 | " 102 | function! s:get_cache_file_path(path) abort 103 | return s:FileCache.DIR . '/' . s:encode_file_path(a:path) 104 | endfunction 105 | 106 | " Encodes a full pathname to a basename. 107 | " 108 | " Original source from Shougo's neocomplcache 109 | " https://github.com/Shougo/neocomplcache 110 | " 111 | function! s:encode_file_path(path) abort 112 | if len(s:FileCache.DIR) + len(a:path) < 150 113 | " Encode {path} to a basename. 114 | return substitute(substitute(a:path, ':', '=-', 'g'), '[/\\]', '=+', 'g') 115 | else 116 | " Calculate a simple hash. 117 | let sum = 0 118 | for idx in range(len(a:path)) 119 | let sum += char2nr(a:path[idx]) * (idx + 1) 120 | endfor 121 | return printf('%X', sum) 122 | endif 123 | endfunction 124 | 125 | " Returns the cached data associated with buffer {bufnr}. 126 | " 127 | function! s:FileCache_get(bufnr) dict 128 | let path = s:get_buffer_path(a:bufnr) 129 | let data = s:load_cache_file(path) 130 | return data 131 | endfunction 132 | call s:FileCache.function('get') 133 | 134 | function! s:load_cache_file(path) abort 135 | let cache_file = s:get_cache_file_path(a:path) 136 | let lines = readfile(cache_file) 137 | if !empty(lines) 138 | let dumped_data = lines[0] 139 | call s:print_debug("[LOADED] cache file: " . cache_file) 140 | else 141 | throw "unite-outline: Couldn't load the cache file: " . cache_file 142 | endif 143 | " Touch; Update the timestamp. 144 | if !unite#util#is_sudo() && writefile([dumped_data], cache_file) == 0 145 | call s:print_debug("[TOUCHED] cache file: " . cache_file) 146 | endif 147 | sandbox let data = eval(dumped_data) 148 | return data 149 | endfunction 150 | 151 | " Saves {data} to the cache file. 152 | " 153 | function! s:FileCache_set(bufnr, data) dict 154 | let path = s:get_buffer_path(a:bufnr) 155 | try 156 | if s:cache_dir_exists() 157 | call s:save_cache_file(path, a:data) 158 | elseif s:cache_file_exists(path) 159 | call s:remove_file(s:get_cache_file_path(path)) 160 | endif 161 | catch /^unite-outline:/ 162 | call unite#util#print_error(v:exception) 163 | endtry 164 | call s:cleanup_cache_files() 165 | endfunction 166 | call s:FileCache.function('set') 167 | 168 | function! s:save_cache_file(path, data) abort 169 | let cache_file = s:get_cache_file_path(a:path) 170 | let dumped_data = string(a:data) 171 | if !unite#util#is_sudo() && writefile([dumped_data], cache_file) == 0 172 | call s:print_debug("[SAVED] cache file: " . cache_file) 173 | else 174 | throw "unite-outline: Couldn't save the cache to: " . cache_file 175 | endif 176 | endfunction 177 | 178 | " Remove the cached data associated with buffer {bufnr}. 179 | " 180 | function! s:FileCache_remove(bufnr) dict 181 | let path = s:get_buffer_path(a:bufnr) 182 | if s:cache_file_exists(path) 183 | try 184 | call s:remove_file(s:get_cache_file_path(path)) 185 | catch /^unite-outline:/ 186 | call unite#util#print_error(v:exception) 187 | endtry 188 | endif 189 | endfunction 190 | call s:FileCache.function('remove') 191 | 192 | function! s:remove_file(path) abort 193 | if delete(a:path) == 0 194 | call s:print_debug("[DELETED] cache file: " . a:path) 195 | else 196 | throw "unite-outline: Couldn't delete the cache file: " . a:path 197 | endif 198 | endfunction 199 | 200 | " Remove all cache files. 201 | " 202 | function! s:FileCache_clear() abort 203 | if s:cache_dir_exists() 204 | call s:cleanup_all_cache_files() 205 | echomsg "unite-outline: Deleted all cache files." 206 | else 207 | call unite#util#print_error("unite-outline: Cache directory doesn't exist.") 208 | endif 209 | endfunction 210 | call s:FileCache.function('clear') 211 | 212 | function! s:cleanup_all_cache_files() abort 213 | call s:cleanup_cache_files(1) 214 | endfunction 215 | 216 | " Remove old cache files. 217 | " 218 | function! s:cleanup_cache_files(...) abort 219 | let delete_all = (a:0 ? a:1 : 0) 220 | let cache_files = split(globpath(s:FileCache.DIR, '*'), "\") 221 | let dlt_files = [] 222 | 223 | if delete_all 224 | let dlt_files = cache_files 225 | elseif len(cache_files) > s:FileCache.CLEANUP_FILE_COUNT 226 | let now = localtime() 227 | if now % s:FileCache.CLEANUP_RATE == 0 228 | for path in cache_files 229 | if now - getftime(path) > s:FileCache.EXPIRES 230 | call add(dlt_files, path) 231 | endif 232 | endfor 233 | endif 234 | endif 235 | for path in dlt_files 236 | try 237 | call s:remove_file(path) 238 | catch /^unite-outline:/ 239 | call unite#util#print_error(v:exception) 240 | endtry 241 | endfor 242 | endfunction 243 | 244 | function! s:print_debug(msg) abort 245 | call s:Util.print_debug('cache', a:msg) 246 | endfunction 247 | 248 | let &cpo = s:save_cpo 249 | unlet s:save_cpo 250 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/modules/tree.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/source/outline/modules/tree.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " Version : 0.5.1 6 | " License : MIT license {{{ 7 | " 8 | " Permission is hereby granted, free of charge, to any person obtaining 9 | " a copy of this software and associated documentation files (the 10 | " "Software"), to deal in the Software without restriction, including 11 | " without limitation the rights to use, copy, modify, merge, publish, 12 | " distribute, sublicense, and/or sell copies of the Software, and to 13 | " permit persons to whom the Software is furnished to do so, subject to 14 | " the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included 17 | " in all copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | " }}} 27 | "============================================================================= 28 | 29 | let s:save_cpo = &cpo 30 | set cpo&vim 31 | 32 | function! unite#sources#outline#modules#tree#import() abort 33 | return s:Tree 34 | endfunction 35 | 36 | "----------------------------------------------------------------------------- 37 | 38 | function! s:get_SID() abort 39 | return matchstr(expand(''), '\d\+_') 40 | endfunction 41 | let s:SID = s:get_SID() 42 | delfunction s:get_SID 43 | 44 | " Tree module provides functions to build a tree structure. 45 | " There are two ways to build a Tree: 46 | " 47 | " A. Build a Tree from a List of objects with the level attribute using 48 | " Tree.build(). 49 | " 50 | " B. Build a Tree one node by one node manually using Tree.new() and 51 | " Tree.append_child(). 52 | " 53 | " The following example shows how to build a Tree in the latter way. 54 | " 55 | " == Example 56 | " 57 | " let s:Tree = unite#sources#outline#import('Tree') 58 | " 59 | " let root = s:Tree.new() 60 | " call s:Tree.append_child(root, heading_A) 61 | " call s:Tree.append_child(root, heading_B) 62 | " call s:Tree.append_child(heading_A, heading_1) 63 | " call s:Tree.append_child(heading_A, heading_2) 64 | " call s:Tree.append_child(heading_B, heading_3) 65 | " 66 | " |/ 67 | " 68 | " root 69 | " | 70 | " +--heading_A 71 | " | +--heading_1 72 | " | +--heading_2 73 | " | 74 | " +--heading_B 75 | " +--heading_3 76 | " 77 | let s:Tree = unite#sources#outline#modules#base#new('Tree', s:SID) 78 | let s:Tree.MAX_DEPTH = 20 79 | 80 | " Creates a new root node. 81 | " 82 | function! s:Tree_new() abort 83 | return { '__root__': 1, 'id': 0, 'level': 0, 'children': [] } 84 | endfunction 85 | call s:Tree.function('new') 86 | 87 | " Append {child} to a List of children of {node}. 88 | " 89 | function! s:Tree_append_child(node, child) abort 90 | if !has_key(a:node, 'children') 91 | let a:node.children = [] 92 | endif 93 | call add(a:node.children, a:child) 94 | " Ensure that all nodes have `children'. 95 | if !has_key(a:child, 'children') 96 | let a:child.children = [] 97 | " NOTE: While building a Tree, all nodes of the Tree pass through this 98 | " function as a:child. 99 | endif 100 | endfunction 101 | call s:Tree.function('append_child') 102 | 103 | " Builds a tree structure from a List of elements, which are Dictionaries with 104 | " `level' attribute, and then returns the root node of the built Tree. 105 | " 106 | " NOTE: This function allows discontinuous levels and can build a Tree from such 107 | " a sequence of levels well. 108 | " 109 | " root root 110 | " | | 111 | " +--1 +--1 112 | " [1, 3, 5, 5, 2, ...] => | +--3 => | +--2 113 | " | | +--5 | | +--3 114 | " | | +--5 | | +--3 115 | " | | | | 116 | " : +--2 : +--2 117 | " 118 | function! s:Tree_build(elems) abort 119 | let root = s:Tree_new() 120 | if empty(a:elems) | return root | endif 121 | " Build a Tree. 122 | let stack = [root] 123 | for elem in a:elems 124 | " Forget about the current children... 125 | let elem.children = [] 126 | " Make the top of the stack point to the parent. 127 | while elem.level <= stack[-1].level 128 | call remove(stack, -1) 129 | endwhile 130 | call s:Tree_append_child(stack[-1], elem) 131 | call add(stack, elem) 132 | endfor 133 | call s:normalize_levels(root) 134 | return root 135 | endfunction 136 | call s:Tree.function('build') 137 | 138 | " Normalize the level of nodes in accordance with the given Tree's structure. 139 | " 140 | " root root 141 | " | | 142 | " +--1 +--1 143 | " | +--3 | +--2 144 | " | | +--5 => | | +--3 145 | " | | +--5 | | +--3 146 | " | | | | 147 | " : +--2 : +--2 148 | " 149 | function! s:normalize_levels(node) abort 150 | for child in a:node.children 151 | let child.level = a:node.level + 1 152 | call s:normalize_levels(child) 153 | endfor 154 | endfunction 155 | 156 | " Flattens a Tree into a List with setting the levels of nodes. 157 | " 158 | function! s:Tree_flatten(node) abort 159 | let elems = [] 160 | for child in a:node.children 161 | let child.level = a:node.level + 1 162 | call add(elems, child) 163 | let elems += s:Tree_flatten(child) 164 | endfor 165 | return elems 166 | endfunction 167 | call s:Tree.function('flatten') 168 | 169 | "----------------------------------------------------------------------------- 170 | " Tree.List 171 | 172 | " Tree.List module provides functions to process a List of objects with the 173 | " level attribute in tree-aware way. 174 | " 175 | let s:List = unite#sources#outline#modules#base#new('List', s:SID) 176 | let s:Tree.List = s:List 177 | 178 | " Normalize the levels of {objs}. 179 | " 180 | function! s:List_normalize_levels(objs) abort 181 | let tree = s:Tree_build(a:objs) 182 | let objs = s:fast_flatten(tree) 183 | return objs 184 | endfunction 185 | call s:List.function('normalize_levels') 186 | 187 | " Flattens a Tree into a List without setting the levels of nodes. 188 | " 189 | function! s:fast_flatten(node) abort 190 | let objs = [] 191 | " Push toplevel nodes. 192 | let stack = reverse(copy(a:node.children)) 193 | while !empty(stack) 194 | " Pop a node. 195 | let node = remove(stack, -1) 196 | call add(objs, node) 197 | " Push the node's children. 198 | let stack += reverse(copy(node.children)) 199 | endwhile 200 | return objs 201 | endfunction 202 | 203 | " Resets the matched-marks of the candidates. 204 | " 205 | function! s:List_reset_marks(candidates) abort 206 | if empty(a:candidates) | return a:candidates | endif 207 | let prev_cand = { 208 | \ 'is_matched': 1, 'source__is_marked': 1, 209 | \ 'source__heading_level': 0, 210 | \ } 211 | for cand in a:candidates 212 | let cand.is_matched = 1 213 | let cand.source__is_marked = 1 214 | let prev_cand.source__has_marked_child = 215 | \ prev_cand.source__heading_level < cand.source__heading_level 216 | let prev_cand = cand 217 | endfor 218 | let cand.source__has_marked_child = 0 219 | endfunction 220 | call s:List.function('reset_marks') 221 | 222 | " Marks the matched candidates and their ancestors. 223 | " 224 | " * A candidate is MATCHED for which eval({pred}) returns True. 225 | " * A candidate is MARKED when any its child has been marked. 226 | " 227 | " NOTE: unite-outline's matcher and formatter see these flags to accomplish 228 | " their tree-aware filtering and formatting tasks. 229 | " 230 | function! s:List_mark(candidates, pred, ...) abort 231 | let pred = substitute(a:pred, '\', 'cand', 'g') 232 | let mark_reserved = map(range(0, s:Tree.MAX_DEPTH), 0) 233 | for cand in reverse(copy(a:candidates)) 234 | if !cand.source__is_marked 235 | continue 236 | endif 237 | let cand.is_matched = cand.is_matched && eval(pred) 238 | if cand.is_matched 239 | let matched_level = cand.source__heading_level 240 | if 1 < matched_level 241 | let mark_reserved[1 : matched_level - 1] = map(range(matched_level - 1), 1) 242 | endif 243 | endif 244 | let cand.source__is_marked = cand.is_matched 245 | if mark_reserved[cand.source__heading_level] 246 | let cand.source__is_marked = 1 247 | let cand.source__has_marked_child = 1 248 | let mark_reserved[cand.source__heading_level] = 0 249 | else 250 | let cand.source__has_marked_child = 0 251 | endif 252 | endfor 253 | endfunction 254 | call s:List.function('mark') 255 | 256 | " Remove the matched headings and their descendants. 257 | " 258 | function! s:List_remove(headings, pred) abort 259 | let pred = substitute(a:pred, '\', 'head', 'g') 260 | let matched_level = s:Tree.MAX_DEPTH + 1 261 | let headings = [] 262 | for head in a:headings 263 | if head.level <= matched_level 264 | if eval(pred) 265 | let matched_level = head.level 266 | else 267 | let matched_level = s:Tree.MAX_DEPTH + 1 268 | call add(headings, head) 269 | endif 270 | endif 271 | endfor 272 | return headings 273 | endfunction 274 | call s:List.function('remove') 275 | 276 | unlet s:List 277 | 278 | let &cpo = s:save_cpo 279 | unlet s:save_cpo 280 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/modules/util.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/source/outline/modules/util.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " Version : 0.5.1 6 | " License : MIT license {{{ 7 | " 8 | " Permission is hereby granted, free of charge, to any person obtaining 9 | " a copy of this software and associated documentation files (the 10 | " "Software"), to deal in the Software without restriction, including 11 | " without limitation the rights to use, copy, modify, merge, publish, 12 | " distribute, sublicense, and/or sell copies of the Software, and to 13 | " permit persons to whom the Software is furnished to do so, subject to 14 | " the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included 17 | " in all copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | " }}} 27 | "============================================================================= 28 | 29 | let s:save_cpo = &cpo 30 | set cpo&vim 31 | 32 | function! unite#sources#outline#modules#util#import() abort 33 | return s:Util 34 | endfunction 35 | 36 | "----------------------------------------------------------------------------- 37 | 38 | function! s:get_SID() abort 39 | return matchstr(expand(''), '\d\+_') 40 | endfunction 41 | let s:SID = s:get_SID() 42 | delfunction s:get_SID 43 | 44 | let s:Util = unite#sources#outline#modules#base#new('Util', s:SID) 45 | 46 | "----------------------------------------------------------------------------- 47 | " Heading 48 | 49 | function! s:Util_get_indent_level(context, lnum) abort 50 | let line = a:context.lines[a:lnum] 51 | let sw = a:context.buffer.sw 52 | let ts = a:context.buffer.ts 53 | let indent = substitute(matchstr(line, '^\s*'), '\t', repeat(' ', ts), 'g') 54 | return strlen(indent) / sw + 1 55 | endfunction 56 | call s:Util.function('get_indent_level') 57 | 58 | function! s:Util_get_comment_heading_level(context, lnum, ...) abort 59 | let line = a:context.lines[a:lnum] 60 | if line =~ '^\s' 61 | let level = (a:0 ? a:1 : s:Util_get_indent_level(a:context, a:lnum) + 3) 62 | else 63 | let level = (strlen(substitute(line, '\s*', '', 'g')) > 40 ? 2 : 3) 64 | let level -= (line =~ '=') 65 | endif 66 | return level 67 | endfunction 68 | call s:Util.function('get_comment_heading_level') 69 | 70 | "----------------------------------------------------------------------------- 71 | " Matching 72 | 73 | " join_to( {context}, {lnum}, {pattern} [, {limit}]) 74 | function! s:Util_join_to(context, lnum, pattern, ...) abort 75 | let lines = a:context.lines 76 | let limit = (a:0 ? a:1 : 3) 77 | if limit < 0 78 | return s:join_to_backward(lines, a:lnum, a:pattern, limit * -1) 79 | endif 80 | let lnum = a:lnum 81 | let limit = min([a:lnum + limit, len(lines) - 1]) 82 | while lnum <= limit 83 | let line = lines[lnum] 84 | if line =~# a:pattern 85 | break 86 | endif 87 | let lnum += 1 88 | endwhile 89 | return join(lines[a:lnum : lnum], "\n") 90 | endfunction 91 | call s:Util.function('join_to') 92 | 93 | function! s:join_to_backward(context, lnum, pattern, limit) abort 94 | let lines = a:context.lines 95 | let lnum = max([1, a:lnum - a:limit]) 96 | while lnum > 0 97 | let line = lines[lnum] 98 | if line =~# a:pattern 99 | break 100 | endif 101 | let lnum -= 1 102 | endwhile 103 | return join(lines[lnum : a:lnum], "\n") 104 | endfunction 105 | 106 | function! s:Util_join_to_rparen(context, lnum, ...) abort 107 | let limit = (a:0 ? a:1 : 3) 108 | let line = s:Util_join_to(a:context, a:lnum, ')', limit) 109 | let line = substitute(line, "\\s*\n\\s*", ' ', 'g') 110 | let line = substitute(line, ')\zs.*$', '', '') 111 | return line 112 | endfunction 113 | call s:Util.function('join_to_rparen') 114 | 115 | " neighbor_match( {context}, {lnum}, {pattern} [, {range} [, {exclusive}]) 116 | function! s:Util_neighbor_match(context, lnum, pattern, ...) abort 117 | let lines = a:context.lines 118 | let range = get(a:000, 0, 1) 119 | let exclusive = !!get(a:000, 1, 0) 120 | if type(range) == type([]) 121 | let [prev, next] = range 122 | else 123 | let [prev, next] = [range, range] 124 | endif 125 | let [bwd_range, fwd_range] = s:neighbor_ranges(a:context, a:lnum, prev, next, exclusive) 126 | for lnum in bwd_range 127 | if lines[lnum] =~# a:pattern 128 | return 1 129 | endif 130 | endfor 131 | for lnum in fwd_range 132 | if lines[lnum] =~# a:pattern 133 | return 1 134 | endif 135 | endfor 136 | return 0 137 | endfunction 138 | call s:Util.function('neighbor_match') 139 | 140 | function! s:neighbor_ranges(context, lnum, prev, next, exclusive) abort 141 | let max_lnum = len(a:context.lines) - 1 142 | let bwd_range = range(max([1, a:lnum - a:prev]), max([1, a:lnum - a:exclusive])) 143 | let fwd_range = range(min([a:lnum + a:exclusive, max_lnum]), min([a:lnum + a:next, max_lnum])) 144 | return [bwd_range, fwd_range] 145 | endfunction 146 | 147 | " neighbor_matchstr( {context}, {lnum}, {pattern} [, {range} [, {exclusive}]) 148 | function! s:Util_neighbor_matchstr(context, lnum, pattern, ...) abort 149 | let lines = a:context.lines 150 | let range = get(a:000, 0, 1) 151 | let exclusive = !!get(a:000, 1, 0) 152 | if type(range) == type([]) 153 | let [prev, next] = range 154 | else 155 | let [prev, next] = [range, range] 156 | endif 157 | let [bwd_range, fwd_range] = s:neighbor_ranges(a:context, a:lnum, prev, next, exclusive) 158 | for lnum in bwd_range 159 | let matched = matchstr(lines[lnum], a:pattern) 160 | if !empty(matched) 161 | return matched 162 | endif 163 | endfor 164 | for lnum in fwd_range 165 | let matched = matchstr(lines[lnum], a:pattern) 166 | if !empty(matched) 167 | return matched 168 | endif 169 | endfor 170 | return "" 171 | endfunction 172 | call s:Util.function('neighbor_matchstr') 173 | 174 | let s:SHARED_PATTERNS = { 175 | \ '*': { 176 | \ 'parameter_list': '\S\s*\zs([^)]*)', 177 | \ 'parameter_list_and_after': '\S\s*\zs([^)]*).*$', 178 | \ 'after_lbrace' : '{.*$', 179 | \ 'after_lbracket': '[.*$', 180 | \ 'after_lparen' : '(.*$', 181 | \ 'after_colon' : ':.*$', 182 | \ }, 183 | \ 'c': { 184 | \ 'heading-1': '^\s*\/\*\s*[-=*]\{10,}\s*$', 185 | \ 'header' : ['^/\*', '\*/\s*$'], 186 | \ }, 187 | \ 'cpp': { 188 | \ 'heading-1': '^\s*/[/*]\s*[-=/*]\{10,}\s*$', 189 | \ 'header' : { 190 | \ 'leading': '^//', 191 | \ 'block' : ['^/\*', '\*/\s*$'], 192 | \ }, 193 | \ }, 194 | \ 'sh': { 195 | \ 'heading-1': '^\s*#\s*[-=#]\{10,}\s*$', 196 | \ 'header' : '^#', 197 | \ }, 198 | \} 199 | 200 | function! s:Util_shared_pattern(filetype, which) abort 201 | return s:SHARED_PATTERNS[a:filetype][a:which] 202 | endfunction 203 | call s:Util.function('shared_pattern') 204 | 205 | "----------------------------------------------------------------------------- 206 | " List 207 | 208 | let s:List = unite#sources#outline#modules#base#new('List', s:SID) 209 | let s:Util.List = s:List 210 | 211 | function! s:List_sort_by_lnum(dicts) abort 212 | return sort(a:dicts, 's:compare_by_lnum') 213 | endfunction 214 | function! s:compare_by_lnum(d1, d2) abort 215 | let n1 = a:d1.lnum 216 | let n2 = a:d2.lnum 217 | return n1 == n2 ? 0 : n1 > n2 ? 1 : -1 218 | endfunction 219 | call s:List.function('sort_by_lnum') 220 | 221 | unlet s:List 222 | 223 | "----------------------------------------------------------------------------- 224 | " Path 225 | 226 | let s:Path = unite#sources#outline#modules#base#new('Path', s:SID) 227 | let s:Util.Path = s:Path 228 | 229 | " Path.normalize( {path} [, {mods}]) 230 | function! s:Path_normalize(path, ...) abort 231 | let path = a:path 232 | if a:0 233 | let mods = a:0 234 | let path = fnamemodify(path, mods) 235 | endif 236 | let path = substitute(path, '[/\\]', '/', 'g') 237 | return path 238 | endfunction 239 | call s:Path.function('normalize') 240 | 241 | unlet s:Path 242 | 243 | "----------------------------------------------------------------------------- 244 | " String 245 | 246 | let s:String = unite#sources#outline#modules#base#new('String', s:SID) 247 | let s:Util.String = s:String 248 | 249 | " String.capitalize( {str} [, {flag}]) 250 | function! s:String_capitalize(str, ...) abort 251 | let flag = (a:0 ? a:1 : '') 252 | return substitute(a:str, '\<\(\h\)\(\w\+\)\>', '\u\1\L\2', flag) 253 | endfunction 254 | call s:String.function('capitalize') 255 | 256 | " Ported from: 257 | " Sample code from Programing Ruby, page 145 258 | " 259 | function! s:String_nr2roman(nr) abort 260 | if a:nr <= 0 || 4999 < a:nr 261 | return string(a:nr) 262 | endif 263 | let factors = [ 264 | \ ["M", 1000], ["CM", 900], ["D", 500], ["CD", 400], 265 | \ ["C", 100], ["XC", 90], ["L", 50], ["XL", 40], 266 | \ ["X", 10], ["IX", 9], ["V", 5], ["IV", 4], 267 | \ ["I", 1], 268 | \] 269 | let nr = a:nr 270 | let roman = "" 271 | for [code, factor] in factors 272 | let cnt = nr / factor 273 | let nr = nr % factor 274 | if cnt > 0 275 | let roman .= repeat(code, cnt) 276 | endif 277 | endfor 278 | return roman 279 | endfunction 280 | call s:String.function('nr2roman') 281 | 282 | function! s:String_shellescape(str) abort 283 | if &shell =~? '^\%(cmd\%(\.exe\)\=\|command\.com\)\%(\s\|$\)' || unite#util#is_windows() 284 | return '"' . substitute(a:str, '"', '""', 'g') . '"' 285 | else 286 | return "'" . substitute(a:str, "'", "'\\\\''", 'g') . "'" 287 | endif 288 | endfunction 289 | call s:String.function('shellescape') 290 | 291 | unlet s:String 292 | 293 | "----------------------------------------------------------------------------- 294 | " Misc 295 | 296 | function! s:Util_print_debug(which, msg) abort 297 | if get(g:, 'unite_source_outline_' . a:which . '_debug', 0) 298 | echomsg "unite-outline: " . a:msg 299 | endif 300 | endfunction 301 | call s:Util.function('print_debug') 302 | 303 | function! s:Util_print_progress(msg) abort 304 | echon a:msg 305 | redraw 306 | endfunction 307 | call s:Util.function('print_progress') 308 | 309 | function! s:Util__cpp_is_in_comment(heading_line, matched_line) abort 310 | return ((a:matched_line =~ '^\s*//' && a:heading_line =~ '^\s*//') || 311 | \ (a:matched_line =~ '^\s*/\*' && a:matched_line !~ '\*/\s*$')) 312 | endfunction 313 | call s:Util.function('_cpp_is_in_comment') 314 | 315 | let &cpo = s:save_cpo 316 | unlet s:save_cpo 317 | -------------------------------------------------------------------------------- /autoload/unite/sources/outline/util.vim: -------------------------------------------------------------------------------- 1 | "============================================================================= 2 | " File : autoload/unite/source/outline/util.vim 3 | " Author : h1mesuke 4 | " Updated : 2012-01-11 5 | " Version : 0.5.1 6 | " License : MIT license {{{ 7 | " 8 | " Permission is hereby granted, free of charge, to any person obtaining 9 | " a copy of this software and associated documentation files (the 10 | " "Software"), to deal in the Software without restriction, including 11 | " without limitation the rights to use, copy, modify, merge, publish, 12 | " distribute, sublicense, and/or sell copies of the Software, and to 13 | " permit persons to whom the Software is furnished to do so, subject to 14 | " the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included 17 | " in all copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | " }}} 27 | "============================================================================= 28 | 29 | let s:save_cpo = &cpo 30 | set cpo&vim 31 | 32 | let s:Util = unite#sources#outline#import('Util') 33 | 34 | " NOTE: All of the functions in this file are obsolete now. If you need any of 35 | " them, please import Util module and call them as Dictionary functions. 36 | 37 | "----------------------------------------------------------------------------- 38 | " Heading 39 | 40 | function! unite#sources#outline#util#get_indent_level(...) abort 41 | return call(s:Util.get_indent_level, a:000) 42 | endfunction 43 | 44 | function! unite#sources#outline#util#get_comment_heading_level(...) abort 45 | return call(s:Util.get_comment_heading_level, a:000) 46 | endfunction 47 | 48 | "----------------------------------------------------------------------------- 49 | " Matching 50 | 51 | function! unite#sources#outline#util#join_to(...) abort 52 | return call(s:Util.join_to, a:000) 53 | endfunction 54 | 55 | function! unite#sources#outline#util#join_to_rparen(...) abort 56 | return call(s:Util.join_to_rparen, a:000) 57 | endfunction 58 | 59 | function! unite#sources#outline#util#neighbor_match(...) abort 60 | return call(s:Util.neighbor_match, a:000) 61 | endfunction 62 | 63 | function! unite#sources#outline#util#neighbor_matchstr(...) abort 64 | return call(s:Util.neighbor_matchstr, a:000) 65 | endfunction 66 | 67 | function! unite#sources#outline#util#shared_pattern(...) abort 68 | return call(s:Util.shared_pattern, a:000) 69 | endfunction 70 | 71 | "----------------------------------------------------------------------------- 72 | " Path 73 | 74 | function! unite#sources#outline#util#normalize_path(...) abort 75 | return call(s:Util.Path.normalize, a:000) 76 | endfunction 77 | 78 | "----------------------------------------------------------------------------- 79 | " String 80 | 81 | function! unite#sources#outline#util#capitalize(...) abort 82 | return call(s:Util.String.capitalize, a:000) 83 | endfunction 84 | 85 | function! unite#sources#outline#util#nr2roman(...) abort 86 | return call(s:Util.String.nr2roman, a:000) 87 | endfunction 88 | 89 | function! unite#sources#outline#util#shellescape(...) abort 90 | return call(s:Util.String.shellescape, a:000) 91 | endfunction 92 | 93 | "----------------------------------------------------------------------------- 94 | " Misc 95 | 96 | function! unite#sources#outline#util#print_debug(...) abort 97 | return call(s:Util.print_debug, a:000) 98 | endfunction 99 | 100 | function! unite#sources#outline#util#print_progress(...) abort 101 | return call(s:Util.print_progress, a:000) 102 | endfunction 103 | 104 | function! unite#sources#outline#util#sort_by_lnum(...) abort 105 | return call(s:Util.List.sort_by_lnum, a:000) 106 | endfunction 107 | 108 | function! unite#sources#outline#util#_cpp_is_in_comment(...) abort 109 | return call(s:Util._cpp_is_in_comment, a:000) 110 | endfunction 111 | 112 | let &cpo = s:save_cpo 113 | unlet s:save_cpo 114 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | tags-* 3 | -------------------------------------------------------------------------------- /doc/unite-outline.jax: -------------------------------------------------------------------------------- 1 | *unite-outline.txt* バッファの見出し一覧を表示し、ジャンプ機能を提供する。 2 | 3 | Author : h1mesuke 4 | Shougo 5 | Updated : 2012-01-11 6 | Version : 0.5.1 7 | License : MIT license {{{ 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining 10 | a copy of this software and associated documentation files (the 11 | "Software"), to deal in the Software without restriction, including 12 | without limitation the rights to use, copy, modify, merge, publish, 13 | distribute, sublicense, and/or sell copies of the Software, and to 14 | permit persons to whom the Software is furnished to do so, subject to 15 | the following conditions: 16 | The above copyright notice and this permission notice shall be 17 | included in all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | }}} 27 | 28 | 目次 *unite-outline-contents* 29 | 30 | 概要 |unite-outline-introduction| 31 | インストール |unite-outline-install| 32 | 使い方 |unite-outline-usage| 33 | 設定 |unite-outline-settings| 34 | 変数 |unite-outline-variables| 35 | 設定例 |unite-outline-settings-example| 36 | Outline Info |unite-outline-info| 37 | outline info の作成 |unite-outline-info-create| 38 | outline info の属性 |unite-outline-info-attributes| 39 | 外部プログラム |unite-outline-info-external-programs| 40 | 関数 |unite-outline-functions| 41 | ユーティリティ関数 |unite-outline-utility-functions| 42 | ToDo |unite-outline-todo| 43 | 既知の問題 |unite-outline-known-issues| 44 | 更新履歴 |unite-outline-changelog| 45 | 46 | ============================================================================== 47 | 概要 *unite-outline-introduction* 48 | 49 | *unite-outline* は、バッファの見出しを抽出し、|unite|のインターフェー 50 | スを使ってそれらを一覧表示、各見出しへのジャンプ機能を提供する source 51 | です。見出しを抽出するためのパターンおよび見出しレベルの決定ロジックを 52 | ファイルタイプごとに設定することができ、ユーザーによる高度なカスタマイ 53 | ズが可能です。 54 | 55 | ============================================================================== 56 | インストール *unite-outline-install* 57 | 58 | 配布アーカイブに含まれるファイル群を、そのフォルダごと Vim の 59 | 'runtimepath' にコピーします。 $HOME/.vim(Windows の場合は 60 | $HOME/vimfiles)へのインストールがもっとも一般的でしょう。 61 | インストール後の配置は 62 | 63 | $HOME/.vim/autoload/unite/sources/outline.vim 64 | $HOME/.vim/autoload/unite/sources/outline/ 65 | $HOME/.vim/autoload/unite/filters/*.vim 66 | $HOME/.vim/doc/unite-outline.* 67 | 68 | になります。 69 | 70 | インストールに成功すると :Unite outline でバッファの見出し一覧を表示で 71 | きます。(そのファイルタイプ用の outline info が存在する場合) 72 | 73 | 74 | C, C++, Java, etc~ 75 | 76 | * Exuberant Ctags(必須) 77 | http://ctags.sourceforge.net/ 78 | 79 | ============================================================================== 80 | 使い方 *unite-outline-usage* 81 | 82 | |unite|の使い方については、unite.vim のヘルプを参照して下さい。ここで 83 | は、unite.vim の source である unite-outline の使い方を説明します。 84 | 85 | 見出し一覧を表示する ~ 86 | 87 | バッファの見出し一覧を表示するには、source として outline を指定し、 88 | :Unite を実行します。 89 | > 90 | :Unite outline 91 | < 92 | これにより、ファイルタイプごとに定義された outline info にもとづく見出 93 | しの抽出が行われ、unite のインターフェースを使って見出しの一覧が表示さ 94 | れます。表示された一覧から見出しを選択すると、該当箇所へジャンプできま 95 | す。 96 | 97 | 抽出された見出しはキャッシュされ、2回目以降は見出し一覧の表示が高速に 98 | なります。 99 | 100 | 見出しを絞り込む ~ 101 | 102 | |unite-usage|を参照 103 | 104 | 見出し一覧を更新する ~ 105 | 106 | キャッシュの内容を破棄し、見出しの抽出をやり直したい場合は、outline の 107 | 引数に "!" を指定して :Unite を実行します。 108 | > 109 | :Unite outline:! 110 | < 111 | もしくは、見出し一覧が表示されている状態(ノーマルモード)で 112 | |(unite_redraw)|(デフォルトのキーマッピングでは )を実行し 113 | ます。 114 | 115 | NOTE: バージョン 0.5.0 から見出しの自動更新が可能になりました。 116 | 詳細は|unite-outline-filetype-option-auto-update|を参照 117 | 118 | ============================================================================== 119 | 設定 *unite-outline-settings* 120 | 121 | ------------------------------------------------------------------------------ 122 | 変数 *unite-outline-variables* 123 | 124 | g:unite_source_outline_info *g:unite_source_outline_info* 125 | 126 | ファイルタイプごとの outline info を格納する辞書 127 | オートロード関数を使わず、vimrc にて直に outline info を定義す 128 | る場合にのみ、作成した outline info をこの辞書に登録します。 129 | 130 | outline info ついては 131 | |unite-outline-info|, |unite-outline-info-create|を参照 132 | 133 | 初期値は {} 134 | 135 | unite-outline に同梱されている outline info はオートロード関数 136 | によって遅延ロードされるため、この辞書の初期値は空になっていま 137 | す。 138 | *g:unite_source_outline_indent_width* 139 | g:unite_source_outline_indent_width 140 | 141 | 見出しレベルに応じて設定されるインデントの幅 142 | unite-outline はこの値にもとづいて見出し一覧のインデントを生成 143 | します。 144 | 145 | 初期値は 2 146 | *g:unite_source_outline_filetype_options* 147 | g:unite_source_outline_filetype_options 148 | 149 | ファイルタイプごとのオプション設定を行うための辞書 150 | ファイルタイプごとに、オプション名をキー、オプション値を値とす 151 | る辞書を設定します。 152 | 153 | 「すべてのファイルタイプ」を意味する特殊なファイルタイプ名とし 154 | て "*" が使用できます。個別の設定がなされていないファイルタイ 155 | プにはその設定が適用されます。 156 | 157 | 初期値は {} 158 | 159 | 設定例: > 160 | let g:unite_source_outline_filetype_options = { 161 | \ '*': { 162 | \ 'auto_update': 1, 163 | \ 'auto_update_event': 'write', 164 | \ }, 165 | \ 'cpp': { 166 | \ 'auto_update': 0, 167 | \ }, 168 | \ 'javascript': { 169 | \ 'ignore_types': ['comment'], 170 | \ }, 171 | \ 'markdown': { 172 | \ 'auto_update_event': 'hold', 173 | \ }, 174 | \} 175 | < 176 | 設定可能なオプション ~ 177 | 178 | auto_update *unite-outline-filetype-option-auto-update* 179 | 180 | 見出しの自動更新を行うかどうか。 181 | デフォルト値は 1 182 | 183 | *unite-outline-filetype-option-auto-update-event* 184 | auto_update_event 185 | 186 | 見出しの自動更新を行うタイミング 187 | 以下のいずれか。 188 | 189 | 値 見出しの更新契機 190 | -------------------------------------------- 191 | "write" |BufWritePost| 192 | "hold" |BufWritePost|, |CursorHold| 193 | 194 | デフォルト値は "write" 195 | 196 | NOTE: 見出しの更新は、前回の更新時からバッファの内容が 197 | 変更されていた場合にのみ行われます。また、"hold" を使 198 | 用する場合、'updatetime' が見出しの更新間隔になります 199 | ので、適切な値に設定して下さい。 200 | 201 | ignore_types *unite-outline-filetype-option-ignore-types* 202 | 203 | 非表示にしたい見出しの種類のリスト 204 | 指定可能な見出しの種類については outline info の定義を 205 | 参照 206 | 207 | デフォルト値は [] 208 | 209 | *g:unite_source_outline_max_headings* 210 | g:unite_source_outline_max_headings 211 | 212 | 抽出する見出し数の上限 213 | 見出しの数がこの値に達すると見出しの抽出を打ち切ります。 214 | 215 | 初期値は 1000 216 | *g:unite_source_outline_cache_limit* 217 | g:unite_source_outline_cache_limit 218 | 219 | キャッシュ永続化の行数しきい値 220 | 221 | 見出しのキャッシュは通常バッファローカル変数に保存されますが、 222 | 見出し抽出の対象バッファの行数がこの値より大きい場合、キャッ 223 | シュをファイルにも保存します。 224 | 225 | キャッシュがファイルに保存されると、Vim の再起動後もそのファイ 226 | ルから見出しを読み込むため、大きなバッファの見出し一覧の表示が 227 | 初回から高速になります。 228 | 229 | 初期値は 1000 230 | *g:unite_source_outline_highlight* 231 | g:unite_source_outline_highlight 232 | 233 | 見出し一覧のハイライトを指定するための辞書 234 | 見出しのグループごとに適用するハイライトを変更できます。 235 | 236 | 初期値は {} 237 | 238 | 設定例: > 239 | let g:unite_source_outline_highlight = { 240 | \ 'comment' : 'Comment', 241 | \ 'expanded': 'Constant', 242 | \ 'function': 'Function', 243 | \ 'id' : 'Special', 244 | \ 'macro' : 'Macro', 245 | \ 'method' : 'Function', 246 | \ 'normal' : 'Normal', 247 | \ 'package' : 'Normal', 248 | \ 'special' : 'Macro', 249 | \ 'type' : 'Type', 250 | \ 'level_1' : 'Type', 251 | \ 'level_2' : 'PreProc', 252 | \ 'level_3' : 'Identifier', 253 | \ 'level_4' : 'Constant', 254 | \ 'level_5' : 'Special', 255 | \ 'level_6' : 'Normal', 256 | \ 'parameter_list': 'Normal', 257 | \ } 258 | < 259 | ハイライトを適用する部分を指定するためのパターンは、個々のファ 260 | イルタイプ用の outline info で定義します。 261 | 262 | 詳細は|unite-outline-info-highlight_rules|を参照 263 | 264 | ------------------------------------------------------------------------------ 265 | 設定例 *unite-outline-settings-example* 266 | > 267 | nnoremap [unite] 268 | nmap f [unite] 269 | 270 | nnoremap [unite]o :Unite -buffer-name=outline outline 271 | 272 | call unite#set_buffer_name_option('outline', 'ignorecase', 1) 273 | call unite#set_buffer_name_option('outline', 'smartcase', 1) 274 | < 275 | ============================================================================== 276 | Outline Info *unite-outline-info* 277 | 278 | unite-outline では、ファイルタイプごとの見出しの抽出パターンと、見出し 279 | レベルの決定ロジック(関数)などを outline info と呼ばれる辞書によって 280 | 定義します。これを vimrc にて、あるいは所定の位置に配置した Vim script 281 | によって記述することで、ファイルタイプごとの見出し抽出と見出し一覧の作 282 | 成を自在にカスタマイズできます。 283 | 284 | 見出し一覧の表示を実行した際、対象バッファのファイルタイプにもとづき 285 | outline info の探索が実行されます。探索の順序は以下の通りです。 286 | 287 | 1. g:unite_source_outline_info.{filetype} 288 | 2. outline#{filetype}#outline_info() 289 | 3. unite#sources#outline#{filetype}#outline_info() 290 | 4. unite#sources#outline#defaults#{filetype}#outline_info() 291 | 292 | ------------------------------------------------------------------------------ 293 | outline info の作成 *unite-outline-info-create* 294 | 295 | unite-outline に同梱されている outline info ではなく、ユーザー独自の 296 | outline info を作成/使用したい場合、その方法は以下の2つです。 297 | 298 | A. オートロード関数を定義する。 [推奨] 299 | 300 | * $HOME/.vim/autoload/unite/sources/outline/ に 301 | {filetype}.vim を作成し、そこにオートロード関数 302 | unite#sources#outline#{filetype}#outline_info() を定義する。 303 | 304 | または 305 | 306 | $HOME/.vim/autoload/outline/ に 307 | {filetype}.vim を作成し、そこにオートロード関数 308 | outline#{filetype}#outline_info() を定義する。 309 | 310 | * 関数の返値として、outline info(辞書)を返す。 311 | 312 | この方法で定義した outline info は必要になるまでロードされませ 313 | ん。 vimrc を肥大化させることもないので、outline info を作り込 314 | むのであればこちらの方法がおすすめです。 315 | 316 | $HOME/.vim/autoload/unite/sources/outline/defaults/ にあるデフ 317 | ォルトの outline info はすべてこの方法で定義されています。 318 | 319 | B. vimrc にてグローバル変数に設定する。 [非推奨] 320 | 321 | * vimrc にて g:unite_source_outline_info.{filetype} に直接 322 | outline info を設定する。 323 | 324 | 定義例(Ruby用): > 325 | let g:unite_source_outline_info.ruby = { 326 | \ 'heading': '^\s*\(module\|class\|def\)\>', 327 | \ 'skip': { 328 | \ 'header': '^#', 329 | \ 'block' : ['^=begin', '^=end'], 330 | \ }, 331 | \} 332 | < 333 | ------------------------------------------------------------------------------ 334 | outline info の属性 *unite-outline-info-attributes* 335 | 336 | outline info の属性は以下の通りです。unite-outline はそれぞれの属性に 337 | 設定された値にもとづき、ファイルタイプ固有の見出し抽出を行います。 338 | 339 | EXTRACTING HEADINGS BY CALLBACK ~ 340 | *unite-outline-info-heading-1* 341 | heading-1 文字列(任意) 342 | 343 | 「次の行が」見出しであるような行にマッチするパターン 344 | これを設定することで、例えば 345 | > 346 | ========================================= 347 | 見出し1 348 | < 349 | や 350 | > 351 | ----------------------------------------- 352 | 見出し2 353 | < 354 | のような、飾りの枠線の下にくるタイプの見出しを抽出できます。 355 | また、 356 | > 357 | /**************************************** 358 | * 359 | * 見出し3 360 | * 361 | ****************************************/ 362 | < 363 | こういうタイプの見出しにも対応できるよう、次の行が実質上の空行 364 | とみなせる場合は、もうひとつ次の行も見るにようになっています。 365 | 366 | 定義例: > 367 | let s:outline_info = { 368 | \ 'heading-1': '^[-=]\{10,}\s*$', 369 | \ } 370 | < 371 | *unite-outline-info-heading* 372 | heading 文字列(任意) 373 | 374 | 「その行が」見出しであるような行にマッチするパターン 375 | 376 | 定義例(HTML用): > 377 | let s:outline_info = { 378 | \ 'heading': '<[hH][1-6][^>]*>', 379 | \ } 380 | < 381 | *unite-outline-info-heading-pattern-restrictions* 382 | 重要:使用できる正規表現の制約 ~ 383 | 384 | heading-1, heaging, heading+1 のパターンとして使用できる正規表 385 | 現には以下の制約があります。 386 | 387 | 1. 'magic'オプションがオンである場合の書法を用いること 388 | 2. 後方参照(\1..\9)を使用しないこと |/magic|, |/\1| 389 | 390 | これらは、見出し抽出時のパターンマッチングの速度を最大限に上げ 391 | るためにもうけられている制約です。見出しの抽出に後方参照が必要 392 | な場合は、 heading-1, heading, heading+1 には後方参照のない緩 393 | めのパターンを設定し、マッチ後の create_heading() 関数にて再度、 394 | 後方参照を用いた厳密なマッチングを行うといった方法で対処して下 395 | さい。 396 | *unite-outline-info-heading+1* 397 | heading+1 文字列(任意) 398 | 399 | 「前の行が」見出しであるような行にマッチするパターン 400 | これを設定することで、例えば Markdown の 401 | > 402 | 見出し 403 | ------ 404 | < 405 | のような、下線をともなうタイプの見出しを抽出できます。 406 | 407 | 定義例(Markdown用): > 408 | let s:outline_info = { 409 | \ 'heading' : '^#\+', 410 | \ 'heading+1': '^[-=]\+$', 411 | \ } 412 | < 413 | *unite-outline-info-create_heading()* 414 | create_heading 関数(任意) 415 | 416 | create_heading( 417 | {which}, {heading-line}, {matched-line}, {context}) 418 | 419 | 設定されていると、heading-1, heading, heading+1 によるマッチが 420 | 成功するたびに呼び出されます。 421 | 返値として見出しオブジェクト(辞書)を返します。 422 | 423 | この関数を定義することで、見出し一覧に設定する文字列の整形、お 424 | よび見出しレベル(インデント)の設定が行えます。 425 | 426 | create_heading() 関数に渡される引数は以下の通りです。 427 | 428 | * {which} 文字列 429 | マッチの種類 430 | "heading-1", "heading", "heading+1" の 431 | いずれか 432 | 433 | * {heading-line} 文字列 434 | 見出しとなる行 435 | 436 | * {matched-line} 文字列 437 | マッチした行 438 | 439 | *unite-outline-context-object* 440 | * {context} 辞書 441 | その他の情報、以下の属性を含む 442 | 443 | * heading_lnum 整数 444 | {heading-line} の行番号 445 | 446 | * matched_lnum 整数 447 | {matched-line} の行番号 448 | 449 | * lines リスト 450 | バッファの全行 451 | リストの添字と行番号が一致するよう、ダ 452 | ミーの空行が先頭に付加されている。イテ 453 | レートの際は注意。 454 | 455 | * buffer 辞書 456 | バッファ情報 457 | 458 | * nr 整数 459 | バッファ番号 460 | 461 | * path 文字列 462 | バッファで編集中のファイルのパス 463 | 464 | * filetype 文字列 465 | バッファのファイルタイプ 466 | 467 | 参照可能なすべての属性については 468 | autoload/unite/source/outline.vim を参 469 | 照 470 | 471 | * outline_info 辞書 472 | outline info 473 | 474 | {context} に渡される辞書は見出し抽出の間同じものが使い回されま 475 | すので、既存の属性を書き換えないで下さい。 476 | 477 | *unite-outline-heading-object* 478 | HEADING OBJECT ~ 479 | 480 | 返値となる辞書には以下の属性を設定します。 481 | 482 | * word 文字列(必須) 483 | 見出し一覧に表示される文字列 484 | 485 | * level 整数 (任意) 486 | 見出しレベル 487 | 設定しておくと、見出し一覧に表示される際、レベ 488 | ルに応じたインデントが付加されます。 489 | 省略した場合は 1 になります。 490 | 491 | 参照:|g:unite_source_outline_indent_width| 492 | 493 | * type 文字列(任意) 494 | 見出しの種類 495 | 省略した場合は "generic" になります。 496 | 497 | 空の辞書を返すと、見出しではないとみなされ、無視されます。 498 | 499 | 定義例(HTML用): > 500 | function! s:outline_info.create_heading(which, heading_line, matched_line, context) 501 | let level = str2nr(matchstr(a:heading_line, '<[hH]\zs[1-6]\ze[^>]*>')) 502 | let heading = { 503 | \ 'word' : "h" . level. ". " . s:get_text_content(level, a:context) 504 | \ 'level': level, 505 | \ 'type' : 'generic', 506 | \ } 507 | return heading 508 | endfunction 509 | < 510 | *unite-outline-info-skip* 511 | skip 辞書(任意) 512 | 513 | 見出し抽出の対象としない領域を指定するための辞書 514 | 以下の属性を設定することで、指定の領域を見出し抽出の対象外にで 515 | きます。 516 | 517 | *unite-outline-info-skip-header* 518 | header 文字列、リスト、辞書のいずれか(任意) 519 | バッファの先頭にあるヘッダ部分(作者や著作権の表示があ 520 | る部分)から見出しが抽出されるのを防ぐために設定します。 521 | 522 | (a) 文字列が設定された場合は、それをパターンとみなし、 523 | バッファの先頭からそのパターンにマッチする行が続く 524 | 間をスキップします。 525 | > 526 | \ 'skip': { 527 | \ 'header': '^#', 528 | \ }, 529 | < 530 | (b) リストが設定された場合は、それをパターンのペアと見 531 | なし、ファイルの先頭が skip.header[0] にマッチする 532 | 場合に、 skip.header[1] にマッチする行までをスキッ 533 | プします。 534 | > 535 | \ 'skip': { 536 | \ 'header': ['^/\*', '\*/\s*$'], 537 | \ }, 538 | < 539 | (c) 辞書が設定された場合は、leading属性に (a) のパター 540 | ン、 block属性に (b) のリストが設定されているもの 541 | とし、バッファの先頭からそれぞれにマッチする部分を 542 | スキップします。 543 | > 544 | \ 'skip': { 545 | \ 'header': { 546 | \ 'leading': '^//', 547 | \ 'block' : ['^/\*', '\*/\s*$'], 548 | \ }, 549 | \ }, 550 | < 551 | block リスト(任意) *unite-outline-info-skip-block* 552 | 設定されていると、値をパターンのペアと見なし、バッファ 553 | 中の、 skip.block[0] にマッチする行から skip.block[1] 554 | にマッチする行までをスキップします。 555 | > 556 | \ 'skip': { 557 | \ 'block': ['^=begin', '^=end'], 558 | \ }, 559 | < 560 | EXTRACTING HEADINGS BY YOURSELF ~ 561 | *unite-outline-info-extract_headings()* 562 | extract_headings 関数(任意) 563 | 564 | extract_headings( {context}) 565 | 566 | 設定されていると、見出しを抽出するために呼ばれます。 567 | 返値として見出し(辞書)のリストまたはツリーを返します。 568 | 569 | この関数を定義することで、outline info独自の見出し抽出を実装で 570 | きます。これにより、従来の正規表現を使ったパターンマッチによる 571 | 方法では見出しの抽出が困難な場合でも、外部の構文解析プログラム 572 | を利用するなどの方法が可能になります。 573 | 574 | extract_headings() に渡される引数は以下の通りです。 575 | 576 | * {context} 辞書 577 | 詳細は|unite-outline-context-object|を参照 578 | 579 | 返値は見出し(辞書)のリストまたはツリーであり、個々の見出しに 580 | は |unite-outline-heading-object|の属性に加え、以下の属性も設 581 | 定する必要があります。 582 | 583 | * lnum 整数 (必須) 584 | 見出し行の行番号 585 | 586 | 見出しのツリーを返す ~ 587 | 588 | アウトラインを解析する過程で outline info が見出しのツリー構造 589 | を把握できる場合、extract_headings() にて見出しのツリーを構築 590 | し、それを返値とすることができます。 591 | 592 | 見出しのツリーは以下のように作成します。 593 | 594 | 例: > 595 | let s:Tree = unite#sources#outline#import('Tree') 596 | 597 | let root = s:Tree.new() 598 | call s:Tree.append_child(root, heading_A) 599 | call s:Tree.append_child(root, heading_B) 600 | call s:Tree.append_child(heading_A, heading_1) 601 | call s:Tree.append_child(heading_A, heading_2) 602 | call s:Tree.append_child(heading_B, heading_3) 603 | < 604 | トップレベルの見出しは Tree.new() で生成した root の子となるよ 605 | うにし、以下、見出し間の親子関係を Tree.append_child() にて設 606 | 定します。 607 | 608 | これにより、下図のような構造のツリーができます。 609 | extract_headings() からは root を返します。(見出し一覧には 610 | root は表示されません) 611 | > 612 | root 613 | | 614 | +--heading_A 615 | | +--heading_1 616 | | +--heading_2 617 | | 618 | +--heading_B 619 | +--heading_3 620 | < 621 | 見出しのツリーを返す場合、見出しの親子関係から見出しレベルを決 622 | 定できるため、個々の見出しに level属性を設定する必要はありませ 623 | ん。 624 | 625 | FORMATTING ~ 626 | *unite-outline-info-heading_groups* 627 | heading_groups 辞書(任意) 628 | 629 | 見出しのグループ分けを行うための辞書 630 | 設定されていると、見出し一覧を表示する際、互いに異なるグループ 631 | に属する見出しの間に空行が挿入されるようになります。 632 | 633 | 個々のグループは見出しの type のリストです。 634 | 635 | 見出しの抽出に際しては、この属性に設定された辞書を元に、所属す 636 | るグループの名前が見出しの group属性に設定されます。 637 | 638 | 定義例(C++用): > 639 | let s:outline_info = { 640 | \ 'heading_groups': { 641 | \ 'namespace': ['namespace'], 642 | \ 'type' : ['class', 'enum', 'struct', 'typedef'], 643 | \ 'function' : ['function'], 644 | \ 'macro' : ['macro'], 645 | \ }, 646 | \} 647 | < 648 | NARROWING ~ 649 | *unite-outline-info-not_match_patterns* 650 | not_match_patterns リスト(任意) 651 | 652 | 絞り込みの対象にしない部分を指定するパターンのリスト 653 | 見出しの word のうち、このリストに指定したパターンにマッチする 654 | 部分は絞り込みの対象にならなくなります。 655 | 656 | SYNTAX HIGHLIGHTING ~ 657 | *unite-outline-info-highlight_rules* 658 | highlight_rules 辞書(任意) 659 | 660 | 見出し一覧のシンタックスハイライトの定義(辞書)のリスト 661 | シンタックスは、見出し一覧が表示される直前に、リストの添字の順 662 | に定義されます。マッチするパターンが複数ある場合は 663 | |:syn-priority|にあるルールにもとづき適用されるシンタックスが 664 | 決定されます。 665 | 666 | パターンは正規表現で記述できますが、両端を '/' などの記号で囲 667 | む必要があります。(詳細は|:syn-pattern|を参照) 668 | 669 | 定義例(Vim script用): > 670 | let s:outline_info = { 671 | \ 'highlight_rules': [ 672 | \ { 'name' : 'comment', 673 | \ 'pattern' : '/".*/' }, 674 | \ { 'name' : 'augroup', 675 | \ 'pattern' : '/\S\+\ze : augroup/', 676 | \ 'highlight': g:unite_source_outline_highlight.type }, 677 | \ { 'name' : 'function', 678 | \ 'pattern' : '/\S\+\ze\s*(/' }, 679 | \ { 'name' : 'parameter_list', 680 | \ 'pattern' : '/(.*)/' }, 681 | \ ], 682 | \} 683 | < 684 | highlight属性は省略でき、その場合は 685 | |g:unite_source_outline_highlight| 変数に設定されているハイラ 686 | イトが使われます。 687 | 688 | CACHING ~ 689 | *unite-outline-info-is_volatile* 690 | is_volatile 数値(任意) 691 | 692 | 抽出した見出しをキャッシュするかどうか。 693 | 1 を設定すると、見出しはキャッシュされません。 694 | 695 | *unite-outline-info-hooks* 696 | HOOKS ~ 697 | *unite-outline-info-initialize()* 698 | initialize 関数(任意) 699 | 700 | initialize() 701 | 702 | 設定されていると、outline info がロードした後に呼び出されます。 703 | outline info の初期化のために実行すべき処理があればここに記述 704 | します。 705 | *unite-outline-info-before()* 706 | before 関数(任意) 707 | 708 | before( {context}) 709 | 710 | 設定されていると、見出しの抽出が始まる前に呼び出されます。 711 | 見出し抽出前に実行すべき処理があればここに記述します。 712 | 713 | {context} については、|unite-outline-context-object|を参照 714 | 715 | *unite-outline-info-after()* 716 | after 関数(任意) 717 | 718 | after( {context}) 719 | 720 | 設定されていると、見出しの抽出が完了した後に呼び出されます。 721 | 見出し抽出後に実行すべき処理があればここに記述します。 722 | 723 | {context} については、|unite-outline-context-object|を参照 724 | 725 | ------------------------------------------------------------------------------ 726 | 外部プログラム *unite-outline-info-external-programs* 727 | 728 | 同梱されている outline info のうち、一部のファイルタイプ用のものは、見 729 | 出しの抽出に特定の外部プログラムを使用します。 730 | 731 | これらのファイルタイプでの見出し抽出を行うためには、指定された外部プロ 732 | グラムが実行可能である(PATH が通っており、|system()|から呼び出せる) 733 | 必要があります。 734 | 735 | C, C++, Java, etc~ 736 | 737 | * Exuberant Ctags(必須) 738 | http://ctags.sourceforge.net/ 739 | 740 | ============================================================================== 741 | 関数 *unite-outline-functions* 742 | 743 | *unite#sources#outline#alias()* 744 | unite#sources#outline#alias( {alias}, {source}) 745 | 746 | ファイルタイプの別名を設定します。{source} の outline info を 747 | 別のファイルタイプでも利用したい場合に使用します。 748 | 749 | 用例: > 750 | call unite#sources#outline#alias('xhtml', 'html') 751 | call unite#sources#outline#alias('zsh', 'sh') 752 | < 753 | *unite#sources#outline#get_outline_info()* 754 | unite#sources#outline#get_outline_info( 755 | {filetype} [, {reload} [, {nouser}]]) 756 | 757 | {filetype} の outline info を返します。 758 | {reload} が non-zero の場合、outline info を取得する前にスクリ 759 | プトを source し直します。(outline info がオートロード関数を 760 | 使ってファイルに定義されている場合にのみ有効) 761 | {nouser} が non-zero の場合、ユーザー定義の outline info の探 762 | 索をスキップします。 763 | outline info が見つからない場合は空の辞書 {} を返します。 764 | 765 | *unite#sources#outline#get_filetype_option()* 766 | unite#sources#outline#get_filetype_option( 767 | {filetype}, {key} [, {default}]) 768 | 769 | {filetype} のオプション {key} の値を返します。 770 | 設定値が見つからない場合、{default} が指定されていれば 771 | {default} を、そうでないなら 0 を返します。 772 | 773 | *unite#sources#outline#get_highlight()* 774 | unite#sources#outline#get_highlight( {name} ...) 775 | 776 | {name} に関連付けられたハイライトグループ名を返します。 777 | 関連付けがない場合は、引数を順次調べ関連付けを探します。関連付 778 | けが最後まで見つからなかった場合は "Normal" の値を返します。 779 | 780 | ハイライトグループ名への関連付けについては 781 | |g:unite_source_outline_highlight| を参照 782 | 783 | *unite#sources#outline#import()* 784 | unite#sources#outline#import( {module}) 785 | 786 | 組み込みモジュールをインポートします。 787 | > 788 | let s:Util = unite#sources#outline#import('Util') 789 | < 790 | *unite#sources#outline#remove_cache_files()* 791 | unite#sources#outline#remove_cache_files() 792 | 793 | ファイルに保存した見出しのキャッシュを削除します。 794 | 795 | UTILITY FUNCTIONS *unite-outline-utility-functions* 796 | 797 | 以下は、outline info を作成するにあたり、create_heading() や 798 | extract_headings() で使用すると便利なユーティリティ関数です。 799 | 800 | 使用する場合は以下のようにモジュールをインポートし、辞書関数として呼び 801 | 出して下さい。 802 | > 803 | let s:Util = unite#sources#outline#import('Util') 804 | call s:Util.get_indent_level(a:context, h_lnum) 805 | < 806 | {context} には、create_heading() や extract_headings() が引数として 807 | 受け取った辞書|unite-outline-context-object|を渡します。 808 | 809 | HEADINGS ~ 810 | *unite-outline-Util.get_indent_level()* 811 | Util.get_indent_level( {context}, {lnum}) 812 | 813 | 行番号が {lnum} である行のインデントレベルを返します。 814 | 815 | MATCHING ~ 816 | *unite-outline-Util.join_to()* 817 | Util.join_to( {context}, {lnum}, {pattern} [, {limit}]) 818 | 819 | 行番号が {lnum} の行から {pattern} にマッチする行までを連結し 820 | た文字列を返します。連結される行と行の間には "\n" が挿入されま 821 | す。{limit} には最大何行先までマッチを試行/連結するかを指定で 822 | き、省略した場合は 3 になります。{limit} に負の値を指定すると、 823 | 行番号が {lnum} の行から前の行に対してマッチの試行と連結を行い 824 | ます。 825 | *unite-outline-Util.neighbor_match()* 826 | Util.neighbor_match( 827 | {context}, {lnum}, {pattern} [, {range} [, {exclusive}]]) 828 | 829 | 行番号が {lnum} の行およびその前後の行が {pattern} にマッチす 830 | るならば真、そうでないなら偽を返します。{range} には前後の何 831 | 行分に対しマッチを試行するかを指定でき、省略した場合は 1 にな 832 | ります。{range} にリストを指定すると、マッチを試行する行数を前 833 | と後ろ、別々に設定できます。 834 | {exclusive} に 1 を指定すると、行番号が {lnum} の行をマッチの 835 | 試行対象から除外します。 836 | 837 | *unite-outline-Util.neighbor_matchstr()* 838 | Util.neighbor_matchstr( 839 | {context}, {lnum}, {pattern} [, {range} [, {exclusive}]]) 840 | 841 | |unite-outline-Util.neighbor_match()|の派生形。真偽値ではなく、 842 | マッチした部分文字列を返します。マッチしない場合は "" を返しま 843 | す。 844 | 845 | ============================================================================== 846 | TODO *unite-outline-todo* 847 | 848 | * D, Erlang, Go, Haskell などの outline info 849 | 850 | * 対応ファイルタイプの充実 851 | 852 | * Issues - h1mesuke/unite-outline - GitHub 853 | https://github.com/h1mesuke/unite-outline/issues 854 | 855 | ------------------------------------------------------------------------------ 856 | outline info 募集! 857 | 858 | outline info が同梱されていないファイルタイプ用の outline info を作成 859 | された方がおられたら、ぜひとも作者までお寄せ下さい。参考に(もしくは配 860 | 布アーカイブにそのまま同梱)させていただきます。 861 | 862 | * Issues - h1mesuke/unite-outline - GitHub 863 | https://github.com/h1mesuke/unite-outline/issues 864 | 865 | * Send a pull request - GitHub 866 | https://github.com/h1mesuke/unite-outline/pull/new/master 867 | 868 | ============================================================================== 869 | 既知の問題 *unite-outline-issues* 870 | 871 | 親子関係の誤認識 ~ 872 | 873 | unite-outline では、見出しの親子関係をツリー構造で把握しています。 874 | 絞り込みの際には、このツリー構造にもとづき、見出しの親子関係に配慮した 875 | 絞り込みを行います。(小見出しがマッチした見出しも残すなど) 876 | 877 | 現在、一部のファイルタイプでは、ソースコードのインデントの深さから見出 878 | しレベルを決定しています。この場合、作成される見出しのツリーが、必ずし 879 | も論理的に正しい親子関係を反映しないことがあります。結果、絞り込みの結 880 | 果に、実際には親子関係にないはずの見出しが残ることがあります。 881 | 882 | ============================================================================== 883 | 更新履歴 *unite-outline-changelog* 884 | 885 | 0.5.1 2011-11-01 886 | 887 | * unite#sources#outline#get_outline_info() のインターフェースを変更 888 | - ファイルタイプリダイレクトに対応 889 | |unite#sources#outline#get_outline_info()| 890 | 891 | * unite#sources#outline#get_default_outline_info() を削除 892 | 893 | * フックを追加 894 | - initialize |unite-outline-info-initialize| 895 | 896 | * フックの名前を変更 897 | - initialize -> before |unite-outline-info-before| 898 | - finalize -> after |unite-outline-info-after| 899 | 900 | * 内部データの管理を改善 901 | 902 | * 見出しの絞り込みを高速化 903 | - 再帰呼び出しをなくし、反復的に処理するように改善 904 | 905 | 0.5.0 2011-09-06 906 | 907 | * 見出しの自動更新を実装し、以下のファイルタイプオプションを追加 908 | - auto_update |unite-outline-filetype-option-auto-update| 909 | - auto_update_event 910 | 911 | 0.3.8 2011-08-25 912 | 913 | * 見出しの抽出を高速化 914 | これにともない、outline info の heading-1, heading, heading+1 に使用 915 | できる正規表現にいくつかの制約を導入 916 | |unite-outline-info-heading-pattern-restrictions| 917 | 918 | * ファイルタイプごとのオプション設定をまとめるため、以下の変数を追加 919 | -|g:unite_source_outline_filetype_options| 920 | - g:unite_source_outline_ignore_heading_types は上記の変数に統合 921 | 922 | * 以下のキーマッピングを deprecated とした 923 | - (unite_outline_loop_cursor_down) 924 | - (unite_outline_loop_cursor_up) 925 | 926 | 0.3.7 2011-08-14 927 | 928 | * 見出しが1つまで絞り込まれたら、絞り込み結果の最上段にその見出しを複 929 | 製する機能を追加。見出し選択のためのカーソル移動を不要とした。 930 | 931 | * 折り畳みの見出し抽出を実装 |unite-outline-usage| 932 | 933 | 0.3.6 2011-08-08 934 | 935 | * 見出し一覧のシンタックスハイライトに対応し、以下の変数を追加 936 | -|g:unite_source_outline_highlight| 937 | 938 | * outline info の仕様に以下の属性を追加 939 | - highlight_rules |unite-outline-info-highlight_rules| 940 | 941 | 0.3.5 2011-05-14 942 | 943 | * outline info の仕様に以下の属性を追加 944 | - heading_groups |unite-outline-info-heading_groups| 945 | - need_blank_between() 946 | 947 | 0.3.4 2011-04-26 948 | 949 | * キャッシュの管理ロジックを改善し、以下の変数を削除 950 | - g:unite_source_outline_cache_buffers 951 | 952 | * outline info の仕様に以下の属性を追加 953 | - not_match_patterns |unite-outline-info-not_match_patterns| 954 | 955 | * 親子関係に配慮した matcher を実装 956 | 957 | 0.3.3 2011-03-19 958 | 959 | * outline info の仕様から以下の属性を削除 960 | - skip_header() 961 | 962 | * キャッシュの保存ディレクトリを g:unite_data_directory以下に固定し、 963 | 以下の変数を削除 964 | - g:unite_source_outline_cache_dir 965 | 966 | * キャッシュに関するオプション変数を整理 967 | - g:unite_source_outline_cache_serialize_limit を 968 | |g:unite_source_outline_cache_limit|に変更 969 | - 従来の g:unite_source_outline_cache_limit は削除 970 | 971 | 0.3.2 2011-03-01 972 | 973 | * outline info の探索パスに "autoload/outline" を追加 974 | 975 | * outline_info.extract_headings() による、outline info独自の見出し 976 | 抽出に対応 977 | 978 | * {context} の仕様を変更 979 | context.lines の先頭にダミーの空行を付加し、リストの添字と行番号が 980 | 一致するように修正し、以下の属性名を変更 981 | - heading_index -> heading_lnum 982 | - matched_index -> matched_lnum 983 | 984 | * ユーティリティ関数のインターフェースを変更 985 | 引数として、{lines} ではなく {context} を、{idx} ではなく {lnum} を 986 | 受け取るように修正 987 | 988 | 0.3.1 2011-01-29 989 | 990 | * 特定の種類の見出しを非表示にする機能を追加し、以下の変数を追加 991 | -|g:unite_source_outline_ignore_heading_types| 992 | 993 | 0.3.0 2011-01-10 994 | 995 | * create_heading() から見出しのメタ情報をもった辞書を返せるように 996 | outline info の仕様を拡張 997 | 998 | 0.2.1 2011-01-04 999 | 1000 | * キャッシュの一部永続化を実装し、以下の変数を追加 1001 | -|g:unite_source_outline_cache_dir| 1002 | -|g:unite_source_outline_cache_serialize_limit| 1003 | 1004 | vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0:fdm=marker: 1005 | --------------------------------------------------------------------------------