Editing Ledger files with TextWrangler

lifepillar edited this page Oct 28, 2012 · 1 revision

The following plist can be used to add Ledger support to the free OS X text editor TextWrangler. Just save the code below as Ledger.plist and put it inside ~/Library/Application Support/TextWrangler/Language Modules; then, close and re-open TextWrangler. Files with suffix .ledger will be recognized as Ledger files (additional file suffixes can be added in TextWrangler > Preferences > Languages) and colored accordingly. Besides, each transaction will be accessible from the function pop-up menu. Do not forget to edit the file to set your currencies (see the comments in the code)!

<!-- Gleefully brought to you by Lifepillar -->
<!-- Version 1.0.2 -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>BBEditDocumentType</key>
  <string>CodelessLanguageModule</string>
  <key>BBLMColorsSyntax</key> <true/>
  <key>BBLMIsCaseSensitive</key> <false/>
  <key>BBLMLanguageCode</key>
  <string>Ldgr</string>
  <key>BBLMLanguageDisplayName</key>
  <string>Ledger</string>
  <key>BBLMScansFunctions</key>
  <true/>
  <key>BBLMSuffixMap</key>
  <array>
    <dict>
      <key>BBLMLanguageSuffix</key>
      <string>.ledger</string>
    </dict>
  </array>
  <key>BBLMCanSpellCheckCodeRuns</key>
  <false/>
  <key>Language Features</key>
  <dict>
    <key>Identifier and Keyword Characters</key>
    <string><![CDATA[!ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]]></string>
    <key>Comment Pattern</key>
    <string><![CDATA[(?x:
      (?>
        (?>  [;#%|\*]  .*  $                       ) |
        (?>  @comment(?s:.*?)(?>@end\scomment|\z)  )
      )
    )]]></string>
    <!-- Adapt currencies as needed (I'm too lazy to add them all) -->
    <key>String Pattern</key>
    <string><![CDATA[(?x:
      (?>  -?\d+([,\.]\d+)*\s*(EUR|USD|CAD|AUD)  ) |
      (?>  \$\s*-?\d+([,\.]\d+)*[\s\z]               ) |
      (?>  \d+[:\/\-]\d+[:\/\-]\d+                   )
    )]]></string>
    <key>Function Pattern</key>
    <string><![CDATA[(?x:
      (?P<function_name>(^\d+.+$))
    )]]></string>
    <key>Skip Pattern</key>
    <string><![CDATA[(?x:(?P>comment))]]></string>
  </dict>
  <key>BBLMKeywordList</key>
  <array>
  <string>Day</string>
  <string>Week</string>
  <string>Month</string>
  <string>Quarter</string>
  <string>Year</string>
  <string>Days</string>
  <string>Weeks</string>
  <string>Months</string>
  <string>Quarters</string>
  <string>Years</string>
  <string>Daily</string>
  <string>Weekly</string>
  <string>Biweekly</string>
  <string>Monthly</string>
  <string>Bimonthly</string>
  <string>Quarterly</string>
  <string>Yearly</string>
  <string>Every</string>
  <string>January</string>
  <string>February</string>
  <string>March</string>
  <string>April</string>
  <string>May</string>
  <string>June</string>
  <string>July</string>
  <string>August</string>
  <string>September</string>
  <string>October</string>
  <string>November</string>
  <string>December</string>
  <string>Jan</string>
  <string>Feb</string>
  <string>Mar</string>
  <string>Apr</string>
  <string>May</string>
  <string>Jun</string>
  <string>Jul</string>
  <string>Aug</string>
  <string>Sep</string>
  <string>Oct</string>
  <string>Nov</string>
  <string>Dec</string>
  <string>This</string>
  <string>Next</string>
  <string>Last</string>
  <string>In</string>
  <string>From</string>
  <string>Since</string>
  <string>To</string>
  <string>Until</string>
  <!-- Commmand directives -->
  <string>account</string>
  <string>alias</string>
  <string>apply</string>
  <string>assert</string>
  <string>bucket</string>
  <string>capture</string>
  <string>check</string>
  <string>comment</string>
  <string>commodity</string>
  <string>default</string>
  <string>define</string>
  <string>end</string>
  <string>endfixed</string>
  <string>eval</string>
  <string>fixed</string>
  <string>format</string>
  <string>include</string>
  <string>nomarket</string>
  <string>note</string>
  <string>payee</string>
  <string>tag</string>
  <string>test</string>
  <!-- The following are not Ledger keywords   -->
  <!-- Feel free to remove them or modify them -->
  <string>Accounts</string>
  <string>Assets</string>
  <string>Card</string>
  <string>Cash</string>
  <string>Checking</string>
  <string>Credit</string>
  <string>Debit</string>
  <string>Equity</string>
  <string>Expenses</string>
  <string>Income</string>
  <string>Interest</string>
  <string>Liabilities</string>
  <string>Payable</string>
  <string>Receivable</string>
  <string>Savings</string>
  <string>Taxes</string>
</array>
</dict> 
</plist>
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.