-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalign.e
86 lines (67 loc) · 1.86 KB
/
align.e
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
#include "slick.sh"
// Based on aligncustom.e from here:
// https://community.slickedit.com/index.php/topic,15632.msg59735.html#msg59735
static int max_col;
static _str find_max_eq_filter(s)
{
int first_char = pos("[^[:blank:]]", s, 1, "R");
if (first_char == 0) {
return s
}
next_space = pos("[[:blank:]]", s, first_char, "R")
if (next_space > max_col) {
max_col = next_space;
}
return s;
}
static _str align_eq_filter(s)
{
if (max_col == 0 || length(s) == 0) {
return s;
}
int first_char = pos("[^[:blank:]]", s, 1, "R");
if (first_char == 0) {
return s;
}
next_space = pos("[[:blank:]]", s, first_char, "R")
if (next_space == 0) {
return s;
}
next_char = pos("[^[:blank:]]", s, next_space, "R");
if (next_char == 0 || next_char <= next_space) {
return s;
}
_str prefix;
_str postfix;
if (next_char > max_col) {
prefix = substr(s, 1, next_space - 1);
postfix = substr(s, next_space + (next_char - max_col) - 1);
} else {
next_space += next_char - next_space - 1;
prefix = substr(s, 1, next_space - 1);
postfix = substr(s, next_space);
while (next_space < max_col) {
prefix = prefix :+ ' ';
next_space++;
}
}
return prefix :+ postfix;
}
static void do_align()
{
max_col = 0;
filter_selection(find_max_eq_filter);
if (max_col == 0) {
return;
}
filter_selection(align_eq_filter);
_free_selection("");
}
_command void align() name_info(','VSARG2_MARK|VSARG2_REQUIRES_EDITORCTL)
{
if (_select_type() == "" || _select_type() != "CHAR") {
message("A line selection is required for this function");
return;
}
do_align();
}