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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
# File: voom_mode_fmr1.py
# Last Modified: 2017-01-07
# Description: VOoM -- two-pane outliner plugin for Python-enabled Vim
# Website: http://www.vim.org/scripts/script.php?script_id=2657
# Author: Vlad Irnov (vlad DOT irnov AT gmail DOT com)
# License: CC0, see http://creativecommons.org/publicdomain/zero/1.0/
"""
VOoM markup mode for start fold markers with levels.
See |voom-mode-fmr1|, ../../../doc/voom.txt#*voom-mode-fmr1*
Headline text is before the start fold marker with level.
Very similar to "fmr" mode.
headline level 1 {{{1
some text
headline level 2 {{{2
more text
"""
import sys
if sys.version_info[0] > 2:
xrange = range
# Define this mode as an 'fmr' mode.
MTYPE = 0
# voom_vim.makeoutline() without char stripping
def hook_makeOutline(VO, blines):
"""Return (tlines, bnodes, levels) for Body lines blines.
blines is either Vim buffer object (Body) or list of buffer lines.
"""
marker = VO.marker
marker_re_search = VO.marker_re.search
Z = len(blines)
tlines, bnodes, levels = [], [], []
tlines_add, bnodes_add, levels_add = tlines.append, bnodes.append, levels.append
#c = VO.rstrip_chars
for i in xrange(Z):
if not marker in blines[i]: continue
bline = blines[i]
m = marker_re_search(bline)
if not m: continue
lev = int(m.group(1))
#head = bline[:m.start()].lstrip().rstrip(c).strip('-=~').strip()
head = bline[:m.start()].strip()
tline = ' %s%s|%s' %(m.group(2) or ' ', '. '*(lev-1), head)
tlines_add(tline)
bnodes_add(i+1)
levels_add(lev)
return (tlines, bnodes, levels)
# same as voom_vim.newHeadline() but without ---
def hook_newHeadline(VO, level, blnum, ln):
"""Return (tree_head, bodyLines).
tree_head is new headline string in Tree buffer (text after |).
bodyLines is list of lines to insert in Body buffer.
"""
tree_head = 'NewHeadline'
#bodyLines = ['---%s--- %s%s' %(tree_head, VO.marker, level), '']
bodyLines = ['%s %s%s' %(tree_head, VO.marker, level), '']
return (tree_head, bodyLines)
|