BasicSaveBuffer and SaveAll improvements
This commit is contained in:
@@ -1,7 +1,15 @@
|
|||||||
! What precise workflow do I need for me to be viable to use this?
|
! What precise workflow do I need for me to be viable to use this?
|
||||||
! From a user (novice) point of view, how does it look like?
|
! From a user (novice) point of view, how does it look like?
|
||||||
|
|
||||||
|
Other:
|
||||||
|
- Try out syncthing and setup the synchronized notes, maybe other things
|
||||||
|
- Write some gmail rules to forward emails from there to my proton account
|
||||||
|
- Maybe I should try out an email aggregator thing like Mozzila thunderbolt, then I will have all the data and stuff locally
|
||||||
|
- Backup all the messages on phone using a tool
|
||||||
|
- Move music and other things from phone to proton and categorize
|
||||||
|
|
||||||
Use session 4
|
Use session 4
|
||||||
|
- Option for inserting tab instead of space
|
||||||
- Add <<File>> <<WorkDir>> template strings to Open (Then remove SEtWorkdirhere)
|
- Add <<File>> <<WorkDir>> template strings to Open (Then remove SEtWorkdirhere)
|
||||||
- :Set Filename to name current buffer ??? :O and others like that!!
|
- :Set Filename to name current buffer ??? :O and others like that!!
|
||||||
- :Close Fuzzy search exact match doesn't match with Close
|
- :Close Fuzzy search exact match doesn't match with Close
|
||||||
|
|||||||
@@ -1517,6 +1517,20 @@ void ReopenBuffer(Buffer *buffer) {
|
|||||||
buffer->dirty = false;
|
buffer->dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BasicSaveBuffer(Buffer *buffer) {
|
||||||
|
Scratch scratch;
|
||||||
|
String string = AllocCharString(scratch, buffer);
|
||||||
|
bool success = WriteFile(buffer->name, string);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
buffer->file_mod_time = GetFileModTime(buffer->name);
|
||||||
|
buffer->dirty = false;
|
||||||
|
buffer->temp = false;
|
||||||
|
} else {
|
||||||
|
ReportWarningf("Failed to save file with name: %S", buffer->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SaveBuffer(Buffer *buffer) {
|
void SaveBuffer(Buffer *buffer) {
|
||||||
bool formatted = false;
|
bool formatted = false;
|
||||||
if (FormatCode) {
|
if (FormatCode) {
|
||||||
@@ -1537,15 +1551,5 @@ void SaveBuffer(Buffer *buffer) {
|
|||||||
TrimWhitespace(buffer);
|
TrimWhitespace(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scratch scratch;
|
BasicSaveBuffer(buffer);
|
||||||
String string = AllocCharString(scratch, buffer);
|
|
||||||
bool success = WriteFile(buffer->name, string);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
buffer->file_mod_time = GetFileModTime(buffer->name);
|
|
||||||
buffer->dirty = false;
|
|
||||||
buffer->temp = false;
|
|
||||||
} else {
|
|
||||||
ReportWarningf("Failed to save file with name: %S", buffer->name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,8 +319,14 @@ void ConvertLineEndingsToLF(Buffer *buffer, bool trim_lines_with_caret = false)
|
|||||||
void ApplyFormattingTool(Buffer *buffer, String tool) {
|
void ApplyFormattingTool(Buffer *buffer, String tool) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String string = AllocCharString(scratch, buffer);
|
String string = AllocCharString(scratch, buffer);
|
||||||
Buffer *temp_buffer = ExecAndWait(scratch, tool, GetDir(buffer), string);
|
ExecResult exec_result = ExecAndWait(scratch, tool, GetDir(buffer), string);
|
||||||
ReplaceWithoutMovingCarets(buffer, GetRange(buffer), {temp_buffer->str, temp_buffer->len});
|
String16 string16 = {exec_result.buffer->str, exec_result.buffer->len};
|
||||||
|
if (exec_result.exit_code == 0) {
|
||||||
|
ReplaceWithoutMovingCarets(buffer, GetRange(buffer), string16);
|
||||||
|
} else {
|
||||||
|
View *view = GetView(NullViewID);
|
||||||
|
Append(view, string16, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GotoNextInList(Window *window, Int line_offset = 1) {
|
void GotoNextInList(Window *window, Int line_offset = 1) {
|
||||||
@@ -448,8 +454,8 @@ BSet ExecBuild(String cmd) {
|
|||||||
void CMD_SaveAll() {
|
void CMD_SaveAll() {
|
||||||
For(Buffers) {
|
For(Buffers) {
|
||||||
// NOTE: file_mod_time is only set when buffer got read or written to disk already so should be saved
|
// NOTE: file_mod_time is only set when buffer got read or written to disk already so should be saved
|
||||||
if (it->file_mod_time) {
|
if (it->file_mod_time && it->dirty) {
|
||||||
SaveBuffer(it);
|
BasicSaveBuffer(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} RegisterCommand(CMD_SaveAll, "ctrl-shift-s");
|
} RegisterCommand(CMD_SaveAll, "ctrl-shift-s");
|
||||||
|
|||||||
@@ -36,17 +36,23 @@ void Exec(ViewID view, bool scroll_to_end, String16 cmd16, String working_dir) {
|
|||||||
Exec(view, scroll_to_end, cmd, working_dir);
|
Exec(view, scroll_to_end, cmd, working_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer *ExecAndWait(Allocator allocator, String cmd, String working_dir, String stdin_string = {}) {
|
struct ExecResult {
|
||||||
|
Buffer *buffer;
|
||||||
|
int exit_code;
|
||||||
|
};
|
||||||
|
|
||||||
|
ExecResult ExecAndWait(Allocator allocator, String cmd, String working_dir, String stdin_string = {}) {
|
||||||
ReportDebugf("ExecAndWait cmd = %S working_dir = %S stdin_string = %S", cmd, working_dir, stdin_string);
|
ReportDebugf("ExecAndWait cmd = %S working_dir = %S stdin_string = %S", cmd, working_dir, stdin_string);
|
||||||
|
|
||||||
Buffer *scratch_buff = CreateScratchBuffer(allocator, 4096 * 4);
|
Buffer *scratch_buff = CreateScratchBuffer(allocator, 4096 * 4);
|
||||||
for (Process process = SpawnProcess(cmd, working_dir, stdin_string, ProcessEnviroment); IsValid(&process);) {
|
Process process = SpawnProcess(cmd, working_dir, stdin_string, ProcessEnviroment);
|
||||||
|
for (;IsValid(&process);) {
|
||||||
Scratch scratch(allocator);
|
Scratch scratch(allocator);
|
||||||
String poll = PollStdout(scratch, &process, true);
|
String poll = PollStdout(scratch, &process, true);
|
||||||
if (poll.len) RawAppend(scratch_buff, poll);
|
if (poll.len) RawAppend(scratch_buff, poll);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scratch_buff;
|
return {scratch_buff, process.exit_code};
|
||||||
}
|
}
|
||||||
|
|
||||||
void KillProcess(View *view) {
|
void KillProcess(View *view) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void CMD_ShowBufferList() {
|
|||||||
ResetBuffer(command_bar.buffer);
|
ResetBuffer(command_bar.buffer);
|
||||||
For (Buffers) {
|
For (Buffers) {
|
||||||
if (it->special || it->temp || it->is_dir) {
|
if (it->special || it->temp || it->is_dir) {
|
||||||
if (it->id != NullBufferID && it->id != BuildBufferID) continue;
|
if (it->id != NullBufferID) continue;
|
||||||
}
|
}
|
||||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user