Misc improvements
This commit is contained in:
@@ -66,6 +66,16 @@
|
|||||||
#define COMPILER_GCC 0
|
#define COMPILER_GCC 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEBUG_BUILD
|
||||||
|
#define DEBUG_BUILD 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG_BUILD
|
||||||
|
#define IF_DEBUG(x) x
|
||||||
|
#else
|
||||||
|
#define IF_DEBUG(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if OS_WINDOWS
|
#if OS_WINDOWS
|
||||||
#define BREAK() __debugbreak()
|
#define BREAK() __debugbreak()
|
||||||
#elif OS_LINUX
|
#elif OS_LINUX
|
||||||
|
|||||||
@@ -41,17 +41,6 @@ void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
|
|||||||
set->buffer->garbage = true;
|
set->buffer->garbage = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
|
|
||||||
set->buffer = GetBuffer(buffer_id);
|
|
||||||
set->view = WindowOpenBufferView(set->window, set->buffer->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void EndJump(BSet set) {
|
|
||||||
Int pos = XYToPos(set.buffer, {0, set.buffer->line_starts.len - 1});
|
|
||||||
set.view->carets[0] = MakeCaret(pos);
|
|
||||||
UpdateScroll(set.window, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseLoadWord(Event event, String meta = "") {
|
void MouseLoadWord(Event event, String meta = "") {
|
||||||
Vec2I mouse = MouseVec2I();
|
Vec2I mouse = MouseVec2I();
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
@@ -637,6 +626,8 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
|
|||||||
} else if (o.kind == OpenKind_BackgroundExec) {
|
} else if (o.kind == OpenKind_BackgroundExec) {
|
||||||
// this shouldn't change the focus/window/view
|
// this shouldn't change the focus/window/view
|
||||||
Exec(NullViewID, true, o.path, GetMainDir());
|
Exec(NullViewID, true, o.path, GetMainDir());
|
||||||
|
} else if (o.kind == OpenKind_Command) {
|
||||||
|
EvalCommand(o.path);
|
||||||
} else if (o.kind == OpenKind_Skip) {
|
} else if (o.kind == OpenKind_Skip) {
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
@@ -704,7 +695,7 @@ void Command_SetWorkDir() {
|
|||||||
WorkDir = GetDir(main.buffer);
|
WorkDir = GetDir(main.buffer);
|
||||||
} RegisterCommand(Command_SetWorkDir, "");
|
} RegisterCommand(Command_SetWorkDir, "");
|
||||||
|
|
||||||
String CodeSkipPatterns[] = {".git/"};
|
String CodeSkipPatterns[] = {".git/", ".obj", ".o", ".pdb", ".exe"};
|
||||||
String Coro_OpenCodeDir;
|
String Coro_OpenCodeDir;
|
||||||
|
|
||||||
void Coro_OpenCode(mco_coro *co) {
|
void Coro_OpenCode(mco_coro *co) {
|
||||||
@@ -756,6 +747,9 @@ void Command_CloseWindow() {
|
|||||||
} RegisterCommand(Command_CloseWindow, "");
|
} RegisterCommand(Command_CloseWindow, "");
|
||||||
|
|
||||||
SaveResult TrySavingBuffer(Buffer *buffer) {
|
SaveResult TrySavingBuffer(Buffer *buffer) {
|
||||||
|
if (buffer->special || buffer->is_dir || buffer->garbage) {
|
||||||
|
return SAVE_NO;
|
||||||
|
}
|
||||||
if (buffer->dirty) {
|
if (buffer->dirty) {
|
||||||
SaveResult save = SaveMessageBox(buffer->name);
|
SaveResult save = SaveMessageBox(buffer->name);
|
||||||
if (save == SAVE_CANCEL) {
|
if (save == SAVE_CANCEL) {
|
||||||
@@ -1080,7 +1074,7 @@ void Command_SelectToLineEnd() {
|
|||||||
void Command_Delete() {
|
void Command_Delete() {
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
Delete(active.view, DIR_LEFT);
|
Delete(active.view, DIR_LEFT);
|
||||||
} RegisterCommand(Command_Delete, "backspace");
|
} RegisterCommand(Command_Delete, "shift-backspace | backspace");
|
||||||
|
|
||||||
void Command_DeleteBoundary() {
|
void Command_DeleteBoundary() {
|
||||||
BSet active = GetBSet(ActiveWindowID);
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
|||||||
@@ -157,6 +157,29 @@ Trigger *ParseKey(Allocator allocator, String key, char *debug_name) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CachedTrigger {
|
||||||
|
Trigger *trigger;
|
||||||
|
String key;
|
||||||
|
};
|
||||||
|
Array<CachedTrigger> CachedTriggers;
|
||||||
|
|
||||||
|
Trigger *ParseKeyCached(String key) {
|
||||||
|
For (CachedTriggers) {
|
||||||
|
if (it.key == key) {
|
||||||
|
return it.trigger;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Allocator allocator = GetSystemAllocator();
|
||||||
|
Trigger *result = ParseKey(allocator, key, key.data);
|
||||||
|
if (!result) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Add(&CachedTriggers, {result, key});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool MatchEvent(Trigger *trigger, Event *event) {
|
bool MatchEvent(Trigger *trigger, Event *event) {
|
||||||
if (trigger->kind == TriggerKind_Key) {
|
if (trigger->kind == TriggerKind_Key) {
|
||||||
if (trigger->key == event->key && trigger->ctrl == event->ctrl && trigger->alt == event->alt && trigger->shift == event->shift) {
|
if (trigger->key == event->key && trigger->ctrl == event->ctrl && trigger->alt == event->alt && trigger->shift == event->shift) {
|
||||||
|
|||||||
@@ -412,6 +412,30 @@ void OnCommand(Event event) {
|
|||||||
IF_DEBUG(AssertRanges(active.view->carets));
|
IF_DEBUG(AssertRanges(active.view->carets));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EvalCommand(String command) {
|
||||||
|
BSet active = GetBSet(ActiveWindowID);
|
||||||
|
For (active.view->hooks) {
|
||||||
|
if (it.name == command) {
|
||||||
|
ProfileScopeEx(it.name);
|
||||||
|
it.function();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
For (CommandFunctions) {
|
||||||
|
if (it.name == command) {
|
||||||
|
ProfileScopeEx(it.name);
|
||||||
|
it.function();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EvalCommand(String16 command) {
|
||||||
|
Scratch scratch;
|
||||||
|
EvalCommand(ToString(scratch, command));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GarbageCollect() {
|
void GarbageCollect() {
|
||||||
if (RunGCThisFrame == false) {
|
if (RunGCThisFrame == false) {
|
||||||
return;
|
return;
|
||||||
@@ -787,7 +811,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
For (CommandFunctions) {
|
For (CommandFunctions) {
|
||||||
if (it.binding.len != 0) {
|
if (it.binding.len != 0) {
|
||||||
it.trigger = ParseKey(Perm, it.binding, it.name.data);
|
it.trigger = ParseKeyCached(it.binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ Buffer *CreateBuffer(Allocator allocator, String name, Int size = 4096);
|
|||||||
View *CreateView(BufferID active_buffer);
|
View *CreateView(BufferID active_buffer);
|
||||||
void ReopenBuffer(Buffer *buffer);
|
void ReopenBuffer(Buffer *buffer);
|
||||||
bool ProcessIsActive(ViewID view);
|
bool ProcessIsActive(ViewID view);
|
||||||
|
void EvalCommand(String command);
|
||||||
|
void EvalCommand(String16 command);
|
||||||
|
|
||||||
inline bool operator==(BufferID a, BufferID b) { return a.id == b.id; }
|
inline bool operator==(BufferID a, BufferID b) { return a.id == b.id; }
|
||||||
inline bool operator==(ViewID a, ViewID b) { return a.id == b.id; }
|
inline bool operator==(ViewID a, ViewID b) { return a.id == b.id; }
|
||||||
@@ -120,17 +122,7 @@ inline bool operator!=(ViewID a, ViewID b) { return a.id != b.id; }
|
|||||||
// We don't really care about opening buffers that don't have proper paths
|
// We don't really care about opening buffers that don't have proper paths
|
||||||
Buffer *BufferOpenFile(String path);
|
Buffer *BufferOpenFile(String path);
|
||||||
|
|
||||||
#if DEBUG_BUILD
|
|
||||||
#define IF_DEBUG(x) x
|
|
||||||
#else
|
|
||||||
#define IF_DEBUG(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
typedef void Function();
|
|
||||||
typedef void PFunction(void *param);
|
typedef void PFunction(void *param);
|
||||||
struct FunctionData { String name; Function *function; };
|
|
||||||
struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; };
|
|
||||||
struct PFunctionData { String name; PFunction *function; };
|
struct PFunctionData { String name; PFunction *function; };
|
||||||
|
|
||||||
struct Register_Function {
|
struct Register_Function {
|
||||||
|
|||||||
@@ -169,21 +169,6 @@ void Command_ShowBufferList() {
|
|||||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||||
} RegisterCommand(Command_ShowBufferList, "ctrl-p");
|
} RegisterCommand(Command_ShowBufferList, "ctrl-p");
|
||||||
|
|
||||||
void EvalCommand(String command) {
|
|
||||||
For (CommandFunctions) {
|
|
||||||
if (it.name == command) {
|
|
||||||
ProfileScopeEx(it.name);
|
|
||||||
it.function();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EvalCommand(String16 command) {
|
|
||||||
Scratch scratch;
|
|
||||||
EvalCommand(ToString(scratch, command));
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenCommand(BSet active) {
|
void OpenCommand(BSet active) {
|
||||||
ProfileFunction();
|
ProfileFunction();
|
||||||
Range range = active.view->carets[0].range;
|
Range range = active.view->carets[0].range;
|
||||||
|
|||||||
Reference in New Issue
Block a user