It's been a while since I've used BBedit as I'm a fairly heavy vim user due 
to working on linux machines at work but I've decided to give it a try 
again for some web development I'm starting on the side.

One of the plugins for vim I loved was Align. I used it to keep assignment 
statements aligned. I didn't see a way to do this in Bbedit so I threw 
together a short Python script I thought I would share. Just save to 
alignequals.py and save to your Text Filters folder. Highlight the section 
of text with assignments and call from the text menu. 

So, assuming you have this:

name = "John Doe"
age = 45
occupation = "artist"
height = 72

After highlighting and calling script from "Apply Text Filter", you get:

name       = "John Doe"
age        = 45
occupation = "artist"
height     = 72

Here's the script (it was quick and dirty and I'm not a Python expert so 
any tweaks are welcome):

#!/usr/bin/env python
# File:        alignequals.py
# Description: Aligns piped in text to equals sign
# -*- coding: utf-8 -*-

import sys

max_chars = 0

def read_in():
    global max_chars
    lines = sys.stdin.readlines()
    aligned = []
    
    # First pass will calculate longest left side variable
    
    for i in range(len(lines)):
        lines[i] = lines[i].split("=")
    
        # Clean up spaces
        
        lines[i][0] = lines[i][0].rstrip()
        lines[i][1] = lines[i][1].lstrip()
        if len(lines[i][0]) > max_chars:
            max_chars = len(lines[i][0])
    
    # Second pass pads left side variable

    for i in range(len(lines)):
        lines[i][0] = lines[i][0].ljust( max_chars + 1 )
        newline = lines[i][0] + "= " + lines[i][1]
        aligned.append(newline.rstrip())
    
    return aligned

def main():
    lines = read_in()
    for i in range( len( lines ) ):
        print lines[i]

if __name__ == '__main__':
    main() 


Mark

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to