File: heading.vim

package info (click to toggle)
vim-link-vim 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 524 kB
  • sloc: python: 66; makefile: 30
file content (48 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
" Return heading text: buffer-local, global or default.
function! linkvim#x#heading#get_text() abort
  let l:default = s:is_ft_markdown()
        \ ? g:linkvim#defaults['heading_markdown']
        \ : g:linkvim#defaults['heading_other']

  return linkvim#x#u#setting_with_default('link_heading', l:default)
endfunction

" Return whether heading is set to an empty string.
function! linkvim#x#heading#is_empty(heading_text) abort
  return type(a:heading_text) == v:t_string && a:heading_text ==# ''
endfunction

" Return whether heading needs to be added.
function! linkvim#x#heading#is_needed(is_empty, heading_text) abort
  if a:is_empty
    return v:false
  endif

  if type(a:heading_text) == v:t_list
    let l:pattern = '^' .. join(a:heading_text, '\_s*') .. '$' " Add newlines
  else
    let l:pattern = '^' .. a:heading_text .. '\s*$'
  endif

  let l:match_line_nr = search(l:pattern, 'nw')

  return l:match_line_nr == 0
endfunction

" Add the specified heading text to the buffer. Return number of lines added.
function! linkvim#x#heading#add(heading_text, lnum) abort
  if type(a:heading_text) == v:t_list
    let l:lines = a:heading_text
  else
    let l:lines = [ '', a:heading_text, ''  ] " Blank line above and below heading
  endif

  call append( a:lnum , l:lines )
  return len(l:lines)
endfunction

" Return whether filetype includes Markdown. This accounts for composite
" filetypes such as `vimwiki.markdown.pandoc`.
function! s:is_ft_markdown() abort
  return &filetype =~# 'markdown'
endfunction