File: meta-compat

package info (click to toggle)
epic5 3.0.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: ansic: 75,810; makefile: 648; ruby: 227; python: 215; sh: 78; perl: 13
file content (116 lines) | stat: -rw-r--r-- 2,966 bytes parent folder | download | duplicates (5)
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
115
116
if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; };

# $EPIC: meta-compat,v 1.3 2005/06/25 14:12:12 jnelson Exp $
# meta-compat - compatibility layer for old-style /bind METAx-y sequences
#
# Copyright 2003 Ben Winslow <rain bluecherry net>
#
# Released under the same license as ircII-EPIC
#
# Caveat: The sticky behavior of META4 isn't supported; META4 will behave
# like any other meta level.

package meta-compat

alias bind (binding, boundto) {
	# we're resetting everything to the defaults - clear our list of
	# meta keys and reinitialize

	@metacompat.depth++;

	if (metacompat.depth > 100) {
		xecho -b meta-compat: recursed too many times for /bind $binding $boundto;
		return;
	};

#	echo bind: $repeat($metacompat.depth $chr(9)) $binding $boundto;
	
	if (binding == [-DEFAULTS]) {
		//bind -defaults;
		metacompat.defaults;

		@metacompat.depth--;
		return;
	};
	
	# this binding uses a meta type, resolve it into a key sequence
	if (binding =~ [META%-%]) {
		@:spec=rest(4 $binding);
		@:meta=before(- $spec);
		@:keys=after(- $spec);

		foreach metacompat[$meta][defs] curmeta {
			bind $decode($curmeta)$keys $boundto;
		};
		if (boundto == [NOTHING]) {
			@:boundto=[];
		};

		@metacompat[$meta][keys][$encode($keys)]=boundto;

		@metacompat.depth--;
		return;
	};

	# look for an existing meta level on this key and clear it because
	# we're binding to something else.  additionally, remove any underlying
	# bindings that will no longer be relevant when this key is removed
	@:encoded=encode($binding);

	foreach metacompat curmeta {
		if (metacompat[$curmeta][defs][$encoded]) {
			# unbind any affected keys
			foreach metacompat[$curmeta][keys] curkey {
				^bind $decode($encoded$curkey) NOTHING;
			};
			^assign -metacompat[$curmeta][defs][$encoded];
		};
	};

	# this binding sets a meta level, save it and NOP
	if (boundto =~ [META%]) {
		@:spec=rest(4 $boundto);
		@:meta=before(_ $spec);
		# allow shortcutting to METAx instead of METAx_CHARACTER
		if (meta == []) {
			@:meta=spec;
		};
		@metacompat[$meta][defs][$encode($binding)]=1;

		# rebind keys for this meta level so that the new meta character
		# takes effect
		foreach metacompat[$meta][keys] curkey {
			bind META$META-$decode($curkey) $metacompat[$meta][keys][$curkey];
		};

		@metacompat.depth--;
		return;
	};

	# we've either resolved the binding to a key sequence, or this is
	# a new-style bind that we don't need to mangle
	if (boundto == []) {
		//bind $binding;
	} else {
		//bind $binding $boundto;
	};
	@metacompat.depth--;
};

alias metacompat.defaults {
	fe ($aliasctl(ASSIGN PMATCH metacompat\.*)) metainfo {
		^assign -$metainfo;
	};
	
	# defaults from EPIC4-1.0.1
	bind ^X META2_CHARACTER;
	bind ^[ META1_CHARACTER;
	bind META1-O META2_CHARACTER;
	bind META1-[ META2_CHARACTER;
	bind META2-1 META32_CHARACTER;
	bind META2-4 META33_CHARACTER;
	bind META2-5 META30_CHARACTER;
	bind META2-6 META31_CHARACTER;
};

metacompat.defaults;