jed-users mailing list

[2006 Date Index] [2006 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Looking for Python programmers for testing.


Hi,

this patch tries to address the problem that python forbids mixing up
spaces and tabs as indention characters. It should select the right
character for each file. Please test it and report all problems and
success.

#v+
#! /bin/sh /usr/share/dpatch/dpatch-run
## fix-pymode-tab-space.dpatch by Jörg Sommer <joerg@xxxxxxxxxxxx>
##
## DP: In Python, it is forbidden to mix up tabs and spaces as indention
## DP: characters. This patch enhances the python mode to take care of the
## DP: prefered indention character in a file. Fixes #305668

@DPATCH@
diff -urNad trunk~/lib/pymode.sl trunk/lib/pymode.sl
--- trunk~/lib/pymode.sl	(Revision 35) 
+++ trunk/lib/pymode.sl	        (Arbeitskopie)
@@ -139,10 +139,16 @@
     
    col = what_column() - 1;
     
+   variable indent;
+   if ( get_blocal_var("py_use_tab") )
+      indent = TAB;
+   else
+      indent = Py_Indent_Level;
+
    if (py_line_ends_with_colon())
-      col += Py_Indent_Level;
+      col += indent;
    if (py_endblock_cmd() or (subblock and not py_line_starts_block()))
-      col -= Py_Indent_Level;
+      col -= indent;
 }
 
 define py_indent_line()
@@ -151,6 +157,9 @@
     
    col = py_indent_calculate();
    bol_trim ();
+   if ( get_blocal_var("py_use_tab") )
+      loop (col / TAB) insert_char('\t');
+   else
    whitespace( col );
 }
 
@@ -246,11 +255,19 @@
    bskip_white(); 
    if (bolp() and (col > 1)) { 
       pop_spot();                                                     
+      if ( blooking_at("\t") )
+      {
+          () = left(1);
+          del();
+      }
+      else
+      {
       bol_trim (); 
       col--;                                                         
       if (col mod Py_Indent_Level == 0) 
         col--; 
       whitespace ( (col / Py_Indent_Level) * Py_Indent_Level ); 
+      }
    } 
    else { 
       pop_spot(); 
@@ -261,6 +278,9 @@
 define py_shift_line_right()
 {
    bol_skip_white();
+   if ( get_blocal_var("py_use_tab") )
+      insert_char('\t');
+   else
    whitespace(Py_Indent_Level);
 }
 
@@ -293,9 +313,17 @@
 {
    bol_skip_white();
    if (what_column() > Py_Indent_Level) {
+      if ( get_blocal_var("py_use_tab") )
+      {
+          () = left(1);
+          del();
+      }
+      else
+      {
       push_mark();
       goto_column(what_column() - Py_Indent_Level);
       del_region();
+      }
    }
 }
 
@@ -440,11 +468,17 @@
 	 % Indent is wrong.  Hopefully it's a continuation line.
 	 level = oldlevel;	% reset level
 	 bol_trim();
+         if ( get_blocal_var("py_use_tab") )
+            loop (level) insert_char('\t');
+         else
 	 whitespace(level * Py_Indent_Level + (col - current_indent));
       } else {
 	 current_indent = col;
 	 indent_level[level] = col;
 	 bol_trim();
+         if ( get_blocal_var("py_use_tab") )
+            loop (level) insert_char('\t');
+         else
 	 whitespace(level * Py_Indent_Level);
       }
    } while (down(1) == 1);
@@ -578,12 +612,29 @@
 {
    variable python = "python";
    
-   % TAB is checked by whitespace(). If TAB=0 no tab character is used,
-   % which avoids mixing up whitespace and tab indention
-   if (Py_Indent_Level == 8)
-     TAB = 8;
-   else
-     TAB = 0;
+   create_blocal_var("py_use_tab");
+   set_blocal_var(Py_Indent_Level == TAB, "py_use_tab");
+   push_spot();
+   bob();
+   do
+   {
+       skip_white();
+       if ( looking_at("\"\"\"") )
+       {
+           () = right(1);
+           () = fsearch("\"\"\"");
+       }
+       else
+         !if (looking_at_char('#') or eolp() or what_column() == 1)
+         {
+             message("foo" + string(what_line()));
+             bol();
+             set_blocal_var(looking_at_char('\t'), "py_use_tab");
+             break;
+         }
+   }
+   while ( down(1) );
+   pop_spot();
 
    set_mode (python, 0x4); % flag value of 4 is generic language mode
    use_keymap(python);
#v-

Bye, Jörg.
-- 
Du kannst einem Schwein einen goldenen Ring durch die Nase ziehen,
deswegen bleibt es trozdem ein Schwein!

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2006 date index] [2006 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]