File: untab.sl

package info (click to toggle)
jed 0.98.7-14
  • links: PTS
  • area: main
  • in suites: slink
  • size: 3,088 kB
  • ctags: 3,851
  • sloc: ansic: 29,315; makefile: 257; sh: 248
file content (54 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% untabify region function



define untab_convert_to_tabs ()
{
   variable c;
   while (fsearch_char (' '))
     {
	c = what_column ();
	push_mark ();
	skip_white ();
	c = what_column () - c;
	if (c > 1)
	  {
	     del_region ();
	     whitespace (c);
	  }
	else pop_mark_0 ();
     }
}

%!% Prototype: Void untab ();
%!% This function may be used either to convert tabs to spaces or, if called
%!% with a prefix argument, it will perform the opposite conversion from 
%!% spaces to tabs.  This function operates on a region.
define untab ()
{
   check_region (0);
   narrow ();
   bob ();
   if (-1 != prefix_argument (-1))
     {
	untab_convert_to_tabs ();
     }
   else
     {
	while (fsearch ("\t")) 
	  {
	     TAB;                       % on stack
	     skip_white ();
	     what_column ();   % on stack
	     bskip_chars ("\t ");
	     () - what_column ();   % on stack
	     trim ();
	     TAB = 0;
	     whitespace (());
	     TAB = ();
	  }
     }
   
   widen ();
}