mgalloy / idldoc

Documenting IDL code
Other
21 stars 13 forks source link

Allow tabs in rst format markup #25

Open mgalloy opened 11 years ago

mgalloy commented 11 years ago

Tabs can be converted to an equivalent number of spaces. IDLdoc should have a keyword to specify the number of spaces for a tab.

mgalloy commented 11 years ago

From Andrew Collette on the mailing list:

I think the keyword approach is best, if you're interesting in implementing it; you could pre-process each line and expand the tabs into spaces before parsing them. That way the document the parser sees is equivalent to the document as it appears in the user's editor. The only wrinkle is people who use tabs for things other than simple indentation, i.e. tables, etc (where they arguably shouldn't be used). Tabs may appear mingled with characters and regular spaces, and the number of spaces to insert will depend on the number of characters since the last "tab-stop." Pseudocode to handle this, for a single input line, would be something like:

space_equivalent = (integer) # number of spaces to a tab, set by keyword
num_not_tabs = 1  # number of non-tab characters processed so far
for each character in input line:
   if( character is tab ):
       n = space_equivalent - ( num_not_tabs mod space_equivalent )
       output "space" n times
       num_not_tabs = 0
   else:
       num_not_tabs += 1
       output character

Most code I've seen in our lab uses either 4 or 8 spaces per tab, with most of that of the 4 variety because you can fit more into a fixed width.