├── .gitignore ├── LICENSE ├── README.md └── plugin └── cppman.vim /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Linwei 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 | # vim-cppman 2 | 3 | Read Cppman/Man pages right inside your vim. 4 | 5 | ## Feature 6 | 7 | - Read pages from both `cppman` and `man`. 8 | - Supports windows: use WSL or MSYS. 9 | - Jump to tag under cursor ( eg. "printf(3)" ) with `C-]` or `K` command. 10 | 11 | ## Installation 12 | 13 | ```VimL 14 | Plug 'skywind3000/vim-cppman' 15 | ``` 16 | 17 | ## Usage 18 | 19 | ```VimL 20 | " Display cppman/man pages: 21 | " :Cppman[!] [section] keyword 22 | " 23 | " When "!" is included, load pages from "man" command, otherwise 24 | " use "cppman" instead. For performance, run "cppman -c" to cache 25 | " all pages before this. 26 | " 27 | " The "[section]" is only available for "man": 28 | " :Cppman! printf 29 | " :Cppman! 3 printf 30 | " 31 | " Use "-k" to search sections: 32 | " :Cppman! -k printf 33 | " 34 | " Window position: 35 | " Option "g:cppman_open_mode" can allow you specify how to open: 36 | " :let g:cppman_open_mode = "vertical" 37 | " :let g:cppman_open_mode = "tab" 38 | " :let g:cppman_open_mode = "vert botright" 39 | " :let g:cppman_open_mode = "" 40 | " 41 | " Position modifiers: 42 | " Another way to indicate window position is using modifiers: 43 | " :vertical Cppman keyword 44 | " :tab Cppman keyword 45 | " :vert botright Cppman keyword 46 | " 47 | " Keymaps: 48 | " "K" - jump to keyword under cursor 49 | " "CTRL+]" - same as "K" 50 | " 51 | " Running on Windows: 52 | " It can use WSL to run cppman/man. If WSL is not available, 53 | " you can setup g:cppman_msys_home to use msys alternatively. 54 | " 55 | " C/C++ keywords help: 56 | " You can setup your "keywordprg" for c/cpp in your vimrc: 57 | " autocmd FileType c,cpp setlocal keywordprg=:Cppman 58 | " 59 | " Than, you can use "K" in to lookup keywords in c/cpp files. 60 | ``` 61 | 62 | ## Credit 63 | 64 | TODO 65 | -------------------------------------------------------------------------------- /plugin/cppman.vim: -------------------------------------------------------------------------------- 1 | "====================================================================== 2 | " 3 | " cppman.vim - Cppman/man intergration 4 | " 5 | " Maintainer: skywind3000 (at) gmail.com, 2020 6 | " 7 | " Last Modified: 2020/02/06 15:23 8 | " Verision: 14 9 | " 10 | " Display cppman/man pages: 11 | " :Cppman[!] [section] keyword 12 | " 13 | " When "!" is included, load pages from "man" command, otherwise 14 | " use "cppman" instead. For performance, run "cppman -c" to cache 15 | " all pages before this. 16 | " 17 | " The "[section]" is only available for "man": 18 | " :Cppman! printf 19 | " :Cppman! 3 printf 20 | " 21 | " Use "-k" to search sections: 22 | " :Cppman! -k printf 23 | " 24 | " Window position: 25 | " Option "g:cppman_open_mode" can allow you specify how to open: 26 | " :let g:cppman_open_mode = "vertical" 27 | " :let g:cppman_open_mode = "tab" 28 | " :let g:cppman_open_mode = "vert botright" 29 | " :let g:cppman_open_mode = "" 30 | " 31 | " Position modifiers: 32 | " Another way to indicate window position is using modifiers: 33 | " :vertical Cppman keyword 34 | " :tab Cppman keyword 35 | " :vert botright Cppman keyword 36 | " 37 | " Keymaps: 38 | " "K" - jump to keyword under cursor 39 | " "CTRL+]" - same as "K" 40 | " 41 | " Running on Windows: 42 | " It can use WSL to run cppman/man. If WSL is not available, 43 | " you can setup g:cppman_msys_home to use msys alternatively. 44 | " 45 | " C/C++ keywords help: 46 | " You can setup your "keywordprg" for c/cpp in your vimrc: 47 | " autocmd FileType c,cpp setlocal keywordprg=:Cppman 48 | " 49 | " Than, you can use "K" in to lookup keywords in c/cpp files. 50 | " 51 | "====================================================================== 52 | 53 | " vim: set noet fenc=utf-8 ff=unix sts=4 sw=4 ts=4 : 54 | 55 | "---------------------------------------------------------------------- 56 | " configuration 57 | "---------------------------------------------------------------------- 58 | 59 | " for windows only, if set, use msys instead of wsl 60 | if !exists('g:cppman_msys_home') 61 | let g:cppman_msys_home = '' 62 | endif 63 | 64 | " for windows only, WSL distribution name, when g:cppman_msys_home is unset 65 | if !exists('g:cppman_wsl_dist') 66 | let g:cppman_wsl_dist = '' 67 | endif 68 | 69 | " open mode: tab/vert/botright vert/topleft/... 70 | if !exists('g:cppman_open_mode') 71 | let g:cppman_open_mode = '' 72 | endif 73 | 74 | " disable keymaps ?? 75 | if !exists('g:cppman_no_keymaps') 76 | let g:cppman_no_keymaps = 0 77 | endif 78 | 79 | " max width 80 | if !exists('g:cppman_max_width') 81 | let g:cppman_max_width = 200 82 | endif 83 | 84 | 85 | "---------------------------------------------------------------------- 86 | " internal states 87 | "---------------------------------------------------------------------- 88 | let s:windows = has('win32') || has('win64') || has('win95') || has('win16') 89 | 90 | 91 | "---------------------------------------------------------------------- 92 | " python simulate system() on window to prevent temporary window 93 | "---------------------------------------------------------------------- 94 | function! s:python_system(cmd, version) 95 | if has('nvim') 96 | let hr = system(a:cmd) 97 | elseif has('win32') || has('win64') || has('win95') || has('win16') 98 | if a:version < 0 || (has('python3') == 0 && has('python2') == 0) 99 | let hr = system(a:cmd) 100 | let s:shell_error = v:shell_error 101 | return hr 102 | elseif a:version == 3 103 | let pyx = 'py3 ' 104 | let python_eval = 'py3eval' 105 | elseif a:version == 2 106 | let pyx = 'py2 ' 107 | let python_eval = 'pyeval' 108 | else 109 | let pyx = 'pyx ' 110 | let python_eval = 'pyxeval' 111 | endif 112 | exec pyx . 'import subprocess, vim' 113 | exec pyx . '__argv = {"args":vim.eval("a:cmd"), "shell":True}' 114 | exec pyx . '__argv["stdout"] = subprocess.PIPE' 115 | exec pyx . '__argv["stderr"] = subprocess.STDOUT' 116 | exec pyx . '__pp = subprocess.Popen(**__argv)' 117 | exec pyx . '__return_text = __pp.stdout.read()' 118 | exec pyx . '__pp.stdout.close()' 119 | exec pyx . '__return_code = __pp.wait()' 120 | exec 'let l:hr = '. python_eval .'("__return_text")' 121 | exec 'let l:pc = '. python_eval .'("__return_code")' 122 | let s:shell_error = l:pc 123 | return l:hr 124 | else 125 | let hr = system(a:cmd) 126 | endif 127 | let s:shell_error = v:shell_error 128 | return hr 129 | endfunc 130 | 131 | 132 | "---------------------------------------------------------------------- 133 | " call python system 134 | "---------------------------------------------------------------------- 135 | function! s:system(cmd) 136 | return s:python_system(a:cmd, get(g:, 'cppman_python_system', 0)) 137 | endfunc 138 | 139 | 140 | "---------------------------------------------------------------------- 141 | " error message 142 | "---------------------------------------------------------------------- 143 | function! s:errmsg(msg) 144 | echohl ErrorMsg 145 | echom 'ERROR: '. a:msg 146 | echohl NONE 147 | endfunc 148 | 149 | 150 | "---------------------------------------------------------------------- 151 | " run wsl command 152 | "---------------------------------------------------------------------- 153 | function! s:system_wsl(cmd) 154 | if s:windows == 0 155 | call s:errmsg("for windows only") 156 | return '' 157 | endif 158 | let root = ($SystemRoot == '')? 'C:/Windows' : $SystemRoot 159 | let t1 = root . '/system32/wsl.exe' 160 | let t2 = root . '/sysnative/wsl.exe' 161 | let tt = executable(t1)? t1 : (executable(t2)? t2 : '') 162 | if tt == '' 163 | call s:errmsg("not find wsl in your system") 164 | return '' 165 | endif 166 | let cmd = shellescape(substitute(tt, '\\', '\/', 'g')) 167 | let dist = get(g:, 'cppman_wsl_dist', '') 168 | let cmd = (dist == '')? cmd : (cmd .. ' -d ' .. shellescape(dist)) 169 | return s:system(cmd .. ' ' .. a:cmd) 170 | endfunc 171 | 172 | 173 | "---------------------------------------------------------------------- 174 | " run msys cmd 175 | "---------------------------------------------------------------------- 176 | function! s:system_msys(cmd) 177 | if s:windows == 0 178 | call s:errmsg("for windows only") 179 | return '' 180 | endif 181 | let msys = get(g:, 'cppman_msys_home', '') 182 | if msys == '' 183 | call s:errmsg("g:cppman_msys_home is empty") 184 | return '' 185 | endif 186 | let msys = tr(msys, "\\", '/') 187 | if !isdirectory(msys) 188 | call s:errmsg("msys does not exist in " .. msys) 189 | return '' 190 | endif 191 | let last = strpart(msys, strlen(msys) - 1, 1) 192 | let name = (last == '/' || last == "\\")? msys : (msys .. '/') 193 | let name = name .. 'usr/bin/bash.exe' 194 | if !executable(name) 195 | call s:errmsg("invalid msys path " .. msys) 196 | return '' 197 | endif 198 | let cmd = shellescape(name) .. ' --login -c ' .. shellescape(a:cmd) 199 | return s:system(cmd) 200 | endfunc 201 | 202 | 203 | "---------------------------------------------------------------------- 204 | " choose best method: 205 | "---------------------------------------------------------------------- 206 | function! s:unix_system(cmd) 207 | if s:windows == 0 208 | return s:system(a:cmd) 209 | endif 210 | let msys = get(g:, 'cppman_msys_home', '') 211 | if msys == '' 212 | return s:system_wsl(a:cmd) 213 | else 214 | return s:system_msys(a:cmd) 215 | endif 216 | endfunc 217 | 218 | 219 | "---------------------------------------------------------------------- 220 | " get page 221 | "---------------------------------------------------------------------- 222 | function! s:cppman_get_page(section, page, width) 223 | let cmd = 'cppman --force-columns=' .. a:width .. ' "' .. a:page .. '"' 224 | if a:section != 'cppman' 225 | let cmd = 'MANPAGER=cat MANWIDTH=' .. a:width .. ' man ' 226 | let cmd = cmd .. a:section .. ' "' .. a:page .. '" ' 227 | let cmd = cmd .. ((s:windows)? '' : ' | col -b') 228 | endif 229 | " echo "cmd: ".cmd 230 | return s:unix_system(cmd) 231 | endfunc 232 | 233 | 234 | "---------------------------------------------------------------------- 235 | " get uri 236 | "---------------------------------------------------------------------- 237 | function! s:page_uri(section, page) 238 | if a:section == 'cppman' 239 | return 'man://cppman/' . a:page 240 | endif 241 | let name = a:page .. '.txt' 242 | return 'man://' .. ((a:section == '')? '.' : a:section) .. '/' .. name 243 | endfunc 244 | 245 | 246 | "---------------------------------------------------------------------- 247 | " extract uri 248 | "---------------------------------------------------------------------- 249 | function! s:extract_uri(uri) 250 | if strpart(a:uri, 0, 6) != 'man://' 251 | return ['', ''] 252 | endif 253 | let part = split(strpart(a:uri, 6), '/') 254 | if len(part) != 2 255 | return ['', ''] 256 | endif 257 | let section = (part[0] == '.')? '' : part[0] 258 | return [section, part[1]] 259 | endfunc 260 | 261 | 262 | "---------------------------------------------------------------------- 263 | " load buffer 264 | "---------------------------------------------------------------------- 265 | function! s:load_buffer(section, page, width) 266 | if a:page == '' 267 | call s:errmsg('empty page keyword') 268 | return -1 269 | endif 270 | let s:shell_error = 0 271 | let width = (a:width <= 0)? 80 : a:width 272 | let content = s:cppman_get_page(a:section, a:page, width) 273 | if s:shell_error != 0 274 | echo content 275 | call s:errmsg('bad return code: ' .. s:shell_error) 276 | return -1 277 | endif 278 | let bid = bufadd(s:page_uri(a:section, a:page)) 279 | if bid <= 0 280 | call s:errmsg('bad buffer number: ' .. bid) 281 | return -1 282 | endif 283 | noautocmd silent! call bufload(bid) 284 | call setbufvar(bid, "&buftype", 'nofile') 285 | call setbufvar(bid, "&buflisted", 0) 286 | call setbufvar(bid, "&swapfile", 0) 287 | call setbufvar(bid, '&bufhidden', 'hide') 288 | if a:width > 0 289 | call setbufvar(bid, "&readonly", 0) 290 | call setbufvar(bid, "&modifiable", 1) 291 | noautocmd silent! call deletebufline(bid, 1, '$') 292 | noautocmd call setbufline(bid, 1, split(content, "\n")) 293 | endif 294 | call setbufvar(bid, "&modifiable", 0) 295 | call setbufvar(bid, "&modified", 0) 296 | call setbufvar(bid, "&readonly", 1) 297 | call setbufvar(bid, "cppman_section", a:section) 298 | call setbufvar(bid, "cppman_page", a:page) 299 | call setbufvar(bid, "cppman_mode", "yes") 300 | return bid 301 | endfunc 302 | 303 | 304 | "---------------------------------------------------------------------- 305 | " split window 306 | "---------------------------------------------------------------------- 307 | function! cppman#display(mods, section, page) 308 | if a:page == '' 309 | call s:errmsg('empty argument') 310 | return 311 | endif 312 | if a:section == '-k' 313 | echo s:cppman_get_page('-k', a:page, 80) 314 | return 315 | endif 316 | let uri = s:page_uri(a:section, a:page) 317 | " redraw! 318 | echo "Loading ..." 319 | let bid = s:load_buffer(a:section, a:page, -1) 320 | if bid < 0 321 | return 322 | endif 323 | if a:mods == 'tab' 324 | exec 'tab split' 325 | elseif get(b:, 'cppman_mode', '') == '' 326 | let avail = -1 327 | for i in range(winnr('$')) 328 | let nr = winbufnr(i + 1) 329 | if getbufvar(nr, 'cppman_page', '') != '' 330 | let avail = i + 1 331 | break 332 | endif 333 | endfor 334 | if avail > 0 335 | exec avail .. 'wincmd w' 336 | else 337 | exec a:mods .. ' split' 338 | endif 339 | endif 340 | silent exec "edit " .. fnameescape(uri) 341 | let width = winwidth(0) - 2 342 | let width = (width < 1)? 1 : width 343 | let limit = get(g:, 'cppman_max_width', 512) 344 | let bid = s:load_buffer(a:section, a:page, (width > limit)? limit : width) 345 | setl nonumber norelativenumber signcolumn=no 346 | setl fdc=0 nofen 347 | noautocmd setl ft=man 348 | exec "normal! gg" 349 | if bid < 0 350 | return 351 | endif 352 | if a:section == 'cppman' 353 | call s:highlight_cppman() 354 | setl keywordprg=:Cppman 355 | setl iskeyword=@,48-57,_,192-255,:,=,~,[,],*,!,<,> 356 | else 357 | call s:highlight_man() 358 | setl keywordprg=:Cppman! 359 | setl iskeyword=@,48-57,_,192-255,.,- 360 | endif 361 | if get(g:, 'cppman_no_keymaps', 0) == 0 362 | call s:setup_keymaps() 363 | endif 364 | exec "normal \" 365 | endfunc 366 | 367 | 368 | "---------------------------------------------------------------------- 369 | " command 370 | "---------------------------------------------------------------------- 371 | function! s:cppman_cmd(mods, bang, ...) 372 | if a:0 <= 0 373 | call s:errmsg('Not enough argument') 374 | return 375 | endif 376 | if a:bang == '' 377 | let section = 'cppman' 378 | if a:0 > 1 379 | call s:errmsg('Too many arguments') 380 | return 381 | endif 382 | let page = a:1 383 | else 384 | if a:0 == 1 385 | let section = '' 386 | let page = a:1 387 | if page == '-k' 388 | call s:errmsg('Empty keyword') 389 | return 390 | endif 391 | elseif a:0 == 2 392 | let section = a:1 393 | let page = a:2 394 | elseif a:0 > 2 395 | call s:errmsg('Too many arguments') 396 | return 397 | endif 398 | endif 399 | let mods = a:mods 400 | if mods == '' 401 | let mods = get(g:, 'cppman_open_mode', '') 402 | if mods == 'auto' || mods == '' 403 | let mods = (winwidth(0) >= 160)? 'vert' : '' 404 | endif 405 | endif 406 | call cppman#display(mods, section, page) 407 | endfunc 408 | 409 | 410 | "---------------------------------------------------------------------- 411 | " command setup 412 | "---------------------------------------------------------------------- 413 | command! -bang -nargs=+ Cppman 414 | \ call s:cppman_cmd(, '', ) 415 | 416 | 417 | "---------------------------------------------------------------------- 418 | " pre get page 419 | "---------------------------------------------------------------------- 420 | function! LoadManPage(cnt) 421 | if a:cnt == 0 422 | let old_isk = &iskeyword 423 | if &ft == 'man' 424 | setl iskeyword+=(,) 425 | endif 426 | let str = expand("") 427 | let &l:iskeyword = old_isk 428 | let page = substitute(str, '(*\(\k\+\).*', '\1', '') 429 | let sect = substitute(str, '\(\k\+\)(\([^()]*\)).*', '\2', '') 430 | if match(sect, '^[0-9 ]\+$') == -1 431 | let sect = "" 432 | endif 433 | if sect == page 434 | let sect = "" 435 | endif 436 | else 437 | let sect = a:cnt 438 | let page = expand("") 439 | endif 440 | if b:cppman_section == 'cppman' 441 | call cppman#display('', 'cppman', page) 442 | else 443 | call cppman#display('', sect, page) 444 | endif 445 | endfunc 446 | 447 | 448 | "---------------------------------------------------------------------- 449 | " load cppman 450 | "---------------------------------------------------------------------- 451 | function! LoadCppmanPage() 452 | let name = expand('') 453 | call cppman#display('', 'cppman', name) 454 | endfunc 455 | 456 | 457 | "---------------------------------------------------------------------- 458 | " setup_keymaps 459 | "---------------------------------------------------------------------- 460 | function! s:setup_keymaps() 461 | let section = b:cppman_section 462 | if section == 'cppman' 463 | noremap K :call LoadCppmanPage() 464 | map K 465 | map K 466 | map <2-LeftMouse> K 467 | else 468 | noremap K :call LoadManPage(0) 469 | nnoremap :call LoadManPage(v:count) 470 | map <2-LeftMouse> K 471 | endif 472 | endfunc 473 | 474 | 475 | "---------------------------------------------------------------------- 476 | " highlight_man 477 | "---------------------------------------------------------------------- 478 | function! s:highlight_man() 479 | if get(b:, 'current_syntax', '') == 'man' 480 | return 481 | endif 482 | 483 | let b:current_syntax = 'man' 484 | 485 | syntax clear 486 | runtime! syntax/ctrlh.vim 487 | 488 | syn case ignore 489 | syn match manReference "\f\+([1-9][a-z]\=)" 490 | syn match manTitle "^\f\+([0-9]\+[a-z]\=).*" 491 | syn match manSectionHeading "^[a-z][a-z -]*[a-z]$" 492 | syn match manSubHeading "^\s\{3\}[a-z][a-z -]*[a-z]$" 493 | syn match manOptionDesc "^\s*[+-][a-z0-9]\S*" 494 | syn match manLongOptionDesc "^\s*--[a-z0-9-]\S*" 495 | " syn match manHistory "^[a-z].*last change.*$" 496 | 497 | if getline(1) =~ '^[a-zA-Z_]\+([23])' 498 | syntax include @cCode runtime! syntax/c.vim 499 | syn match manCFuncDefinition display "\<\h\w*\>\s*("me=e-1 contained 500 | syn region manSynopsis start="^SYNOPSIS"hs=s+8 end="^\u\+\s*$"me=e-12 keepend contains=manSectionHeading,@cCode,manCFuncDefinition 501 | endif 502 | 503 | 504 | " Define the default highlighting. 505 | " Only when an item doesn't have highlighting yet 506 | 507 | hi def link manTitle Title 508 | hi def link manSectionHeading Statement 509 | hi def link manOptionDesc Constant 510 | hi def link manLongOptionDesc Constant 511 | hi def link manReference PreProc 512 | hi def link manSubHeading Function 513 | hi def link manCFuncDefinition Function 514 | 515 | endfunc 516 | 517 | 518 | "---------------------------------------------------------------------- 519 | " highlight cppman 520 | "---------------------------------------------------------------------- 521 | function! s:highlight_cppman() 522 | if get(b:, 'current_syntax', '') == 'cppman' 523 | return 524 | endif 525 | 526 | let b:current_syntax = 'cppman' 527 | 528 | syntax clear 529 | syntax case ignore 530 | syntax match manReference "[a-z_:+-\*][a-z_:+-~!\*<>]\+([1-9][a-z]\=)" 531 | syntax match manTitle "^\w.\+([0-9]\+[a-z]\=).*" 532 | syntax match manSectionHeading "^[a-z][a-z_ \-:]*[a-z]$" 533 | syntax match manSubHeading "^\s\{3\}[a-z][a-z ]*[a-z]$" 534 | syntax match manOptionDesc "^\s*[+-][a-z0-9]\S*" 535 | syntax match manLongOptionDesc "^\s*--[a-z0-9-]\S*" 536 | 537 | syntax include @cppCode runtime! syntax/cpp.vim 538 | syntax match manCFuncDefinition display "\<\h\w*\>\s*("me=e-1 contained 539 | 540 | syntax region manSynopsis start="^SYNOPSIS"hs=s+8 end="^\u\+\s*$"me=e-12 keepend contains=manSectionHeading,@cppCode,manCFuncDefinition 541 | syntax region manSynopsis start="^EXAMPLE"hs=s+7 end="^ [^ ]"he=s-1 keepend contains=manSectionHeading,@cppCode,manCFuncDefinition 542 | 543 | " Define the default highlighting. 544 | " For version 5.7 and earlier: only when not done already 545 | " For version 5.8 and later: only when an item doesn't have highlighting yet 546 | if version >= 508 || !exists("did_man_syn_inits") 547 | hi def link manTitle Title 548 | hi def link manSectionHeading Statement 549 | hi def link manOptionDesc Constant 550 | hi def link manLongOptionDesc Constant 551 | hi def link manReference PreProc 552 | hi def link manSubHeading Function 553 | hi def link manCFuncDefinition Function 554 | endif 555 | 556 | endfunc 557 | 558 | 559 | "---------------------------------------------------------------------- 560 | " testing suit 561 | "---------------------------------------------------------------------- 562 | if 1 563 | " echo s:system_wsl('ls -la /') 564 | " echo s:cppman_get_page('cppman', 'printf', 80) 565 | " echo s:load_buffer('', 'printf', 80) 566 | " echo s:page_uri('', 'printf') 567 | " echo s:page_uri('3', 'printf') 568 | " echo s:page_uri('cppman', 'printf') 569 | " echo s:extract_uri('man://*/printf') 570 | " echo s:extract_uri('man://3/printf') 571 | " echo s:extract_uri('man://cppman/printf') 572 | endif 573 | 574 | 575 | --------------------------------------------------------------------------------