mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Implementation of getting last editing/viewing position of file.
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
7fd906ba13
commit
6447c76cca
@ -1102,7 +1102,8 @@ load_file_position (const vfs_path_t * filename_vpath, long *line, long *column,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* prepare array for serialized bookmarks */
|
/* prepare array for serialized bookmarks */
|
||||||
*bookmarks = g_array_sized_new (FALSE, FALSE, sizeof (size_t), MAX_SAVED_BOOKMARKS);
|
if (bookmarks != NULL)
|
||||||
|
*bookmarks = g_array_sized_new (FALSE, FALSE, sizeof (size_t), MAX_SAVED_BOOKMARKS);
|
||||||
filename = vfs_path_to_str (filename_vpath);
|
filename = vfs_path_to_str (filename_vpath);
|
||||||
|
|
||||||
while (fgets (buf, sizeof (buf), f) != NULL)
|
while (fgets (buf, sizeof (buf), f) != NULL)
|
||||||
@ -1143,7 +1144,7 @@ load_file_position (const vfs_path_t * filename_vpath, long *line, long *column,
|
|||||||
*column = strtol (pos_tokens[1], NULL, 10);
|
*column = strtol (pos_tokens[1], NULL, 10);
|
||||||
if (pos_tokens[2] == NULL)
|
if (pos_tokens[2] == NULL)
|
||||||
*offset = 0;
|
*offset = 0;
|
||||||
else
|
else if (bookmarks != NULL)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ int pause_after_run = pause_on_dumb_terminals;
|
|||||||
void do_execute (const char *shell, const char *command, int flags);
|
void do_execute (const char *shell, const char *command, int flags);
|
||||||
void do_executev (const char *shell, int flags, char *const argv[]);
|
void do_executev (const char *shell, int flags, char *const argv[]);
|
||||||
char *execute_get_external_cmd_opts_from_config (const char *command,
|
char *execute_get_external_cmd_opts_from_config (const char *command,
|
||||||
const vfs_path_t * filename_vpath, int start_line);
|
const vfs_path_t * filename_vpath, long start_line);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ execute_get_opts_from_cfg (const char *command, const char *default_str)
|
|||||||
|
|
||||||
char *
|
char *
|
||||||
execute_get_external_cmd_opts_from_config (const char *command, const vfs_path_t * filename_vpath,
|
execute_get_external_cmd_opts_from_config (const char *command, const vfs_path_t * filename_vpath,
|
||||||
int start_line)
|
long start_line)
|
||||||
{
|
{
|
||||||
char *str_from_config, *return_str;
|
char *str_from_config, *return_str;
|
||||||
char *parameter;
|
char *parameter;
|
||||||
@ -270,7 +270,7 @@ execute_get_external_cmd_opts_from_config (const char *command, const vfs_path_t
|
|||||||
g_free (str_from_config);
|
g_free (str_from_config);
|
||||||
str_from_config = return_str;
|
str_from_config = return_str;
|
||||||
|
|
||||||
parameter = g_strdup_printf ("%d", start_line);
|
parameter = g_strdup_printf ("%ld", start_line);
|
||||||
return_str = str_replace_all (str_from_config, "%lineno", parameter);
|
return_str = str_replace_all (str_from_config, "%lineno", parameter);
|
||||||
g_free (parameter);
|
g_free (parameter);
|
||||||
g_free (str_from_config);
|
g_free (str_from_config);
|
||||||
@ -612,7 +612,7 @@ execute_with_vfs_arg (const char *command, const vfs_path_t * filename_vpath)
|
|||||||
|
|
||||||
void
|
void
|
||||||
execute_external_editor_or_viewer (const char *command, const vfs_path_t * filename_vpath,
|
execute_external_editor_or_viewer (const char *command, const vfs_path_t * filename_vpath,
|
||||||
int start_line)
|
long start_line)
|
||||||
{
|
{
|
||||||
vfs_path_t *localcopy_vpath = NULL;
|
vfs_path_t *localcopy_vpath = NULL;
|
||||||
const vfs_path_t *do_execute_vpath;
|
const vfs_path_t *do_execute_vpath;
|
||||||
|
@ -44,7 +44,7 @@ gboolean execute_suspend (const gchar * event_group_name, const gchar * event_na
|
|||||||
/* Execute command on a filename that can be on VFS */
|
/* Execute command on a filename that can be on VFS */
|
||||||
void execute_with_vfs_arg (const char *command, const vfs_path_t * filename_vpath);
|
void execute_with_vfs_arg (const char *command, const vfs_path_t * filename_vpath);
|
||||||
void execute_external_editor_or_viewer (const char *command, const vfs_path_t * filename_vpath,
|
void execute_external_editor_or_viewer (const char *command, const vfs_path_t * filename_vpath,
|
||||||
int start_line);
|
long start_line);
|
||||||
|
|
||||||
void post_exec (void);
|
void post_exec (void);
|
||||||
void pre_exec (void);
|
void pre_exec (void);
|
||||||
|
@ -166,7 +166,17 @@ do_view_cmd (gboolean normal)
|
|||||||
static inline void
|
static inline void
|
||||||
do_edit (const vfs_path_t * what_vpath)
|
do_edit (const vfs_path_t * what_vpath)
|
||||||
{
|
{
|
||||||
do_edit_at_line (what_vpath, use_internal_edit, 0);
|
long line = 0;
|
||||||
|
|
||||||
|
if (!use_internal_edit)
|
||||||
|
{
|
||||||
|
long column;
|
||||||
|
off_t offset;
|
||||||
|
|
||||||
|
if (what_vpath != NULL && *(vfs_path_get_by_index (what_vpath, 0)->path) != '\0')
|
||||||
|
load_file_position (what_vpath, &line, &column, &offset, NULL);
|
||||||
|
}
|
||||||
|
do_edit_at_line (what_vpath, use_internal_edit, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -607,7 +617,7 @@ set_basic_panel_listing_to (int panel_index, int listing_mode)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, int start_line)
|
view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, long start_line)
|
||||||
{
|
{
|
||||||
static const char *viewer = NULL;
|
static const char *viewer = NULL;
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
@ -647,7 +657,7 @@ view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int intern
|
|||||||
char view_entry[BUF_TINY];
|
char view_entry[BUF_TINY];
|
||||||
|
|
||||||
if (start_line != 0)
|
if (start_line != 0)
|
||||||
g_snprintf (view_entry, sizeof (view_entry), "View:%d", start_line);
|
g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line);
|
||||||
else
|
else
|
||||||
strcpy (view_entry, "View");
|
strcpy (view_entry, "View");
|
||||||
|
|
||||||
@ -688,7 +698,18 @@ view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int intern
|
|||||||
gboolean
|
gboolean
|
||||||
view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
|
view_file (const vfs_path_t * filename_vpath, int plain_view, int internal)
|
||||||
{
|
{
|
||||||
return view_file_at_line (filename_vpath, plain_view, internal, 0);
|
long line = 0;
|
||||||
|
|
||||||
|
if (!internal)
|
||||||
|
{
|
||||||
|
long column;
|
||||||
|
off_t offset;
|
||||||
|
|
||||||
|
if (filename_vpath != NULL && *(vfs_path_get_by_index (filename_vpath, 0)->path) != '\0')
|
||||||
|
load_file_position (filename_vpath, &line, &column, &offset, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view_file_at_line (filename_vpath, plain_view, internal, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -761,7 +782,7 @@ view_filtered_cmd (void)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line)
|
do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line)
|
||||||
{
|
{
|
||||||
static const char *editor = NULL;
|
static const char *editor = NULL;
|
||||||
|
|
||||||
@ -777,6 +798,10 @@ do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_lin
|
|||||||
if (editor == NULL)
|
if (editor == NULL)
|
||||||
editor = get_default_editor ();
|
editor = get_default_editor ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (start_line < 1)
|
||||||
|
start_line = 1;
|
||||||
|
|
||||||
execute_external_editor_or_viewer (editor, what_vpath, start_line);
|
execute_external_editor_or_viewer (editor, what_vpath, start_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,13 +53,13 @@ void smart_dirsize_cmd (void);
|
|||||||
void single_dirsize_cmd (void);
|
void single_dirsize_cmd (void);
|
||||||
void dirsizes_cmd (void);
|
void dirsizes_cmd (void);
|
||||||
gboolean view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal,
|
gboolean view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal,
|
||||||
int start_line);
|
long start_line);
|
||||||
gboolean view_file (const vfs_path_t * filename_vpath, int normal, int internal);
|
gboolean view_file (const vfs_path_t * filename_vpath, int normal, int internal);
|
||||||
void view_cmd (void);
|
void view_cmd (void);
|
||||||
void view_file_cmd (void);
|
void view_file_cmd (void);
|
||||||
void view_raw_cmd (void);
|
void view_raw_cmd (void);
|
||||||
void view_filtered_cmd (void);
|
void view_filtered_cmd (void);
|
||||||
void do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, int start_line);
|
void do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line);
|
||||||
void edit_cmd (void);
|
void edit_cmd (void);
|
||||||
void edit_cmd_new (void);
|
void edit_cmd_new (void);
|
||||||
#ifdef USE_INTERNAL_EDIT
|
#ifdef USE_INTERNAL_EDIT
|
||||||
|
Loading…
Reference in New Issue
Block a user