2017-01-23 06:19:43 +00:00
|
|
|
/*
|
|
|
|
4coder_jump_parsing.cpp - Commands and helpers for parsing jump locations from
|
|
|
|
compiler errors and jumping to them in the corresponding buffer.
|
2016-07-13 19:59:42 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
TYPE: 'drop-in-command-pack'
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
#if !defined(FCODER_JUMP_PARSING)
|
2016-07-13 19:59:42 +00:00
|
|
|
#define FCODER_JUMP_PARSING
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#include "4coder_default_framework.h"
|
|
|
|
#include "4coder_helper/4coder_long_seek.h"
|
|
|
|
#include "4coder_helper/4coder_helper.h"
|
2017-02-24 16:48:56 +00:00
|
|
|
#include "4coder_helper/4coder_jump_parsing.h"
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
#include "4coder_lib/4coder_mem.h"
|
|
|
|
|
2016-07-13 19:59:42 +00:00
|
|
|
CUSTOM_COMMAND_SIG(goto_jump_at_cursor){
|
|
|
|
Temp_Memory temp = begin_temp_memory(&global_part);
|
2016-09-17 00:03:09 +00:00
|
|
|
View_Summary view = get_active_view(app, AccessProtected);
|
2016-07-13 19:59:42 +00:00
|
|
|
|
2016-09-01 00:26:52 +00:00
|
|
|
Name_Based_Jump_Location location = {0};
|
2017-03-20 06:35:39 +00:00
|
|
|
if (parse_jump_from_buffer_line(app, &global_part, view.buffer_id, view.cursor.line, false, &location)){
|
2016-07-13 19:59:42 +00:00
|
|
|
exec_command(app, change_active_panel);
|
2016-09-17 00:03:09 +00:00
|
|
|
view = get_active_view(app, AccessAll);
|
2016-07-13 19:59:42 +00:00
|
|
|
jump_to_location(app, &view, &location);
|
|
|
|
}
|
|
|
|
|
|
|
|
end_temp_memory(temp);
|
|
|
|
}
|
|
|
|
|
2016-09-01 00:26:52 +00:00
|
|
|
|
2016-07-13 19:59:42 +00:00
|
|
|
//
|
|
|
|
// Error Jumping
|
|
|
|
//
|
|
|
|
|
2017-03-20 06:35:39 +00:00
|
|
|
static bool32
|
2017-03-23 19:14:39 +00:00
|
|
|
seek_next_jump_in_buffer(Application_Links *app, Partition *part, int32_t buffer_id, size_t first_line, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){
|
2016-09-01 00:26:52 +00:00
|
|
|
|
|
|
|
Assert(direction == 1 || direction == -1);
|
2016-07-13 19:59:42 +00:00
|
|
|
|
2017-03-20 06:35:39 +00:00
|
|
|
bool32 result = false;
|
2017-03-23 19:14:39 +00:00
|
|
|
size_t line = first_line;
|
2016-07-13 19:59:42 +00:00
|
|
|
String line_str = {0};
|
2016-09-17 00:03:09 +00:00
|
|
|
Buffer_Summary buffer = get_buffer(app, buffer_id, AccessAll);
|
2016-07-13 19:59:42 +00:00
|
|
|
for (;;){
|
|
|
|
if (read_line(app, part, &buffer, line, &line_str)){
|
2016-09-01 00:26:52 +00:00
|
|
|
if (parse_jump_location(line_str, location_out, skip_sub_errors, colon_index_out)){
|
2016-07-13 19:59:42 +00:00
|
|
|
result = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
line += direction;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line < 0){
|
|
|
|
line = 0;
|
|
|
|
}
|
|
|
|
|
2016-09-01 00:26:52 +00:00
|
|
|
*line_out = line;
|
2016-07-13 19:59:42 +00:00
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2016-09-01 00:26:52 +00:00
|
|
|
static ID_Based_Jump_Location
|
|
|
|
convert_name_based_to_id_based(Application_Links *app, Name_Based_Jump_Location loc){
|
|
|
|
ID_Based_Jump_Location result = {0};
|
2016-07-18 19:02:22 +00:00
|
|
|
Buffer_Summary buffer =
|
2016-09-17 00:03:09 +00:00
|
|
|
get_buffer_by_name(app, loc.file.str, loc.file.size, AccessAll);
|
2016-07-18 19:02:22 +00:00
|
|
|
|
|
|
|
if (buffer.exists){
|
|
|
|
result.buffer_id = buffer.buffer_id;
|
|
|
|
result.line = loc.line;
|
2016-09-01 00:26:52 +00:00
|
|
|
result.column = loc.column;
|
2016-07-18 19:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:03:26 +00:00
|
|
|
static int32_t
|
2017-03-23 19:14:39 +00:00
|
|
|
seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, bool32 skip_sub_errors, int32_t direction, size_t *line_out, size_t *colon_index_out, Name_Based_Jump_Location *location_out){
|
2016-08-29 01:03:26 +00:00
|
|
|
int32_t result = false;
|
2016-07-13 19:59:42 +00:00
|
|
|
|
2016-09-01 00:26:52 +00:00
|
|
|
Name_Based_Jump_Location location = {0};
|
2017-03-23 19:14:39 +00:00
|
|
|
size_t line = view->cursor.line;
|
|
|
|
size_t colon_index = 0;
|
2017-01-29 00:03:23 +00:00
|
|
|
if (seek_next_jump_in_buffer(app, part, view->buffer_id, line+direction, skip_sub_errors, direction, &line, &colon_index, &location)){
|
2016-09-01 00:26:52 +00:00
|
|
|
result = true;
|
|
|
|
*line_out = line;
|
|
|
|
*colon_index_out = colon_index;
|
|
|
|
*location_out = location;
|
2016-07-13 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:03:26 +00:00
|
|
|
static int32_t
|
2016-09-01 00:26:52 +00:00
|
|
|
skip_this_jump(ID_Based_Jump_Location prev, ID_Based_Jump_Location jump){
|
2016-08-29 01:03:26 +00:00
|
|
|
int32_t result = false;
|
2016-09-01 00:26:52 +00:00
|
|
|
if (prev.buffer_id != 0 &&
|
|
|
|
prev.buffer_id == jump.buffer_id &&
|
|
|
|
prev.line == jump.line &&
|
|
|
|
prev.column <= jump.column){
|
2016-07-13 19:59:42 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-03-20 06:35:39 +00:00
|
|
|
static bool32
|
|
|
|
advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summary *view, int32_t skip_repeats, bool32 skip_sub_error, int32_t direction, Name_Based_Jump_Location *location_out){
|
|
|
|
bool32 result = true;
|
2016-09-01 00:26:52 +00:00
|
|
|
|
|
|
|
Name_Based_Jump_Location location = {0};
|
|
|
|
ID_Based_Jump_Location jump = {0};
|
2017-03-23 19:14:39 +00:00
|
|
|
size_t line = 0, colon_index = 0;
|
2016-09-01 00:26:52 +00:00
|
|
|
|
2016-07-13 19:59:42 +00:00
|
|
|
do{
|
|
|
|
Temp_Memory temp = begin_temp_memory(part);
|
2017-01-29 00:03:23 +00:00
|
|
|
if (seek_next_jump_in_view(app, part, view, skip_sub_error, direction, &line, &colon_index, &location)){
|
2016-09-01 00:26:52 +00:00
|
|
|
jump = convert_name_based_to_id_based(app, location);
|
2017-01-29 00:03:23 +00:00
|
|
|
view_set_cursor(app, view, seek_line_char(line, colon_index+1), true);
|
2016-07-13 19:59:42 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
jump.buffer_id = 0;
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
end_temp_memory(temp);
|
2016-09-01 00:26:52 +00:00
|
|
|
}while(skip_repeats && skip_this_jump(prev_location, jump));
|
|
|
|
|
|
|
|
if (result){
|
|
|
|
*location_out = location;
|
2016-09-17 00:03:09 +00:00
|
|
|
view_set_cursor(app, view, seek_line_char(line, colon_index+1), true);
|
2016-09-01 00:26:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 19:59:42 +00:00
|
|
|
prev_location = jump;
|
2016-09-01 00:26:52 +00:00
|
|
|
|
2016-07-13 19:59:42 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:03:26 +00:00
|
|
|
static int32_t
|
2017-01-29 00:03:23 +00:00
|
|
|
seek_jump(Application_Links *app, Partition *part, int32_t skip_repeats, int32_t skip_sub_errors, int32_t direction){
|
2016-09-01 00:26:52 +00:00
|
|
|
int32_t result = 0;
|
|
|
|
|
|
|
|
View_Summary view = get_view_for_locked_jump_buffer(app);
|
|
|
|
if (view.exists){
|
|
|
|
|
|
|
|
Name_Based_Jump_Location location = {0};
|
2017-01-29 00:03:23 +00:00
|
|
|
if (advance_cursor_in_jump_view(app, &global_part, &view, skip_repeats, skip_sub_errors, direction, &location)){
|
2016-09-17 00:03:09 +00:00
|
|
|
View_Summary active_view = get_active_view(app, AccessAll);
|
2016-09-01 00:26:52 +00:00
|
|
|
if (active_view.view_id == view.view_id){
|
2016-09-01 19:40:25 +00:00
|
|
|
exec_command(app, change_active_panel);
|
2016-09-17 00:03:09 +00:00
|
|
|
active_view = get_active_view(app, AccessAll);
|
2016-09-01 00:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jump_to_location(app, &active_view, &location);
|
|
|
|
result = 1;
|
|
|
|
}
|
2016-07-18 20:53:04 +00:00
|
|
|
}
|
2016-09-01 00:26:52 +00:00
|
|
|
|
|
|
|
return(result);
|
2016-07-18 20:53:04 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 00:26:52 +00:00
|
|
|
|
2016-09-01 20:29:07 +00:00
|
|
|
CUSTOM_COMMAND_SIG(goto_next_jump){
|
2016-09-01 00:26:52 +00:00
|
|
|
int32_t skip_repeats = true;
|
|
|
|
int32_t skip_sub_errors = true;
|
|
|
|
int32_t dir = 1;
|
2017-01-29 00:03:23 +00:00
|
|
|
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
|
2016-07-13 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 20:29:07 +00:00
|
|
|
CUSTOM_COMMAND_SIG(goto_prev_jump){
|
2016-09-01 00:26:52 +00:00
|
|
|
int32_t skip_repeats = true;
|
|
|
|
int32_t skip_sub_errors = true;
|
|
|
|
int32_t dir = -1;
|
2017-01-29 00:03:23 +00:00
|
|
|
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
|
2016-07-13 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 20:29:07 +00:00
|
|
|
CUSTOM_COMMAND_SIG(goto_next_jump_no_skips){
|
2016-09-01 00:26:52 +00:00
|
|
|
int32_t skip_repeats = false;
|
|
|
|
int32_t skip_sub_errors = true;
|
|
|
|
int32_t dir = 1;
|
2017-01-29 00:03:23 +00:00
|
|
|
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
|
2016-07-18 19:02:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 20:29:07 +00:00
|
|
|
CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips){
|
2016-09-01 00:26:52 +00:00
|
|
|
int32_t skip_repeats = false;
|
|
|
|
int32_t skip_sub_errors = true;
|
|
|
|
int32_t dir = -1;
|
2017-01-29 00:03:23 +00:00
|
|
|
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
|
2016-07-18 19:02:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 20:29:07 +00:00
|
|
|
CUSTOM_COMMAND_SIG(goto_first_jump){
|
2016-07-13 19:59:42 +00:00
|
|
|
Temp_Memory temp = begin_temp_memory(&global_part);
|
2016-09-01 00:26:52 +00:00
|
|
|
View_Summary view = get_view_for_locked_jump_buffer(app);
|
|
|
|
if (view.exists){
|
2016-09-17 00:03:09 +00:00
|
|
|
view_set_cursor(app, &view, seek_pos(0), true);
|
2016-09-01 00:26:52 +00:00
|
|
|
prev_location = null_location;
|
2017-01-29 00:03:23 +00:00
|
|
|
seek_jump(app, &global_part, false, true, 1);
|
2016-09-01 00:26:52 +00:00
|
|
|
}
|
2016-07-13 19:59:42 +00:00
|
|
|
end_temp_memory(temp);
|
|
|
|
}
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
//
|
2017-02-24 16:48:56 +00:00
|
|
|
// Insert Newline or Tigger Jump on Read Only Buffer
|
2017-01-29 00:03:23 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(newline_or_goto_position){
|
|
|
|
View_Summary view = get_active_view(app, AccessProtected);
|
|
|
|
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected);
|
|
|
|
|
|
|
|
if (buffer.lock_flags & AccessProtected){
|
|
|
|
exec_command(app, goto_jump_at_cursor);
|
|
|
|
lock_jump_buffer(buffer);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
exec_command(app, write_character);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define seek_error seek_jump
|
2016-09-02 15:58:04 +00:00
|
|
|
#define goto_next_error goto_next_jump
|
|
|
|
#define goto_prev_error goto_prev_jump
|
|
|
|
#define goto_next_error_no_skips goto_next_jump_no_skips
|
|
|
|
#define goto_first_error goto_first_jump
|
2016-09-01 20:29:07 +00:00
|
|
|
|
2016-07-13 19:59:42 +00:00
|
|
|
#endif
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
// BOTTOM
|
|
|
|
|