diff --git a/src/editor/edit.c b/src/editor/edit.c index fc107cfc8..da356cff4 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -4135,10 +4135,7 @@ void edit_stack_init (void) { for (edit_stack_iterator = 0; edit_stack_iterator < MAX_HISTORY_MOVETO; edit_stack_iterator++) - { - edit_history_moveto[edit_stack_iterator].file_vpath = NULL; - edit_history_moveto[edit_stack_iterator].line_number = -1; - } + edit_arg_init (&edit_history_moveto[edit_stack_iterator], NULL, -1); edit_stack_iterator = 0; } @@ -4206,6 +4203,38 @@ edit_arg_new (const char *file_name, long line_number) return edit_arg_vpath_new (vfs_path_from_str (file_name), line_number); } +/* --------------------------------------------------------------------------------------------- */ +/** + * Initialize edit_arg_t object. + * + * @param arg edit_arg_t object + * @param vpath vfs_path_t object + * @param line line number + */ + +void +edit_arg_init (edit_arg_t * arg, vfs_path_t * vpath, long line) +{ + arg->file_vpath = (vfs_path_t *) vpath; + arg->line_number = line; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Apply new values to edit_arg_t object members. + * + * @param arg edit_arg_t object + * @param vpath vfs_path_t object + * @param line line number + */ + +void +edit_arg_assign (edit_arg_t * arg, vfs_path_t * vpath, long line) +{ + vfs_path_free (arg->file_vpath, TRUE); + edit_arg_init (arg, vpath, line); +} + /* --------------------------------------------------------------------------------------------- */ /** * Free the edit_arg_t object. diff --git a/src/editor/edit.h b/src/editor/edit.h index 89c6f879c..d3231d29d 100644 --- a/src/editor/edit.h +++ b/src/editor/edit.h @@ -83,6 +83,8 @@ gboolean edit_files (const GList * files); edit_arg_t *edit_arg_vpath_new (vfs_path_t * file_vpath, long line_number); edit_arg_t *edit_arg_new (const char *file_name, long line_number); +void edit_arg_init (edit_arg_t * arg, vfs_path_t * vpath, long line); +void edit_arg_assign (edit_arg_t * arg, vfs_path_t * vpath, long line); void edit_arg_free (edit_arg_t * arg); const char *edit_get_file_name (const WEdit * edit); diff --git a/src/editor/etags.c b/src/editor/etags.c index 8ef7e21d8..64229dae5 100644 --- a/src/editor/etags.c +++ b/src/editor/etags.c @@ -380,23 +380,20 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, GPtrArray if (curr != NULL && do_moveto && edit_stack_iterator + 1 < MAX_HISTORY_MOVETO) { - vfs_path_free (edit_history_moveto[edit_stack_iterator].file_vpath, TRUE); + vfs_path_t *vpath; /* Is file path absolute? Prepend with dir_vpath if necessary */ if (edit->filename_vpath != NULL && edit->filename_vpath->relative && edit->dir_vpath != NULL) - edit_history_moveto[edit_stack_iterator].file_vpath = - vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, NULL); + vpath = vfs_path_append_vpath_new (edit->dir_vpath, edit->filename_vpath, NULL); else - edit_history_moveto[edit_stack_iterator].file_vpath = - vfs_path_clone (edit->filename_vpath); + vpath = vfs_path_clone (edit->filename_vpath); - edit_history_moveto[edit_stack_iterator].line_number = edit->start_line + edit->curs_row + 1; + edit_arg_assign (&edit_history_moveto[edit_stack_iterator], vpath, + edit->start_line + edit->curs_row + 1); edit_stack_iterator++; - vfs_path_free (edit_history_moveto[edit_stack_iterator].file_vpath, TRUE); - edit_history_moveto[edit_stack_iterator].file_vpath = - vfs_path_from_str ((char *) curr_def->fullpath); - edit_history_moveto[edit_stack_iterator].line_number = curr_def->line; + edit_arg_assign (&edit_history_moveto[edit_stack_iterator], + vfs_path_from_str ((char *) curr_def->fullpath), curr_def->line); edit_reload_line (edit, edit_history_moveto[edit_stack_iterator].file_vpath, edit_history_moveto[edit_stack_iterator].line_number); }