Lua_Error, ClangFormatOnSave
This commit is contained in:
@@ -467,6 +467,7 @@ void GenerateConfig() {
|
|||||||
style.add({"DrawScrollbar", "1"});
|
style.add({"DrawScrollbar", "1"});
|
||||||
style.add({"IndentSize", "4"});
|
style.add({"IndentSize", "4"});
|
||||||
style.add({"TrimWhitespaceOnSave", "1"});
|
style.add({"TrimWhitespaceOnSave", "1"});
|
||||||
|
style.add({"ClangFormatOnSave", "0"});
|
||||||
style.add({"FontSize", "12"});
|
style.add({"FontSize", "12"});
|
||||||
style.add({"FontFilter", "0"}); // nearest = 0, linear = 1 - seems like nearest always better?
|
style.add({"FontFilter", "0"}); // nearest = 0, linear = 1 - seems like nearest always better?
|
||||||
style.add({"Font", "C:/Windows/Fonts/consola.ttf"});
|
style.add({"Font", "C:/Windows/Fonts/consola.ttf"});
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ void ReportWarningf(const char *fmt, ...) {
|
|||||||
|
|
||||||
void Command_InsertTitlebarCommand(BSet title, String16 needle, String16 string, bool select_entire);
|
void Command_InsertTitlebarCommand(BSet title, String16 needle, String16 string, bool select_entire);
|
||||||
BSet title = GetActiveTitleSet();
|
BSet title = GetActiveTitleSet();
|
||||||
Command_InsertTitlebarCommand(title, L"#Error(\"", ToString16(scratch, string), true);
|
Command_InsertTitlebarCommand(title, L"#Error('", ToString16(scratch, string), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
|
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
|
||||||
@@ -589,21 +589,26 @@ void Command_ConvertLineEndings(View *view, bool dont_trim_lines_with_cursor) {
|
|||||||
view->update_scroll = false;
|
view->update_scroll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsCFile(String name) {
|
||||||
|
bool result = EndsWith(name, ".cpp") || EndsWith(name, ".c") || EndsWith(name, ".hpp") || EndsWith(name, ".h");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void SaveBuffer(View *view) {
|
void SaveBuffer(View *view) {
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
bool dont_trim_lines_with_cursor = true;
|
||||||
|
Command_ConvertLineEndings(view, dont_trim_lines_with_cursor);
|
||||||
if (StyleTrimWhitespaceOnSave) {
|
if (StyleTrimWhitespaceOnSave) {
|
||||||
bool dont_trim_lines_with_cursor = true;
|
|
||||||
Command_TrimTrailingWhitespace(view, dont_trim_lines_with_cursor);
|
Command_TrimTrailingWhitespace(view, dont_trim_lines_with_cursor);
|
||||||
Command_ConvertLineEndings(view, dont_trim_lines_with_cursor);
|
|
||||||
Assert(view->active_buffer == buffer->id);
|
Assert(view->active_buffer == buffer->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// {
|
if (StyleClangFormatOnSave && IsCFile(buffer->name)) {
|
||||||
// Scratch scratch;
|
Scratch scratch;
|
||||||
// String string = AllocCharString(scratch, buffer);
|
String string = AllocCharString(scratch, buffer);
|
||||||
// Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string);
|
Buffer *temp_buffer = ExecAndWait(scratch, "clang-format", GetDir(buffer), string);
|
||||||
// Command_ReplaceWithoutMovingCarets(view, GetRange(buffer), {temp_buffer->str, temp_buffer->len});
|
Command_ReplaceWithoutMovingCarets(view, GetRange(buffer), {temp_buffer->str, temp_buffer->len});
|
||||||
// }
|
}
|
||||||
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String string = AllocCharString(scratch, buffer);
|
String string = AllocCharString(scratch, buffer);
|
||||||
@@ -890,7 +895,7 @@ void Command_InsertTitlebarCommand(BSet title, String16 needle, String16 initial
|
|||||||
{
|
{
|
||||||
String needle8 = ToString(scratch, needle);
|
String needle8 = ToString(scratch, needle);
|
||||||
String initial_value8 = ToString(scratch, initial_value);
|
String initial_value8 = ToString(scratch, initial_value);
|
||||||
String quoted = Format(scratch, "%.*s%.*s\")", FmtString(needle8), FmtString(initial_value8));
|
String quoted = Format(scratch, "%.*s%.*s')", FmtString(needle8), FmtString(initial_value8));
|
||||||
quoted16 = ToString16(scratch, quoted);
|
quoted16 = ToString16(scratch, quoted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlPress(SDLK_F)) {
|
if (CtrlPress(SDLK_F)) {
|
||||||
Command_SelectTitlebarCommand(active.window, L"#Search(\"");
|
Command_SelectTitlebarCommand(active.window, L"#Search('");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlPress(SDLK_S)) {
|
if (CtrlPress(SDLK_S)) {
|
||||||
@@ -455,7 +455,7 @@ void OnCommand(Event event) {
|
|||||||
|
|
||||||
if (CtrlShiftPress(SDLK_G)) {
|
if (CtrlShiftPress(SDLK_G)) {
|
||||||
} else if (CtrlPress(SDLK_G)) {
|
} else if (CtrlPress(SDLK_G)) {
|
||||||
Command_SelectTitlebarCommand(active.window, L"#FuzzySort(\"");
|
Command_SelectTitlebarCommand(active.window, L"#FuzzySort('");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CtrlShiftPress(SDLK_W)) {
|
if (CtrlShiftPress(SDLK_W)) {
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ Style.DrawLineNumbers = 1
|
|||||||
Style.DrawScrollbar = 1
|
Style.DrawScrollbar = 1
|
||||||
Style.IndentSize = 4
|
Style.IndentSize = 4
|
||||||
Style.TrimWhitespaceOnSave = 1
|
Style.TrimWhitespaceOnSave = 1
|
||||||
|
Style.ClangFormatOnSave = 0
|
||||||
Style.FontSize = 12
|
Style.FontSize = 12
|
||||||
Style.FontFilter = 0
|
Style.FontFilter = 0
|
||||||
Style.Font = "C:/Windows/Fonts/consola.ttf"
|
Style.Font = "C:/Windows/Fonts/consola.ttf"
|
||||||
@@ -307,6 +308,7 @@ void ReloadStyle() {
|
|||||||
StyleDrawScrollbar = GetStyleInt("DrawScrollbar", StyleDrawScrollbar);
|
StyleDrawScrollbar = GetStyleInt("DrawScrollbar", StyleDrawScrollbar);
|
||||||
StyleIndentSize = GetStyleInt("IndentSize", StyleIndentSize);
|
StyleIndentSize = GetStyleInt("IndentSize", StyleIndentSize);
|
||||||
StyleTrimWhitespaceOnSave = GetStyleInt("TrimWhitespaceOnSave", StyleTrimWhitespaceOnSave);
|
StyleTrimWhitespaceOnSave = GetStyleInt("TrimWhitespaceOnSave", StyleTrimWhitespaceOnSave);
|
||||||
|
StyleClangFormatOnSave = GetStyleInt("ClangFormatOnSave", StyleClangFormatOnSave);
|
||||||
StyleFontSize = GetStyleInt("FontSize", StyleFontSize);
|
StyleFontSize = GetStyleInt("FontSize", StyleFontSize);
|
||||||
StyleFontFilter = GetStyleInt("FontFilter", StyleFontFilter);
|
StyleFontFilter = GetStyleInt("FontFilter", StyleFontFilter);
|
||||||
StyleFont = GetStyleString("Font", StyleFont);
|
StyleFont = GetStyleString("Font", StyleFont);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ Int StyleDrawLineNumbers = 1;
|
|||||||
Int StyleDrawScrollbar = 1;
|
Int StyleDrawScrollbar = 1;
|
||||||
Int StyleIndentSize = 4;
|
Int StyleIndentSize = 4;
|
||||||
Int StyleTrimWhitespaceOnSave = 1;
|
Int StyleTrimWhitespaceOnSave = 1;
|
||||||
|
Int StyleClangFormatOnSave = 0;
|
||||||
Int StyleFontSize = 12;
|
Int StyleFontSize = 12;
|
||||||
Int StyleFontFilter = 0;
|
Int StyleFontFilter = 0;
|
||||||
String StyleFont = "C:/Windows/Fonts/consola.ttf";
|
String StyleFont = "C:/Windows/Fonts/consola.ttf";
|
||||||
@@ -113,6 +113,12 @@ int Lua_Kill(lua_State *L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Lua_Error(lua_State *L) {
|
||||||
|
Buffer *buffer = GetBuffer(NullBufferID);
|
||||||
|
Open(buffer->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Lua_Open(lua_State *L) {
|
int Lua_Open(lua_State *L) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String path = luaL_checkstring(L, 1);
|
String path = luaL_checkstring(L, 1);
|
||||||
@@ -477,6 +483,7 @@ bool EvalString(Allocator allocator, String16 string16) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Command_EvalLua(View *view, String16 string) {
|
bool Command_EvalLua(View *view, String16 string) {
|
||||||
|
if (string.len && string.data[0] == L'#') string = Skip(string, 1);
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
return EvalString(scratch, string);
|
return EvalString(scratch, string);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{"AppendCmd", Lua_AppendCmd},
|
{"AppendCmd", Lua_AppendCmd},
|
||||||
{"C", Lua_C},
|
{"C", Lua_C},
|
||||||
{"Kill", Lua_Kill},
|
{"Kill", Lua_Kill},
|
||||||
|
{"Error", Lua_Error},
|
||||||
{"Open", Lua_Open},
|
{"Open", Lua_Open},
|
||||||
{"Reopen", Lua_Reopen},
|
{"Reopen", Lua_Reopen},
|
||||||
{"Print", Lua_Print},
|
{"Print", Lua_Print},
|
||||||
|
|||||||
Reference in New Issue
Block a user