File: modehook.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 (98 lines) | stat: -rw-r--r-- 2,042 bytes parent folder | download | duplicates (4)
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
% modehook.sl	-*- SLang -*-
%\function{modeline_hook2}
%\synopsis{modeline_hook2}
%\description
% check for the following mode statements:
%#v+
% -*- mode: NAME -*-		set mode to NAME
% -*- evalfile: FILE -*-	evaluate file FILE
% -*- eval: expression -*-    evaluate expression
% -*- VAR: VALUE -*-		set VAR = VALUE
%#v-
% these statements may be combined:
%#v+
% -*- mode: NAME; evalfile: FILE; VAR: VALUE -*-
%#v-
define modeline_hook2 ()
{
   variable keyword, value, mode = 0, tag = "-*-", modestr;

   bob ();
   !if (fsearch (tag)) return 0;

   while (ffind (tag))
     {
	go_right (3);
#iffalse
	if (looking_at ("END -*-")) break;
#endif

	push_spot ();
	skip_white (); 
	!if (ffind (tag), pop_spot ()) break;	% closing tag exists?

	forever
	  {
	     skip_chars (" \t;");
	     push_mark ();
	     !if (ffind_char (':'))
	       {
		  pop_mark_0 ();
		  break;
	       }
	     keyword = bufsubstr ();	     
	     go_right_1 ();

	     push_mark ();
	     do
	       {
		  skip_chars ("^-;");
		  if (looking_at_char (';') or looking_at (tag))
		    break;
	       }
	     while (right (1));
	     value = strtrim (bufsubstr ());
	     
	     push_spot ();
	     
	     ERROR_BLOCK
	       {
		  pop_spot ();
	       }
	     % error (sprintf ("keyword <%s> value <%s>", keyword, value));
	     switch (keyword)
	       { case "mode":
		  modestr = "_mode";
		  value = strlow (strtrans (value, "-", "_"));
		  !if (is_substr (value, modestr)) 
		    value += modestr;
		  if (value == "c++_mode")
		    value = "c_mode";
		  if (is_defined(value))
		    {
		       eval (value);
		       mode++;
		    }
	       }
	       { case "evalfile":
		  () = evalfile (value);
	       }
	       { case "eval" :
		  eval (value);
	       }
	       { is_defined (keyword) < 0 :		% set a value
		  eval (keyword + " = " + value);
	       }
#iffalse
	       { is_defined (keyword) > 0 :
		  if (value [0] == '.')		% RPN interpret
		    eval (value + " " + keyword);
	       }
#endif
	     
	     pop_spot ();
	  }
	go_down_1 ();
     }
   mode;
}