In verbatim text tabs automatically are being replaced by spaces. If you want to show code snipplets that are formatted using tabs, then this behavior may distort the code. I should be possible to turn off this substitution.

Problem Description

I often write pages in my MoinMoin wiki that contain short snipplets of code (bash scripts, some lines of Java, ...). For intending the code usually I use tabs. Unfortunately, MoinMoin automatically replaces tabs by spaces. In particular, this behavior is annoying when I want to display diffs of two files that contain tabs. These diffs then cannot be used by copy and paste for patching files. Additionally, since every browser known to me can display tabs in verbatim environments correctly, there is no urgent need to do the substitution. I think it is a good idea to make this feature configurable.

Patch

I suggest to introduce a new config option called "tab_expansion" that by default is set to "True". If set to "False" the above mentioned substitution of tabs by spaces is disabled. To implement this I suggest the following patches for MoinMoin 1.9.4:

Changes to MoinMoin/config/multiconfig.py:

--- multiconfig.py
+++ multiconfig.py
@@ -958,6 +958,7 @@
     ('edit_locking', 'warn 10', "Editor locking policy: `None`, `'warn <timeout in minutes>'`, or `'lock <timeout in minutes>'`"),
     ('edit_ticketing', True, None),
     ('edit_rows', 20, "Default height of the edit box"),
+    ('tab_expansion', True, 'if True, replace tabs by spaces.'),
 
   )),
   # ==========================================================================

Changes to MoinMoin/parser/text_moin_wiki.py:

--- text_moin_wiki.py
+++ text_moin_wiki.py
@@ -1433,7 +1433,10 @@
         self.hilite_re = self.formatter.page.hilite_re
 
         # get text and replace TABs
-        rawtext = self.raw.expandtabs()
+        if self.cfg.tab_expansion:
+           rawtext = self.raw.expandtabs()
+       else:
+           rawtext = self.raw
 
         # go through the lines

Discussion

If it is made configurable then may be only for the plain text parser and not for the python parser. Because there tabs are a PEP-8 violation. I have learned myself tabs are always evil for contributors on any language I use. Because often they don't care for patches about that the source was done with tabs. The problem with tabs is that the editor program can handle it always different against to a defined amount of blanks. ReimarBauer/Photo/img.png -- ReimarBauer 2008-07-04 20:10:17

While I also dislike tabs for source code formatting, this is somehow a matter of taste and should not be enforced by MoinMoin IMHO. PEP8 only applies to python, it is not a valid counterargument in general. If for a project all contributors consistently use tabs (and make sure nobody mixes in blanks), I think it is a valid way of formatting. So I think the feature request is valid and we could apply the suggested changes. -- ThomasWaldmann 2012-09-15 22:28:50

Isn't that solved by just using the highlight parser? For all kind of code snippets the pygments based parser should be used. I think it is not needed to add another config option. This issue should be forwarded to pygements if it still exists or we have to use an option for the highlightparser for tabwidth. -- ReimarBauer 2012-09-17 07:19:28

highlight

   1     Level1 (4 blanks)
   2         Level1 (1 Tab)
   3         Level2 (8 blanks)

verbatim

    Level1 (4 blanks)
        Level1 (1 Tab)
        Level2 (8 blanks)

Hmm, it looks like text processed by moin and by pygments has the same issue (tabs are getting expanded). Above we have a solution for moin wiki markup, but I don't see one for pygments (or for other markups). So I guess we can't consistently solve that now. -- ThomasWaldmann 2012-09-17 12:14:53


CategoryFeatureRequest

MoinMoin: FeatureRequests/MakeExpansionOfTabsConfigurable (last edited 2012-09-17 12:14:54 by ThomasWaldmann)