File: krconv.sl

package info (click to toggle)
jed 0.99.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,312 kB
  • ctags: 4,736
  • sloc: ansic: 36,879; sh: 8,660; makefile: 379
file content (102 lines) | stat: -rw-r--r-- 1,904 bytes parent folder | download
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
static define fixup_line ()
{
   variable col;

   !if (parse_to_point ())
     {
	col = what_column ();
	bol_skip_white ();
	if (col != what_column ())
	  {
	     goto_column (col);
	     indent_line ();
	     if (C_BRA_NEWLINE) newline ();
	  }
	go_right_1 ();
	trim ();
	!if (eolp () or looking_at_char (',') or looking_at_char (';'))
	  {
	     indent_line ();
	     newline ();
	  }
	continue;
     }
   go_right_1 ();
}

define c_indent_buffer ()
{
   variable line = -50, max_line;
   push_spot ();
   eob ();
   max_line = what_line ();
   bob ();
   do
     {
	bol_skip_white ();
	if (looking_at ("/*"))
	  {
	     % skip the comment 
	     () = fsearch ("*/");
	     continue;
	  }
	
	eol ();
	if (blooking_at ("\\"))
	  {
	     indent_line ();
	     % skip all continuation lines.
	     while (down (1))
	       {
		  eol ();
		  !if (blooking_at ("\\")) break;
	       }
	     continue;
	  }
	trim ();
	bol_skip_white ();
	!if (looking_at_char ('{'))
	  {
	     variable this_line = what_line ();
	     % I do not want to touch constructs such as x = {1, 3};
	     while (ffind_char ('{')
		    and parse_to_point ())
	       go_right_1 ();
	     
	     if (looking_at_char ('{'))
	       {
		  variable m = create_user_mark ();
		  if (find_matching_delimiter ('{')
		      and (this_line == what_line ()))
		    {
		       eol ();
		       indent_line ();
		       continue;
		    }
		  goto_user_mark (m);
	       }
	     bol ();
	     while (ffind_char ('}'))
	       fixup_line ();
	     bol ();
	     while (ffind_char ('{'))
	       fixup_line ();
	  }

	indent_line ();
	if (line + 50 < what_line ())
	  {
	     line = what_line ();
	     flush (sprintf ("processed %d/%d lines.", line, max_line));
	  }
	
	%update_sans_update_hook (1);
     }
   while (down_1 ());
   trim_buffer ();
   flush (sprintf ("processed %d/%d lines.", what_line (), max_line));
   pop_spot ();
}