startify.vim 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. " vim: et sw=2 sts=2
  2. " Plugin: https://github.com/mhinz/vim-startify
  3. " Description: A fancy start screen for Vim.
  4. " Maintainer: Marco Hinz <http://github.com/mhinz>
  5. if exists('g:autoloaded_startify') || &compatible
  6. finish
  7. endif
  8. let g:autoloaded_startify = 1
  9. " Init: values {{{1
  10. let s:numfiles = get(g:, 'startify_files_number', 10)
  11. let s:show_special = get(g:, 'startify_enable_special', 1)
  12. let s:delete_buffers = get(g:, 'startify_session_delete_buffers')
  13. let s:relative_path = get(g:, 'startify_relative_path') ? ':.' : ':p:~'
  14. let s:session_dir = resolve(expand(get(g:, 'startify_session_dir',
  15. \ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
  16. let s:skiplist = get(g:, 'startify_skiplist', [
  17. \ 'COMMIT_EDITMSG',
  18. \ fnamemodify($VIMRUNTIME, ':p') .'/doc',
  19. \ 'bundle/.*/doc',
  20. \ ])
  21. " Function: #get_separator {{{1
  22. function! startify#get_separator() abort
  23. return !exists('+shellslash') || &shellslash ? '/' : '\'
  24. endfunction
  25. let s:sep = startify#get_separator()
  26. " Function: #get_lastline {{{1
  27. function! startify#get_lastline() abort
  28. return s:lastline + 1
  29. endfunction
  30. " Function: #insane_in_the_membrane {{{1
  31. function! startify#insane_in_the_membrane() abort
  32. if &insertmode
  33. return
  34. endif
  35. if !empty(v:servername) && exists('g:startify_skiplist_server')
  36. for servname in g:startify_skiplist_server
  37. if servname == v:servername
  38. return
  39. endif
  40. endfor
  41. endif
  42. setlocal
  43. \ bufhidden=wipe
  44. \ buftype=nofile
  45. \ nobuflisted
  46. \ nocursorcolumn
  47. \ nocursorline
  48. \ nolist
  49. \ nonumber
  50. \ noswapfile
  51. if empty(&statusline)
  52. setlocal statusline=\ startify
  53. endif
  54. if v:version >= 703
  55. setlocal norelativenumber
  56. endif
  57. if exists('g:startify_custom_header')
  58. call append('$', g:startify_custom_header)
  59. endif
  60. let s:tick = 0
  61. let s:entries = {}
  62. if s:show_special
  63. call append('$', [' [e] <empty buffer>', ''])
  64. endif
  65. call s:register(line('$')-1, 'e', 'special', 'enew', '')
  66. let s:entry_number = 0
  67. if filereadable('Session.vim')
  68. call append('$', [' [0] '. getcwd() . s:sep .'Session.vim', ''])
  69. call s:register(line('$')-1, '0', 'session',
  70. \ 'call startify#session_delete_buffers() | source', 'Session.vim')
  71. let s:entry_number = 1
  72. let l:show_session = 1
  73. endif
  74. if empty(v:oldfiles)
  75. echohl WarningMsg
  76. echomsg "startify: Can't read viminfo file. Read :help startify-faq-02"
  77. echohl None
  78. endif
  79. let b:startify_section_header_lines = []
  80. let s:lists = get(g:, 'startify_list_order', [
  81. \ [' Most recently used files:'],
  82. \ 'files',
  83. \ [' Most recently used files in the current directory:'],
  84. \ 'dir',
  85. \ [' My sessions:'],
  86. \ 'sessions',
  87. \ [' My bookmarks:'],
  88. \ 'bookmarks',
  89. \ ])
  90. for item in s:lists
  91. if type(item) == 1
  92. call s:show_{item}()
  93. else
  94. let s:last_message = item
  95. endif
  96. unlet item
  97. endfor
  98. silent $delete _
  99. if s:show_special
  100. call append('$', ['', ' [q] <quit>'])
  101. endif
  102. call s:register(line('$'), 'q', 'special', 'call s:close()', '')
  103. " compute first line offset
  104. let s:firstline = 2
  105. " increase offset if there is a custom header
  106. if exists('g:startify_custom_header')
  107. let s:firstline += len(g:startify_custom_header)
  108. endif
  109. " no special, no local Session.vim, but a section header
  110. if !s:show_special && !exists('l:show_session') && type(s:lists[0]) == 3
  111. let s:firstline += len(s:lists[0]) + 1
  112. endif
  113. let s:lastline = line('$')
  114. if exists('g:startify_custom_footer')
  115. call append('$', g:startify_custom_footer)
  116. endif
  117. setlocal nomodifiable nomodified
  118. call s:set_mappings()
  119. call cursor(s:firstline + (s:show_special ? 2 : 0), 5)
  120. autocmd startify CursorMoved <buffer> call s:set_cursor()
  121. set filetype=startify
  122. silent! doautocmd <nomodeline> User Startified
  123. endfunction
  124. " Function: #session_load {{{1
  125. function! startify#session_load(...) abort
  126. if !isdirectory(s:session_dir)
  127. echomsg 'The session directory does not exist: '. s:session_dir
  128. return
  129. elseif empty(startify#session_list_as_string(''))
  130. echomsg 'There are no sessions...'
  131. return
  132. endif
  133. call inputsave()
  134. let spath = s:session_dir . s:sep . (exists('a:1')
  135. \ ? a:1
  136. \ : input('Load this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
  137. \ | redraw
  138. call inputrestore()
  139. if filereadable(spath)
  140. if get(g:, 'startify_session_persistence')
  141. \ && exists('v:this_session')
  142. \ && filewritable(v:this_session)
  143. call startify#session_write(fnameescape(v:this_session))
  144. endif
  145. call startify#session_delete_buffers()
  146. execute 'source '. fnameescape(spath)
  147. else
  148. echo 'No such file: '. spath
  149. endif
  150. endfunction
  151. " Function: #session_save {{{1
  152. function! startify#session_save(...) abort
  153. if !isdirectory(s:session_dir)
  154. if exists('*mkdir')
  155. echo 'The session directory does not exist: '. s:session_dir .'. Create it? [y/n]'
  156. if (nr2char(getchar()) == 'y')
  157. call mkdir(s:session_dir, 'p')
  158. else
  159. echo
  160. return
  161. endif
  162. else
  163. echo 'The session directory does not exist: '. s:session_dir
  164. return
  165. endif
  166. endif
  167. call inputsave()
  168. let sname = exists('a:1')
  169. \ ? a:1
  170. \ : input('Save under this session name: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string')
  171. \ | redraw
  172. call inputrestore()
  173. if empty(sname)
  174. echo 'You gave an empty name!'
  175. return
  176. endif
  177. let spath = s:session_dir . s:sep . sname
  178. if !filereadable(spath)
  179. call startify#session_write(fnameescape(spath))
  180. echo 'Session saved under: '. spath
  181. return
  182. endif
  183. echo 'Session already exists. Overwrite? [y/n]' | redraw
  184. if nr2char(getchar()) == 'y'
  185. call startify#session_write(fnameescape(spath))
  186. echo 'Session saved under: '. spath
  187. else
  188. echo 'Did NOT save the session!'
  189. endif
  190. endfunction
  191. " Function: #session_close {{{1
  192. function! startify#session_close() abort
  193. if exists('v:this_session') && filewritable(v:this_session)
  194. call startify#session_write(fnameescape(v:this_session))
  195. let v:this_session = ''
  196. endif
  197. call startify#session_delete_buffers()
  198. Startify
  199. endfunction
  200. " Function: #session_write {{{1
  201. function! startify#session_write(spath)
  202. let ssop = &sessionoptions
  203. try
  204. " if this function is called while being in the Startify buffer
  205. " (by loading another session or running :SSave/:SLoad directly)
  206. " switch back to the previous buffer before saving the session
  207. if &filetype == 'startify'
  208. let callingbuffer = bufnr('#')
  209. if callingbuffer > 0
  210. execute 'buffer' callingbuffer
  211. endif
  212. endif
  213. " prevent saving already deleted buffers that were in the arglist
  214. for arg in argv()
  215. if !buflisted(arg)
  216. execute 'argdelete' fnameescape(arg)
  217. endif
  218. endfor
  219. set sessionoptions-=options
  220. execute 'mksession!' a:spath
  221. catch
  222. execute 'echoerr' string(v:exception)
  223. finally
  224. let &sessionoptions = ssop
  225. endtry
  226. if exists('g:startify_session_remove_lines')
  227. \ || exists('g:startify_session_savevars')
  228. \ || exists('g:startify_session_savecmds')
  229. execute 'split' a:spath
  230. " remove lines from the session file
  231. if exists('g:startify_session_remove_lines')
  232. for pattern in g:startify_session_remove_lines
  233. execute 'silent global/'. pattern .'/delete'
  234. endfor
  235. endif
  236. " put existing variables from savevars into session file
  237. if exists('g:startify_session_savevars')
  238. call append(line('$')-3, map(filter(copy(g:startify_session_savevars), 'exists(v:val)'), '"let ". v:val ." = ". strtrans(string(eval(v:val)))'))
  239. endif
  240. " put commands from savecmds into session file
  241. if exists('g:startify_session_savecmds')
  242. call append(line('$')-3, g:startify_session_savecmds)
  243. endif
  244. setlocal bufhidden=delete
  245. silent update
  246. silent hide
  247. endif
  248. endfunction
  249. " Function: #session_delete {{{1
  250. function! startify#session_delete(...) abort
  251. if !isdirectory(s:session_dir)
  252. echo 'The session directory does not exist: '. s:session_dir
  253. return
  254. elseif empty(startify#session_list_as_string(''))
  255. echo 'There are no sessions...'
  256. return
  257. endif
  258. call inputsave()
  259. let spath = s:session_dir . s:sep . (exists('a:1')
  260. \ ? a:1
  261. \ : input('Delete this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
  262. \ | redraw
  263. call inputrestore()
  264. echo 'Really delete '. spath .'? [y/n]' | redraw
  265. if (nr2char(getchar()) == 'y')
  266. if delete(spath) == 0
  267. echo 'Deleted session '. spath .'!'
  268. else
  269. echo 'Deletion failed!'
  270. endif
  271. else
  272. echo 'Deletion aborted!'
  273. endif
  274. endfunction
  275. " Function: #session_delete_buffers {{{1
  276. function! startify#session_delete_buffers() abort
  277. if !s:delete_buffers
  278. return
  279. endif
  280. let n = 1
  281. while n <= bufnr('$')
  282. if buflisted(n)
  283. silent execute 'bdelete' n
  284. endif
  285. let n += 1
  286. endwhile
  287. endfunction
  288. " Function: #session_list {{{1
  289. function! startify#session_list(lead, ...) abort
  290. return map(split(globpath(s:session_dir, '*'.a:lead.'*'), '\n'), 'fnamemodify(v:val, ":t")')
  291. endfunction
  292. " Function: #session_list_as_string {{{1
  293. function! startify#session_list_as_string(lead, ...) abort
  294. return join(map(split(globpath(s:session_dir, '*'.a:lead.'*'), '\n'), 'fnamemodify(v:val, ":t")'), "\n")
  295. endfunction
  296. " Function: startify#debug {{{1
  297. function! startify#debug()
  298. if exists('s:entries')
  299. for k in sort(keys(s:entries))
  300. echomsg '['. k .'] = '. string(s:entries[k])
  301. endfor
  302. endif
  303. endfunction
  304. " Function: #open_buffers {{{1
  305. function! startify#open_buffers(...) abort
  306. if exists('a:1') " used in mappings
  307. let entry = s:entries[a:1]
  308. execute entry.cmd entry.path
  309. return
  310. endif
  311. let marked = filter(copy(s:entries), 'v:val.marked')
  312. if empty(marked) " open current entry
  313. let entry = s:entries[line('.')]
  314. execute entry.cmd entry.path
  315. return
  316. endif
  317. enew
  318. setlocal nobuflisted
  319. " Open all marked entries.
  320. for entry in sort(values(marked), 's:sort_by_tick')
  321. if entry.type == 'special'
  322. execute entry.cmd
  323. elseif entry.type == 'session'
  324. execute entry.cmd entry.path
  325. elseif entry.type == 'file'
  326. if line2byte('$') == -1
  327. execute 'edit' entry.path
  328. else
  329. execute entry.cmd entry.path
  330. endif
  331. call s:check_user_options()
  332. endif
  333. endfor
  334. endfunction
  335. " Function: s:display_by_path {{{1
  336. function! s:display_by_path(path_prefix, path_format) abort
  337. let oldfiles = call(get(g:, 'startify_enable_unsafe') ? 's:filter_oldfiles_unsafe' : 's:filter_oldfiles',
  338. \ [a:path_prefix, a:path_format])
  339. if !empty(oldfiles)
  340. if exists('s:last_message')
  341. call s:print_section_header()
  342. endif
  343. for [absolute_path, entry_path] in oldfiles
  344. let index = s:get_index_as_string(s:entry_number)
  345. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . entry_path)
  346. if has('win32')
  347. let absolute_path = substitute(absolute_path, '\[', '\[[]', 'g')
  348. endif
  349. call s:register(line('$'), index, 'file', 'edit', absolute_path)
  350. let s:entry_number += 1
  351. endfor
  352. call append('$', '')
  353. endif
  354. endfunction
  355. " Function: s:filter_oldfiles {{{1
  356. function! s:filter_oldfiles(path_prefix, path_format) abort
  357. let path_prefix = '\V'. escape(a:path_prefix, '\')
  358. let counter = s:numfiles
  359. let entries = {}
  360. let oldfiles = []
  361. for fname in v:oldfiles
  362. if counter <= 0
  363. break
  364. endif
  365. let absolute_path = fnamemodify(resolve(fname), ":p")
  366. " filter duplicates, bookmarks and entries from the skiplist
  367. if has_key(entries, absolute_path)
  368. \ || !filereadable(absolute_path)
  369. \ || s:is_in_skiplist(absolute_path)
  370. \ || (exists('g:startify_bookmarks') && s:is_bookmark(absolute_path))
  371. \ || match(absolute_path, path_prefix)
  372. continue
  373. endif
  374. let entry_path = fnamemodify(absolute_path, a:path_format)
  375. let entries[absolute_path] = 1
  376. let counter -= 1
  377. let oldfiles += [[fnameescape(absolute_path), entry_path]]
  378. endfor
  379. return oldfiles
  380. endfun
  381. " Function: s:filter_oldfiles_unsafe {{{1
  382. function! s:filter_oldfiles_unsafe(path_prefix, path_format) abort
  383. let path_prefix = '\V'. escape(a:path_prefix, '\')
  384. let counter = s:numfiles
  385. let entries = {}
  386. let oldfiles = []
  387. for fname in v:oldfiles
  388. if counter <= 0
  389. break
  390. endif
  391. let absolute_path = glob(fnamemodify(fname, ":p"))
  392. if empty(absolute_path)
  393. \ || has_key(entries, absolute_path)
  394. \ || s:is_in_skiplist(absolute_path)
  395. \ || match(absolute_path, path_prefix)
  396. continue
  397. endif
  398. let entry_path = fnamemodify(absolute_path, a:path_format)
  399. let entries[absolute_path] = 1
  400. let counter -= 1
  401. let oldfiles += [[fnameescape(absolute_path), entry_path]]
  402. endfor
  403. return oldfiles
  404. endfun
  405. " Function: s:show_dir {{{1
  406. function! s:show_dir() abort
  407. return s:display_by_path(getcwd(), ':.')
  408. endfunction
  409. " Function: s:show_files {{{1
  410. function! s:show_files() abort
  411. return s:display_by_path('', s:relative_path)
  412. endfunction
  413. " Function: s:show_sessions {{{1
  414. function! s:show_sessions() abort
  415. let sfiles = split(globpath(s:session_dir, '*'), '\n')
  416. if empty(sfiles)
  417. if exists('s:last_message')
  418. unlet s:last_message
  419. endif
  420. return
  421. endif
  422. if exists('s:last_message')
  423. call s:print_section_header()
  424. endif
  425. for i in range(len(sfiles))
  426. let index = s:get_index_as_string(s:entry_number)
  427. let fname = fnamemodify(sfiles[i], ':t')
  428. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
  429. if has('win32')
  430. let fname = substitute(fname, '\[', '\[[]', 'g')
  431. endif
  432. call s:register(line('$'), index, 'session', 'SLoad', fname)
  433. let s:entry_number += 1
  434. endfor
  435. call append('$', '')
  436. endfunction
  437. " Function: s:show_bookmarks {{{1
  438. function! s:show_bookmarks() abort
  439. if !exists('g:startify_bookmarks') || empty(g:startify_bookmarks)
  440. return
  441. endif
  442. if exists('s:last_message')
  443. call s:print_section_header()
  444. endif
  445. for fname in g:startify_bookmarks
  446. let index = s:get_index_as_string(s:entry_number)
  447. call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
  448. if has('win32')
  449. let absolute_path = substitute(fname, '\[', '\[[]', 'g')
  450. endif
  451. call s:register(line('$'), index, 'file', 'edit', fname)
  452. let s:entry_number += 1
  453. endfor
  454. call append('$', '')
  455. endfunction
  456. " Function: s:is_in_skiplist {{{1
  457. function! s:is_in_skiplist(arg) abort
  458. for regexp in s:skiplist
  459. if (a:arg =~# regexp)
  460. return 1
  461. endif
  462. endfor
  463. endfunction
  464. " Function: s:is_bookmark {{{1
  465. function! s:is_bookmark(arg) abort
  466. for foo in map(filter(copy(g:startify_bookmarks), '!isdirectory(v:val)'), 'resolve(fnamemodify(v:val, ":p"))')
  467. if foo == a:arg
  468. return 1
  469. endif
  470. endfor
  471. endfunction
  472. " Function: s:set_cursor {{{1
  473. function! s:set_cursor() abort
  474. let s:oldline = exists('s:newline') ? s:newline : 5
  475. let s:newline = line('.')
  476. " going up (-1) or down (1)
  477. let movement = 2 * (s:newline > s:oldline) - 1
  478. " skip section headers lines until an entry is found
  479. while index(b:startify_section_header_lines, s:newline) != -1
  480. let s:newline += movement
  481. endwhile
  482. " skip blank lines between lists
  483. if empty(getline(s:newline))
  484. let s:newline += movement
  485. endif
  486. " don't go beyond first or last entry
  487. let s:newline = max([s:firstline, min([s:lastline, s:newline])])
  488. call cursor(s:newline, 5)
  489. endfunction
  490. " Function: s:set_mappings {{{1
  491. function! s:set_mappings() abort
  492. for k in keys(s:entries)
  493. execute 'nnoremap <buffer><silent>' s:entries[k].index
  494. \ ':call startify#open_buffers('. string(k) .')<cr>'
  495. endfor
  496. nnoremap <buffer><silent> i :enew <bar> startinsert<cr>
  497. nnoremap <buffer><silent> <insert> :enew <bar> startinsert<cr>
  498. nnoremap <buffer><silent> b :call <sid>set_mark('B')<cr>
  499. nnoremap <buffer><silent> s :call <sid>set_mark('S')<cr>
  500. nnoremap <buffer><silent> t :call <sid>set_mark('T')<cr>
  501. nnoremap <buffer><silent> v :call <sid>set_mark('V')<cr>
  502. nnoremap <buffer><silent> <cr> :call startify#open_buffers()<cr>
  503. nnoremap <buffer><silent> <2-LeftMouse> :call startify#open_buffers()<cr>
  504. " Prevent 'nnoremap j gj' mappings, since they would break navigation.
  505. " (One can't leave the [x].)
  506. if !empty(maparg('j', 'n'))
  507. nnoremap <buffer> j j
  508. endif
  509. if !empty(maparg('k', 'n'))
  510. nnoremap <buffer> k k
  511. endif
  512. endfunction
  513. " Function: s:set_mark {{{1
  514. function! s:set_mark(type, ...) abort
  515. let index = expand('<cword>')
  516. let line = exists('a:1') ? a:1 : line('.')
  517. let entry = s:entries[line]
  518. if entry.type != 'file'
  519. return
  520. endif
  521. let default_cmds = {
  522. \ 'B': 'edit',
  523. \ 'S': 'split',
  524. \ 'V': 'vsplit',
  525. \ 'T': 'tabnew',
  526. \ }
  527. setlocal modifiable
  528. if entry.marked && index[0] == a:type
  529. let entry.cmd = 'edit'
  530. let entry.marked = 0
  531. execute 'normal! ci]'. entry.index
  532. else
  533. let entry.cmd = default_cmds[a:type]
  534. let entry.marked = 1
  535. let entry.tick = s:tick
  536. let s:tick += 1
  537. execute 'normal! ci]'. repeat(a:type, len(index))
  538. endif
  539. setlocal nomodifiable nomodified
  540. endfunction
  541. " Function: s:sort_by_tick {{{1
  542. function! s:sort_by_tick(one, two)
  543. return a:one.tick - a:two.tick
  544. endfunction
  545. " Function: s:check_user_options {{{1
  546. function! s:check_user_options() abort
  547. let path = expand('%')
  548. let session = path . s:sep .'Session.vim'
  549. " change to VCS root directory
  550. if get(g:, 'startify_session_autoload') && filereadable(session)
  551. execute 'source' session
  552. elseif get(g:, 'startify_change_to_vcs_root')
  553. call s:cd_to_vcs_root(path)
  554. " change directory
  555. elseif get(g:, 'startify_change_to_dir', 1)
  556. if isdirectory(path)
  557. lcd %
  558. else
  559. lcd %:h
  560. endif
  561. endif
  562. endfunction
  563. " Function: s:cd_to_vcs_root {{{1
  564. function! s:cd_to_vcs_root(path) abort
  565. let dir = fnamemodify(a:path, ':p:h')
  566. for vcs in [ '.git', '.hg', '.bzr', '.svn' ]
  567. let root = finddir(vcs, dir .';')
  568. if !empty(root)
  569. execute 'cd '. fnamemodify(root, ':h')
  570. return
  571. endif
  572. endfor
  573. endfunction
  574. " Function: s:close {{{1
  575. function! s:close() abort
  576. if len(filter(range(0, bufnr('$')), 'buflisted(v:val)'))
  577. if bufloaded(bufnr('#')) && bufnr('#') != bufnr('%')
  578. buffer #
  579. else
  580. bnext
  581. endif
  582. else
  583. quit
  584. endif
  585. endfunction
  586. " Function: s:get_index_as_string {{{1
  587. function! s:get_index_as_string(idx) abort
  588. if exists('g:startify_custom_indices')
  589. let listlen = len(g:startify_custom_indices)
  590. return (a:idx < listlen) ? g:startify_custom_indices[a:idx] : string(a:idx - listlen)
  591. else
  592. return string(a:idx)
  593. endif
  594. endfunction
  595. " Function: s:print_section_header {{{1
  596. function! s:print_section_header() abort
  597. $
  598. let curline = line('.')
  599. for lnum in range(curline, curline + len(s:last_message) + 1)
  600. call add(b:startify_section_header_lines, lnum)
  601. endfor
  602. call append('$', s:last_message + [''])
  603. unlet s:last_message
  604. endfunction
  605. " Function: s:register {{{1
  606. function! s:register(line, index, type, cmd, path)
  607. let s:entries[a:line] = {
  608. \ 'index': a:index,
  609. \ 'type': a:type,
  610. \ 'cmd': a:cmd,
  611. \ 'path': a:path,
  612. \ 'marked': 0,
  613. \ }
  614. endfunction