[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



I am tring to write an indent script for my ledger files.  Here is an example:

; Globals
; Year
Y2004

; Begin Register
12/2 Paycheck
    Assets:Bank1:Checking   $100.00
    Assets:Bank2:Savings    $100.00
    Salary:Work

The indenting is really simple.  the indent is 0 unless the previous line is a
line starting with a date.  Then continue to indent by &sw until a blank line
and a date string line for the next transaction.

I am getting the indent set to 0 on the date string line, but no indenting is
happening on the next line.  

What am I doing wrone?

Here is the script:


" File Name: ledger.vim (indent file)
" Maintainer: Allan Neal
" Original Date: 04/12/04 10:55:20 
" Last Update: 04/12/04 10:55:12 
" Description: Indent the ledger file the in compliance with the ledger syntax
" highlighting file.  Entry is flush left and all accounts are indented one ts

" Only define the funtion once
if exists("*LedgerIndent")
	finish
endif

let b:did_indent = 1

setlocal indentexpr=LedgerIndent()

function LedgerIndent()
	let cline = getline(v:lnum)
	let ind = 0
	if (cline =~ "^\d+")
		return 0
	endif
	if cline =~ "\<.*:\<.*"
		let ind = ind + &sw
	endif
	if cline =~ "^$"
		return 0
	endif
	let lnum = prevnonblank(v:lnum - 1)
	if lnum == 0
		return 0
	endif
	let pline = getline(lnum)
	if (indent(v:lnum - 1) != 0 && pline !~ "^$")
		return -1
	endif
	if ( pline =~ "^\d+" )
		let ind = ind + &sw
	endif
	return ind
endfunction

" vim:sw=4

-- 
 __^__                                          __^__
( ___ )----------------------------------------( ___ )
 | / | "Engineers aren't boring people,         | \ |
 | / | we just get excited about boring things" | \ |
 |___|                 --Anon                   |___|
(_____)----------------------------------------(_____)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available



</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00248" href="msg00248.html">[ale] indent script problems</a></strong>
<ul><li><em>From:</em> allanneal at bellsouth.net (Allan Neal)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00220.html">[ale] PPPulling my hair out</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00222.html">[ale] Resources for making family oriented slide shows</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00476.html">[ale] Debian 2.6.8/Plextor dvd - FIXED</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00248.html">[ale] indent script problems</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00221"><strong>Date</strong></a></li>
<li><a href="threads.html#00221"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>