-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhm_adjust_textile-lists.mac
78 lines (68 loc) · 1.48 KB
/
hm_adjust_textile-lists.mac
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
// Adjust level of lists for Textile syntax
//
// How to setup
// Set up your keyboard shortcuts configuration as below
// 1) * + * + right -> this macro
// 2) * + * + left -> this macro
// e.g.
// Shift + Alt + Right (or Left)
// aka Promote/Demote for Microsoft Office.
//
// Functions
// - process a line under cursor
// - process multi line seleted
disabledraw;
#indent_mode = 1;
#unindent_mode = -1;
#mode = #indent_mode;
if(iskeydown(0x25)) #mode = #unindent_mode;
#x = column;
#y = lineno;
if(selecting == yes){
#was_selecting = yes;
#target_top_row = seltoplineno;
#target_end_row = selendlineno;
if(selendcolumn == 0) #target_end_row = #target_end_row - 1;
escape;
} else {
#target_top_row = lineno;
#target_end_row = #target_top_row;
}
#target_row = #target_top_row;
while (#target_row <= #target_end_row){
call ProcLine #target_row;
#target_row = #target_row + 1;
}
EndMacro:
if(#was_selecting == yes){
movetolineno 1, #target_top_row;
beginsel;
movetolineno 1, #target_end_row + 1;
} else movetolineno #x + 1, #y;
endmacroall;
ProcLine:
movetolineno 1, ##1;
while(code == 0x20 || code == 0x09) right;
if(code == 0x0D){;}
else if((code == 0x23) // #
|| (code == 0x2A)) // *
{
if(#mode == #indent_mode){
insertfix char(code);
#x = #x + 1;
} else if(#mode == #unindent_mode) {
#code = code;
right;
if(code == #code){
delete;
if(column < #x) #x= #x - 1;
}
}
} else {
if(#mode == #indent_mode){
golinetop2;
insertfix "* ";
#x = #x + 2;
}
}
return 0;