-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScintillaLispCtrl.h
157 lines (137 loc) · 4.21 KB
/
ScintillaLispCtrl.h
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
#ifndef __SCINTILLALISPCTRL_H__
#define __SCINTILLALISPCTRL_H__
#define CWnd ATL::CWindow
#define DECLARE_DYNAMIC(x) // Do nothing
#define IMPLEMENT_DYNAMIC(x, y) // Do nothing
#define ASSERT ATLASSERT
#define CreateEx(dwExStyle, lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, lpParam) \
Create(lpszClassName, HWND(pParentWnd), _U_RECT((RECT&)rect), lpszWindowName, dwStyle, dwExStyle, nID, lpParam)
#include "ScintillaCtrl.h"
#include "Lexilla.h"
#include "SciLexer.h"
// A few basic colors
const COLORREF black = RGB(0, 0, 0);
const COLORREF grey = RGB(128, 128, 128);
const COLORREF white = RGB(255, 255, 255);
const COLORREF green = RGB(0, 128, 0);
const COLORREF red = RGB(255, 0, 0);
const COLORREF blue = RGB(0, 0, 255);
const COLORREF yellow = RGB(255, 255, 0);
const COLORREF magenta = RGB(255, 0, 255);
const COLORREF cyan = RGB(0, 255, 255);
const COLORREF brown = RGB(165, 42, 42);
struct SScintillaColors
{
int iItem;
COLORREF rgb;
};
static SScintillaColors g_rgbSyntaxLisp[] =
{
{ SCE_LISP_DEFAULT, blue },
{ SCE_LISP_COMMENT, grey },
{ SCE_LISP_NUMBER , green },
{ SCE_LISP_KEYWORD, blue },
{ SCE_LISP_KEYWORD_KW, blue },
{ SCE_LISP_SYMBOL, red },
{ SCE_LISP_STRING, magenta },
{ SCE_LISP_STRINGEOL, magenta },
{ SCE_LISP_IDENTIFIER, black },
{ SCE_LISP_OPERATOR, red },
{ SCE_LISP_SPECIAL, red },
{ SCE_LISP_MULTI_COMMENT, cyan },
{ STYLE_BRACELIGHT, black },
{ STYLE_BRACEBAD, black },
{ -1, 0 }
};
//////////////////// Classes //////////////////////////////////////////////////
class SCINTILLACTRL_EXT_CLASS CScintillaLispCtrl : public CScintillaCtrl
{
public:
BOOL m_CanLisp;
CFont m_Font;
UINT m_KeyWordSet;
int OnUpdateUI(LPNMHDR nmhdr)
{
// do brace matching
Sci_Position lStart = GetCurrentPos();
int chBr = GetCharAt(lStart - 1);
m_CanLisp = FALSE;
if (chBr && CString("()[]{}").Find(chBr) != -1) {
Sci_Position lEnd = BraceMatch(lStart - 1, 0);
// if there is a matching brace highlight it
if (lEnd >= 0) {
BraceHighlight(lStart - 1, lEnd);
m_CanLisp = TRUE;
}
// if there is NO matching brace erase old highlight
else {
BraceBadLight(lStart - 1);
}
}
else {
BraceHighlight(-1, -1);
}
if (GetSelectionEnd() != GetSelectionStart())
m_CanLisp = TRUE;
return 0;
}
void Init() {
SetCallDirect(FALSE);
ILexer5* pLexer = CreateLexer("lisp");
SetILexer(pLexer);
StyleClearAll();
SetMarginWidthN(0, 40);
SetMarginWidthN(1, 0);
// ClearCmdKey(SCK_RETURN + (SCMOD_NORM << 16));
// ClearCmdKey(SCK_RETURN + (SCMOD_SHIFT << 16));
int tabSize = g_Settings.GetUserProfileDword("Settings", "TabSize");
SetTabWidth(tabSize);
if (g_Settings.GetUserProfileDword("Settings", "TabUsesSpaces"))
SetUseTabs(FALSE);
DWORD fontsize = g_Settings.GetUserProfileDword("Settings", "FontSize");
CString fontname = g_Settings.GetUserProfileString("Settings", "FontName", NULL);
if (!fontname.IsEmpty() && fontsize) {
m_Font.CreatePointFont(fontsize, fontname);
}
else {
m_Font = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
}
LOGFONT logfont;
m_Font.GetLogFont(logfont);
int nPixels = (-MulDiv(logfont.lfHeight, 72, GetDeviceCaps(GetDC(), LOGPIXELSY)));
for (long i = 0; g_rgbSyntaxLisp[i].iItem != -1; i++) {
StyleSetFore(g_rgbSyntaxLisp[i].iItem, g_rgbSyntaxLisp[i].rgb);
StyleSetFont(g_rgbSyntaxLisp[i].iItem, logfont.lfFaceName);
StyleSetSize(g_rgbSyntaxLisp[i].iItem, nPixels);
}
DWORD keywordset = g_Settings.GetUserProfileDword("Settings", "KeywordSet");
switch (keywordset) {
case 0:
SetKeyWords(0, g_LispKeyWords);
break;
case 1:
SetKeyWords(0, g_SchemeKeyWords);
break;
case 2:
SetKeyWords(0, g_NewLispKeyWords);
break;
case 3:
SetKeyWords(0, g_ISLispKeyWords);
break;
case 4:
SetKeyWords(0, g_PicoLispKeyWords);
break;
case 5:
SetKeyWords(0, g_ClojureKeyWords);
break;
case 6:
SetKeyWords(0, g_JanetKeyWords);
break;
}
StyleSetBack(STYLE_BRACELIGHT, RGB(0, 255, 0));
StyleSetBack(STYLE_BRACEBAD, RGB(255, 0, 0));
}
};
// #include "ScintillaCtrl.cpp"
#endif //#ifndef __SCINTILLACTRL_H__