├── LICENSE ├── README.md ├── autoload └── popupiece.vim └── plugin └── popupiece.vim /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 deris 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | popupiece 2 | === 3 | 4 | This is Vim plugin for popup text around tag, local declaration, etc. 5 | 6 | ***This plugin is experimental*** 7 | 8 | 9 | Require 10 | --- 11 | 12 | Vim 8.1.1407 or later is required(popup feature is required) 13 | 14 | 15 | Screenshot 16 | --- 17 | 18 | ![screenshot](https://raw.githubusercontent.com/deris/s/master/vim-popupiece/vim-popupiece_01_popup.gif) 19 | 20 | Usage 21 | --- 22 | 23 | No default key mapping. 24 | 25 | You can map key like following. 26 | 27 | ```vim 28 | nmap (popupiece-tag) 29 | nmap (popupiece-local-decl) 30 | ``` 31 | 32 | If you want to spread popup area, you can set global settings. 33 | 34 | ```vim 35 | " If you spread area before target line, you can set additional line before. 36 | let g:popupiece_before_additional_line = 0 37 | 38 | " If you spread area after target line, you can set additional line after. 39 | let g:popupiece_after_additional_line = 4 40 | 41 | " no blank line include if set 1. 42 | let g:popupiece_no_blank_line = 1 43 | ``` 44 | 45 | You can define custom popup like following 46 | 47 | ```vim 48 | " example: write your .vimrc and define command for popup header of file 49 | command! -nargs=0 MyPopupiece call popupiece#popup_custom(function('s:mypopup_pre_hof'), function('s:mypopup_post_hof')) 50 | 51 | function! s:mypopup_pre_hof() 52 | execute "normal! gg" 53 | endfunction 54 | 55 | function! s:mypopup_post_hof() 56 | execute "normal! \" 57 | endfunction 58 | ``` 59 | 60 | License 61 | --- 62 | 63 | MIT License 64 | 65 | -------------------------------------------------------------------------------- /autoload/popupiece.vim: -------------------------------------------------------------------------------- 1 | " popupiece - popup text around tag, local decraration, etc 2 | " Version: 0.0.1 3 | " Copyright (C) 2019 deris0126 4 | " License: MIT license {{{ 5 | " Permission is hereby granted, free of charge, to any person obtaining 6 | " a copy of this software and associated documentation files (the 7 | " "Software"), to deal in the Software without restriction, including 8 | " without limitation the rights to use, copy, modify, merge, publish, 9 | " distribute, sublicense, and/or sell copies of the Software, and to 10 | " permit persons to whom the Software is furnished to do so, subject to 11 | " the following conditions: 12 | " 13 | " The above copyright notice and this permission notice shall be included 14 | " in all copies or substantial portions of the Software. 15 | " 16 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | " }}} 24 | 25 | let s:save_cpo = &cpo 26 | set cpo&vim 27 | 28 | " Public API {{{1 29 | function! popupiece#popup_tag() 30 | call s:move_and_popup(function('s:tag'), function('s:pop')) 31 | endfunction 32 | 33 | function! popupiece#popup_local_declaration() 34 | call s:move_and_popup(function('s:go_local_decl'), function('s:go_back')) 35 | endfunction 36 | 37 | function! popupiece#popup_custom(pre_func, post_func) 38 | call s:move_and_popup(a:pre_func, a:post_func) 39 | endfunction 40 | "}}} 41 | 42 | " Private {{{1 43 | function! s:tag() 44 | execute "normal! \" 45 | endfunction 46 | 47 | function! s:pop() 48 | execute "normal! \" 49 | endfunction 50 | 51 | function! s:go_local_decl() 52 | execute "normal! gd" 53 | endfunction 54 | 55 | function! s:go_back() 56 | execute "normal! \" 57 | endfunction 58 | 59 | function! s:move_and_popup(pre_func, post_func) 60 | if !exists('*popup_create') 61 | echohl WarningMsg 62 | echom printf('[error] popup_create is not supported') 63 | echohl None 64 | return 65 | endif 66 | 67 | let save_view = {} 68 | let first_pos = 0 69 | let cur_pos = 0 70 | let has_jumped = 0 71 | try 72 | let first_pos = getcurpos() 73 | let save_view = winsaveview() 74 | call function(a:pre_func)() 75 | let cur_pos = getcurpos() 76 | if first_pos == cur_pos 77 | return 78 | endif 79 | let has_jumped = 1 80 | let lines = s:get_around_lines(g:popupiece_before_additional_line, g:popupiece_after_additional_line, g:popupiece_no_blank_line) 81 | call map(lines, {key, val -> substitute(val, "\t", repeat(' ', &tabstop), 'g')}) 82 | finally 83 | if has_jumped == 1 84 | call function(a:post_func)() 85 | call winrestview(save_view) 86 | else 87 | let cur_pos = getcurpos() 88 | if first_pos != cur_pos 89 | call function(a:post_func)() 90 | call winrestview(save_view) 91 | endif 92 | endif 93 | endtry 94 | 95 | call popup_create(lines, { 96 | \ 'line': 'cursor', 97 | \ 'col': 'cursor', 98 | \ 'pos': 'topleft', 99 | \ 'wrap': 0, 100 | \ 'border': [1, 1, 1, 1], 101 | \ 'moved': 'any', 102 | \ }) 103 | endfunction 104 | 105 | function! s:get_around_lines(before_count, after_count, no_blank_line) 106 | let cur_lnum = line('.') 107 | let before_lnum = max([1, cur_lnum - a:before_count]) 108 | let after_lnum = min([line('$'), cur_lnum + a:after_count]) 109 | 110 | if a:no_blank_line != 0 111 | if before_lnum < cur_lnum 112 | let srch_lnum = search('^\s*$', 'bnW', before_lnum) 113 | if srch_lnum != 0 114 | let before_lnum = srch_lnum + 1 115 | endif 116 | endif 117 | if after_lnum < cur_lnum 118 | let srch_lnum = search('^\s*$', 'nW', after_lnum) 119 | if srch_lnum != 0 120 | let after_lnum = srch_lnum - 1 121 | endif 122 | endif 123 | endif 124 | 125 | return getline(before_lnum, after_lnum) 126 | endfunction 127 | "}}} 128 | 129 | let &cpo = s:save_cpo 130 | unlet s:save_cpo 131 | 132 | " __END__ "{{{1 133 | " vim: foldmethod=marker 134 | -------------------------------------------------------------------------------- /plugin/popupiece.vim: -------------------------------------------------------------------------------- 1 | " popupiece - popup text around tag, local decraration, etc 2 | " Version: 0.0.1 3 | " Copyright (C) 2019 deris0126 4 | " License: MIT license {{{ 5 | " Permission is hereby granted, free of charge, to any person obtaining 6 | " a copy of this software and associated documentation files (the 7 | " "Software"), to deal in the Software without restriction, including 8 | " without limitation the rights to use, copy, modify, merge, publish, 9 | " distribute, sublicense, and/or sell copies of the Software, and to 10 | " permit persons to whom the Software is furnished to do so, subject to 11 | " the following conditions: 12 | " 13 | " The above copyright notice and this permission notice shall be included 14 | " in all copies or substantial portions of the Software. 15 | " 16 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | " }}} 24 | 25 | if exists('g:loaded_popupiece') 26 | finish 27 | endif 28 | let g:loaded_popupiece = 1 29 | 30 | let g:popupiece_before_additional_line = get(g:, 'popupiece_before_additional_line', 0) 31 | let g:popupiece_after_additional_line = get(g:, 'popupiece_after_additional_line', 4) 32 | let g:popupiece_no_blank_line = get(g:, 'popupiece_no_blank_line', 1) 33 | 34 | nnoremap (popupiece-tag) :silent! call popupiece#popup_tag() 35 | nnoremap (popupiece-local-decl) :silent! call popupiece#popup_local_declaration() 36 | 37 | command! -nargs=0 PopupieceTag call popupiece#popup_tag() 38 | command! -nargs=0 PopupieceLocalDeclaration call popupiece#popup_local_declaration() 39 | 40 | " __END__ 41 | " vim: foldmethod=marker 42 | --------------------------------------------------------------------------------