File: macro.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 (114 lines) | stat: -rw-r--r-- 2,023 bytes parent folder | download | duplicates (2)
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
103
104
105
106
107
108
109
110
111
112
113
114

define macro_save_macro ()
{
   variable str = get_last_macro ();
   variable file;
   variable macro_name;
   
   file = read_file_from_mini ("Macro filename:");
   !if (strlen (file)) return;
   
   macro_name = read_mini ("Name of macro:", Null_String, Null_String);
   !if (strlen (macro_name)) return;
   
   str = sprintf ("%%%%%%MACRO NAME: %s\n@%s\n\n", macro_name, str);
   
   if (-1 == append_string_to_file (str, file))
     {
	error ("Error appending macro to file");
     }
}

   
define macro_to_function ()
{
   variable macro = get_last_macro ();
   variable i, imax, ch, num;
   variable last_was_insert = 0, f, ftype;
   
   pop2buf ("*macro*");
   eob ();
   
   newline ();
   insert ("\ndefine macro_");
   push_spot ();
   insert ("EDITME ()\n{\n");
   
   imax = strlen (macro);
   num = 0;
   i = 0;
   % Push macro characters on stack 
   while (i < imax)
     {
	ch = macro[i];
	if (ch == '\\')
	  {
	     i++;
	     ch = macro[i];
	  }
	else if (ch == '^') 
	  {
	     i++;
	     ch = macro[i];
	     ch -= '@';
	  }
	
	ch;			       %  push it on stack
	num++;
	i++;
     }
   
   while (num)
     {
	num--;
	ungetkey (());
     }
   
   while (input_pending (0))
     {
	(ftype, f) = get_key_binding ();
	
	
	if (f == "self_insert_cmd")
	  {
	     !if (last_was_insert)
	       {
		  insert ("  insert (\"\");  % insert text here\n");
		  last_was_insert = 1;
	       }
	     continue;
	  }

	if (ftype)
	  {
	     insert (sprintf ("  call (\"%s\");\n", f));
	  }
	else insert (sprintf ("  %s ();\n", f));
	     
	last_was_insert = 0;
     }
   
   insert ("}\n");
   pop_spot ();
}

   
   
define macro_assign_macro_to_key ()
{
   variable key = Null_String;
   variable ch = 0;
   flush ("Press key to assign macro to:");
   
   do
     {
	ch = getkey ();
	if (ch == 0) ch = "^@"; else ch = char (ch);
	key = strcat (key, ch);
     }
   while (input_pending (5));
   
   local_setkey (strcat ("@", get_last_macro ()), key);
   message (strcat ("Macro set to ", expand_keystring (key)));
}